LCOV - code coverage report
Current view: top level - libavformat - ncdec.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 31 36 86.1 %
Date: 2017-12-13 18:07:29 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * NC camera feed demuxer
       3             :  * Copyright (c) 2009  Nicolas Martin (martinic at iro dot umontreal dot ca)
       4             :  *                     Edouard Auvinet
       5             :  *
       6             :  * This file is part of FFmpeg.
       7             :  *
       8             :  * FFmpeg is free software; you can redistribute it and/or
       9             :  * modify it under the terms of the GNU Lesser General Public
      10             :  * License as published by the Free Software Foundation; either
      11             :  * version 2.1 of the License, or (at your option) any later version.
      12             :  *
      13             :  * FFmpeg is distributed in the hope that it will be useful,
      14             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :  * Lesser General Public License for more details.
      17             :  *
      18             :  * You should have received a copy of the GNU Lesser General Public
      19             :  * License along with FFmpeg; if not, write to the Free Software
      20             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      21             :  */
      22             : 
      23             : #include "libavutil/intreadwrite.h"
      24             : #include "avformat.h"
      25             : #include "internal.h"
      26             : 
      27             : #define NC_VIDEO_FLAG 0x1A5
      28             : 
      29        6130 : static int nc_probe(AVProbeData *probe_packet)
      30             : {
      31             :     int size;
      32             : 
      33        6130 :     if (AV_RB32(probe_packet->buf) != NC_VIDEO_FLAG)
      34        6129 :         return 0;
      35             : 
      36           1 :     size = AV_RL16(probe_packet->buf + 5);
      37             : 
      38           1 :     if (size + 20 > probe_packet->buf_size)
      39           0 :         return AVPROBE_SCORE_MAX/4;
      40             : 
      41           1 :     if (AV_RB32(probe_packet->buf+16+size) == NC_VIDEO_FLAG)
      42           1 :         return AVPROBE_SCORE_MAX;
      43             : 
      44           0 :     return 0;
      45             : }
      46             : 
      47           1 : static int nc_read_header(AVFormatContext *s)
      48             : {
      49           1 :     AVStream *st = avformat_new_stream(s, NULL);
      50             : 
      51           1 :     if (!st)
      52           0 :         return AVERROR(ENOMEM);
      53             : 
      54           1 :     st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
      55           1 :     st->codecpar->codec_id   = AV_CODEC_ID_MPEG4;
      56           1 :     st->need_parsing      = AVSTREAM_PARSE_FULL;
      57             : 
      58           1 :     avpriv_set_pts_info(st, 64, 1, 100);
      59             : 
      60           1 :     return 0;
      61             : }
      62             : 
      63        1057 : static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)
      64             : {
      65             :     int size;
      66             :     int ret;
      67             : 
      68        1057 :     uint32_t state=-1;
      69        6338 :     while (state != NC_VIDEO_FLAG) {
      70        4225 :         if (avio_feof(s->pb))
      71           1 :             return AVERROR(EIO);
      72        4224 :         state = (state<<8) + avio_r8(s->pb);
      73             :     }
      74             : 
      75        1056 :     avio_r8(s->pb);
      76        1056 :     size = avio_rl16(s->pb);
      77        1056 :     avio_skip(s->pb, 9);
      78             : 
      79        1056 :     if (size == 0) {
      80           0 :         av_log(s, AV_LOG_DEBUG, "Next packet size is zero\n");
      81           0 :         return AVERROR(EAGAIN);
      82             :     }
      83             : 
      84        1056 :     ret = av_get_packet(s->pb, pkt, size);
      85        1056 :     if (ret != size) {
      86           1 :         if (ret > 0) av_packet_unref(pkt);
      87           1 :         return AVERROR(EIO);
      88             :     }
      89             : 
      90        1055 :     pkt->stream_index = 0;
      91        1055 :     return size;
      92             : }
      93             : 
      94             : AVInputFormat ff_nc_demuxer = {
      95             :     .name           = "nc",
      96             :     .long_name      = NULL_IF_CONFIG_SMALL("NC camera feed"),
      97             :     .read_probe     = nc_probe,
      98             :     .read_header    = nc_read_header,
      99             :     .read_packet    = nc_read_packet,
     100             :     .extensions     = "v",
     101             : };

Generated by: LCOV version 1.13