LCOV - code coverage report
Current view: top level - libavformat - g729dec.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 32 0.0 %
Date: 2017-12-18 13:19:42 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :  * G.729 raw format demuxer
       3             :  * Copyright (c) 2011 Vladimir Voroshilov
       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/log.h"
      23             : #include "libavutil/opt.h"
      24             : 
      25             : #include "avformat.h"
      26             : #include "internal.h"
      27             : 
      28             : typedef struct G729DemuxerContext {
      29             :     AVClass *class;
      30             : 
      31             :     int bit_rate;
      32             : } G729DemuxerContext;
      33             : 
      34           0 : static int g729_read_header(AVFormatContext *s)
      35             : {
      36             :     AVStream* st;
      37           0 :     G729DemuxerContext *s1 = s->priv_data;
      38             : 
      39           0 :     st = avformat_new_stream(s, NULL);
      40           0 :     if (!st)
      41           0 :         return AVERROR(ENOMEM);
      42             : 
      43           0 :     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
      44           0 :     st->codecpar->codec_id    = AV_CODEC_ID_G729;
      45           0 :     st->codecpar->sample_rate = 8000;
      46           0 :     st->codecpar->channels    = 1;
      47             : 
      48           0 :     if (s1 && s1->bit_rate)
      49           0 :         s->bit_rate = s1->bit_rate;
      50             : 
      51           0 :     switch(s->bit_rate) {
      52           0 :     case 6400:
      53           0 :         st->codecpar->block_align = 8;
      54           0 :         break;
      55           0 :     case 8000:
      56           0 :         st->codecpar->block_align = 10;
      57           0 :         break;
      58           0 :     default:
      59           0 :         av_log(s, AV_LOG_ERROR, "Invalid bit_rate value %"PRId64". "
      60             :                "Only 6400 and 8000 b/s are supported.", s->bit_rate);
      61           0 :         return AVERROR(EINVAL);
      62             :     }
      63             : 
      64           0 :     avpriv_set_pts_info(st, st->codecpar->block_align << 3, 1,
      65           0 :                         st->codecpar->sample_rate);
      66             : 
      67           0 :     return 0;
      68             : }
      69             : 
      70           0 : static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
      71             : {
      72           0 :     AVStream *st = s->streams[0];
      73           0 :     int ret = av_get_packet(s->pb, pkt, st->codecpar->block_align);
      74           0 :     if (ret < 0)
      75           0 :         return ret;
      76             : 
      77           0 :     pkt->stream_index = 0;
      78           0 :     pkt->dts = pkt->pts = pkt->pos / st->codecpar->block_align;
      79             : 
      80           0 :     return 0;
      81             : }
      82             : 
      83             : #define OFFSET(x) offsetof(G729DemuxerContext, x)
      84             : static const AVOption g729_options[] = {
      85             :     { "bit_rate", "", OFFSET(bit_rate), AV_OPT_TYPE_INT, { .i64 = 8000 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
      86             :     { NULL },
      87             : };
      88             : 
      89             : static const AVClass g729_demuxer_class = {
      90             :     .class_name = "g729 demuxer",
      91             :     .item_name  = av_default_item_name,
      92             :     .option     = g729_options,
      93             :     .version    = LIBAVUTIL_VERSION_INT,
      94             : };
      95             : 
      96             : AVInputFormat ff_g729_demuxer = {
      97             :     .name           = "g729",
      98             :     .long_name      = NULL_IF_CONFIG_SMALL("G.729 raw format demuxer"),
      99             :     .priv_data_size = sizeof(G729DemuxerContext),
     100             :     .read_header    = g729_read_header,
     101             :     .read_packet    = g729_read_packet,
     102             :     .flags          = AVFMT_GENERIC_INDEX,
     103             :     .extensions     = "g729",
     104             :     .priv_class     = &g729_demuxer_class,
     105             : };

Generated by: LCOV version 1.13