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