| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/singleton.h" | 7 #include "base/singleton.h" |
| 8 #include "base/tuple.h" | 8 #include "base/tuple.h" |
| 9 #include "media/base/filter_host.h" | 9 #include "media/base/filter_host.h" |
| 10 #include "media/base/filters.h" | 10 #include "media/base/filters.h" |
| 11 #include "media/base/mock_ffmpeg.h" | 11 #include "media/base/mock_ffmpeg.h" |
| 12 #include "media/base/mock_filter_host.h" | 12 #include "media/base/mock_filter_host.h" |
| 13 #include "media/base/mock_media_filters.h" | 13 #include "media/base/mock_media_filters.h" |
| 14 #include "media/base/mock_reader.h" | 14 #include "media/base/mock_reader.h" |
| 15 #include "media/filters/ffmpeg_common.h" | 15 #include "media/filters/ffmpeg_common.h" |
| 16 #include "media/filters/ffmpeg_demuxer.h" | 16 #include "media/filters/ffmpeg_demuxer.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using ::testing::_; | 19 using ::testing::_; |
| 20 using ::testing::DoAll; | 20 using ::testing::DoAll; |
| 21 using ::testing::InSequence; | 21 using ::testing::InSequence; |
| 22 using ::testing::Return; | 22 using ::testing::Return; |
| 23 using ::testing::SetArgumentPointee; | 23 using ::testing::SetArgumentPointee; |
| 24 using ::testing::StrictMock; |
| 24 | 25 |
| 25 namespace media { | 26 namespace media { |
| 26 | 27 |
| 27 // Fixture class to facilitate writing tests. Takes care of setting up the | 28 // Fixture class to facilitate writing tests. Takes care of setting up the |
| 28 // FFmpeg, pipeline and filter host mocks. | 29 // FFmpeg, pipeline and filter host mocks. |
| 29 class FFmpegDemuxerTest : public testing::Test { | 30 class FFmpegDemuxerTest : public testing::Test { |
| 30 protected: | 31 protected: |
| 31 // These constants refer to the stream ordering inside AVFormatContext. We | 32 // These constants refer to the stream ordering inside AVFormatContext. We |
| 32 // simulate media with a data stream, audio stream and video stream. Having | 33 // simulate media with a data stream, audio stream and video stream. Having |
| 33 // the data stream first forces the audio and video streams to get remapped | 34 // the data stream first forces the audio and video streams to get remapped |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 | 607 |
| 607 // We shouldn't have freed the MP3 packet yet. | 608 // We shouldn't have freed the MP3 packet yet. |
| 608 MockFFmpeg::get()->CheckPoint(1); | 609 MockFFmpeg::get()->CheckPoint(1); |
| 609 | 610 |
| 610 // Manually release the last reference to the buffer and verify it was freed. | 611 // Manually release the last reference to the buffer and verify it was freed. |
| 611 reader->Reset(); | 612 reader->Reset(); |
| 612 WaitForDemuxerThread(); | 613 WaitForDemuxerThread(); |
| 613 MockFFmpeg::get()->CheckPoint(2); | 614 MockFFmpeg::get()->CheckPoint(2); |
| 614 } | 615 } |
| 615 | 616 |
| 617 // A mocked callback specialization for calling Read(). Since RunWithParams() |
| 618 // is mocked we don't need to pass in object or method pointers. |
| 619 typedef CallbackImpl<FFmpegDemuxerTest, void (FFmpegDemuxerTest::*)(Buffer*), |
| 620 Tuple1<Buffer*> > ReadCallback; |
| 621 class MockReadCallback : public ReadCallback { |
| 622 public: |
| 623 MockReadCallback() |
| 624 : ReadCallback(NULL, NULL) { |
| 625 } |
| 626 |
| 627 virtual ~MockReadCallback() { |
| 628 OnDelete(); |
| 629 } |
| 630 |
| 631 MOCK_METHOD0(OnDelete, void()); |
| 632 MOCK_METHOD1(RunWithParams, void(const Tuple1<Buffer*>& params)); |
| 633 }; |
| 634 |
| 635 TEST_F(FFmpegDemuxerTest, Stop) { |
| 636 // Tests that calling Read() on a stopped demuxer immediately deletes the |
| 637 // callback. |
| 638 { |
| 639 SCOPED_TRACE(""); |
| 640 InitializeDemuxer(); |
| 641 } |
| 642 |
| 643 // Create our mocked callback. The demuxer will take ownership of this |
| 644 // pointer. |
| 645 scoped_ptr<StrictMock<MockReadCallback> > callback( |
| 646 new StrictMock<MockReadCallback>()); |
| 647 |
| 648 // Get our stream. |
| 649 scoped_refptr<DemuxerStream> audio = demuxer_->GetStream(DS_STREAM_AUDIO); |
| 650 ASSERT_TRUE(audio); |
| 651 |
| 652 // Stop the demuxer. |
| 653 demuxer_->Stop(); |
| 654 |
| 655 // Expect all calls in sequence. |
| 656 InSequence s; |
| 657 |
| 658 // The callback should be immediately deleted. We'll use a checkpoint to |
| 659 // verify that it has indeed been deleted. |
| 660 EXPECT_CALL(*callback, OnDelete()); |
| 661 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(1)); |
| 662 |
| 663 // Attempt the read... |
| 664 audio->Read(callback.release()); |
| 665 |
| 666 // ...and verify that |callback| was deleted. |
| 667 MockFFmpeg::get()->CheckPoint(1); |
| 668 } |
| 669 |
| 616 } // namespace media | 670 } // namespace media |
| OLD | NEW |