annotate faac.c @ 4570:58be423405db libavcodec

Doxygenize the comments for the av_get_bits_per_sample() function.
author takis
date Thu, 22 Feb 2007 19:09:35 +0000
parents f97a2081b5b1
children d77c5a6824e4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1500
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
1 /*
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
2 * Interface to libfaac for aac encoding
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
3 * Copyright (c) 2002 Gildas Bazin <gbazin@netcourrier.com>
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3099
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3099
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3099
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
1500
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3099
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
1500
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3099
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
1500
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
15 * Lesser General Public License for more details.
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
16 *
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3099
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 3031
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1500
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
20 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2841
diff changeset
21
1500
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
22 /**
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
23 * @file faacaudio.c
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
24 * Interface to libfaac for aac encoding.
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
25 */
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
26
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
27 #include "avcodec.h"
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
28 #include <faac.h>
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
29
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
30 typedef struct FaacAudioContext {
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
31 faacEncHandle faac_handle;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
32 } FaacAudioContext;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
33
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
34 static int Faac_encode_init(AVCodecContext *avctx)
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
35 {
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
36 FaacAudioContext *s = avctx->priv_data;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
37 faacEncConfigurationPtr faac_cfg;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
38 unsigned long samples_input, max_bytes_output;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
39
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
40 /* number of channels */
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
41 if (avctx->channels < 1 || avctx->channels > 6)
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
42 return -1;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
43
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
44 s->faac_handle = faacEncOpen(avctx->sample_rate,
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
45 avctx->channels,
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
46 &samples_input, &max_bytes_output);
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
47
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
48 /* check faac version */
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
49 faac_cfg = faacEncGetCurrentConfiguration(s->faac_handle);
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
50 if (faac_cfg->version != FAAC_CFG_VERSION) {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
51 av_log(avctx, AV_LOG_ERROR, "wrong libfaac version (compiled for: %d, using %d)\n", FAAC_CFG_VERSION, faac_cfg->version);
1500
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
52 faacEncClose(s->faac_handle);
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
53 return -1;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
54 }
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
55
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
56 /* put the options in the configuration struct */
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
57 faac_cfg->aacObjectType = LOW;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
58 faac_cfg->mpegVersion = MPEG4;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
59 faac_cfg->useTns = 0;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
60 faac_cfg->allowMidside = 1;
2841
bceeca1bb30f vbr audio encode patch by (Justin Ruggles: jruggle, earthlink net)
michael
parents: 1826
diff changeset
61 faac_cfg->bitRate = avctx->bit_rate / avctx->channels;
3031
0f5f311f2f94 Parameter added for user to set the cutoff frequency when encoding with faac.
banan
parents: 2979
diff changeset
62 faac_cfg->bandWidth = avctx->cutoff;
2841
bceeca1bb30f vbr audio encode patch by (Justin Ruggles: jruggle, earthlink net)
michael
parents: 1826
diff changeset
63 if(avctx->flags & CODEC_FLAG_QSCALE) {
bceeca1bb30f vbr audio encode patch by (Justin Ruggles: jruggle, earthlink net)
michael
parents: 1826
diff changeset
64 faac_cfg->bitRate = 0;
bceeca1bb30f vbr audio encode patch by (Justin Ruggles: jruggle, earthlink net)
michael
parents: 1826
diff changeset
65 faac_cfg->quantqual = avctx->global_quality / FF_QP2LAMBDA;
bceeca1bb30f vbr audio encode patch by (Justin Ruggles: jruggle, earthlink net)
michael
parents: 1826
diff changeset
66 }
3099
a2a116fee880 create adts stream if CODEC_FLAG_GLOBAL_HEADER not set
mru
parents: 3036
diff changeset
67 faac_cfg->outputFormat = 1;
1500
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
68 faac_cfg->inputFormat = FAAC_INPUT_16BIT;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
69
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
70 avctx->frame_size = samples_input / avctx->channels;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
71
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
72 avctx->coded_frame= avcodec_alloc_frame();
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
73 avctx->coded_frame->key_frame= 1;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
74
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
75 /* Set decoder specific info */
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
76 avctx->extradata_size = 0;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
77 if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
78
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
79 unsigned char *buffer;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
80 unsigned long decoder_specific_info_size;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
81
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
82 if (!faacEncGetDecoderSpecificInfo(s->faac_handle, &buffer,
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
83 &decoder_specific_info_size)) {
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
84 avctx->extradata = buffer;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
85 avctx->extradata_size = decoder_specific_info_size;
3099
a2a116fee880 create adts stream if CODEC_FLAG_GLOBAL_HEADER not set
mru
parents: 3036
diff changeset
86 faac_cfg->outputFormat = 0;
1500
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
87 }
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
88 }
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
89
3099
a2a116fee880 create adts stream if CODEC_FLAG_GLOBAL_HEADER not set
mru
parents: 3036
diff changeset
90 if (!faacEncSetConfiguration(s->faac_handle, faac_cfg)) {
a2a116fee880 create adts stream if CODEC_FLAG_GLOBAL_HEADER not set
mru
parents: 3036
diff changeset
91 av_log(avctx, AV_LOG_ERROR, "libfaac doesn't support this output format!\n");
a2a116fee880 create adts stream if CODEC_FLAG_GLOBAL_HEADER not set
mru
parents: 3036
diff changeset
92 return -1;
a2a116fee880 create adts stream if CODEC_FLAG_GLOBAL_HEADER not set
mru
parents: 3036
diff changeset
93 }
a2a116fee880 create adts stream if CODEC_FLAG_GLOBAL_HEADER not set
mru
parents: 3036
diff changeset
94
1500
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
95 return 0;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
96 }
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
97
4170
f97a2081b5b1 make some symbols static
mru
parents: 3947
diff changeset
98 static int Faac_encode_frame(AVCodecContext *avctx,
f97a2081b5b1 make some symbols static
mru
parents: 3947
diff changeset
99 unsigned char *frame, int buf_size, void *data)
1500
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
100 {
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
101 FaacAudioContext *s = avctx->priv_data;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
102 int bytes_written;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
103
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
104 bytes_written = faacEncEncode(s->faac_handle,
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
105 data,
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
106 avctx->frame_size * avctx->channels,
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
107 frame,
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
108 buf_size);
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
109
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
110 return bytes_written;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
111 }
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
112
4170
f97a2081b5b1 make some symbols static
mru
parents: 3947
diff changeset
113 static int Faac_encode_close(AVCodecContext *avctx)
1500
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
114 {
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
115 FaacAudioContext *s = avctx->priv_data;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
116
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
117 av_freep(&avctx->coded_frame);
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
118
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
119 //if (avctx->extradata_size) free(avctx->extradata);
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
120
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
121 faacEncClose(s->faac_handle);
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
122 return 0;
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
123 }
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
124
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
125 AVCodec faac_encoder = {
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
126 "aac",
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
127 CODEC_TYPE_AUDIO,
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
128 CODEC_ID_AAC,
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
129 sizeof(FaacAudioContext),
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
130 Faac_encode_init,
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
131 Faac_encode_frame,
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
132 Faac_encode_close
726a81d83ddd Patch for AAC encoding with libfaac by (Gildas Bazin <gbazin at altern dot org>)
michaelni
parents:
diff changeset
133 };