[FFmpeg-soc] [soc]: r2280 - in aacenc: aac_enc.patch aacenc.c

kostya subversion at mplayerhq.hu
Sat May 31 10:11:18 CEST 2008


Author: kostya
Date: Sat May 31 10:11:18 2008
New Revision: 2280

Log:
Hier ist der Drachen.

Decoder sceleton which can produce dummy AAC files.


Added:
   aacenc/aac_enc.patch
   aacenc/aacenc.c

Added: aacenc/aac_enc.patch
==============================================================================
--- (empty file)
+++ aacenc/aac_enc.patch	Sat May 31 10:11:18 2008
@@ -0,0 +1,140 @@
+diff --git a/libavcodec/Makefile b/libavcodec/Makefile
+index d4f6d1c..0ed9057 100644
+--- a/libavcodec/Makefile
++++ b/libavcodec/Makefile
+@@ -29,6 +29,7 @@ HEADERS = avcodec.h opt.h
+ 
+ OBJS-$(CONFIG_ENCODERS)                += faandct.o jfdctfst.o jfdctint.o
+ 
++OBJS-$(CONFIG_AAC_ENCODER)             += aacenc.o mdct.o fft.o mpeg4audio.o
+ OBJS-$(CONFIG_AASC_DECODER)            += aasc.o
+ OBJS-$(CONFIG_AC3_DECODER)             += ac3dec.o ac3tab.o ac3.o mdct.o fft.o
+ OBJS-$(CONFIG_AC3_ENCODER)             += ac3enc.o ac3tab.o ac3.o
+diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
+new file mode 100644
+index 0000000..1c44007
+--- /dev/null
++++ b/libavcodec/aacenc.c
+@@ -0,0 +1,110 @@
++/*
++ * AAC encoder
++ * Copyright (C) 2008 Konstantin Shishkov
++ *
++ * This file is part of FFmpeg.
++ *
++ * FFmpeg is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU Lesser General Public
++ * License as published by the Free Software Foundation; either
++ * version 2.1 of the License, or (at your option) any later version.
++ *
++ * FFmpeg is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++ * Lesser General Public License for more details.
++ *
++ * You should have received a copy of the GNU Lesser General Public
++ * License along with FFmpeg; if not, write to the Free Software
++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
++ */
++
++/**
++ * @file aacenc.c
++ * AAC encoder
++ */
++
++#include "avcodec.h"
++#include "bitstream.h"
++#include "dsputil.h"
++#include "mpeg4audio.h"
++
++typedef struct {
++    PutBitContext pb;
++    MDCTContext mdct;
++    DECLARE_ALIGNED_16(float, kbd_long_1024[1024]);
++} AACEncContext;
++
++/**
++ * Make AAC audio config object.
++ * @see 1.6.2.1
++ */
++static int put_audio_specific_config(AVCodecContext *avctx)
++{
++    PutBitContext pb;    
++    init_put_bits(&pb, avctx->extradata, avctx->extradata_size*8);
++    put_bits(&pb, 5, 2); //object type - AAC-LC
++    for(i = 0; i < 16; i++)
++        if(avctx->sample_rate == ff_mpeg4audio_sample_rates[i])
++            break;
++    if(i == 16){
++        av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n", avctx->sample_rate);
++        return -1;
++    }
++    put_bits(&pb, 4, i); //sample rate index
++    put_bits(&pb, 4, avctx->channels); //channel config - stereo
++    //GASpecificConfig
++    put_bits(&pb, 1, 0); //frame length - 1024 samples
++    put_bits(&pb, 1, 0); //does not depend on core coder
++    put_bits(&pb, 1, 0); //is not extension
++    flush_put_bits(&pb);
++}
++
++static int aac_encode_init(AVCodecContext *avctx)
++{
++    AACEncContext *c = avctx->priv_data;
++    int i;
++
++    avctx->frame_size = 1024;
++
++    ff_mdct_init(&c->mdct, 11, 1);
++    // windows init
++    ff_kbd_window_init(c->kbd_long_1024, 4.0, 1024);
++
++    // produce AAC audio config object
++    // see 1.6.2.1
++    avctx->extradata = av_malloc(2);
++    avctx->extradata_size = 2;
++    put_audio_specific_config(avctx);
++    return 0;
++}
++
++static int aac_encode_frame(AVCodecContext *avctx,
++                            uint8_t *frame, int buf_size, void *data)
++{
++    int i,k,channel;
++    AACEncContext *s = avctx->priv_data;
++    int16_t *samples = data;
++    
++    init_put_bits(&s->pb, frame, buf_size*8);
++    put_bits(&s->pb, 8, 0xAB);
++
++    flush_put_bits(&s->pb);
++    return put_bits_count(&s->pb)>>3;
++}
++
++static void sine_window_init(float *window, int n) {
++    const float alpha = M_PI / n;
++    int i;
++    for(i = 0; i < n/2; i++)
++        window[i] = sin((i + 0.5) * alpha);
++}
++
++AVCodec aac_encoder = {
++    "aac",
++    CODEC_TYPE_AUDIO,
++    CODEC_ID_AAC,
++    sizeof(AACEncContext),
++    aac_encode_init,
++    aac_encode_frame,
++};
+diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
+index 33a4242..6871496 100644
+--- a/libavcodec/allcodecs.c
++++ b/libavcodec/allcodecs.c
+@@ -178,6 +178,7 @@ void avcodec_register_all(void)
+     REGISTER_ENCDEC  (ZMBV, zmbv);
+ 
+     /* audio codecs */
++    REGISTER_ENCODER (AAC, aac);
+     REGISTER_ENCDEC  (AC3, ac3);
+     REGISTER_DECODER (ALAC, alac);
+     REGISTER_DECODER (APE, ape);

