libavcodec/flacenc.c File Reference

#include "libavutil/crc.h"
#include "libavutil/md5.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "get_bits.h"
#include "golomb.h"
#include "lpc.h"
#include "flac.h"
#include "flacdata.h"

Go to the source code of this file.

Data Structures

struct  CompressionOptions
struct  RiceContext
struct  FlacSubframe
struct  FlacFrame
struct  FlacEncodeContext

Defines

#define FLAC_SUBFRAME_CONSTANT   0
 FLAC audio encoder Copyright (c) 2006 Justin Ruggles <justin.ruggles@gmail.com>.
#define FLAC_SUBFRAME_VERBATIM   1
#define FLAC_SUBFRAME_FIXED   8
#define FLAC_SUBFRAME_LPC   32
#define MAX_FIXED_ORDER   4
#define MAX_PARTITION_ORDER   8
#define MAX_PARTITIONS   (1 << MAX_PARTITION_ORDER)
#define MAX_LPC_PRECISION   15
#define MAX_LPC_SHIFT   15
#define MAX_RICE_PARAM   14
#define rice_encode_count(sum, n, k)   (((n)*((k)+1))+((sum-(n>>1))>>(k)))
#define LPC1(x)
#define FLAGS   AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM

Functions

static void write_streaminfo (FlacEncodeContext *s, uint8_t *header)
 Write streaminfo metadata block to byte array.
static int select_blocksize (int samplerate, int block_time_ms)
 Set blocksize based on samplerate.
static av_cold void dprint_compression_options (FlacEncodeContext *s)
static av_cold int flac_encode_init (AVCodecContext *avctx)
static void init_frame (FlacEncodeContext *s)
static void copy_samples (FlacEncodeContext *s, const int16_t *samples)
 Copy channel-interleaved input samples into separate subframes.
static int rice_count_exact (int32_t *res, int n, int k)
static int subframe_count_exact (FlacEncodeContext *s, FlacSubframe *sub, int pred_order)
static int find_optimal_param (uint32_t sum, int n)
 Solve for d/dk(rice_encode_count) = n-((sum-(n>>1))>>(k+1)) = 0.
static uint32_t calc_optimal_rice_params (RiceContext *rc, int porder, uint32_t *sums, int n, int pred_order)
static void calc_sums (int pmin, int pmax, uint32_t *data, int n, int pred_order, uint32_t sums[][MAX_PARTITIONS])
static uint32_t calc_rice_params (RiceContext *rc, int pmin, int pmax, int32_t *data, int n, int pred_order)
static int get_max_p_order (int max_porder, int n, int order)
static uint32_t find_subframe_rice_params (FlacEncodeContext *s, FlacSubframe *sub, int pred_order)
static void encode_residual_fixed (int32_t *res, const int32_t *smp, int n, int order)
static av_always_inline void encode_residual_lpc_unrolled (int32_t *res, const int32_t *smp, int n, int order, const int32_t *coefs, int shift, int big)
static void encode_residual_lpc (int32_t *res, const int32_t *smp, int n, int order, const int32_t *coefs, int shift)
static int encode_residual_ch (FlacEncodeContext *s, int ch)
static int count_frame_header (FlacEncodeContext *s)
static int encode_frame (FlacEncodeContext *s)
static int estimate_stereo_mode (int32_t *left_ch, int32_t *right_ch, int n)
static void channel_decorrelation (FlacEncodeContext *s)
 Perform stereo channel decorrelation.
static void write_utf8 (PutBitContext *pb, uint32_t val)
static void write_frame_header (FlacEncodeContext *s)
static void write_subframes (FlacEncodeContext *s)
static void write_frame_footer (FlacEncodeContext *s)
static int write_frame (FlacEncodeContext *s, uint8_t *frame, int buf_size)
static void update_md5_sum (FlacEncodeContext *s, const int16_t *samples)
static int flac_encode_frame (AVCodecContext *avctx, uint8_t *frame, int buf_size, void *data)
static av_cold int flac_encode_close (AVCodecContext *avctx)

Variables

static const AVOption options []
static const AVClass flac_encoder_class
AVCodec ff_flac_encoder


Define Documentation

#define FLAC_SUBFRAME_CONSTANT   0

FLAC audio encoder Copyright (c) 2006 Justin Ruggles <justin.ruggles@gmail.com>.

This file is part of FFmpeg.

FFmpeg is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

FFmpeg is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with FFmpeg; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Definition at line 32 of file flacenc.c.

Referenced by encode_residual_ch(), subframe_count_exact(), and write_subframes().

#define FLAC_SUBFRAME_FIXED   8

Definition at line 34 of file flacenc.c.

Referenced by encode_residual_ch().

#define FLAC_SUBFRAME_LPC   32

#define FLAC_SUBFRAME_VERBATIM   1

Definition at line 33 of file flacenc.c.

Referenced by encode_residual_ch(), subframe_count_exact(), and write_subframes().

#define FLAGS   AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM

Definition at line 1353 of file flacenc.c.

#define LPC1 (  ) 

