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

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

Issue 23702007: Render inband text tracks in the media pipeline (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: incorporate aaron's comments (10/16) Created 7 years, 2 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
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 "media/filters/chunk_demuxer.h" 5 #include "media/filters/chunk_demuxer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 #include <limits> 9 #include <limits>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/message_loop/message_loop_proxy.h" 14 #include "base/message_loop/message_loop_proxy.h"
15 #include "base/stl_util.h"
15 #include "media/base/audio_decoder_config.h" 16 #include "media/base/audio_decoder_config.h"
16 #include "media/base/bind_to_loop.h" 17 #include "media/base/bind_to_loop.h"
17 #include "media/base/stream_parser_buffer.h" 18 #include "media/base/stream_parser_buffer.h"
18 #include "media/base/video_decoder_config.h" 19 #include "media/base/video_decoder_config.h"
19 #include "media/filters/stream_parser_factory.h" 20 #include "media/filters/stream_parser_factory.h"
20 #include "media/webm/webm_webvtt_parser.h"
21 21
22 using base::TimeDelta; 22 using base::TimeDelta;
23 23
24 namespace media { 24 namespace media {
25 25
26 // Contains state belonging to a source id. 26 // Contains state belonging to a source id.
27 class SourceState { 27 class SourceState {
28 public: 28 public:
29 // Callback signature used to create ChunkDemuxerStreams. 29 // Callback signature used to create ChunkDemuxerStreams.
30 typedef base::Callback<ChunkDemuxerStream*( 30 typedef base::Callback<ChunkDemuxerStream*(
31 DemuxerStream::Type)> CreateDemuxerStreamCB; 31 DemuxerStream::Type)> CreateDemuxerStreamCB;
32 32
33 // Callback signature used to notify ChunkDemuxer of timestamps 33 // Callback signature used to notify ChunkDemuxer of timestamps
34 // that may cause the duration to be updated. 34 // that may cause the duration to be updated.
35 typedef base::Callback<void( 35 typedef base::Callback<void(
36 TimeDelta, ChunkDemuxerStream*)> IncreaseDurationCB; 36 TimeDelta, ChunkDemuxerStream*)> IncreaseDurationCB;
37 37
38 SourceState(scoped_ptr<StreamParser> stream_parser, const LogCB& log_cb, 38 SourceState(scoped_ptr<StreamParser> stream_parser, const LogCB& log_cb,
39 const CreateDemuxerStreamCB& create_demuxer_stream_cb, 39 const CreateDemuxerStreamCB& create_demuxer_stream_cb,
40 const IncreaseDurationCB& increase_duration_cb); 40 const IncreaseDurationCB& increase_duration_cb);
41 41
42 ~SourceState();
43
42 void Init(const StreamParser::InitCB& init_cb, 44 void Init(const StreamParser::InitCB& init_cb,
43 bool allow_audio, 45 bool allow_audio,
44 bool allow_video, 46 bool allow_video,
45 const StreamParser::NewTextBuffersCB& text_cb,
46 const StreamParser::NeedKeyCB& need_key_cb, 47 const StreamParser::NeedKeyCB& need_key_cb,
47 const AddTextTrackCB& add_text_track_cb); 48 bool enable_text_tracks);
48 49
49 // Appends new data to the StreamParser. 50 // Appends new data to the StreamParser.
50 // Returns true if the data was successfully appended. Returns false if an 51 // Returns true if the data was successfully appended. Returns false if an
51 // error occurred. 52 // error occurred.
52 bool Append(const uint8* data, size_t length); 53 bool Append(const uint8* data, size_t length);
53 54
54 // Aborts the current append sequence and resets the parser. 55 // Aborts the current append sequence and resets the parser.
55 void Abort(); 56 void Abort();
56 57
57 // Sets |timestamp_offset_| if possible. 58 // Sets |timestamp_offset_| if possible.
58 // Returns if the offset was set. Returns false if the offset could not be 59 // Returns if the offset was set. Returns false if the offset could not be
59 // updated at this time. 60 // updated at this time.
60 bool SetTimestampOffset(TimeDelta timestamp_offset); 61 bool SetTimestampOffset(TimeDelta timestamp_offset);
61 62
62 TimeDelta timestamp_offset() const { return timestamp_offset_; } 63 TimeDelta timestamp_offset() const { return timestamp_offset_; }
63 64
64 void set_append_window_start(TimeDelta start) { 65 void set_append_window_start(TimeDelta start) {
65 append_window_start_ = start; 66 append_window_start_ = start;
66 } 67 }
67 void set_append_window_end(TimeDelta end) { append_window_end_ = end; } 68 void set_append_window_end(TimeDelta end) { append_window_end_ = end; }
68 69
70 void TextStartReturningData();
71 void TextAbortReads();
72 void TextSeek(TimeDelta);
acolwell GONE FROM CHROMIUM 2013/10/21 20:10:40 nit: Specify parameter name here.
Matthew Heaney (Chromium) 2013/10/23 05:09:01 Done.
73 void TextCompletePendingReadIfPossible();
74
69 private: 75 private:
70 // Called by the |stream_parser_| when a new initialization segment is 76 // Called by the |stream_parser_| when a new initialization segment is
71 // encountered. 77 // encountered.
72 // Returns true on a successful call. Returns false if an error occured while 78 // Returns true on a successful call. Returns false if an error occured while
73 // processing decoder configurations. 79 // processing decoder configurations.
74 bool OnNewConfigs(bool allow_audio, bool allow_video, 80 bool OnNewConfigs(bool allow_audio, bool allow_video,
75 const AudioDecoderConfig& audio_config, 81 const AudioDecoderConfig& audio_config,
76 const VideoDecoderConfig& video_config); 82 const VideoDecoderConfig& video_config,
83 const TextTrackConfigMap& text_track_config_map);
77 84
78 // Called by the |stream_parser_| at the beginning of a new media segment. 85 // Called by the |stream_parser_| at the beginning of a new media segment.
79 void OnNewMediaSegment(); 86 void OnNewMediaSegment();
80 87
81 // Called by the |stream_parser_| at the end of a media segment. 88 // Called by the |stream_parser_| at the end of a media segment.
82 void OnEndOfMediaSegment(); 89 void OnEndOfMediaSegment();
83 90
84 // Called by the |stream_parser_| when new buffers have been parsed. It 91 // Called by the |stream_parser_| when new buffers have been parsed. It
85 // applies |timestamp_offset_| to all buffers in |audio_buffers| and 92 // applies |timestamp_offset_| to all buffers in |audio_buffers| and
86 // |video_buffers| and then calls Append() on |audio_| and/or 93 // |video_buffers| and then calls Append() on |audio_| and/or
87 // |video_| with the modified buffers. 94 // |video_| with the modified buffers.
88 // Returns true on a successful call. Returns false if an error occured while 95 // Returns true on a successful call. Returns false if an error occured while
89 // processing the buffers. 96 // processing the buffers.
90 bool OnNewBuffers(const StreamParser::BufferQueue& audio_buffers, 97 bool OnNewBuffers(const StreamParser::BufferQueue& audio_buffers,
91 const StreamParser::BufferQueue& video_buffers); 98 const StreamParser::BufferQueue& video_buffers);
92 99
93 // Called by the |stream_parser_| when new text buffers have been parsed. It 100 // Called by the |stream_parser_| when new text buffers have been parsed. It
94 // applies |timestamp_offset_| to all buffers in |buffers| and then calls 101 // applies |timestamp_offset_| to all buffers in |buffers| and then appends
95 // |new_buffers_cb| with the modified buffers. 102 // the (modified) buffers to the demuxer stream associated with
103 // the track having |text_track_number|.
96 // Returns true on a successful call. Returns false if an error occured while 104 // Returns true on a successful call. Returns false if an error occured while
97 // processing the buffers. 105 // processing the buffers.
98 bool OnTextBuffers(const StreamParser::NewTextBuffersCB& new_buffers_cb, 106 bool OnTextBuffers(int text_track_number,
99 TextTrack* text_track,
100 const StreamParser::BufferQueue& buffers); 107 const StreamParser::BufferQueue& buffers);
101 108
102 // Helper function that adds |timestamp_offset_| to each buffer in |buffers|. 109 // Helper function that adds |timestamp_offset_| to each buffer in |buffers|.
103 void AdjustBufferTimestamps(const StreamParser::BufferQueue& buffers); 110 void AdjustBufferTimestamps(const StreamParser::BufferQueue& buffers);
104 111
105 // Filters out buffers that are outside of the append window 112 // Filters out buffers that are outside of the append window
106 // [|append_window_start_|, |append_window_end_|). 113 // [|append_window_start_|, |append_window_end_|).
107 // |needs_keyframe| is a pointer to the |xxx_need_keyframe_| flag 114 // |needs_keyframe| is a pointer to the |xxx_need_keyframe_| flag
108 // associated with the |buffers|. Its state is read an updated as 115 // associated with the |buffers|. Its state is read an updated as
109 // this method filters |buffers|. 116 // this method filters |buffers|.
(...skipping 25 matching lines...) Expand all
135 142
136 // The object used to parse appended data. 143 // The object used to parse appended data.
137 scoped_ptr<StreamParser> stream_parser_; 144 scoped_ptr<StreamParser> stream_parser_;
138 145
139 ChunkDemuxerStream* audio_; 146 ChunkDemuxerStream* audio_;
140 bool audio_needs_keyframe_; 147 bool audio_needs_keyframe_;
141 148
142 ChunkDemuxerStream* video_; 149 ChunkDemuxerStream* video_;
143 bool video_needs_keyframe_; 150 bool video_needs_keyframe_;
144 151
152 typedef std::map<int, ChunkDemuxerStream*> TextStreamMap;
153 TextStreamMap text_stream_map_;
154
145 LogCB log_cb_; 155 LogCB log_cb_;
146 156
147 DISALLOW_COPY_AND_ASSIGN(SourceState); 157 DISALLOW_COPY_AND_ASSIGN(SourceState);
148 }; 158 };
149 159
150 class ChunkDemuxerStream : public DemuxerStream { 160 class ChunkDemuxerStream : public DemuxerStream {
151 public: 161 public:
152 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; 162 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue;
153 163
154 explicit ChunkDemuxerStream(Type type); 164 explicit ChunkDemuxerStream(Type type);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 196
187 // Signal to the stream that buffers handed in through subsequent calls to 197 // Signal to the stream that buffers handed in through subsequent calls to
188 // Append() belong to a media segment that starts at |start_timestamp|. 198 // Append() belong to a media segment that starts at |start_timestamp|.
189 void OnNewMediaSegment(TimeDelta start_timestamp); 199 void OnNewMediaSegment(TimeDelta start_timestamp);
190 200
191 // Called when midstream config updates occur. 201 // Called when midstream config updates occur.
192 // Returns true if the new config is accepted. 202 // Returns true if the new config is accepted.
193 // Returns false if the new config should trigger an error. 203 // Returns false if the new config should trigger an error.
194 bool UpdateAudioConfig(const AudioDecoderConfig& config, const LogCB& log_cb); 204 bool UpdateAudioConfig(const AudioDecoderConfig& config, const LogCB& log_cb);
195 bool UpdateVideoConfig(const VideoDecoderConfig& config, const LogCB& log_cb); 205 bool UpdateVideoConfig(const VideoDecoderConfig& config, const LogCB& log_cb);
206 void UpdateTextConfig(const TextTrackConfig& config, const LogCB& log_cb);
196 207
197 void MarkEndOfStream(); 208 void MarkEndOfStream();
198 void UnmarkEndOfStream(); 209 void UnmarkEndOfStream();
199 210
200 // DemuxerStream methods. 211 // DemuxerStream methods.
201 virtual void Read(const ReadCB& read_cb) OVERRIDE; 212 virtual void Read(const ReadCB& read_cb) OVERRIDE;
202 virtual Type type() OVERRIDE; 213 virtual Type type() OVERRIDE;
203 virtual void EnableBitstreamConverter() OVERRIDE; 214 virtual void EnableBitstreamConverter() OVERRIDE;
204 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE; 215 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE;
205 virtual VideoDecoderConfig video_decoder_config() OVERRIDE; 216 virtual VideoDecoderConfig video_decoder_config() OVERRIDE;
217 virtual TextTrackConfig text_track_config() OVERRIDE;
206 218
207 void set_memory_limit_for_testing(int memory_limit) { 219 void set_memory_limit_for_testing(int memory_limit) {
208 stream_->set_memory_limit_for_testing(memory_limit); 220 stream_->set_memory_limit_for_testing(memory_limit);
209 } 221 }
210 222
211 private: 223 private:
212 enum State { 224 enum State {
213 UNINITIALIZED, 225 UNINITIALIZED,
214 RETURNING_DATA_FOR_READS, 226 RETURNING_DATA_FOR_READS,
215 RETURNING_ABORT_FOR_READS, 227 RETURNING_ABORT_FOR_READS,
216 SHUTDOWN, 228 SHUTDOWN,
217 }; 229 };
218 230
219 // Assigns |state_| to |state| 231 // Assigns |state_| to |state|
220 void ChangeState_Locked(State state); 232 void ChangeState_Locked(State state);
221 233
222 void CompletePendingReadIfPossible_Locked(); 234 void CompletePendingReadIfPossible_Locked();
223 235
224 // Gets the value to pass to the next Read() callback. Returns true if 236 // Gets the value to pass to the next Read() callback. Returns true if
225 // |status| and |buffer| should be passed to the callback. False indicates 237 // |status| and |buffer| should be passed to the callback. False indicates
226 // that |status| and |buffer| were not set and more data is needed. 238 // that |status| and |buffer| were not set and more data is needed.
227 bool GetNextBuffer_Locked(DemuxerStream::Status* status, 239 bool GetNextBuffer_Locked(DemuxerStream::Status* status,
228 scoped_refptr<StreamParserBuffer>* buffer); 240 scoped_refptr<StreamParserBuffer>* buffer);
229 241
230 // Specifies the type of the stream (must be AUDIO or VIDEO for now). 242 // Specifies the type of the stream.
231 Type type_; 243 Type type_;
232 244
233 scoped_ptr<SourceBufferStream> stream_; 245 scoped_ptr<SourceBufferStream> stream_;
234 246
235 mutable base::Lock lock_; 247 mutable base::Lock lock_;
236 State state_; 248 State state_;
237 ReadCB read_cb_; 249 ReadCB read_cb_;
238 250
239 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream); 251 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream);
240 }; 252 };
(...skipping 10 matching lines...) Expand all
251 stream_parser_(stream_parser.release()), 263 stream_parser_(stream_parser.release()),
252 audio_(NULL), 264 audio_(NULL),
253 audio_needs_keyframe_(true), 265 audio_needs_keyframe_(true),
254 video_(NULL), 266 video_(NULL),
255 video_needs_keyframe_(true), 267 video_needs_keyframe_(true),
256 log_cb_(log_cb) { 268 log_cb_(log_cb) {
257 DCHECK(!create_demuxer_stream_cb_.is_null()); 269 DCHECK(!create_demuxer_stream_cb_.is_null());
258 DCHECK(!increase_duration_cb_.is_null()); 270 DCHECK(!increase_duration_cb_.is_null());
259 } 271 }
260 272
273 SourceState::~SourceState() {
274 STLDeleteValues(&text_stream_map_);
acolwell GONE FROM CHROMIUM 2013/10/21 20:10:40 I believe you may need to call Shutdown() on each
Matthew Heaney (Chromium) 2013/10/23 05:09:01 Done.
275 }
276
261 void SourceState::Init(const StreamParser::InitCB& init_cb, 277 void SourceState::Init(const StreamParser::InitCB& init_cb,
262 bool allow_audio, 278 bool allow_audio,
263 bool allow_video, 279 bool allow_video,
264 const StreamParser::NewTextBuffersCB& text_cb,
265 const StreamParser::NeedKeyCB& need_key_cb, 280 const StreamParser::NeedKeyCB& need_key_cb,
266 const AddTextTrackCB& add_text_track_cb) { 281 bool enable_text_tracks) {
267 StreamParser::NewBuffersCB audio_cb; 282 StreamParser::NewBuffersCB audio_cb;
268 283
269 stream_parser_->Init(init_cb, 284 stream_parser_->Init(init_cb,
270 base::Bind(&SourceState::OnNewConfigs, 285 base::Bind(&SourceState::OnNewConfigs,
271 base::Unretained(this), 286 base::Unretained(this),
272 allow_audio, 287 allow_audio,
273 allow_video), 288 allow_video),
274 base::Bind(&SourceState::OnNewBuffers, 289 base::Bind(&SourceState::OnNewBuffers,
275 base::Unretained(this)), 290 base::Unretained(this)),
276 base::Bind(&SourceState::OnTextBuffers, 291 base::Bind(&SourceState::OnTextBuffers,
277 base::Unretained(this), text_cb), 292 base::Unretained(this)),
278 need_key_cb, 293 need_key_cb,
279 add_text_track_cb, 294 enable_text_tracks,
280 base::Bind(&SourceState::OnNewMediaSegment, 295 base::Bind(&SourceState::OnNewMediaSegment,
281 base::Unretained(this)), 296 base::Unretained(this)),
282 base::Bind(&SourceState::OnEndOfMediaSegment, 297 base::Bind(&SourceState::OnEndOfMediaSegment,
283 base::Unretained(this)), 298 base::Unretained(this)),
284 log_cb_); 299 log_cb_);
285 } 300 }
286 301
287 bool SourceState::SetTimestampOffset(TimeDelta timestamp_offset) { 302 bool SourceState::SetTimestampOffset(TimeDelta timestamp_offset) {
288 if (!can_update_offset_) 303 if (!can_update_offset_)
289 return false; 304 return false;
290 305
291 timestamp_offset_ = timestamp_offset; 306 timestamp_offset_ = timestamp_offset;
292 return true; 307 return true;
293 } 308 }
294 309
295 bool SourceState::Append(const uint8* data, size_t length) { 310 bool SourceState::Append(const uint8* data, size_t length) {
296 return stream_parser_->Parse(data, length); 311 return stream_parser_->Parse(data, length);
297 } 312 }
298 313
299 void SourceState::Abort() { 314 void SourceState::Abort() {
300 stream_parser_->Flush(); 315 stream_parser_->Flush();
301 audio_needs_keyframe_ = true; 316 audio_needs_keyframe_ = true;
302 video_needs_keyframe_ = true; 317 video_needs_keyframe_ = true;
303 can_update_offset_ = true; 318 can_update_offset_ = true;
304 } 319 }
305 320
321
322 void SourceState::TextStartReturningData() {
323 for (TextStreamMap::iterator itr = text_stream_map_.begin();
324 itr != text_stream_map_.end(); ++itr) {
325 itr->second->StartReturningData();
326 }
327 }
328
329 void SourceState::TextAbortReads() {
330 for (TextStreamMap::iterator itr = text_stream_map_.begin();
331 itr != text_stream_map_.end(); ++itr) {
332 itr->second->AbortReads();
333 }
334 }
335
336 void SourceState::TextSeek(TimeDelta time) {
337 for (TextStreamMap::iterator itr = text_stream_map_.begin();
338 itr != text_stream_map_.end(); ++itr) {
339 itr->second->Seek(time);
340 }
341 }
342
343 void SourceState::TextCompletePendingReadIfPossible() {
344 for (TextStreamMap::iterator itr = text_stream_map_.begin();
345 itr != text_stream_map_.end(); ++itr) {
346 itr->second->CompletePendingReadIfPossible();
347 }
348 }
349
306 void SourceState::AdjustBufferTimestamps( 350 void SourceState::AdjustBufferTimestamps(
307 const StreamParser::BufferQueue& buffers) { 351 const StreamParser::BufferQueue& buffers) {
308 if (timestamp_offset_ == TimeDelta()) 352 if (timestamp_offset_ == TimeDelta())
309 return; 353 return;
310 354
311 for (StreamParser::BufferQueue::const_iterator itr = buffers.begin(); 355 for (StreamParser::BufferQueue::const_iterator itr = buffers.begin();
312 itr != buffers.end(); ++itr) { 356 itr != buffers.end(); ++itr) {
313 (*itr)->SetDecodeTimestamp( 357 (*itr)->SetDecodeTimestamp(
314 (*itr)->GetDecodeTimestamp() + timestamp_offset_); 358 (*itr)->GetDecodeTimestamp() + timestamp_offset_);
315 (*itr)->set_timestamp((*itr)->timestamp() + timestamp_offset_); 359 (*itr)->set_timestamp((*itr)->timestamp() + timestamp_offset_);
316 } 360 }
317 } 361 }
318 362
319 bool SourceState::OnNewConfigs(bool allow_audio, bool allow_video, 363 bool SourceState::OnNewConfigs(bool allow_audio, bool allow_video,
320 const AudioDecoderConfig& audio_config, 364 const AudioDecoderConfig& audio_config,
321 const VideoDecoderConfig& video_config) { 365 const VideoDecoderConfig& video_config,
366 const TextTrackConfigMap& text_config) {
acolwell GONE FROM CHROMIUM 2013/10/21 20:10:40 nit: s/test_config/text_configs/
Matthew Heaney (Chromium) 2013/10/23 05:09:01 Done.
322 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video 367 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video
323 << ", " << audio_config.IsValidConfig() 368 << ", " << audio_config.IsValidConfig()
324 << ", " << video_config.IsValidConfig() << ")"; 369 << ", " << video_config.IsValidConfig() << ")";
325 370
326 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { 371 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) {
327 DVLOG(1) << "OnNewConfigs() : Audio & video config are not valid!"; 372 DVLOG(1) << "OnNewConfigs() : Audio & video config are not valid!";
328 return false; 373 return false;
329 } 374 }
330 375
331 // Signal an error if we get configuration info for stream types that weren't 376 // Signal an error if we get configuration info for stream types that weren't
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 415
371 if (!video_) { 416 if (!video_) {
372 DVLOG(1) << "Failed to create a video stream."; 417 DVLOG(1) << "Failed to create a video stream.";
373 return false; 418 return false;
374 } 419 }
375 } 420 }
376 421
377 success &= video_->UpdateVideoConfig(video_config, log_cb_); 422 success &= video_->UpdateVideoConfig(video_config, log_cb_);
378 } 423 }
379 424
425 if (text_stream_map_.empty()) {
426 for (TextTrackConfigMap::const_iterator itr = text_config.begin();
427 itr != text_config.end(); ++itr) {
428 ChunkDemuxerStream* const text_stream =
429 create_demuxer_stream_cb_.Run(DemuxerStream::TEXT);
430 text_stream->UpdateTextConfig(itr->second, log_cb_);
431 text_stream_map_[itr->first] = text_stream;
432 }
433 // TODO(matthewjheaney): must callback chunk demuxer, so it can notify
434 // its host to add text stream(s).
435 } else {
436 const TextStreamMap::size_type text_count = text_stream_map_.size();
acolwell GONE FROM CHROMIUM 2013/10/21 20:10:40 nit: Please just use size_t here.
Matthew Heaney (Chromium) 2013/10/23 05:09:01 Done.
437 if (text_config.size() != text_count) {
438 success &= false;
439 } else if (text_count == 1) {
440 TextTrackConfigMap::const_iterator config_itr = text_config.begin();
441 const TextTrackConfig& new_config = config_itr->second;
442 TextStreamMap::iterator stream_itr = text_stream_map_.begin();
443 ChunkDemuxerStream* stream = stream_itr->second;
444 TextTrackConfig old_config = stream->text_track_config();
445 if (!new_config.Matches(old_config)) {
446 success &= false;
447 } else {
448 // TODO(matthewjheaney): replace old with new
acolwell GONE FROM CHROMIUM 2013/10/21 20:10:40 I think this is just text_stream_map_.clear(). te
Matthew Heaney (Chromium) 2013/10/23 05:09:01 Done.
449 }
450 } else {
451 for (TextTrackConfigMap::const_iterator config_itr = text_config.begin();
452 config_itr != text_config.end(); ++config_itr) {
453 TextStreamMap::iterator stream_itr =
454 text_stream_map_.find(config_itr->first);
455 if (stream_itr == text_stream_map_.end()) {
456 success &= false;
acolwell GONE FROM CHROMIUM 2013/10/21 20:10:40 nit: Break out of the loop here and then drop the
Matthew Heaney (Chromium) 2013/10/23 05:09:01 Done.
457 } else {
458 const TextTrackConfig& new_config = config_itr->second;
459 ChunkDemuxerStream* stream = stream_itr->second;
460 TextTrackConfig old_config = stream->text_track_config();
461 if (!new_config.Matches(old_config)) {
462 success &= false;
463 }
464 }
465 }
466
467 // TODO(matthewjheaney): if all configs match, then replace old with new
acolwell GONE FROM CHROMIUM 2013/10/21 20:10:40 I don't think you need to do anything here. If the
Matthew Heaney (Chromium) 2013/10/23 05:09:01 Done.
468 }
469 }
470
380 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); 471 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed");
381 return success; 472 return success;
382 } 473 }
383 474
384 void SourceState::OnNewMediaSegment() { 475 void SourceState::OnNewMediaSegment() {
385 DVLOG(2) << "OnNewMediaSegment()"; 476 DVLOG(2) << "OnNewMediaSegment()";
386 can_update_offset_ = false; 477 can_update_offset_ = false;
387 new_media_segment_ = true; 478 new_media_segment_ = true;
388 } 479 }
389 480
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 segment_timestamp = filtered_video.front()->GetDecodeTimestamp(); 516 segment_timestamp = filtered_video.front()->GetDecodeTimestamp();
426 } 517 }
427 518
428 new_media_segment_ = false; 519 new_media_segment_ = false;
429 520
430 if (audio_) 521 if (audio_)
431 audio_->OnNewMediaSegment(segment_timestamp); 522 audio_->OnNewMediaSegment(segment_timestamp);
432 523
433 if (video_) 524 if (video_)
434 video_->OnNewMediaSegment(segment_timestamp); 525 video_->OnNewMediaSegment(segment_timestamp);
526
527 for (TextStreamMap::iterator itr = text_stream_map_.begin();
528 itr != text_stream_map_.end(); ++itr) {
529 itr->second->OnNewMediaSegment(segment_timestamp);
530 }
435 } 531 }
436 532
437 if (!filtered_audio.empty()) { 533 if (!filtered_audio.empty()) {
438 if (!audio_ || !audio_->Append(filtered_audio)) 534 if (!audio_ || !audio_->Append(filtered_audio))
439 return false; 535 return false;
440 increase_duration_cb_.Run(filtered_audio.back()->timestamp(), audio_); 536 increase_duration_cb_.Run(filtered_audio.back()->timestamp(), audio_);
441 } 537 }
442 538
443 if (!filtered_video.empty()) { 539 if (!filtered_video.empty()) {
444 if (!video_ || !video_->Append(filtered_video)) 540 if (!video_ || !video_->Append(filtered_video))
445 return false; 541 return false;
446 increase_duration_cb_.Run(filtered_video.back()->timestamp(), video_); 542 increase_duration_cb_.Run(filtered_video.back()->timestamp(), video_);
447 } 543 }
448 544
449 return true; 545 return true;
450 } 546 }
451 547
452 bool SourceState::OnTextBuffers( 548 bool SourceState::OnTextBuffers(
453 const StreamParser::NewTextBuffersCB& new_buffers_cb, 549 int text_track_number,
454 TextTrack* text_track,
455 const StreamParser::BufferQueue& buffers) { 550 const StreamParser::BufferQueue& buffers) {
456 if (new_buffers_cb.is_null()) 551 DCHECK(!buffers.empty());
552
553 TextStreamMap::iterator itr = text_stream_map_.find(text_track_number);
554 if (itr == text_stream_map_.end())
457 return false; 555 return false;
458 556
459 AdjustBufferTimestamps(buffers); 557 AdjustBufferTimestamps(buffers);
460 558
461 return new_buffers_cb.Run(text_track, buffers); 559 return itr->second->Append(buffers);
462 } 560 }
463 561
464 void SourceState::FilterWithAppendWindow( 562 void SourceState::FilterWithAppendWindow(
465 const StreamParser::BufferQueue& buffers, bool* needs_keyframe, 563 const StreamParser::BufferQueue& buffers, bool* needs_keyframe,
466 StreamParser::BufferQueue* filtered_buffers) { 564 StreamParser::BufferQueue* filtered_buffers) {
467 DCHECK(needs_keyframe); 565 DCHECK(needs_keyframe);
468 DCHECK(filtered_buffers); 566 DCHECK(filtered_buffers);
469 567
470 // This loop implements steps 1.9, 1.10, & 1.11 of the "Coded frame 568 // This loop implements steps 1.9, 1.10, & 1.11 of the "Coded frame
471 // processing loop" in the Media Source Extensions spec. 569 // processing loop" in the Media Source Extensions spec.
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 740
643 if (!stream_) { 741 if (!stream_) {
644 DCHECK_EQ(state_, UNINITIALIZED); 742 DCHECK_EQ(state_, UNINITIALIZED);
645 stream_.reset(new SourceBufferStream(config, log_cb)); 743 stream_.reset(new SourceBufferStream(config, log_cb));
646 return true; 744 return true;
647 } 745 }
648 746
649 return stream_->UpdateVideoConfig(config); 747 return stream_->UpdateVideoConfig(config);
650 } 748 }
651 749
750 void ChunkDemuxerStream::UpdateTextConfig(const TextTrackConfig& config,
751 const LogCB& log_cb) {
752 DCHECK_EQ(type_, TEXT);
753 base::AutoLock auto_lock(lock_);
754
755 if (!stream_) {
acolwell GONE FROM CHROMIUM 2013/10/21 20:10:40 Since we don't update TextTrackConfigs, you should
Matthew Heaney (Chromium) 2013/10/23 05:09:01 Done.
756 DCHECK_EQ(state_, UNINITIALIZED);
757 stream_.reset(new SourceBufferStream(config, log_cb));
758 }
759 }
760
652 void ChunkDemuxerStream::MarkEndOfStream() { 761 void ChunkDemuxerStream::MarkEndOfStream() {
653 base::AutoLock auto_lock(lock_); 762 base::AutoLock auto_lock(lock_);
654 stream_->MarkEndOfStream(); 763 stream_->MarkEndOfStream();
655 } 764 }
656 765
657 void ChunkDemuxerStream::UnmarkEndOfStream() { 766 void ChunkDemuxerStream::UnmarkEndOfStream() {
658 base::AutoLock auto_lock(lock_); 767 base::AutoLock auto_lock(lock_);
659 stream_->UnmarkEndOfStream(); 768 stream_->UnmarkEndOfStream();
660 } 769 }
661 770
(...skipping 16 matching lines...) Expand all
678 base::AutoLock auto_lock(lock_); 787 base::AutoLock auto_lock(lock_);
679 return stream_->GetCurrentAudioDecoderConfig(); 788 return stream_->GetCurrentAudioDecoderConfig();
680 } 789 }
681 790
682 VideoDecoderConfig ChunkDemuxerStream::video_decoder_config() { 791 VideoDecoderConfig ChunkDemuxerStream::video_decoder_config() {
683 CHECK_EQ(type_, VIDEO); 792 CHECK_EQ(type_, VIDEO);
684 base::AutoLock auto_lock(lock_); 793 base::AutoLock auto_lock(lock_);
685 return stream_->GetCurrentVideoDecoderConfig(); 794 return stream_->GetCurrentVideoDecoderConfig();
686 } 795 }
687 796
797 TextTrackConfig ChunkDemuxerStream::text_track_config() {
798 CHECK_EQ(type_, TEXT);
799 base::AutoLock auto_lock(lock_);
800 return stream_->GetCurrentTextTrackConfig();
801 }
802
688 void ChunkDemuxerStream::ChangeState_Locked(State state) { 803 void ChunkDemuxerStream::ChangeState_Locked(State state) {
689 lock_.AssertAcquired(); 804 lock_.AssertAcquired();
690 DVLOG(1) << "ChunkDemuxerStream::ChangeState_Locked() : " 805 DVLOG(1) << "ChunkDemuxerStream::ChangeState_Locked() : "
691 << "type " << type_ 806 << "type " << type_
692 << " - " << state_ << " -> " << state; 807 << " - " << state_ << " -> " << state;
693 state_ = state; 808 state_ = state;
694 } 809 }
695 810
696 ChunkDemuxerStream::~ChunkDemuxerStream() {} 811 ChunkDemuxerStream::~ChunkDemuxerStream() {}
697 812
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 status = DemuxerStream::kOk; 852 status = DemuxerStream::kOk;
738 buffer = StreamParserBuffer::CreateEOSBuffer(); 853 buffer = StreamParserBuffer::CreateEOSBuffer();
739 break; 854 break;
740 } 855 }
741 856
742 base::ResetAndReturn(&read_cb_).Run(status, buffer); 857 base::ResetAndReturn(&read_cb_).Run(status, buffer);
743 } 858 }
744 859
745 ChunkDemuxer::ChunkDemuxer(const base::Closure& open_cb, 860 ChunkDemuxer::ChunkDemuxer(const base::Closure& open_cb,
746 const NeedKeyCB& need_key_cb, 861 const NeedKeyCB& need_key_cb,
747 const AddTextTrackCB& add_text_track_cb, 862 bool enable_text,
748 const LogCB& log_cb) 863 const LogCB& log_cb)
749 : state_(WAITING_FOR_INIT), 864 : state_(WAITING_FOR_INIT),
750 cancel_next_seek_(false), 865 cancel_next_seek_(false),
751 host_(NULL), 866 host_(NULL),
752 open_cb_(open_cb), 867 open_cb_(open_cb),
753 need_key_cb_(need_key_cb), 868 need_key_cb_(need_key_cb),
754 add_text_track_cb_(add_text_track_cb), 869 enable_text_(enable_text),
755 log_cb_(log_cb), 870 log_cb_(log_cb),
756 duration_(kNoTimestamp()), 871 duration_(kNoTimestamp()),
757 user_specified_duration_(-1) { 872 user_specified_duration_(-1) {
758 DCHECK(!open_cb_.is_null()); 873 DCHECK(!open_cb_.is_null());
759 DCHECK(!need_key_cb_.is_null()); 874 DCHECK(!need_key_cb_.is_null());
760 } 875 }
761 876
762 void ChunkDemuxer::Initialize(DemuxerHost* host, const PipelineStatusCB& cb) { 877 void ChunkDemuxer::Initialize(DemuxerHost* host, const PipelineStatusCB& cb) {
763 DVLOG(1) << "Init()"; 878 DVLOG(1) << "Init()";
764 879
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 } 929 }
815 930
816 void ChunkDemuxer::OnAudioRendererDisabled() { 931 void ChunkDemuxer::OnAudioRendererDisabled() {
817 base::AutoLock auto_lock(lock_); 932 base::AutoLock auto_lock(lock_);
818 audio_->Shutdown(); 933 audio_->Shutdown();
819 disabled_audio_ = audio_.Pass(); 934 disabled_audio_ = audio_.Pass();
820 } 935 }
821 936
822 // Demuxer implementation. 937 // Demuxer implementation.
823 DemuxerStream* ChunkDemuxer::GetStream(DemuxerStream::Type type) { 938 DemuxerStream* ChunkDemuxer::GetStream(DemuxerStream::Type type) {
939 DCHECK_NE(type, DemuxerStream::TEXT);
824 base::AutoLock auto_lock(lock_); 940 base::AutoLock auto_lock(lock_);
825 if (type == DemuxerStream::VIDEO) 941 if (type == DemuxerStream::VIDEO)
826 return video_.get(); 942 return video_.get();
827 943
828 if (type == DemuxerStream::AUDIO) 944 if (type == DemuxerStream::AUDIO)
829 return audio_.get(); 945 return audio_.get();
830 946
831 return NULL; 947 return NULL;
832 } 948 }
833 949
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 new SourceState(stream_parser.Pass(), log_cb_, 1019 new SourceState(stream_parser.Pass(), log_cb_,
904 base::Bind(&ChunkDemuxer::CreateDemuxerStream, 1020 base::Bind(&ChunkDemuxer::CreateDemuxerStream,
905 base::Unretained(this)), 1021 base::Unretained(this)),
906 base::Bind(&ChunkDemuxer::IncreaseDurationIfNecessary, 1022 base::Bind(&ChunkDemuxer::IncreaseDurationIfNecessary,
907 base::Unretained(this)))); 1023 base::Unretained(this))));
908 1024
909 source_state->Init( 1025 source_state->Init(
910 base::Bind(&ChunkDemuxer::OnSourceInitDone, base::Unretained(this)), 1026 base::Bind(&ChunkDemuxer::OnSourceInitDone, base::Unretained(this)),
911 has_audio, 1027 has_audio,
912 has_video, 1028 has_video,
913 base::Bind(&ChunkDemuxer::OnTextBuffers, base::Unretained(this)),
914 need_key_cb_, 1029 need_key_cb_,
915 add_text_track_cb_); 1030 enable_text_);
916 1031
917 source_state_map_[id] = source_state.release(); 1032 source_state_map_[id] = source_state.release();
918 return kOk; 1033 return kOk;
919 } 1034 }
920 1035
921 void ChunkDemuxer::RemoveId(const std::string& id) { 1036 void ChunkDemuxer::RemoveId(const std::string& id) {
922 base::AutoLock auto_lock(lock_); 1037 base::AutoLock auto_lock(lock_);
923 CHECK(IsValidId(id)); 1038 CHECK(IsValidId(id));
924 1039
925 delete source_state_map_[id]; 1040 delete source_state_map_[id];
926 source_state_map_.erase(id); 1041 source_state_map_.erase(id);
927 1042
928 if (source_id_audio_ == id) { 1043 if (source_id_audio_ == id) {
929 if (audio_) 1044 if (audio_)
930 audio_->Shutdown(); 1045 audio_->Shutdown();
931 source_id_audio_.clear(); 1046 source_id_audio_.clear();
932 } 1047 }
933 1048
934 if (source_id_video_ == id) { 1049 if (source_id_video_ == id) {
935 if (video_) 1050 if (video_)
936 video_->Shutdown(); 1051 video_->Shutdown();
937 source_id_video_.clear(); 1052 source_id_video_.clear();
938 } 1053 }
1054
1055 // TODO(matthewjheaney): delete the text streams associated with this id
acolwell GONE FROM CHROMIUM 2013/10/21 20:10:40 nit: No longer needed since the streams get delete
Matthew Heaney (Chromium) 2013/10/23 05:09:01 Done.
939 } 1056 }
940 1057
941 Ranges<TimeDelta> ChunkDemuxer::GetBufferedRanges(const std::string& id) const { 1058 Ranges<TimeDelta> ChunkDemuxer::GetBufferedRanges(const std::string& id) const {
942 base::AutoLock auto_lock(lock_); 1059 base::AutoLock auto_lock(lock_);
943 DCHECK(!id.empty()); 1060 DCHECK(!id.empty());
944 DCHECK(IsValidId(id)); 1061 DCHECK(IsValidId(id));
945 DCHECK(id == source_id_audio_ || id == source_id_video_); 1062 DCHECK(id == source_id_audio_ || id == source_id_video_);
946 1063
947 if (id == source_id_audio_ && id != source_id_video_) { 1064 if (id == source_id_audio_ && id != source_id_video_) {
948 // Only include ranges that have been buffered in |audio_| 1065 // Only include ranges that have been buffered in |audio_|
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 return NULL; 1452 return NULL;
1336 audio_.reset(new ChunkDemuxerStream(DemuxerStream::AUDIO)); 1453 audio_.reset(new ChunkDemuxerStream(DemuxerStream::AUDIO));
1337 return audio_.get(); 1454 return audio_.get();
1338 break; 1455 break;
1339 case DemuxerStream::VIDEO: 1456 case DemuxerStream::VIDEO:
1340 if (video_) 1457 if (video_)
1341 return NULL; 1458 return NULL;
1342 video_.reset(new ChunkDemuxerStream(DemuxerStream::VIDEO)); 1459 video_.reset(new ChunkDemuxerStream(DemuxerStream::VIDEO));
1343 return video_.get(); 1460 return video_.get();
1344 break; 1461 break;
1462 case DemuxerStream::TEXT: {
1463 // TODO(matthewjheaney): we need to destroy this text stream
1464 return new ChunkDemuxerStream(DemuxerStream::TEXT);
1465 break;
1466 }
1345 case DemuxerStream::UNKNOWN: 1467 case DemuxerStream::UNKNOWN:
1346 case DemuxerStream::NUM_TYPES: 1468 case DemuxerStream::NUM_TYPES:
1347 NOTREACHED(); 1469 NOTREACHED();
1348 return NULL; 1470 return NULL;
1349 } 1471 }
1350 NOTREACHED(); 1472 NOTREACHED();
1351 return NULL; 1473 return NULL;
1352 } 1474 }
1353 1475
1354 bool ChunkDemuxer::OnTextBuffers( 1476 #if 0
acolwell GONE FROM CHROMIUM 2013/10/21 20:10:40 remove this block if it is no longer needed.
Matthew Heaney (Chromium) 2013/10/23 05:09:01 I restored the callback, so that the demuxer can n
1355 TextTrack* text_track, 1477 // TODO(matthewjheaney): must be called from source state
1356 const StreamParser::BufferQueue& buffers) { 1478 void ChunkDemuxer::OnNewTextTrack(ChunkDemuxerStream* text_stream,
1479 TextKind kind,
1480 const std::string& name,
1481 const std::string& language) {
1357 lock_.AssertAcquired(); 1482 lock_.AssertAcquired();
1358 DCHECK_NE(state_, SHUTDOWN); 1483 DCHECK_NE(state_, SHUTDOWN);
1359 1484 DCHECK(text_stream_set_.find(text_stream) != text_stream_set_.end());
1360 // TODO(matthewjheaney): IncreaseDurationIfNecessary 1485 host_->AddTextStream(text_stream, kind, name, language);
1361
1362 for (StreamParser::BufferQueue::const_iterator itr = buffers.begin();
1363 itr != buffers.end(); ++itr) {
1364 const StreamParserBuffer* const buffer = itr->get();
1365 const TimeDelta start = buffer->timestamp();
1366 const TimeDelta end = start + buffer->duration();
1367
1368 std::string id, settings, content;
1369
1370 WebMWebVTTParser::Parse(buffer->data(),
1371 buffer->data_size(),
1372 &id, &settings, &content);
1373
1374 text_track->addWebVTTCue(start, end, id, content, settings);
1375 }
1376
1377 return true;
1378 } 1486 }
1487 #endif
1379 1488
1380 bool ChunkDemuxer::IsValidId(const std::string& source_id) const { 1489 bool ChunkDemuxer::IsValidId(const std::string& source_id) const {
1381 lock_.AssertAcquired(); 1490 lock_.AssertAcquired();
1382 return source_state_map_.count(source_id) > 0u; 1491 return source_state_map_.count(source_id) > 0u;
1383 } 1492 }
1384 1493
1385 void ChunkDemuxer::UpdateDuration(TimeDelta new_duration) { 1494 void ChunkDemuxer::UpdateDuration(TimeDelta new_duration) {
1386 DCHECK(duration_ != new_duration); 1495 DCHECK(duration_ != new_duration);
1387 user_specified_duration_ = -1; 1496 user_specified_duration_ = -1;
1388 duration_ = new_duration; 1497 duration_ = new_duration;
(...skipping 28 matching lines...) Expand all
1417 Ranges<TimeDelta> ChunkDemuxer::GetBufferedRanges() const { 1526 Ranges<TimeDelta> ChunkDemuxer::GetBufferedRanges() const {
1418 if (audio_ && !video_) 1527 if (audio_ && !video_)
1419 return audio_->GetBufferedRanges(duration_); 1528 return audio_->GetBufferedRanges(duration_);
1420 else if (!audio_ && video_) 1529 else if (!audio_ && video_)
1421 return video_->GetBufferedRanges(duration_); 1530 return video_->GetBufferedRanges(duration_);
1422 return ComputeIntersection(); 1531 return ComputeIntersection();
1423 } 1532 }
1424 1533
1425 void ChunkDemuxer::StartReturningData() { 1534 void ChunkDemuxer::StartReturningData() {
1426 if (audio_) 1535 if (audio_)
1427 audio_->StartReturningData(); 1536 audio_->StartReturningData();
acolwell GONE FROM CHROMIUM 2013/10/21 20:10:40 Is there any reason the calls on audio_ and video_
1428 1537
1429 if (video_) 1538 if (video_)
1430 video_->StartReturningData(); 1539 video_->StartReturningData();
1540
1541 for (SourceStateMap::iterator itr = source_state_map_.begin();
1542 itr != source_state_map_.end(); ++itr) {
1543 itr->second->TextStartReturningData();
1544 }
1431 } 1545 }
1432 1546
1433 void ChunkDemuxer::AbortPendingReads() { 1547 void ChunkDemuxer::AbortPendingReads() {
1434 if (audio_) 1548 if (audio_)
1435 audio_->AbortReads(); 1549 audio_->AbortReads();
1436 1550
1437 if (video_) 1551 if (video_)
1438 video_->AbortReads(); 1552 video_->AbortReads();
1553
1554 for (SourceStateMap::iterator itr = source_state_map_.begin();
1555 itr != source_state_map_.end(); ++itr) {
1556 itr->second->TextAbortReads();
1557 }
1439 } 1558 }
1440 1559
1441 void ChunkDemuxer::SeekAllSources(TimeDelta seek_time) { 1560 void ChunkDemuxer::SeekAllSources(TimeDelta seek_time) {
1442 if (audio_) 1561 if (audio_)
1443 audio_->Seek(seek_time); 1562 audio_->Seek(seek_time);
1444 1563
1445 if (video_) 1564 if (video_)
1446 video_->Seek(seek_time); 1565 video_->Seek(seek_time);
1566
1567 for (SourceStateMap::iterator itr = source_state_map_.begin();
1568 itr != source_state_map_.end(); ++itr) {
1569 itr->second->TextSeek(seek_time);
1570 }
1447 } 1571 }
1448 1572
1449 void ChunkDemuxer::CompletePendingReadsIfPossible() { 1573 void ChunkDemuxer::CompletePendingReadsIfPossible() {
1450 if (audio_) 1574 if (audio_)
1451 audio_->CompletePendingReadIfPossible(); 1575 audio_->CompletePendingReadIfPossible();
1452 1576
1453 if (video_) 1577 if (video_)
1454 video_->CompletePendingReadIfPossible(); 1578 video_->CompletePendingReadIfPossible();
1579
1580 for (SourceStateMap::iterator itr = source_state_map_.begin();
1581 itr != source_state_map_.end(); ++itr) {
1582 itr->second->TextCompletePendingReadIfPossible();
1583 }
1455 } 1584 }
1456 1585
1457 } // namespace media 1586 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698