diff --git a/packager/app/packager_main.cc b/packager/app/packager_main.cc index 4ebf183e97..860a1fa473 100644 --- a/packager/app/packager_main.cc +++ b/packager/app/packager_main.cc @@ -22,6 +22,7 @@ #include "packager/base/optional.h" #include "packager/base/strings/string_number_conversions.h" #include "packager/base/strings/string_split.h" +#include "packager/base/strings/string_util.h" #include "packager/base/strings/stringprintf.h" #include "packager/file/file.h" #include "packager/packager.h" @@ -118,6 +119,21 @@ bool GetWidevineSigner(WidevineSigner* signer) { return true; } +bool GetHlsPlaylistType(const std::string& playlist_type, + HlsPlaylistType* playlist_type_enum) { + if (base::ToUpperASCII(playlist_type) == "VOD") { + *playlist_type_enum = HlsPlaylistType::kVod; + } else if (base::ToUpperASCII(playlist_type) == "LIVE") { + *playlist_type_enum = HlsPlaylistType::kLive; + } else if (base::ToUpperASCII(playlist_type) == "EVENT") { + *playlist_type_enum = HlsPlaylistType::kEvent; + } else { + LOG(ERROR) << "Unrecognized playlist type " << playlist_type; + return false; + } + return true; +} + base::Optional GetPackagingParams() { PackagingParams packaging_params; @@ -263,14 +279,7 @@ base::Optional GetPackagingParams() { mpd_params.default_language = FLAGS_default_language; HlsParams& hls_params = packaging_params.hls_params; - if (FLAGS_hls_playlist_type == "VOD") { - hls_params.playlist_type = HlsPlaylistType::kVod; - } else if (FLAGS_hls_playlist_type == "LIVE") { - hls_params.playlist_type = HlsPlaylistType::kLive; - } else if (FLAGS_hls_playlist_type == "EVENT") { - hls_params.playlist_type = HlsPlaylistType::kEvent; - } else { - LOG(ERROR) << "Unrecognized playlist type " << FLAGS_hls_playlist_type; + if (!GetHlsPlaylistType(FLAGS_hls_playlist_type, &hls_params.playlist_type)) { return base::nullopt; } hls_params.master_playlist_output = FLAGS_hls_master_playlist_output; diff --git a/packager/hls/base/hls_notifier.h b/packager/hls/base/hls_notifier.h index 74ee64d149..b5f92137eb 100644 --- a/packager/hls/base/hls_notifier.h +++ b/packager/hls/base/hls_notifier.h @@ -10,22 +10,17 @@ #include #include +#include "packager/hls/public/hls_playlist_type.h" #include "packager/mpd/base/media_info.pb.h" namespace shaka { namespace hls { -// TODO(kqyang): Combine with MediaPlaylistType in media_playlist.h. -enum class HlsProfile { - kOnDemandProfile, - kEventProfile, - kLiveProfile, -}; - // TODO(rkuroiwa): Consider merging this with MpdNotifier. class HlsNotifier { public: - explicit HlsNotifier(HlsProfile profile) : profile_(profile) {} + explicit HlsNotifier(HlsPlaylistType playlist_type) + : playlist_type_(playlist_type) {} virtual ~HlsNotifier() {} /// Intialize the notifier. @@ -81,13 +76,14 @@ class HlsNotifier { /// @return true on success, false otherwise. virtual bool Flush() = 0; - /// @return the profile. - HlsProfile profile() const { return profile_; } + /// @return the playlist type. + HlsPlaylistType playlist_type() const { return playlist_type_; } private: - HlsProfile profile_; + HlsPlaylistType playlist_type_; }; } // namespace hls } // namespace shaka + #endif // PACKAGER_HLS_BASE_HLS_NOTIFIER_H_ diff --git a/packager/hls/base/master_playlist_unittest.cc b/packager/hls/base/master_playlist_unittest.cc index 8e899243f2..6f1d02cb92 100644 --- a/packager/hls/base/master_playlist_unittest.cc +++ b/packager/hls/base/master_playlist_unittest.cc @@ -30,8 +30,7 @@ namespace { const char kDefaultMasterPlaylistName[] = "playlist.m3u8"; const uint32_t kWidth = 800; const uint32_t kHeight = 600; -const MediaPlaylist::MediaPlaylistType kVodPlaylist = - MediaPlaylist::MediaPlaylistType::kVod; +const HlsPlaylistType kVodPlaylist = HlsPlaylistType::kVod; } // namespace class MasterPlaylistTest : public ::testing::Test { diff --git a/packager/hls/base/media_playlist.cc b/packager/hls/base/media_playlist.cc index b86992eb31..d246fcd849 100644 --- a/packager/hls/base/media_playlist.cc +++ b/packager/hls/base/media_playlist.cc @@ -59,12 +59,11 @@ std::string CreateExtXMap(const MediaInfo& media_info) { return ext_x_map; } -std::string CreatePlaylistHeader( - const MediaInfo& media_info, - uint32_t target_duration, - MediaPlaylist::MediaPlaylistType type, - int media_sequence_number, - int discontinuity_sequence_number) { +std::string CreatePlaylistHeader(const MediaInfo& media_info, + uint32_t target_duration, + HlsPlaylistType type, + int media_sequence_number, + int discontinuity_sequence_number) { const std::string version = GetPackagerVersion(); std::string version_line; if (!version.empty()) { @@ -82,13 +81,13 @@ std::string CreatePlaylistHeader( version_line.c_str(), target_duration); switch (type) { - case MediaPlaylist::MediaPlaylistType::kVod: + case HlsPlaylistType::kVod: header += "#EXT-X-PLAYLIST-TYPE:VOD\n"; break; - case MediaPlaylist::MediaPlaylistType::kEvent: + case HlsPlaylistType::kEvent: header += "#EXT-X-PLAYLIST-TYPE:EVENT\n"; break; - case MediaPlaylist::MediaPlaylistType::kLive: + case HlsPlaylistType::kLive: if (media_sequence_number > 0) { base::StringAppendF(&header, "#EXT-X-MEDIA-SEQUENCE:%d\n", media_sequence_number); @@ -278,7 +277,7 @@ double LatestSegmentStartTime( HlsEntry::HlsEntry(HlsEntry::EntryType type) : type_(type) {} HlsEntry::~HlsEntry() {} -MediaPlaylist::MediaPlaylist(MediaPlaylistType playlist_type, +MediaPlaylist::MediaPlaylist(HlsPlaylistType playlist_type, double time_shift_buffer_depth, const std::string& file_name, const std::string& name, @@ -379,8 +378,8 @@ bool MediaPlaylist::WriteToFile(const std::string& file_path) { } std::string header = CreatePlaylistHeader( - media_info_, target_duration_, playlist_type_, - media_sequence_number_, discontinuity_sequence_number_); + media_info_, target_duration_, playlist_type_, media_sequence_number_, + discontinuity_sequence_number_); std::string body; for (const auto& entry : entries_) @@ -388,7 +387,7 @@ bool MediaPlaylist::WriteToFile(const std::string& file_path) { std::string content = header + body; - if (playlist_type_ == MediaPlaylistType::kVod) { + if (playlist_type_ == HlsPlaylistType::kVod) { content += "#EXT-X-ENDLIST\n"; } @@ -456,7 +455,7 @@ bool MediaPlaylist::GetDisplayResolution(uint32_t* width, void MediaPlaylist::SlideWindow() { DCHECK(!entries_.empty()); if (time_shift_buffer_depth_ <= 0.0 || - playlist_type_ != MediaPlaylistType::kLive) { + playlist_type_ != HlsPlaylistType::kLive) { return; } DCHECK_GT(time_scale_, 0u); diff --git a/packager/hls/base/media_playlist.h b/packager/hls/base/media_playlist.h index 0dc60d77c0..896627baa2 100644 --- a/packager/hls/base/media_playlist.h +++ b/packager/hls/base/media_playlist.h @@ -12,6 +12,7 @@ #include #include "packager/base/macros.h" +#include "packager/hls/public/hls_playlist_type.h" #include "packager/mpd/base/media_info.pb.h" namespace shaka { @@ -42,11 +43,6 @@ class HlsEntry { /// Methods are virtual for mocking. class MediaPlaylist { public: - enum class MediaPlaylistType { - kVod, - kEvent, - kLive, - }; enum class MediaPlaylistStreamType { kPlaylistUnknown, kPlayListAudio, @@ -60,7 +56,7 @@ class MediaPlaylist { kSampleAesCenc, // 'cenc' encrypted content. }; - /// @param type is the type of this media playlist. + /// @param playlist_type is the type of this media playlist. /// @param time_shift_buffer_depth determines the duration of the time /// shifting buffer, only for live HLS. /// @param file_name is the file name of this media playlist. @@ -69,7 +65,7 @@ class MediaPlaylist { /// necessarily the same as @a file_name. /// @param group_id is the group ID for this playlist. This is the value of /// GROUP-ID attribute for EXT-X-MEDIA. - MediaPlaylist(MediaPlaylistType playlist_type, + MediaPlaylist(HlsPlaylistType playlist_type, double time_shift_buffer_depth, const std::string& file_name, const std::string& name, @@ -168,7 +164,7 @@ class MediaPlaylist { // |sequence_number_| by the number of segments removed. void SlideWindow(); - const MediaPlaylistType playlist_type_; + const HlsPlaylistType playlist_type_; const double time_shift_buffer_depth_; // Mainly for MasterPlaylist to use these values. const std::string file_name_; diff --git a/packager/hls/base/media_playlist_unittest.cc b/packager/hls/base/media_playlist_unittest.cc index 8f1496feab..43fb5dd97d 100644 --- a/packager/hls/base/media_playlist_unittest.cc +++ b/packager/hls/base/media_playlist_unittest.cc @@ -36,10 +36,9 @@ MATCHER_P(MatchesString, expected_string, "") { class MediaPlaylistTest : public ::testing::Test { protected: - MediaPlaylistTest() - : MediaPlaylistTest(MediaPlaylist::MediaPlaylistType::kVod) {} + MediaPlaylistTest() : MediaPlaylistTest(HlsPlaylistType::kVod) {} - MediaPlaylistTest(MediaPlaylist::MediaPlaylistType type) + MediaPlaylistTest(HlsPlaylistType type) : default_file_name_(kDefaultPlaylistFileName), default_name_("default_name"), default_group_id_("default_group_id"), @@ -77,7 +76,7 @@ class MediaPlaylistMultiSegmentTest : public MediaPlaylistTest { protected: MediaPlaylistMultiSegmentTest() : MediaPlaylistTest() {} // This constructor is for Live and Event playlist tests. - MediaPlaylistMultiSegmentTest(MediaPlaylist::MediaPlaylistType type) + MediaPlaylistMultiSegmentTest(HlsPlaylistType type) : MediaPlaylistTest(type) {} void SetUp() override { @@ -538,8 +537,7 @@ TEST_F(MediaPlaylistMultiSegmentTest, MultipleEncryptionInfo) { class LiveMediaPlaylistTest : public MediaPlaylistMultiSegmentTest { protected: LiveMediaPlaylistTest() - : MediaPlaylistMultiSegmentTest(MediaPlaylist::MediaPlaylistType::kLive) { - } + : MediaPlaylistMultiSegmentTest(HlsPlaylistType::kLive) {} }; TEST_F(LiveMediaPlaylistTest, Basic) { @@ -701,8 +699,7 @@ TEST_F(LiveMediaPlaylistTest, TimeShiftedWithEncryptionInfoShifted) { class EventMediaPlaylistTest : public MediaPlaylistMultiSegmentTest { protected: EventMediaPlaylistTest() - : MediaPlaylistMultiSegmentTest( - MediaPlaylist::MediaPlaylistType::kEvent) {} + : MediaPlaylistMultiSegmentTest(HlsPlaylistType::kEvent) {} }; TEST_F(EventMediaPlaylistTest, Basic) { diff --git a/packager/hls/base/mock_media_playlist.cc b/packager/hls/base/mock_media_playlist.cc index d04055f0e7..f073aacc52 100644 --- a/packager/hls/base/mock_media_playlist.cc +++ b/packager/hls/base/mock_media_playlist.cc @@ -9,7 +9,7 @@ namespace shaka { namespace hls { -MockMediaPlaylist::MockMediaPlaylist(MediaPlaylistType type, +MockMediaPlaylist::MockMediaPlaylist(HlsPlaylistType type, const std::string& file_name, const std::string& name, const std::string& group_id) diff --git a/packager/hls/base/mock_media_playlist.h b/packager/hls/base/mock_media_playlist.h index 70dfce7389..a8f141c57e 100644 --- a/packager/hls/base/mock_media_playlist.h +++ b/packager/hls/base/mock_media_playlist.h @@ -18,7 +18,7 @@ class MockMediaPlaylist : public MediaPlaylist { public: // The actual parameters to MediaPlaylist() (parent) constructor doesn't // matter because the return value can be mocked. - MockMediaPlaylist(MediaPlaylistType type, + MockMediaPlaylist(HlsPlaylistType type, const std::string& file_name, const std::string& name, const std::string& group_id); @@ -31,7 +31,6 @@ class MockMediaPlaylist : public MediaPlaylist { uint64_t duration, uint64_t start_byte_offset, uint64_t size)); - MOCK_METHOD0(RemoveOldestSegment, void()); MOCK_METHOD6(AddEncryptionInfo, void(EncryptionMethod method, const std::string& url, diff --git a/packager/hls/base/simple_hls_notifier.cc b/packager/hls/base/simple_hls_notifier.cc index fd085a73b3..eb6cefa158 100644 --- a/packager/hls/base/simple_hls_notifier.cc +++ b/packager/hls/base/simple_hls_notifier.cc @@ -211,7 +211,7 @@ bool WriteMediaPlaylist(const std::string& output_dir, MediaPlaylistFactory::~MediaPlaylistFactory() {} std::unique_ptr MediaPlaylistFactory::Create( - MediaPlaylist::MediaPlaylistType type, + HlsPlaylistType type, double time_shift_buffer_depth, const std::string& file_name, const std::string& name, @@ -220,12 +220,12 @@ std::unique_ptr MediaPlaylistFactory::Create( type, time_shift_buffer_depth, file_name, name, group_id)); } -SimpleHlsNotifier::SimpleHlsNotifier(HlsProfile profile, +SimpleHlsNotifier::SimpleHlsNotifier(HlsPlaylistType playlist_type, double time_shift_buffer_depth, const std::string& prefix, const std::string& output_dir, const std::string& master_playlist_name) - : HlsNotifier(profile), + : HlsNotifier(playlist_type), time_shift_buffer_depth_(time_shift_buffer_depth), prefix_(prefix), output_dir_(output_dir), @@ -245,27 +245,11 @@ bool SimpleHlsNotifier::NotifyNewStream(const MediaInfo& media_info, uint32_t* stream_id) { DCHECK(stream_id); - MediaPlaylist::MediaPlaylistType type; - switch (profile()) { - case HlsProfile::kLiveProfile: - type = MediaPlaylist::MediaPlaylistType::kLive; - break; - case HlsProfile::kOnDemandProfile: - type = MediaPlaylist::MediaPlaylistType::kVod; - break; - case HlsProfile::kEventProfile: - type = MediaPlaylist::MediaPlaylistType::kEvent; - break; - default: - NOTREACHED(); - return false; - } - MediaInfo adjusted_media_info(media_info); MakePathsRelativeToOutputDirectory(output_dir_, &adjusted_media_info); std::unique_ptr media_playlist = - media_playlist_factory_->Create(type, time_shift_buffer_depth_, + media_playlist_factory_->Create(playlist_type(), time_shift_buffer_depth_, playlist_name, name, group_id); if (!media_playlist->SetMediaInfo(adjusted_media_info)) { LOG(ERROR) << "Failed to set media info for playlist " << playlist_name; @@ -324,8 +308,8 @@ bool SimpleHlsNotifier::NotifyNewSegment(uint32_t stream_id, } // Update the playlists when there is new segments in live mode. - if (profile() == HlsProfile::kLiveProfile || - profile() == HlsProfile::kEventProfile) { + if (playlist_type() == HlsPlaylistType::kLive || + playlist_type() == HlsPlaylistType::kEvent) { if (!master_playlist_->WriteMasterPlaylist(prefix_, output_dir_)) { LOG(ERROR) << "Failed to write master playlist."; return false; diff --git a/packager/hls/base/simple_hls_notifier.h b/packager/hls/base/simple_hls_notifier.h index 937782bbc2..31efddf8c4 100644 --- a/packager/hls/base/simple_hls_notifier.h +++ b/packager/hls/base/simple_hls_notifier.h @@ -18,6 +18,7 @@ #include "packager/hls/base/hls_notifier.h" #include "packager/hls/base/master_playlist.h" #include "packager/hls/base/media_playlist.h" +#include "packager/hls/public/hls_playlist_type.h" namespace shaka { namespace hls { @@ -27,12 +28,11 @@ namespace hls { class MediaPlaylistFactory { public: virtual ~MediaPlaylistFactory(); - virtual std::unique_ptr Create( - MediaPlaylist::MediaPlaylistType type, - double time_shift_buffer_depth, - const std::string& file_name, - const std::string& name, - const std::string& group_id); + virtual std::unique_ptr Create(HlsPlaylistType type, + double time_shift_buffer_depth, + const std::string& file_name, + const std::string& name, + const std::string& group_id); }; /// This is thread safe. @@ -40,7 +40,7 @@ class SimpleHlsNotifier : public HlsNotifier { public: /// @a prefix is used as hte prefix for all the URIs for Media Playlist. This /// includes the segment URIs in the Media Playlists. - /// @param profile is the profile of the playlists. + /// @param playlist_type is the type of the playlists. /// @param time_shift_buffer_depth determines the duration of the time /// shifting buffer, only for live HLS. /// @param prefix is the used as the prefix for MediaPlaylist URIs. May be @@ -48,7 +48,7 @@ class SimpleHlsNotifier : public HlsNotifier { /// @param output_dir is the output directory of the playlists. May be empty /// to write to current directory. /// @param master_playlist_name is the name of the master playlist. - SimpleHlsNotifier(HlsProfile profile, + SimpleHlsNotifier(HlsPlaylistType playlist_type, double time_shift_buffer_depth, const std::string& prefix, const std::string& output_dir, diff --git a/packager/hls/base/simple_hls_notifier_unittest.cc b/packager/hls/base/simple_hls_notifier_unittest.cc index d5d16296c9..2a22c1e398 100644 --- a/packager/hls/base/simple_hls_notifier_unittest.cc +++ b/packager/hls/base/simple_hls_notifier_unittest.cc @@ -30,8 +30,7 @@ using ::testing::_; namespace { const char kMasterPlaylistName[] = "master.m3u8"; -const MediaPlaylist::MediaPlaylistType kVodPlaylist = - MediaPlaylist::MediaPlaylistType::kVod; +const HlsPlaylistType kVodPlaylist = HlsPlaylistType::kVod; class MockMasterPlaylist : public MasterPlaylist { public: @@ -45,13 +44,13 @@ class MockMasterPlaylist : public MasterPlaylist { class MockMediaPlaylistFactory : public MediaPlaylistFactory { public: MOCK_METHOD5(CreateMock, - MediaPlaylist*(MediaPlaylist::MediaPlaylistType type, + MediaPlaylist*(HlsPlaylistType type, double time_shift_buffer_depth, const std::string& file_name, const std::string& name, const std::string& group_id)); - std::unique_ptr Create(MediaPlaylist::MediaPlaylistType type, + std::unique_ptr Create(HlsPlaylistType type, double time_shift_buffer_depth, const std::string& file_name, const std::string& name, @@ -87,10 +86,9 @@ const char kSampleAesProtectionScheme[] = "cbca"; class SimpleHlsNotifierTest : public ::testing::Test { protected: - SimpleHlsNotifierTest() - : SimpleHlsNotifierTest(HlsProfile::kOnDemandProfile) {} + SimpleHlsNotifierTest() : SimpleHlsNotifierTest(kVodPlaylist) {} - SimpleHlsNotifierTest(HlsProfile profile) + SimpleHlsNotifierTest(HlsPlaylistType playlist_type) : widevine_system_id_( media::kWidevineSystemId, media::kWidevineSystemId + arraysize(media::kWidevineSystemId)), @@ -144,9 +142,8 @@ class SimpleHlsNotifierTest : public ::testing::Test { }; TEST_F(SimpleHlsNotifierTest, Init) { - SimpleHlsNotifier notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAnyOutputDir, kMasterPlaylistName); + SimpleHlsNotifier notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAnyOutputDir, kMasterPlaylistName); EXPECT_TRUE(notifier.Init()); } @@ -177,9 +174,8 @@ TEST_F(SimpleHlsNotifierTest, RebaseSegmentTemplateRelative) { StrEq("groupid"))) .WillOnce(Return(mock_media_playlist)); - SimpleHlsNotifier notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAnyOutputDir, kMasterPlaylistName); + SimpleHlsNotifier notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAnyOutputDir, kMasterPlaylistName); InjectMasterPlaylist(std::move(mock_master_playlist), ¬ifier); InjectMediaPlaylistFactory(std::move(factory), ¬ifier); @@ -201,9 +197,9 @@ TEST_F(SimpleHlsNotifierTest, RebaseSegmentTemplateRelative) { TEST_F(SimpleHlsNotifierTest, RebaseAbsoluteSegmentTemplatePrefixAndOutputDirMatch) { const char kAbsoluteOutputDir[] = "/tmp/something/"; - SimpleHlsNotifier test_notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAbsoluteOutputDir, kMasterPlaylistName); + SimpleHlsNotifier test_notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAbsoluteOutputDir, + kMasterPlaylistName); std::unique_ptr mock_master_playlist( new MockMasterPlaylist()); @@ -246,9 +242,9 @@ TEST_F(SimpleHlsNotifierTest, TEST_F(SimpleHlsNotifierTest, RebaseAbsoluteSegmentTemplateCompletelyDifferentDirectory) { const char kAbsoluteOutputDir[] = "/tmp/something/"; - SimpleHlsNotifier test_notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAbsoluteOutputDir, kMasterPlaylistName); + SimpleHlsNotifier test_notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAbsoluteOutputDir, + kMasterPlaylistName); std::unique_ptr mock_master_playlist( new MockMasterPlaylist()); @@ -286,9 +282,8 @@ TEST_F(SimpleHlsNotifierTest, } TEST_F(SimpleHlsNotifierTest, Flush) { - SimpleHlsNotifier notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAnyOutputDir, kMasterPlaylistName); + SimpleHlsNotifier notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAnyOutputDir, kMasterPlaylistName); std::unique_ptr mock_master_playlist( new MockMasterPlaylist()); EXPECT_CALL(*mock_master_playlist, @@ -316,9 +311,8 @@ TEST_F(SimpleHlsNotifierTest, NotifyNewStream) { StrEq("groupid"))) .WillOnce(Return(mock_media_playlist)); - SimpleHlsNotifier notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAnyOutputDir, kMasterPlaylistName); + SimpleHlsNotifier notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAnyOutputDir, kMasterPlaylistName); InjectMasterPlaylist(std::move(mock_master_playlist), ¬ifier); InjectMediaPlaylistFactory(std::move(factory), ¬ifier); @@ -360,9 +354,8 @@ TEST_F(SimpleHlsNotifierTest, NotifyNewSegment) { EXPECT_CALL(*mock_media_playlist, GetLongestSegmentDuration()) .WillOnce(Return(kLongestSegmentDuration)); - SimpleHlsNotifier notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAnyOutputDir, kMasterPlaylistName); + SimpleHlsNotifier notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAnyOutputDir, kMasterPlaylistName); MockMasterPlaylist* mock_master_playlist_ptr = mock_master_playlist.get(); InjectMasterPlaylist(std::move(mock_master_playlist), ¬ifier); InjectMediaPlaylistFactory(std::move(factory), ¬ifier); @@ -393,9 +386,8 @@ TEST_F(SimpleHlsNotifierTest, NotifyNewSegment) { } TEST_F(SimpleHlsNotifierTest, NotifyNewSegmentWithoutStreamsRegistered) { - SimpleHlsNotifier notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAnyOutputDir, kMasterPlaylistName); + SimpleHlsNotifier notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAnyOutputDir, kMasterPlaylistName); EXPECT_TRUE(notifier.Init()); EXPECT_FALSE(notifier.NotifyNewSegment(1u, "anything", 0u, 0u, 0u, 0u)); } @@ -404,9 +396,8 @@ TEST_F(SimpleHlsNotifierTest, NotifyEncryptionUpdateWidevine) { // Pointer released by SimpleHlsNotifier. MockMediaPlaylist* mock_media_playlist = new MockMediaPlaylist(kVodPlaylist, "playlist.m3u8", "", ""); - SimpleHlsNotifier notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAnyOutputDir, kMasterPlaylistName); + SimpleHlsNotifier notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAnyOutputDir, kMasterPlaylistName); const uint32_t stream_id = SetupStream(kSampleAesProtectionScheme, mock_media_playlist, ¬ifier); @@ -467,9 +458,8 @@ TEST_F(SimpleHlsNotifierTest, NotifyEncryptionUpdateWidevineNoKeyidsInPssh) { // Pointer released by SimpleHlsNotifier. MockMediaPlaylist* mock_media_playlist = new MockMediaPlaylist(kVodPlaylist, "playlist.m3u8", "", ""); - SimpleHlsNotifier notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAnyOutputDir, kMasterPlaylistName); + SimpleHlsNotifier notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAnyOutputDir, kMasterPlaylistName); const uint32_t stream_id = SetupStream(kSampleAesProtectionScheme, mock_media_playlist, ¬ifier); @@ -526,9 +516,8 @@ TEST_F(SimpleHlsNotifierTest, NotifyEncryptionUpdateFixedKey) { // Pointer released by SimpleHlsNotifier. MockMediaPlaylist* mock_media_playlist = new MockMediaPlaylist(kVodPlaylist, "playlist.m3u8", "", ""); - SimpleHlsNotifier notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAnyOutputDir, kMasterPlaylistName); + SimpleHlsNotifier notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAnyOutputDir, kMasterPlaylistName); const uint32_t stream_id = SetupStream(kSampleAesProtectionScheme, mock_media_playlist, ¬ifier); @@ -556,9 +545,8 @@ TEST_F(SimpleHlsNotifierTest, WidevineMultipleKeyIdsNoContentIdInPssh) { // Pointer released by SimpleHlsNotifier. MockMediaPlaylist* mock_media_playlist = new MockMediaPlaylist(kVodPlaylist, "playlist.m3u8", "", ""); - SimpleHlsNotifier notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAnyOutputDir, kMasterPlaylistName); + SimpleHlsNotifier notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAnyOutputDir, kMasterPlaylistName); uint32_t stream_id = SetupStream(kSampleAesProtectionScheme, mock_media_playlist, ¬ifier); @@ -634,9 +622,8 @@ TEST_F(SimpleHlsNotifierTest, EncryptionScheme) { // Pointer released by SimpleHlsNotifier. MockMediaPlaylist* mock_media_playlist = new MockMediaPlaylist(kVodPlaylist, "playlist.m3u8", "", ""); - SimpleHlsNotifier notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAnyOutputDir, kMasterPlaylistName); + SimpleHlsNotifier notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAnyOutputDir, kMasterPlaylistName); const uint32_t stream_id = SetupStream(kCencProtectionScheme, mock_media_playlist, ¬ifier); @@ -663,9 +650,8 @@ TEST_F(SimpleHlsNotifierTest, WidevineCencEncryptionScheme) { // Pointer released by SimpleHlsNotifier. MockMediaPlaylist* mock_media_playlist = new MockMediaPlaylist(kVodPlaylist, "playlist.m3u8", "", ""); - SimpleHlsNotifier notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAnyOutputDir, kMasterPlaylistName); + SimpleHlsNotifier notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAnyOutputDir, kMasterPlaylistName); const uint32_t stream_id = SetupStream(kCencProtectionScheme, mock_media_playlist, ¬ifier); @@ -712,9 +698,8 @@ TEST_F(SimpleHlsNotifierTest, WidevineNotifyEncryptionUpdateEmptyIv) { // Pointer released by SimpleHlsNotifier. MockMediaPlaylist* mock_media_playlist = new MockMediaPlaylist(kVodPlaylist, "playlist.m3u8", "", ""); - SimpleHlsNotifier notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAnyOutputDir, kMasterPlaylistName); + SimpleHlsNotifier notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAnyOutputDir, kMasterPlaylistName); const uint32_t stream_id = SetupStream(kSampleAesProtectionScheme, mock_media_playlist, ¬ifier); @@ -780,9 +765,8 @@ TEST_F(SimpleHlsNotifierTest, NotifyEncryptionUpdateWithoutStreamsRegistered) { std::vector iv; std::vector pssh_data; std::vector key_id; - SimpleHlsNotifier notifier(HlsProfile::kOnDemandProfile, - kTestTimeShiftBufferDepth, kTestPrefix, - kAnyOutputDir, kMasterPlaylistName); + SimpleHlsNotifier notifier(kVodPlaylist, kTestTimeShiftBufferDepth, + kTestPrefix, kAnyOutputDir, kMasterPlaylistName); EXPECT_TRUE(notifier.Init()); EXPECT_FALSE( notifier.NotifyEncryptionUpdate(1238u, key_id, system_id, iv, pssh_data)); @@ -790,23 +774,13 @@ TEST_F(SimpleHlsNotifierTest, NotifyEncryptionUpdateWithoutStreamsRegistered) { class LiveOrEventSimpleHlsNotifierTest : public SimpleHlsNotifierTest, - public ::testing::WithParamInterface { + public ::testing::WithParamInterface { protected: LiveOrEventSimpleHlsNotifierTest() : SimpleHlsNotifierTest(GetParam()) { - switch (GetParam()) { - case HlsProfile::kLiveProfile: - expected_playlist_type_ = MediaPlaylist::MediaPlaylistType::kLive; - break; - case HlsProfile::kOnDemandProfile: - expected_playlist_type_ = MediaPlaylist::MediaPlaylistType::kVod; - break; - case HlsProfile::kEventProfile: - expected_playlist_type_ = MediaPlaylist::MediaPlaylistType::kEvent; - break; - } + expected_playlist_type_ = GetParam(); } - MediaPlaylist::MediaPlaylistType expected_playlist_type_; + HlsPlaylistType expected_playlist_type_; }; TEST_P(LiveOrEventSimpleHlsNotifierTest, NotifyNewSegment) { @@ -959,7 +933,7 @@ TEST_P(LiveOrEventSimpleHlsNotifierTest, NotifyNewSegmentsWithMultipleStreams) { INSTANTIATE_TEST_CASE_P(PlaylistTypes, LiveOrEventSimpleHlsNotifierTest, - ::testing::Values(HlsProfile::kLiveProfile, - HlsProfile::kEventProfile)); + ::testing::Values(HlsPlaylistType::kLive, + HlsPlaylistType::kEvent)); } // namespace hls } // namespace shaka diff --git a/packager/hls/hls.gyp b/packager/hls/hls.gyp index 58e3ec463d..ffa13853d9 100644 --- a/packager/hls/hls.gyp +++ b/packager/hls/hls.gyp @@ -20,6 +20,7 @@ 'base/media_playlist.h', 'base/simple_hls_notifier.cc', 'base/simple_hls_notifier.h', + 'public/hls_playlist_type.h', ], 'dependencies': [ '../base/base.gyp:base', diff --git a/packager/hls/public/hls_playlist_type.h b/packager/hls/public/hls_playlist_type.h new file mode 100644 index 0000000000..06e8912135 --- /dev/null +++ b/packager/hls/public/hls_playlist_type.h @@ -0,0 +1,22 @@ +// Copyright 2017 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#ifndef PACKAGER_HLS_PUBLIC_HLS_PLAYLIST_TYPE_H_ +#define PACKAGER_HLS_PUBLIC_HLS_PLAYLIST_TYPE_H_ + +namespace shaka { + +/// Defines the EXT-X-PLAYLIST-TYPE in the HLS specification. For +/// HlsPlaylistType of kLive, EXT-X-PLAYLIST-TYPE tag is omitted. +enum class HlsPlaylistType { + kVod, + kEvent, + kLive, +}; + +} // namespace shaka + +#endif // PACKAGER_HLS_PUBLIC_HLS_PLAYLIST_TYPE_H_ diff --git a/packager/media/event/hls_notify_muxer_listener_unittest.cc b/packager/media/event/hls_notify_muxer_listener_unittest.cc index 9fe6842af5..c880b0b424 100644 --- a/packager/media/event/hls_notify_muxer_listener_unittest.cc +++ b/packager/media/event/hls_notify_muxer_listener_unittest.cc @@ -24,7 +24,7 @@ namespace { class MockHlsNotifier : public hls::HlsNotifier { public: - MockHlsNotifier() : HlsNotifier(hls::HlsProfile::kOnDemandProfile) {} + MockHlsNotifier() : HlsNotifier(HlsPlaylistType::kVod) {} MOCK_METHOD0(Init, bool()); MOCK_METHOD5(NotifyNewStream, diff --git a/packager/packager.cc b/packager/packager.cc index 96ed040d8d..ee1c85610d 100644 --- a/packager/packager.cc +++ b/packager/packager.cc @@ -205,20 +205,6 @@ bool ValidateParams(const PackagingParams& packaging_params, return true; } -hls::HlsProfile GetHlsNotifierProfile(HlsPlaylistType playlist_type) { - switch (playlist_type) { - case HlsPlaylistType::kVod: - return hls::HlsProfile::kOnDemandProfile; - case HlsPlaylistType::kEvent: - return hls::HlsProfile::kEventProfile; - case HlsPlaylistType::kLive: - return hls::HlsProfile::kLiveProfile; - } - LOG(WARNING) << "Unrecognized playlist type (" - << static_cast(playlist_type) << "). Assuming VOD."; - return hls::HlsProfile::kOnDemandProfile; -} - class StreamDescriptorCompareFn { public: bool operator()(const StreamDescriptor& a, const StreamDescriptor& b) { @@ -647,8 +633,8 @@ Status Packager::Initialize( base::FilePath master_playlist_name = master_playlist_path.BaseName(); internal->hls_notifier.reset(new hls::SimpleHlsNotifier( - media::GetHlsNotifierProfile(hls_params.playlist_type), - hls_params.time_shift_buffer_depth, hls_params.base_url, + hls_params.playlist_type, hls_params.time_shift_buffer_depth, + hls_params.base_url, master_playlist_path.DirName().AsEndingWithSeparator().AsUTF8Unsafe(), master_playlist_name.AsUTF8Unsafe())); } diff --git a/packager/packager.h b/packager/packager.h index a45dc639f9..06992cf607 100644 --- a/packager/packager.h +++ b/packager/packager.h @@ -14,6 +14,7 @@ #include #include +#include "packager/hls/public/hls_playlist_type.h" #include "packager/status.h" namespace shaka { @@ -94,14 +95,6 @@ struct MpdParams { bool generate_dash_if_iop_compliant_mpd = true; }; -/// Defines the EXT-X-PLAYLIST-TYPE in the HLS specification. For -/// HlsPlaylistType of kLive, EXT-X-PLAYLIST-TYPE tag is omitted. -enum class HlsPlaylistType { - kVod, - kEvent, - kLive, -}; - /// HLS related parameters. struct HlsParams { /// HLS playlist type. See HLS specification for details.