00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #define CONFIG_AC3ENC_FLOAT 1
00028 #include "ac3enc.h"
00029 #include "eac3enc.h"
00030
00031
00032 #define AC3ENC_TYPE AC3ENC_TYPE_EAC3
00033 #include "ac3enc_opts_template.c"
00034 static AVClass eac3enc_class = { "E-AC-3 Encoder", av_default_item_name,
00035 eac3_options, LIBAVUTIL_VERSION_INT };
00036
00037
00038 void ff_eac3_set_cpl_states(AC3EncodeContext *s)
00039 {
00040 int ch, blk;
00041 int first_cpl_coords[AC3_MAX_CHANNELS];
00042
00043
00044 for (ch = 1; ch <= s->fbw_channels; ch++)
00045 first_cpl_coords[ch] = 1;
00046 for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
00047 AC3Block *block = &s->blocks[blk];
00048 for (ch = 1; ch <= s->fbw_channels; ch++) {
00049 if (block->channel_in_cpl[ch]) {
00050 if (first_cpl_coords[ch]) {
00051 block->new_cpl_coords = 2;
00052 first_cpl_coords[ch] = 0;
00053 }
00054 } else {
00055 first_cpl_coords[ch] = 1;
00056 }
00057 }
00058 }
00059
00060
00061 for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
00062 AC3Block *block = &s->blocks[blk];
00063 if (block->cpl_in_use) {
00064 block->new_cpl_leak = 2;
00065 break;
00066 }
00067 }
00068 }
00069
00070
00071 void ff_eac3_output_frame_header(AC3EncodeContext *s)
00072 {
00073 int blk, ch;
00074 AC3EncOptions *opt = &s->options;
00075
00076 put_bits(&s->pb, 16, 0x0b77);
00077
00078
00079 put_bits(&s->pb, 2, 0);
00080 put_bits(&s->pb, 3, 0);
00081 put_bits(&s->pb, 11, (s->frame_size / 2) - 1);
00082 if (s->bit_alloc.sr_shift) {
00083 put_bits(&s->pb, 2, 0x3);
00084 put_bits(&s->pb, 2, s->bit_alloc.sr_code);
00085 } else {
00086 put_bits(&s->pb, 2, s->bit_alloc.sr_code);
00087 put_bits(&s->pb, 2, 0x3);
00088 }
00089 put_bits(&s->pb, 3, s->channel_mode);
00090 put_bits(&s->pb, 1, s->lfe_on);
00091 put_bits(&s->pb, 5, s->bitstream_id);
00092 put_bits(&s->pb, 5, -opt->dialogue_level);
00093 put_bits(&s->pb, 1, 0);
00094 put_bits(&s->pb, 1, 0);
00095
00096 put_bits(&s->pb, 1, 0);
00097
00098 put_bits(&s->pb, 1, 0);
00099
00100
00101 put_bits(&s->pb, 1, 1);
00102 put_bits(&s->pb, 1, 0);
00103 put_bits(&s->pb, 2, 0);
00104 put_bits(&s->pb, 1, 0);
00105 put_bits(&s->pb, 1, 0);
00106 put_bits(&s->pb, 1, 0);
00107 put_bits(&s->pb, 1, 0);
00108 put_bits(&s->pb, 1, 0);
00109 put_bits(&s->pb, 1, 0);
00110 put_bits(&s->pb, 1, 0);
00111 put_bits(&s->pb, 1, 0);
00112
00113 if (s->channel_mode > AC3_CHMODE_MONO) {
00114 put_bits(&s->pb, 1, s->blocks[0].cpl_in_use);
00115 for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) {
00116 AC3Block *block = &s->blocks[blk];
00117 put_bits(&s->pb, 1, block->new_cpl_strategy);
00118 if (block->new_cpl_strategy)
00119 put_bits(&s->pb, 1, block->cpl_in_use);
00120 }
00121 }
00122
00123 for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
00124 for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++)
00125 put_bits(&s->pb, 2, s->exp_strategy[ch][blk]);
00126 if (s->lfe_on) {
00127 for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
00128 put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]);
00129 }
00130
00131 for (ch = 1; ch <= s->fbw_channels; ch++)
00132 put_bits(&s->pb, 5, 0);
00133
00134 put_bits(&s->pb, 6, s->coarse_snr_offset);
00135 put_bits(&s->pb, 4, s->fine_snr_offset[1]);
00136
00137 put_bits(&s->pb, 1, 0);
00138 }
00139
00140
00141 #if CONFIG_EAC3_ENCODER
00142 AVCodec ff_eac3_encoder = {
00143 .name = "eac3",
00144 .type = AVMEDIA_TYPE_AUDIO,
00145 .id = CODEC_ID_EAC3,
00146 .priv_data_size = sizeof(AC3EncodeContext),
00147 .init = ff_ac3_encode_init,
00148 .encode = ff_ac3_encode_frame,
00149 .close = ff_ac3_encode_close,
00150 .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE},
00151 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52 E-AC-3"),
00152 .priv_class = &eac3enc_class,
00153 .channel_layouts = ff_ac3_channel_layouts,
00154 };
00155 #endif