Browse code

rtpdec: Add support for G726 audio

This requires using a separate init function, since there
isn't necessarily any fmtp lines for this codec, so
parse_sdp_a_line won't be called. Incorporating it with the
alloc function wouldn't do either, since it is called before
the full rtpmap line is parsed (where the sample rate is
extracted).

Signed-off-by: Martin Storsjö <martin@martin.st>

Miroslav Slugeň authored on 2011/11/07 20:13:55
Showing 4 changed files
... ...
@@ -247,6 +247,7 @@ OBJS-$(CONFIG_RTPDEC)                    += rdt.o         \
247 247
                                             rtpdec.o      \
248 248
                                             rtpdec_amr.o  \
249 249
                                             rtpdec_asf.o  \
250
+                                            rtpdec_g726.o \
250 251
                                             rtpdec_h263.o \
251 252
                                             rtpdec_h264.o \
252 253
                                             rtpdec_latm.o \
... ...
@@ -83,6 +83,11 @@ void av_register_rtp_dynamic_payload_handlers(void)
83 83
     ff_register_dynamic_payload_handler(&ff_qt_rtp_vid_handler);
84 84
     ff_register_dynamic_payload_handler(&ff_quicktime_rtp_aud_handler);
85 85
     ff_register_dynamic_payload_handler(&ff_quicktime_rtp_vid_handler);
86
+
87
+    ff_register_dynamic_payload_handler(&ff_g726_16_dynamic_handler);
88
+    ff_register_dynamic_payload_handler(&ff_g726_24_dynamic_handler);
89
+    ff_register_dynamic_payload_handler(&ff_g726_32_dynamic_handler);
90
+    ff_register_dynamic_payload_handler(&ff_g726_40_dynamic_handler);
86 91
 }
87 92
 
88 93
 RTPDynamicProtocolHandler *ff_rtp_handler_find_by_name(const char *name,
... ...
@@ -33,6 +33,10 @@ int ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p);
33 33
 
34 34
 extern RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler;
35 35
 extern RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler;
36
+extern RTPDynamicProtocolHandler ff_g726_16_dynamic_handler;
37
+extern RTPDynamicProtocolHandler ff_g726_24_dynamic_handler;
38
+extern RTPDynamicProtocolHandler ff_g726_32_dynamic_handler;
39
+extern RTPDynamicProtocolHandler ff_g726_40_dynamic_handler;
36 40
 extern RTPDynamicProtocolHandler ff_h263_1998_dynamic_handler;
37 41
 extern RTPDynamicProtocolHandler ff_h263_2000_dynamic_handler;
38 42
 extern RTPDynamicProtocolHandler ff_h264_dynamic_handler;
39 43
new file mode 100644
... ...
@@ -0,0 +1,102 @@
0
+/*
1
+ * Copyright (c) 2011 Miroslav Slugeň <Thunder.m@seznam.cz>
2
+ *
3
+ * This file is part of Libav.
4
+ *
5
+ * Libav is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * Libav is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with Libav; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+#include "avformat.h"
21
+#include "rtpdec_formats.h"
22
+
23
+static int g726_16_init(AVFormatContext *s, int st_index, PayloadContext *data)
24
+{
25
+    AVStream *stream = s->streams[st_index];
26
+    AVCodecContext *codec = stream->codec;
27
+
28
+    codec->bit_rate = 16000;
29
+    if (codec->sample_rate)
30
+        codec->bits_per_coded_sample =
31
+            av_clip((codec->bit_rate + codec->sample_rate/2) / codec->sample_rate, 2, 5);
32
+
33
+    return 0;
34
+}
35
+
36
+static int g726_24_init(AVFormatContext *s, int st_index, PayloadContext *data)
37
+{
38
+    AVStream *stream = s->streams[st_index];
39
+    AVCodecContext *codec = stream->codec;
40
+
41
+    codec->bit_rate = 24000;
42
+    if (codec->sample_rate)
43
+        codec->bits_per_coded_sample =
44
+            av_clip((codec->bit_rate + codec->sample_rate/2) / codec->sample_rate, 2, 5);
45
+
46
+    return 0;
47
+}
48
+
49
+static int g726_32_init(AVFormatContext *s, int st_index, PayloadContext *data)
50
+{
51
+    AVStream *stream = s->streams[st_index];
52
+    AVCodecContext *codec = stream->codec;
53
+
54
+    codec->bit_rate = 32000;
55
+    if (codec->sample_rate)
56
+        codec->bits_per_coded_sample =
57
+            av_clip((codec->bit_rate + codec->sample_rate/2) / codec->sample_rate, 2, 5);
58
+
59
+    return 0;
60
+}
61
+
62
+static int g726_40_init(AVFormatContext *s, int st_index, PayloadContext *data)
63
+{
64
+    AVStream *stream = s->streams[st_index];
65
+    AVCodecContext *codec = stream->codec;
66
+
67
+    codec->bit_rate = 40000;
68
+    if (codec->sample_rate)
69
+        codec->bits_per_coded_sample =
70
+            av_clip((codec->bit_rate + codec->sample_rate/2) / codec->sample_rate, 2, 5);
71
+
72
+    return 0;
73
+}
74
+
75
+RTPDynamicProtocolHandler ff_g726_16_dynamic_handler = {
76
+    .enc_name   = "G726-16",
77
+    .codec_type = AVMEDIA_TYPE_AUDIO,
78
+    .codec_id   = CODEC_ID_ADPCM_G726,
79
+    .init       = g726_16_init,
80
+};
81
+
82
+RTPDynamicProtocolHandler ff_g726_24_dynamic_handler = {
83
+    .enc_name   = "G726-24",
84
+    .codec_type = AVMEDIA_TYPE_AUDIO,
85
+    .codec_id   = CODEC_ID_ADPCM_G726,
86
+    .init       = g726_24_init,
87
+};
88
+
89
+RTPDynamicProtocolHandler ff_g726_32_dynamic_handler = {
90
+    .enc_name   = "G726-32",
91
+    .codec_type = AVMEDIA_TYPE_AUDIO,
92
+    .codec_id   = CODEC_ID_ADPCM_G726,
93
+    .init       = g726_32_init,
94
+};
95
+
96
+RTPDynamicProtocolHandler ff_g726_40_dynamic_handler = {
97
+    .enc_name   = "G726-40",
98
+    .codec_type = AVMEDIA_TYPE_AUDIO,
99
+    .codec_id   = CODEC_ID_ADPCM_G726,
100
+    .init       = g726_40_init,
101
+};