OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "media/base/text_renderer.h" | 5 #include "media/base/text_renderer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/run_loop.h" |
17 #include "media/base/audio_decoder_config.h" | 18 #include "media/base/audio_decoder_config.h" |
18 #include "media/base/decoder_buffer.h" | 19 #include "media/base/decoder_buffer.h" |
19 #include "media/base/demuxer_stream.h" | 20 #include "media/base/demuxer_stream.h" |
20 #include "media/base/fake_text_track_stream.h" | 21 #include "media/base/fake_text_track_stream.h" |
21 #include "media/base/text_track_config.h" | 22 #include "media/base/text_track_config.h" |
22 #include "media/base/video_decoder_config.h" | 23 #include "media/base/video_decoder_config.h" |
23 #include "media/filters/webvtt_util.h" | 24 #include "media/filters/webvtt_util.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 | 27 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 text_renderer_.reset( | 62 text_renderer_.reset( |
62 new TextRenderer(message_loop_.task_runner(), | 63 new TextRenderer(message_loop_.task_runner(), |
63 base::Bind(&TextRendererTest::OnAddTextTrack, | 64 base::Bind(&TextRendererTest::OnAddTextTrack, |
64 base::Unretained(this)))); | 65 base::Unretained(this)))); |
65 text_renderer_->Initialize(base::Bind(&TextRendererTest::OnEnd, | 66 text_renderer_->Initialize(base::Bind(&TextRendererTest::OnEnd, |
66 base::Unretained(this))); | 67 base::Unretained(this))); |
67 } | 68 } |
68 | 69 |
69 void Destroy() { | 70 void Destroy() { |
70 text_renderer_.reset(); | 71 text_renderer_.reset(); |
71 message_loop_.RunUntilIdle(); | 72 base::RunLoop().RunUntilIdle(); |
72 } | 73 } |
73 | 74 |
74 void AddTextTrack(TextKind kind, | 75 void AddTextTrack(TextKind kind, |
75 const std::string& name, | 76 const std::string& name, |
76 const std::string& language, | 77 const std::string& language, |
77 bool expect_read) { | 78 bool expect_read) { |
78 const size_t idx = text_track_streams_.size(); | 79 const size_t idx = text_track_streams_.size(); |
79 text_track_streams_.push_back(new FakeTextTrackStream); | 80 text_track_streams_.push_back(new FakeTextTrackStream); |
80 | 81 |
81 if (expect_read) | 82 if (expect_read) |
82 ExpectRead(idx); | 83 ExpectRead(idx); |
83 | 84 |
84 const TextTrackConfig config(kind, name, language, std::string()); | 85 const TextTrackConfig config(kind, name, language, std::string()); |
85 text_renderer_->AddTextStream(text_track_streams_.back(), config); | 86 text_renderer_->AddTextStream(text_track_streams_.back(), config); |
86 message_loop_.RunUntilIdle(); | 87 base::RunLoop().RunUntilIdle(); |
87 | 88 |
88 EXPECT_EQ(text_tracks_.size(), text_track_streams_.size()); | 89 EXPECT_EQ(text_tracks_.size(), text_track_streams_.size()); |
89 FakeTextTrack* const text_track = text_tracks_.back(); | 90 FakeTextTrack* const text_track = text_tracks_.back(); |
90 EXPECT_TRUE(text_track); | 91 EXPECT_TRUE(text_track); |
91 EXPECT_TRUE(text_track->config_.Matches(config)); | 92 EXPECT_TRUE(text_track->config_.Matches(config)); |
92 } | 93 } |
93 | 94 |
94 void OnAddTextTrack(const TextTrackConfig& config, | 95 void OnAddTextTrack(const TextTrackConfig& config, |
95 const AddTextTrackDoneCB& done_cb) { | 96 const AddTextTrackDoneCB& done_cb) { |
96 base::Closure destroy_cb = | 97 base::Closure destroy_cb = |
(...skipping 21 matching lines...) Expand all Loading... |
118 const std::string& settings) { | 119 const std::string& settings) { |
119 for (TextTrackStreams::iterator itr = text_track_streams_.begin(); | 120 for (TextTrackStreams::iterator itr = text_track_streams_.begin(); |
120 itr != text_track_streams_.end(); ++itr) { | 121 itr != text_track_streams_.end(); ++itr) { |
121 (*itr)->SatisfyPendingRead(start, duration, id, content, settings); | 122 (*itr)->SatisfyPendingRead(start, duration, id, content, settings); |
122 } | 123 } |
123 } | 124 } |
124 | 125 |
125 void AbortPendingRead(unsigned idx) { | 126 void AbortPendingRead(unsigned idx) { |
126 FakeTextTrackStream* const stream = text_track_streams_[idx]; | 127 FakeTextTrackStream* const stream = text_track_streams_[idx]; |
127 stream->AbortPendingRead(); | 128 stream->AbortPendingRead(); |
128 message_loop_.RunUntilIdle(); | 129 base::RunLoop().RunUntilIdle(); |
129 } | 130 } |
130 | 131 |
131 void AbortPendingReads() { | 132 void AbortPendingReads() { |
132 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { | 133 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { |
133 AbortPendingRead(idx); | 134 AbortPendingRead(idx); |
134 } | 135 } |
135 } | 136 } |
136 | 137 |
137 void SendEosNotification(unsigned idx) { | 138 void SendEosNotification(unsigned idx) { |
138 FakeTextTrackStream* const stream = text_track_streams_[idx]; | 139 FakeTextTrackStream* const stream = text_track_streams_[idx]; |
139 stream->SendEosNotification(); | 140 stream->SendEosNotification(); |
140 message_loop_.RunUntilIdle(); | 141 base::RunLoop().RunUntilIdle(); |
141 } | 142 } |
142 | 143 |
143 void SendEosNotifications() { | 144 void SendEosNotifications() { |
144 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { | 145 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { |
145 SendEosNotification(idx); | 146 SendEosNotification(idx); |
146 } | 147 } |
147 } | 148 } |
148 | 149 |
149 void SendCue(unsigned idx, bool expect_cue) { | 150 void SendCue(unsigned idx, bool expect_cue) { |
150 FakeTextTrackStream* const text_stream = text_track_streams_[idx]; | 151 FakeTextTrackStream* const text_stream = text_track_streams_[idx]; |
151 | 152 |
152 const base::TimeDelta start; | 153 const base::TimeDelta start; |
153 const base::TimeDelta duration = base::TimeDelta::FromSeconds(42); | 154 const base::TimeDelta duration = base::TimeDelta::FromSeconds(42); |
154 const std::string id = "id"; | 155 const std::string id = "id"; |
155 const std::string content = "subtitle"; | 156 const std::string content = "subtitle"; |
156 const std::string settings; | 157 const std::string settings; |
157 | 158 |
158 if (expect_cue) { | 159 if (expect_cue) { |
159 FakeTextTrack* const text_track = text_tracks_[idx]; | 160 FakeTextTrack* const text_track = text_tracks_[idx]; |
160 EXPECT_CALL(*text_track, addWebVTTCue(start, | 161 EXPECT_CALL(*text_track, addWebVTTCue(start, |
161 start + duration, | 162 start + duration, |
162 id, | 163 id, |
163 content, | 164 content, |
164 settings)); | 165 settings)); |
165 } | 166 } |
166 | 167 |
167 text_stream->SatisfyPendingRead(start, duration, id, content, settings); | 168 text_stream->SatisfyPendingRead(start, duration, id, content, settings); |
168 message_loop_.RunUntilIdle(); | 169 base::RunLoop().RunUntilIdle(); |
169 } | 170 } |
170 | 171 |
171 void SendCues(bool expect_cue) { | 172 void SendCues(bool expect_cue) { |
172 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { | 173 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { |
173 SendCue(idx, expect_cue); | 174 SendCue(idx, expect_cue); |
174 } | 175 } |
175 } | 176 } |
176 | 177 |
177 void OnDestroyTextTrack(unsigned idx) { | 178 void OnDestroyTextTrack(unsigned idx) { |
178 text_tracks_[idx] = NULL; | 179 text_tracks_[idx] = NULL; |
179 } | 180 } |
180 | 181 |
181 void Play() { | 182 void Play() { |
182 text_renderer_->StartPlaying(); | 183 text_renderer_->StartPlaying(); |
183 } | 184 } |
184 | 185 |
185 void Pause() { | 186 void Pause() { |
186 text_renderer_->Pause(base::Bind(&TextRendererTest::OnPause, | 187 text_renderer_->Pause(base::Bind(&TextRendererTest::OnPause, |
187 base::Unretained(this))); | 188 base::Unretained(this))); |
188 message_loop_.RunUntilIdle(); | 189 base::RunLoop().RunUntilIdle(); |
189 } | 190 } |
190 | 191 |
191 void Flush() { | 192 void Flush() { |
192 EXPECT_CALL(*this, OnFlush()); | 193 EXPECT_CALL(*this, OnFlush()); |
193 text_renderer_->Flush(base::Bind(&TextRendererTest::OnFlush, | 194 text_renderer_->Flush(base::Bind(&TextRendererTest::OnFlush, |
194 base::Unretained(this))); | 195 base::Unretained(this))); |
195 } | 196 } |
196 | 197 |
197 void ExpectRead(size_t idx) { | 198 void ExpectRead(size_t idx) { |
198 FakeTextTrackStream* const stream = text_track_streams_[idx]; | 199 FakeTextTrackStream* const stream = text_track_streams_[idx]; |
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 Play(); | 1206 Play(); |
1206 AbortPendingRead(0); | 1207 AbortPendingRead(0); |
1207 RemoveTextTrack(0); | 1208 RemoveTextTrack(0); |
1208 EXPECT_TRUE(text_renderer_->HasTracks()); | 1209 EXPECT_TRUE(text_renderer_->HasTracks()); |
1209 Pause(); | 1210 Pause(); |
1210 EXPECT_CALL(*this, OnPause()); | 1211 EXPECT_CALL(*this, OnPause()); |
1211 SendEosNotification(1); | 1212 SendEosNotification(1); |
1212 } | 1213 } |
1213 | 1214 |
1214 } // namespace media | 1215 } // namespace media |
OLD | NEW |