diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-26 01:49:32 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-26 01:49:32 +0000 |
commit | a651b74d09d8f96d6dbb488dde3c494d97544886 (patch) | |
tree | 30c6280d152e13b42e38d1ceed96759ce65db15b /media/ffmpeg/ffmpeg_common.h | |
parent | 673590a92d94c9fac62a3984f31e89461bde5054 (diff) | |
download | chromium_src-a651b74d09d8f96d6dbb488dde3c494d97544886.zip chromium_src-a651b74d09d8f96d6dbb488dde3c494d97544886.tar.gz chromium_src-a651b74d09d8f96d6dbb488dde3c494d97544886.tar.bz2 |
Refactor some code that depends on FFmpeg
Some FFmpeg header and source files are misplaced:
media/filters/ffmpeg_common.{cc, h} -> media/ffmpeg
media/tools/media_bench/file_protocol.{cc, h} -> media/ffmpeg
And the necessary refactoring for the new location is done.
Review URL: http://codereview.chromium.org/555087
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37080 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/ffmpeg/ffmpeg_common.h')
-rw-r--r-- | media/ffmpeg/ffmpeg_common.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/media/ffmpeg/ffmpeg_common.h b/media/ffmpeg/ffmpeg_common.h new file mode 100644 index 0000000..9be245f --- /dev/null +++ b/media/ffmpeg/ffmpeg_common.h @@ -0,0 +1,82 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MEDIA_FFMPEG_FFMPEG_COMMON_H_ +#define MEDIA_FFMPEG_FFMPEG_COMMON_H_ + +// Used for FFmpeg error codes. +#include <cerrno> + +#include "base/compiler_specific.h" +#include "base/singleton.h" + +// Used with URLProtocol. +typedef int64 offset_t; + +// Include FFmpeg header files. +extern "C" { +// Temporarily disable possible loss of data warning. +// TODO(scherkus): fix and upstream the compiler warnings. +MSVC_PUSH_DISABLE_WARNING(4244); +#include "third_party/ffmpeg/include/libavcodec/avcodec.h" +#include "third_party/ffmpeg/include/libavformat/avformat.h" +#include "third_party/ffmpeg/include/libavutil/log.h" +MSVC_POP_WARNING(); +} // extern "C" + +namespace media { + +// FFmpegLock is used to serialize calls to avcodec_open(), avcodec_close(), +// and av_find_stream_info() for an entire process because for whatever reason +// it does Very Bad Things to other FFmpeg instances. +// +// TODO(scherkus): track down and upstream a fix to FFmpeg, if possible. +class FFmpegLock : public Singleton<FFmpegLock> { + public: + Lock& lock(); + + private: + // Only allow Singleton to create and delete FFmpegLock. + friend struct DefaultSingletonTraits<FFmpegLock>; + FFmpegLock(); + virtual ~FFmpegLock(); + + Lock lock_; + DISALLOW_COPY_AND_ASSIGN(FFmpegLock); +}; + + +// Wraps FFmpeg's av_free() in a class that can be passed as a template argument +// to scoped_ptr_malloc. +class ScopedPtrAVFree { + public: + inline void operator()(void* x) const { + av_free(x); + } +}; + +// This assumes that the AVPacket being captured was allocated outside of +// FFmpeg via the new operator. Do not use this with AVPacket instances that +// are allocated via malloc() or av_malloc(). +class ScopedPtrAVFreePacket { + public: + inline void operator()(void* x) const { + AVPacket* packet = static_cast<AVPacket*>(x); + av_free_packet(packet); + delete packet; + } +}; + + +// FFmpeg MIME types. +namespace mime_type { + +extern const char kFFmpegAudio[]; +extern const char kFFmpegVideo[]; + +} // namespace mime_type + +} // namespace media + +#endif // MEDIA_FFMPEG_FFMPEG_COMMON_H_ |