summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-25 20:50:29 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-25 20:50:29 +0000
commitbf557e1bbabd298e06e57b2345f96a3fec657f34 (patch)
tree0cb2a13165718213256161bcb3dead8fd73f2fd7 /chrome
parent774a996a8235bd91dbbdaf6418ad405810f3be5d (diff)
downloadchromium_src-bf557e1bbabd298e06e57b2345f96a3fec657f34.zip
chromium_src-bf557e1bbabd298e06e57b2345f96a3fec657f34.tar.gz
chromium_src-bf557e1bbabd298e06e57b2345f96a3fec657f34.tar.bz2
Dynamically load FFmpeg DLLs if present and --enable-video is on.
If any of the DLLs fail to load or are not present, video is disabled. Review URL: http://codereview.chromium.org/24025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10376 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/common/chrome_paths.cc23
-rw-r--r--chrome/common/chrome_paths.h3
-rw-r--r--chrome/renderer/render_process.cc40
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() {
}
}
}
-