diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/common/chrome_paths.cc | 23 | ||||
-rw-r--r-- | chrome/common/chrome_paths.h | 3 | ||||
-rw-r--r-- | chrome/renderer/render_process.cc | 40 |
3 files changed, 63 insertions, 3 deletions
diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc index 0c16079..40f22ba 100644 --- a/chrome/common/chrome_paths.cc +++ b/chrome/common/chrome_paths.cc @@ -31,6 +31,17 @@ 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) { @@ -149,6 +160,18 @@ bool PathProvider(int key, FilePath* result) { } } 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-49.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/common/chrome_paths.h b/chrome/common/chrome_paths.h index 9300e99..dec6da9 100644 --- a/chrome/common/chrome_paths.h +++ b/chrome/common/chrome_paths.h @@ -32,6 +32,9 @@ enum { FILE_RECORDED_SCRIPT, // full path to the script.log file that contains // recorded browser events for playback. FILE_GEARS_PLUGIN, // full path to the gears.dll plugin file. + 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. // Valid only in development environment; TODO(darin): move these DIR_TEST_DATA, // directory where unit test data resides diff --git a/chrome/renderer/render_process.cc b/chrome/renderer/render_process.cc index 8cec986..80ec5fb 100644 --- a/chrome/renderer/render_process.cc +++ b/chrome/renderer/render_process.cc @@ -29,6 +29,42 @@ #include "chrome/renderer/render_view.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() : ChildProcess(new RenderThread()), @@ -122,8 +158,7 @@ void RenderProcess::Init() { #endif } - if (command_line.HasSwitch(switches::kEnableVideo)) { - // TODO(scherkus): check for any DLL dependencies. + if (command_line.HasSwitch(switches::kEnableVideo) && LoadFFmpeg()) { webkit_glue::SetMediaPlayerAvailable(true); } } @@ -269,4 +304,3 @@ void RenderProcess::ClearTransportDIBCache() { } } } - |