Chromium Code Reviews| 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/ffmpeg_demuxer.h" | 5 #include "media/filters/ffmpeg_demuxer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 } | 48 } |
| 49 | 49 |
| 50 return base::Time(); | 50 return base::Time(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 static base::TimeDelta FramesToTimeDelta(int frames, double sample_rate) { | 53 static base::TimeDelta FramesToTimeDelta(int frames, double sample_rate) { |
| 54 return base::TimeDelta::FromMicroseconds( | 54 return base::TimeDelta::FromMicroseconds( |
| 55 frames * base::Time::kMicrosecondsPerSecond / sample_rate); | 55 frames * base::Time::kMicrosecondsPerSecond / sample_rate); |
| 56 } | 56 } |
| 57 | 57 |
| 58 static base::TimeDelta ExtractStartTime(AVStream* stream) { | |
| 59 if (stream->start_time == static_cast<int64_t>(AV_NOPTS_VALUE)) | |
| 60 return kNoTimestamp(); | |
| 61 | |
| 62 // First try to use the |start_time| value directly. | |
| 63 const base::TimeDelta start_time = | |
| 64 ConvertFromTimeBase(stream->time_base, stream->start_time); | |
| 65 | |
| 66 // Then compare against the first timestamp to see if adjustment is required. | |
| 67 if (stream->first_dts == static_cast<int64_t>(AV_NOPTS_VALUE)) | |
| 68 return start_time; | |
| 69 | |
| 70 const base::TimeDelta first_dts = | |
| 71 ConvertFromTimeBase(stream->time_base, stream->first_dts); | |
| 72 | |
| 73 return first_dts < start_time ? first_dts : start_time; | |
| 74 } | |
| 75 | |
| 58 // | 76 // |
| 59 // FFmpegDemuxerStream | 77 // FFmpegDemuxerStream |
| 60 // | 78 // |
| 61 FFmpegDemuxerStream::FFmpegDemuxerStream( | 79 FFmpegDemuxerStream::FFmpegDemuxerStream( |
| 62 FFmpegDemuxer* demuxer, | 80 FFmpegDemuxer* demuxer, |
| 63 AVStream* stream) | 81 AVStream* stream, |
| 82 bool discard_negative_timestamps) | |
| 64 : demuxer_(demuxer), | 83 : demuxer_(demuxer), |
| 65 task_runner_(base::MessageLoopProxy::current()), | 84 task_runner_(base::MessageLoopProxy::current()), |
| 66 stream_(stream), | 85 stream_(stream), |
| 67 type_(UNKNOWN), | 86 type_(UNKNOWN), |
| 68 end_of_stream_(false), | 87 end_of_stream_(false), |
| 69 last_packet_timestamp_(kNoTimestamp()), | 88 last_packet_timestamp_(kNoTimestamp()), |
| 70 bitstream_converter_enabled_(false) { | 89 bitstream_converter_enabled_(false), |
| 90 discard_negative_timestamps_(discard_negative_timestamps) { | |
| 71 DCHECK(demuxer_); | 91 DCHECK(demuxer_); |
| 72 | 92 |
| 73 bool is_encrypted = false; | 93 bool is_encrypted = false; |
| 74 | 94 |
| 75 // Determine our media format. | 95 // Determine our media format. |
| 76 switch (stream->codec->codec_type) { | 96 switch (stream->codec->codec_type) { |
| 77 case AVMEDIA_TYPE_AUDIO: | 97 case AVMEDIA_TYPE_AUDIO: |
| 78 type_ = AUDIO; | 98 type_ = AUDIO; |
| 79 AVStreamToAudioDecoderConfig(stream, &audio_config_, true); | 99 AVStreamToAudioDecoderConfig(stream, &audio_config_, true); |
| 80 is_encrypted = audio_config_.is_encrypted(); | 100 is_encrypted = audio_config_.is_encrypted(); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 audio_decoder_config().samples_per_second(); | 239 audio_decoder_config().samples_per_second(); |
| 220 buffer->set_discard_padding(std::make_pair( | 240 buffer->set_discard_padding(std::make_pair( |
| 221 FramesToTimeDelta(discard_front_samples, samples_per_second), | 241 FramesToTimeDelta(discard_front_samples, samples_per_second), |
| 222 FramesToTimeDelta(discard_end_samples, samples_per_second))); | 242 FramesToTimeDelta(discard_end_samples, samples_per_second))); |
| 223 } | 243 } |
| 224 | 244 |
| 225 if (decrypt_config) | 245 if (decrypt_config) |
| 226 buffer->set_decrypt_config(decrypt_config.Pass()); | 246 buffer->set_decrypt_config(decrypt_config.Pass()); |
| 227 } | 247 } |
| 228 | 248 |
| 229 buffer->set_timestamp(ConvertStreamTimestamp( | 249 buffer->set_duration( |
| 230 stream_->time_base, packet->pts)); | 250 ConvertStreamTimestamp(stream_->time_base, packet->duration)); |
| 231 buffer->set_duration(ConvertStreamTimestamp( | 251 |
| 232 stream_->time_base, packet->duration)); | 252 // Note: If pts is AV_NOPTS_VALUE, stream_timestamp will be kNoTimestamp(). |
| 233 if (buffer->timestamp() != kNoTimestamp() && | 253 const base::TimeDelta stream_timestamp = |
| 234 last_packet_timestamp_ != kNoTimestamp() && | 254 ConvertStreamTimestamp(stream_->time_base, packet->pts); |
| 235 last_packet_timestamp_ < buffer->timestamp()) { | 255 |
| 236 buffered_ranges_.Add(last_packet_timestamp_, buffer->timestamp()); | 256 if (stream_timestamp != kNoTimestamp()) { |
| 237 demuxer_->NotifyBufferingChanged(); | 257 buffer->set_timestamp(stream_timestamp - demuxer_->start_time()); |
| 258 | |
| 259 // If enabled, mark packets with negative timestamps for post-decode | |
| 260 // discard. | |
| 261 if (discard_negative_timestamps_ && stream_timestamp < base::TimeDelta()) { | |
| 262 if (stream_timestamp + buffer->duration() < base::TimeDelta()) { | |
| 263 // Discard the entier packet if it's entirely before zero. | |
| 264 buffer->set_discard_padding( | |
| 265 std::make_pair(kInfiniteDuration(), base::TimeDelta())); | |
| 266 } else { | |
| 267 // Only discard part of the frame if it overlaps zero. | |
| 268 buffer->set_discard_padding( | |
| 269 std::make_pair(-stream_timestamp, base::TimeDelta())); | |
| 270 } | |
| 271 } | |
| 272 | |
| 273 if (last_packet_timestamp_ != kNoTimestamp() && | |
| 274 last_packet_timestamp_ < buffer->timestamp()) { | |
| 275 buffered_ranges_.Add(last_packet_timestamp_, buffer->timestamp()); | |
| 276 demuxer_->NotifyBufferingChanged(); | |
| 277 } | |
| 278 | |
| 279 // The demuxer should always output positive timestamps. | |
| 280 DCHECK(buffer->timestamp() >= base::TimeDelta()); | |
| 281 } else { | |
| 282 buffer->set_timestamp(kNoTimestamp()); | |
| 238 } | 283 } |
| 239 last_packet_timestamp_ = buffer->timestamp(); | 284 last_packet_timestamp_ = buffer->timestamp(); |
|
acolwell GONE FROM CHROMIUM
2014/06/13 18:12:13
Can't this cause gaps in the buffered ranges repor
DaleCurtis
2014/06/13 20:40:02
We should probably just stop allowing kNoTimestamp
| |
| 240 | 285 |
| 241 buffer_queue_.Push(buffer); | 286 buffer_queue_.Push(buffer); |
| 242 SatisfyPendingRead(); | 287 SatisfyPendingRead(); |
| 243 } | 288 } |
| 244 | 289 |
| 245 void FFmpegDemuxerStream::SetEndOfStream() { | 290 void FFmpegDemuxerStream::SetEndOfStream() { |
| 246 DCHECK(task_runner_->BelongsToCurrentThread()); | 291 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 247 end_of_stream_ = true; | 292 end_of_stream_ = true; |
| 248 SatisfyPendingRead(); | 293 SatisfyPendingRead(); |
| 249 } | 294 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 261 buffer_queue_.Clear(); | 306 buffer_queue_.Clear(); |
| 262 if (!read_cb_.is_null()) { | 307 if (!read_cb_.is_null()) { |
| 263 base::ResetAndReturn(&read_cb_).Run( | 308 base::ResetAndReturn(&read_cb_).Run( |
| 264 DemuxerStream::kOk, DecoderBuffer::CreateEOSBuffer()); | 309 DemuxerStream::kOk, DecoderBuffer::CreateEOSBuffer()); |
| 265 } | 310 } |
| 266 demuxer_ = NULL; | 311 demuxer_ = NULL; |
| 267 stream_ = NULL; | 312 stream_ = NULL; |
| 268 end_of_stream_ = true; | 313 end_of_stream_ = true; |
| 269 } | 314 } |
| 270 | 315 |
| 271 base::TimeDelta FFmpegDemuxerStream::duration() { | |
| 272 return duration_; | |
| 273 } | |
| 274 | |
| 275 DemuxerStream::Type FFmpegDemuxerStream::type() { | 316 DemuxerStream::Type FFmpegDemuxerStream::type() { |
| 276 DCHECK(task_runner_->BelongsToCurrentThread()); | 317 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 277 return type_; | 318 return type_; |
| 278 } | 319 } |
| 279 | 320 |
| 280 void FFmpegDemuxerStream::Read(const ReadCB& read_cb) { | 321 void FFmpegDemuxerStream::Read(const ReadCB& read_cb) { |
| 281 DCHECK(task_runner_->BelongsToCurrentThread()); | 322 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 282 CHECK(read_cb_.is_null()) << "Overlapping reads are not supported"; | 323 CHECK(read_cb_.is_null()) << "Overlapping reads are not supported"; |
| 283 read_cb_ = BindToCurrentLoop(read_cb); | 324 read_cb_ = BindToCurrentLoop(read_cb); |
| 284 | 325 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 pending_read_(false), | 454 pending_read_(false), |
| 414 pending_seek_(false), | 455 pending_seek_(false), |
| 415 data_source_(data_source), | 456 data_source_(data_source), |
| 416 media_log_(media_log), | 457 media_log_(media_log), |
| 417 bitrate_(0), | 458 bitrate_(0), |
| 418 start_time_(kNoTimestamp()), | 459 start_time_(kNoTimestamp()), |
| 419 liveness_(LIVENESS_UNKNOWN), | 460 liveness_(LIVENESS_UNKNOWN), |
| 420 text_enabled_(false), | 461 text_enabled_(false), |
| 421 duration_known_(false), | 462 duration_known_(false), |
| 422 need_key_cb_(need_key_cb), | 463 need_key_cb_(need_key_cb), |
| 464 stream_index_for_seeking_(0), | |
| 423 weak_factory_(this) { | 465 weak_factory_(this) { |
| 424 DCHECK(task_runner_.get()); | 466 DCHECK(task_runner_.get()); |
| 425 DCHECK(data_source_); | 467 DCHECK(data_source_); |
| 426 } | 468 } |
| 427 | 469 |
| 428 FFmpegDemuxer::~FFmpegDemuxer() {} | 470 FFmpegDemuxer::~FFmpegDemuxer() {} |
| 429 | 471 |
| 430 void FFmpegDemuxer::Stop(const base::Closure& callback) { | 472 void FFmpegDemuxer::Stop(const base::Closure& callback) { |
| 431 DCHECK(task_runner_->BelongsToCurrentThread()); | 473 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 432 url_protocol_->Abort(); | 474 url_protocol_->Abort(); |
| 433 data_source_->Stop( | 475 data_source_->Stop( |
| 434 BindToCurrentLoop(base::Bind(&FFmpegDemuxer::OnDataSourceStopped, | 476 BindToCurrentLoop(base::Bind(&FFmpegDemuxer::OnDataSourceStopped, |
| 435 weak_factory_.GetWeakPtr(), | 477 weak_factory_.GetWeakPtr(), |
| 436 BindToCurrentLoop(callback)))); | 478 BindToCurrentLoop(callback)))); |
| 437 data_source_ = NULL; | 479 data_source_ = NULL; |
| 438 } | 480 } |
| 439 | 481 |
| 440 void FFmpegDemuxer::Seek(base::TimeDelta time, const PipelineStatusCB& cb) { | 482 void FFmpegDemuxer::Seek(base::TimeDelta time, const PipelineStatusCB& cb) { |
| 441 DCHECK(task_runner_->BelongsToCurrentThread()); | 483 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 442 CHECK(!pending_seek_); | 484 CHECK(!pending_seek_); |
| 443 | 485 |
| 444 // TODO(scherkus): Inspect |pending_read_| and cancel IO via |blocking_url_|, | 486 // TODO(scherkus): Inspect |pending_read_| and cancel IO via |blocking_url_|, |
| 445 // otherwise we can end up waiting for a pre-seek read to complete even though | 487 // otherwise we can end up waiting for a pre-seek read to complete even though |
| 446 // we know we're going to drop it on the floor. | 488 // we know we're going to drop it on the floor. |
| 447 | 489 |
| 448 // Always seek to a timestamp less than or equal to the desired timestamp. | 490 const AVStream* seeking_stream = |
| 449 int flags = AVSEEK_FLAG_BACKWARD; | 491 glue_->format_context()->streams[stream_index_for_seeking_]; |
| 450 | 492 |
| 451 // Passing -1 as our stream index lets FFmpeg pick a default stream. FFmpeg | |
| 452 // will attempt to use the lowest-index video stream, if present, followed by | |
| 453 // the lowest-index audio stream. | |
| 454 pending_seek_ = true; | 493 pending_seek_ = true; |
| 455 base::PostTaskAndReplyWithResult( | 494 base::PostTaskAndReplyWithResult( |
| 456 blocking_thread_.message_loop_proxy().get(), | 495 blocking_thread_.message_loop_proxy().get(), |
| 457 FROM_HERE, | 496 FROM_HERE, |
| 458 base::Bind(&av_seek_frame, | 497 base::Bind( |
| 459 glue_->format_context(), | 498 &av_seek_frame, |
| 460 -1, | 499 glue_->format_context(), |
| 461 time.InMicroseconds(), | 500 stream_index_for_seeking_, |
| 462 flags), | 501 ConvertToTimeBase(seeking_stream->time_base, time + start_time()), |
| 502 // Always seek to a timestamp <= to the desired timestamp. | |
| 503 AVSEEK_FLAG_BACKWARD), | |
| 463 base::Bind( | 504 base::Bind( |
| 464 &FFmpegDemuxer::OnSeekFrameDone, weak_factory_.GetWeakPtr(), cb)); | 505 &FFmpegDemuxer::OnSeekFrameDone, weak_factory_.GetWeakPtr(), cb)); |
| 465 } | 506 } |
| 466 | 507 |
| 467 void FFmpegDemuxer::Initialize(DemuxerHost* host, | 508 void FFmpegDemuxer::Initialize(DemuxerHost* host, |
| 468 const PipelineStatusCB& status_cb, | 509 const PipelineStatusCB& status_cb, |
| 469 bool enable_text_tracks) { | 510 bool enable_text_tracks) { |
| 470 DCHECK(task_runner_->BelongsToCurrentThread()); | 511 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 471 host_ = host; | 512 host_ = host; |
| 472 text_enabled_ = enable_text_tracks; | 513 text_enabled_ = enable_text_tracks; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 501 DemuxerStream::Type type) const { | 542 DemuxerStream::Type type) const { |
| 502 StreamVector::const_iterator iter; | 543 StreamVector::const_iterator iter; |
| 503 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { | 544 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { |
| 504 if (*iter && (*iter)->type() == type) { | 545 if (*iter && (*iter)->type() == type) { |
| 505 return *iter; | 546 return *iter; |
| 506 } | 547 } |
| 507 } | 548 } |
| 508 return NULL; | 549 return NULL; |
| 509 } | 550 } |
| 510 | 551 |
| 511 base::TimeDelta FFmpegDemuxer::GetStartTime() const { | |
| 512 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 513 return start_time_; | |
| 514 } | |
| 515 | |
| 516 base::Time FFmpegDemuxer::GetTimelineOffset() const { | 552 base::Time FFmpegDemuxer::GetTimelineOffset() const { |
| 517 return timeline_offset_; | 553 return timeline_offset_; |
| 518 } | 554 } |
| 519 | 555 |
| 520 Demuxer::Liveness FFmpegDemuxer::GetLiveness() const { | 556 Demuxer::Liveness FFmpegDemuxer::GetLiveness() const { |
| 521 DCHECK(task_runner_->BelongsToCurrentThread()); | 557 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 522 return liveness_; | 558 return liveness_; |
| 523 } | 559 } |
| 524 | 560 |
| 525 void FFmpegDemuxer::AddTextStreams() { | 561 void FFmpegDemuxer::AddTextStreams() { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 621 // partial playback. At least one audio or video stream must be playable. | 657 // partial playback. At least one audio or video stream must be playable. |
| 622 AVFormatContext* format_context = glue_->format_context(); | 658 AVFormatContext* format_context = glue_->format_context(); |
| 623 streams_.resize(format_context->nb_streams); | 659 streams_.resize(format_context->nb_streams); |
| 624 | 660 |
| 625 AVStream* audio_stream = NULL; | 661 AVStream* audio_stream = NULL; |
| 626 AudioDecoderConfig audio_config; | 662 AudioDecoderConfig audio_config; |
| 627 | 663 |
| 628 AVStream* video_stream = NULL; | 664 AVStream* video_stream = NULL; |
| 629 VideoDecoderConfig video_config; | 665 VideoDecoderConfig video_config; |
| 630 | 666 |
| 667 // If available, |start_time_| will be set to the lowest stream start time. | |
| 668 start_time_ = kInfiniteDuration(); | |
| 669 | |
| 631 base::TimeDelta max_duration; | 670 base::TimeDelta max_duration; |
| 632 for (size_t i = 0; i < format_context->nb_streams; ++i) { | 671 for (size_t i = 0; i < format_context->nb_streams; ++i) { |
| 633 AVStream* stream = format_context->streams[i]; | 672 AVStream* stream = format_context->streams[i]; |
| 634 AVCodecContext* codec_context = stream->codec; | 673 AVCodecContext* codec_context = stream->codec; |
| 635 AVMediaType codec_type = codec_context->codec_type; | 674 AVMediaType codec_type = codec_context->codec_type; |
| 675 bool discard_negative_timestamps = false; | |
| 636 | 676 |
| 637 if (codec_type == AVMEDIA_TYPE_AUDIO) { | 677 if (codec_type == AVMEDIA_TYPE_AUDIO) { |
| 638 if (audio_stream) | 678 if (audio_stream) |
| 639 continue; | 679 continue; |
| 640 | 680 |
| 641 // Log the codec detected, whether it is supported or not. | 681 // Log the codec detected, whether it is supported or not. |
| 642 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedAudioCodec", | 682 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedAudioCodec", |
| 643 codec_context->codec_id); | 683 codec_context->codec_id); |
| 644 // Ensure the codec is supported. IsValidConfig() also checks that the | 684 // Ensure the codec is supported. IsValidConfig() also checks that the |
| 645 // channel layout and sample format are valid. | 685 // channel layout and sample format are valid. |
| 646 AVStreamToAudioDecoderConfig(stream, &audio_config, false); | 686 AVStreamToAudioDecoderConfig(stream, &audio_config, false); |
| 647 if (!audio_config.IsValidConfig()) | 687 if (!audio_config.IsValidConfig()) |
| 648 continue; | 688 continue; |
| 649 audio_stream = stream; | 689 audio_stream = stream; |
| 690 | |
| 691 const base::TimeDelta audio_start_time = ExtractStartTime(stream); | |
| 692 if (audio_start_time != kNoTimestamp() && | |
| 693 audio_start_time < start_time_) { | |
| 694 stream_index_for_seeking_ = i; | |
| 695 start_time_ = audio_start_time; | |
| 696 } | |
| 697 | |
| 698 // Enable post-decode frame dropping for packets with negative timestamps | |
| 699 // as outlined in section A.2 in the Ogg Vorbis spec: | |
| 700 // http://xiph.org/vorbis/doc/Vorbis_I_spec.html | |
| 701 discard_negative_timestamps = | |
| 702 audio_config.codec() == kCodecVorbis && | |
| 703 strcmp(glue_->format_context()->iformat->name, "ogg") == 0; | |
| 650 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { | 704 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { |
| 651 if (video_stream) | 705 if (video_stream) |
| 652 continue; | 706 continue; |
| 653 | 707 |
| 654 // Log the codec detected, whether it is supported or not. | 708 // Log the codec detected, whether it is supported or not. |
| 655 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedVideoCodec", | 709 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedVideoCodec", |
| 656 codec_context->codec_id); | 710 codec_context->codec_id); |
| 657 // Ensure the codec is supported. IsValidConfig() also checks that the | 711 // Ensure the codec is supported. IsValidConfig() also checks that the |
| 658 // frame size and visible size are valid. | 712 // frame size and visible size are valid. |
| 659 AVStreamToVideoDecoderConfig(stream, &video_config, false); | 713 AVStreamToVideoDecoderConfig(stream, &video_config, false); |
| 660 | 714 |
| 661 if (!video_config.IsValidConfig()) | 715 if (!video_config.IsValidConfig()) |
| 662 continue; | 716 continue; |
| 663 video_stream = stream; | 717 video_stream = stream; |
| 718 | |
| 719 // Find the video start time. Note the <= comparison causes the video | |
| 720 // stream to be preferred for seeking when start times match. | |
| 721 const base::TimeDelta video_start_time = ExtractStartTime(stream); | |
| 722 if (video_start_time != kNoTimestamp() && | |
| 723 video_start_time <= start_time_) { | |
| 724 stream_index_for_seeking_ = i; | |
| 725 start_time_ = video_start_time; | |
| 726 } | |
| 664 } else if (codec_type == AVMEDIA_TYPE_SUBTITLE) { | 727 } else if (codec_type == AVMEDIA_TYPE_SUBTITLE) { |
| 665 if (codec_context->codec_id != AV_CODEC_ID_WEBVTT || !text_enabled_) { | 728 if (codec_context->codec_id != AV_CODEC_ID_WEBVTT || !text_enabled_) { |
| 666 continue; | 729 continue; |
| 667 } | 730 } |
| 668 } else { | 731 } else { |
| 669 continue; | 732 continue; |
| 670 } | 733 } |
| 671 | 734 |
|
acolwell GONE FROM CHROMIUM
2014/06/13 18:12:12
Can't we move the start_time check/update here and
DaleCurtis
2014/06/13 20:40:02
Done.
| |
| 672 streams_[i] = new FFmpegDemuxerStream(this, stream); | 735 streams_[i] = |
| 736 new FFmpegDemuxerStream(this, stream, discard_negative_timestamps); | |
| 673 max_duration = std::max(max_duration, streams_[i]->duration()); | 737 max_duration = std::max(max_duration, streams_[i]->duration()); |
| 674 | |
| 675 if (stream->first_dts != static_cast<int64_t>(AV_NOPTS_VALUE)) { | |
| 676 const base::TimeDelta first_dts = ConvertFromTimeBase( | |
| 677 stream->time_base, stream->first_dts); | |
| 678 if (start_time_ == kNoTimestamp() || first_dts < start_time_) | |
| 679 start_time_ = first_dts; | |
| 680 } | |
| 681 } | 738 } |
| 682 | 739 |
| 683 if (!audio_stream && !video_stream) { | 740 if (!audio_stream && !video_stream) { |
| 684 status_cb.Run(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); | 741 status_cb.Run(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); |
| 685 return; | 742 return; |
| 686 } | 743 } |
| 687 | 744 |
| 688 if (text_enabled_) | 745 if (text_enabled_) |
| 689 AddTextStreams(); | 746 AddTextStreams(); |
| 690 | 747 |
| 691 if (format_context->duration != static_cast<int64_t>(AV_NOPTS_VALUE)) { | 748 if (format_context->duration != static_cast<int64_t>(AV_NOPTS_VALUE)) { |
| 692 // If there is a duration value in the container use that to find the | 749 // If there is a duration value in the container use that to find the |
| 693 // maximum between it and the duration from A/V streams. | 750 // maximum between it and the duration from A/V streams. |
| 694 const AVRational av_time_base = {1, AV_TIME_BASE}; | 751 const AVRational av_time_base = {1, AV_TIME_BASE}; |
| 695 max_duration = | 752 max_duration = |
| 696 std::max(max_duration, | 753 std::max(max_duration, |
| 697 ConvertFromTimeBase(av_time_base, format_context->duration)); | 754 ConvertFromTimeBase(av_time_base, format_context->duration)); |
| 698 } else { | 755 } else { |
| 699 // The duration is unknown, in which case this is likely a live stream. | 756 // The duration is unknown, in which case this is likely a live stream. |
| 700 max_duration = kInfiniteDuration(); | 757 max_duration = kInfiniteDuration(); |
| 701 } | 758 } |
| 702 | 759 |
| 703 // Some demuxers, like WAV, do not put timestamps on their frames. We | 760 // If no start time could be determined, default to zero and prefer the video |
| 704 // assume the the start time is 0. | 761 // stream over the audio stream for seeking. E.g., The WAV demuxer does not |
| 705 if (start_time_ == kNoTimestamp()) | 762 // put timestamps on its frames. |
| 763 if (start_time_ == kInfiniteDuration()) { | |
| 706 start_time_ = base::TimeDelta(); | 764 start_time_ = base::TimeDelta(); |
| 765 stream_index_for_seeking_ = | |
| 766 video_stream ? video_stream->index : audio_stream->index; | |
| 767 } | |
| 707 | 768 |
| 708 // MPEG-4 B-frames cause grief for a simple container like AVI. Enable PTS | 769 // MPEG-4 B-frames cause grief for a simple container like AVI. Enable PTS |
| 709 // generation so we always get timestamps, see http://crbug.com/169570 | 770 // generation so we always get timestamps, see http://crbug.com/169570 |
| 710 if (strcmp(format_context->iformat->name, "avi") == 0) | 771 if (strcmp(format_context->iformat->name, "avi") == 0) |
| 711 format_context->flags |= AVFMT_FLAG_GENPTS; | 772 format_context->flags |= AVFMT_FLAG_GENPTS; |
| 712 | 773 |
| 713 timeline_offset_ = ExtractTimelineOffset(format_context); | 774 timeline_offset_ = ExtractTimelineOffset(format_context); |
| 714 | 775 |
| 776 // Since we're shifting the externally visible start time to zero, we need to | |
| 777 // adjust the timeline offset to compensate. | |
| 778 if (!timeline_offset_.is_null()) | |
| 779 timeline_offset_ += start_time_; | |
| 780 | |
| 715 if (max_duration == kInfiniteDuration() && !timeline_offset_.is_null()) { | 781 if (max_duration == kInfiniteDuration() && !timeline_offset_.is_null()) { |
| 716 liveness_ = LIVENESS_LIVE; | 782 liveness_ = LIVENESS_LIVE; |
| 717 } else if (max_duration != kInfiniteDuration()) { | 783 } else if (max_duration != kInfiniteDuration()) { |
| 718 liveness_ = LIVENESS_RECORDED; | 784 liveness_ = LIVENESS_RECORDED; |
| 719 } else { | 785 } else { |
| 720 liveness_ = LIVENESS_UNKNOWN; | 786 liveness_ = LIVENESS_UNKNOWN; |
| 721 } | 787 } |
| 722 | 788 |
| 723 // Good to go: set the duration and bitrate and notify we're done | 789 // Good to go: set the duration and bitrate and notify we're done |
| 724 // initializing. | 790 // initializing. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 776 video_codec->time_base.num, | 842 video_codec->time_base.num, |
| 777 video_codec->time_base.den)); | 843 video_codec->time_base.den)); |
| 778 media_log_->SetStringProperty( | 844 media_log_->SetStringProperty( |
| 779 "video_format", VideoFrame::FormatToString(video_config.format())); | 845 "video_format", VideoFrame::FormatToString(video_config.format())); |
| 780 media_log_->SetBooleanProperty("video_is_encrypted", | 846 media_log_->SetBooleanProperty("video_is_encrypted", |
| 781 video_config.is_encrypted()); | 847 video_config.is_encrypted()); |
| 782 } else { | 848 } else { |
| 783 media_log_->SetBooleanProperty("found_video_stream", false); | 849 media_log_->SetBooleanProperty("found_video_stream", false); |
| 784 } | 850 } |
| 785 | 851 |
| 786 | |
| 787 media_log_->SetTimeProperty("max_duration", max_duration); | 852 media_log_->SetTimeProperty("max_duration", max_duration); |
| 788 media_log_->SetTimeProperty("start_time", start_time_); | 853 media_log_->SetTimeProperty("start_time", start_time_); |
| 789 media_log_->SetIntegerProperty("bitrate", bitrate_); | 854 media_log_->SetIntegerProperty("bitrate", bitrate_); |
| 790 | 855 |
| 791 status_cb.Run(PIPELINE_OK); | 856 status_cb.Run(PIPELINE_OK); |
| 792 } | 857 } |
| 793 | 858 |
| 794 void FFmpegDemuxer::OnSeekFrameDone(const PipelineStatusCB& cb, int result) { | 859 void FFmpegDemuxer::OnSeekFrameDone(const PipelineStatusCB& cb, int result) { |
| 795 DCHECK(task_runner_->BelongsToCurrentThread()); | 860 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 796 CHECK(pending_seek_); | 861 CHECK(pending_seek_); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1012 } | 1077 } |
| 1013 for (size_t i = 0; i < buffered.size(); ++i) | 1078 for (size_t i = 0; i < buffered.size(); ++i) |
| 1014 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); | 1079 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); |
| 1015 } | 1080 } |
| 1016 | 1081 |
| 1017 void FFmpegDemuxer::OnDataSourceError() { | 1082 void FFmpegDemuxer::OnDataSourceError() { |
| 1018 host_->OnDemuxerError(PIPELINE_ERROR_READ); | 1083 host_->OnDemuxerError(PIPELINE_ERROR_READ); |
| 1019 } | 1084 } |
| 1020 | 1085 |
| 1021 } // namespace media | 1086 } // namespace media |
| OLD | NEW |