FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
g729dec.c
Go to the documentation of this file.
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 "avformat.h"
23 #include "internal.h"
24 #include "libavutil/log.h"
25 #include "libavutil/opt.h"
26 
27 typedef struct G729DemuxerContext {
28  AVClass *class;
29  int bit_rate;
31 
33 {
34  AVStream* st;
36 
37  st = avformat_new_stream(s, NULL);
38  if (!st)
39  return AVERROR(ENOMEM);
40 
43  st->codec->sample_rate = 8000;
44  st->codec->channels = 1;
45 
46  if (s1 && s1->bit_rate) {
47  s->bit_rate = s1->bit_rate;
48  }
49 
50  if (s->bit_rate == 0) {
51  av_log(s, AV_LOG_DEBUG, "No bitrate specified. Assuming 8000 b/s\n");
52  s->bit_rate = 8000;
53  }
54 
55  if (s->bit_rate == 6400) {
56  st->codec->block_align = 8;
57  } else if (s->bit_rate == 8000) {
58  st->codec->block_align = 10;
59  } else {
60  av_log(s, AV_LOG_ERROR, "Only 8000 b/s and 6400 b/s bitrates are supported. Provided: %d b/s\n", s->bit_rate);
61  return AVERROR_INVALIDDATA;
62  }
63 
64  avpriv_set_pts_info(st, st->codec->block_align << 3, 1, st->codec->sample_rate);
65  return 0;
66 }
68 {
69  int ret;
70 
71  ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align);
72 
73  pkt->stream_index = 0;
74  if (ret < 0)
75  return ret;
76 
77  pkt->dts = pkt->pts = pkt->pos / s->streams[0]->codec->block_align;
78 
79  return ret;
80 }
81 
82 static const AVOption g729_options[] = {
83  { "bit_rate", "", offsetof(G729DemuxerContext, bit_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
84  { NULL },
85 };
86 
87 static const AVClass g729_demuxer_class = {
88  .class_name = "g729 demuxer",
89  .item_name = av_default_item_name,
90  .option = g729_options,
91  .version = LIBAVUTIL_VERSION_INT,
92 };
93 
95  .name = "g729",
96  .long_name = NULL_IF_CONFIG_SMALL("G.729 raw format demuxer"),
97  .priv_data_size = sizeof(G729DemuxerContext),
101  .extensions = "g729",
102  .priv_class = &g729_demuxer_class,
103 };