OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 case FILE_LIBAVFORMAT: | 37 case FILE_LIBAVFORMAT: |
38 return FILE_PATH_LITERAL("avformat-52.dll"); | 38 return FILE_PATH_LITERAL("avformat-52.dll"); |
39 case FILE_LIBAVUTIL: | 39 case FILE_LIBAVUTIL: |
40 return FILE_PATH_LITERAL("avutil-50.dll"); | 40 return FILE_PATH_LITERAL("avutil-50.dll"); |
41 default: | 41 default: |
42 LOG(DFATAL) << "Invalid DLL key requested: " << dll_key; | 42 LOG(DFATAL) << "Invalid DLL key requested: " << dll_key; |
43 return FILE_PATH_LITERAL(""); | 43 return FILE_PATH_LITERAL(""); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
| 47 static bool g_media_library_is_initialized = false; |
| 48 |
47 // Attempts to initialize the media library (loading DLLs, DSOs, etc.). | 49 // Attempts to initialize the media library (loading DLLs, DSOs, etc.). |
48 // Returns true if everything was successfully initialized, false otherwise. | 50 // Returns true if everything was successfully initialized, false otherwise. |
49 bool InitializeMediaLibrary(const FilePath& base_path) { | 51 bool InitializeMediaLibrary(const FilePath& base_path) { |
| 52 if (g_media_library_is_initialized) |
| 53 return true; |
| 54 |
50 FFmpegDLLKeys path_keys[] = { | 55 FFmpegDLLKeys path_keys[] = { |
51 media::FILE_LIBAVCODEC, | 56 media::FILE_LIBAVCODEC, |
52 media::FILE_LIBAVFORMAT, | 57 media::FILE_LIBAVFORMAT, |
53 media::FILE_LIBAVUTIL | 58 media::FILE_LIBAVUTIL |
54 }; | 59 }; |
55 HMODULE libs[arraysize(path_keys)] = {NULL}; | 60 HMODULE libs[arraysize(path_keys)] = {NULL}; |
56 | 61 |
57 for (size_t i = 0; i < arraysize(path_keys); ++i) { | 62 for (size_t i = 0; i < arraysize(path_keys); ++i) { |
58 FilePath path = base_path.Append(GetDLLName(path_keys[i])); | 63 FilePath path = base_path.Append(GetDLLName(path_keys[i])); |
59 #ifdef TESTING | 64 #ifdef TESTING |
(...skipping 11 matching lines...) Expand all Loading... |
71 std::wstring outputbuf = StringPrintf(L"DLL loadtime %5.2f ms, %ls\n", | 76 std::wstring outputbuf = StringPrintf(L"DLL loadtime %5.2f ms, %ls\n", |
72 (dll_loadtime_end - dll_loadtime_start).InMillisecondsF(), | 77 (dll_loadtime_end - dll_loadtime_start).InMillisecondsF(), |
73 cpath); | 78 cpath); |
74 OutputDebugStringW(outputbuf.c_str()); | 79 OutputDebugStringW(outputbuf.c_str()); |
75 #endif | 80 #endif |
76 } | 81 } |
77 | 82 |
78 // Check that we loaded all libraries successfully. We only need to check the | 83 // Check that we loaded all libraries successfully. We only need to check the |
79 // last array element because the loop above will break without initializing | 84 // last array element because the loop above will break without initializing |
80 // it on any prior error. | 85 // it on any prior error. |
81 if (libs[arraysize(libs)-1]) | 86 g_media_library_is_initialized = (libs[arraysize(libs)-1] != NULL); |
82 return true; | |
83 | 87 |
84 // Free any loaded libraries if we weren't successful. | 88 if (!g_media_library_is_initialized) { |
85 for (size_t i = 0; i < arraysize(libs) && libs[i] != NULL; ++i) { | 89 // Free any loaded libraries if we weren't successful. |
86 FreeLibrary(libs[i]); | 90 for (size_t i = 0; i < arraysize(libs) && libs[i] != NULL; ++i) { |
87 libs[i] = NULL; // Just to be safe. | 91 FreeLibrary(libs[i]); |
| 92 libs[i] = NULL; // Just to be safe. |
| 93 } |
88 } | 94 } |
89 return false; | 95 |
| 96 return g_media_library_is_initialized; |
| 97 } |
| 98 |
| 99 bool IsMediaLibraryInitialized() { |
| 100 return g_media_library_is_initialized; |
90 } | 101 } |
91 | 102 |
92 bool InitializeOpenMaxLibrary(const FilePath& module_dir) { | 103 bool InitializeOpenMaxLibrary(const FilePath& module_dir) { |
93 NOTIMPLEMENTED() << "OpenMAX is not used in Windows."; | 104 NOTIMPLEMENTED() << "OpenMAX is not used in Windows."; |
94 return false; | 105 return false; |
95 } | 106 } |
96 | 107 |
97 } // namespace media | 108 } // namespace media |
OLD | NEW |