| OLD | NEW |
| 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 <deque> | 5 #include <deque> |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "media/base/filters.h" | 9 #include "media/base/filters.h" |
| 10 #include "media/base/mock_ffmpeg.h" | 10 #include "media/base/mock_ffmpeg.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 static const int kWidth; | 58 static const int kWidth; |
| 59 static const int kHeight; | 59 static const int kHeight; |
| 60 | 60 |
| 61 static const size_t kDataSize; | 61 static const size_t kDataSize; |
| 62 static const uint8 kAudioData[]; | 62 static const uint8 kAudioData[]; |
| 63 static const uint8 kVideoData[]; | 63 static const uint8 kVideoData[]; |
| 64 static const uint8* kNullData; | 64 static const uint8* kNullData; |
| 65 | 65 |
| 66 FFmpegDemuxerTest() { | 66 FFmpegDemuxerTest() { |
| 67 // Create an FFmpegDemuxer. | 67 // Create an FFmpegDemuxer. |
| 68 demuxer_ = new FFmpegDemuxer(); | 68 demuxer_ = new FFmpegDemuxer(&message_loop_); |
| 69 DCHECK(demuxer_); | 69 DCHECK(demuxer_); |
| 70 | 70 |
| 71 // Inject a filter host and message loop and prepare a data source. | 71 // Inject a filter host and message loop and prepare a data source. |
| 72 demuxer_->set_host(&host_); | 72 demuxer_->set_host(&host_); |
| 73 demuxer_->set_message_loop(&message_loop_); | |
| 74 data_source_ = new StrictMock<MockDataSource>(); | 73 data_source_ = new StrictMock<MockDataSource>(); |
| 75 | 74 |
| 76 // Initialize FFmpeg fixtures. | 75 // Initialize FFmpeg fixtures. |
| 77 memset(&format_context_, 0, sizeof(format_context_)); | 76 memset(&format_context_, 0, sizeof(format_context_)); |
| 78 memset(&input_format_, 0, sizeof(input_format_)); | 77 memset(&input_format_, 0, sizeof(input_format_)); |
| 79 memset(&streams_, 0, sizeof(streams_)); | 78 memset(&streams_, 0, sizeof(streams_)); |
| 80 memset(&codecs_, 0, sizeof(codecs_)); | 79 memset(&codecs_, 0, sizeof(codecs_)); |
| 81 | 80 |
| 82 // Initialize AVCodecContext structures. | 81 // Initialize AVCodecContext structures. |
| 83 codecs_[AV_STREAM_DATA].codec_type = CODEC_TYPE_DATA; | 82 codecs_[AV_STREAM_DATA].codec_type = CODEC_TYPE_DATA; |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 ASSERT_TRUE(video); | 630 ASSERT_TRUE(video); |
| 632 | 631 |
| 633 // Attempt a read from the video stream and run the message loop until done. | 632 // Attempt a read from the video stream and run the message loop until done. |
| 634 scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader()); | 633 scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader()); |
| 635 reader->Read(video); | 634 reader->Read(video); |
| 636 message_loop_.RunAllPending(); | 635 message_loop_.RunAllPending(); |
| 637 } | 636 } |
| 638 | 637 |
| 639 class MockFFmpegDemuxer : public FFmpegDemuxer { | 638 class MockFFmpegDemuxer : public FFmpegDemuxer { |
| 640 public: | 639 public: |
| 641 MockFFmpegDemuxer() {} | 640 MockFFmpegDemuxer(MessageLoop* message_loop) : |
| 641 FFmpegDemuxer(message_loop) { |
| 642 } |
| 642 virtual ~MockFFmpegDemuxer() {} | 643 virtual ~MockFFmpegDemuxer() {} |
| 643 | 644 |
| 644 MOCK_METHOD0(WaitForRead, size_t()); | 645 MOCK_METHOD0(WaitForRead, size_t()); |
| 645 MOCK_METHOD1(SignalReadCompleted, void(size_t size)); | 646 MOCK_METHOD1(SignalReadCompleted, void(size_t size)); |
| 646 | 647 |
| 647 private: | 648 private: |
| 648 DISALLOW_COPY_AND_ASSIGN(MockFFmpegDemuxer); | 649 DISALLOW_COPY_AND_ASSIGN(MockFFmpegDemuxer); |
| 649 }; | 650 }; |
| 650 | 651 |
| 651 // A gmock helper method to execute the callback and deletes it. | 652 // A gmock helper method to execute the callback and deletes it. |
| 652 void RunCallback(size_t size, DataSource::ReadCallback* callback) { | 653 void RunCallback(size_t size, DataSource::ReadCallback* callback) { |
| 653 DCHECK(callback); | 654 DCHECK(callback); |
| 654 callback->RunWithParams(Tuple1<size_t>(size)); | 655 callback->RunWithParams(Tuple1<size_t>(size)); |
| 655 delete callback; | 656 delete callback; |
| 656 } | 657 } |
| 657 | 658 |
| 658 TEST_F(FFmpegDemuxerTest, ProtocolRead) { | 659 TEST_F(FFmpegDemuxerTest, ProtocolRead) { |
| 659 // Creates a demuxer. | 660 // Creates a demuxer. |
| 660 scoped_refptr<MockFFmpegDemuxer> demuxer(new MockFFmpegDemuxer()); | 661 scoped_refptr<MockFFmpegDemuxer> demuxer( |
| 662 new MockFFmpegDemuxer(&message_loop_)); |
| 661 ASSERT_TRUE(demuxer); | 663 ASSERT_TRUE(demuxer); |
| 662 demuxer->set_host(&host_); | 664 demuxer->set_host(&host_); |
| 663 demuxer->set_message_loop(&message_loop_); | |
| 664 demuxer->data_source_ = data_source_; | 665 demuxer->data_source_ = data_source_; |
| 665 | 666 |
| 666 uint8 kBuffer[1]; | 667 uint8 kBuffer[1]; |
| 667 InSequence s; | 668 InSequence s; |
| 668 // Actions taken in the first read. | 669 // Actions taken in the first read. |
| 669 EXPECT_CALL(*data_source_, GetSize(_)) | 670 EXPECT_CALL(*data_source_, GetSize(_)) |
| 670 .WillOnce(DoAll(SetArgumentPointee<0>(1024), Return(true))); | 671 .WillOnce(DoAll(SetArgumentPointee<0>(1024), Return(true))); |
| 671 EXPECT_CALL(*data_source_, Read(0, 512, kBuffer, NotNull())) | 672 EXPECT_CALL(*data_source_, Read(0, 512, kBuffer, NotNull())) |
| 672 .WillOnce(WithArgs<1, 3>(Invoke(&RunCallback))); | 673 .WillOnce(WithArgs<1, 3>(Invoke(&RunCallback))); |
| 673 EXPECT_CALL(*demuxer, SignalReadCompleted(512)); | 674 EXPECT_CALL(*demuxer, SignalReadCompleted(512)); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 { | 756 { |
| 756 SCOPED_TRACE(""); | 757 SCOPED_TRACE(""); |
| 757 InitializeDemuxer(); | 758 InitializeDemuxer(); |
| 758 } | 759 } |
| 759 EXPECT_CALL(*data_source_, IsStreaming()) | 760 EXPECT_CALL(*data_source_, IsStreaming()) |
| 760 .WillOnce(Return(false)); | 761 .WillOnce(Return(false)); |
| 761 EXPECT_FALSE(demuxer_->IsStreaming()); | 762 EXPECT_FALSE(demuxer_->IsStreaming()); |
| 762 } | 763 } |
| 763 | 764 |
| 764 } // namespace media | 765 } // namespace media |
| OLD | NEW |