Added: aacenc/aacenc.c
==============================================================================
--- (empty file)
+++ aacenc/aacenc.c	Sat May 31 10:11:18 2008
@@ -0,0 +1,101 @@
+/*
+ * AAC encoder
+ * Copyright (C) 2008 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file aacenc.c
+ * AAC encoder
+ */
+
+#include "avcodec.h"
+#include "bitstream.h"
+#include "dsputil.h"
+#include "mpeg4audio.h"
+
+typedef struct {
+    PutBitContext pb;
+    MDCTContext mdct;
+    DECLARE_ALIGNED_16(float, kbd_long_1024[1024]);
+} AACEncContext;
+
+/**
+ * Make AAC audio config object.
+ * @see 1.6.2.1
+ */
+static int put_audio_specific_config(AVCodecContext *avctx)
+{
+    PutBitContext pb;
+    init_put_bits(&pb, avctx->extradata, avctx->extradata_size*8);
+    put_bits(&pb, 5, 2); //object type - AAC-LC
+    for(i = 0; i < 16; i++)
+        if(avctx->sample_rate == ff_mpeg4audio_sample_rates[i])
+            break;
+    if(i == 16){
+        av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n", avctx->sample_rate);
+        return -1;
+    }
+    put_bits(&pb, 4, i); //sample rate index
+    put_bits(&pb, 4, avctx->channels); //channel config - stereo
+    //GASpecificConfig
+    put_bits(&pb, 1, 0); //frame length - 1024 samples
+    put_bits(&pb, 1, 0); //does not depend on core coder
+    put_bits(&pb, 1, 0); //is not extension
+    flush_put_bits(&pb);
+}
+
+static int aac_encode_init(AVCodecContext *avctx)
+{
+    AACEncContext *c = avctx->priv_data;
+    int i;
+
+    avctx->frame_size = 1024;
+
+    ff_mdct_init(&c->mdct, 11, 1);
+    // window init
+    ff_kbd_window_init(c->kbd_long_1024, 4.0, 1024);
+
+    avctx->extradata = av_malloc(2);
+    avctx->extradata_size = 2;
+    put_audio_specific_config(avctx);
+    return 0;
+}
+
+static int aac_encode_frame(AVCodecContext *avctx,
+                            uint8_t *frame, int buf_size, void *data)
+{
+    int i,k,channel;
+    AACEncContext *s = avctx->priv_data;
+    int16_t *samples = data;
+
+    init_put_bits(&s->pb, frame, buf_size*8);
+    put_bits(&s->pb, 8, 0xAB);
+
+    flush_put_bits(&s->pb);
+    return put_bits_count(&s->pb)>>3;
+}
+
+AVCodec aac_encoder = {
+    "aac",
+    CODEC_TYPE_AUDIO,
+    CODEC_ID_AAC,
+    sizeof(AACEncContext),
+    aac_encode_init,
+    aac_encode_frame,
+};



More information about the FFmpeg-soc mailing list