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/source_buffer_stream.h" | 5 #include "media/filters/source_buffer_stream.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 } | 333 } |
334 // The maximum amount of data in bytes the stream will keep in memory. | 334 // The maximum amount of data in bytes the stream will keep in memory. |
335 // 12MB: approximately 5 minutes of 320Kbps content. | 335 // 12MB: approximately 5 minutes of 320Kbps content. |
336 // 150MB: approximately 5 minutes of 4Mbps content. | 336 // 150MB: approximately 5 minutes of 4Mbps content. |
337 static int kDefaultAudioMemoryLimit = 12 * 1024 * 1024; | 337 static int kDefaultAudioMemoryLimit = 12 * 1024 * 1024; |
338 static int kDefaultVideoMemoryLimit = 150 * 1024 * 1024; | 338 static int kDefaultVideoMemoryLimit = 150 * 1024 * 1024; |
339 | 339 |
340 namespace media { | 340 namespace media { |
341 | 341 |
342 SourceBufferStream::SourceBufferStream(const AudioDecoderConfig& audio_config, | 342 SourceBufferStream::SourceBufferStream(const AudioDecoderConfig& audio_config, |
343 const LogCB& log_cb) | 343 const LogCB& log_cb, |
| 344 bool splice_frames_enabled) |
344 : log_cb_(log_cb), | 345 : log_cb_(log_cb), |
345 current_config_index_(0), | 346 current_config_index_(0), |
346 append_config_index_(0), | 347 append_config_index_(0), |
347 seek_pending_(false), | 348 seek_pending_(false), |
348 end_of_stream_(false), | 349 end_of_stream_(false), |
349 seek_buffer_timestamp_(kNoTimestamp()), | 350 seek_buffer_timestamp_(kNoTimestamp()), |
350 selected_range_(NULL), | 351 selected_range_(NULL), |
351 media_segment_start_time_(kNoTimestamp()), | 352 media_segment_start_time_(kNoTimestamp()), |
352 range_for_next_append_(ranges_.end()), | 353 range_for_next_append_(ranges_.end()), |
353 new_media_segment_(false), | 354 new_media_segment_(false), |
354 last_appended_buffer_timestamp_(kNoTimestamp()), | 355 last_appended_buffer_timestamp_(kNoTimestamp()), |
355 last_appended_buffer_is_keyframe_(false), | 356 last_appended_buffer_is_keyframe_(false), |
356 last_output_buffer_timestamp_(kNoTimestamp()), | 357 last_output_buffer_timestamp_(kNoTimestamp()), |
357 max_interbuffer_distance_(kNoTimestamp()), | 358 max_interbuffer_distance_(kNoTimestamp()), |
358 memory_limit_(kDefaultAudioMemoryLimit), | 359 memory_limit_(kDefaultAudioMemoryLimit), |
359 config_change_pending_(false), | 360 config_change_pending_(false), |
360 splice_buffers_index_(0) { | 361 splice_buffers_index_(0), |
| 362 splice_frames_enabled_(splice_frames_enabled) { |
361 DCHECK(audio_config.IsValidConfig()); | 363 DCHECK(audio_config.IsValidConfig()); |
362 audio_configs_.push_back(audio_config); | 364 audio_configs_.push_back(audio_config); |
363 } | 365 } |
364 | 366 |
365 SourceBufferStream::SourceBufferStream(const VideoDecoderConfig& video_config, | 367 SourceBufferStream::SourceBufferStream(const VideoDecoderConfig& video_config, |
366 const LogCB& log_cb) | 368 const LogCB& log_cb, |
| 369 bool splice_frames_enabled) |
367 : log_cb_(log_cb), | 370 : log_cb_(log_cb), |
368 current_config_index_(0), | 371 current_config_index_(0), |
369 append_config_index_(0), | 372 append_config_index_(0), |
370 seek_pending_(false), | 373 seek_pending_(false), |
371 end_of_stream_(false), | 374 end_of_stream_(false), |
372 seek_buffer_timestamp_(kNoTimestamp()), | 375 seek_buffer_timestamp_(kNoTimestamp()), |
373 selected_range_(NULL), | 376 selected_range_(NULL), |
374 media_segment_start_time_(kNoTimestamp()), | 377 media_segment_start_time_(kNoTimestamp()), |
375 range_for_next_append_(ranges_.end()), | 378 range_for_next_append_(ranges_.end()), |
376 new_media_segment_(false), | 379 new_media_segment_(false), |
377 last_appended_buffer_timestamp_(kNoTimestamp()), | 380 last_appended_buffer_timestamp_(kNoTimestamp()), |
378 last_appended_buffer_is_keyframe_(false), | 381 last_appended_buffer_is_keyframe_(false), |
379 last_output_buffer_timestamp_(kNoTimestamp()), | 382 last_output_buffer_timestamp_(kNoTimestamp()), |
380 max_interbuffer_distance_(kNoTimestamp()), | 383 max_interbuffer_distance_(kNoTimestamp()), |
381 memory_limit_(kDefaultVideoMemoryLimit), | 384 memory_limit_(kDefaultVideoMemoryLimit), |
382 config_change_pending_(false), | 385 config_change_pending_(false), |
383 splice_buffers_index_(0) { | 386 splice_buffers_index_(0), |
| 387 splice_frames_enabled_(splice_frames_enabled) { |
384 DCHECK(video_config.IsValidConfig()); | 388 DCHECK(video_config.IsValidConfig()); |
385 video_configs_.push_back(video_config); | 389 video_configs_.push_back(video_config); |
386 } | 390 } |
387 | 391 |
388 SourceBufferStream::SourceBufferStream(const TextTrackConfig& text_config, | 392 SourceBufferStream::SourceBufferStream(const TextTrackConfig& text_config, |
389 const LogCB& log_cb) | 393 const LogCB& log_cb, |
| 394 bool splice_frames_enabled) |
390 : log_cb_(log_cb), | 395 : log_cb_(log_cb), |
391 current_config_index_(0), | 396 current_config_index_(0), |
392 append_config_index_(0), | 397 append_config_index_(0), |
393 text_track_config_(text_config), | 398 text_track_config_(text_config), |
394 seek_pending_(false), | 399 seek_pending_(false), |
395 end_of_stream_(false), | 400 end_of_stream_(false), |
396 seek_buffer_timestamp_(kNoTimestamp()), | 401 seek_buffer_timestamp_(kNoTimestamp()), |
397 selected_range_(NULL), | 402 selected_range_(NULL), |
398 media_segment_start_time_(kNoTimestamp()), | 403 media_segment_start_time_(kNoTimestamp()), |
399 range_for_next_append_(ranges_.end()), | 404 range_for_next_append_(ranges_.end()), |
400 new_media_segment_(false), | 405 new_media_segment_(false), |
401 last_appended_buffer_timestamp_(kNoTimestamp()), | 406 last_appended_buffer_timestamp_(kNoTimestamp()), |
402 last_appended_buffer_is_keyframe_(false), | 407 last_appended_buffer_is_keyframe_(false), |
403 last_output_buffer_timestamp_(kNoTimestamp()), | 408 last_output_buffer_timestamp_(kNoTimestamp()), |
404 max_interbuffer_distance_(kNoTimestamp()), | 409 max_interbuffer_distance_(kNoTimestamp()), |
405 memory_limit_(kDefaultAudioMemoryLimit), | 410 memory_limit_(kDefaultAudioMemoryLimit), |
406 config_change_pending_(false), | 411 config_change_pending_(false), |
407 splice_buffers_index_(0) { | 412 splice_buffers_index_(0), |
408 } | 413 splice_frames_enabled_(splice_frames_enabled) {} |
409 | 414 |
410 SourceBufferStream::~SourceBufferStream() { | 415 SourceBufferStream::~SourceBufferStream() { |
411 while (!ranges_.empty()) { | 416 while (!ranges_.empty()) { |
412 delete ranges_.front(); | 417 delete ranges_.front(); |
413 ranges_.pop_front(); | 418 ranges_.pop_front(); |
414 } | 419 } |
415 } | 420 } |
416 | 421 |
417 void SourceBufferStream::OnNewMediaSegment( | 422 void SourceBufferStream::OnNewMediaSegment( |
418 base::TimeDelta media_segment_start_time) { | 423 base::TimeDelta media_segment_start_time) { |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 // position. | 963 // position. |
959 // TODO(acolwell): Figure out a more elegant way to do this. | 964 // TODO(acolwell): Figure out a more elegant way to do this. |
960 SeekAndSetSelectedRange(*range_for_next_append_, seek_timestamp); | 965 SeekAndSetSelectedRange(*range_for_next_append_, seek_timestamp); |
961 temporarily_select_range = true; | 966 temporarily_select_range = true; |
962 } | 967 } |
963 } | 968 } |
964 | 969 |
965 // Handle splices between the existing buffers and the new buffers. If a | 970 // Handle splices between the existing buffers and the new buffers. If a |
966 // splice is generated the timestamp and duration of the first buffer in | 971 // splice is generated the timestamp and duration of the first buffer in |
967 // |new_buffers| will be modified. | 972 // |new_buffers| will be modified. |
968 GenerateSpliceFrame(new_buffers); | 973 if (splice_frames_enabled_) |
| 974 GenerateSpliceFrame(new_buffers); |
969 | 975 |
970 base::TimeDelta prev_timestamp = last_appended_buffer_timestamp_; | 976 base::TimeDelta prev_timestamp = last_appended_buffer_timestamp_; |
971 bool prev_is_keyframe = last_appended_buffer_is_keyframe_; | 977 bool prev_is_keyframe = last_appended_buffer_is_keyframe_; |
972 base::TimeDelta next_timestamp = new_buffers.front()->GetDecodeTimestamp(); | 978 base::TimeDelta next_timestamp = new_buffers.front()->GetDecodeTimestamp(); |
973 bool next_is_keyframe = new_buffers.front()->IsKeyframe(); | 979 bool next_is_keyframe = new_buffers.front()->IsKeyframe(); |
974 | 980 |
975 if (prev_timestamp != kNoTimestamp() && prev_timestamp != next_timestamp) { | 981 if (prev_timestamp != kNoTimestamp() && prev_timestamp != next_timestamp) { |
976 // Clean up the old buffers between the last appended buffer and the | 982 // Clean up the old buffers between the last appended buffer and the |
977 // beginning of |new_buffers|. | 983 // beginning of |new_buffers|. |
978 RemoveInternal(prev_timestamp, next_timestamp, true, deleted_buffers); | 984 RemoveInternal(prev_timestamp, next_timestamp, true, deleted_buffers); |
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2181 if (buffer->end_of_stream() || buffer->timestamp() >= end) | 2187 if (buffer->end_of_stream() || buffer->timestamp() >= end) |
2182 break; | 2188 break; |
2183 if (buffer->timestamp() + buffer->duration() <= start) | 2189 if (buffer->timestamp() + buffer->duration() <= start) |
2184 continue; | 2190 continue; |
2185 buffers->push_back(buffer); | 2191 buffers->push_back(buffer); |
2186 } | 2192 } |
2187 return previous_size < buffers->size(); | 2193 return previous_size < buffers->size(); |
2188 } | 2194 } |
2189 | 2195 |
2190 } // namespace media | 2196 } // namespace media |
OLD | NEW |