Use max bitrate for MediaPlaylist bandwidth calculation

- HLS expects max for VOD.

Change-Id: I91e9e07a27abe7167efeefc99aaada2acbed9314
This commit is contained in:
Rintaro Kuroiwa 2016-06-29 20:09:36 -07:00
parent f9bf197f2b
commit 50fe17fa9f
3 changed files with 8 additions and 17 deletions

View File

@ -182,10 +182,9 @@ void MediaPlaylist::AddSegment(const std::string& file_name,
if (segment_duration_seconds > longest_segment_duration_)
longest_segment_duration_ = segment_duration_seconds;
total_duration_in_seconds_ += segment_duration_seconds;
total_segments_size_ += size;
++total_num_segments_;
const int kBitsInByte = 8;
const uint64_t bitrate = kBitsInByte * size / segment_duration_seconds;
max_bitrate_ = std::max(max_bitrate_, bitrate);
entries_.push_back(new SegmentInfoEntry(file_name, segment_duration_seconds));
}
@ -313,12 +312,7 @@ bool MediaPlaylist::WriteToFile(media::File* file) {
uint64_t MediaPlaylist::Bitrate() const {
if (media_info_.has_bandwidth())
return media_info_.bandwidth();
if (total_duration_in_seconds_ == 0.0)
return 0;
if (total_segments_size_ == 0)
return 0;
const int kBytesToBits = 8;
return total_segments_size_ * kBytesToBits / total_duration_in_seconds_;
return max_bitrate_;
}
double MediaPlaylist::GetLongestSegmentDuration() const {

View File

@ -132,8 +132,7 @@ class MediaPlaylist {
virtual bool WriteToFile(media::File* file);
/// If bitrate is specified in MediaInfo then it will use that value.
/// Otherwise, it is calculated from the duration and the size of the
/// segments added to this object.
/// Otherwise, returns the max bitrate.
/// @return the bitrate (in bits per second) of this MediaPlaylist.
virtual uint64_t Bitrate() const;
@ -165,10 +164,8 @@ class MediaPlaylist {
double longest_segment_duration_ = 0.0;
uint32_t time_scale_ = 0;
// The sum of the size of the segments listed in this playlist (in bytes).
uint64_t total_segments_size_ = 0;
uint64_t max_bitrate_ = 0;
double total_duration_in_seconds_ = 0.0;
int total_num_segments_;
// See SetTargetDuration() comments.
bool target_duration_set_ = false;

View File

@ -148,8 +148,8 @@ TEST_F(MediaPlaylistTest, GetBitrateFromSegments) {
// 20 seconds, 5MB.
media_playlist_.AddSegment("file2.ts", 1800000, 5000000);
// 200KB per second which is 1600K bits / sec.
EXPECT_EQ(1600000u, media_playlist_.Bitrate());
// Max bitrate is 2000Kb/s.
EXPECT_EQ(2000000u, media_playlist_.Bitrate());
}
TEST_F(MediaPlaylistTest, GetLongestSegmentDuration) {