comparison mp3lameaudio.c @ 4119:85438e10d72d libavcodec

reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
author diego
date Wed, 01 Nov 2006 21:09:14 +0000
parents c8c591fe26f8
children f97a2081b5b1
comparison
equal deleted inserted replaced
4118:a1786732cd62 4119:85438e10d72d
28 #include "mpegaudio.h" 28 #include "mpegaudio.h"
29 #include <lame/lame.h> 29 #include <lame/lame.h>
30 30
31 #define BUFFER_SIZE (2*MPA_FRAME_SIZE) 31 #define BUFFER_SIZE (2*MPA_FRAME_SIZE)
32 typedef struct Mp3AudioContext { 32 typedef struct Mp3AudioContext {
33 lame_global_flags *gfp; 33 lame_global_flags *gfp;
34 int stereo; 34 int stereo;
35 uint8_t buffer[BUFFER_SIZE]; 35 uint8_t buffer[BUFFER_SIZE];
36 int buffer_index; 36 int buffer_index;
37 } Mp3AudioContext; 37 } Mp3AudioContext;
38 38
39 static int MP3lame_encode_init(AVCodecContext *avctx) 39 static int MP3lame_encode_init(AVCodecContext *avctx)
40 { 40 {
41 Mp3AudioContext *s = avctx->priv_data; 41 Mp3AudioContext *s = avctx->priv_data;
42 42
43 if (avctx->channels > 2) 43 if (avctx->channels > 2)
44 return -1; 44 return -1;
45 45
46 s->stereo = avctx->channels > 1 ? 1 : 0; 46 s->stereo = avctx->channels > 1 ? 1 : 0;
47 47
48 if ((s->gfp = lame_init()) == NULL) 48 if ((s->gfp = lame_init()) == NULL)
49 goto err; 49 goto err;
50 lame_set_in_samplerate(s->gfp, avctx->sample_rate); 50 lame_set_in_samplerate(s->gfp, avctx->sample_rate);
51 lame_set_out_samplerate(s->gfp, avctx->sample_rate); 51 lame_set_out_samplerate(s->gfp, avctx->sample_rate);
52 lame_set_num_channels(s->gfp, avctx->channels); 52 lame_set_num_channels(s->gfp, avctx->channels);
53 /* lame 3.91 dies on quality != 5 */ 53 /* lame 3.91 dies on quality != 5 */
54 lame_set_quality(s->gfp, 5); 54 lame_set_quality(s->gfp, 5);
55 /* lame 3.91 doesn't work in mono */ 55 /* lame 3.91 doesn't work in mono */
56 lame_set_mode(s->gfp, JOINT_STEREO); 56 lame_set_mode(s->gfp, JOINT_STEREO);
57 lame_set_brate(s->gfp, avctx->bit_rate/1000); 57 lame_set_brate(s->gfp, avctx->bit_rate/1000);
58 if(avctx->flags & CODEC_FLAG_QSCALE) { 58 if(avctx->flags & CODEC_FLAG_QSCALE) {
59 lame_set_brate(s->gfp, 0); 59 lame_set_brate(s->gfp, 0);
60 lame_set_VBR(s->gfp, vbr_default); 60 lame_set_VBR(s->gfp, vbr_default);
61 lame_set_VBR_q(s->gfp, avctx->global_quality / (float)FF_QP2LAMBDA); 61 lame_set_VBR_q(s->gfp, avctx->global_quality / (float)FF_QP2LAMBDA);
62 } 62 }
63 lame_set_bWriteVbrTag(s->gfp,0); 63 lame_set_bWriteVbrTag(s->gfp,0);
64 if (lame_init_params(s->gfp) < 0) 64 if (lame_init_params(s->gfp) < 0)
65 goto err_close; 65 goto err_close;
66 66
67 avctx->frame_size = lame_get_framesize(s->gfp); 67 avctx->frame_size = lame_get_framesize(s->gfp);
68 68
69 avctx->coded_frame= avcodec_alloc_frame(); 69 avctx->coded_frame= avcodec_alloc_frame();
70 avctx->coded_frame->key_frame= 1; 70 avctx->coded_frame->key_frame= 1;
71 71
72 return 0; 72 return 0;
73 73
74 err_close: 74 err_close:
75 lame_close(s->gfp); 75 lame_close(s->gfp);
76 err: 76 err:
77 return -1; 77 return -1;
78 } 78 }
79 79
80 static const int sSampleRates[3] = { 80 static const int sSampleRates[3] = {
81 44100, 48000, 32000 81 44100, 48000, 32000
82 }; 82 };
136 } 136 }
137 137
138 int MP3lame_encode_frame(AVCodecContext *avctx, 138 int MP3lame_encode_frame(AVCodecContext *avctx,
139 unsigned char *frame, int buf_size, void *data) 139 unsigned char *frame, int buf_size, void *data)
140 { 140 {
141 Mp3AudioContext *s = avctx->priv_data; 141 Mp3AudioContext *s = avctx->priv_data;
142 int len; 142 int len;
143 int lame_result; 143 int lame_result;
144 144
145 /* lame 3.91 dies on '1-channel interleaved' data */ 145 /* lame 3.91 dies on '1-channel interleaved' data */
146 146
147 if(data){ 147 if(data){
148 if (s->stereo) { 148 if (s->stereo) {
149 lame_result = lame_encode_buffer_interleaved( 149 lame_result = lame_encode_buffer_interleaved(
150 s->gfp, 150 s->gfp,
198 return 0; 198 return 0;
199 } 199 }
200 200
201 int MP3lame_encode_close(AVCodecContext *avctx) 201 int MP3lame_encode_close(AVCodecContext *avctx)
202 { 202 {
203 Mp3AudioContext *s = avctx->priv_data; 203 Mp3AudioContext *s = avctx->priv_data;
204 204
205 av_freep(&avctx->coded_frame); 205 av_freep(&avctx->coded_frame);
206 206
207 lame_close(s->gfp); 207 lame_close(s->gfp);
208 return 0; 208 return 0;
209 } 209 }
210 210
211 211
212 AVCodec mp3lame_encoder = { 212 AVCodec mp3lame_encoder = {
213 "mp3", 213 "mp3",