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
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2012-01-12 15:20:36 +03:00
|
|
|
static int nc_read_header(AVFormatContext *s)
|
2009-02-08 20:50:32 +02:00
|
|
|
{
|
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;
|
2012-08-05 12:11:04 +03:00
|
|
|
st->codec->codec_id = AV_CODEC_ID_MPEG4;
|
2009-02-08 20:50:32 +02:00
|
|
|
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) {
|
2014-08-07 23:12:41 +03:00
|
|
|
if (avio_feof(s->pb))
|
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",
|
2012-07-25 00:51:41 +03:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("NC camera feed"),
|
2011-07-16 23:18:12 +03:00
|
|
|
.read_probe = nc_probe,
|
|
|
|
.read_header = nc_read_header,
|
|
|
|
.read_packet = nc_read_packet,
|
2012-04-06 17:50:48 +03:00
|
|
|
.extensions = "v",
|
2009-02-08 20:50:32 +02:00
|
|
|
};
|