• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavformat/ncdec.c

Go to the documentation of this file.
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 #include "internal.h"
00026 
00027 #define NC_VIDEO_FLAG 0x1A5
00028 
00029 static int nc_probe(AVProbeData *probe_packet)
00030 {
00031     int size;
00032 
00033     if (AV_RB32(probe_packet->buf) != NC_VIDEO_FLAG)
00034         return 0;
00035 
00036     size = AV_RL16(probe_packet->buf + 5);
00037 
00038     if (size + 20 > probe_packet->buf_size)
00039         return AVPROBE_SCORE_MAX/4;
00040 
00041     if (AV_RB32(probe_packet->buf+16+size) == NC_VIDEO_FLAG)
00042         return AVPROBE_SCORE_MAX;
00043 
00044     return 0;
00045 }
00046 
00047 static int nc_read_header(AVFormatContext *s, AVFormatParameters *ap)
00048 {
00049     AVStream *st = avformat_new_stream(s, NULL);
00050 
00051     if (!st)
00052         return AVERROR(ENOMEM);
00053 
00054     st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00055     st->codec->codec_id   = CODEC_ID_MPEG4;
00056     st->need_parsing      = AVSTREAM_PARSE_FULL;
00057 
00058     avpriv_set_pts_info(st, 64, 1, 100);
00059 
00060     return 0;
00061 }
00062 
00063 static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)
00064 {
00065     int size;
00066     int ret;
00067 
00068     uint32_t state=-1;
00069     while (state != NC_VIDEO_FLAG) {
00070         if (s->pb->eof_reached)
00071             return AVERROR(EIO);
00072         state = (state<<8) + avio_r8(s->pb);
00073     }
00074 
00075     avio_r8(s->pb);
00076     size = avio_rl16(s->pb);
00077     avio_skip(s->pb, 9);
00078 
00079     if (size == 0) {
00080         av_log(s, AV_LOG_DEBUG, "Next packet size is zero\n");
00081         return AVERROR(EAGAIN);
00082     }
00083 
00084     ret = av_get_packet(s->pb, pkt, size);
00085     if (ret != size) {
00086         if (ret > 0) av_free_packet(pkt);
00087         return AVERROR(EIO);
00088     }
00089 
00090     pkt->stream_index = 0;
00091     return size;
00092 }
00093 
00094 AVInputFormat ff_nc_demuxer = {
00095     .name           = "nc",
00096     .long_name      = NULL_IF_CONFIG_SMALL("NC camera feed format"),
00097     .read_probe     = nc_probe,
00098     .read_header    = nc_read_header,
00099     .read_packet    = nc_read_packet,
00100     .extensions = "v",
00101 };
Generated on Thu Jul 11 2013 15:38:24 for Libav by doxygen 1.7.1