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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <deque> | 9 #include <deque> |
10 #include <string> | 10 #include <string> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 using ::testing::WithArgs; | 47 using ::testing::WithArgs; |
48 using ::testing::_; | 48 using ::testing::_; |
49 | 49 |
50 namespace media { | 50 namespace media { |
51 | 51 |
52 MATCHER(IsEndOfStreamBuffer, | 52 MATCHER(IsEndOfStreamBuffer, |
53 std::string(negation ? "isn't" : "is") + " end of stream") { | 53 std::string(negation ? "isn't" : "is") + " end of stream") { |
54 return arg->end_of_stream(); | 54 return arg->end_of_stream(); |
55 } | 55 } |
56 | 56 |
57 namespace { | |
58 void OnStreamStatusChanged(base::WaitableEvent* event, | |
59 DemuxerStream* stream, | |
60 bool enabled, | |
61 base::TimeDelta) { | |
62 event->Signal(); | |
63 } | |
64 | |
65 void CheckStreamStatusNotifications(MediaResource* media_resource, | |
66 FFmpegDemuxerStream* stream) { | |
67 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
68 base::WaitableEvent::InitialState::NOT_SIGNALED); | |
69 | |
70 ASSERT_TRUE(stream->IsEnabled()); | |
71 media_resource->SetStreamStatusChangeCB( | |
72 base::Bind(&OnStreamStatusChanged, base::Unretained(&event))); | |
73 | |
74 stream->SetEnabled(false, base::TimeDelta()); | |
75 base::RunLoop().RunUntilIdle(); | |
76 ASSERT_TRUE(event.IsSignaled()); | |
77 | |
78 event.Reset(); | |
79 stream->SetEnabled(true, base::TimeDelta()); | |
80 base::RunLoop().RunUntilIdle(); | |
81 ASSERT_TRUE(event.IsSignaled()); | |
82 } | |
83 | |
84 void OnReadDone_ExpectEos(DemuxerStream::Status status, | |
85 const scoped_refptr<DecoderBuffer>& buffer) { | |
86 EXPECT_EQ(status, DemuxerStream::kOk); | |
87 EXPECT_TRUE(buffer->end_of_stream()); | |
88 } | |
89 } | |
90 | |
57 const uint8_t kEncryptedMediaInitData[] = { | 91 const uint8_t kEncryptedMediaInitData[] = { |
58 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, | 92 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, |
59 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, | 93 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, |
60 }; | 94 }; |
61 | 95 |
62 static void EosOnReadDone(bool* got_eos_buffer, | 96 static void EosOnReadDone(bool* got_eos_buffer, |
63 DemuxerStream::Status status, | 97 DemuxerStream::Status status, |
64 const scoped_refptr<DecoderBuffer>& buffer) { | 98 const scoped_refptr<DecoderBuffer>& buffer) { |
65 base::ThreadTaskRunnerHandle::Get()->PostTask( | 99 base::ThreadTaskRunnerHandle::Get()->PostTask( |
66 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 100 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
(...skipping 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1591 EXPECT_EQ(nullptr, GetStream(DemuxerStream::VIDEO)); | 1625 EXPECT_EQ(nullptr, GetStream(DemuxerStream::VIDEO)); |
1592 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta())); | 1626 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta())); |
1593 | 1627 |
1594 // Now pretend that audio stream got disabled. | 1628 // Now pretend that audio stream got disabled. |
1595 astream->SetEnabled(false, base::TimeDelta()); | 1629 astream->SetEnabled(false, base::TimeDelta()); |
1596 // Since there's no other enabled streams, the preferred seeking stream should | 1630 // Since there's no other enabled streams, the preferred seeking stream should |
1597 // still be the audio stream. | 1631 // still be the audio stream. |
1598 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta())); | 1632 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta())); |
1599 } | 1633 } |
1600 | 1634 |
1635 TEST_F(FFmpegDemuxerTest, StreamStatusNotifications) { | |
1636 CreateDemuxer("bear-320x240.webm"); | |
1637 InitializeDemuxer(); | |
1638 FFmpegDemuxerStream* audio_stream = | |
1639 static_cast<FFmpegDemuxerStream*>(GetStream(DemuxerStream::AUDIO)); | |
1640 EXPECT_NE(nullptr, audio_stream); | |
1641 FFmpegDemuxerStream* video_stream = | |
1642 static_cast<FFmpegDemuxerStream*>(GetStream(DemuxerStream::VIDEO)); | |
1643 EXPECT_NE(nullptr, video_stream); | |
1644 | |
1645 // Verify stream status notifications delivery without pending read first. | |
1646 CheckStreamStatusNotifications(demuxer_.get(), audio_stream); | |
1647 CheckStreamStatusNotifications(demuxer_.get(), video_stream); | |
1648 | |
1649 // Verify that stream notifications are delivered properly when stream status | |
1650 // changes with a pending read. | |
1651 audio_stream->FlushBuffers(); | |
chcunningham
2017/04/19 01:01:34
What is the FlushBuffers needed for?
servolk
2017/04/19 01:05:33
To ensure there's no prepared frames that are read
chcunningham
2017/04/20 01:00:25
Makes good sense. Maybe a comment to explain that
servolk
2017/04/20 01:04:19
Done.
| |
1652 audio_stream->Read(base::Bind(&media::OnReadDone_ExpectEos)); | |
1653 CheckStreamStatusNotifications(demuxer_.get(), audio_stream); | |
1654 video_stream->FlushBuffers(); | |
1655 video_stream->Read(base::Bind(&media::OnReadDone_ExpectEos)); | |
1656 CheckStreamStatusNotifications(demuxer_.get(), video_stream); | |
1657 } | |
1658 | |
1601 } // namespace media | 1659 } // namespace media |
OLD | NEW |