diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-18 00:36:22 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-18 00:36:22 +0000 |
commit | 10000d66052ed5a1c42f5173bd93ea0af8a6d19b (patch) | |
tree | 272e718e2858efd87e71af38fcffd897fd4c6e94 /media/base | |
parent | 359cadcdcebadd6d9d87ee92d3dace00ad0a0736 (diff) | |
download | chromium_src-10000d66052ed5a1c42f5173bd93ea0af8a6d19b.zip chromium_src-10000d66052ed5a1c42f5173bd93ea0af8a6d19b.tar.gz chromium_src-10000d66052ed5a1c42f5173bd93ea0af8a6d19b.tar.bz2 |
Move the ffmpeg loading function into media library.
This will allow us to hide the platform specific library loading code from the main chrome code.
Review URL: http://codereview.chromium.org/69027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13991 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base')
-rwxr-xr-x | media/base/media.h | 26 | ||||
-rwxr-xr-x | media/base/media_posix.cc | 19 | ||||
-rwxr-xr-x | media/base/media_win.cc | 69 |
3 files changed, 114 insertions, 0 deletions
diff --git a/media/base/media.h b/media/base/media.h new file mode 100755 index 0000000..171d4e8 --- /dev/null +++ b/media/base/media.h @@ -0,0 +1,26 @@ +// Copyright (c) 2009 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. + +// Contains code that should be used for initializing, or querying the state +// of the media library as a whole. + +#ifndef MEDIA_BASE_MEDIA_H_ +#define MEDIA_BASE_MEDIA_H_ + +class FilePath; + +namespace media { + +// Attempts to initialize the media library (loading DLLs, DSOs, etc.). +// If |module_dir| is the emptry string, then the system default library paths +// are searched for the dynamic libraries. If a |module_dir| is provided, then +// only the specified |module_dir| will be searched for the dynamic libraries. +// +// Returns true if everything was successfully initialized, false otherwise. +bool InitializeMediaLibrary(const FilePath& module_dir); + +} // namespace media + +#endif // MEDIA_BASE_MEDIA_H_ + diff --git a/media/base/media_posix.cc b/media/base/media_posix.cc new file mode 100755 index 0000000..664f9f8 --- /dev/null +++ b/media/base/media_posix.cc @@ -0,0 +1,19 @@ +// Copyright (c) 2009 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. + +#include "media/base/media.h" + +#include "base/logging.h" +#include "base/path_service.h" + +namespace media { + +// Attempts to initialize the media library (loading DLLs, DSOs, etc.). +// Returns true if everything was successfully initialized, false otherwise. +bool InitializeMediaLibrary(const FilePath& module_dir) { + NOTIMPLEMENTED(); + return false; +} + +} // namespace media diff --git a/media/base/media_win.cc b/media/base/media_win.cc new file mode 100755 index 0000000..c0219d9 --- /dev/null +++ b/media/base/media_win.cc @@ -0,0 +1,69 @@ +// Copyright (c) 2009 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. + +#include "media/base/media.h" + +#include <windows.h> + +#include "base/file_path.h" +#include "base/logging.h" +#include "base/path_service.h" + +namespace media { + +namespace { + +enum FFmpegDLLKeys { + FILE_LIBAVCODEC, // full path to libavcodec media decoding library. + FILE_LIBAVFORMAT, // full path to libavformat media parsing library. + FILE_LIBAVUTIL, // full path to libavutil media utility library. +}; + +// Retrieves the DLLName for the given key. +FilePath::CharType* GetDLLName(FFmpegDLLKeys dll_key) { + // TODO(ajwong): Do we want to lock to a specific ffmpeg version? + switch (dll_key) { + case FILE_LIBAVCODEC: + return FILE_PATH_LITERAL("avcodec-52.dll"); + case FILE_LIBAVFORMAT: + return FILE_PATH_LITERAL("avcodec-52.dll"); + case FILE_LIBAVUTIL: + return FILE_PATH_LITERAL("avutil-50.dll"); + default: + LOG(DFATAL) << "Invalid DLL key requested: " << dll_key; + return FILE_PATH_LITERAL(""); + } +} + +} // namespace + +// Attempts to initialize the media library (loading DLLs, DSOs, etc.). +// Returns true if everything was successfully initialized, false otherwise. +bool InitializeMediaLibrary(const FilePath& base_path) { + FFmpegDLLKeys path_keys[] = { + media::FILE_LIBAVCODEC, + media::FILE_LIBAVFORMAT, + media::FILE_LIBAVUTIL + }; + HMODULE libs[arraysize(path_keys)] = {NULL}; + for (size_t i = 0; i < arraysize(path_keys); ++i) { + FilePath path = base_path.Append(GetDLLName(path_keys[i])); + libs[i] = LoadLibrary(path.value().c_str()); + if (!libs[i]) + break; + } + + // Check that we loaded all libraries successfully. + if (libs[arraysize(libs)-1]) + return true; + + // Free any loaded libraries if we weren't successful. + for (size_t i = 0; i < arraysize(libs) && libs[i] != NULL; ++i) { + FreeLibrary(libs[i]); + libs[i] = NULL; // Just to be safe. + } + return false; +} + +} // namespace media |