1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-21 16:11:11 +01:00

Bug 467 (P3) fix - Audacity fails to build with latest FFmpeg/libav. Main patch by Leland Lucius with modification from Benjamin Drung.

This commit is contained in:
mchinen
2012-01-21 08:01:32 +00:00
parent 40ff3fd0b8
commit 682759d965
4 changed files with 160 additions and 43 deletions

View File

@@ -154,6 +154,10 @@ private:
AVFifoBuffer * mEncAudioFifo; // FIFO to write incoming audio samples into
uint8_t * mEncAudioFifoOutBuf; // buffer to read _out_ of the FIFO into
#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(50, 0, 0)
AVFifoBuffer mEncAudioFifoBuffer; // FIFO to write incoming audio samples into
#endif
wxString mName;
int mSubFormat;
@@ -174,6 +178,11 @@ ExportFFmpeg::ExportFFmpeg()
#define MAX_AUDIO_PACKET_SIZE (128 * 1024)
mEncAudioEncodedBufSiz = 4*MAX_AUDIO_PACKET_SIZE;
mEncAudioFifoOutBuf = NULL; // buffer to read _out_ of the FIFO into
#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(50, 0, 0)
mEncAudioFifo = &mEncAudioFifoBuffer;
#endif
mSampleRate = 0;
mSupportsUTF8 = true;
@@ -350,7 +359,6 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
mEncAudioCodecCtx = mEncAudioStream->codec;
avcodec_get_context_defaults(mEncAudioCodecCtx);
mEncAudioCodecCtx->codec_id = ExportFFmpegOptions::fmts[mSubFormat].codecid;
mEncAudioCodecCtx->codec_type = CODEC_TYPE_AUDIO;
mEncAudioCodecCtx->codec_tag = av_codec_get_tag((const AVCodecTag **)mEncFormatCtx->oformat->codec_tag,mEncAudioCodecCtx->codec_id);
@@ -403,7 +411,9 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
mEncAudioCodecCtx->flags2 = 0;
if (gPrefs->Read(wxT("/FileFormats/FFmpegBitReservoir"),true)) mEncAudioCodecCtx->flags2 |= CODEC_FLAG2_BIT_RESERVOIR;
if (gPrefs->Read(wxT("/FileFormats/FFmpegVariableBlockLen"),true)) mEncAudioCodecCtx->flags2 |= 0x0004; //WMA only?
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53, 0, 0)
mEncAudioCodecCtx->use_lpc = gPrefs->Read(wxT("/FileFormats/FFmpegUseLPC"),true);
#endif
mEncAudioCodecCtx->compression_level = gPrefs->Read(wxT("/FileFormats/FFmpegCompLevel"),-1);
mEncAudioCodecCtx->frame_size = gPrefs->Read(wxT("/FileFormats/FFmpegFrameSize"),(long)0);
mEncAudioCodecCtx->lpc_coeff_precision = gPrefs->Read(wxT("/FileFormats/FFmpegLPCCoefPrec"),(long)0);
@@ -487,7 +497,11 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
// The encoder may require a minimum number of raw audio samples for each encoding but we can't
// guarantee we'll get this minimum each time an audio frame is decoded from the input file so
// we use a FIFO to store up incoming raw samples until we have enough for one call to the codec.
#if LIBAVUTIL_VERSION_INT > AV_VERSION_INT(49, 15, 0)
mEncAudioFifo = av_fifo_alloc(1024);
#else
av_fifo_init(mEncAudioFifo, 1024);
#endif
// Allocate a buffer to read OUT of the FIFO into. The FIFO maintains its own buffer internally.
if ((mEncAudioFifoOutBuf = (uint8_t*)av_malloc(2*MAX_AUDIO_PACKET_SIZE)) == NULL)
@@ -544,7 +558,11 @@ bool ExportFFmpeg::Finalize()
nFifoBytes, mEncAudioCodecCtx->frame_size);
// Pull the bytes out from the FIFO and feed them to the encoder.
#if LIBAVUTIL_VERSION_INT > AV_VERSION_INT(49, 15, 0)
if (av_fifo_generic_read(mEncAudioFifo, mEncAudioFifoOutBuf, nFifoBytes, NULL) == 0)
#else
if (av_fifo_generic_read(mEncAudioFifo, nFifoBytes, NULL, mEncAudioFifoOutBuf) == 0)
#endif
{
if (mEncAudioCodecCtx->frame_size != 1)
nEncodedBytes = avcodec_encode_audio(mEncAudioCodecCtx, mEncAudioEncodedBuf, mEncAudioEncodedBufSiz, (int16_t*)mEncAudioFifoOutBuf);
@@ -609,7 +627,10 @@ bool ExportFFmpeg::Finalize()
av_free(mEncAudioFifoOutBuf);
av_fifo_free(mEncAudioFifo);
#if LIBAVUTIL_VERSION_INT > AV_VERSION_INT(49, 15, 0)
mEncAudioFifo = NULL;
#endif
return true;
}
@@ -635,7 +656,11 @@ bool ExportFFmpeg::EncodeAudioFrame(int16_t *pFrame, int frameSize)
// Read raw audio samples out of the FIFO in nAudioFrameSizeOut byte-sized groups to encode.
while ((ret = av_fifo_size(mEncAudioFifo)) >= nAudioFrameSizeOut)
{
#if LIBAVUTIL_VERSION_INT > AV_VERSION_INT(49, 15, 0)
ret = av_fifo_generic_read(mEncAudioFifo, mEncAudioFifoOutBuf, nAudioFrameSizeOut, NULL);
#else
ret = av_fifo_generic_read(mEncAudioFifo, nAudioFrameSizeOut, NULL, mEncAudioFifoOutBuf);
#endif
av_init_packet(&pkt);