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