| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 return; | 512 return; |
| 513 } | 513 } |
| 514 if (format_context_->duration != static_cast<int64_t>(AV_NOPTS_VALUE)) { | 514 if (format_context_->duration != static_cast<int64_t>(AV_NOPTS_VALUE)) { |
| 515 // If there is a duration value in the container use that to find the | 515 // If there is a duration value in the container use that to find the |
| 516 // maximum between it and the duration from A/V streams. | 516 // maximum between it and the duration from A/V streams. |
| 517 const AVRational av_time_base = {1, AV_TIME_BASE}; | 517 const AVRational av_time_base = {1, AV_TIME_BASE}; |
| 518 max_duration = | 518 max_duration = |
| 519 std::max(max_duration, | 519 std::max(max_duration, |
| 520 ConvertFromTimeBase(av_time_base, format_context_->duration)); | 520 ConvertFromTimeBase(av_time_base, format_context_->duration)); |
| 521 } else { | 521 } else { |
| 522 // The duration is not a valid value. Assume that this is a live stream | 522 // The duration is unknown, in which case this is likely a live stream. |
| 523 // and set duration to the maximum int64 number to represent infinity. | 523 max_duration = kInfiniteDuration; |
| 524 max_duration = base::TimeDelta::FromMicroseconds( | |
| 525 Limits::kMaxTimeInMicroseconds); | |
| 526 } | 524 } |
| 527 | 525 |
| 528 // Some demuxers, like WAV, do not put timestamps on their frames. We | 526 // Some demuxers, like WAV, do not put timestamps on their frames. We |
| 529 // assume the the start time is 0. | 527 // assume the the start time is 0. |
| 530 if (start_time_ == kNoTimestamp) | 528 if (start_time_ == kNoTimestamp) |
| 531 start_time_ = base::TimeDelta(); | 529 start_time_ = base::TimeDelta(); |
| 532 | 530 |
| 533 // Good to go: set the duration and bitrate and notify we're done | 531 // Good to go: set the duration and bitrate and notify we're done |
| 534 // initializing. | 532 // initializing. |
| 535 if (host()) | 533 if (host()) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 552 | 550 |
| 553 // Then try to sum the bitrates individually per stream. | 551 // Then try to sum the bitrates individually per stream. |
| 554 int bitrate = 0; | 552 int bitrate = 0; |
| 555 for (size_t i = 0; i < format_context_->nb_streams; ++i) { | 553 for (size_t i = 0; i < format_context_->nb_streams; ++i) { |
| 556 AVCodecContext* codec_context = format_context_->streams[i]->codec; | 554 AVCodecContext* codec_context = format_context_->streams[i]->codec; |
| 557 bitrate += codec_context->bit_rate; | 555 bitrate += codec_context->bit_rate; |
| 558 } | 556 } |
| 559 if (bitrate > 0) | 557 if (bitrate > 0) |
| 560 return bitrate; | 558 return bitrate; |
| 561 | 559 |
| 562 // If there isn't a bitrate set in the container or streams, but there is a | 560 // See if we can approximate the bitrate as long as we have a filesize and |
| 563 // valid duration, approximate the bitrate using the duration. | 561 // valid duration. |
| 564 if (max_duration_.InMilliseconds() > 0 && | 562 int64 filesize_in_bytes; |
| 565 max_duration_.InMicroseconds() < Limits::kMaxTimeInMicroseconds) { | 563 if (max_duration_.InMicroseconds() <= 0 || |
| 566 int64 filesize_in_bytes; | 564 max_duration_ == kInfiniteDuration || |
| 567 if (GetSize(&filesize_in_bytes)) | 565 !GetSize(&filesize_in_bytes)) { |
| 568 return 8000 * filesize_in_bytes / max_duration_.InMilliseconds(); | 566 return 0; |
| 569 } | 567 } |
| 570 | 568 |
| 571 // Bitrate could not be determined. | 569 // Do math in floating point as we'd overflow an int64 if the filesize was |
| 572 return 0; | 570 // larger than ~1073GB. |
| 571 double bytes = filesize_in_bytes; |
| 572 double duration = max_duration_.InMicroseconds(); |
| 573 return bytes * 8000000.0 / duration; |
| 573 } | 574 } |
| 574 | 575 |
| 575 bool FFmpegDemuxer::IsLocalSource() { | 576 bool FFmpegDemuxer::IsLocalSource() { |
| 576 return local_source_; | 577 return local_source_; |
| 577 } | 578 } |
| 578 | 579 |
| 579 bool FFmpegDemuxer::IsSeekable() { | 580 bool FFmpegDemuxer::IsSeekable() { |
| 580 return !IsStreaming(); | 581 return !IsStreaming(); |
| 581 } | 582 } |
| 582 | 583 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 read_event_.Wait(); | 733 read_event_.Wait(); |
| 733 return last_read_bytes_; | 734 return last_read_bytes_; |
| 734 } | 735 } |
| 735 | 736 |
| 736 void FFmpegDemuxer::SignalReadCompleted(size_t size) { | 737 void FFmpegDemuxer::SignalReadCompleted(size_t size) { |
| 737 last_read_bytes_ = size; | 738 last_read_bytes_ = size; |
| 738 read_event_.Signal(); | 739 read_event_.Signal(); |
| 739 } | 740 } |
| 740 | 741 |
| 741 } // namespace media | 742 } // namespace media |
| OLD | NEW |