From 2cfa1f1f2058a73b0a1778dd562ba6ed39e40f92 Mon Sep 17 00:00:00 2001 From: "jrummell@chromium.org" Date: Thu, 26 Sep 2013 07:55:02 +0000 Subject: Cleanup destruction of ffmpeg objects The code to free up AVCodecContext and AVFrame objects is replicated in several places. This cleanup is to common code into a scoped_ptr deleter, and then use scoped_ptr_malloc for all references to these objects. BUG= TEST=media_unittests successful using ASAN and HeapChecker Review URL: https://codereview.chromium.org/24286009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225382 0039d316-1c4b-4281-b951-d872f2087c98 --- media/ffmpeg/ffmpeg_common.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'media/ffmpeg') diff --git a/media/ffmpeg/ffmpeg_common.h b/media/ffmpeg/ffmpeg_common.h index ccd2aa5..39626ac 100644 --- a/media/ffmpeg/ffmpeg_common.h +++ b/media/ffmpeg/ffmpeg_common.h @@ -58,6 +58,28 @@ class ScopedPtrAVFreePacket { } }; +// Frees an AVCodecContext object in a class that can be passed as a Deleter +// argument to scoped_ptr_malloc. +class ScopedPtrAVFreeContext { + public: + inline void operator()(void* x) const { + AVCodecContext* codec_context = static_cast(x); + av_free(codec_context->extradata); + avcodec_close(codec_context); + av_free(codec_context); + } +}; + +// Frees an AVFrame object in a class that can be passed as a Deleter argument +// to scoped_ptr_malloc. +class ScopedPtrAVFreeFrame { + public: + inline void operator()(void* x) const { + AVFrame* frame = static_cast(x); + av_frame_free(&frame); + } +}; + // Converts an int64 timestamp in |time_base| units to a base::TimeDelta. // For example if |timestamp| equals 11025 and |time_base| equals {1, 44100} // then the return value will be a base::TimeDelta for 0.25 seconds since that -- cgit v1.1