Use max bitrate for MediaPlaylist bandwidth calculation
- HLS expects max for VOD. Change-Id: I91e9e07a27abe7167efeefc99aaada2acbed9314
This commit is contained in:
parent
f9bf197f2b
commit
50fe17fa9f
|
@ -182,10 +182,9 @@ void MediaPlaylist::AddSegment(const std::string& file_name,
|
||||||
if (segment_duration_seconds > longest_segment_duration_)
|
if (segment_duration_seconds > longest_segment_duration_)
|
||||||
longest_segment_duration_ = segment_duration_seconds;
|
longest_segment_duration_ = segment_duration_seconds;
|
||||||
|
|
||||||
total_duration_in_seconds_ += segment_duration_seconds;
|
const int kBitsInByte = 8;
|
||||||
total_segments_size_ += size;
|
const uint64_t bitrate = kBitsInByte * size / segment_duration_seconds;
|
||||||
++total_num_segments_;
|
max_bitrate_ = std::max(max_bitrate_, bitrate);
|
||||||
|
|
||||||
entries_.push_back(new SegmentInfoEntry(file_name, segment_duration_seconds));
|
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 {
|
uint64_t MediaPlaylist::Bitrate() const {
|
||||||
if (media_info_.has_bandwidth())
|
if (media_info_.has_bandwidth())
|
||||||
return media_info_.bandwidth();
|
return media_info_.bandwidth();
|
||||||
if (total_duration_in_seconds_ == 0.0)
|
return max_bitrate_;
|
||||||
return 0;
|
|
||||||
if (total_segments_size_ == 0)
|
|
||||||
return 0;
|
|
||||||
const int kBytesToBits = 8;
|
|
||||||
return total_segments_size_ * kBytesToBits / total_duration_in_seconds_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double MediaPlaylist::GetLongestSegmentDuration() const {
|
double MediaPlaylist::GetLongestSegmentDuration() const {
|
||||||
|
|
|
@ -132,8 +132,7 @@ class MediaPlaylist {
|
||||||
virtual bool WriteToFile(media::File* file);
|
virtual bool WriteToFile(media::File* file);
|
||||||
|
|
||||||
/// If bitrate is specified in MediaInfo then it will use that value.
|
/// If bitrate is specified in MediaInfo then it will use that value.
|
||||||
/// Otherwise, it is calculated from the duration and the size of the
|
/// Otherwise, returns the max bitrate.
|
||||||
/// segments added to this object.
|
|
||||||
/// @return the bitrate (in bits per second) of this MediaPlaylist.
|
/// @return the bitrate (in bits per second) of this MediaPlaylist.
|
||||||
virtual uint64_t Bitrate() const;
|
virtual uint64_t Bitrate() const;
|
||||||
|
|
||||||
|
@ -165,10 +164,8 @@ class MediaPlaylist {
|
||||||
double longest_segment_duration_ = 0.0;
|
double longest_segment_duration_ = 0.0;
|
||||||
uint32_t time_scale_ = 0;
|
uint32_t time_scale_ = 0;
|
||||||
|
|
||||||
// The sum of the size of the segments listed in this playlist (in bytes).
|
uint64_t max_bitrate_ = 0;
|
||||||
uint64_t total_segments_size_ = 0;
|
|
||||||
double total_duration_in_seconds_ = 0.0;
|
double total_duration_in_seconds_ = 0.0;
|
||||||
int total_num_segments_;
|
|
||||||
|
|
||||||
// See SetTargetDuration() comments.
|
// See SetTargetDuration() comments.
|
||||||
bool target_duration_set_ = false;
|
bool target_duration_set_ = false;
|
||||||
|
|
|
@ -148,8 +148,8 @@ TEST_F(MediaPlaylistTest, GetBitrateFromSegments) {
|
||||||
// 20 seconds, 5MB.
|
// 20 seconds, 5MB.
|
||||||
media_playlist_.AddSegment("file2.ts", 1800000, 5000000);
|
media_playlist_.AddSegment("file2.ts", 1800000, 5000000);
|
||||||
|
|
||||||
// 200KB per second which is 1600K bits / sec.
|
// Max bitrate is 2000Kb/s.
|
||||||
EXPECT_EQ(1600000u, media_playlist_.Bitrate());
|
EXPECT_EQ(2000000u, media_playlist_.Bitrate());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MediaPlaylistTest, GetLongestSegmentDuration) {
|
TEST_F(MediaPlaylistTest, GetLongestSegmentDuration) {
|
||||||
|
|
Loading…
Reference in New Issue