Value:

{\
    int c = coefs[(x)-1];\
    p0   += c * s;\
    s     = smp[i-(x)+1];\
    p1   += c * s;\
}

Definition at line 763 of file flacenc.c.

Referenced by encode_residual_lpc_unrolled().

#define MAX_FIXED_ORDER   4

Definition at line 37 of file flacenc.c.

Referenced by encode_residual_ch(), and flac_encode_init().

#define MAX_LPC_PRECISION   15

Definition at line 40 of file flacenc.c.

Referenced by flac_encode_init().

#define MAX_LPC_SHIFT   15

Definition at line 41 of file flacenc.c.

Referenced by encode_residual_ch().

#define MAX_PARTITION_ORDER   8

Definition at line 38 of file flacenc.c.

Referenced by calc_rice_params(), and flac_encode_init().

#define MAX_PARTITIONS   (1 << MAX_PARTITION_ORDER)

Definition at line 39 of file flacenc.c.

Referenced by calc_rice_params().

#define MAX_RICE_PARAM   14

Definition at line 42 of file flacenc.c.

Referenced by find_optimal_param().

#define rice_encode_count ( sum,
n,
 )     (((n)*((k)+1))+((sum-(n>>1))>>(k)))

Definition at line 582 of file flacenc.c.

Referenced by calc_optimal_rice_params(), and estimate_stereo_mode().


Function Documentation

static uint32_t calc_optimal_rice_params ( RiceContext rc,
int  porder,
uint32_t *  sums,
int  n,
int  pred_order 
) [static]

Definition at line 600 of file flacenc.c.

Referenced by calc_rice_params().

static uint32_t calc_rice_params ( RiceContext rc,
int  pmin,
int  pmax,
int32_t *  data,
int  n,
int  pred_order 
) [static]

Definition at line 651 of file flacenc.c.

Referenced by find_subframe_rice_params().

static void calc_sums ( int  pmin,
int  pmax,
uint32_t *  data,
int  n,
int  pred_order,
uint32_t  sums[][MAX_PARTITIONS] 
) [static]

Definition at line 624 of file flacenc.c.

Referenced by calc_rice_params().

static void channel_decorrelation ( FlacEncodeContext s  )  [static]

Perform stereo channel decorrelation.

Definition at line 1105 of file flacenc.c.

Referenced by flac_encode_frame().

static void copy_samples ( FlacEncodeContext s,
const int16_t samples 
) [static]

Copy channel-interleaved input samples into separate subframes.

Definition at line 509 of file flacenc.c.

Referenced by flac_encode_frame().

static int count_frame_header ( FlacEncodeContext s  )  [static]

Definition at line 1003 of file flacenc.c.

Referenced by encode_frame().

static av_cold void dprint_compression_options ( FlacEncodeContext s  )  [static]

Definition at line 153 of file flacenc.c.

Referenced by flac_encode_init().

static int encode_frame ( FlacEncodeContext s  )  [static]

Definition at line 1039 of file flacenc.c.

static int encode_residual_ch ( FlacEncodeContext s,
int  ch 
) [static]

Definition at line 867 of file flacenc.c.

Referenced by encode_frame().

static void encode_residual_fixed ( int32_t *  res,
const int32_t *  smp,
int  n,
int  order 
) [static]

Definition at line 712 of file flacenc.c.

Referenced by encode_residual_ch().

static void encode_residual_lpc ( int32_t *  res,
const int32_t *  smp,
int  n,
int  order,
const int32_t *  coefs,
int  shift 
) [static]

Definition at line 831 of file flacenc.c.

Referenced by encode_residual_ch().

static av_always_inline void encode_residual_lpc_unrolled ( int32_t *  res,
const int32_t *  smp,
int  n,
int  order,
const int32_t *  coefs,
int  shift,
int  big 
) [static]

Definition at line 770 of file flacenc.c.

Referenced by encode_residual_lpc().

static int estimate_stereo_mode ( int32_t *  left_ch,
int32_t *  right_ch,
int  n 
) [static]

Definition at line 1055 of file flacenc.c.

static int find_optimal_param ( uint32_t  sum,
int  n 
) [static]

Solve for d/dk(rice_encode_count) = n-((sum-(n>>1))>>(k+1)) = 0.

Definition at line 587 of file flacenc.c.

Referenced by calc_optimal_rice_params(), and estimate_stereo_mode().

static uint32_t find_subframe_rice_params ( FlacEncodeContext s,
FlacSubframe sub,
int  pred_order 
) [static]

Definition at line 695 of file flacenc.c.

Referenced by encode_residual_ch().

static av_cold int flac_encode_close ( AVCodecContext avctx  )  [static]

Definition at line 1340 of file flacenc.c.

static int flac_encode_frame ( AVCodecContext avctx,
uint8_t *  frame,
int  buf_size,
void *  data 
) [static]

Definition at line 1283 of file flacenc.c.

static av_cold int flac_encode_init ( AVCodecContext avctx  )  [static]

Definition at line 211 of file flacenc.c.

