LCOV - code coverage report
Current view: top level - src/libavformat - filmstripdec.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 33 46 71.7 %
Date: 2017-09-22 00:04:37 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /*
       2             :  * Adobe Filmstrip demuxer
       3             :  * Copyright (c) 2010 Peter Ross
       4             :  *
       5             :  * This file is part of FFmpeg.
       6             :  *
       7             :  * FFmpeg is free software; you can redistribute it and/or
       8             :  * modify it under the terms of the GNU Lesser General Public
       9             :  * License as published by the Free Software Foundation; either
      10             :  * version 2.1 of the License, or (at your option) any later version.
      11             :  *
      12             :  * FFmpeg is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :  * Lesser General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU Lesser General Public
      18             :  * License along with FFmpeg; if not, write to the Free Software
      19             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      20             :  */
      21             : 
      22             : /**
      23             :  * @file
      24             :  * Adobe Filmstrip demuxer
      25             :  */
      26             : 
      27             : #include "libavutil/intreadwrite.h"
      28             : #include "libavutil/imgutils.h"
      29             : #include "avformat.h"
      30             : #include "internal.h"
      31             : 
      32             : #define RAND_TAG MKBETAG('R','a','n','d')
      33             : 
      34             : typedef struct FilmstripDemuxContext {
      35             :     int leading;
      36             : } FilmstripDemuxContext;
      37             : 
      38           1 : static int read_header(AVFormatContext *s)
      39             : {
      40           1 :     FilmstripDemuxContext *film = s->priv_data;
      41           1 :     AVIOContext *pb = s->pb;
      42             :     AVStream *st;
      43             : 
      44           1 :     if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL))
      45           0 :         return AVERROR(EIO);
      46             : 
      47           1 :     avio_seek(pb, avio_size(pb) - 36, SEEK_SET);
      48           1 :     if (avio_rb32(pb) != RAND_TAG) {
      49           0 :         av_log(s, AV_LOG_ERROR, "magic number not found\n");
      50           0 :         return AVERROR_INVALIDDATA;
      51             :     }
      52             : 
      53           1 :     st = avformat_new_stream(s, NULL);
      54           1 :     if (!st)
      55           0 :         return AVERROR(ENOMEM);
      56             : 
      57           1 :     st->nb_frames = avio_rb32(pb);
      58           1 :     if (avio_rb16(pb) != 0) {
      59           0 :         avpriv_request_sample(s, "Unsupported packing method");
      60           0 :         return AVERROR_PATCHWELCOME;
      61             :     }
      62             : 
      63           1 :     avio_skip(pb, 2);
      64           1 :     st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
      65           1 :     st->codecpar->codec_id   = AV_CODEC_ID_RAWVIDEO;
      66           1 :     st->codecpar->format     = AV_PIX_FMT_RGBA;
      67           1 :     st->codecpar->codec_tag  = 0; /* no fourcc */
      68           1 :     st->codecpar->width      = avio_rb16(pb);
      69           1 :     st->codecpar->height     = avio_rb16(pb);
      70           1 :     film->leading         = avio_rb16(pb);
      71             : 
      72           1 :     if (av_image_check_size(st->codecpar->width, st->codecpar->height, 0, s) < 0)
      73           0 :         return AVERROR_INVALIDDATA;
      74             : 
      75           1 :     avpriv_set_pts_info(st, 64, 1, avio_rb16(pb));
      76             : 
      77           1 :     avio_seek(pb, 0, SEEK_SET);
      78             : 
      79           1 :     return 0;
      80             : }
      81             : 
      82          27 : static int read_packet(AVFormatContext *s,
      83             :                        AVPacket *pkt)
      84             : {
      85          27 :     FilmstripDemuxContext *film = s->priv_data;
      86          27 :     AVStream *st = s->streams[0];
      87             : 
      88          27 :     if (avio_feof(s->pb))
      89           1 :         return AVERROR(EIO);
      90          26 :     pkt->dts = avio_tell(s->pb) / (st->codecpar->width * (int64_t)(st->codecpar->height + film->leading) * 4);
      91          26 :     pkt->size = av_get_packet(s->pb, pkt, st->codecpar->width * st->codecpar->height * 4);
      92          26 :     avio_skip(s->pb, st->codecpar->width * (int64_t) film->leading * 4);
      93          26 :     if (pkt->size < 0)
      94           0 :         return pkt->size;
      95          26 :     pkt->flags |= AV_PKT_FLAG_KEY;
      96          26 :     return 0;
      97             : }
      98             : 
      99           0 : static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
     100             : {
     101           0 :     AVStream *st = s->streams[stream_index];
     102           0 :     if (avio_seek(s->pb, FFMAX(timestamp, 0) * st->codecpar->width * st->codecpar->height * 4, SEEK_SET) < 0)
     103           0 :         return -1;
     104           0 :     return 0;
     105             : }
     106             : 
     107             : AVInputFormat ff_filmstrip_demuxer = {
     108             :     .name           = "filmstrip",
     109             :     .long_name      = NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
     110             :     .priv_data_size = sizeof(FilmstripDemuxContext),
     111             :     .read_header    = read_header,
     112             :     .read_packet    = read_packet,
     113             :     .read_seek      = read_seek,
     114             :     .extensions     = "flm",
     115             : };

Generated by: LCOV version 1.13