| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "media/base/filters.h" | 10 #include "media/base/filters.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 EXPECT_CALL(host_, SetDuration(_)); | 96 EXPECT_CALL(host_, SetDuration(_)); |
| 97 demuxer_->Initialize(data_source, NewExpectedStatusCB(PIPELINE_OK)); | 97 demuxer_->Initialize(data_source, NewExpectedStatusCB(PIPELINE_OK)); |
| 98 message_loop_.RunAllPending(); | 98 message_loop_.RunAllPending(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Verifies that |buffer| has a specific |size| and |timestamp|. | 101 // Verifies that |buffer| has a specific |size| and |timestamp|. |
| 102 // |location| simply indicates where the call to this function was made. | 102 // |location| simply indicates where the call to this function was made. |
| 103 // This makes it easier to track down where test failures occur. | 103 // This makes it easier to track down where test failures occur. |
| 104 void ValidateBuffer(const tracked_objects::Location& location, | 104 void ValidateBuffer(const tracked_objects::Location& location, |
| 105 const scoped_refptr<Buffer>& buffer, | 105 const scoped_refptr<Buffer>& buffer, |
| 106 size_t size, int64 timestampInMicroseconds) { | 106 int size, int64 timestampInMicroseconds) { |
| 107 std::string location_str; | 107 std::string location_str; |
| 108 location.Write(true, false, &location_str); | 108 location.Write(true, false, &location_str); |
| 109 location_str += "\n"; | 109 location_str += "\n"; |
| 110 SCOPED_TRACE(location_str); | 110 SCOPED_TRACE(location_str); |
| 111 EXPECT_TRUE(buffer.get() != NULL); | 111 EXPECT_TRUE(buffer.get() != NULL); |
| 112 EXPECT_EQ(size, buffer->GetDataSize()); | 112 EXPECT_EQ(size, buffer->GetDataSize()); |
| 113 EXPECT_EQ(base::TimeDelta::FromMicroseconds(timestampInMicroseconds), | 113 EXPECT_EQ(base::TimeDelta::FromMicroseconds(timestampInMicroseconds), |
| 114 buffer->GetTimestamp()); | 114 buffer->GetTimestamp()); |
| 115 } | 115 } |
| 116 | 116 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 const int kMaxBuffers = 170; | 334 const int kMaxBuffers = 170; |
| 335 for (int i = 0; !got_eos_buffer && i < kMaxBuffers; i++) { | 335 for (int i = 0; !got_eos_buffer && i < kMaxBuffers; i++) { |
| 336 reader->Read(audio); | 336 reader->Read(audio); |
| 337 message_loop_.RunAllPending(); | 337 message_loop_.RunAllPending(); |
| 338 EXPECT_TRUE(reader->called()); | 338 EXPECT_TRUE(reader->called()); |
| 339 ASSERT_TRUE(reader->buffer()); | 339 ASSERT_TRUE(reader->buffer()); |
| 340 | 340 |
| 341 if (reader->buffer()->IsEndOfStream()) { | 341 if (reader->buffer()->IsEndOfStream()) { |
| 342 got_eos_buffer = true; | 342 got_eos_buffer = true; |
| 343 EXPECT_TRUE(reader->buffer()->GetData() == NULL); | 343 EXPECT_TRUE(reader->buffer()->GetData() == NULL); |
| 344 EXPECT_EQ(0u, reader->buffer()->GetDataSize()); | 344 EXPECT_EQ(0, reader->buffer()->GetDataSize()); |
| 345 break; | 345 break; |
| 346 } | 346 } |
| 347 | 347 |
| 348 EXPECT_TRUE(reader->buffer()->GetData() != NULL); | 348 EXPECT_TRUE(reader->buffer()->GetData() != NULL); |
| 349 EXPECT_GT(reader->buffer()->GetDataSize(), 0u); | 349 EXPECT_GT(reader->buffer()->GetDataSize(), 0); |
| 350 reader->Reset(); | 350 reader->Reset(); |
| 351 } | 351 } |
| 352 | 352 |
| 353 EXPECT_TRUE(got_eos_buffer); | 353 EXPECT_TRUE(got_eos_buffer); |
| 354 } | 354 } |
| 355 | 355 |
| 356 TEST_F(FFmpegDemuxerTest, Seek) { | 356 TEST_F(FFmpegDemuxerTest, Seek) { |
| 357 // We're testing that the demuxer frees all queued packets when it receives | 357 // We're testing that the demuxer frees all queued packets when it receives |
| 358 // a Seek(). | 358 // a Seek(). |
| 359 InitializeDemuxer(CreateDataSource("bear-320x240.webm")); | 359 InitializeDemuxer(CreateDataSource("bear-320x240.webm")); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 EXPECT_TRUE(reader->buffer()->IsEndOfStream()); | 546 EXPECT_TRUE(reader->buffer()->IsEndOfStream()); |
| 547 } | 547 } |
| 548 | 548 |
| 549 class MockFFmpegDemuxer : public FFmpegDemuxer { | 549 class MockFFmpegDemuxer : public FFmpegDemuxer { |
| 550 public: | 550 public: |
| 551 explicit MockFFmpegDemuxer(MessageLoop* message_loop) | 551 explicit MockFFmpegDemuxer(MessageLoop* message_loop) |
| 552 : FFmpegDemuxer(message_loop, true) { | 552 : FFmpegDemuxer(message_loop, true) { |
| 553 } | 553 } |
| 554 virtual ~MockFFmpegDemuxer() {} | 554 virtual ~MockFFmpegDemuxer() {} |
| 555 | 555 |
| 556 MOCK_METHOD0(WaitForRead, size_t()); | 556 MOCK_METHOD0(WaitForRead, int()); |
| 557 MOCK_METHOD1(SignalReadCompleted, void(size_t size)); | 557 MOCK_METHOD1(SignalReadCompleted, void(int size)); |
| 558 | 558 |
| 559 private: | 559 private: |
| 560 DISALLOW_COPY_AND_ASSIGN(MockFFmpegDemuxer); | 560 DISALLOW_COPY_AND_ASSIGN(MockFFmpegDemuxer); |
| 561 }; | 561 }; |
| 562 | 562 |
| 563 // A gmock helper method to execute the callback and deletes it. | 563 // A gmock helper method to execute the callback and deletes it. |
| 564 void RunCallback(size_t size, const DataSource::ReadCB& callback) { | 564 void RunCallback(int size, const DataSource::ReadCB& callback) { |
| 565 DCHECK(!callback.is_null()); | 565 DCHECK(!callback.is_null()); |
| 566 callback.Run(size); | 566 callback.Run(size); |
| 567 } | 567 } |
| 568 | 568 |
| 569 TEST_F(FFmpegDemuxerTest, ProtocolRead) { | 569 TEST_F(FFmpegDemuxerTest, ProtocolRead) { |
| 570 scoped_refptr<StrictMock<MockDataSource> > data_source = | 570 scoped_refptr<StrictMock<MockDataSource> > data_source = |
| 571 new StrictMock<MockDataSource>(); | 571 new StrictMock<MockDataSource>(); |
| 572 | 572 |
| 573 EXPECT_CALL(*data_source, Stop(_)) | 573 EXPECT_CALL(*data_source, Stop(_)) |
| 574 .WillRepeatedly(Invoke(&RunStopFilterCallback)); | 574 .WillRepeatedly(Invoke(&RunStopFilterCallback)); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 message_loop_.RunAllPending(); | 737 message_loop_.RunAllPending(); |
| 738 EXPECT_TRUE(reader->called()); | 738 EXPECT_TRUE(reader->called()); |
| 739 ValidateBuffer(FROM_HERE, reader->buffer(), 1740, 2436000); | 739 ValidateBuffer(FROM_HERE, reader->buffer(), 1740, 2436000); |
| 740 | 740 |
| 741 // Manually release the last reference to the buffer and verify it was freed. | 741 // Manually release the last reference to the buffer and verify it was freed. |
| 742 reader->Reset(); | 742 reader->Reset(); |
| 743 message_loop_.RunAllPending(); | 743 message_loop_.RunAllPending(); |
| 744 } | 744 } |
| 745 | 745 |
| 746 } // namespace media | 746 } // namespace media |
| OLD | NEW |