static int get_max_p_order ( int  max_porder,
int  n,
int  order 
) [static]

Definition at line 686 of file flacenc.c.

Referenced by find_subframe_rice_params().

static void init_frame ( FlacEncodeContext s  )  [static]

Definition at line 473 of file flacenc.c.

Referenced by flac_encode_frame().

static int rice_count_exact ( int32_t *  res,
int  n,
int  k 
) [static]

Definition at line 521 of file flacenc.c.

Referenced by subframe_count_exact().

static int select_blocksize ( int  samplerate,
int  block_time_ms 
) [static]

Set blocksize based on samplerate.

Choose the closest predefined blocksize >= BLOCK_TIME_MS milliseconds.

Definition at line 134 of file flacenc.c.

Referenced by flac_encode_init().

static int subframe_count_exact ( FlacEncodeContext s,
FlacSubframe sub,
int  pred_order 
) [static]

Definition at line 535 of file flacenc.c.

Referenced by encode_residual_ch().

static void update_md5_sum ( FlacEncodeContext s,
const int16_t samples 
) [static]

Definition at line 1269 of file flacenc.c.

Referenced by flac_encode_frame().

static int write_frame ( FlacEncodeContext s,
uint8_t *  frame,
int  buf_size 
) [static]

Definition at line 1259 of file flacenc.c.

static void write_frame_footer ( FlacEncodeContext s  )  [static]

Definition at line 1248 of file flacenc.c.

Referenced by write_frame().

static void write_frame_header ( FlacEncodeContext s  )  [static]

Definition at line 1153 of file flacenc.c.

static void write_streaminfo ( FlacEncodeContext s,
uint8_t *  header 
) [static]

Write streaminfo metadata block to byte array.

Definition at line 107 of file flacenc.c.

Referenced by flac_encode_frame(), flac_encode_init(), and write_headers().

static void write_subframes ( FlacEncodeContext s  )  [static]

Definition at line 1190 of file flacenc.c.

Referenced by write_frame().

static void write_utf8 ( PutBitContext pb,
uint32_t  val 
) [static]

Definition at line 1146 of file flacenc.c.

Referenced by write_frame_header().


Variable Documentation

Initial value:

 {
    .name           = "flac",
    .type           = AVMEDIA_TYPE_AUDIO,
    .id             = CODEC_ID_FLAC,
    .priv_data_size = sizeof(FlacEncodeContext),
    .init           = flac_encode_init,
    .encode         = flac_encode_frame,
    .close          = flac_encode_close,
    .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_LOSSLESS,
    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
    .long_name = NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"),
    .priv_class = &flac_encoder_class,
}

Definition at line 1381 of file flacenc.c.

const AVClass flac_encoder_class [static]

Initial value:

Definition at line 1374 of file flacenc.c.

const AVOption options[] [static]

Initial value:

 {
{ "lpc_coeff_precision", "LPC coefficient precision", 0x42, AV_OPT_TYPE_INT, {.dbl = 15 }, 0, MAX_LPC_PRECISION, FLAGS },
{ "lpc_type", "LPC algorithm", 0x42, AV_OPT_TYPE_INT, {.dbl = FF_LPC_TYPE_DEFAULT }, FF_LPC_TYPE_DEFAULT, FF_LPC_TYPE_NB-1, FLAGS, "lpc_type" },
{ "none",     NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_NONE },     INT_MIN, INT_MAX, FLAGS, "lpc_type" },
{ "fixed",    NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_FIXED },    INT_MIN, INT_MAX, FLAGS, "lpc_type" },
{ "levinson", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_LEVINSON }, INT_MIN, INT_MAX, FLAGS, "lpc_type" },
{ "cholesky", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_CHOLESKY }, INT_MIN, INT_MAX, FLAGS, "lpc_type" },
{ "lpc_passes", "Number of passes to use for Cholesky factorization during LPC analysis", 0x42,  AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, FLAGS },
{ "min_partition_order",  NULL, 0x42,  AV_OPT_TYPE_INT, {.dbl = -1 },      -1, MAX_PARTITION_ORDER, FLAGS },
{ "max_partition_order",  NULL, 0x42,  AV_OPT_TYPE_INT, {.dbl = -1 },      -1, MAX_PARTITION_ORDER, FLAGS },
{ "prediction_order_method", "Search method for selecting prediction order", 0x42, AV_OPT_TYPE_INT, {.dbl = -1 }, -1, ORDER_METHOD_LOG, FLAGS, "predm" },
{ "estimation", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_EST },    INT_MIN, INT_MAX, FLAGS, "predm" },
{ "2level",     NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_2LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
{ "4level",     NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_4LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
{ "8level",     NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_8LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
{ "search",     NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_SEARCH }, INT_MIN, INT_MAX, FLAGS, "predm" },
{ "log",        NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_LOG },    INT_MIN, INT_MAX, FLAGS, "predm" },
{ NULL },
}

Definition at line 1354 of file flacenc.c.


Generated on Fri Oct 26 02:43:47 2012 for FFmpeg by  doxygen 1.5.8