Libav 0.7.1
|
00001 /* 00002 * NC camera feed demuxer 00003 * Copyright (c) 2009 Nicolas Martin (martinic at iro dot umontreal dot ca) 00004 * Edouard Auvinet 00005 * 00006 * This file is part of Libav. 00007 * 00008 * Libav is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * Libav is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Libav; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #include "libavutil/intreadwrite.h" 00024 #include "avformat.h" 00025 00026 #define NC_VIDEO_FLAG 0x1A5 00027 00028 static int nc_probe(AVProbeData *probe_packet) 00029 { 00030 int size; 00031 00032 if (AV_RB32(probe_packet->buf) != NC_VIDEO_FLAG) 00033 return 0; 00034 00035 size = AV_RL16(probe_packet->buf + 5); 00036 00037 if (size + 20 > probe_packet->buf_size) 00038 return AVPROBE_SCORE_MAX/4; 00039 00040 if (AV_RB32(probe_packet->buf+16+size) == NC_VIDEO_FLAG) 00041 return AVPROBE_SCORE_MAX; 00042 00043 return 0; 00044 } 00045 00046 static int nc_read_header(AVFormatContext *s, AVFormatParameters *ap) 00047 { 00048 AVStream *st = av_new_stream(s, 0); 00049 00050 if (!st) 00051 return AVERROR(ENOMEM); 00052 00053 st->codec->codec_type = AVMEDIA_TYPE_VIDEO; 00054 st->codec->codec_id = CODEC_ID_MPEG4; 00055 st->need_parsing = AVSTREAM_PARSE_FULL; 00056 00057 av_set_pts_info(st, 64, 1, 100); 00058 00059 return 0; 00060 } 00061 00062 static int nc_read_packet(AVFormatContext *s, AVPacket *pkt) 00063 { 00064 int size; 00065 int ret; 00066 00067 uint32_t state=-1; 00068 while (state != NC_VIDEO_FLAG) { 00069 if (s->pb->eof_reached) 00070 return AVERROR(EIO); 00071 state = (state<<8) + avio_r8(s->pb); 00072 } 00073 00074 avio_r8(s->pb); 00075 size = avio_rl16(s->pb); 00076 avio_skip(s->pb, 9); 00077 00078 if (size == 0) { 00079 av_log(s, AV_LOG_DEBUG, "Next packet size is zero\n"); 00080 return AVERROR(EAGAIN); 00081 } 00082 00083 ret = av_get_packet(s->pb, pkt, size); 00084 if (ret != size) { 00085 if (ret > 0) av_free_packet(pkt); 00086 return AVERROR(EIO); 00087 } 00088 00089 pkt->stream_index = 0; 00090 return size; 00091 } 00092 00093 AVInputFormat ff_nc_demuxer = { 00094 "nc", 00095 NULL_IF_CONFIG_SMALL("NC camera feed format"), 00096 0, 00097 nc_probe, 00098 nc_read_header, 00099 nc_read_packet, 00100 .extensions = "v", 00101 };