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

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

Issue 6969026: Convert Filter::Seek() to use new callback system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add files in content/renderer/media Created 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/bind.h"
5 #include "base/logging.h" 6 #include "base/logging.h"
6 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
7 #include "base/string_split.h" 8 #include "base/string_split.h"
8 #include "base/string_util.h" 9 #include "base/string_util.h"
9 #include "media/filters/adaptive_demuxer.h" 10 #include "media/filters/adaptive_demuxer.h"
10 11
11 namespace media { 12 namespace media {
12 13
13 // 14 //
14 // AdaptiveDemuxerStream 15 // AdaptiveDemuxerStream
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 orig_cb_->Run(); 185 orig_cb_->Run();
185 delete this; 186 delete this;
186 } 187 }
187 } 188 }
188 189
189 base::Lock lock_; 190 base::Lock lock_;
190 int remaining_count_; 191 int remaining_count_;
191 scoped_ptr<FilterCallback> orig_cb_; 192 scoped_ptr<FilterCallback> orig_cb_;
192 }; 193 };
193 194
195 // Helper class that wraps FilterStatusCB and expects to get called a set
Ami GONE FROM CHROMIUM 2011/05/12 20:42:16 Sad panda that this has to coexist w/ CountingCall
acolwell GONE FROM CHROMIUM 2011/05/12 22:30:40 Agreed. It won't last too long. Once I convert Sto
196 // number of times, after which the wrapped callback is fired. If an error
197 // is reported in any of the callbacks, only the first error code is passed
198 // to the wrapped callback.
199 class CountingStatusCB {
200 public:
201 CountingStatusCB(int count, const FilterStatusCB& orig_cb)
202 : remaining_count_(count), orig_cb_(orig_cb),
203 overall_status_(PIPELINE_OK) {
204 DCHECK_GT(remaining_count_, 0);
205 DCHECK(!orig_cb.is_null());
206 }
207
208 FilterStatusCB GetACallback() {
209 return base::Bind(&CountingStatusCB::OnChildCallbackDone,
210 base::Unretained(this));
Ami GONE FROM CHROMIUM 2011/05/12 20:42:16 I think if you drop the unretained then you can al
acolwell GONE FROM CHROMIUM 2011/05/12 22:30:40 Yes. I had to derive from RefCountedThreadSafe<> t
211 }
212
213 private:
214 void OnChildCallbackDone(PipelineStatus status) {
215 bool fire_orig_cb = false;
216 PipelineStatus overall_status = PIPELINE_OK;
217
218 {
219 base::AutoLock auto_lock(lock_);
220
221 if (overall_status_ == PIPELINE_OK && status != PIPELINE_OK)
222 overall_status_ = status;
223
224 if (--remaining_count_ == 0) {
225 fire_orig_cb = true;
226 overall_status = overall_status_;
227 }
228 }
229
230 if (fire_orig_cb) {
231 orig_cb_.Run(overall_status);
232 delete this;
233 }
234 }
235
236 base::Lock lock_;
237 int remaining_count_;
238 FilterStatusCB orig_cb_;
239 PipelineStatus overall_status_;
240 };
241
194 void AdaptiveDemuxer::Stop(FilterCallback* callback) { 242 void AdaptiveDemuxer::Stop(FilterCallback* callback) {
195 // Stop() must be called on all of the demuxers even though only one demuxer 243 // Stop() must be called on all of the demuxers even though only one demuxer
196 // is actively delivering audio and another one is delivering video. This 244 // is actively delivering audio and another one is delivering video. This
197 // just satisfies the contract that all demuxers must have Stop() called on 245 // just satisfies the contract that all demuxers must have Stop() called on
198 // them before they are destroyed. 246 // them before they are destroyed.
199 CountingCallback* wrapper = new CountingCallback(demuxers_.size(), callback); 247 CountingCallback* wrapper = new CountingCallback(demuxers_.size(), callback);
200 for (size_t i = 0; i < demuxers_.size(); ++i) 248 for (size_t i = 0; i < demuxers_.size(); ++i)
201 demuxers_[i]->Stop(wrapper->GetACallback()); 249 demuxers_[i]->Stop(wrapper->GetACallback());
202 } 250 }
203 251
204 void AdaptiveDemuxer::Seek(base::TimeDelta time, FilterCallback* callback) { 252 void AdaptiveDemuxer::Seek(base::TimeDelta time, const FilterStatusCB& cb) {
205 Demuxer* audio = current_demuxer(DemuxerStream::AUDIO); 253 Demuxer* audio = current_demuxer(DemuxerStream::AUDIO);
206 Demuxer* video = current_demuxer(DemuxerStream::VIDEO); 254 Demuxer* video = current_demuxer(DemuxerStream::VIDEO);
207 int count = (audio ? 1 : 0) + (video && audio != video ? 1 : 0); 255 int count = (audio ? 1 : 0) + (video && audio != video ? 1 : 0);
208 CountingCallback* wrapper = new CountingCallback(count, callback); 256 CountingStatusCB* wrapper = new CountingStatusCB(count, cb);
209 if (audio) 257 if (audio)
210 audio->Seek(time, wrapper->GetACallback()); 258 audio->Seek(time, wrapper->GetACallback());
211 if (video && audio != video) 259 if (video && audio != video)
212 video->Seek(time, wrapper->GetACallback()); 260 video->Seek(time, wrapper->GetACallback());
213 } 261 }
214 262
215 void AdaptiveDemuxer::OnAudioRendererDisabled() { 263 void AdaptiveDemuxer::OnAudioRendererDisabled() {
216 for (size_t i = 0; i < demuxers_.size(); ++i) 264 for (size_t i = 0; i < demuxers_.size(); ++i)
217 demuxers_[i]->OnAudioRendererDisabled(); 265 demuxers_[i]->OnAudioRendererDisabled();
218 } 266 }
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 delete cb; 482 delete cb;
435 return; 483 return;
436 } 484 }
437 DemuxerAccumulator* accumulator = new DemuxerAccumulator( 485 DemuxerAccumulator* accumulator = new DemuxerAccumulator(
438 audio_index, video_index, urls.size(), cb); 486 audio_index, video_index, urls.size(), cb);
439 for (size_t i = 0; i < urls.size(); ++i) 487 for (size_t i = 0; i < urls.size(); ++i)
440 delegate_factory_->Build(urls[i], accumulator->GetNthCallback(i)); 488 delegate_factory_->Build(urls[i], accumulator->GetNthCallback(i));
441 } 489 }
442 490
443 } // namespace media 491 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698