• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavcodec/eac3enc.c

Go to the documentation of this file.
00001 /*
00002  * E-AC-3 encoder
00003  * Copyright (c) 2011 Justin Ruggles <justin.ruggles@gmail.com>
00004  *
00005  * This file is part of Libav.
00006  *
00007  * Libav is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * Libav is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with Libav; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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     /* set first cpl coords */
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     /* set first cpl leak */
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);                   /* sync word */
00077 
00078     /* BSI header */
00079     put_bits(&s->pb,  2, 0);                        /* stream type = independent */
00080     put_bits(&s->pb,  3, 0);                        /* substream id = 0 */
00081     put_bits(&s->pb, 11, (s->frame_size / 2) - 1);  /* frame size */
00082     if (s->bit_alloc.sr_shift) {
00083         put_bits(&s->pb, 2, 0x3);                   /* fscod2 */
00084         put_bits(&s->pb, 2, s->bit_alloc.sr_code);  /* sample rate code */
00085     } else {
00086         put_bits(&s->pb, 2, s->bit_alloc.sr_code);  /* sample rate code */
00087         put_bits(&s->pb, 2, 0x3);                   /* number of blocks = 6 */
00088     }
00089     put_bits(&s->pb, 3, s->channel_mode);           /* audio coding mode */
00090     put_bits(&s->pb, 1, s->lfe_on);                 /* LFE channel indicator */
00091     put_bits(&s->pb, 5, s->bitstream_id);           /* bitstream id (EAC3=16) */
00092     put_bits(&s->pb, 5, -opt->dialogue_level);      /* dialogue normalization level */
00093     put_bits(&s->pb, 1, 0);                         /* no compression gain */
00094     put_bits(&s->pb, 1, 0);                         /* no mixing metadata */
00095     /* TODO: mixing metadata */
00096     put_bits(&s->pb, 1, 0);                         /* no info metadata */
00097     /* TODO: info metadata */
00098     put_bits(&s->pb, 1, 0);                         /* no additional bit stream info */
00099 
00100     /* frame header */
00101     put_bits(&s->pb, 1, 1);                         /* exponent strategy syntax = each block */
00102     put_bits(&s->pb, 1, 0);                         /* aht enabled = no */
00103     put_bits(&s->pb, 2, 0);                         /* snr offset strategy = 1 */
00104     put_bits(&s->pb, 1, 0);                         /* transient pre-noise processing enabled = no */
00105     put_bits(&s->pb, 1, 0);                         /* block switch syntax enabled = no */
00106     put_bits(&s->pb, 1, 0);                         /* dither flag syntax enabled = no */
00107     put_bits(&s->pb, 1, 0);                         /* bit allocation model syntax enabled = no */
00108     put_bits(&s->pb, 1, 0);                         /* fast gain codes enabled = no */
00109     put_bits(&s->pb, 1, 0);                         /* dba syntax enabled = no */
00110     put_bits(&s->pb, 1, 0);                         /* skip field syntax enabled = no */
00111     put_bits(&s->pb, 1, 0);                         /* spx enabled = no */
00112     /* coupling strategy use flags */
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     /* exponent strategy */
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     /* E-AC-3 to AC-3 converter exponent strategy (unfortunately not optional...) */
00131     for (ch = 1; ch <= s->fbw_channels; ch++)
00132         put_bits(&s->pb, 5, 0);
00133     /* snr offsets */
00134     put_bits(&s->pb, 6, s->coarse_snr_offset);
00135     put_bits(&s->pb, 4, s->fine_snr_offset[1]);
00136     /* block start info */
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

Generated on Wed Apr 11 2012 07:31:33 for FFmpeg by  doxygen 1.7.1