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

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

Issue 6686061: PipelineError is dead. Long live PipelineStatus! (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Double-delete fix for PipelineStatusNotification Created 9 years, 9 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 "media/base/composite_filter.h" 5 #include "media/base/composite_filter.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/stl_util-inl.h" 8 #include "base/stl_util-inl.h"
9 #include "media/base/callback.h" 9 #include "media/base/callback.h"
10 10
11 namespace media { 11 namespace media {
12 12
13 class CompositeFilter::FilterHostImpl : public FilterHost { 13 class CompositeFilter::FilterHostImpl : public FilterHost {
14 public: 14 public:
15 FilterHostImpl(CompositeFilter* parent, FilterHost* host); 15 FilterHostImpl(CompositeFilter* parent, FilterHost* host);
16 16
17 FilterHost* host(); 17 FilterHost* host();
18 18
19 // media::FilterHost methods. 19 // media::FilterHost methods.
20 virtual void SetError(PipelineError error); 20 virtual void SetError(PipelineStatus error);
21 virtual base::TimeDelta GetTime() const; 21 virtual base::TimeDelta GetTime() const;
22 virtual base::TimeDelta GetDuration() const; 22 virtual base::TimeDelta GetDuration() const;
23 virtual void SetTime(base::TimeDelta time); 23 virtual void SetTime(base::TimeDelta time);
24 virtual void SetDuration(base::TimeDelta duration); 24 virtual void SetDuration(base::TimeDelta duration);
25 virtual void SetBufferedTime(base::TimeDelta buffered_time); 25 virtual void SetBufferedTime(base::TimeDelta buffered_time);
26 virtual void SetTotalBytes(int64 total_bytes); 26 virtual void SetTotalBytes(int64 total_bytes);
27 virtual void SetBufferedBytes(int64 buffered_bytes); 27 virtual void SetBufferedBytes(int64 buffered_bytes);
28 virtual void SetVideoSize(size_t width, size_t height); 28 virtual void SetVideoSize(size_t width, size_t height);
29 virtual void SetStreaming(bool streaming); 29 virtual void SetStreaming(bool streaming);
30 virtual void NotifyEnded(); 30 virtual void NotifyEnded();
31 virtual void SetLoaded(bool loaded); 31 virtual void SetLoaded(bool loaded);
32 virtual void SetNetworkActivity(bool network_activity); 32 virtual void SetNetworkActivity(bool network_activity);
33 virtual void DisableAudioRenderer(); 33 virtual void DisableAudioRenderer();
34 virtual void SetCurrentReadPosition(int64 offset); 34 virtual void SetCurrentReadPosition(int64 offset);
35 virtual int64 GetCurrentReadPosition(); 35 virtual int64 GetCurrentReadPosition();
36 36
37 private: 37 private:
38 CompositeFilter* parent_; 38 CompositeFilter* parent_;
39 FilterHost* host_; 39 FilterHost* host_;
40 40
41 DISALLOW_COPY_AND_ASSIGN(FilterHostImpl); 41 DISALLOW_COPY_AND_ASSIGN(FilterHostImpl);
42 }; 42 };
43 43
44 CompositeFilter::CompositeFilter(MessageLoop* message_loop) 44 CompositeFilter::CompositeFilter(MessageLoop* message_loop)
45 : state_(kCreated), 45 : state_(kCreated),
46 sequence_index_(0), 46 sequence_index_(0),
47 message_loop_(message_loop), 47 message_loop_(message_loop),
48 error_(PIPELINE_OK) { 48 status_(PIPELINE_OK) {
49 DCHECK(message_loop); 49 DCHECK(message_loop);
50 runnable_factory_.reset( 50 runnable_factory_.reset(
51 new ScopedRunnableMethodFactory<CompositeFilter>(this)); 51 new ScopedRunnableMethodFactory<CompositeFilter>(this));
52 } 52 }
53 53
54 CompositeFilter::~CompositeFilter() { 54 CompositeFilter::~CompositeFilter() {
55 DCHECK_EQ(message_loop_, MessageLoop::current()); 55 DCHECK_EQ(message_loop_, MessageLoop::current());
56 DCHECK(state_ == kCreated || state_ == kStopped); 56 DCHECK(state_ == kCreated || state_ == kStopped);
57 57
58 filters_.clear(); 58 filters_.clear();
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 221 }
222 } 222 }
223 223
224 void CompositeFilter::ChangeState(State new_state) { 224 void CompositeFilter::ChangeState(State new_state) {
225 DCHECK_EQ(message_loop_, MessageLoop::current()); 225 DCHECK_EQ(message_loop_, MessageLoop::current());
226 state_ = new_state; 226 state_ = new_state;
227 } 227 }
228 228
229 void CompositeFilter::StartSerialCallSequence() { 229 void CompositeFilter::StartSerialCallSequence() {
230 DCHECK_EQ(message_loop_, MessageLoop::current()); 230 DCHECK_EQ(message_loop_, MessageLoop::current());
231 error_ = PIPELINE_OK; 231 status_ = PIPELINE_OK;
232 232
233 if (!filters_.empty()) { 233 if (!filters_.empty()) {
234 sequence_index_ = 0; 234 sequence_index_ = 0;
235 CallFilter(filters_[sequence_index_], 235 CallFilter(filters_[sequence_index_],
236 NewThreadSafeCallback(&CompositeFilter::SerialCallback)); 236 NewThreadSafeCallback(&CompositeFilter::SerialCallback));
237 } else { 237 } else {
238 sequence_index_ = 0; 238 sequence_index_ = 0;
239 SerialCallback(); 239 SerialCallback();
240 } 240 }
241 } 241 }
242 242
243 void CompositeFilter::StartParallelCallSequence() { 243 void CompositeFilter::StartParallelCallSequence() {
244 DCHECK_EQ(message_loop_, MessageLoop::current()); 244 DCHECK_EQ(message_loop_, MessageLoop::current());
245 error_ = PIPELINE_OK; 245 status_ = PIPELINE_OK;
246 246
247 if (!filters_.empty()) { 247 if (!filters_.empty()) {
248 sequence_index_ = 0; 248 sequence_index_ = 0;
249 for (size_t i = 0; i < filters_.size(); i++) { 249 for (size_t i = 0; i < filters_.size(); i++) {
250 CallFilter(filters_[i], 250 CallFilter(filters_[i],
251 NewThreadSafeCallback(&CompositeFilter::ParallelCallback)); 251 NewThreadSafeCallback(&CompositeFilter::ParallelCallback));
252 } 252 }
253 } else { 253 } else {
254 sequence_index_ = 0; 254 sequence_index_ = 0;
255 ParallelCallback(); 255 ParallelCallback();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 break; 322 break;
323 323
324 // default: intentionally left out to catch missing states. 324 // default: intentionally left out to catch missing states.
325 } 325 }
326 326
327 return ret; 327 return ret;
328 } 328 }
329 329
330 void CompositeFilter::SerialCallback() { 330 void CompositeFilter::SerialCallback() {
331 DCHECK_EQ(message_loop_, MessageLoop::current()); 331 DCHECK_EQ(message_loop_, MessageLoop::current());
332 if (error_ != PIPELINE_OK) { 332 if (status_ != PIPELINE_OK) {
333 // We encountered an error. Terminate the sequence now. 333 // We encountered an error. Terminate the sequence now.
334 ChangeState(kError); 334 ChangeState(kError);
335 HandleError(error_); 335 HandleError(status_);
336 return; 336 return;
337 } 337 }
338 338
339 if (!filters_.empty()) 339 if (!filters_.empty())
340 sequence_index_++; 340 sequence_index_++;
341 341
342 if (sequence_index_ == filters_.size()) { 342 if (sequence_index_ == filters_.size()) {
343 // All filters have been successfully called without error. 343 // All filters have been successfully called without error.
344 OnCallSequenceDone(); 344 OnCallSequenceDone();
345 } else if (GetNextState(state_) == kStopPending) { 345 } else if (GetNextState(state_) == kStopPending) {
346 // Abort sequence early and start issuing Stop() calls. 346 // Abort sequence early and start issuing Stop() calls.
347 ChangeState(kStopPending); 347 ChangeState(kStopPending);
348 StartSerialCallSequence(); 348 StartSerialCallSequence();
349 } else { 349 } else {
350 // We aren't done with the sequence. Call the next filter. 350 // We aren't done with the sequence. Call the next filter.
351 CallFilter(filters_[sequence_index_], 351 CallFilter(filters_[sequence_index_],
352 NewThreadSafeCallback(&CompositeFilter::SerialCallback)); 352 NewThreadSafeCallback(&CompositeFilter::SerialCallback));
353 } 353 }
354 } 354 }
355 355
356 void CompositeFilter::ParallelCallback() { 356 void CompositeFilter::ParallelCallback() {
357 DCHECK_EQ(message_loop_, MessageLoop::current()); 357 DCHECK_EQ(message_loop_, MessageLoop::current());
358 358
359 if (!filters_.empty()) 359 if (!filters_.empty())
360 sequence_index_++; 360 sequence_index_++;
361 361
362 if (sequence_index_ == filters_.size()) { 362 if (sequence_index_ == filters_.size()) {
363 if (error_ != PIPELINE_OK) { 363 if (status_ != PIPELINE_OK) {
364 // We encountered an error. 364 // We encountered an error.
365 ChangeState(kError); 365 ChangeState(kError);
366 HandleError(error_); 366 HandleError(status_);
367 return; 367 return;
368 } 368 }
369 369
370 OnCallSequenceDone(); 370 OnCallSequenceDone();
371 } 371 }
372 } 372 }
373 373
374 void CompositeFilter::OnCallSequenceDone() { 374 void CompositeFilter::OnCallSequenceDone() {
375 State next_state = GetNextState(state_); 375 State next_state = GetNextState(state_);
376 376
377 if (next_state == kInvalid) { 377 if (next_state == kInvalid) {
378 // We somehow got into an unexpected state. 378 // We somehow got into an unexpected state.
379 ChangeState(kError); 379 ChangeState(kError);
380 HandleError(PIPELINE_ERROR_INVALID_STATE); 380 HandleError(PIPELINE_ERROR_INVALID_STATE);
381 } 381 }
382 382
383 ChangeState(next_state); 383 ChangeState(next_state);
384 384
385 if (state_ == kStopPending) { 385 if (state_ == kStopPending) {
386 // Handle a deferred Stop(). 386 // Handle a deferred Stop().
387 StartSerialCallSequence(); 387 StartSerialCallSequence();
388 } else { 388 } else {
389 // Call the callback to indicate that the operation has completed. 389 // Call the callback to indicate that the operation has completed.
390 DispatchPendingCallback(); 390 DispatchPendingCallback();
391 } 391 }
392 } 392 }
393 393
394 void CompositeFilter::SendErrorToHost(PipelineError error) { 394 void CompositeFilter::SendErrorToHost(PipelineStatus error) {
395 if (host_impl_.get()) 395 if (host_impl_.get())
396 host_impl_.get()->host()->SetError(error); 396 host_impl_.get()->host()->SetError(error);
397 } 397 }
398 398
399 void CompositeFilter::HandleError(PipelineError error) { 399 void CompositeFilter::HandleError(PipelineStatus error) {
400 if (error != PIPELINE_OK) { 400 DCHECK_NE(error, PIPELINE_OK);
401 SendErrorToHost(error); 401 SendErrorToHost(error);
402 }
403
404 DispatchPendingCallback(); 402 DispatchPendingCallback();
405 } 403 }
406 404
407 FilterCallback* CompositeFilter::NewThreadSafeCallback( 405 FilterCallback* CompositeFilter::NewThreadSafeCallback(
408 void (CompositeFilter::*method)()) { 406 void (CompositeFilter::*method)()) {
409 return TaskToCallbackAdapter::NewCallback( 407 return TaskToCallbackAdapter::NewCallback(
410 NewRunnableFunction(&CompositeFilter::OnCallback, 408 NewRunnableFunction(&CompositeFilter::OnCallback,
411 message_loop_, 409 message_loop_,
412 runnable_factory_->NewRunnableMethod(method))); 410 runnable_factory_->NewRunnableMethod(method)));
413 } 411 }
(...skipping 14 matching lines...) Expand all
428 } 426 }
429 427
430 task->Run(); 428 task->Run();
431 delete task; 429 delete task;
432 } 430 }
433 431
434 bool CompositeFilter::CanForwardError() { 432 bool CompositeFilter::CanForwardError() {
435 return (state_ == kCreated) || (state_ == kPlaying) || (state_ == kPaused); 433 return (state_ == kCreated) || (state_ == kPlaying) || (state_ == kPaused);
436 } 434 }
437 435
438 void CompositeFilter::SetError(PipelineError error) { 436 void CompositeFilter::SetError(PipelineStatus error) {
439 // TODO(acolwell): Temporary hack to handle errors that occur 437 // TODO(acolwell): Temporary hack to handle errors that occur
440 // during filter initialization. In this case we just forward 438 // during filter initialization. In this case we just forward
441 // the error to the host even if it is on the wrong thread. We 439 // the error to the host even if it is on the wrong thread. We
442 // have to do this because if we defer the call, we can't be 440 // have to do this because if we defer the call, we can't be
443 // sure the host will get the error before the "init done" callback 441 // sure the host will get the error before the "init done" callback
444 // is executed. This will be cleaned up when filter init is refactored. 442 // is executed. This will be cleaned up when filter init is refactored.
445 if (state_ == kCreated) { 443 if (state_ == kCreated) {
446 SendErrorToHost(error); 444 SendErrorToHost(error);
447 return; 445 return;
448 } 446 }
449 447
450 if (message_loop_ != MessageLoop::current()) { 448 if (message_loop_ != MessageLoop::current()) {
451 message_loop_->PostTask(FROM_HERE, 449 message_loop_->PostTask(FROM_HERE,
452 NewRunnableMethod(this, &CompositeFilter::SetError, error)); 450 NewRunnableMethod(this, &CompositeFilter::SetError, error));
453 return; 451 return;
454 } 452 }
455 453
456 DCHECK_EQ(message_loop_, MessageLoop::current()); 454 DCHECK_EQ(message_loop_, MessageLoop::current());
457 455
458 // Drop errors recieved while stopping or stopped. 456 // Drop errors recieved while stopping or stopped.
459 // This shields the owner of this object from having 457 // This shields the owner of this object from having
460 // to deal with errors it can't do anything about. 458 // to deal with errors it can't do anything about.
461 if (state_ == kStopPending || state_ == kStopped) 459 if (state_ == kStopPending || state_ == kStopped)
462 return; 460 return;
463 461
464 error_ = error; 462 status_ = error;
465 if (CanForwardError()) 463 if (CanForwardError())
466 SendErrorToHost(error); 464 SendErrorToHost(error);
467 } 465 }
468 466
469 CompositeFilter::FilterHostImpl::FilterHostImpl(CompositeFilter* parent, 467 CompositeFilter::FilterHostImpl::FilterHostImpl(CompositeFilter* parent,
470 FilterHost* host) 468 FilterHost* host)
471 : parent_(parent), 469 : parent_(parent),
472 host_(host) { 470 host_(host) {
473 } 471 }
474 472
475 FilterHost* CompositeFilter::FilterHostImpl::host() { 473 FilterHost* CompositeFilter::FilterHostImpl::host() {
476 return host_; 474 return host_;
477 } 475 }
478 476
479 // media::FilterHost methods. 477 // media::FilterHost methods.
480 void CompositeFilter::FilterHostImpl::SetError(PipelineError error) { 478 void CompositeFilter::FilterHostImpl::SetError(PipelineStatus error) {
481 parent_->SetError(error); 479 parent_->SetError(error);
482 } 480 }
483 481
484 base::TimeDelta CompositeFilter::FilterHostImpl::GetTime() const { 482 base::TimeDelta CompositeFilter::FilterHostImpl::GetTime() const {
485 return host_->GetTime(); 483 return host_->GetTime();
486 } 484 }
487 485
488 base::TimeDelta CompositeFilter::FilterHostImpl::GetDuration() const { 486 base::TimeDelta CompositeFilter::FilterHostImpl::GetDuration() const {
489 return host_->GetDuration(); 487 return host_->GetDuration();
490 } 488 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 536
539 void CompositeFilter::FilterHostImpl::SetCurrentReadPosition(int64 offset) { 537 void CompositeFilter::FilterHostImpl::SetCurrentReadPosition(int64 offset) {
540 host_->SetCurrentReadPosition(offset); 538 host_->SetCurrentReadPosition(offset);
541 } 539 }
542 540
543 int64 CompositeFilter::FilterHostImpl::GetCurrentReadPosition() { 541 int64 CompositeFilter::FilterHostImpl::GetCurrentReadPosition() {
544 return host_->GetCurrentReadPosition(); 542 return host_->GetCurrentReadPosition();
545 } 543 }
546 544
547 } // namespace media 545 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698