Mercurial > libavcodec.hg
comparison mp3lameaudio.c @ 2979:bfabfdf9ce55 libavcodec
COSMETICS: tabs --> spaces, some prettyprinting
author | diego |
---|---|
date | Thu, 22 Dec 2005 01:10:11 +0000 |
parents | ef2149182f1c |
children | 0b546eab515d |
comparison
equal
deleted
inserted
replaced
2978:403183bbb505 | 2979:bfabfdf9ce55 |
---|---|
26 #include "mpegaudio.h" | 26 #include "mpegaudio.h" |
27 #include <lame/lame.h> | 27 #include <lame/lame.h> |
28 | 28 |
29 #define BUFFER_SIZE (2*MPA_FRAME_SIZE) | 29 #define BUFFER_SIZE (2*MPA_FRAME_SIZE) |
30 typedef struct Mp3AudioContext { | 30 typedef struct Mp3AudioContext { |
31 lame_global_flags *gfp; | 31 lame_global_flags *gfp; |
32 int stereo; | 32 int stereo; |
33 uint8_t buffer[BUFFER_SIZE]; | 33 uint8_t buffer[BUFFER_SIZE]; |
34 int buffer_index; | 34 int buffer_index; |
35 } Mp3AudioContext; | 35 } Mp3AudioContext; |
36 | 36 |
37 static int MP3lame_encode_init(AVCodecContext *avctx) | 37 static int MP3lame_encode_init(AVCodecContext *avctx) |
38 { | 38 { |
39 Mp3AudioContext *s = avctx->priv_data; | 39 Mp3AudioContext *s = avctx->priv_data; |
40 | 40 |
41 if (avctx->channels > 2) | 41 if (avctx->channels > 2) |
42 return -1; | 42 return -1; |
43 | 43 |
44 s->stereo = avctx->channels > 1 ? 1 : 0; | 44 s->stereo = avctx->channels > 1 ? 1 : 0; |
45 | 45 |
46 if ((s->gfp = lame_init()) == NULL) | 46 if ((s->gfp = lame_init()) == NULL) |
47 goto err; | 47 goto err; |
48 lame_set_in_samplerate(s->gfp, avctx->sample_rate); | 48 lame_set_in_samplerate(s->gfp, avctx->sample_rate); |
49 lame_set_out_samplerate(s->gfp, avctx->sample_rate); | 49 lame_set_out_samplerate(s->gfp, avctx->sample_rate); |
50 lame_set_num_channels(s->gfp, avctx->channels); | 50 lame_set_num_channels(s->gfp, avctx->channels); |
51 /* lame 3.91 dies on quality != 5 */ | 51 /* lame 3.91 dies on quality != 5 */ |
52 lame_set_quality(s->gfp, 5); | 52 lame_set_quality(s->gfp, 5); |
53 /* lame 3.91 doesn't work in mono */ | 53 /* lame 3.91 doesn't work in mono */ |
54 lame_set_mode(s->gfp, JOINT_STEREO); | 54 lame_set_mode(s->gfp, JOINT_STEREO); |
55 lame_set_brate(s->gfp, avctx->bit_rate/1000); | 55 lame_set_brate(s->gfp, avctx->bit_rate/1000); |
56 if(avctx->flags & CODEC_FLAG_QSCALE) { | 56 if(avctx->flags & CODEC_FLAG_QSCALE) { |
57 lame_set_brate(s->gfp, 0); | 57 lame_set_brate(s->gfp, 0); |
58 lame_set_VBR(s->gfp, vbr_default); | 58 lame_set_VBR(s->gfp, vbr_default); |
59 lame_set_VBR_q(s->gfp, avctx->global_quality / (float)FF_QP2LAMBDA); | 59 lame_set_VBR_q(s->gfp, avctx->global_quality / (float)FF_QP2LAMBDA); |
60 } | 60 } |
61 lame_set_bWriteVbrTag(s->gfp,0); | 61 lame_set_bWriteVbrTag(s->gfp,0); |
62 if (lame_init_params(s->gfp) < 0) | 62 if (lame_init_params(s->gfp) < 0) |
63 goto err_close; | 63 goto err_close; |
64 | 64 |
65 avctx->frame_size = lame_get_framesize(s->gfp); | 65 avctx->frame_size = lame_get_framesize(s->gfp); |
66 | 66 |
67 avctx->coded_frame= avcodec_alloc_frame(); | 67 avctx->coded_frame= avcodec_alloc_frame(); |
68 avctx->coded_frame->key_frame= 1; | 68 avctx->coded_frame->key_frame= 1; |
69 | 69 |
70 return 0; | 70 return 0; |
71 | 71 |
72 err_close: | 72 err_close: |
73 lame_close(s->gfp); | 73 lame_close(s->gfp); |
74 err: | 74 err: |
75 return -1; | 75 return -1; |
76 } | 76 } |
77 | 77 |
78 static const int sSampleRates[3] = { | 78 static const int sSampleRates[3] = { |
79 44100, 48000, 32000 | 79 44100, 48000, 32000 |
80 }; | 80 }; |
134 } | 134 } |
135 | 135 |
136 int MP3lame_encode_frame(AVCodecContext *avctx, | 136 int MP3lame_encode_frame(AVCodecContext *avctx, |
137 unsigned char *frame, int buf_size, void *data) | 137 unsigned char *frame, int buf_size, void *data) |
138 { | 138 { |
139 Mp3AudioContext *s = avctx->priv_data; | 139 Mp3AudioContext *s = avctx->priv_data; |
140 int len; | 140 int len; |
141 int lame_result; | 141 int lame_result; |
142 | 142 |
143 /* lame 3.91 dies on '1-channel interleaved' data */ | 143 /* lame 3.91 dies on '1-channel interleaved' data */ |
144 | 144 |
145 if(data){ | 145 if(data){ |
146 if (s->stereo) { | 146 if (s->stereo) { |
147 lame_result = lame_encode_buffer_interleaved( | 147 lame_result = lame_encode_buffer_interleaved( |
148 s->gfp, | 148 s->gfp, |
196 return 0; | 196 return 0; |
197 } | 197 } |
198 | 198 |
199 int MP3lame_encode_close(AVCodecContext *avctx) | 199 int MP3lame_encode_close(AVCodecContext *avctx) |
200 { | 200 { |
201 Mp3AudioContext *s = avctx->priv_data; | 201 Mp3AudioContext *s = avctx->priv_data; |
202 | 202 |
203 av_freep(&avctx->coded_frame); | 203 av_freep(&avctx->coded_frame); |
204 | 204 |
205 lame_close(s->gfp); | 205 lame_close(s->gfp); |
206 return 0; | 206 return 0; |
207 } | 207 } |
208 | 208 |
209 | 209 |
210 AVCodec mp3lame_encoder = { | 210 AVCodec mp3lame_encoder = { |
211 "mp3", | 211 "mp3", |