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

Side by Side Diff: media/filters/ffmpeg_glue.cc

Issue 5581008: Add a new GetInstance() method for singleton classes, take 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years 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) 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 "base/string_util.h" 5 #include "base/string_util.h"
6 #include "media/base/filters.h" 6 #include "media/base/filters.h"
7 #include "media/ffmpeg/ffmpeg_common.h" 7 #include "media/ffmpeg/ffmpeg_common.h"
8 #include "media/filters/ffmpeg_glue.h" 8 #include "media/filters/ffmpeg_glue.h"
9 9
10 namespace { 10 namespace {
11 11
12 media::FFmpegURLProtocol* ToProtocol(void* data) { 12 media::FFmpegURLProtocol* ToProtocol(void* data) {
13 return reinterpret_cast<media::FFmpegURLProtocol*>(data); 13 return reinterpret_cast<media::FFmpegURLProtocol*>(data);
14 } 14 }
15 15
16 // FFmpeg protocol interface. 16 // FFmpeg protocol interface.
17 int OpenContext(URLContext* h, const char* filename, int flags) { 17 int OpenContext(URLContext* h, const char* filename, int flags) {
18 media::FFmpegURLProtocol* protocol; 18 media::FFmpegURLProtocol* protocol;
19 media::FFmpegGlue::get()->GetProtocol(filename, &protocol); 19 media::FFmpegGlue::GetInstance()->GetProtocol(filename, &protocol);
20 if (!protocol) 20 if (!protocol)
21 return AVERROR_IO; 21 return AVERROR_IO;
22 22
23 h->priv_data = protocol; 23 h->priv_data = protocol;
24 h->flags = URL_RDONLY; 24 h->flags = URL_RDONLY;
25 h->is_streamed = protocol->IsStreaming(); 25 h->is_streamed = protocol->IsStreaming();
26 return 0; 26 return 0;
27 } 27 }
28 28
29 int ReadContext(URLContext* h, unsigned char* buf, int size) { 29 int ReadContext(URLContext* h, unsigned char* buf, int size) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 av_lockmgr_register(&LockManagerOperation); 138 av_lockmgr_register(&LockManagerOperation);
139 139
140 // Now register the rest of FFmpeg. 140 // Now register the rest of FFmpeg.
141 av_register_all(); 141 av_register_all();
142 } 142 }
143 143
144 FFmpegGlue::~FFmpegGlue() { 144 FFmpegGlue::~FFmpegGlue() {
145 av_lockmgr_register(NULL); 145 av_lockmgr_register(NULL);
146 } 146 }
147 147
148 // static
149 FFmpegGlue* FFmpegGlue::GetInstance() {
150 return Singleton<FFmpegGlue>::get();
151 }
152
148 std::string FFmpegGlue::AddProtocol(FFmpegURLProtocol* protocol) { 153 std::string FFmpegGlue::AddProtocol(FFmpegURLProtocol* protocol) {
149 AutoLock auto_lock(lock_); 154 AutoLock auto_lock(lock_);
150 std::string key = GetProtocolKey(protocol); 155 std::string key = GetProtocolKey(protocol);
151 if (protocols_.find(key) == protocols_.end()) { 156 if (protocols_.find(key) == protocols_.end()) {
152 protocols_[key] = protocol; 157 protocols_[key] = protocol;
153 } 158 }
154 return key; 159 return key;
155 } 160 }
156 161
157 void FFmpegGlue::RemoveProtocol(FFmpegURLProtocol* protocol) { 162 void FFmpegGlue::RemoveProtocol(FFmpegURLProtocol* protocol) {
(...skipping 20 matching lines...) Expand all
178 } 183 }
179 184
180 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { 185 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) {
181 // Use the FFmpegURLProtocol's memory address to generate the unique string. 186 // Use the FFmpegURLProtocol's memory address to generate the unique string.
182 // This also has the nice property that adding the same FFmpegURLProtocol 187 // This also has the nice property that adding the same FFmpegURLProtocol
183 // reference will not generate duplicate entries. 188 // reference will not generate duplicate entries.
184 return StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); 189 return StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol));
185 } 190 }
186 191
187 } // namespace media 192 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698