Mercurial > mplayer.hg
comparison libaf/af_lavcac3enc.c @ 30243:05f085c36d5b
Let the format filter do the AC3 endianness conversion instead of duplicating
the conversion code over and over.
author | reimar |
---|---|
date | Mon, 11 Jan 2010 20:40:51 +0000 |
parents | 02b9c1a452e1 |
children | 1ba5eef167aa |
comparison
equal
deleted
inserted
replaced
30242:03c1ad03f29d | 30243:05f085c36d5b |
---|---|
30 #include "help_mp.h" | 30 #include "help_mp.h" |
31 #include "reorder_ch.h" | 31 #include "reorder_ch.h" |
32 | 32 |
33 #include "libavcodec/avcodec.h" | 33 #include "libavcodec/avcodec.h" |
34 #include "libavcodec/ac3.h" | 34 #include "libavcodec/ac3.h" |
35 #include "libavutil/intreadwrite.h" | |
35 | 36 |
36 // Data for specific instances of this filter | 37 // Data for specific instances of this filter |
37 typedef struct af_ac3enc_s { | 38 typedef struct af_ac3enc_s { |
38 struct AVCodec *lavc_acodec; | 39 struct AVCodec *lavc_acodec; |
39 struct AVCodecContext *lavc_actx; | 40 struct AVCodecContext *lavc_actx; |
100 if(avcodec_open(s->lavc_actx, s->lavc_acodec) < 0) { | 101 if(avcodec_open(s->lavc_actx, s->lavc_acodec) < 0) { |
101 mp_msg(MSGT_AFILTER, MSGL_ERR, MSGTR_CouldntOpenCodec, "ac3", bit_rate); | 102 mp_msg(MSGT_AFILTER, MSGL_ERR, MSGTR_CouldntOpenCodec, "ac3", bit_rate); |
102 return AF_ERROR; | 103 return AF_ERROR; |
103 } | 104 } |
104 } | 105 } |
105 af->data->format = AF_FORMAT_AC3_NE; | 106 af->data->format = AF_FORMAT_AC3_BE; |
106 af->data->nch = 2; | 107 af->data->nch = 2; |
107 return test_output_res; | 108 return test_output_res; |
108 case AF_CONTROL_COMMAND_LINE: | 109 case AF_CONTROL_COMMAND_LINE: |
109 mp_msg(MSGT_AFILTER, MSGL_DBG2, "af_lavcac3enc cmdline: %s.\n", (char*)arg); | 110 mp_msg(MSGT_AFILTER, MSGL_DBG2, "af_lavcac3enc cmdline: %s.\n", (char*)arg); |
110 s->bit_rate = 0; | 111 s->bit_rate = 0; |
233 } | 234 } |
234 mp_msg(MSGT_AFILTER, MSGL_DBG2, "avcodec_encode_audio got %d, pending %d.\n", | 235 mp_msg(MSGT_AFILTER, MSGL_DBG2, "avcodec_encode_audio got %d, pending %d.\n", |
235 len, s->pending_len); | 236 len, s->pending_len); |
236 | 237 |
237 if (s->add_iec61937_header) { | 238 if (s->add_iec61937_header) { |
238 int16_t *out = (int16_t *)buf; | |
239 int bsmod = dest[5] & 0x7; | 239 int bsmod = dest[5] & 0x7; |
240 | 240 |
241 #if !HAVE_BIGENDIAN | 241 AV_WB16(buf, 0xF872); // iec 61937 syncword 1 |
242 int i; | 242 AV_WB16(buf + 2, 0x4E1F); // iec 61937 syncword 2 |
243 char tmp; | 243 buf[4] = bsmod; // bsmod |
244 for (i = 0; i < len; i += 2) { | 244 buf[5] = 0x01; // data-type ac3 |
245 tmp = dest[i]; | 245 AV_WB16(buf + 6, len << 3); // number of bits in payload |
246 dest[i] = dest[i+1]; | |
247 dest[i+1] = tmp; | |
248 } | |
249 if (len & 1) { | |
250 dest[len] = dest[len-1]; | |
251 dest[len-1] = 0; | |
252 len++; | |
253 } | |
254 #endif | |
255 out[0] = 0xF872; // iec 61937 syncword 1 | |
256 out[1] = 0x4E1F; // iec 61937 syncword 2 | |
257 out[2] = 0x0001; // data-type ac3 | |
258 out[2] |= bsmod << 8; // bsmod | |
259 out[3] = len << 3; // number of bits in payload | |
260 | 246 |
261 memset(buf + 8 + len, 0, AC3_FRAME_SIZE * 2 * 2 - 8 - len); | 247 memset(buf + 8 + len, 0, AC3_FRAME_SIZE * 2 * 2 - 8 - len); |
262 len = AC3_FRAME_SIZE * 2 * 2; | 248 len = AC3_FRAME_SIZE * 2 * 2; |
263 } | 249 } |
264 | 250 |