diff options
Diffstat (limited to 'libavcodec/flacenc.c')
-rw-r--r-- | libavcodec/flacenc.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c index 3e0ddbb75c..06213d086b 100644 --- a/libavcodec/flacenc.c +++ b/libavcodec/flacenc.c @@ -2,23 +2,24 @@ * FLAC audio encoder * Copyright (c) 2006 Justin Ruggles <justin.ruggles@gmail.com> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/avassert.h" #include "libavutil/crc.h" #include "libavutil/md5.h" #include "libavutil/opt.h" @@ -139,7 +140,7 @@ static int select_blocksize(int samplerate, int block_time_ms) int target; int blocksize; - assert(samplerate > 0); + av_assert0(samplerate > 0); blocksize = ff_flac_blocksize_table[1]; target = (samplerate * block_time_ms) / 1000; for (i = 0; i < 16; i++) { @@ -375,6 +376,28 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) return AVERROR(ENOMEM); #endif + if (channels == 3 && + avctx->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) || + channels == 4 && + avctx->channel_layout != AV_CH_LAYOUT_2_2 && + avctx->channel_layout != AV_CH_LAYOUT_QUAD || + channels == 5 && + avctx->channel_layout != AV_CH_LAYOUT_5POINT0 && + avctx->channel_layout != AV_CH_LAYOUT_5POINT0_BACK || + channels == 6 && + avctx->channel_layout != AV_CH_LAYOUT_5POINT1 && + avctx->channel_layout != AV_CH_LAYOUT_5POINT1_BACK) { + if (avctx->channel_layout) { + av_log(avctx, AV_LOG_ERROR, "Channel layout not supported by Flac, " + "output stream will have incorrect " + "channel layout.\n"); + } else { + av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The encoder " + "will use Flac channel layout for " + "%d channels.\n", channels); + } + } + ret = ff_lpc_init(&s->lpc_ctx, avctx->frame_size, s->options.max_prediction_order, FF_LPC_TYPE_LEVINSON); @@ -572,9 +595,9 @@ static uint32_t calc_rice_params(RiceContext *rc, int pmin, int pmax, uint32_t *udata; uint32_t sums[MAX_PARTITION_ORDER+1][MAX_PARTITIONS]; - assert(pmin >= 0 && pmin <= MAX_PARTITION_ORDER); - assert(pmax >= 0 && pmax <= MAX_PARTITION_ORDER); - assert(pmin <= pmax); + av_assert1(pmin >= 0 && pmin <= MAX_PARTITION_ORDER); + av_assert1(pmax >= 0 && pmax <= MAX_PARTITION_ORDER); + av_assert1(pmin <= pmax); udata = av_malloc(n * sizeof(uint32_t)); for (i = 0; i < n; i++) @@ -1229,10 +1252,8 @@ static int flac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, frame_bytes = encode_frame(s); } - if ((ret = ff_alloc_packet(avpkt, frame_bytes))) { - av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); + if ((ret = ff_alloc_packet2(avctx, avpkt, frame_bytes))) return ret; - } out_bytes = write_frame(s, avpkt); @@ -1309,7 +1330,7 @@ AVCodec ff_flac_encoder = { .init = flac_encode_init, .encode2 = flac_encode_frame, .close = flac_encode_close, - .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY, + .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)"), |