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

Side by Side Diff: media/base/mock_media_filters.h

Issue 39170: Pipeline_Impl was modified to properly render a stream that has video but no ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #ifndef MEDIA_BASE_MOCK_MEDIA_FILTERS_H_ 5 #ifndef MEDIA_BASE_MOCK_MEDIA_FILTERS_H_
6 #define MEDIA_BASE_MOCK_MEDIA_FILTERS_H_ 6 #define MEDIA_BASE_MOCK_MEDIA_FILTERS_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/waitable_event.h" 10 #include "base/waitable_event.h"
11 #include "media/base/buffers.h" 11 #include "media/base/buffers.h"
12 #include "media/base/factory.h" 12 #include "media/base/factory.h"
13 #include "media/base/filter_host.h" 13 #include "media/base/filter_host.h"
14 #include "media/base/filters.h" 14 #include "media/base/filters.h"
15 #include "media/base/media_format.h" 15 #include "media/base/media_format.h"
16 #include "media/base/pipeline.h" 16 #include "media/base/pipeline.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace media { 19 namespace media {
20 20
21 // Behaviors for MockDataSource filter. 21 // Behaviors for MockDataSource filter.
22 enum MockDataSourceBehavior { 22 enum MockDataSourceBehavior {
23 MOCK_DATA_SOURCE_NORMAL_INIT, 23 MOCK_DATA_SOURCE_NORMAL_INIT,
24 MOCK_DATA_SOURCE_NEVER_INIT, 24 MOCK_DATA_SOURCE_NEVER_INIT,
25 MOCK_DATA_SOURCE_TASK_INIT, 25 MOCK_DATA_SOURCE_TASK_INIT,
26 MOCK_DATA_SOURCE_ERROR_IN_INIT, 26 MOCK_DATA_SOURCE_URL_ERROR_IN_INIT,
27 MOCK_DATA_SOURCE_INIT_RETURN_FALSE, 27 MOCK_DATA_SOURCE_INIT_RETURN_FALSE,
28 MOCK_DATA_SOURCE_TASK_ERROR_PRE_INIT, 28 MOCK_DATA_SOURCE_TASK_ERROR_PRE_INIT,
29 MOCK_DATA_SOURCE_TASK_ERROR_POST_INIT 29 MOCK_DATA_SOURCE_TASK_ERROR_POST_INIT
30 }; 30 };
31 31
32 32
33 // This class is used by all of the mock filters to change the configuration 33 // This class is used by all of the mock filters to change the configuration
34 // of the desired pipeline. The test using this must ensure that the lifetime 34 // of the desired pipeline. The test using this must ensure that the lifetime
35 // of the object is at least as long as the lifetime of the filters, as this 35 // of the object is at least as long as the lifetime of the filters, as this
36 // is typically allocated on the stack. 36 // is typically allocated on the stack.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 return true; 89 return true;
90 case MOCK_DATA_SOURCE_NEVER_INIT: 90 case MOCK_DATA_SOURCE_NEVER_INIT:
91 return true; 91 return true;
92 case MOCK_DATA_SOURCE_TASK_ERROR_POST_INIT: 92 case MOCK_DATA_SOURCE_TASK_ERROR_POST_INIT:
93 host_->InitializationComplete(); 93 host_->InitializationComplete();
94 // Yes, we want to fall through to schedule the task... 94 // Yes, we want to fall through to schedule the task...
95 case MOCK_DATA_SOURCE_TASK_ERROR_PRE_INIT: 95 case MOCK_DATA_SOURCE_TASK_ERROR_PRE_INIT:
96 case MOCK_DATA_SOURCE_TASK_INIT: 96 case MOCK_DATA_SOURCE_TASK_INIT:
97 host_->PostTask(NewRunnableMethod(this, &MockDataSource::TaskBehavior)); 97 host_->PostTask(NewRunnableMethod(this, &MockDataSource::TaskBehavior));
98 return true; 98 return true;
99 case MOCK_DATA_SOURCE_ERROR_IN_INIT: 99 case MOCK_DATA_SOURCE_URL_ERROR_IN_INIT:
100 host_->Error(PIPELINE_ERROR_NETWORK); 100 host_->Error(PIPELINE_ERROR_URL_NOT_FOUND);
101 return false; 101 return false;
102 case MOCK_DATA_SOURCE_INIT_RETURN_FALSE: 102 case MOCK_DATA_SOURCE_INIT_RETURN_FALSE:
103 return false; 103 return false;
104 default: 104 default:
105 NOTREACHED(); 105 NOTREACHED();
106 return false; 106 return false;
107 } 107 }
108 } 108 }
109 109
110 virtual const MediaFormat* GetMediaFormat() { 110 virtual const MediaFormat* GetMediaFormat() {
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 522
523 virtual ~MockVideoRenderer() {} 523 virtual ~MockVideoRenderer() {}
524 524
525 const MockFilterConfig* config_; 525 const MockFilterConfig* config_;
526 526
527 DISALLOW_COPY_AND_ASSIGN(MockVideoRenderer); 527 DISALLOW_COPY_AND_ASSIGN(MockVideoRenderer);
528 }; 528 };
529 529
530 530
531 //------------------------------------------------------------------------------ 531 //------------------------------------------------------------------------------
532 // Simple class that derives from the WaitableEvent class. The event remains 532 // A simple class that waits for a pipeline to be started and checks some
533 // in the reset state until the initialization complete callback is called from 533 // basic initialization values. The Start() method will not return until
534 // a media pipeline. The normal use of this object looks like: 534 // either a pre-dermined amount of time has passed or the pipeline calls the
535 // InitCallback() callback. A typical use would be:
535 // Pipeline p; 536 // Pipeline p;
536 // FilterFactoryCollection f; 537 // FilterFactoryCollection f;
537 // f->AddFactory(a); 538 // f->AddFactory(a);
538 // f->AddFactory(b); 539 // f->AddFactory(b);
539 // ... 540 // ...
540 // InitializationHelper h; 541 // InitializationHelper h;
541 // h.Start(&p, f, uri); 542 // h.Start(&p, f, uri);
542 // h.Wait(); 543 //
543 // (when the Wait() returns, the pipeline is initialized or in error state) 544 // If the test is expecting to produce an error use would be:
544 class InitializationHelper : public base::WaitableEvent { 545 // h.Start(&p, f, uri, PIPELINE_ERROR_REQUIRED_FILTER_MISSING)
546 //
547 // If the test expects the pipeline to hang during initialization (a filter
548 // never calls FilterHost::InitializationComplete()) then the use would be:
549 // h.Start(&p, f, uri, PIPELINE_OK, true);
550 class InitializationHelper {
545 public: 551 public:
546 InitializationHelper() 552 InitializationHelper()
547 : WaitableEvent(true, false), 553 : event_(true, false),
548 callback_success_status_(false), 554 callback_success_status_(false),
549 waiting_for_callback_(false) {} 555 waiting_for_callback_(false) {}
550 556
551 // If callback has been called, then returns the boolean passed by the 557 // If callback has been called, then returns the boolean passed by the
552 // pipeline to the callback. 558 // pipeline to the callback.
553 bool callback_success_status() { return callback_success_status_; } 559 bool callback_success_status() { return callback_success_status_; }
554 560
555 // Returns true if Start has been called, but the pipeline has not yet 561 // Returns true if Start has been called, but the pipeline has not yet
556 // called the intialization complete callback. 562 // called the intialization complete callback.
557 bool waiting_for_callback() { return waiting_for_callback_; } 563 bool waiting_for_callback() { return waiting_for_callback_; }
558 564
559 // Starts the pipeline, providing an initialization callback that points 565 // Starts the pipeline, providing an initialization callback that points
560 // to this object. 566 // to this object.
561 void Start(Pipeline* pipeline, 567 void Start(Pipeline* pipeline,
562 FilterFactory* filter_factory, 568 FilterFactory* filter_factory,
563 const std::string& uri) { 569 const std::string& uri,
564 Reset(); 570 PipelineError expect_error = PIPELINE_OK,
571 bool expect_hang = false) {
572 // For tests that we expect to hang in initialization, we want to
573 // wait a short time. If a hang is not expected, then wait long enough
574 // to make sure that the filters have time to initalize. 1/2 second if
575 // we expect to hang, and 3 seconds if we expect success.
576 base::TimeDelta max_wait = base::TimeDelta::FromMilliseconds(expect_hang ?
577 500 : 3000);
578 EXPECT_FALSE(waiting_for_callback_);
565 waiting_for_callback_ = true; 579 waiting_for_callback_ = true;
580 callback_success_status_ = false;
581 event_.Reset();
566 pipeline->Start(filter_factory, uri, 582 pipeline->Start(filter_factory, uri,
567 NewCallback(this, &InitializationHelper::InitCallback)); 583 NewCallback(this, &InitializationHelper::InitCallback));
568 } 584 bool signaled = event_.TimedWait(max_wait);
569 585 if (expect_hang) {
570 // Resets the state. This method should not be called if waiting for 586 EXPECT_FALSE(signaled);
571 // a callback from a previous call to Start. Note that the Start method 587 EXPECT_FALSE(pipeline->IsInitialized());
572 // resets the state, so callers are not required to call this method prior 588 EXPECT_TRUE(waiting_for_callback_);
573 // to calling the start method. 589 } else {
574 void Reset() { 590 EXPECT_TRUE(signaled);
575 EXPECT_FALSE(waiting_for_callback_); 591 EXPECT_FALSE(waiting_for_callback_);
576 base::WaitableEvent::Reset(); 592 EXPECT_EQ(pipeline->GetError(), expect_error);
577 callback_success_status_ = false; 593 EXPECT_EQ(callback_success_status_, (expect_error == PIPELINE_OK));
594 EXPECT_EQ(pipeline->IsInitialized(), (expect_error == PIPELINE_OK));
595 }
578 } 596 }
579 597
580 private: 598 private:
581 void InitCallback(bool success) { 599 void InitCallback(bool success) {
582 EXPECT_TRUE(waiting_for_callback_); 600 EXPECT_TRUE(waiting_for_callback_);
583 EXPECT_FALSE(IsSignaled()); 601 EXPECT_FALSE(event_.IsSignaled());
584 waiting_for_callback_ = false; 602 waiting_for_callback_ = false;
585 callback_success_status_ = success; 603 callback_success_status_ = success;
586 Signal(); 604 event_.Signal();
587 } 605 }
588 606
607 base::WaitableEvent event_;
589 bool callback_success_status_; 608 bool callback_success_status_;
590 bool waiting_for_callback_; 609 bool waiting_for_callback_;
591 610
592 DISALLOW_COPY_AND_ASSIGN(InitializationHelper); 611 DISALLOW_COPY_AND_ASSIGN(InitializationHelper);
593 }; 612 };
594 613
595 } // namespace media 614 } // namespace media
596 615
597 #endif // MEDIA_BASE_MOCK_MEDIA_FILTERS_H_ 616 #endif // MEDIA_BASE_MOCK_MEDIA_FILTERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698