diff options
-rw-r--r-- | chrome/common/chrome_paths.cc | 23 | ||||
-rw-r--r-- | chrome/renderer/render_process.cc | 43 | ||||
-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 | ||||
-rw-r--r-- | media/media.gyp | 10 |
6 files changed, 130 insertions, 60 deletions
diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc index b8d7867..f5f6bf9 100644 --- a/chrome/common/chrome_paths.cc +++ b/chrome/common/chrome_paths.cc @@ -31,17 +31,6 @@ bool GetGearsPluginPathFromCommandLine(FilePath* path) { #endif } -// Attempts to find the given FFmpeg library and stores the result in |path|. -// Returns true if the library was found and exists, false otherwise. -static bool GetFFmpegLibraryPath(FilePath* path, - const FilePath::StringType& library) { - // Assume FFmpeg DLLs are kept alongside chrome.dll. - if (!PathService::Get(base::DIR_MODULE, path)) - return false; - *path = path->Append(library); - return file_util::PathExists(*path); -} - bool PathProvider(int key, FilePath* result) { // Some keys are just aliases... switch (key) { @@ -161,18 +150,6 @@ bool PathProvider(int key, FilePath* result) { #endif } break; - case chrome::FILE_LIBAVCODEC: - if (!GetFFmpegLibraryPath(&cur, FILE_PATH_LITERAL("avcodec-52.dll"))) - return false; - break; - case chrome::FILE_LIBAVFORMAT: - if (!GetFFmpegLibraryPath(&cur, FILE_PATH_LITERAL("avformat-52.dll"))) - return false; - break; - case chrome::FILE_LIBAVUTIL: - if (!GetFFmpegLibraryPath(&cur, FILE_PATH_LITERAL("avutil-50.dll"))) - return false; - break; // The following are only valid in the development environment, and // will fail if executed from an installed executable (because the // generated path won't exist). diff --git a/chrome/renderer/render_process.cc b/chrome/renderer/render_process.cc index 52043db..6cd9b68 100644 --- a/chrome/renderer/render_process.cc +++ b/chrome/renderer/render_process.cc @@ -28,43 +28,9 @@ #include "chrome/common/render_messages.h" #include "chrome/common/transport_dib.h" #include "chrome/renderer/render_view.h" +#include "media/base/media.h" #include "webkit/glue/webkit_glue.h" -// Attempts to load FFmpeg before engaging the sandbox. Returns true if all -// libraries were loaded successfully, false otherwise. -static bool LoadFFmpeg() { -#if defined(OS_WIN) - int path_keys[] = { - chrome::FILE_LIBAVCODEC, - chrome::FILE_LIBAVFORMAT, - chrome::FILE_LIBAVUTIL - }; - HMODULE libs[arraysize(path_keys)] = {NULL}; - for (size_t i = 0; i < arraysize(path_keys); ++i) { - std::wstring path; - if (!PathService::Get(path_keys[i], &path)) - break; - libs[i] = LoadLibrary(path.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]); - } - return false; -#else - // TODO(port): Need to handle loading FFmpeg on non-Windows platforms. - NOTIMPLEMENTED(); - return false; -#endif -} - //----------------------------------------------------------------------------- RenderProcess::RenderProcess() @@ -140,8 +106,11 @@ void RenderProcess::Init() { StatisticsRecorder::set_dump_on_exit(true); } - if (LoadFFmpeg()) { - webkit_glue::SetMediaPlayerAvailable(true); + FilePath module_path; + if (PathService::Get(base::DIR_MODULE, &module_path)) { + if (media::InitializeMediaLibrary(module_path)) { + webkit_glue::SetMediaPlayerAvailable(true); + } } } 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 diff --git a/media/media.gyp b/media/media.gyp index 2c85e3a..fec2b64 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -49,6 +49,9 @@ 'base/filter_host_impl.cc', 'base/filter_host_impl.h', 'base/filters.h', + 'base/media_posix.cc', + 'base/media_win.cc', + 'base/media.h', 'base/media_format.cc', 'base/media_format.h', 'base/mock_filter_host.h', @@ -101,6 +104,8 @@ 'filters/ffmpeg_glue.cc', 'filters/ffmpeg_video_decoder.cc', ], + 'sources/': [ ['exclude', '_(mac|win)\\.cc$'], + ['exclude', '\\.mm?$' ] ], }], ['OS =="mac"', { 'link_settings': { @@ -114,6 +119,11 @@ 'filters/ffmpeg_glue.cc', 'filters/ffmpeg_video_decoder.cc', ], + 'sources/': [ ['exclude', '_(linux|win)\\.cc$'] ], + }], + [ 'OS == "win"', { + 'sources/': [ ['exclude', '_(linux|mac|posix)\\.cc$'], + ['exclude', '\\.mm?$' ] ], }], ], }, |