Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1295)

Side by Side Diff: media/filters/ffmpeg_demuxer_unittest.cc

Issue 2825863002: Fix status notifications for FFmpegDemuxerStream with a pending read (Closed)
Patch Set: Add a comment explaining FlushBuffers Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/filters/ffmpeg_demuxer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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. Call FlushBuffers before reading, to ensure
1651 // there is no buffers ready to be returned by the Read right away, thus
1652 // ensuring that status changes occur while an async read is pending.
1653 audio_stream->FlushBuffers();
1654 audio_stream->Read(base::Bind(&media::OnReadDone_ExpectEos));
1655 CheckStreamStatusNotifications(demuxer_.get(), audio_stream);
1656 video_stream->FlushBuffers();
1657 video_stream->Read(base::Bind(&media::OnReadDone_ExpectEos));
1658 CheckStreamStatusNotifications(demuxer_.get(), video_stream);
1659 }
1660
1601 } // namespace media 1661 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_demuxer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698