Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: media/base/media_win.cc

Issue 14891002: Remove function level static initializers media library initialization. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moar typos. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"; 22 bool for_testing) {
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 23 // LoadLibraryEx(..., LOAD_WITH_ALTERED_SEARCH_PATH) cannot handle
35 // relative path. 24 // relative path.
36 if (!base_path.IsAbsolute()) 25 if (!module_dir.IsAbsolute())
37 return false; 26 return false;
38 27
39 // Use alternate DLL search path so we don't load dependencies from the 28 // Use alternate DLL search path so we don't load dependencies from the
40 // system path. Refer to http://crbug.com/35857 29 // system path. Refer to http://crbug.com/35857
30 static const char kFFmpegDLL[] = "ffmpegsumo.dll";
41 HMODULE lib = ::LoadLibraryEx( 31 HMODULE lib = ::LoadLibraryEx(
42 base_path.AppendASCII(kFFmpegDLL).value().c_str(), NULL, 32 module_dir.AppendASCII(kFFmpegDLL).value().c_str(), NULL,
43 LOAD_WITH_ALTERED_SEARCH_PATH); 33 LOAD_WITH_ALTERED_SEARCH_PATH);
44 34
45 // Check that we loaded the library successfully. 35 // Check that we loaded the library successfully.
46 g_media_library_is_initialized = (lib != NULL); 36 return lib != NULL;
47 return g_media_library_is_initialized;
48 } 37 }
49 38
50 bool InitializeMediaLibrary(const base::FilePath& base_path) { 39 } // 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 40 } // namespace media
OLDNEW
« media/base/media_android.cc ('K') | « media/base/media_stub.cc ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698