Bug 1486080 - Always allocate memory to pass extradata. r=padenot

Despite wording of the documentation to the contrary, we can't provide a static pointer to an immutable object.
Apparently, it's always been that way.

Differential Revision: https://phabricator.services.mozilla.com/D4323

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jean-Yves Avenard 2018-08-27 13:22:26 +00:00
parent 5b894e11fe
commit 95343883e7

View file

@ -77,12 +77,21 @@ FFmpegDataDecoder<LIBAV_VER>::InitDecoder()
mCodecContext->extradata_size = mExtraData->Length(); mCodecContext->extradata_size = mExtraData->Length();
// FFmpeg may use SIMD instructions to access the data which reads the // FFmpeg may use SIMD instructions to access the data which reads the
// data in 32 bytes block. Must ensure we have enough data to read. // data in 32 bytes block. Must ensure we have enough data to read.
uint32_t padding_size =
#if LIBAVCODEC_VERSION_MAJOR >= 58 #if LIBAVCODEC_VERSION_MAJOR >= 58
mExtraData->AppendElements(AV_INPUT_BUFFER_PADDING_SIZE); AV_INPUT_BUFFER_PADDING_SIZE;
#else #else
mExtraData->AppendElements(FF_INPUT_BUFFER_PADDING_SIZE); FF_INPUT_BUFFER_PADDING_SIZE;
#endif #endif
mCodecContext->extradata = mExtraData->Elements(); mCodecContext->extradata = static_cast<uint8_t*>(
mLib->av_malloc(mExtraData->Length() + padding_size));
if (!mCodecContext->extradata) {
return MediaResult(NS_ERROR_OUT_OF_MEMORY,
RESULT_DETAIL("Couldn't init ffmpeg extradata"));
}
memcpy(mCodecContext->extradata,
mExtraData->Elements(),
mExtraData->Length());
} else { } else {
mCodecContext->extradata_size = 0; mCodecContext->extradata_size = 0;
} }
@ -225,6 +234,9 @@ FFmpegDataDecoder<LIBAV_VER>::ProcessShutdown()
StaticMutexAutoLock mon(sMonitor); StaticMutexAutoLock mon(sMonitor);
if (mCodecContext) { if (mCodecContext) {
if (mCodecContext->extradata) {
mLib->av_freep(&mCodecContext->extradata);
}
mLib->avcodec_close(mCodecContext); mLib->avcodec_close(mCodecContext);
mLib->av_freep(&mCodecContext); mLib->av_freep(&mCodecContext);
#if LIBAVCODEC_VERSION_MAJOR >= 55 #if LIBAVCODEC_VERSION_MAJOR >= 55