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

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: Rebase. 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
« no previous file with comments | « media/base/media_stub.cc ('k') | media/base/run_all_unittests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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";
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 22 // LoadLibraryEx(..., LOAD_WITH_ALTERED_SEARCH_PATH) cannot handle
35 // relative path. 23 // relative path.
36 if (!base_path.IsAbsolute()) 24 if (!module_dir.IsAbsolute())
37 return false; 25 return false;
38 26
39 // Use alternate DLL search path so we don't load dependencies from the 27 // Use alternate DLL search path so we don't load dependencies from the
40 // system path. Refer to http://crbug.com/35857 28 // system path. Refer to http://crbug.com/35857
29 static const char kFFmpegDLL[] = "ffmpegsumo.dll";
41 HMODULE lib = ::LoadLibraryEx( 30 HMODULE lib = ::LoadLibraryEx(
42 base_path.AppendASCII(kFFmpegDLL).value().c_str(), NULL, 31 module_dir.AppendASCII(kFFmpegDLL).value().c_str(), NULL,
43 LOAD_WITH_ALTERED_SEARCH_PATH); 32 LOAD_WITH_ALTERED_SEARCH_PATH);
44 33
45 // Check that we loaded the library successfully. 34 // Check that we loaded the library successfully.
46 g_media_library_is_initialized = (lib != NULL); 35 return lib != NULL;
47 return g_media_library_is_initialized;
48 } 36 }
49 37
50 bool InitializeMediaLibrary(const base::FilePath& base_path) { 38 } // 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 39 } // namespace media
OLDNEW
« no previous file with comments | « media/base/media_stub.cc ('k') | media/base/run_all_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698