Browse code

Add an AAC encoder by using the libvo-aacenc library

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

Martin Storsjö authored on 2010/12/20 04:40:23
Showing 7 changed files
... ...
@@ -83,6 +83,7 @@ version <next>:
83 83
 - Linux framebuffer input device added
84 84
 - Chronomaster DFA decoder
85 85
 - Mobotix MxPEG decoder
86
+- AAC encoding via libvo-aacenc
86 87
 
87 88
 
88 89
 version 0.6:
... ...
@@ -178,6 +178,7 @@ External library support:
178 178
   --enable-libschroedinger enable Dirac support via libschroedinger [no]
179 179
   --enable-libspeex        enable Speex decoding via libspeex [no]
180 180
   --enable-libtheora       enable Theora encoding via libtheora [no]
181
+  --enable-libvo-aacenc    enable AAC encoding via libvo-aacenc [no]
181 182
   --enable-libvorbis       enable Vorbis encoding via libvorbis,
182 183
                            native implementation exists [no]
183 184
   --enable-libvpx          enable VP8 support via libvpx [no]
... ...
@@ -937,6 +938,7 @@ CONFIG_LIST="
937 937
     libschroedinger
938 938
     libspeex
939 939
     libtheora
940
+    libvo_aacenc
940 941
     libvorbis
941 942
     libvpx
942 943
     libx264
... ...
@@ -1384,6 +1386,7 @@ libschroedinger_decoder_deps="libschroedinger"
1384 1384
 libschroedinger_encoder_deps="libschroedinger"
1385 1385
 libspeex_decoder_deps="libspeex"
1386 1386
 libtheora_encoder_deps="libtheora"
1387
+libvo_aacenc_encoder_deps="libvo_aacenc"
1387 1388
 libvorbis_encoder_deps="libvorbis"
1388 1389
 libvpx_decoder_deps="libvpx"
1389 1390
 libvpx_encoder_deps="libvpx"
... ...
@@ -2525,6 +2528,7 @@ die_license_disabled nonfree libfaac
2525 2525
 
2526 2526
 die_license_disabled version3 libopencore_amrnb
2527 2527
 die_license_disabled version3 libopencore_amrwb
2528
+die_license_disabled version3 libvo_aacenc
2528 2529
 
2529 2530
 enabled version3 && { enabled gpl && enable gplv3 || enable lgplv3; }
2530 2531
 
... ...
@@ -2864,6 +2868,7 @@ enabled librtmp    && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
2864 2864
 enabled libschroedinger && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init
2865 2865
 enabled libspeex   && require  libspeex speex/speex.h speex_decoder_init -lspeex
2866 2866
 enabled libtheora  && require  libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg
2867
+enabled libvo_aacenc && require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -lvo-aacenc
2867 2868
 enabled libvorbis  && require  libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
