Pass hls_name and hls_group to HlsNotifyMuxerListener constructor

- Also don't Flush the notifier OnMediaEnd().

Change-Id: I2ffbbfacda74bb88678ac4e32b1f28c3e64eb85d
This commit is contained in:
Rintaro Kuroiwa 2016-04-16 15:58:47 -07:00
parent d06a9cd17c
commit 565affe7fb
3 changed files with 36 additions and 17 deletions

View File

@ -16,9 +16,15 @@
namespace shaka { namespace shaka {
namespace media { namespace media {
HlsNotifyMuxerListener::HlsNotifyMuxerListener(const std::string& playlist_name, HlsNotifyMuxerListener::HlsNotifyMuxerListener(
hls::HlsNotifier* hls_notifier) const std::string& playlist_name,
: playlist_name_(playlist_name), hls_notifier_(hls_notifier) { const std::string& ext_x_media_name,
const std::string& ext_x_media_group_id,
hls::HlsNotifier* hls_notifier)
: playlist_name_(playlist_name),
ext_x_media_name_(ext_x_media_name),
ext_x_media_group_id_(ext_x_media_group_id),
hls_notifier_(hls_notifier) {
DCHECK(hls_notifier); DCHECK(hls_notifier);
} }
@ -48,13 +54,12 @@ void HlsNotifyMuxerListener::OnMediaStart(const MuxerOptions& muxer_options,
return; return;
} }
const bool result = hls_notifier_->NotifyNewStream( const bool result = hls_notifier_->NotifyNewStream(
media_info, playlist_name_, muxer_options.hls_name, media_info, playlist_name_, ext_x_media_name_, ext_x_media_group_id_,
muxer_options.hls_group_id, &stream_id_); &stream_id_);
LOG_IF(WARNING, !result) << "Failed to notify new stream."; LOG_IF(WARNING, !result) << "Failed to notify new stream.";
} }
void HlsNotifyMuxerListener::OnSampleDurationReady(uint32_t sample_duration) { void HlsNotifyMuxerListener::OnSampleDurationReady(uint32_t sample_duration) {}
}
void HlsNotifyMuxerListener::OnMediaEnd(bool has_init_range, void HlsNotifyMuxerListener::OnMediaEnd(bool has_init_range,
uint64_t init_range_start, uint64_t init_range_start,
@ -64,8 +69,9 @@ void HlsNotifyMuxerListener::OnMediaEnd(bool has_init_range,
uint64_t index_range_end, uint64_t index_range_end,
float duration_seconds, float duration_seconds,
uint64_t file_size) { uint64_t file_size) {
const bool result = hls_notifier_->Flush(); // Don't flush the notifier here. Flushing here would write all the playlists
LOG_IF(WARNING, !result) << "Failed to flush."; // before all Media Playlists are read. Which could cause problems
// setting the correct EXT-X-TARGETDURATION.
} }
void HlsNotifyMuxerListener::OnNewSegment(const std::string& file_name, void HlsNotifyMuxerListener::OnNewSegment(const std::string& file_name,

View File

@ -24,8 +24,16 @@ namespace media {
class HlsNotifyMuxerListener : public MuxerListener { class HlsNotifyMuxerListener : public MuxerListener {
public: public:
/// @param playlist_name is the name of the playlist for the muxer's stream. /// @param playlist_name is the name of the playlist for the muxer's stream.
/// @param ext_x_media_name is the name of this playlist. This is the
/// value of the NAME attribute for EXT-X-MEDIA, it is not the same as
/// @a playlist_name. This may be empty for video.
/// @param ext_x_media_group_id is the group ID for this playlist. This is the
/// value of GROUP-ID attribute for EXT-X-MEDIA. This may be empty for
/// video.
/// @param hls_notifier used by this listener. Ownership does not transfer. /// @param hls_notifier used by this listener. Ownership does not transfer.
HlsNotifyMuxerListener(const std::string& playlist_name, HlsNotifyMuxerListener(const std::string& playlist_name,
const std::string& ext_x_media_name,
const std::string& ext_x_media_group_id,
hls::HlsNotifier* hls_notifier); hls::HlsNotifier* hls_notifier);
~HlsNotifyMuxerListener() override; ~HlsNotifyMuxerListener() override;
@ -58,6 +66,8 @@ class HlsNotifyMuxerListener : public MuxerListener {
private: private:
const std::string playlist_name_; const std::string playlist_name_;
const std::string ext_x_media_name_;
const std::string ext_x_media_group_id_;
hls::HlsNotifier* const hls_notifier_; hls::HlsNotifier* const hls_notifier_;
uint32_t stream_id_ = 0; uint32_t stream_id_ = 0;

View File

@ -66,13 +66,18 @@ const uint8_t kAnyData[] = {
const bool kInitialEncryptionInfo = true; const bool kInitialEncryptionInfo = true;
const char kDefaultPlaylistName[] = "default_playlist.m3u8"; const char kDefaultPlaylistName[] = "default_playlist.m3u8";
const char kDefaultName[] = "DEFAULTNAME";
const char kDefaultGroupId[] = "DEFAULTGROUPID";
} // namespace } // namespace
class HlsNotifyMuxerListenerTest : public ::testing::Test { class HlsNotifyMuxerListenerTest : public ::testing::Test {
protected: protected:
HlsNotifyMuxerListenerTest() HlsNotifyMuxerListenerTest()
: listener_(kDefaultPlaylistName, &mock_notifier_) {} : listener_(kDefaultPlaylistName,
kDefaultName,
kDefaultGroupId,
&mock_notifier_) {}
MockHlsNotifier mock_notifier_; MockHlsNotifier mock_notifier_;
HlsNotifyMuxerListener listener_; HlsNotifyMuxerListener listener_;
@ -100,29 +105,27 @@ TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionInfoReady) {
} }
TEST_F(HlsNotifyMuxerListenerTest, OnMediaStart) { TEST_F(HlsNotifyMuxerListenerTest, OnMediaStart) {
MuxerOptions muxer_options;
muxer_options.hls_name = "Name";
muxer_options.hls_group_id = "GroupID";
SetDefaultMuxerOptionsValues(&muxer_options);
VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams();
scoped_refptr<StreamInfo> video_stream_info = scoped_refptr<StreamInfo> video_stream_info =
CreateVideoStreamInfo(video_params); CreateVideoStreamInfo(video_params);
EXPECT_CALL(mock_notifier_, EXPECT_CALL(mock_notifier_,
NotifyNewStream(_, StrEq(kDefaultPlaylistName), StrEq("Name"), NotifyNewStream(_, StrEq(kDefaultPlaylistName),
StrEq("GroupID"), _)) StrEq("DEFAULTNAME"), StrEq("DEFAULTGROUPID"), _))
.WillOnce(Return(true)); .WillOnce(Return(true));
MuxerOptions muxer_options;
listener_.OnMediaStart(muxer_options, *video_stream_info, 90000, listener_.OnMediaStart(muxer_options, *video_stream_info, 90000,
MuxerListener::kContainerMpeg2ts); MuxerListener::kContainerMpeg2ts);
} }
// Make sure it doesn't crash.
TEST_F(HlsNotifyMuxerListenerTest, OnSampleDurationReady) { TEST_F(HlsNotifyMuxerListenerTest, OnSampleDurationReady) {
listener_.OnSampleDurationReady(2340); listener_.OnSampleDurationReady(2340);
} }
// Make sure it doesn't crash.
TEST_F(HlsNotifyMuxerListenerTest, OnMediaEnd) { TEST_F(HlsNotifyMuxerListenerTest, OnMediaEnd) {
EXPECT_CALL(mock_notifier_, Flush()).WillOnce(Return(true));
// None of these values matter, they are not used. // None of these values matter, they are not used.
listener_.OnMediaEnd(false, 0, 0, false, 0, 0, 0, 0); listener_.OnMediaEnd(false, 0, 0, false, 0, 0, 0, 0);
} }