2009-02-08 18:50:32 +00:00
|
|
|
/*
|
|
|
|
* NC camera feed demuxer
|
|
|
|
* Copyright (c) 2009 Nicolas Martin (martinic at iro dot umontreal dot ca)
|
|
|
|
* Edouard Auvinet
|
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* This file is part of Libav.
|
2009-02-08 18:50:32 +00:00
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2009-02-08 18:50:32 +00: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 17:35:10 +00:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2009-02-08 18:50:32 +00: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 17:35:10 +00:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2009-02-08 18:50:32 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libavutil/intreadwrite.h"
|
|
|
|
#include "avformat.h"
|
2011-11-29 18:28:15 +00:00
|
|
|
#include "internal.h"
|
2009-02-08 18:50:32 +00: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 13:28:14 +00:00
|
|
|
return AVPROBE_SCORE_MAX/4;
|
2009-02-08 18:50:32 +00:00
|
|
|
|
|
|
|
if (AV_RB32(probe_packet->buf+16+size) == NC_VIDEO_FLAG)
|
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-12 12:20:36 +00:00
|
|
|
static int nc_read_header(AVFormatContext *s)
|
2009-02-08 18:50:32 +00:00
|
|
|
{
|
2011-06-18 09:43:24 +00:00
|
|
|
AVStream *st = avformat_new_stream(s, NULL);
|
2009-02-08 18:50:32 +00:00
|
|
|
|
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2010-03-30 23:30:55 +00:00
|
|
|
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
|
2009-02-08 18:50:32 +00:00
|
|
|
st->codec->codec_id = CODEC_ID_MPEG4;
|
|
|
|
st->need_parsing = AVSTREAM_PARSE_FULL;
|
|
|
|
|
2011-11-29 18:28:15 +00:00
|
|
|
avpriv_set_pts_info(st, 64, 1, 100);
|
2009-02-08 18:50:32 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
int size;
|
2009-02-08 21:42:06 +00:00
|
|
|
int ret;
|
2009-02-08 18:50:32 +00:00
|
|
|
|
|
|
|
uint32_t state=-1;
|
|
|
|
while (state != NC_VIDEO_FLAG) {
|
2011-03-07 20:50:25 +00:00
|
|
|
if (s->pb->eof_reached)
|
2009-02-08 18:50:32 +00:00
|
|
|
return AVERROR(EIO);
|
2011-02-21 15:43:01 +00:00
|
|
|
state = (state<<8) + avio_r8(s->pb);
|
2009-02-08 18:50:32 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
avio_r8(s->pb);
|
|
|
|
size = avio_rl16(s->pb);
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(s->pb, 9);
|
2009-02-08 18:50:32 +00:00
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
av_log(s, AV_LOG_DEBUG, "Next packet size is zero\n");
|
|
|
|
return AVERROR(EAGAIN);
|
|
|
|
}
|
|
|
|
|
2009-02-08 21:42:06 +00:00
|
|
|
ret = av_get_packet(s->pb, pkt, size);
|
2009-02-08 18:50:32 +00:00
|
|
|
if (ret != size) {
|
|
|
|
if (ret > 0) av_free_packet(pkt);
|
|
|
|
return AVERROR(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
pkt->stream_index = 0;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2011-01-25 22:03:28 +00:00
|
|
|
AVInputFormat ff_nc_demuxer = {
|
2011-07-16 20:18:12 +00: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 18:50:32 +00:00
|
|
|
.extensions = "v",
|
|
|
|
};
|