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 |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace media { | 21 namespace media { |
22 | 22 |
23 // FFmpeg library name. | 23 // FFmpeg library name. |
24 static const char* kFFmpegDLL = "ffmpegsumo.dll"; | 24 static const char* kFFmpegDLL = "ffmpegsumo.dll"; |
25 | 25 |
26 // Use a global to indicate whether the library has been initialized or not. We | 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 | 27 // rely on function level static initialization in InitializeMediaLibrary() to |
28 // guarantee this is only set once in a thread safe manner. | 28 // guarantee this is only set once in a thread safe manner. |
29 static bool g_media_library_is_initialized = false; | 29 static bool g_media_library_is_initialized = false; |
30 | 30 |
31 static bool InitializeMediaLibraryInternal(const FilePath& base_path) { | 31 static bool InitializeMediaLibraryInternal(const base::FilePath& base_path) { |
32 DCHECK(!g_media_library_is_initialized); | 32 DCHECK(!g_media_library_is_initialized); |
33 | 33 |
34 // LoadLibraryEx(..., LOAD_WITH_ALTERED_SEARCH_PATH) cannot handle | 34 // LoadLibraryEx(..., LOAD_WITH_ALTERED_SEARCH_PATH) cannot handle |
35 // relative path. | 35 // relative path. |
36 if (!base_path.IsAbsolute()) | 36 if (!base_path.IsAbsolute()) |
37 return false; | 37 return false; |
38 | 38 |
39 // Use alternate DLL search path so we don't load dependencies from the | 39 // Use alternate DLL search path so we don't load dependencies from the |
40 // system path. Refer to http://crbug.com/35857 | 40 // system path. Refer to http://crbug.com/35857 |
41 HMODULE lib = ::LoadLibraryEx( | 41 HMODULE lib = ::LoadLibraryEx( |
42 base_path.AppendASCII(kFFmpegDLL).value().c_str(), NULL, | 42 base_path.AppendASCII(kFFmpegDLL).value().c_str(), NULL, |
43 LOAD_WITH_ALTERED_SEARCH_PATH); | 43 LOAD_WITH_ALTERED_SEARCH_PATH); |
44 | 44 |
45 // Check that we loaded the library successfully. | 45 // Check that we loaded the library successfully. |
46 g_media_library_is_initialized = (lib != NULL); | 46 g_media_library_is_initialized = (lib != NULL); |
47 return g_media_library_is_initialized; | 47 return g_media_library_is_initialized; |
48 } | 48 } |
49 | 49 |
50 bool InitializeMediaLibrary(const FilePath& base_path) { | 50 bool InitializeMediaLibrary(const base::FilePath& base_path) { |
51 static const bool kMediaLibraryInitialized = | 51 static const bool kMediaLibraryInitialized = |
52 InitializeMediaLibraryInternal(base_path); | 52 InitializeMediaLibraryInternal(base_path); |
53 DCHECK_EQ(kMediaLibraryInitialized, g_media_library_is_initialized); | 53 DCHECK_EQ(kMediaLibraryInitialized, g_media_library_is_initialized); |
54 return kMediaLibraryInitialized; | 54 return kMediaLibraryInitialized; |
55 } | 55 } |
56 | 56 |
57 void InitializeMediaLibraryForTesting() { | 57 void InitializeMediaLibraryForTesting() { |
58 FilePath file_path; | 58 base::FilePath file_path; |
59 CHECK(PathService::Get(base::DIR_EXE, &file_path)); | 59 CHECK(PathService::Get(base::DIR_EXE, &file_path)); |
60 CHECK(InitializeMediaLibrary(file_path)); | 60 CHECK(InitializeMediaLibrary(file_path)); |
61 } | 61 } |
62 | 62 |
63 bool IsMediaLibraryInitialized() { | 63 bool IsMediaLibraryInitialized() { |
64 return g_media_library_is_initialized; | 64 return g_media_library_is_initialized; |
65 } | 65 } |
66 | 66 |
67 } // namespace media | 67 } // namespace media |
OLD | NEW |