LCOV - code coverage report
Current view: top level - src/libavformat - aixdec.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 77 3.9 %
Date: 2017-01-23 11:54:22 Functions: 1 3 33.3 %

          Line data    Source code
       1             : /*
       2             :  * AIX demuxer
       3             :  * Copyright (c) 2016 Paul B Mahol
       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             : #include "libavutil/intreadwrite.h"
      23             : #include "avformat.h"
      24             : #include "internal.h"
      25             : 
      26        5563 : static int aix_probe(AVProbeData *p)
      27             : {
      28        5563 :     if (AV_RL32(p->buf) != MKTAG('A','I','X','F') ||
      29           0 :         AV_RB32(p->buf +  8) != 0x01000014 ||
      30           0 :         AV_RB32(p->buf + 12) != 0x00000800)
      31        5563 :         return 0;
      32             : 
      33           0 :     return AVPROBE_SCORE_MAX;
      34             : }
      35             : 
      36           0 : static int aix_read_header(AVFormatContext *s)
      37             : {
      38             :     unsigned nb_streams, first_offset, nb_segments;
      39             :     unsigned stream_list_offset;
      40           0 :     unsigned segment_list_offset = 0x20;
      41           0 :     unsigned segment_list_entry_size = 0x10;
      42             :     unsigned size;
      43             :     int i;
      44             : 
      45           0 :     avio_skip(s->pb, 4);
      46           0 :     first_offset = avio_rb32(s->pb) + 8;
      47           0 :     avio_skip(s->pb, 16);
      48           0 :     nb_segments = avio_rb16(s->pb);
      49           0 :     if (nb_segments == 0)
      50           0 :         return AVERROR_INVALIDDATA;
      51           0 :     stream_list_offset = segment_list_offset + segment_list_entry_size * nb_segments + 0x10;
      52           0 :     if (stream_list_offset >= first_offset)
      53           0 :         return AVERROR_INVALIDDATA;
      54           0 :     avio_seek(s->pb, stream_list_offset, SEEK_SET);
      55           0 :     nb_streams = avio_r8(s->pb);
      56           0 :     if (nb_streams == 0)
      57           0 :         return AVERROR_INVALIDDATA;
      58           0 :     avio_skip(s->pb, 7);
      59           0 :     for (i = 0; i < nb_streams; i++) {
      60           0 :         AVStream *st = avformat_new_stream(s, NULL);
      61             : 
      62           0 :         if (!st)
      63           0 :             return AVERROR(ENOMEM);
      64           0 :         st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
      65           0 :         st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_ADX;
      66           0 :         st->codecpar->sample_rate = avio_rb32(s->pb);
      67           0 :         st->codecpar->channels    = avio_r8(s->pb);
      68           0 :         avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
      69           0 :         avio_skip(s->pb, 3);
      70             :     }
      71             : 
      72           0 :     avio_seek(s->pb, first_offset, SEEK_SET);
      73           0 :     for (i = 0; i < nb_streams; i++) {
      74           0 :         if (avio_rl32(s->pb) != MKTAG('A','I','X','P'))
      75           0 :             return AVERROR_INVALIDDATA;
      76           0 :         size = avio_rb32(s->pb);
      77           0 :         if (size <= 8)
      78           0 :             return AVERROR_INVALIDDATA;
      79           0 :         avio_skip(s->pb, 8);
      80           0 :         ff_get_extradata(s, s->streams[i]->codecpar, s->pb, size - 8);
      81             :     }
      82             : 
      83           0 :     return 0;
      84             : }
      85             : 
      86           0 : static int aix_read_packet(AVFormatContext *s, AVPacket *pkt)
      87             : {
      88             :     unsigned size, index, duration, chunk;
      89             :     int64_t pos;
      90             :     int sequence, ret, i;
      91             : 
      92           0 :     pos = avio_tell(s->pb);
      93           0 :     if (avio_feof(s->pb))
      94           0 :         return AVERROR_EOF;
      95           0 :     chunk = avio_rl32(s->pb);
      96           0 :     size = avio_rb32(s->pb);
      97           0 :     if (chunk == MKTAG('A','I','X','E')) {
      98           0 :         avio_skip(s->pb, size);
      99           0 :         for (i = 0; i < s->nb_streams; i++) {
     100           0 :             if (avio_feof(s->pb))
     101           0 :                 return AVERROR_EOF;
     102           0 :             chunk = avio_rl32(s->pb);
     103           0 :             size = avio_rb32(s->pb);
     104           0 :             avio_skip(s->pb, size);
     105             :         }
     106           0 :         pos = avio_tell(s->pb);
     107           0 :         chunk = avio_rl32(s->pb);
     108           0 :         size = avio_rb32(s->pb);
     109             :     }
     110             : 
     111           0 :     if (chunk != MKTAG('A','I','X','P'))
     112           0 :         return AVERROR_INVALIDDATA;
     113           0 :     if (size <= 8)
     114           0 :         return AVERROR_INVALIDDATA;
     115           0 :     index = avio_r8(s->pb);
     116           0 :     if (avio_r8(s->pb) != s->nb_streams || index >= s->nb_streams)
     117           0 :         return AVERROR_INVALIDDATA;
     118           0 :     duration = avio_rb16(s->pb);
     119           0 :     sequence = avio_rb32(s->pb);
     120           0 :     if (sequence < 0) {
     121           0 :         avio_skip(s->pb, size - 8);
     122           0 :         return 0;
     123             :     }
     124             : 
     125           0 :     ret = av_get_packet(s->pb, pkt, size - 8);
     126           0 :     pkt->stream_index = index;
     127           0 :     pkt->duration = duration;
     128           0 :     pkt->pos = pos;
     129           0 :     return ret;
     130             : }
     131             : 
     132             : AVInputFormat ff_aix_demuxer = {
     133             :     .name        = "aix",
     134             :     .long_name   = NULL_IF_CONFIG_SMALL("CRI AIX"),
     135             :     .read_probe  = aix_probe,
     136             :     .read_header = aix_read_header,
     137             :     .read_packet = aix_read_packet,
     138             :     .extensions  = "aix",
     139             :     .flags       = AVFMT_GENERIC_INDEX,
     140             : };

Generated by: LCOV version 1.12