Change MediaPlaylist to return display resolution

- The master playlist should have the display resolution instead of the
  encoded resolution.
- Changed MediaPlaylist to return display resolution.

Change-Id: I162727d0bdeed0302518286e42a22b69a58fc4a3
This commit is contained in:
Rintaro Kuroiwa 2017-07-13 13:25:36 -07:00
parent d096f4b485
commit 013a83c9d4
6 changed files with 40 additions and 14 deletions

View File

@ -109,7 +109,7 @@ bool MasterPlaylist::WriteMasterPlaylist(const std::string& base_url,
uint32_t video_width; uint32_t video_width;
uint32_t video_height; uint32_t video_height;
CHECK(video_playlist->GetResolution(&video_width, &video_height)); CHECK(video_playlist->GetDisplayResolution(&video_width, &video_height));
AppendStreamInfoTag(video_bitrate + max_audio_bitrate, AppendStreamInfoTag(video_bitrate + max_audio_bitrate,
video_codec + "," + audio_codec, video_codec + "," + audio_codec,
@ -129,7 +129,7 @@ bool MasterPlaylist::WriteMasterPlaylist(const std::string& base_url,
uint32_t video_width; uint32_t video_width;
uint32_t video_height; uint32_t video_height;
CHECK(video_playlist->GetResolution(&video_width, &video_height)); CHECK(video_playlist->GetDisplayResolution(&video_width, &video_height));
AppendStreamInfoTag(video_bitrate, AppendStreamInfoTag(video_bitrate,
video_codec, video_codec,

View File

@ -67,7 +67,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistOneVideo) {
MediaPlaylist::MediaPlaylistStreamType::kPlayListVideo); MediaPlaylist::MediaPlaylistStreamType::kPlayListVideo);
mock_playlist.SetCodecForTesting(codec); mock_playlist.SetCodecForTesting(codec);
EXPECT_CALL(mock_playlist, Bitrate()).WillOnce(Return(435889)); EXPECT_CALL(mock_playlist, Bitrate()).WillOnce(Return(435889));
EXPECT_CALL(mock_playlist, GetResolution(NotNull(), NotNull())) EXPECT_CALL(mock_playlist, GetDisplayResolution(NotNull(), NotNull()))
.WillOnce(DoAll(SetArgPointee<0>(kWidth), .WillOnce(DoAll(SetArgPointee<0>(kWidth),
SetArgPointee<1>(kHeight), SetArgPointee<1>(kHeight),
Return(true))); Return(true)));
@ -101,7 +101,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndAudio) {
EXPECT_CALL(sd_video_playlist, Bitrate()) EXPECT_CALL(sd_video_playlist, Bitrate())
.Times(AtLeast(1)) .Times(AtLeast(1))
.WillRepeatedly(Return(300000)); .WillRepeatedly(Return(300000));
EXPECT_CALL(sd_video_playlist, GetResolution(NotNull(), NotNull())) EXPECT_CALL(sd_video_playlist, GetDisplayResolution(NotNull(), NotNull()))
.WillRepeatedly(DoAll(SetArgPointee<0>(kWidth), .WillRepeatedly(DoAll(SetArgPointee<0>(kWidth),
SetArgPointee<1>(kHeight), SetArgPointee<1>(kHeight),
Return(true))); Return(true)));
@ -117,7 +117,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndAudio) {
EXPECT_CALL(hd_video_playlist, Bitrate()) EXPECT_CALL(hd_video_playlist, Bitrate())
.Times(AtLeast(1)) .Times(AtLeast(1))
.WillRepeatedly(Return(700000)); .WillRepeatedly(Return(700000));
EXPECT_CALL(hd_video_playlist, GetResolution(NotNull(), NotNull())) EXPECT_CALL(hd_video_playlist, GetDisplayResolution(NotNull(), NotNull()))
.WillRepeatedly(DoAll(SetArgPointee<0>(kWidth), .WillRepeatedly(DoAll(SetArgPointee<0>(kWidth),
SetArgPointee<1>(kHeight), SetArgPointee<1>(kHeight),
Return(true))); Return(true)));
@ -136,7 +136,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndAudio) {
EXPECT_CALL(english_playlist, Bitrate()) EXPECT_CALL(english_playlist, Bitrate())
.Times(AtLeast(1)) .Times(AtLeast(1))
.WillRepeatedly(Return(50000)); .WillRepeatedly(Return(50000));
EXPECT_CALL(english_playlist, GetResolution(NotNull(), NotNull())) EXPECT_CALL(english_playlist, GetDisplayResolution(NotNull(), NotNull()))
.Times(0); .Times(0);
master_playlist_.AddMediaPlaylist(&english_playlist); master_playlist_.AddMediaPlaylist(&english_playlist);
@ -150,7 +150,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndAudio) {
EXPECT_CALL(spanish_playlist, Bitrate()) EXPECT_CALL(spanish_playlist, Bitrate())
.Times(AtLeast(1)) .Times(AtLeast(1))
.WillRepeatedly(Return(60000)); .WillRepeatedly(Return(60000));
EXPECT_CALL(spanish_playlist, GetResolution(NotNull(), NotNull())) EXPECT_CALL(spanish_playlist, GetDisplayResolution(NotNull(), NotNull()))
.Times(0); .Times(0);
master_playlist_.AddMediaPlaylist(&spanish_playlist); master_playlist_.AddMediaPlaylist(&spanish_playlist);
@ -190,7 +190,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistMultipleAudioGroups) {
EXPECT_CALL(video_playlist, Bitrate()) EXPECT_CALL(video_playlist, Bitrate())
.Times(AtLeast(1)) .Times(AtLeast(1))
.WillRepeatedly(Return(300000)); .WillRepeatedly(Return(300000));
EXPECT_CALL(video_playlist, GetResolution(NotNull(), NotNull())) EXPECT_CALL(video_playlist, GetDisplayResolution(NotNull(), NotNull()))
.WillRepeatedly(DoAll(SetArgPointee<0>(kWidth), .WillRepeatedly(DoAll(SetArgPointee<0>(kWidth),
SetArgPointee<1>(kHeight), SetArgPointee<1>(kHeight),
Return(true))); Return(true)));
@ -207,7 +207,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistMultipleAudioGroups) {
EXPECT_CALL(eng_lo_playlist, Bitrate()) EXPECT_CALL(eng_lo_playlist, Bitrate())
.Times(AtLeast(1)) .Times(AtLeast(1))
.WillRepeatedly(Return(50000)); .WillRepeatedly(Return(50000));
EXPECT_CALL(eng_lo_playlist, GetResolution(NotNull(), NotNull())) EXPECT_CALL(eng_lo_playlist, GetDisplayResolution(NotNull(), NotNull()))
.Times(0); .Times(0);
master_playlist_.AddMediaPlaylist(&eng_lo_playlist); master_playlist_.AddMediaPlaylist(&eng_lo_playlist);
@ -221,7 +221,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistMultipleAudioGroups) {
EXPECT_CALL(eng_hi_playlist, Bitrate()) EXPECT_CALL(eng_hi_playlist, Bitrate())
.Times(AtLeast(1)) .Times(AtLeast(1))
.WillRepeatedly(Return(100000)); .WillRepeatedly(Return(100000));
EXPECT_CALL(eng_hi_playlist, GetResolution(NotNull(), NotNull())) EXPECT_CALL(eng_hi_playlist, GetDisplayResolution(NotNull(), NotNull()))
.Times(0); .Times(0);
master_playlist_.AddMediaPlaylist(&eng_hi_playlist); master_playlist_.AddMediaPlaylist(&eng_hi_playlist);

View File

@ -435,11 +435,18 @@ std::string MediaPlaylist::GetLanguage() const {
return LanguageToShortestForm(lang); return LanguageToShortestForm(lang);
} }
bool MediaPlaylist::GetResolution(uint32_t* width, uint32_t* height) const { bool MediaPlaylist::GetDisplayResolution(uint32_t* width,
uint32_t* height) const {
DCHECK(width); DCHECK(width);
DCHECK(height); DCHECK(height);
if (media_info_.has_video_info()) { if (media_info_.has_video_info()) {
*width = media_info_.video_info().width(); const double pixel_aspect_ratio =
media_info_.video_info().pixel_height() > 0
? static_cast<double>(media_info_.video_info().pixel_width()) /
media_info_.video_info().pixel_height()
: 1.0;
*width = static_cast<uint32_t>(media_info_.video_info().width() *
pixel_aspect_ratio);
*height = media_info_.video_info().height(); *height = media_info_.video_info().height();
return true; return true;
} }

View File

@ -163,7 +163,7 @@ class MediaPlaylist {
/// @return true if |width| and |height| have been set with a valid /// @return true if |width| and |height| have been set with a valid
/// resolution values. /// resolution values.
virtual bool GetResolution(uint32_t* width, uint32_t* height) const; virtual bool GetDisplayResolution(uint32_t* width, uint32_t* height) const;
private: private:
// Remove elements from |entries_| for live profile. Increments // Remove elements from |entries_| for live profile. Increments

View File

@ -124,6 +124,24 @@ TEST_F(MediaPlaylistMultiSegmentTest, AddSegment) {
media_playlist_.AddSegment("file1.ts", 900000, 0, kZeroByteOffset, 1000000); media_playlist_.AddSegment("file1.ts", 900000, 0, kZeroByteOffset, 1000000);
} }
// Verify that it returns the display resolution.
TEST_F(MediaPlaylistMultiSegmentTest, GetDisplayResolution) {
// A real case using sintel video.
MediaInfo media_info;
media_info.set_reference_time_scale(kTimeScale);
MediaInfo::VideoInfo* video_info = media_info.mutable_video_info();
video_info->set_width(1920);
video_info->set_height(818);
video_info->set_pixel_width(1636);
video_info->set_pixel_height(1635);
ASSERT_TRUE(media_playlist_.SetMediaInfo(media_info));
uint32_t width = 0;
uint32_t height = 0;
EXPECT_TRUE(media_playlist_.GetDisplayResolution(&width, &height));
EXPECT_EQ(1921u, width);
EXPECT_EQ(818u, height);
}
TEST_F(MediaPlaylistSingleSegmentTest, InitRange) { TEST_F(MediaPlaylistSingleSegmentTest, InitRange) {
const std::string kExpectedOutput = const std::string kExpectedOutput =
"#EXTM3U\n" "#EXTM3U\n"

View File

@ -44,7 +44,8 @@ class MockMediaPlaylist : public MediaPlaylist {
MOCK_CONST_METHOD0(GetLongestSegmentDuration, double()); MOCK_CONST_METHOD0(GetLongestSegmentDuration, double());
MOCK_METHOD1(SetTargetDuration, void(uint32_t target_duration)); MOCK_METHOD1(SetTargetDuration, void(uint32_t target_duration));
MOCK_CONST_METHOD0(GetLanguage, std::string()); MOCK_CONST_METHOD0(GetLanguage, std::string());
MOCK_CONST_METHOD2(GetResolution, bool(uint32_t* width, uint32_t* height)); MOCK_CONST_METHOD2(GetDisplayResolution,
bool(uint32_t* width, uint32_t* height));
}; };
} // namespace hls } // namespace hls