r1009: Move the dependencies to newer package names
[cinelerra_cv/mob.git] / quicktime / ffmpeg / libavcodec / faac.c
bloba65bdefae5d9d149b4752d87b4134752d9136ea7
1 /*
2 * Interface to libfaac for aac encoding
3 * Copyright (c) 2002 Gildas Bazin <gbazin@netcourrier.com>
5 * This library 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 of the License, or (at your option) any later version.
10 * This library 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.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 /**
21 * @file faacaudio.c
22 * Interface to libfaac for aac encoding.
25 #include "avcodec.h"
26 #include <faac.h>
28 typedef struct FaacAudioContext {
29 faacEncHandle faac_handle;
30 } FaacAudioContext;
32 static int Faac_encode_init(AVCodecContext *avctx)
34 FaacAudioContext *s = avctx->priv_data;
35 faacEncConfigurationPtr faac_cfg;
36 unsigned long samples_input, max_bytes_output;
38 /* number of channels */
39 if (avctx->channels < 1 || avctx->channels > 6)
40 return -1;
42 s->faac_handle = faacEncOpen(avctx->sample_rate,
43 avctx->channels,
44 &samples_input, &max_bytes_output);
46 /* check faac version */
47 faac_cfg = faacEncGetCurrentConfiguration(s->faac_handle);
48 if (faac_cfg->version != FAAC_CFG_VERSION) {
49 av_log(avctx, AV_LOG_ERROR, "wrong libfaac version (compiled for: %d, using %d)\n", FAAC_CFG_VERSION, faac_cfg->version);
50 faacEncClose(s->faac_handle);
51 return -1;
54 /* put the options in the configuration struct */
55 faac_cfg->aacObjectType = LOW;
56 faac_cfg->mpegVersion = MPEG4;
57 faac_cfg->useTns = 0;
58 faac_cfg->allowMidside = 1;
59 faac_cfg->bitRate = avctx->bit_rate;
60 faac_cfg->outputFormat = 0;
61 faac_cfg->inputFormat = FAAC_INPUT_16BIT;
63 if (!faacEncSetConfiguration(s->faac_handle, faac_cfg)) {
64 av_log(avctx, AV_LOG_ERROR, "libfaac doesn't support this output format!\n");
65 return -1;
68 avctx->frame_size = samples_input / avctx->channels;
70 avctx->coded_frame= avcodec_alloc_frame();
71 avctx->coded_frame->key_frame= 1;
73 /* Set decoder specific info */
74 avctx->extradata_size = 0;
75 if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
77 unsigned char *buffer;
78 unsigned long decoder_specific_info_size;
80 if (!faacEncGetDecoderSpecificInfo(s->faac_handle, &buffer,
81 &decoder_specific_info_size)) {
82 avctx->extradata = buffer;
83 avctx->extradata_size = decoder_specific_info_size;
87 return 0;
90 int Faac_encode_frame(AVCodecContext *avctx,
91 unsigned char *frame, int buf_size, void *data)
93 FaacAudioContext *s = avctx->priv_data;
94 int bytes_written;
96 bytes_written = faacEncEncode(s->faac_handle,
97 data,
98 avctx->frame_size * avctx->channels,
99 frame,
100 buf_size);
102 return bytes_written;
105 int Faac_encode_close(AVCodecContext *avctx)
107 FaacAudioContext *s = avctx->priv_data;
109 av_freep(&avctx->coded_frame);
111 //if (avctx->extradata_size) free(avctx->extradata);
113 faacEncClose(s->faac_handle);
114 return 0;
117 AVCodec faac_encoder = {
118 "aac",
119 CODEC_TYPE_AUDIO,
120 CODEC_ID_AAC,
121 sizeof(FaacAudioContext),
122 Faac_encode_init,
123 Faac_encode_frame,
124 Faac_encode_close