mirror of https://git.ffmpeg.org/ffmpeg.git
Cleaned up alacenc.c
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
This commit is contained in:
parent
04403ec2e4
commit
d0fd6fc201
|
@ -75,7 +75,8 @@ typedef struct AlacEncodeContext {
|
||||||
} AlacEncodeContext;
|
} AlacEncodeContext;
|
||||||
|
|
||||||
|
|
||||||
static void init_sample_buffers(AlacEncodeContext *s, const int16_t *input_samples)
|
static void init_sample_buffers(AlacEncodeContext *s,
|
||||||
|
const int16_t *input_samples)
|
||||||
{
|
{
|
||||||
int ch, i;
|
int ch, i;
|
||||||
|
|
||||||
|
@ -88,7 +89,8 @@ static void init_sample_buffers(AlacEncodeContext *s, const int16_t *input_sampl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void encode_scalar(AlacEncodeContext *s, int x, int k, int write_sample_size)
|
static void encode_scalar(AlacEncodeContext *s, int x,
|
||||||
|
int k, int write_sample_size)
|
||||||
{
|
{
|
||||||
int divisor, q, r;
|
int divisor, q, r;
|
||||||
|
|
||||||
|
@ -323,12 +325,12 @@ static void alac_entropy_coder(AlacEncodeContext *s)
|
||||||
if (x > 0xFFFF)
|
if (x > 0xFFFF)
|
||||||
history = 0xFFFF;
|
history = 0xFFFF;
|
||||||
|
|
||||||
if((history < 128) && (i < s->avctx->frame_size)) {
|
if (history < 128 && i < s->avctx->frame_size) {
|
||||||
unsigned int block_size = 0;
|
unsigned int block_size = 0;
|
||||||
|
|
||||||
k = 7 - av_log2(history) + ((history + 16) >> 6);
|
k = 7 - av_log2(history) + ((history + 16) >> 6);
|
||||||
|
|
||||||
while((*samples == 0) && (i < s->avctx->frame_size)) {
|
while (*samples == 0 && i < s->avctx->frame_size) {
|
||||||
samples++;
|
samples++;
|
||||||
i++;
|
i++;
|
||||||
block_size++;
|
block_size++;
|
||||||
|
@ -411,7 +413,8 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
|
||||||
AV_WB8 (alac_extradata+17, avctx->bits_per_coded_sample);
|
AV_WB8 (alac_extradata+17, avctx->bits_per_coded_sample);
|
||||||
AV_WB8 (alac_extradata+21, avctx->channels);
|
AV_WB8 (alac_extradata+21, avctx->channels);
|
||||||
AV_WB32(alac_extradata+24, s->max_coded_frame_size);
|
AV_WB32(alac_extradata+24, s->max_coded_frame_size);
|
||||||
AV_WB32(alac_extradata+28, avctx->sample_rate*avctx->channels*avctx->bits_per_coded_sample); // average bitrate
|
AV_WB32(alac_extradata+28,
|
||||||
|
avctx->sample_rate * avctx->channels * avctx->bits_per_coded_sample); // average bitrate
|
||||||
AV_WB32(alac_extradata+32, avctx->sample_rate);
|
AV_WB32(alac_extradata+32, avctx->sample_rate);
|
||||||
|
|
||||||
// Set relevant extradata fields
|
// Set relevant extradata fields
|
||||||
|
@ -425,7 +428,8 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
|
||||||
if (avctx->min_prediction_order >= 0) {
|
if (avctx->min_prediction_order >= 0) {
|
||||||
if (avctx->min_prediction_order < MIN_LPC_ORDER ||
|
if (avctx->min_prediction_order < MIN_LPC_ORDER ||
|
||||||
avctx->min_prediction_order > ALAC_MAX_LPC_ORDER) {
|
avctx->min_prediction_order > ALAC_MAX_LPC_ORDER) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n", avctx->min_prediction_order);
|
av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n",
|
||||||
|
avctx->min_prediction_order);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +440,8 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
|
||||||
if (avctx->max_prediction_order >= 0) {
|
if (avctx->max_prediction_order >= 0) {
|
||||||
if (avctx->max_prediction_order < MIN_LPC_ORDER ||
|
if (avctx->max_prediction_order < MIN_LPC_ORDER ||
|
||||||
avctx->max_prediction_order > ALAC_MAX_LPC_ORDER) {
|
avctx->max_prediction_order > ALAC_MAX_LPC_ORDER) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n", avctx->max_prediction_order);
|
av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n",
|
||||||
|
avctx->max_prediction_order);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,7 +449,8 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->max_prediction_order < s->min_prediction_order) {
|
if (s->max_prediction_order < s->min_prediction_order) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n",
|
av_log(avctx, AV_LOG_ERROR,
|
||||||
|
"invalid prediction orders: min=%d max=%d\n",
|
||||||
s->min_prediction_order, s->max_prediction_order);
|
s->min_prediction_order, s->max_prediction_order);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -482,7 +488,7 @@ static int alac_encode_frame(AVCodecContext *avctx, uint8_t *frame,
|
||||||
verbatim:
|
verbatim:
|
||||||
init_put_bits(pb, frame, buf_size);
|
init_put_bits(pb, frame, buf_size);
|
||||||
|
|
||||||
if((s->compression_level == 0) || verbatim_flag) {
|
if (s->compression_level == 0 || verbatim_flag) {
|
||||||
// Verbatim mode
|
// Verbatim mode
|
||||||
const int16_t *samples = data;
|
const int16_t *samples = data;
|
||||||
write_frame_header(s, 1);
|
write_frame_header(s, 1);
|
||||||
|
@ -501,7 +507,7 @@ verbatim:
|
||||||
|
|
||||||
if (out_bytes > s->max_coded_frame_size) {
|
if (out_bytes > s->max_coded_frame_size) {
|
||||||
/* frame too large. use verbatim mode */
|
/* frame too large. use verbatim mode */
|
||||||
if(verbatim_flag || (s->compression_level == 0)) {
|
if (verbatim_flag || s->compression_level == 0) {
|
||||||
/* still too large. must be an error. */
|
/* still too large. must be an error. */
|
||||||
av_log(avctx, AV_LOG_ERROR, "error encoding frame\n");
|
av_log(avctx, AV_LOG_ERROR, "error encoding frame\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -532,6 +538,7 @@ AVCodec ff_alac_encoder = {
|
||||||
.encode = alac_encode_frame,
|
.encode = alac_encode_frame,
|
||||||
.close = alac_encode_close,
|
.close = alac_encode_close,
|
||||||
.capabilities = CODEC_CAP_SMALL_LAST_FRAME,
|
.capabilities = CODEC_CAP_SMALL_LAST_FRAME,
|
||||||
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE},
|
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
|
||||||
|
AV_SAMPLE_FMT_NONE },
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
|
.long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue