Browse code

lavf: Raw G.729 demuxer

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>

Vladimir Voroshilov authored on 2016/03/20 06:48:39
Showing 5 changed files
... ...
@@ -56,6 +56,7 @@ version <next>:
56 56
 - VAAPI-accelerate H.264/HEVC/MJPEG encoding
57 57
 - Generic OpenMAX IL encoder with support for Raspberry Pi
58 58
 - MMAL-accelerated MPEG-2 and VC-1 decoding
59
+- G.729 raw demuxer
59 60
 
60 61
 
61 62
 version 11:
... ...
@@ -140,6 +140,7 @@ OBJS-$(CONFIG_G722_DEMUXER)              += g722.o rawdec.o
140 140
 OBJS-$(CONFIG_G722_MUXER)                += rawenc.o
141 141
 OBJS-$(CONFIG_G723_1_DEMUXER)            += g723_1.o
142 142
 OBJS-$(CONFIG_G723_1_MUXER)              += rawenc.o
143
+OBJS-$(CONFIG_G729_DEMUXER)              += g729dec.o
143 144
 OBJS-$(CONFIG_GIF_MUXER)                 += gif.o
144 145
 OBJS-$(CONFIG_GSM_DEMUXER)               += gsmdec.o
145 146
 OBJS-$(CONFIG_GXF_DEMUXER)               += gxf.o
... ...
@@ -105,6 +105,7 @@ void av_register_all(void)
105 105
     REGISTER_MUXER   (FRAMEMD5,         framemd5);
106 106
     REGISTER_MUXDEMUX(G722,             g722);
107 107
     REGISTER_MUXDEMUX(G723_1,           g723_1);
108
+    REGISTER_DEMUXER (G729,             g729);
108 109
     REGISTER_MUXER   (GIF,              gif);
109 110
     REGISTER_DEMUXER (GSM,              gsm);
110 111
     REGISTER_MUXDEMUX(GXF,              gxf);
111 112
new file mode 100644
... ...
@@ -0,0 +1,105 @@
0
+/*
1
+ * G.729 raw format demuxer
2
+ * Copyright (c) 2011 Vladimir Voroshilov
3
+ *
4
+ * This file is part of Libav.
5
+ *
6
+ * Libav is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * Libav is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with Libav; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#include "libavutil/log.h"
22
+#include "libavutil/opt.h"
23
+
24
+#include "avformat.h"
25
+#include "internal.h"
26
+
27
+typedef struct G729DemuxerContext {
28
+    AVClass *class;
29
+
30
+    int bit_rate;
31
+} G729DemuxerContext;
32
+
33
+static int g729_read_header(AVFormatContext *s)
34
+{
35
+    AVStream* st;
36
+    G729DemuxerContext *s1 = s->priv_data;
37
+
38
+    st = avformat_new_stream(s, NULL);
39
+    if (!st)
40
+        return AVERROR(ENOMEM);
41
+
42
+    st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
43
+    st->codecpar->codec_id    = AV_CODEC_ID_G729;
44
+    st->codecpar->sample_rate = 8000;
45
+    st->codecpar->channels    = 1;
46
+
47
+    if (s1 && s1->bit_rate)
48
+        s->bit_rate = s1->bit_rate;
49
+
50
+    switch(s->bit_rate) {
51
+    case 6400:
52
+        st->codecpar->block_align = 8;
53
+        break;
54
+    case 8000:
55
+        st->codecpar->block_align = 10;
56
+        break;
57
+    default:
58
+        av_log(s, AV_LOG_ERROR, "Invalid bit_rate value %d. "
59
+               "Only 6400 and 8000 b/s are supported.", s->bit_rate);
60
+        return AVERROR(EINVAL);
61
+    }
62
+
63
+    avpriv_set_pts_info(st, st->codecpar->block_align << 3, 1,
64
+                        st->codecpar->sample_rate);
65
+
66
+    return 0;
67
+}
68
+
69
+static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
70
+{
71
+    AVStream *st = s->streams[0];
72
+    int ret = av_get_packet(s->pb, pkt, st->codecpar->block_align);
73
+    if (ret < 0)
74
+        return ret;
75
+
76
+    pkt->stream_index = 0;
77
+    pkt->dts = pkt->pts = pkt->pos / st->codecpar->block_align;
78
+
79
+    return 0;
80
+}
81
+
82
+#define OFFSET(x) offsetof(G729DemuxerContext, x)
83
+static const AVOption g729_options[] = {
84
+    { "bit_rate", "", OFFSET(bit_rate), AV_OPT_TYPE_INT, { .i64 = 8000 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
85
+    { NULL },
86
+};
87
+
88
+static const AVClass g729_demuxer_class = {
89
+    .class_name = "g729 demuxer",
90
+    .item_name  = av_default_item_name,
91
+    .option     = g729_options,
92
+    .version    = LIBAVUTIL_VERSION_INT,
93
+};
94
+
95
+AVInputFormat ff_g729_demuxer = {
96
+    .name           = "g729",
97
+    .long_name      = NULL_IF_CONFIG_SMALL("G.729 raw format demuxer"),
98
+    .priv_data_size = sizeof(G729DemuxerContext),
99
+    .read_header    = g729_read_header,
100
+    .read_packet    = g729_read_packet,
101
+    .flags          = AVFMT_GENERIC_INDEX,
102
+    .extensions     = "g729",
103
+    .priv_class     = &g729_demuxer_class,
104
+};
... ...
@@ -30,8 +30,8 @@
30 30
 #include "libavutil/version.h"
31 31
 
32 32
 #define LIBAVFORMAT_VERSION_MAJOR 57
33
-#define LIBAVFORMAT_VERSION_MINOR  5
34
-#define LIBAVFORMAT_VERSION_MICRO  2
33
+#define LIBAVFORMAT_VERSION_MINOR  6
34
+#define LIBAVFORMAT_VERSION_MICRO  0
35 35
 
36 36
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
37 37
                                                LIBAVFORMAT_VERSION_MINOR, \