diff --git a/packager/hls/base/master_playlist.cc b/packager/hls/base/master_playlist.cc index 4751138222..fd7294d461 100644 --- a/packager/hls/base/master_playlist.cc +++ b/packager/hls/base/master_playlist.cc @@ -109,7 +109,7 @@ bool MasterPlaylist::WriteMasterPlaylist(const std::string& base_url, uint32_t video_width; 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, video_codec + "," + audio_codec, @@ -129,7 +129,7 @@ bool MasterPlaylist::WriteMasterPlaylist(const std::string& base_url, uint32_t video_width; uint32_t video_height; - CHECK(video_playlist->GetResolution(&video_width, &video_height)); + CHECK(video_playlist->GetDisplayResolution(&video_width, &video_height)); AppendStreamInfoTag(video_bitrate, video_codec, diff --git a/packager/hls/base/master_playlist_unittest.cc b/packager/hls/base/master_playlist_unittest.cc index cf0fd8320c..ece19acb4b 100644 --- a/packager/hls/base/master_playlist_unittest.cc +++ b/packager/hls/base/master_playlist_unittest.cc @@ -67,7 +67,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistOneVideo) { MediaPlaylist::MediaPlaylistStreamType::kPlayListVideo); mock_playlist.SetCodecForTesting(codec); 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), SetArgPointee<1>(kHeight), Return(true))); @@ -101,7 +101,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndAudio) { EXPECT_CALL(sd_video_playlist, Bitrate()) .Times(AtLeast(1)) .WillRepeatedly(Return(300000)); - EXPECT_CALL(sd_video_playlist, GetResolution(NotNull(), NotNull())) + EXPECT_CALL(sd_video_playlist, GetDisplayResolution(NotNull(), NotNull())) .WillRepeatedly(DoAll(SetArgPointee<0>(kWidth), SetArgPointee<1>(kHeight), Return(true))); @@ -117,7 +117,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndAudio) { EXPECT_CALL(hd_video_playlist, Bitrate()) .Times(AtLeast(1)) .WillRepeatedly(Return(700000)); - EXPECT_CALL(hd_video_playlist, GetResolution(NotNull(), NotNull())) + EXPECT_CALL(hd_video_playlist, GetDisplayResolution(NotNull(), NotNull())) .WillRepeatedly(DoAll(SetArgPointee<0>(kWidth), SetArgPointee<1>(kHeight), Return(true))); @@ -136,7 +136,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndAudio) { EXPECT_CALL(english_playlist, Bitrate()) .Times(AtLeast(1)) .WillRepeatedly(Return(50000)); - EXPECT_CALL(english_playlist, GetResolution(NotNull(), NotNull())) + EXPECT_CALL(english_playlist, GetDisplayResolution(NotNull(), NotNull())) .Times(0); master_playlist_.AddMediaPlaylist(&english_playlist); @@ -150,7 +150,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndAudio) { EXPECT_CALL(spanish_playlist, Bitrate()) .Times(AtLeast(1)) .WillRepeatedly(Return(60000)); - EXPECT_CALL(spanish_playlist, GetResolution(NotNull(), NotNull())) + EXPECT_CALL(spanish_playlist, GetDisplayResolution(NotNull(), NotNull())) .Times(0); master_playlist_.AddMediaPlaylist(&spanish_playlist); @@ -190,7 +190,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistMultipleAudioGroups) { EXPECT_CALL(video_playlist, Bitrate()) .Times(AtLeast(1)) .WillRepeatedly(Return(300000)); - EXPECT_CALL(video_playlist, GetResolution(NotNull(), NotNull())) + EXPECT_CALL(video_playlist, GetDisplayResolution(NotNull(), NotNull())) .WillRepeatedly(DoAll(SetArgPointee<0>(kWidth), SetArgPointee<1>(kHeight), Return(true))); @@ -207,7 +207,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistMultipleAudioGroups) { EXPECT_CALL(eng_lo_playlist, Bitrate()) .Times(AtLeast(1)) .WillRepeatedly(Return(50000)); - EXPECT_CALL(eng_lo_playlist, GetResolution(NotNull(), NotNull())) + EXPECT_CALL(eng_lo_playlist, GetDisplayResolution(NotNull(), NotNull())) .Times(0); master_playlist_.AddMediaPlaylist(&eng_lo_playlist); @@ -221,7 +221,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistMultipleAudioGroups) { EXPECT_CALL(eng_hi_playlist, Bitrate()) .Times(AtLeast(1)) .WillRepeatedly(Return(100000)); - EXPECT_CALL(eng_hi_playlist, GetResolution(NotNull(), NotNull())) + EXPECT_CALL(eng_hi_playlist, GetDisplayResolution(NotNull(), NotNull())) .Times(0); master_playlist_.AddMediaPlaylist(&eng_hi_playlist); diff --git a/packager/hls/base/media_playlist.cc b/packager/hls/base/media_playlist.cc index 0f431acf98..789a4da8c4 100644 --- a/packager/hls/base/media_playlist.cc +++ b/packager/hls/base/media_playlist.cc @@ -435,11 +435,18 @@ std::string MediaPlaylist::GetLanguage() const { 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(height); 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(media_info_.video_info().pixel_width()) / + media_info_.video_info().pixel_height() + : 1.0; + *width = static_cast(media_info_.video_info().width() * + pixel_aspect_ratio); *height = media_info_.video_info().height(); return true; } diff --git a/packager/hls/base/media_playlist.h b/packager/hls/base/media_playlist.h index 7342d38544..4b306aaca5 100644 --- a/packager/hls/base/media_playlist.h +++ b/packager/hls/base/media_playlist.h @@ -163,7 +163,7 @@ class MediaPlaylist { /// @return true if |width| and |height| have been set with a valid /// resolution values. - virtual bool GetResolution(uint32_t* width, uint32_t* height) const; + virtual bool GetDisplayResolution(uint32_t* width, uint32_t* height) const; private: // Remove elements from |entries_| for live profile. Increments diff --git a/packager/hls/base/media_playlist_unittest.cc b/packager/hls/base/media_playlist_unittest.cc index a28ab6decc..0402edb016 100644 --- a/packager/hls/base/media_playlist_unittest.cc +++ b/packager/hls/base/media_playlist_unittest.cc @@ -124,6 +124,24 @@ TEST_F(MediaPlaylistMultiSegmentTest, AddSegment) { 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) { const std::string kExpectedOutput = "#EXTM3U\n" diff --git a/packager/hls/base/mock_media_playlist.h b/packager/hls/base/mock_media_playlist.h index 43e1c706f3..70dfce7389 100644 --- a/packager/hls/base/mock_media_playlist.h +++ b/packager/hls/base/mock_media_playlist.h @@ -44,7 +44,8 @@ class MockMediaPlaylist : public MediaPlaylist { MOCK_CONST_METHOD0(GetLongestSegmentDuration, double()); MOCK_METHOD1(SetTargetDuration, void(uint32_t target_duration)); 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