| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/base/media.h" | 5 #include "media/base/media.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #if defined(_WIN32_WINNT_WIN8) | 8 #if defined(_WIN32_WINNT_WIN8) |
| 9 // The Windows 8 SDK defines FACILITY_VISUALCPP in winerror.h. | 9 // The Windows 8 SDK defines FACILITY_VISUALCPP in winerror.h. |
| 10 #undef FACILITY_VISUALCPP | 10 #undef FACILITY_VISUALCPP |
| 11 #endif | 11 #endif |
| 12 #include <delayimp.h> | 12 #include <delayimp.h> |
| 13 | 13 |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/logging.h" | |
| 16 #include "base/native_library.h" | |
| 17 #include "base/path_service.h" | |
| 18 | 15 |
| 19 #pragma comment(lib, "delayimp.lib") | 16 #pragma comment(lib, "delayimp.lib") |
| 20 | 17 |
| 21 namespace media { | 18 namespace media { |
| 19 namespace internal { |
| 22 | 20 |
| 23 // FFmpeg library name. | 21 bool InitializeMediaLibraryInternal(const base::FilePath& module_dir) { |
| 24 static const char kFFmpegDLL[] = "ffmpegsumo.dll"; | |
| 25 | |
| 26 // Use a global to indicate whether the library has been initialized or not. We | |
| 27 // rely on function level static initialization in InitializeMediaLibrary() to | |
| 28 // guarantee this is only set once in a thread safe manner. | |
| 29 static bool g_media_library_is_initialized = false; | |
| 30 | |
| 31 static bool InitializeMediaLibraryInternal(const base::FilePath& base_path) { | |
| 32 DCHECK(!g_media_library_is_initialized); | |
| 33 | |
| 34 // LoadLibraryEx(..., LOAD_WITH_ALTERED_SEARCH_PATH) cannot handle | 22 // LoadLibraryEx(..., LOAD_WITH_ALTERED_SEARCH_PATH) cannot handle |
| 35 // relative path. | 23 // relative path. |
| 36 if (!base_path.IsAbsolute()) | 24 if (!module_dir.IsAbsolute()) |
| 37 return false; | 25 return false; |
| 38 | 26 |
| 39 // Use alternate DLL search path so we don't load dependencies from the | 27 // Use alternate DLL search path so we don't load dependencies from the |
| 40 // system path. Refer to http://crbug.com/35857 | 28 // system path. Refer to http://crbug.com/35857 |
| 29 static const char kFFmpegDLL[] = "ffmpegsumo.dll"; |
| 41 HMODULE lib = ::LoadLibraryEx( | 30 HMODULE lib = ::LoadLibraryEx( |
| 42 base_path.AppendASCII(kFFmpegDLL).value().c_str(), NULL, | 31 module_dir.AppendASCII(kFFmpegDLL).value().c_str(), NULL, |
| 43 LOAD_WITH_ALTERED_SEARCH_PATH); | 32 LOAD_WITH_ALTERED_SEARCH_PATH); |
| 44 | 33 |
| 45 // Check that we loaded the library successfully. | 34 // Check that we loaded the library successfully. |
| 46 g_media_library_is_initialized = (lib != NULL); | 35 return lib != NULL; |
| 47 return g_media_library_is_initialized; | |
| 48 } | 36 } |
| 49 | 37 |
| 50 bool InitializeMediaLibrary(const base::FilePath& base_path) { | 38 } // namespace internal |
| 51 static const bool kMediaLibraryInitialized = | |
| 52 InitializeMediaLibraryInternal(base_path); | |
| 53 DCHECK_EQ(kMediaLibraryInitialized, g_media_library_is_initialized); | |
| 54 return kMediaLibraryInitialized; | |
| 55 } | |
| 56 | |
| 57 void InitializeMediaLibraryForTesting() { | |
| 58 base::FilePath file_path; | |
| 59 CHECK(PathService::Get(base::DIR_EXE, &file_path)); | |
| 60 CHECK(InitializeMediaLibrary(file_path)); | |
| 61 } | |
| 62 | |
| 63 bool IsMediaLibraryInitialized() { | |
| 64 return g_media_library_is_initialized; | |
| 65 } | |
| 66 | |
| 67 } // namespace media | 39 } // namespace media |
| OLD | NEW |