LCOV - code coverage report
Current view: top level - src/libavformat - eacdata.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 33 40 82.5 %
Date: 2017-08-17 10:06:07 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Electronic Arts .cdata file Demuxer
       3             :  * Copyright (c) 2007 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             :  * Electronic Arts cdata Format Demuxer
      25             :  * by Peter Ross (pross@xvid.org)
      26             :  *
      27             :  * Technical details here:
      28             :  *  http://wiki.multimedia.cx/index.php?title=EA_Command_And_Conquer_3_Audio_Codec
      29             :  */
      30             : 
      31             : #include "avformat.h"
      32             : #include "internal.h"
      33             : 
      34             : typedef struct CdataDemuxContext {
      35             :   unsigned int channels;
      36             :   unsigned int audio_pts;
      37             : } CdataDemuxContext;
      38             : 
      39        5978 : static int cdata_probe(AVProbeData *p)
      40             : {
      41        5978 :     const uint8_t *b = p->buf;
      42             : 
      43        5978 :     if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C || b[1] == 0x14))
      44         163 :         return AVPROBE_SCORE_MAX/8;
      45        5815 :     return 0;
      46             : }
      47             : 
      48           1 : static int cdata_read_header(AVFormatContext *s)
      49             : {
      50           1 :     CdataDemuxContext *cdata = s->priv_data;
      51           1 :     AVIOContext *pb = s->pb;
      52             :     unsigned int sample_rate, header;
      53             :     AVStream *st;
      54           1 :     int64_t channel_layout = 0;
      55             : 
      56           1 :     header = avio_rb16(pb);
      57           1 :     switch (header) {
      58           1 :         case 0x0400: cdata->channels = 1; break;
      59           0 :         case 0x0404: cdata->channels = 2; break;
      60           0 :         case 0x040C: cdata->channels = 4; channel_layout = AV_CH_LAYOUT_QUAD;         break;
      61           0 :         case 0x0414: cdata->channels = 6; channel_layout = AV_CH_LAYOUT_5POINT1_BACK; break;
      62           0 :         default:
      63           0 :             av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
      64           0 :             return -1;
      65             :     };
      66             : 
      67           1 :     sample_rate = avio_rb16(pb);
      68           1 :     avio_skip(pb, (avio_r8(pb) & 0x20) ? 15 : 11);
      69             : 
      70           1 :     st = avformat_new_stream(s, NULL);
      71           1 :     if (!st)
      72           0 :         return AVERROR(ENOMEM);
      73           1 :     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
      74           1 :     st->codecpar->codec_tag = 0; /* no fourcc */
      75           1 :     st->codecpar->codec_id = AV_CODEC_ID_ADPCM_EA_XAS;
      76           1 :     st->codecpar->channels = cdata->channels;
      77           1 :     st->codecpar->channel_layout = channel_layout;
      78           1 :     st->codecpar->sample_rate = sample_rate;
      79           1 :     avpriv_set_pts_info(st, 64, 1, sample_rate);
      80             : 
      81           1 :     cdata->audio_pts = 0;
      82           1 :     return 0;
      83             : }
      84             : 
      85         601 : static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt)
      86             : {
      87         601 :     CdataDemuxContext *cdata = s->priv_data;
      88         601 :     int packet_size = 76*cdata->channels;
      89             : 
      90         601 :     int ret = av_get_packet(s->pb, pkt, packet_size);
      91         601 :     if (ret < 0)
      92           1 :         return ret;
      93         600 :     pkt->pts = cdata->audio_pts++;
      94         600 :     return 0;
      95             : }
      96             : 
      97             : AVInputFormat ff_ea_cdata_demuxer = {
      98             :     .name           = "ea_cdata",
      99             :     .long_name      = NULL_IF_CONFIG_SMALL("Electronic Arts cdata"),
     100             :     .priv_data_size = sizeof(CdataDemuxContext),
     101             :     .read_probe     = cdata_probe,
     102             :     .read_header    = cdata_read_header,
     103             :     .read_packet    = cdata_read_packet,
     104             :     .extensions = "cdata",
     105             : };

Generated by: LCOV version 1.13