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

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

Issue 1141703002: Chromium changes for static linking ffmpeg (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updating media library initialize calls Created 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "media/base/yuv_convert.h" 12 #include "media/base/yuv_convert.h"
13 13
14 #if !defined(MEDIA_DISABLE_FFMPEG)
15 #include "media/ffmpeg/ffmpeg_common.h"
16 #endif
17
14 namespace media { 18 namespace media {
15 19
16 namespace internal { 20 namespace internal {
17 // Platform specific initialization method. 21 // Platform specific initialization method.
18 extern bool InitializeMediaLibraryInternal(const base::FilePath& module_dir); 22 extern void InitializeMediaLibraryInternal();
19 } // namespace internal 23 } // namespace internal
20 24
21 // Media must only be initialized once, so use a LazyInstance to ensure this. 25 // Media must only be initialized once, so use a LazyInstance to ensure this.
22 class MediaInitializer { 26 class MediaInitializer {
23 public: 27 public:
24 bool Initialize(const base::FilePath& module_dir) { 28 void Initialize() {
25 base::AutoLock auto_lock(lock_); 29 base::AutoLock auto_lock(lock_);
26 if (!tried_initialize_) { 30 if (!initialized_) {
27 tried_initialize_ = true; 31 #if !defined(MEDIA_DISABLE_FFMPEG)
28 initialized_ = internal::InitializeMediaLibraryInternal(module_dir); 32 // Disable logging as it interferes with layout tests.
33 av_log_set_level(AV_LOG_QUIET);
34
35 #if defined(ALLOCATOR_SHIM)
36 // Remove allocation limit from ffmpeg, so calls go down to shim layer.
37 av_max_alloc(0);
38 #endif // defined(ALLOCATOR_SHIM)
39
40 #endif // !defined(MEDIA_DISABLE_FFMPEG)
41
42 initialized_ = true;
29 } 43 }
30 return initialized_;
31 }
32
33 bool IsInitialized() {
34 base::AutoLock auto_lock(lock_);
35 return initialized_;
36 } 44 }
37 45
38 private: 46 private:
39 friend struct base::DefaultLazyInstanceTraits<MediaInitializer>; 47 friend struct base::DefaultLazyInstanceTraits<MediaInitializer>;
40 48
41 MediaInitializer() 49 MediaInitializer() : initialized_(false) {
42 : initialized_(false),
43 tried_initialize_(false) {
44 // Perform initialization of libraries which require runtime CPU detection. 50 // Perform initialization of libraries which require runtime CPU detection.
45 InitializeCPUSpecificYUVConversions(); 51 InitializeCPUSpecificYUVConversions();
46 } 52 }
47 53
48 ~MediaInitializer() { 54 ~MediaInitializer() {
49 NOTREACHED() << "MediaInitializer should be leaky!"; 55 NOTREACHED() << "MediaInitializer should be leaky!";
50 } 56 }
51 57
52 base::Lock lock_; 58 base::Lock lock_;
53 bool initialized_; 59 bool initialized_;
54 bool tried_initialize_;
55 60
56 DISALLOW_COPY_AND_ASSIGN(MediaInitializer); 61 DISALLOW_COPY_AND_ASSIGN(MediaInitializer);
57 }; 62 };
58 63
59 static base::LazyInstance<MediaInitializer>::Leaky g_media_library = 64 static base::LazyInstance<MediaInitializer>::Leaky g_media_library =
60 LAZY_INSTANCE_INITIALIZER; 65 LAZY_INSTANCE_INITIALIZER;
61 66
62 bool InitializeMediaLibrary(const base::FilePath& module_dir) { 67 void InitializeMediaLibrary() {
63 return g_media_library.Get().Initialize(module_dir); 68 g_media_library.Get().Initialize();
64 }
65
66 void InitializeMediaLibraryForTesting() {
67 base::FilePath module_dir;
68 CHECK(PathService::Get(base::DIR_EXE, &module_dir));
69 CHECK(g_media_library.Get().Initialize(module_dir));
70 }
71
72 bool IsMediaLibraryInitialized() {
73 return g_media_library.Get().IsInitialized();
74 } 69 }
75 70
76 void InitializeCPUSpecificMediaFeatures() { 71 void InitializeCPUSpecificMediaFeatures() {
77 // Force initialization of the media initializer, but don't call Initialize(). 72 // Force initialization of the media initializer, but don't call Initialize().
78 g_media_library.Get(); 73 g_media_library.Get();
79 } 74 }
80 75
81 } // namespace media 76 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698