| 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/ptr_util.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 "base/run_loop.h" |
| 18 #include "media/base/audio_decoder_config.h" | 18 #include "media/base/audio_decoder_config.h" |
| 19 #include "media/base/decoder_buffer.h" | 19 #include "media/base/decoder_buffer.h" |
| 20 #include "media/base/demuxer_stream.h" | 20 #include "media/base/demuxer_stream.h" |
| 21 #include "media/base/fake_text_track_stream.h" | 21 #include "media/base/fake_text_track_stream.h" |
| 22 #include "media/base/text_track_config.h" | 22 #include "media/base/text_track_config.h" |
| 23 #include "media/base/video_decoder_config.h" | 23 #include "media/base/video_decoder_config.h" |
| 24 #include "media/filters/webvtt_util.h" | 24 #include "media/filters/webvtt_util.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 void Destroy() { | 70 void Destroy() { |
| 71 text_renderer_.reset(); | 71 text_renderer_.reset(); |
| 72 base::RunLoop().RunUntilIdle(); | 72 base::RunLoop().RunUntilIdle(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void AddTextTrack(TextKind kind, | 75 void AddTextTrack(TextKind kind, |
| 76 const std::string& name, | 76 const std::string& name, |
| 77 const std::string& language, | 77 const std::string& language, |
| 78 bool expect_read) { | 78 bool expect_read) { |
| 79 const size_t idx = text_track_streams_.size(); | 79 const size_t idx = text_track_streams_.size(); |
| 80 text_track_streams_.push_back(new FakeTextTrackStream); | 80 text_track_streams_.push_back(base::MakeUnique<FakeTextTrackStream>()); |
| 81 | 81 |
| 82 if (expect_read) | 82 if (expect_read) |
| 83 ExpectRead(idx); | 83 ExpectRead(idx); |
| 84 | 84 |
| 85 const TextTrackConfig config(kind, name, language, std::string()); | 85 const TextTrackConfig config(kind, name, language, std::string()); |
| 86 text_renderer_->AddTextStream(text_track_streams_.back(), config); | 86 text_renderer_->AddTextStream(text_track_streams_.back().get(), config); |
| 87 base::RunLoop().RunUntilIdle(); | 87 base::RunLoop().RunUntilIdle(); |
| 88 | 88 |
| 89 EXPECT_EQ(text_tracks_.size(), text_track_streams_.size()); | 89 EXPECT_EQ(text_tracks_.size(), text_track_streams_.size()); |
| 90 FakeTextTrack* const text_track = text_tracks_.back(); | 90 FakeTextTrack* const text_track = text_tracks_.back(); |
| 91 EXPECT_TRUE(text_track); | 91 EXPECT_TRUE(text_track); |
| 92 EXPECT_TRUE(text_track->config_.Matches(config)); | 92 EXPECT_TRUE(text_track->config_.Matches(config)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void OnAddTextTrack(const TextTrackConfig& config, | 95 void OnAddTextTrack(const TextTrackConfig& config, |
| 96 const AddTextTrackDoneCB& done_cb) { | 96 const AddTextTrackDoneCB& done_cb) { |
| 97 base::Closure destroy_cb = | 97 base::Closure destroy_cb = |
| 98 base::Bind(&TextRendererTest::OnDestroyTextTrack, | 98 base::Bind(&TextRendererTest::OnDestroyTextTrack, |
| 99 base::Unretained(this), | 99 base::Unretained(this), |
| 100 text_tracks_.size()); | 100 text_tracks_.size()); |
| 101 // Text track objects are owned by the text renderer, but we cache them | 101 // Text track objects are owned by the text renderer, but we cache them |
| 102 // here so we can inspect them. They get removed from our cache when the | 102 // here so we can inspect them. They get removed from our cache when the |
| 103 // text renderer deallocates them. | 103 // text renderer deallocates them. |
| 104 text_tracks_.push_back(new FakeTextTrack(destroy_cb, config)); | 104 text_tracks_.push_back(new FakeTextTrack(destroy_cb, config)); |
| 105 std::unique_ptr<TextTrack> text_track(text_tracks_.back()); | 105 std::unique_ptr<TextTrack> text_track(text_tracks_.back()); |
| 106 done_cb.Run(std::move(text_track)); | 106 done_cb.Run(std::move(text_track)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void RemoveTextTrack(unsigned idx) { | 109 void RemoveTextTrack(unsigned idx) { |
| 110 FakeTextTrackStream* const stream = text_track_streams_[idx]; | 110 FakeTextTrackStream* const stream = text_track_streams_[idx].get(); |
| 111 text_renderer_->RemoveTextStream(stream); | 111 text_renderer_->RemoveTextStream(stream); |
| 112 EXPECT_FALSE(text_tracks_[idx]); | 112 EXPECT_FALSE(text_tracks_[idx]); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void SatisfyPendingReads(const base::TimeDelta& start, | 115 void SatisfyPendingReads(const base::TimeDelta& start, |
| 116 const base::TimeDelta& duration, | 116 const base::TimeDelta& duration, |
| 117 const std::string& id, | 117 const std::string& id, |
| 118 const std::string& content, | 118 const std::string& content, |
| 119 const std::string& settings) { | 119 const std::string& settings) { |
| 120 for (TextTrackStreams::iterator itr = text_track_streams_.begin(); | 120 for (TextTrackStreams::iterator itr = text_track_streams_.begin(); |
| 121 itr != text_track_streams_.end(); ++itr) { | 121 itr != text_track_streams_.end(); ++itr) { |
| 122 (*itr)->SatisfyPendingRead(start, duration, id, content, settings); | 122 (*itr)->SatisfyPendingRead(start, duration, id, content, settings); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 | 125 |
| 126 void AbortPendingRead(unsigned idx) { | 126 void AbortPendingRead(unsigned idx) { |
| 127 FakeTextTrackStream* const stream = text_track_streams_[idx]; | 127 FakeTextTrackStream* const stream = text_track_streams_[idx].get(); |
| 128 stream->AbortPendingRead(); | 128 stream->AbortPendingRead(); |
| 129 base::RunLoop().RunUntilIdle(); | 129 base::RunLoop().RunUntilIdle(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void AbortPendingReads() { | 132 void AbortPendingReads() { |
| 133 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { | 133 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { |
| 134 AbortPendingRead(idx); | 134 AbortPendingRead(idx); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 void SendEosNotification(unsigned idx) { | 138 void SendEosNotification(unsigned idx) { |
| 139 FakeTextTrackStream* const stream = text_track_streams_[idx]; | 139 FakeTextTrackStream* const stream = text_track_streams_[idx].get(); |
| 140 stream->SendEosNotification(); | 140 stream->SendEosNotification(); |
| 141 base::RunLoop().RunUntilIdle(); | 141 base::RunLoop().RunUntilIdle(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void SendEosNotifications() { | 144 void SendEosNotifications() { |
| 145 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { | 145 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { |
| 146 SendEosNotification(idx); | 146 SendEosNotification(idx); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 void SendCue(unsigned idx, bool expect_cue) { | 150 void SendCue(unsigned idx, bool expect_cue) { |
| 151 FakeTextTrackStream* const text_stream = text_track_streams_[idx]; | 151 FakeTextTrackStream* const text_stream = text_track_streams_[idx].get(); |
| 152 | 152 |
| 153 const base::TimeDelta start; | 153 const base::TimeDelta start; |
| 154 const base::TimeDelta duration = base::TimeDelta::FromSeconds(42); | 154 const base::TimeDelta duration = base::TimeDelta::FromSeconds(42); |
| 155 const std::string id = "id"; | 155 const std::string id = "id"; |
| 156 const std::string content = "subtitle"; | 156 const std::string content = "subtitle"; |
| 157 const std::string settings; | 157 const std::string settings; |
| 158 | 158 |
| 159 if (expect_cue) { | 159 if (expect_cue) { |
| 160 FakeTextTrack* const text_track = text_tracks_[idx]; | 160 FakeTextTrack* const text_track = text_tracks_[idx]; |
| 161 EXPECT_CALL(*text_track, addWebVTTCue(start, | 161 EXPECT_CALL(*text_track, addWebVTTCue(start, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 189 base::RunLoop().RunUntilIdle(); | 189 base::RunLoop().RunUntilIdle(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void Flush() { | 192 void Flush() { |
| 193 EXPECT_CALL(*this, OnFlush()); | 193 EXPECT_CALL(*this, OnFlush()); |
| 194 text_renderer_->Flush(base::Bind(&TextRendererTest::OnFlush, | 194 text_renderer_->Flush(base::Bind(&TextRendererTest::OnFlush, |
| 195 base::Unretained(this))); | 195 base::Unretained(this))); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void ExpectRead(size_t idx) { | 198 void ExpectRead(size_t idx) { |
| 199 FakeTextTrackStream* const stream = text_track_streams_[idx]; | 199 FakeTextTrackStream* const stream = text_track_streams_[idx].get(); |
| 200 EXPECT_CALL(*stream, OnRead()); | 200 EXPECT_CALL(*stream, OnRead()); |
| 201 } | 201 } |
| 202 | 202 |
| 203 MOCK_METHOD0(OnEnd, void()); | 203 MOCK_METHOD0(OnEnd, void()); |
| 204 MOCK_METHOD0(OnPause, void()); | 204 MOCK_METHOD0(OnPause, void()); |
| 205 MOCK_METHOD0(OnFlush, void()); | 205 MOCK_METHOD0(OnFlush, void()); |
| 206 | 206 |
| 207 base::MessageLoop message_loop_; | 207 base::MessageLoop message_loop_; |
| 208 | 208 |
| 209 typedef ScopedVector<FakeTextTrackStream> TextTrackStreams; | 209 typedef std::vector<std::unique_ptr<FakeTextTrackStream>> TextTrackStreams; |
| 210 TextTrackStreams text_track_streams_; | 210 TextTrackStreams text_track_streams_; |
| 211 | 211 |
| 212 typedef std::vector<FakeTextTrack*> TextTracks; | 212 typedef std::vector<FakeTextTrack*> TextTracks; |
| 213 TextTracks text_tracks_; | 213 TextTracks text_tracks_; |
| 214 | 214 |
| 215 std::unique_ptr<TextRenderer> text_renderer_; | 215 std::unique_ptr<TextRenderer> text_renderer_; |
| 216 | 216 |
| 217 private: | 217 private: |
| 218 DISALLOW_COPY_AND_ASSIGN(TextRendererTest); | 218 DISALLOW_COPY_AND_ASSIGN(TextRendererTest); |
| 219 }; | 219 }; |
| (...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 Play(); | 1206 Play(); |
| 1207 AbortPendingRead(0); | 1207 AbortPendingRead(0); |
| 1208 RemoveTextTrack(0); | 1208 RemoveTextTrack(0); |
| 1209 EXPECT_TRUE(text_renderer_->HasTracks()); | 1209 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1210 Pause(); | 1210 Pause(); |
| 1211 EXPECT_CALL(*this, OnPause()); | 1211 EXPECT_CALL(*this, OnPause()); |
| 1212 SendEosNotification(1); | 1212 SendEosNotification(1); |
| 1213 } | 1213 } |
| 1214 | 1214 |
| 1215 } // namespace media | 1215 } // namespace media |
| OLD | NEW |