Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 case tp_ffmpeg::kModuleAvformat52: | 59 case tp_ffmpeg::kModuleAvformat52: |
| 60 return FILE_PATH_LITERAL(DSO_NAME("avformat", AVFORMAT_VERSION)); | 60 return FILE_PATH_LITERAL(DSO_NAME("avformat", AVFORMAT_VERSION)); |
| 61 case tp_ffmpeg::kModuleAvutil50: | 61 case tp_ffmpeg::kModuleAvutil50: |
| 62 return FILE_PATH_LITERAL(DSO_NAME("avutil", AVUTIL_VERSION)); | 62 return FILE_PATH_LITERAL(DSO_NAME("avutil", AVUTIL_VERSION)); |
| 63 default: | 63 default: |
| 64 LOG(DFATAL) << "Invalid stub module requested: " << stub_key; | 64 LOG(DFATAL) << "Invalid stub module requested: " << stub_key; |
| 65 return FILE_PATH_LITERAL(""); | 65 return FILE_PATH_LITERAL(""); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 static bool g_media_library_is_initialized = false; | |
|
awong
2011/02/25 02:41:59
If it's in an anonymous namespace, don't bother wi
| |
| 70 | |
| 69 } // namespace | 71 } // namespace |
| 70 | 72 |
| 71 // Attempts to initialize the media library (loading DSOs, etc.). | 73 // Attempts to initialize the media library (loading DSOs, etc.). |
| 72 // Returns true if everything was successfully initialized, false otherwise. | 74 // Returns true if everything was successfully initialized, false otherwise. |
| 73 bool InitializeMediaLibrary(const FilePath& module_dir) { | 75 void InitializeMediaLibrary(const FilePath& module_dir) { |
| 76 if (g_media_library_is_initialized) | |
| 77 return; | |
| 78 | |
| 74 // TODO(ajwong): We need error resolution. | 79 // TODO(ajwong): We need error resolution. |
| 75 tp_ffmpeg::StubPathMap paths; | 80 tp_ffmpeg::StubPathMap paths; |
| 76 for (int i = 0; i < static_cast<int>(tp_ffmpeg::kNumStubModules); ++i) { | 81 for (int i = 0; i < static_cast<int>(tp_ffmpeg::kNumStubModules); ++i) { |
| 77 tp_ffmpeg::StubModules module = static_cast<tp_ffmpeg::StubModules>(i); | 82 tp_ffmpeg::StubModules module = static_cast<tp_ffmpeg::StubModules>(i); |
| 78 | 83 |
| 79 // Add the sumo library first so it takes precedence. | 84 // Add the sumo library first so it takes precedence. |
| 80 paths[module].push_back(module_dir.Append(sumo_name).value()); | 85 paths[module].push_back(module_dir.Append(sumo_name).value()); |
| 81 | 86 |
| 82 // Add the more specific FFmpeg library name. | 87 // Add the more specific FFmpeg library name. |
| 83 FilePath path = module_dir.Append(GetDSOName(module)); | 88 FilePath path = module_dir.Append(GetDSOName(module)); |
| 84 paths[module].push_back(path.value()); | 89 paths[module].push_back(path.value()); |
| 85 } | 90 } |
| 86 | 91 |
| 87 bool ret = tp_ffmpeg::InitializeStubs(paths); | 92 g_media_library_is_initialized = tp_ffmpeg::InitializeStubs(paths); |
| 88 return ret; | 93 } |
| 94 | |
| 95 bool IsMediaLibraryInitialized() { | |
| 96 return g_media_library_is_initialized; | |
| 89 } | 97 } |
| 90 | 98 |
| 91 #if defined(OS_LINUX) | 99 #if defined(OS_LINUX) |
| 92 namespace tp_openmax = third_party_openmax; | 100 namespace tp_openmax = third_party_openmax; |
| 93 bool InitializeOpenMaxLibrary(const FilePath& module_dir) { | 101 bool InitializeOpenMaxLibrary(const FilePath& module_dir) { |
| 94 // TODO(ajwong): We need error resolution. | 102 // TODO(ajwong): We need error resolution. |
| 95 tp_openmax::StubPathMap paths; | 103 tp_openmax::StubPathMap paths; |
| 96 for (int i = 0; i < static_cast<int>(tp_openmax::kNumStubModules); ++i) { | 104 for (int i = 0; i < static_cast<int>(tp_openmax::kNumStubModules); ++i) { |
| 97 tp_openmax::StubModules module = static_cast<tp_openmax::StubModules>(i); | 105 tp_openmax::StubModules module = static_cast<tp_openmax::StubModules>(i); |
| 98 | 106 |
| 99 // Add the OpenMAX library first so it takes precedence. | 107 // Add the OpenMAX library first so it takes precedence. |
| 100 paths[module].push_back(module_dir.Append(openmax_name).value()); | 108 paths[module].push_back(module_dir.Append(openmax_name).value()); |
| 101 } | 109 } |
| 102 | 110 |
| 103 bool result = tp_openmax::InitializeStubs(paths); | 111 bool result = tp_openmax::InitializeStubs(paths); |
| 104 if (!result) { | 112 if (!result) { |
| 105 LOG(FATAL) << "Cannot load " << openmax_name << "." | 113 LOG(FATAL) << "Cannot load " << openmax_name << "." |
| 106 << " Make sure it exists for OpenMAX."; | 114 << " Make sure it exists for OpenMAX."; |
| 107 } | 115 } |
| 108 return result; | 116 return result; |
| 109 } | 117 } |
| 110 #else | 118 #else |
| 111 bool InitializeOpenMaxLibrary(const FilePath& module_dir) { | 119 bool InitializeOpenMaxLibrary(const FilePath& module_dir) { |
| 112 NOTIMPLEMENTED() << "OpenMAX is only used in Linux."; | 120 NOTIMPLEMENTED() << "OpenMAX is only used in Linux."; |
| 113 return false; | 121 return false; |
| 114 } | 122 } |
| 115 #endif | 123 #endif |
| 116 | 124 |
| 117 } // namespace media | 125 } // namespace media |
| OLD | NEW |