2009-02-08 20:50:32 +02:00
|
|
|
/*
|
|
|
|
* NC camera feed demuxer
|
|
|
|
* Copyright (c) 2009 Nicolas Martin (martinic at iro dot umontreal dot ca)
|
|
|
|
* Edouard Auvinet
|
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* This file is part of Libav.
|
2009-02-08 20:50:32 +02:00
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2009-02-08 20:50:32 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2009-02-08 20:50:32 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2011-03-18 19:35:10 +02:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2009-02-08 20:50:32 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libavutil/intreadwrite.h"
|
|
|
|
#include "avformat.h"
|
2011-11-29 21:28:15 +03:00
|
|
|
#include "internal.h"
|
2009-02-08 20:50:32 +02:00
|
|
|
|
|
|
|
#define NC_VIDEO_FLAG 0x1A5
|
|
|
|
|
|
|
|
static int nc_probe(AVProbeData *probe_packet)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if (AV_RB32(probe_packet->buf) != NC_VIDEO_FLAG)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
size = AV_RL16(probe_packet->buf + 5);
|
|
|
|
|
|
|
|
if (size + 20 > probe_packet->buf_size)
|
2009-09-15 16:28:14 +03:00
|
|
|
return AVPROBE_SCORE_MAX/4;
|
2009-02-08 20:50:32 +02:00
|
|
|
|
|
|
|
if (AV_RB32(probe_packet->buf+16+size) == NC_VIDEO_FLAG)
|
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nc_read_header(AVFormatContext *s, AVFormatParameters *ap)
|
|
|
|
{
|
2011-06-18 12:43:24 +03:00
|
|
|
AVStream *st = avformat_new_stream(s, NULL);
|
2009-02-08 20:50:32 +02:00
|
|
|
|
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2010-03-31 02:30:55 +03:00
|
|
|
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
|
2009-02-08 20:50:32 +02:00
|
|
|
st->codec->codec_id = CODEC_ID_MPEG4;
|
|
|
|
st->need_parsing = AVSTREAM_PARSE_FULL;
|
|
|
|
|
2011-11-29 21:28:15 +03:00
|
|
|
avpriv_set_pts_info(st, 64, 1, 100);
|
2009-02-08 20:50:32 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
int size;
|
2009-02-08 23:42:06 +02:00
|
|
|
int ret;
|
2009-02-08 20:50:32 +02:00
|
|
|
|
|
|
|
uint32_t state=-1;
|
|
|
|
while (state != NC_VIDEO_FLAG) {
|
2011-03-07 22:50:25 +02:00
|
|
|
if (s->pb->eof_reached)
|
2009-02-08 20:50:32 +02:00
|
|
|
return AVERROR(EIO);
|
2011-02-21 17:43:01 +02:00
|
|
|
state = (state<<8) + avio_r8(s->pb);
|
2009-02-08 20:50:32 +02:00
|
|
|
}
|
|
|
|
|
2011-02-21 17:43:01 +02:00
|
|
|
avio_r8(s->pb);
|
|
|
|
size = avio_rl16(s->pb);
|
2011-03-15 10:14:38 +02:00
|
|
|
avio_skip(s->pb, 9);
|
2009-02-08 20:50:32 +02:00
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
av_log(s, AV_LOG_DEBUG, "Next packet size is zero\n");
|
|
|
|
return AVERROR(EAGAIN);
|
|
|
|
}
|
|
|
|
|
2009-02-08 23:42:06 +02:00
|
|
|
ret = av_get_packet(s->pb, pkt, size);
|
2009-02-08 20:50:32 +02:00
|
|
|
if (ret != size) {
|
|
|
|
if (ret > 0) av_free_packet(pkt);
|
|
|
|
return AVERROR(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
pkt->stream_index = 0;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2011-01-26 00:03:28 +02:00
|
|
|
AVInputFormat ff_nc_demuxer = {
|
2011-07-16 23:18:12 +03:00
|
|
|
.name = "nc",
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("NC camera feed format"),
|
|
|
|
.read_probe = nc_probe,
|
|
|
|
.read_header = nc_read_header,
|
|
|
|
.read_packet = nc_read_packet,
|
2009-02-08 20:50:32 +02:00
|
|
|
.extensions = "v",
|
|
|
|
};
|