2868 2869
 enabled libvpx     && {
2869 2870
     enabled libvpx_decoder && { check_lib2 "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_dec_init_ver -lvpx ||
... ...
@@ -3132,6 +3137,7 @@ echo "libschroedinger enabled   ${libschroedinger-no}"
3132 3132
 echo "libspeex enabled          ${libspeex-no}"
3133 3133
 echo "libtheora enabled         ${libtheora-no}"
3134 3134
 echo "libva enabled             ${vaapi-no}"
3135
+echo "libvo-aacenc support      ${libvo_aacenc-no}"
3135 3136
 echo "libvorbis enabled         ${libvorbis-no}"
3136 3137
 echo "libvpx enabled            ${libvpx-no}"
3137 3138
 echo "libx264 enabled           ${libx264-no}"
... ...
@@ -540,7 +540,7 @@ following image formats are supported:
540 540
 @item Name @tab Encoding @tab Decoding @tab Comments
541 541
 @item 8SVX audio             @tab     @tab  X
542 542
 @item AAC                    @tab  E  @tab  X
543
-    @tab encoding supported through external library libfaac
543
+    @tab encoding supported through external library libfaac and libvo-aacenc
544 544
 @item AC-3                   @tab IX  @tab  X
545 545
 @item ADPCM 4X Movie         @tab     @tab  X
546 546
 @item ADPCM CDROM XA         @tab     @tab  X
... ...
@@ -568,6 +568,7 @@ OBJS-$(CONFIG_LIBSCHROEDINGER_ENCODER)    += libschroedingerenc.o \
568 568
                                              libdirac_libschro.o
569 569
 OBJS-$(CONFIG_LIBSPEEX_DECODER)           += libspeexdec.o
570 570
 OBJS-$(CONFIG_LIBTHEORA_ENCODER)          += libtheoraenc.o
571
+OBJS-$(CONFIG_LIBVO_AACENC_ENCODER)       += libvo-aacenc.o mpeg4audio.o
571 572
 OBJS-$(CONFIG_LIBVORBIS_ENCODER)          += libvorbis.o vorbis_data.o
572 573
 OBJS-$(CONFIG_LIBVPX_DECODER)             += libvpxdec.o
573 574
 OBJS-$(CONFIG_LIBVPX_ENCODER)             += libvpxenc.o
... ...
@@ -366,6 +366,7 @@ void avcodec_register_all(void)
366 366
     REGISTER_ENCDEC  (LIBSCHROEDINGER, libschroedinger);
367 367
     REGISTER_DECODER (LIBSPEEX, libspeex);
368 368
     REGISTER_ENCODER (LIBTHEORA, libtheora);
369
+    REGISTER_ENCODER (LIBVO_AACENC, libvo_aacenc);
369 370
     REGISTER_ENCODER (LIBVORBIS, libvorbis);
370 371
     REGISTER_ENCDEC  (LIBVPX, libvpx);
371 372
     REGISTER_ENCODER (LIBX264, libx264);
372 373
new file mode 100644
... ...
@@ -0,0 +1,128 @@
0
+/*
1
+ * AAC encoder wrapper
2
+ * Copyright (c) 2010 Martin Storsjo
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 <vo-aacenc/voAAC.h>
22
+#include <vo-aacenc/cmnMemory.h>
23
+
24
+#include "avcodec.h"
25
+#include "mpeg4audio.h"
26
+
27
+typedef struct AACContext {
28
+    VO_AUDIO_CODECAPI codec_api;
29
+    VO_HANDLE handle;
30
+    VO_MEM_OPERATOR mem_operator;
31
+    VO_CODEC_INIT_USERDATA user_data;
32
+} AACContext;
33
+
34
+static av_cold int aac_encode_init(AVCodecContext *avctx)
35
+{
36
+    AACContext *s = avctx->priv_data;
37
+    AACENC_PARAM params = { 0 };
38
+    int index;
39
+
40
+    avctx->coded_frame = avcodec_alloc_frame();
41
+    avctx->frame_size = 1024;
42
+
43
+    voGetAACEncAPI(&s->codec_api);
44
+
45
+    s->mem_operator.Alloc = cmnMemAlloc;
46
+    s->mem_operator.Copy = cmnMemCopy;
47
+    s->mem_operator.Free = cmnMemFree;
48
+    s->mem_operator.Set = cmnMemSet;
49
+    s->mem_operator.Check = cmnMemCheck;
50
+    s->user_data.memflag = VO_IMF_USERMEMOPERATOR;
51
+    s->user_data.memData = &s->mem_operator;
52
+    s->codec_api.Init(&s->handle, VO_AUDIO_CodingAAC, &s->user_data);
53
+
54
+    params.sampleRate = avctx->sample_rate;
55
+    params.bitRate    = avctx->bit_rate;
56
+    params.nChannels  = avctx->channels;
57
+    params.adtsUsed   = !(avctx->flags & CODEC_FLAG_GLOBAL_HEADER);
58
+    if (s->codec_api.SetParam(s->handle, VO_PID_AAC_ENCPARAM, &params)
59
+        != VO_ERR_NONE) {
60
+        av_log(avctx, AV_LOG_ERROR, "Unable to set encoding parameters\n");
61
+        return AVERROR_UNKNOWN;
62
+    }
63
+
64
+    avctx->extradata_size = 2;
65
+    avctx->extradata      = av_mallocz(avctx->extradata_size +
66
+                                       FF_INPUT_BUFFER_PADDING_SIZE);
67
+    if (!avctx->extradata)
68
+        return AVERROR(ENOMEM);
69
+
70
+    for (index = 0; index < 16; index++)
71
+        if (avctx->sample_rate == ff_mpeg4audio_sample_rates[index])
72
+            break;
73
+    if (index == 16) {
74
+        av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n",
75
+                                    avctx->sample_rate);
76
+        return AVERROR_NOTSUPP;
77
+    }
78
+    avctx->extradata[0] = 0x02 << 3 | index >> 1;
79
+    avctx->extradata[1] = (index & 0x01) << 7 | avctx->channels << 3;
80
+    return 0;
81
+}
82
+
83
+static int aac_encode_close(AVCodecContext *avctx)
84
+{
85
+    AACContext *s = avctx->priv_data;
86
+
87
+    s->codec_api.Uninit(s->handle);
88
+    av_freep(&avctx->coded_frame);
89
+
90
+    return 0;
91
+}
92
+
93
+static int aac_encode_frame(AVCodecContext *avctx,
94
+                            unsigned char *frame/*out*/,
95
+                            int buf_size, void *data/*in*/)
96
+{
97
+    AACContext *s = avctx->priv_data;
98
+    VO_CODECBUFFER input = { 0 }, output = { 0 };
99
+    VO_AUDIO_OUTPUTINFO output_info = { { 0 } };
100
+
101
+    input.Buffer = data;
102
+    input.Length = 2 * avctx->channels * avctx->frame_size;
103
+    output.Buffer = frame;
104
+    output.Length = buf_size;
105
+
106
+    s->codec_api.SetInputData(s->handle, &input);
107
+    if (s->codec_api.GetOutputData(s->handle, &output, &output_info)
108
+        != VO_ERR_NONE) {
109
+        av_log(avctx, AV_LOG_ERROR, "Unable to encode frame\n");
110
+        return AVERROR_UNKNOWN;
111
+    }
112
+    return output.Length;
113
+}
114
+
115
+AVCodec ff_libvo_aacenc_encoder = {
116
+    "libvo_aacenc",
117
+    CODEC_TYPE_AUDIO,
118
+    CODEC_ID_AAC,
119
+    sizeof(AACContext),
120
+    aac_encode_init,
121
+    aac_encode_frame,
122
+    aac_encode_close,
123
+    NULL,
124
+    .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
125
+    .long_name = NULL_IF_CONFIG_SMALL("libvo-aacenc AAC"),
126
+};
127
+
... ...
@@ -21,8 +21,8 @@
21 21
 #define AVCODEC_VERSION_H
22 22
 
23 23
 #define LIBAVCODEC_VERSION_MAJOR 52
24
-#define LIBAVCODEC_VERSION_MINOR 117
25
-#define LIBAVCODEC_VERSION_MICRO  1
24
+#define LIBAVCODEC_VERSION_MINOR 118
25
+#define LIBAVCODEC_VERSION_MICRO  0
26 26
 
27 27
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
28 28
                                                LIBAVCODEC_VERSION_MINOR, \