| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <deque> | 6 #include <deque> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 using ::testing::_; | 33 using ::testing::_; |
| 34 | 34 |
| 35 namespace media { | 35 namespace media { |
| 36 | 36 |
| 37 MATCHER(IsEndOfStreamBuffer, | 37 MATCHER(IsEndOfStreamBuffer, |
| 38 std::string(negation ? "isn't" : "is") + " end of stream") { | 38 std::string(negation ? "isn't" : "is") + " end of stream") { |
| 39 return arg->IsEndOfStream(); | 39 return arg->IsEndOfStream(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 static void EosOnReadDone(bool* got_eos_buffer, | 42 static void EosOnReadDone(bool* got_eos_buffer, |
| 43 DemuxerStream::Status status, |
| 43 const scoped_refptr<DecoderBuffer>& buffer) { | 44 const scoped_refptr<DecoderBuffer>& buffer) { |
| 45 EXPECT_EQ(status, DemuxerStream::kOk); |
| 44 if (buffer->IsEndOfStream()) { | 46 if (buffer->IsEndOfStream()) { |
| 45 *got_eos_buffer = true; | 47 *got_eos_buffer = true; |
| 46 EXPECT_TRUE(!buffer->GetData()); | 48 EXPECT_TRUE(!buffer->GetData()); |
| 47 EXPECT_EQ(buffer->GetDataSize(), 0); | 49 EXPECT_EQ(buffer->GetDataSize(), 0); |
| 48 return; | 50 return; |
| 49 } | 51 } |
| 50 | 52 |
| 51 EXPECT_TRUE(buffer->GetData()); | 53 EXPECT_TRUE(buffer->GetData()); |
| 52 EXPECT_GT(buffer->GetDataSize(), 0); | 54 EXPECT_GT(buffer->GetDataSize(), 0); |
| 53 *got_eos_buffer = false; | 55 *got_eos_buffer = false; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 message_loop_.RunAllPending(); | 97 message_loop_.RunAllPending(); |
| 96 } | 98 } |
| 97 | 99 |
| 98 MOCK_METHOD2(OnReadDoneCalled, void(int, int64)); | 100 MOCK_METHOD2(OnReadDoneCalled, void(int, int64)); |
| 99 | 101 |
| 100 // Verifies that |buffer| has a specific |size| and |timestamp|. | 102 // Verifies that |buffer| has a specific |size| and |timestamp|. |
| 101 // |location| simply indicates where the call to this function was made. | 103 // |location| simply indicates where the call to this function was made. |
| 102 // This makes it easier to track down where test failures occur. | 104 // This makes it easier to track down where test failures occur. |
| 103 void OnReadDone(const tracked_objects::Location& location, | 105 void OnReadDone(const tracked_objects::Location& location, |
| 104 int size, int64 timestampInMicroseconds, | 106 int size, int64 timestampInMicroseconds, |
| 107 DemuxerStream::Status status, |
| 105 const scoped_refptr<DecoderBuffer>& buffer) { | 108 const scoped_refptr<DecoderBuffer>& buffer) { |
| 106 std::string location_str; | 109 std::string location_str; |
| 107 location.Write(true, false, &location_str); | 110 location.Write(true, false, &location_str); |
| 108 location_str += "\n"; | 111 location_str += "\n"; |
| 109 SCOPED_TRACE(location_str); | 112 SCOPED_TRACE(location_str); |
| 113 EXPECT_EQ(status, DemuxerStream::kOk); |
| 110 OnReadDoneCalled(size, timestampInMicroseconds); | 114 OnReadDoneCalled(size, timestampInMicroseconds); |
| 111 EXPECT_TRUE(buffer.get() != NULL); | 115 EXPECT_TRUE(buffer.get() != NULL); |
| 112 EXPECT_EQ(size, buffer->GetDataSize()); | 116 EXPECT_EQ(size, buffer->GetDataSize()); |
| 113 EXPECT_EQ(base::TimeDelta::FromMicroseconds(timestampInMicroseconds), | 117 EXPECT_EQ(base::TimeDelta::FromMicroseconds(timestampInMicroseconds), |
| 114 buffer->GetTimestamp()); | 118 buffer->GetTimestamp()); |
| 115 } | 119 } |
| 116 | 120 |
| 117 DemuxerStream::ReadCB NewReadCB(const tracked_objects::Location& location, | 121 DemuxerStream::ReadCB NewReadCB(const tracked_objects::Location& location, |
| 118 int size, int64 timestampInMicroseconds) { | 122 int size, int64 timestampInMicroseconds) { |
| 119 EXPECT_CALL(*this, OnReadDoneCalled(size, timestampInMicroseconds)); | 123 EXPECT_CALL(*this, OnReadDoneCalled(size, timestampInMicroseconds)); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 message_loop_.RunAllPending(); | 409 message_loop_.RunAllPending(); |
| 406 } | 410 } |
| 407 | 411 |
| 408 // A mocked callback specialization for calling Read(). Since RunWithParams() | 412 // A mocked callback specialization for calling Read(). Since RunWithParams() |
| 409 // is mocked we don't need to pass in object or method pointers. | 413 // is mocked we don't need to pass in object or method pointers. |
| 410 class MockReadCB : public base::RefCountedThreadSafe<MockReadCB> { | 414 class MockReadCB : public base::RefCountedThreadSafe<MockReadCB> { |
| 411 public: | 415 public: |
| 412 MockReadCB() {} | 416 MockReadCB() {} |
| 413 | 417 |
| 414 MOCK_METHOD0(OnDelete, void()); | 418 MOCK_METHOD0(OnDelete, void()); |
| 415 MOCK_METHOD1(Run, void(const scoped_refptr<DecoderBuffer>& buffer)); | 419 MOCK_METHOD2(Run, void(DemuxerStream::Status status, |
| 420 const scoped_refptr<DecoderBuffer>& buffer)); |
| 416 | 421 |
| 417 protected: | 422 protected: |
| 418 virtual ~MockReadCB() { | 423 virtual ~MockReadCB() { |
| 419 OnDelete(); | 424 OnDelete(); |
| 420 } | 425 } |
| 421 | 426 |
| 422 private: | 427 private: |
| 423 friend class base::RefCountedThreadSafe<MockReadCB>; | 428 friend class base::RefCountedThreadSafe<MockReadCB>; |
| 424 | 429 |
| 425 DISALLOW_COPY_AND_ASSIGN(MockReadCB); | 430 DISALLOW_COPY_AND_ASSIGN(MockReadCB); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 440 | 445 |
| 441 // Expect all calls in sequence. | 446 // Expect all calls in sequence. |
| 442 InSequence s; | 447 InSequence s; |
| 443 | 448 |
| 444 // Create our mocked callback. The Callback created by base::Bind() will take | 449 // Create our mocked callback. The Callback created by base::Bind() will take |
| 445 // ownership of this pointer. | 450 // ownership of this pointer. |
| 446 StrictMock<MockReadCB>* callback = new StrictMock<MockReadCB>(); | 451 StrictMock<MockReadCB>* callback = new StrictMock<MockReadCB>(); |
| 447 | 452 |
| 448 // The callback should be immediately deleted. We'll use a checkpoint to | 453 // The callback should be immediately deleted. We'll use a checkpoint to |
| 449 // verify that it has indeed been deleted. | 454 // verify that it has indeed been deleted. |
| 450 EXPECT_CALL(*callback, Run(IsEndOfStreamBuffer())); | 455 EXPECT_CALL(*callback, Run(DemuxerStream::kOk, IsEndOfStreamBuffer())); |
| 451 EXPECT_CALL(*callback, OnDelete()); | 456 EXPECT_CALL(*callback, OnDelete()); |
| 452 EXPECT_CALL(*this, CheckPoint(1)); | 457 EXPECT_CALL(*this, CheckPoint(1)); |
| 453 | 458 |
| 454 // Attempt the read... | 459 // Attempt the read... |
| 455 audio->Read(base::Bind(&MockReadCB::Run, callback)); | 460 audio->Read(base::Bind(&MockReadCB::Run, callback)); |
| 456 | 461 |
| 457 message_loop_.RunAllPending(); | 462 message_loop_.RunAllPending(); |
| 458 | 463 |
| 459 // ...and verify that |callback| was deleted. | 464 // ...and verify that |callback| was deleted. |
| 460 CheckPoint(1); | 465 CheckPoint(1); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 480 | 485 |
| 481 // Expect all calls in sequence. | 486 // Expect all calls in sequence. |
| 482 InSequence s; | 487 InSequence s; |
| 483 | 488 |
| 484 // Create our mocked callback. The Callback created by base::Bind() will take | 489 // Create our mocked callback. The Callback created by base::Bind() will take |
| 485 // ownership of this pointer. | 490 // ownership of this pointer. |
| 486 StrictMock<MockReadCB>* callback = new StrictMock<MockReadCB>(); | 491 StrictMock<MockReadCB>* callback = new StrictMock<MockReadCB>(); |
| 487 | 492 |
| 488 // The callback should be immediately deleted. We'll use a checkpoint to | 493 // The callback should be immediately deleted. We'll use a checkpoint to |
| 489 // verify that it has indeed been deleted. | 494 // verify that it has indeed been deleted. |
| 490 EXPECT_CALL(*callback, Run(IsEndOfStreamBuffer())); | 495 EXPECT_CALL(*callback, Run(DemuxerStream::kOk, IsEndOfStreamBuffer())); |
| 491 EXPECT_CALL(*callback, OnDelete()); | 496 EXPECT_CALL(*callback, OnDelete()); |
| 492 EXPECT_CALL(*this, CheckPoint(1)); | 497 EXPECT_CALL(*this, CheckPoint(1)); |
| 493 | 498 |
| 494 // Release the reference to the demuxer. This should also destroy it. | 499 // Release the reference to the demuxer. This should also destroy it. |
| 495 demuxer_ = NULL; | 500 demuxer_ = NULL; |
| 496 // |audio| now has a demuxer_ pointer to invalid memory. | 501 // |audio| now has a demuxer_ pointer to invalid memory. |
| 497 | 502 |
| 498 // Attempt the read... | 503 // Attempt the read... |
| 499 audio->Read(base::Bind(&MockReadCB::Run, callback)); | 504 audio->Read(base::Bind(&MockReadCB::Run, callback)); |
| 500 | 505 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 TEST_F(FFmpegDemuxerTest, UnsupportedVideoSupportedAudioDemux) { | 722 TEST_F(FFmpegDemuxerTest, UnsupportedVideoSupportedAudioDemux) { |
| 718 CreateDemuxer("vorbis_audio_wmv_video.mkv"); | 723 CreateDemuxer("vorbis_audio_wmv_video.mkv"); |
| 719 InitializeDemuxer(); | 724 InitializeDemuxer(); |
| 720 | 725 |
| 721 // Ensure the expected streams are present. | 726 // Ensure the expected streams are present. |
| 722 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::VIDEO)); | 727 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::VIDEO)); |
| 723 EXPECT_TRUE(demuxer_->GetStream(DemuxerStream::AUDIO)); | 728 EXPECT_TRUE(demuxer_->GetStream(DemuxerStream::AUDIO)); |
| 724 } | 729 } |
| 725 | 730 |
| 726 } // namespace media | 731 } // namespace media |
| OLD | NEW |