LCOV - code coverage report
Current view: top level - src/libavformat - astdec.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 42 54 77.8 %
Date: 2017-09-22 00:04:37 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * AST demuxer
       3             :  * Copyright (c) 2012 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/channel_layout.h"
      23             : #include "libavutil/intreadwrite.h"
      24             : #include "avformat.h"
      25             : #include "internal.h"
      26             : #include "ast.h"
      27             : 
      28        6034 : static int ast_probe(AVProbeData *p)
      29             : {
      30        6034 :     if (AV_RL32(p->buf) != MKTAG('S','T','R','M'))
      31        6031 :         return 0;
      32             : 
      33           6 :     if (!AV_RB16(p->buf + 10) ||
      34           9 :         !AV_RB16(p->buf + 12) || AV_RB16(p->buf + 12) > 256 ||
      35           6 :         !AV_RB32(p->buf + 16) || AV_RB32(p->buf + 16) > 8*48000)
      36           0 :         return AVPROBE_SCORE_MAX / 8;
      37             : 
      38           3 :     return AVPROBE_SCORE_MAX / 3 * 2;
      39             : }
      40             : 
      41           3 : static int ast_read_header(AVFormatContext *s)
      42             : {
      43             :     int depth;
      44             :     AVStream *st;
      45             : 
      46           3 :     st = avformat_new_stream(s, NULL);
      47           3 :     if (!st)
      48           0 :         return AVERROR(ENOMEM);
      49             : 
      50           3 :     avio_skip(s->pb, 8);
      51           3 :     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
      52           3 :     st->codecpar->codec_id   = ff_codec_get_id(ff_codec_ast_tags, avio_rb16(s->pb));
      53             : 
      54           3 :     depth = avio_rb16(s->pb);
      55           3 :     if (depth != 16) {
      56           0 :         avpriv_request_sample(s, "depth %d", depth);
      57           0 :         return AVERROR_INVALIDDATA;
      58             :     }
      59             : 
      60           3 :     st->codecpar->channels = avio_rb16(s->pb);
      61           3 :     if (!st->codecpar->channels)
      62           0 :         return AVERROR_INVALIDDATA;
      63             : 
      64           3 :     if (st->codecpar->channels == 2)
      65           3 :         st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
      66           0 :     else if (st->codecpar->channels == 4)
      67           0 :         st->codecpar->channel_layout = AV_CH_LAYOUT_4POINT0;
      68             : 
      69           3 :     avio_skip(s->pb, 2);
      70           3 :     st->codecpar->sample_rate = avio_rb32(s->pb);
      71           3 :     if (st->codecpar->sample_rate <= 0)
      72           0 :         return AVERROR_INVALIDDATA;
      73           3 :     st->start_time         = 0;
      74           3 :     st->duration           = avio_rb32(s->pb);
      75           3 :     avio_skip(s->pb, 40);
      76           3 :     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
      77             : 
      78           3 :     return 0;
      79             : }
      80             : 
      81          74 : static int ast_read_packet(AVFormatContext *s, AVPacket *pkt)
      82             : {
      83             :     uint32_t type, size;
      84             :     int64_t pos;
      85             :     int ret;
      86             : 
      87          74 :     if (avio_feof(s->pb))
      88           3 :         return AVERROR_EOF;
      89             : 
      90          71 :     pos  = avio_tell(s->pb);
      91          71 :     type = avio_rl32(s->pb);
      92          71 :     size = avio_rb32(s->pb);
      93          71 :     if (!s->streams[0]->codecpar->channels || size > INT_MAX / s->streams[0]->codecpar->channels)
      94           0 :         return AVERROR_INVALIDDATA;
      95             : 
      96          71 :     size *= s->streams[0]->codecpar->channels;
      97          71 :     if ((ret = avio_skip(s->pb, 24)) < 0) // padding
      98           3 :         return ret;
      99             : 
     100          68 :     if (type == MKTAG('B','L','C','K')) {
     101          68 :         ret = av_get_packet(s->pb, pkt, size);
     102          68 :         pkt->stream_index = 0;
     103          68 :         pkt->pos = pos;
     104             :     } else {
     105           0 :         av_log(s, AV_LOG_ERROR, "unknown chunk %"PRIx32"\n", type);
     106           0 :         avio_skip(s->pb, size);
     107           0 :         ret = AVERROR_INVALIDDATA;
     108             :     }
     109             : 
     110          68 :     return ret;
     111             : }
     112             : 
     113             : AVInputFormat ff_ast_demuxer = {
     114             :     .name           = "ast",
     115             :     .long_name      = NULL_IF_CONFIG_SMALL("AST (Audio Stream)"),
     116             :     .read_probe     = ast_probe,
     117             :     .read_header    = ast_read_header,
     118             :     .read_packet    = ast_read_packet,
     119             :     .extensions     = "ast",
     120             :     .flags          = AVFMT_GENERIC_INDEX,
     121             :     .codec_tag      = (const AVCodecTag* const []){ff_codec_ast_tags, 0},
     122             : };

Generated by: LCOV version 1.13