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 "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 typedef base::Callback<void( |
| 39 ChunkDemuxerStream*, const TextTrackConfig&)> NewTextTrackCB; |
| 40 |
38 SourceState(scoped_ptr<StreamParser> stream_parser, const LogCB& log_cb, | 41 SourceState(scoped_ptr<StreamParser> stream_parser, const LogCB& log_cb, |
39 const CreateDemuxerStreamCB& create_demuxer_stream_cb, | 42 const CreateDemuxerStreamCB& create_demuxer_stream_cb, |
40 const IncreaseDurationCB& increase_duration_cb); | 43 const IncreaseDurationCB& increase_duration_cb); |
41 | 44 |
| 45 ~SourceState(); |
| 46 |
42 void Init(const StreamParser::InitCB& init_cb, | 47 void Init(const StreamParser::InitCB& init_cb, |
43 bool allow_audio, | 48 bool allow_audio, |
44 bool allow_video, | 49 bool allow_video, |
45 const StreamParser::NewTextBuffersCB& text_cb, | |
46 const StreamParser::NeedKeyCB& need_key_cb, | 50 const StreamParser::NeedKeyCB& need_key_cb, |
47 const AddTextTrackCB& add_text_track_cb); | 51 const NewTextTrackCB& new_text_track_cb); |
48 | 52 |
49 // Appends new data to the StreamParser. | 53 // Appends new data to the StreamParser. |
50 // Returns true if the data was successfully appended. Returns false if an | 54 // Returns true if the data was successfully appended. Returns false if an |
51 // error occurred. | 55 // error occurred. |
52 bool Append(const uint8* data, size_t length); | 56 bool Append(const uint8* data, size_t length); |
53 | 57 |
54 // Aborts the current append sequence and resets the parser. | 58 // Aborts the current append sequence and resets the parser. |
55 void Abort(); | 59 void Abort(); |
56 | 60 |
57 // Sets |timestamp_offset_| if possible. | 61 // Sets |timestamp_offset_| if possible. |
58 // Returns if the offset was set. Returns false if the offset could not be | 62 // Returns if the offset was set. Returns false if the offset could not be |
59 // updated at this time. | 63 // updated at this time. |
60 bool SetTimestampOffset(TimeDelta timestamp_offset); | 64 bool SetTimestampOffset(TimeDelta timestamp_offset); |
61 | 65 |
62 TimeDelta timestamp_offset() const { return timestamp_offset_; } | 66 TimeDelta timestamp_offset() const { return timestamp_offset_; } |
63 | 67 |
64 void set_append_window_start(TimeDelta start) { | 68 void set_append_window_start(TimeDelta start) { |
65 append_window_start_ = start; | 69 append_window_start_ = start; |
66 } | 70 } |
67 void set_append_window_end(TimeDelta end) { append_window_end_ = end; } | 71 void set_append_window_end(TimeDelta end) { append_window_end_ = end; } |
68 | 72 |
| 73 void TextStartReturningData(); |
| 74 void TextAbortReads(); |
| 75 void TextSeek(TimeDelta seek_time); |
| 76 void TextCompletePendingReadIfPossible(); |
| 77 |
69 private: | 78 private: |
70 // Called by the |stream_parser_| when a new initialization segment is | 79 // Called by the |stream_parser_| when a new initialization segment is |
71 // encountered. | 80 // encountered. |
72 // Returns true on a successful call. Returns false if an error occured while | 81 // Returns true on a successful call. Returns false if an error occured while |
73 // processing decoder configurations. | 82 // processing decoder configurations. |
74 bool OnNewConfigs(bool allow_audio, bool allow_video, | 83 bool OnNewConfigs(bool allow_audio, bool allow_video, |
75 const AudioDecoderConfig& audio_config, | 84 const AudioDecoderConfig& audio_config, |
76 const VideoDecoderConfig& video_config); | 85 const VideoDecoderConfig& video_config, |
| 86 const StreamParser::TextTrackConfigMap& text_configs); |
77 | 87 |
78 // Called by the |stream_parser_| at the beginning of a new media segment. | 88 // Called by the |stream_parser_| at the beginning of a new media segment. |
79 void OnNewMediaSegment(); | 89 void OnNewMediaSegment(); |
80 | 90 |
81 // Called by the |stream_parser_| at the end of a media segment. | 91 // Called by the |stream_parser_| at the end of a media segment. |
82 void OnEndOfMediaSegment(); | 92 void OnEndOfMediaSegment(); |
83 | 93 |
84 // Called by the |stream_parser_| when new buffers have been parsed. It | 94 // Called by the |stream_parser_| when new buffers have been parsed. It |
85 // applies |timestamp_offset_| to all buffers in |audio_buffers| and | 95 // applies |timestamp_offset_| to all buffers in |audio_buffers| and |
86 // |video_buffers| and then calls Append() on |audio_| and/or | 96 // |video_buffers| and then calls Append() on |audio_| and/or |
87 // |video_| with the modified buffers. | 97 // |video_| with the modified buffers. |
88 // Returns true on a successful call. Returns false if an error occured while | 98 // Returns true on a successful call. Returns false if an error occured while |
89 // processing the buffers. | 99 // processing the buffers. |
90 bool OnNewBuffers(const StreamParser::BufferQueue& audio_buffers, | 100 bool OnNewBuffers(const StreamParser::BufferQueue& audio_buffers, |
91 const StreamParser::BufferQueue& video_buffers); | 101 const StreamParser::BufferQueue& video_buffers); |
92 | 102 |
93 // Called by the |stream_parser_| when new text buffers have been parsed. It | 103 // 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 | 104 // applies |timestamp_offset_| to all buffers in |buffers| and then appends |
95 // |new_buffers_cb| with the modified buffers. | 105 // the (modified) buffers to the demuxer stream associated with |
| 106 // the track having |text_track_number|. |
96 // Returns true on a successful call. Returns false if an error occured while | 107 // Returns true on a successful call. Returns false if an error occured while |
97 // processing the buffers. | 108 // processing the buffers. |
98 bool OnTextBuffers(const StreamParser::NewTextBuffersCB& new_buffers_cb, | 109 bool OnTextBuffers(int text_track_number, |
99 TextTrack* text_track, | |
100 const StreamParser::BufferQueue& buffers); | 110 const StreamParser::BufferQueue& buffers); |
101 | 111 |
102 // Helper function that adds |timestamp_offset_| to each buffer in |buffers|. | 112 // Helper function that adds |timestamp_offset_| to each buffer in |buffers|. |
103 void AdjustBufferTimestamps(const StreamParser::BufferQueue& buffers); | 113 void AdjustBufferTimestamps(const StreamParser::BufferQueue& buffers); |
104 | 114 |
105 // Filters out buffers that are outside of the append window | 115 // Filters out buffers that are outside of the append window |
106 // [|append_window_start_|, |append_window_end_|). | 116 // [|append_window_start_|, |append_window_end_|). |
107 // |needs_keyframe| is a pointer to the |xxx_need_keyframe_| flag | 117 // |needs_keyframe| is a pointer to the |xxx_need_keyframe_| flag |
108 // associated with the |buffers|. Its state is read an updated as | 118 // associated with the |buffers|. Its state is read an updated as |
109 // this method filters |buffers|. | 119 // this method filters |buffers|. |
110 // Buffers that are inside the append window are appended to the end | 120 // Buffers that are inside the append window are appended to the end |
111 // of |filtered_buffers|. | 121 // of |filtered_buffers|. |
112 void FilterWithAppendWindow(const StreamParser::BufferQueue& buffers, | 122 void FilterWithAppendWindow(const StreamParser::BufferQueue& buffers, |
113 bool* needs_keyframe, | 123 bool* needs_keyframe, |
114 StreamParser::BufferQueue* filtered_buffers); | 124 StreamParser::BufferQueue* filtered_buffers); |
115 | 125 |
116 CreateDemuxerStreamCB create_demuxer_stream_cb_; | 126 CreateDemuxerStreamCB create_demuxer_stream_cb_; |
117 IncreaseDurationCB increase_duration_cb_; | 127 IncreaseDurationCB increase_duration_cb_; |
| 128 NewTextTrackCB new_text_track_cb_; |
118 | 129 |
119 // The offset to apply to media segment timestamps. | 130 // The offset to apply to media segment timestamps. |
120 TimeDelta timestamp_offset_; | 131 TimeDelta timestamp_offset_; |
121 | 132 |
122 TimeDelta append_window_start_; | 133 TimeDelta append_window_start_; |
123 TimeDelta append_window_end_; | 134 TimeDelta append_window_end_; |
124 | 135 |
125 // Set to true if the next buffers appended within the append window | 136 // Set to true if the next buffers appended within the append window |
126 // represent the start of a new media segment. This flag being set | 137 // represent the start of a new media segment. This flag being set |
127 // triggers a call to |new_segment_cb_| when the new buffers are | 138 // triggers a call to |new_segment_cb_| when the new buffers are |
128 // appended. The flag is set on actual media segment boundaries and | 139 // appended. The flag is set on actual media segment boundaries and |
129 // when the "append window" filtering causes discontinuities in the | 140 // when the "append window" filtering causes discontinuities in the |
130 // appended data. | 141 // appended data. |
131 bool new_media_segment_; | 142 bool new_media_segment_; |
132 | 143 |
133 // Keeps track of whether |timestamp_offset_| can be modified. | 144 // Keeps track of whether |timestamp_offset_| can be modified. |
134 bool can_update_offset_; | 145 bool can_update_offset_; |
135 | 146 |
136 // The object used to parse appended data. | 147 // The object used to parse appended data. |
137 scoped_ptr<StreamParser> stream_parser_; | 148 scoped_ptr<StreamParser> stream_parser_; |
138 | 149 |
139 ChunkDemuxerStream* audio_; | 150 ChunkDemuxerStream* audio_; |
140 bool audio_needs_keyframe_; | 151 bool audio_needs_keyframe_; |
141 | 152 |
142 ChunkDemuxerStream* video_; | 153 ChunkDemuxerStream* video_; |
143 bool video_needs_keyframe_; | 154 bool video_needs_keyframe_; |
144 | 155 |
| 156 typedef std::map<int, ChunkDemuxerStream*> TextStreamMap; |
| 157 TextStreamMap text_stream_map_; |
| 158 |
145 LogCB log_cb_; | 159 LogCB log_cb_; |
146 | 160 |
147 DISALLOW_COPY_AND_ASSIGN(SourceState); | 161 DISALLOW_COPY_AND_ASSIGN(SourceState); |
148 }; | 162 }; |
149 | 163 |
150 class ChunkDemuxerStream : public DemuxerStream { | 164 class ChunkDemuxerStream : public DemuxerStream { |
151 public: | 165 public: |
152 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; | 166 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; |
153 | 167 |
154 explicit ChunkDemuxerStream(Type type); | 168 explicit ChunkDemuxerStream(Type type); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 200 |
187 // Signal to the stream that buffers handed in through subsequent calls to | 201 // Signal to the stream that buffers handed in through subsequent calls to |
188 // Append() belong to a media segment that starts at |start_timestamp|. | 202 // Append() belong to a media segment that starts at |start_timestamp|. |
189 void OnNewMediaSegment(TimeDelta start_timestamp); | 203 void OnNewMediaSegment(TimeDelta start_timestamp); |
190 | 204 |
191 // Called when midstream config updates occur. | 205 // Called when midstream config updates occur. |
192 // Returns true if the new config is accepted. | 206 // Returns true if the new config is accepted. |
193 // Returns false if the new config should trigger an error. | 207 // Returns false if the new config should trigger an error. |
194 bool UpdateAudioConfig(const AudioDecoderConfig& config, const LogCB& log_cb); | 208 bool UpdateAudioConfig(const AudioDecoderConfig& config, const LogCB& log_cb); |
195 bool UpdateVideoConfig(const VideoDecoderConfig& config, const LogCB& log_cb); | 209 bool UpdateVideoConfig(const VideoDecoderConfig& config, const LogCB& log_cb); |
| 210 void UpdateTextConfig(const TextTrackConfig& config, const LogCB& log_cb); |
196 | 211 |
197 void MarkEndOfStream(); | 212 void MarkEndOfStream(); |
198 void UnmarkEndOfStream(); | 213 void UnmarkEndOfStream(); |
199 | 214 |
200 // DemuxerStream methods. | 215 // DemuxerStream methods. |
201 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 216 virtual void Read(const ReadCB& read_cb) OVERRIDE; |
202 virtual Type type() OVERRIDE; | 217 virtual Type type() OVERRIDE; |
203 virtual void EnableBitstreamConverter() OVERRIDE; | 218 virtual void EnableBitstreamConverter() OVERRIDE; |
204 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE; | 219 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE; |
205 virtual VideoDecoderConfig video_decoder_config() OVERRIDE; | 220 virtual VideoDecoderConfig video_decoder_config() OVERRIDE; |
206 | 221 |
| 222 // Returns the text track configuration. It is an error to call this method |
| 223 // if type() != TEXT. |
| 224 TextTrackConfig text_track_config(); |
| 225 |
207 void set_memory_limit_for_testing(int memory_limit) { | 226 void set_memory_limit_for_testing(int memory_limit) { |
208 stream_->set_memory_limit_for_testing(memory_limit); | 227 stream_->set_memory_limit_for_testing(memory_limit); |
209 } | 228 } |
210 | 229 |
211 private: | 230 private: |
212 enum State { | 231 enum State { |
213 UNINITIALIZED, | 232 UNINITIALIZED, |
214 RETURNING_DATA_FOR_READS, | 233 RETURNING_DATA_FOR_READS, |
215 RETURNING_ABORT_FOR_READS, | 234 RETURNING_ABORT_FOR_READS, |
216 SHUTDOWN, | 235 SHUTDOWN, |
217 }; | 236 }; |
218 | 237 |
219 // Assigns |state_| to |state| | 238 // Assigns |state_| to |state| |
220 void ChangeState_Locked(State state); | 239 void ChangeState_Locked(State state); |
221 | 240 |
222 void CompletePendingReadIfPossible_Locked(); | 241 void CompletePendingReadIfPossible_Locked(); |
223 | 242 |
224 // Gets the value to pass to the next Read() callback. Returns true if | 243 // 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 | 244 // |status| and |buffer| should be passed to the callback. False indicates |
226 // that |status| and |buffer| were not set and more data is needed. | 245 // that |status| and |buffer| were not set and more data is needed. |
227 bool GetNextBuffer_Locked(DemuxerStream::Status* status, | 246 bool GetNextBuffer_Locked(DemuxerStream::Status* status, |
228 scoped_refptr<StreamParserBuffer>* buffer); | 247 scoped_refptr<StreamParserBuffer>* buffer); |
229 | 248 |
230 // Specifies the type of the stream (must be AUDIO or VIDEO for now). | 249 // Specifies the type of the stream. |
231 Type type_; | 250 Type type_; |
232 | 251 |
233 scoped_ptr<SourceBufferStream> stream_; | 252 scoped_ptr<SourceBufferStream> stream_; |
234 | 253 |
235 mutable base::Lock lock_; | 254 mutable base::Lock lock_; |
236 State state_; | 255 State state_; |
237 ReadCB read_cb_; | 256 ReadCB read_cb_; |
238 | 257 |
239 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream); | 258 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream); |
240 }; | 259 }; |
(...skipping 10 matching lines...) Expand all Loading... |
251 stream_parser_(stream_parser.release()), | 270 stream_parser_(stream_parser.release()), |
252 audio_(NULL), | 271 audio_(NULL), |
253 audio_needs_keyframe_(true), | 272 audio_needs_keyframe_(true), |
254 video_(NULL), | 273 video_(NULL), |
255 video_needs_keyframe_(true), | 274 video_needs_keyframe_(true), |
256 log_cb_(log_cb) { | 275 log_cb_(log_cb) { |
257 DCHECK(!create_demuxer_stream_cb_.is_null()); | 276 DCHECK(!create_demuxer_stream_cb_.is_null()); |
258 DCHECK(!increase_duration_cb_.is_null()); | 277 DCHECK(!increase_duration_cb_.is_null()); |
259 } | 278 } |
260 | 279 |
| 280 SourceState::~SourceState() { |
| 281 for (TextStreamMap::iterator itr = text_stream_map_.begin(); |
| 282 itr != text_stream_map_.end(); ++itr) { |
| 283 itr->second->Shutdown(); |
| 284 delete itr->second; |
| 285 } |
| 286 } |
| 287 |
261 void SourceState::Init(const StreamParser::InitCB& init_cb, | 288 void SourceState::Init(const StreamParser::InitCB& init_cb, |
262 bool allow_audio, | 289 bool allow_audio, |
263 bool allow_video, | 290 bool allow_video, |
264 const StreamParser::NewTextBuffersCB& text_cb, | |
265 const StreamParser::NeedKeyCB& need_key_cb, | 291 const StreamParser::NeedKeyCB& need_key_cb, |
266 const AddTextTrackCB& add_text_track_cb) { | 292 const NewTextTrackCB& new_text_track_cb) { |
267 StreamParser::NewBuffersCB audio_cb; | 293 new_text_track_cb_ = new_text_track_cb; |
| 294 |
| 295 StreamParser::NewTextBuffersCB new_text_buffers_cb; |
| 296 |
| 297 if (!new_text_track_cb_.is_null()) { |
| 298 new_text_buffers_cb = base::Bind(&SourceState::OnTextBuffers, |
| 299 base::Unretained(this)); |
| 300 } |
268 | 301 |
269 stream_parser_->Init(init_cb, | 302 stream_parser_->Init(init_cb, |
270 base::Bind(&SourceState::OnNewConfigs, | 303 base::Bind(&SourceState::OnNewConfigs, |
271 base::Unretained(this), | 304 base::Unretained(this), |
272 allow_audio, | 305 allow_audio, |
273 allow_video), | 306 allow_video), |
274 base::Bind(&SourceState::OnNewBuffers, | 307 base::Bind(&SourceState::OnNewBuffers, |
275 base::Unretained(this)), | 308 base::Unretained(this)), |
276 base::Bind(&SourceState::OnTextBuffers, | 309 new_text_buffers_cb, |
277 base::Unretained(this), text_cb), | |
278 need_key_cb, | 310 need_key_cb, |
279 add_text_track_cb, | |
280 base::Bind(&SourceState::OnNewMediaSegment, | 311 base::Bind(&SourceState::OnNewMediaSegment, |
281 base::Unretained(this)), | 312 base::Unretained(this)), |
282 base::Bind(&SourceState::OnEndOfMediaSegment, | 313 base::Bind(&SourceState::OnEndOfMediaSegment, |
283 base::Unretained(this)), | 314 base::Unretained(this)), |
284 log_cb_); | 315 log_cb_); |
285 } | 316 } |
286 | 317 |
287 bool SourceState::SetTimestampOffset(TimeDelta timestamp_offset) { | 318 bool SourceState::SetTimestampOffset(TimeDelta timestamp_offset) { |
288 if (!can_update_offset_) | 319 if (!can_update_offset_) |
289 return false; | 320 return false; |
290 | 321 |
291 timestamp_offset_ = timestamp_offset; | 322 timestamp_offset_ = timestamp_offset; |
292 return true; | 323 return true; |
293 } | 324 } |
294 | 325 |
295 bool SourceState::Append(const uint8* data, size_t length) { | 326 bool SourceState::Append(const uint8* data, size_t length) { |
296 return stream_parser_->Parse(data, length); | 327 return stream_parser_->Parse(data, length); |
297 } | 328 } |
298 | 329 |
299 void SourceState::Abort() { | 330 void SourceState::Abort() { |
300 stream_parser_->Flush(); | 331 stream_parser_->Flush(); |
301 audio_needs_keyframe_ = true; | 332 audio_needs_keyframe_ = true; |
302 video_needs_keyframe_ = true; | 333 video_needs_keyframe_ = true; |
303 can_update_offset_ = true; | 334 can_update_offset_ = true; |
304 } | 335 } |
305 | 336 |
| 337 |
| 338 void SourceState::TextStartReturningData() { |
| 339 for (TextStreamMap::iterator itr = text_stream_map_.begin(); |
| 340 itr != text_stream_map_.end(); ++itr) { |
| 341 itr->second->StartReturningData(); |
| 342 } |
| 343 } |
| 344 |
| 345 void SourceState::TextAbortReads() { |
| 346 for (TextStreamMap::iterator itr = text_stream_map_.begin(); |
| 347 itr != text_stream_map_.end(); ++itr) { |
| 348 itr->second->AbortReads(); |
| 349 } |
| 350 } |
| 351 |
| 352 void SourceState::TextSeek(TimeDelta seek_time) { |
| 353 for (TextStreamMap::iterator itr = text_stream_map_.begin(); |
| 354 itr != text_stream_map_.end(); ++itr) { |
| 355 itr->second->Seek(seek_time); |
| 356 } |
| 357 } |
| 358 |
| 359 void SourceState::TextCompletePendingReadIfPossible() { |
| 360 for (TextStreamMap::iterator itr = text_stream_map_.begin(); |
| 361 itr != text_stream_map_.end(); ++itr) { |
| 362 itr->second->CompletePendingReadIfPossible(); |
| 363 } |
| 364 } |
| 365 |
306 void SourceState::AdjustBufferTimestamps( | 366 void SourceState::AdjustBufferTimestamps( |
307 const StreamParser::BufferQueue& buffers) { | 367 const StreamParser::BufferQueue& buffers) { |
308 if (timestamp_offset_ == TimeDelta()) | 368 if (timestamp_offset_ == TimeDelta()) |
309 return; | 369 return; |
310 | 370 |
311 for (StreamParser::BufferQueue::const_iterator itr = buffers.begin(); | 371 for (StreamParser::BufferQueue::const_iterator itr = buffers.begin(); |
312 itr != buffers.end(); ++itr) { | 372 itr != buffers.end(); ++itr) { |
313 (*itr)->SetDecodeTimestamp( | 373 (*itr)->SetDecodeTimestamp( |
314 (*itr)->GetDecodeTimestamp() + timestamp_offset_); | 374 (*itr)->GetDecodeTimestamp() + timestamp_offset_); |
315 (*itr)->set_timestamp((*itr)->timestamp() + timestamp_offset_); | 375 (*itr)->set_timestamp((*itr)->timestamp() + timestamp_offset_); |
316 } | 376 } |
317 } | 377 } |
318 | 378 |
319 bool SourceState::OnNewConfigs(bool allow_audio, bool allow_video, | 379 bool SourceState::OnNewConfigs( |
320 const AudioDecoderConfig& audio_config, | 380 bool allow_audio, bool allow_video, |
321 const VideoDecoderConfig& video_config) { | 381 const AudioDecoderConfig& audio_config, |
| 382 const VideoDecoderConfig& video_config, |
| 383 const StreamParser::TextTrackConfigMap& text_configs) { |
322 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video | 384 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video |
323 << ", " << audio_config.IsValidConfig() | 385 << ", " << audio_config.IsValidConfig() |
324 << ", " << video_config.IsValidConfig() << ")"; | 386 << ", " << video_config.IsValidConfig() << ")"; |
325 | 387 |
326 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { | 388 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { |
327 DVLOG(1) << "OnNewConfigs() : Audio & video config are not valid!"; | 389 DVLOG(1) << "OnNewConfigs() : Audio & video config are not valid!"; |
328 return false; | 390 return false; |
329 } | 391 } |
330 | 392 |
331 // Signal an error if we get configuration info for stream types that weren't | 393 // 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 Loading... |
370 | 432 |
371 if (!video_) { | 433 if (!video_) { |
372 DVLOG(1) << "Failed to create a video stream."; | 434 DVLOG(1) << "Failed to create a video stream."; |
373 return false; | 435 return false; |
374 } | 436 } |
375 } | 437 } |
376 | 438 |
377 success &= video_->UpdateVideoConfig(video_config, log_cb_); | 439 success &= video_->UpdateVideoConfig(video_config, log_cb_); |
378 } | 440 } |
379 | 441 |
| 442 typedef StreamParser::TextTrackConfigMap::const_iterator TextConfigItr; |
| 443 if (text_stream_map_.empty()) { |
| 444 for (TextConfigItr itr = text_configs.begin(); |
| 445 itr != text_configs.end(); ++itr) { |
| 446 ChunkDemuxerStream* const text_stream = |
| 447 create_demuxer_stream_cb_.Run(DemuxerStream::TEXT); |
| 448 text_stream->UpdateTextConfig(itr->second, log_cb_); |
| 449 text_stream_map_[itr->first] = text_stream; |
| 450 new_text_track_cb_.Run(text_stream, itr->second); |
| 451 } |
| 452 } else { |
| 453 const size_t text_count = text_stream_map_.size(); |
| 454 if (text_configs.size() != text_count) { |
| 455 success &= false; |
| 456 MEDIA_LOG(log_cb_) << "The number of text track configs changed."; |
| 457 } else if (text_count == 1) { |
| 458 TextConfigItr config_itr = text_configs.begin(); |
| 459 const TextTrackConfig& new_config = config_itr->second; |
| 460 TextStreamMap::iterator stream_itr = text_stream_map_.begin(); |
| 461 ChunkDemuxerStream* text_stream = stream_itr->second; |
| 462 TextTrackConfig old_config = text_stream->text_track_config(); |
| 463 if (!new_config.Matches(old_config)) { |
| 464 success &= false; |
| 465 MEDIA_LOG(log_cb_) << "New text track config does not match old one."; |
| 466 } else { |
| 467 text_stream_map_.clear(); |
| 468 text_stream_map_[config_itr->first] = text_stream; |
| 469 } |
| 470 } else { |
| 471 for (TextConfigItr config_itr = text_configs.begin(); |
| 472 config_itr != text_configs.end(); ++config_itr) { |
| 473 TextStreamMap::iterator stream_itr = |
| 474 text_stream_map_.find(config_itr->first); |
| 475 if (stream_itr == text_stream_map_.end()) { |
| 476 success &= false; |
| 477 MEDIA_LOG(log_cb_) << "Unexpected text track configuration " |
| 478 "for track ID " |
| 479 << config_itr->first; |
| 480 break; |
| 481 } |
| 482 |
| 483 const TextTrackConfig& new_config = config_itr->second; |
| 484 ChunkDemuxerStream* stream = stream_itr->second; |
| 485 TextTrackConfig old_config = stream->text_track_config(); |
| 486 if (!new_config.Matches(old_config)) { |
| 487 success &= false; |
| 488 MEDIA_LOG(log_cb_) << "New text track config for track ID " |
| 489 << config_itr->first |
| 490 << " does not match old one."; |
| 491 break; |
| 492 } |
| 493 } |
| 494 } |
| 495 } |
| 496 |
380 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); | 497 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); |
381 return success; | 498 return success; |
382 } | 499 } |
383 | 500 |
384 void SourceState::OnNewMediaSegment() { | 501 void SourceState::OnNewMediaSegment() { |
385 DVLOG(2) << "OnNewMediaSegment()"; | 502 DVLOG(2) << "OnNewMediaSegment()"; |
386 can_update_offset_ = false; | 503 can_update_offset_ = false; |
387 new_media_segment_ = true; | 504 new_media_segment_ = true; |
388 } | 505 } |
389 | 506 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 segment_timestamp = filtered_video.front()->GetDecodeTimestamp(); | 542 segment_timestamp = filtered_video.front()->GetDecodeTimestamp(); |
426 } | 543 } |
427 | 544 |
428 new_media_segment_ = false; | 545 new_media_segment_ = false; |
429 | 546 |
430 if (audio_) | 547 if (audio_) |
431 audio_->OnNewMediaSegment(segment_timestamp); | 548 audio_->OnNewMediaSegment(segment_timestamp); |
432 | 549 |
433 if (video_) | 550 if (video_) |
434 video_->OnNewMediaSegment(segment_timestamp); | 551 video_->OnNewMediaSegment(segment_timestamp); |
| 552 |
| 553 for (TextStreamMap::iterator itr = text_stream_map_.begin(); |
| 554 itr != text_stream_map_.end(); ++itr) { |
| 555 itr->second->OnNewMediaSegment(segment_timestamp); |
| 556 } |
435 } | 557 } |
436 | 558 |
437 if (!filtered_audio.empty()) { | 559 if (!filtered_audio.empty()) { |
438 if (!audio_ || !audio_->Append(filtered_audio)) | 560 if (!audio_ || !audio_->Append(filtered_audio)) |
439 return false; | 561 return false; |
440 increase_duration_cb_.Run(filtered_audio.back()->timestamp(), audio_); | 562 increase_duration_cb_.Run(filtered_audio.back()->timestamp(), audio_); |
441 } | 563 } |
442 | 564 |
443 if (!filtered_video.empty()) { | 565 if (!filtered_video.empty()) { |
444 if (!video_ || !video_->Append(filtered_video)) | 566 if (!video_ || !video_->Append(filtered_video)) |
445 return false; | 567 return false; |
446 increase_duration_cb_.Run(filtered_video.back()->timestamp(), video_); | 568 increase_duration_cb_.Run(filtered_video.back()->timestamp(), video_); |
447 } | 569 } |
448 | 570 |
449 return true; | 571 return true; |
450 } | 572 } |
451 | 573 |
452 bool SourceState::OnTextBuffers( | 574 bool SourceState::OnTextBuffers( |
453 const StreamParser::NewTextBuffersCB& new_buffers_cb, | 575 int text_track_number, |
454 TextTrack* text_track, | |
455 const StreamParser::BufferQueue& buffers) { | 576 const StreamParser::BufferQueue& buffers) { |
456 if (new_buffers_cb.is_null()) | 577 DCHECK(!buffers.empty()); |
| 578 |
| 579 TextStreamMap::iterator itr = text_stream_map_.find(text_track_number); |
| 580 if (itr == text_stream_map_.end()) |
457 return false; | 581 return false; |
458 | 582 |
459 AdjustBufferTimestamps(buffers); | 583 AdjustBufferTimestamps(buffers); |
460 | 584 |
461 return new_buffers_cb.Run(text_track, buffers); | 585 return itr->second->Append(buffers); |
462 } | 586 } |
463 | 587 |
464 void SourceState::FilterWithAppendWindow( | 588 void SourceState::FilterWithAppendWindow( |
465 const StreamParser::BufferQueue& buffers, bool* needs_keyframe, | 589 const StreamParser::BufferQueue& buffers, bool* needs_keyframe, |
466 StreamParser::BufferQueue* filtered_buffers) { | 590 StreamParser::BufferQueue* filtered_buffers) { |
467 DCHECK(needs_keyframe); | 591 DCHECK(needs_keyframe); |
468 DCHECK(filtered_buffers); | 592 DCHECK(filtered_buffers); |
469 | 593 |
470 // This loop implements steps 1.9, 1.10, & 1.11 of the "Coded frame | 594 // This loop implements steps 1.9, 1.10, & 1.11 of the "Coded frame |
471 // processing loop" in the Media Source Extensions spec. | 595 // processing loop" in the Media Source Extensions spec. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 | 766 |
643 if (!stream_) { | 767 if (!stream_) { |
644 DCHECK_EQ(state_, UNINITIALIZED); | 768 DCHECK_EQ(state_, UNINITIALIZED); |
645 stream_.reset(new SourceBufferStream(config, log_cb)); | 769 stream_.reset(new SourceBufferStream(config, log_cb)); |
646 return true; | 770 return true; |
647 } | 771 } |
648 | 772 |
649 return stream_->UpdateVideoConfig(config); | 773 return stream_->UpdateVideoConfig(config); |
650 } | 774 } |
651 | 775 |
| 776 void ChunkDemuxerStream::UpdateTextConfig(const TextTrackConfig& config, |
| 777 const LogCB& log_cb) { |
| 778 DCHECK_EQ(type_, TEXT); |
| 779 base::AutoLock auto_lock(lock_); |
| 780 DCHECK(!stream_); |
| 781 DCHECK_EQ(state_, UNINITIALIZED); |
| 782 stream_.reset(new SourceBufferStream(config, log_cb)); |
| 783 } |
| 784 |
652 void ChunkDemuxerStream::MarkEndOfStream() { | 785 void ChunkDemuxerStream::MarkEndOfStream() { |
653 base::AutoLock auto_lock(lock_); | 786 base::AutoLock auto_lock(lock_); |
654 stream_->MarkEndOfStream(); | 787 stream_->MarkEndOfStream(); |
655 } | 788 } |
656 | 789 |
657 void ChunkDemuxerStream::UnmarkEndOfStream() { | 790 void ChunkDemuxerStream::UnmarkEndOfStream() { |
658 base::AutoLock auto_lock(lock_); | 791 base::AutoLock auto_lock(lock_); |
659 stream_->UnmarkEndOfStream(); | 792 stream_->UnmarkEndOfStream(); |
660 } | 793 } |
661 | 794 |
(...skipping 16 matching lines...) Expand all Loading... |
678 base::AutoLock auto_lock(lock_); | 811 base::AutoLock auto_lock(lock_); |
679 return stream_->GetCurrentAudioDecoderConfig(); | 812 return stream_->GetCurrentAudioDecoderConfig(); |
680 } | 813 } |
681 | 814 |
682 VideoDecoderConfig ChunkDemuxerStream::video_decoder_config() { | 815 VideoDecoderConfig ChunkDemuxerStream::video_decoder_config() { |
683 CHECK_EQ(type_, VIDEO); | 816 CHECK_EQ(type_, VIDEO); |
684 base::AutoLock auto_lock(lock_); | 817 base::AutoLock auto_lock(lock_); |
685 return stream_->GetCurrentVideoDecoderConfig(); | 818 return stream_->GetCurrentVideoDecoderConfig(); |
686 } | 819 } |
687 | 820 |
| 821 TextTrackConfig ChunkDemuxerStream::text_track_config() { |
| 822 CHECK_EQ(type_, TEXT); |
| 823 base::AutoLock auto_lock(lock_); |
| 824 return stream_->GetCurrentTextTrackConfig(); |
| 825 } |
| 826 |
688 void ChunkDemuxerStream::ChangeState_Locked(State state) { | 827 void ChunkDemuxerStream::ChangeState_Locked(State state) { |
689 lock_.AssertAcquired(); | 828 lock_.AssertAcquired(); |
690 DVLOG(1) << "ChunkDemuxerStream::ChangeState_Locked() : " | 829 DVLOG(1) << "ChunkDemuxerStream::ChangeState_Locked() : " |
691 << "type " << type_ | 830 << "type " << type_ |
692 << " - " << state_ << " -> " << state; | 831 << " - " << state_ << " -> " << state; |
693 state_ = state; | 832 state_ = state; |
694 } | 833 } |
695 | 834 |
696 ChunkDemuxerStream::~ChunkDemuxerStream() {} | 835 ChunkDemuxerStream::~ChunkDemuxerStream() {} |
697 | 836 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 status = DemuxerStream::kOk; | 876 status = DemuxerStream::kOk; |
738 buffer = StreamParserBuffer::CreateEOSBuffer(); | 877 buffer = StreamParserBuffer::CreateEOSBuffer(); |
739 break; | 878 break; |
740 } | 879 } |
741 | 880 |
742 base::ResetAndReturn(&read_cb_).Run(status, buffer); | 881 base::ResetAndReturn(&read_cb_).Run(status, buffer); |
743 } | 882 } |
744 | 883 |
745 ChunkDemuxer::ChunkDemuxer(const base::Closure& open_cb, | 884 ChunkDemuxer::ChunkDemuxer(const base::Closure& open_cb, |
746 const NeedKeyCB& need_key_cb, | 885 const NeedKeyCB& need_key_cb, |
747 const AddTextTrackCB& add_text_track_cb, | |
748 const LogCB& log_cb) | 886 const LogCB& log_cb) |
749 : state_(WAITING_FOR_INIT), | 887 : state_(WAITING_FOR_INIT), |
750 cancel_next_seek_(false), | 888 cancel_next_seek_(false), |
751 host_(NULL), | 889 host_(NULL), |
752 open_cb_(open_cb), | 890 open_cb_(open_cb), |
753 need_key_cb_(need_key_cb), | 891 need_key_cb_(need_key_cb), |
754 add_text_track_cb_(add_text_track_cb), | 892 enable_text_(false), |
755 log_cb_(log_cb), | 893 log_cb_(log_cb), |
756 duration_(kNoTimestamp()), | 894 duration_(kNoTimestamp()), |
757 user_specified_duration_(-1) { | 895 user_specified_duration_(-1) { |
758 DCHECK(!open_cb_.is_null()); | 896 DCHECK(!open_cb_.is_null()); |
759 DCHECK(!need_key_cb_.is_null()); | 897 DCHECK(!need_key_cb_.is_null()); |
760 } | 898 } |
761 | 899 |
762 void ChunkDemuxer::Initialize(DemuxerHost* host, const PipelineStatusCB& cb) { | 900 void ChunkDemuxer::Initialize( |
| 901 DemuxerHost* host, |
| 902 const PipelineStatusCB& cb, |
| 903 bool enable_text_tracks) { |
763 DVLOG(1) << "Init()"; | 904 DVLOG(1) << "Init()"; |
764 | 905 |
765 base::AutoLock auto_lock(lock_); | 906 base::AutoLock auto_lock(lock_); |
766 | 907 |
767 init_cb_ = BindToCurrentLoop(cb); | 908 init_cb_ = BindToCurrentLoop(cb); |
768 if (state_ == SHUTDOWN) { | 909 if (state_ == SHUTDOWN) { |
769 base::ResetAndReturn(&init_cb_).Run(DEMUXER_ERROR_COULD_NOT_OPEN); | 910 base::ResetAndReturn(&init_cb_).Run(DEMUXER_ERROR_COULD_NOT_OPEN); |
770 return; | 911 return; |
771 } | 912 } |
772 DCHECK_EQ(state_, WAITING_FOR_INIT); | 913 DCHECK_EQ(state_, WAITING_FOR_INIT); |
773 host_ = host; | 914 host_ = host; |
| 915 enable_text_ = enable_text_tracks; |
774 | 916 |
775 ChangeState_Locked(INITIALIZING); | 917 ChangeState_Locked(INITIALIZING); |
776 | 918 |
777 base::ResetAndReturn(&open_cb_).Run(); | 919 base::ResetAndReturn(&open_cb_).Run(); |
778 } | 920 } |
779 | 921 |
780 void ChunkDemuxer::Stop(const base::Closure& callback) { | 922 void ChunkDemuxer::Stop(const base::Closure& callback) { |
781 DVLOG(1) << "Stop()"; | 923 DVLOG(1) << "Stop()"; |
782 Shutdown(); | 924 Shutdown(); |
783 callback.Run(); | 925 callback.Run(); |
(...skipping 30 matching lines...) Expand all Loading... |
814 } | 956 } |
815 | 957 |
816 void ChunkDemuxer::OnAudioRendererDisabled() { | 958 void ChunkDemuxer::OnAudioRendererDisabled() { |
817 base::AutoLock auto_lock(lock_); | 959 base::AutoLock auto_lock(lock_); |
818 audio_->Shutdown(); | 960 audio_->Shutdown(); |
819 disabled_audio_ = audio_.Pass(); | 961 disabled_audio_ = audio_.Pass(); |
820 } | 962 } |
821 | 963 |
822 // Demuxer implementation. | 964 // Demuxer implementation. |
823 DemuxerStream* ChunkDemuxer::GetStream(DemuxerStream::Type type) { | 965 DemuxerStream* ChunkDemuxer::GetStream(DemuxerStream::Type type) { |
| 966 DCHECK_NE(type, DemuxerStream::TEXT); |
824 base::AutoLock auto_lock(lock_); | 967 base::AutoLock auto_lock(lock_); |
825 if (type == DemuxerStream::VIDEO) | 968 if (type == DemuxerStream::VIDEO) |
826 return video_.get(); | 969 return video_.get(); |
827 | 970 |
828 if (type == DemuxerStream::AUDIO) | 971 if (type == DemuxerStream::AUDIO) |
829 return audio_.get(); | 972 return audio_.get(); |
830 | 973 |
831 return NULL; | 974 return NULL; |
832 } | 975 } |
833 | 976 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 if (has_video) | 1042 if (has_video) |
900 source_id_video_ = id; | 1043 source_id_video_ = id; |
901 | 1044 |
902 scoped_ptr<SourceState> source_state( | 1045 scoped_ptr<SourceState> source_state( |
903 new SourceState(stream_parser.Pass(), log_cb_, | 1046 new SourceState(stream_parser.Pass(), log_cb_, |
904 base::Bind(&ChunkDemuxer::CreateDemuxerStream, | 1047 base::Bind(&ChunkDemuxer::CreateDemuxerStream, |
905 base::Unretained(this)), | 1048 base::Unretained(this)), |
906 base::Bind(&ChunkDemuxer::IncreaseDurationIfNecessary, | 1049 base::Bind(&ChunkDemuxer::IncreaseDurationIfNecessary, |
907 base::Unretained(this)))); | 1050 base::Unretained(this)))); |
908 | 1051 |
| 1052 SourceState::NewTextTrackCB new_text_track_cb; |
| 1053 |
| 1054 if (enable_text_) { |
| 1055 new_text_track_cb = base::Bind(&ChunkDemuxer::OnNewTextTrack, |
| 1056 base::Unretained(this)); |
| 1057 } |
| 1058 |
909 source_state->Init( | 1059 source_state->Init( |
910 base::Bind(&ChunkDemuxer::OnSourceInitDone, base::Unretained(this)), | 1060 base::Bind(&ChunkDemuxer::OnSourceInitDone, base::Unretained(this)), |
911 has_audio, | 1061 has_audio, |
912 has_video, | 1062 has_video, |
913 base::Bind(&ChunkDemuxer::OnTextBuffers, base::Unretained(this)), | |
914 need_key_cb_, | 1063 need_key_cb_, |
915 add_text_track_cb_); | 1064 new_text_track_cb); |
916 | 1065 |
917 source_state_map_[id] = source_state.release(); | 1066 source_state_map_[id] = source_state.release(); |
918 return kOk; | 1067 return kOk; |
919 } | 1068 } |
920 | 1069 |
921 void ChunkDemuxer::RemoveId(const std::string& id) { | 1070 void ChunkDemuxer::RemoveId(const std::string& id) { |
922 base::AutoLock auto_lock(lock_); | 1071 base::AutoLock auto_lock(lock_); |
923 CHECK(IsValidId(id)); | 1072 CHECK(IsValidId(id)); |
924 | 1073 |
925 delete source_state_map_[id]; | 1074 delete source_state_map_[id]; |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 return NULL; | 1484 return NULL; |
1336 audio_.reset(new ChunkDemuxerStream(DemuxerStream::AUDIO)); | 1485 audio_.reset(new ChunkDemuxerStream(DemuxerStream::AUDIO)); |
1337 return audio_.get(); | 1486 return audio_.get(); |
1338 break; | 1487 break; |
1339 case DemuxerStream::VIDEO: | 1488 case DemuxerStream::VIDEO: |
1340 if (video_) | 1489 if (video_) |
1341 return NULL; | 1490 return NULL; |
1342 video_.reset(new ChunkDemuxerStream(DemuxerStream::VIDEO)); | 1491 video_.reset(new ChunkDemuxerStream(DemuxerStream::VIDEO)); |
1343 return video_.get(); | 1492 return video_.get(); |
1344 break; | 1493 break; |
| 1494 case DemuxerStream::TEXT: { |
| 1495 return new ChunkDemuxerStream(DemuxerStream::TEXT); |
| 1496 break; |
| 1497 } |
1345 case DemuxerStream::UNKNOWN: | 1498 case DemuxerStream::UNKNOWN: |
1346 case DemuxerStream::NUM_TYPES: | 1499 case DemuxerStream::NUM_TYPES: |
1347 NOTREACHED(); | 1500 NOTREACHED(); |
1348 return NULL; | 1501 return NULL; |
1349 } | 1502 } |
1350 NOTREACHED(); | 1503 NOTREACHED(); |
1351 return NULL; | 1504 return NULL; |
1352 } | 1505 } |
1353 | 1506 |
1354 bool ChunkDemuxer::OnTextBuffers( | 1507 void ChunkDemuxer::OnNewTextTrack(ChunkDemuxerStream* text_stream, |
1355 TextTrack* text_track, | 1508 const TextTrackConfig& config) { |
1356 const StreamParser::BufferQueue& buffers) { | |
1357 lock_.AssertAcquired(); | 1509 lock_.AssertAcquired(); |
1358 DCHECK_NE(state_, SHUTDOWN); | 1510 DCHECK_NE(state_, SHUTDOWN); |
1359 | 1511 host_->AddTextStream(text_stream, config); |
1360 // TODO(matthewjheaney): IncreaseDurationIfNecessary | |
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 } | 1512 } |
1379 | 1513 |
1380 bool ChunkDemuxer::IsValidId(const std::string& source_id) const { | 1514 bool ChunkDemuxer::IsValidId(const std::string& source_id) const { |
1381 lock_.AssertAcquired(); | 1515 lock_.AssertAcquired(); |
1382 return source_state_map_.count(source_id) > 0u; | 1516 return source_state_map_.count(source_id) > 0u; |
1383 } | 1517 } |
1384 | 1518 |
1385 void ChunkDemuxer::UpdateDuration(TimeDelta new_duration) { | 1519 void ChunkDemuxer::UpdateDuration(TimeDelta new_duration) { |
1386 DCHECK(duration_ != new_duration); | 1520 DCHECK(duration_ != new_duration); |
1387 user_specified_duration_ = -1; | 1521 user_specified_duration_ = -1; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1428 return video_->GetBufferedRanges(duration_); | 1562 return video_->GetBufferedRanges(duration_); |
1429 return ComputeIntersection(); | 1563 return ComputeIntersection(); |
1430 } | 1564 } |
1431 | 1565 |
1432 void ChunkDemuxer::StartReturningData() { | 1566 void ChunkDemuxer::StartReturningData() { |
1433 if (audio_) | 1567 if (audio_) |
1434 audio_->StartReturningData(); | 1568 audio_->StartReturningData(); |
1435 | 1569 |
1436 if (video_) | 1570 if (video_) |
1437 video_->StartReturningData(); | 1571 video_->StartReturningData(); |
| 1572 |
| 1573 for (SourceStateMap::iterator itr = source_state_map_.begin(); |
| 1574 itr != source_state_map_.end(); ++itr) { |
| 1575 itr->second->TextStartReturningData(); |
| 1576 } |
1438 } | 1577 } |
1439 | 1578 |
1440 void ChunkDemuxer::AbortPendingReads() { | 1579 void ChunkDemuxer::AbortPendingReads() { |
1441 if (audio_) | 1580 if (audio_) |
1442 audio_->AbortReads(); | 1581 audio_->AbortReads(); |
1443 | 1582 |
1444 if (video_) | 1583 if (video_) |
1445 video_->AbortReads(); | 1584 video_->AbortReads(); |
| 1585 |
| 1586 for (SourceStateMap::iterator itr = source_state_map_.begin(); |
| 1587 itr != source_state_map_.end(); ++itr) { |
| 1588 itr->second->TextAbortReads(); |
| 1589 } |
1446 } | 1590 } |
1447 | 1591 |
1448 void ChunkDemuxer::SeekAllSources(TimeDelta seek_time) { | 1592 void ChunkDemuxer::SeekAllSources(TimeDelta seek_time) { |
1449 if (audio_) | 1593 if (audio_) |
1450 audio_->Seek(seek_time); | 1594 audio_->Seek(seek_time); |
1451 | 1595 |
1452 if (video_) | 1596 if (video_) |
1453 video_->Seek(seek_time); | 1597 video_->Seek(seek_time); |
| 1598 |
| 1599 for (SourceStateMap::iterator itr = source_state_map_.begin(); |
| 1600 itr != source_state_map_.end(); ++itr) { |
| 1601 itr->second->TextSeek(seek_time); |
| 1602 } |
1454 } | 1603 } |
1455 | 1604 |
1456 void ChunkDemuxer::CompletePendingReadsIfPossible() { | 1605 void ChunkDemuxer::CompletePendingReadsIfPossible() { |
1457 if (audio_) | 1606 if (audio_) |
1458 audio_->CompletePendingReadIfPossible(); | 1607 audio_->CompletePendingReadIfPossible(); |
1459 | 1608 |
1460 if (video_) | 1609 if (video_) |
1461 video_->CompletePendingReadIfPossible(); | 1610 video_->CompletePendingReadIfPossible(); |
| 1611 |
| 1612 for (SourceStateMap::iterator itr = source_state_map_.begin(); |
| 1613 itr != source_state_map_.end(); ++itr) { |
| 1614 itr->second->TextCompletePendingReadIfPossible(); |
| 1615 } |
1462 } | 1616 } |
1463 | 1617 |
1464 } // namespace media | 1618 } // namespace media |
OLD | NEW |