From c6cbd734653b5bcef4110291f8de491667f29fa0 Mon Sep 17 00:00:00 2001 From: Kongqun Yang Date: Wed, 22 Feb 2017 12:14:26 -0800 Subject: [PATCH] Rename FlushStream to OnFlushRequest; add FlushOutput Change-Id: I2b37030b0c35aa34e9c72e43825f157924034227 --- packager/media/base/demuxer.cc | 2 +- packager/media/base/media_handler.cc | 19 ++++++++++++------- packager/media/base/media_handler.h | 7 +++++-- .../media/base/media_handler_test_base.cc | 2 +- packager/media/base/muxer.h | 2 +- packager/media/chunking/chunking_handler.cc | 5 +++-- packager/media/chunking/chunking_handler.h | 2 +- .../chunking/chunking_handler_unittest.cc | 14 +++++++------- 8 files changed, 31 insertions(+), 22 deletions(-) diff --git a/packager/media/base/demuxer.cc b/packager/media/base/demuxer.cc index 93e90e1962..95f4ef5708 100644 --- a/packager/media/base/demuxer.cc +++ b/packager/media/base/demuxer.cc @@ -107,7 +107,7 @@ Status Demuxer::Run() { if (status.error_code() == error::END_OF_STREAM) { for (int stream_index : stream_indexes_) { - status = FlushStream(stream_index); + status = FlushDownstream(stream_index); if (!status.ok()) return status; } diff --git a/packager/media/base/media_handler.cc b/packager/media/base/media_handler.cc index 0ab130cb9b..0b91c0f8ba 100644 --- a/packager/media/base/media_handler.cc +++ b/packager/media/base/media_handler.cc @@ -38,15 +38,11 @@ Status MediaHandler::Initialize() { return Status::OK; } -Status MediaHandler::FlushStream(int input_stream_index) { +Status MediaHandler::OnFlushRequest(int input_stream_index) { // The default implementation treats the output stream index to be identical // to the input stream index, which is true for most handlers. - auto handler_it = output_handlers_.find(input_stream_index); - if (handler_it == output_handlers_.end()) { - return Status(error::NOT_FOUND, - "No output handler exist at the specified index."); - } - return handler_it->second.first->FlushStream(handler_it->second.second); + const int output_stream_index = input_stream_index; + return FlushDownstream(output_stream_index); } bool MediaHandler::ValidateOutputStreamIndex(int stream_index) const { @@ -64,5 +60,14 @@ Status MediaHandler::Dispatch(std::unique_ptr stream_data) { return handler_it->second.first->Process(std::move(stream_data)); } +Status MediaHandler::FlushDownstream(int output_stream_index) { + auto handler_it = output_handlers_.find(output_stream_index); + if (handler_it == output_handlers_.end()) { + return Status(error::NOT_FOUND, + "No output handler exist at the specified index."); + } + return handler_it->second.first->OnFlushRequest(handler_it->second.second); +} + } // namespace media } // namespace shaka diff --git a/packager/media/base/media_handler.h b/packager/media/base/media_handler.h index 8c44c6f6b1..6053d255f8 100644 --- a/packager/media/base/media_handler.h +++ b/packager/media/base/media_handler.h @@ -96,8 +96,8 @@ class MediaHandler { /// handlers after finishing processing if needed. virtual Status Process(std::unique_ptr stream_data) = 0; - /// Flush the stream at the specified input stream index. - virtual Status FlushStream(int input_stream_index); + /// Event handler for flush request at the specific input stream index. + virtual Status OnFlushRequest(int input_stream_index); /// Validate if the stream at the specified index actually exists. virtual bool ValidateOutputStreamIndex(int stream_index) const; @@ -170,6 +170,9 @@ class MediaHandler { return Dispatch(std::move(stream_data)); } + /// Flush the downstream connected at the specified output stream index. + Status FlushDownstream(int output_stream_index); + int num_input_streams() const { return num_input_streams_; } int next_output_stream_index() const { return next_output_stream_index_; } const std::map, int>>& diff --git a/packager/media/base/media_handler_test_base.cc b/packager/media/base/media_handler_test_base.cc index 0f843324ad..79cf1092ce 100644 --- a/packager/media/base/media_handler_test_base.cc +++ b/packager/media/base/media_handler_test_base.cc @@ -73,7 +73,7 @@ class FakeMediaHandler : public MediaHandler { stream_data_vector_.push_back(std::move(stream_data)); return Status::OK; } - Status FlushStream(int input_stream_index) override { return Status::OK; } + Status OnFlushRequest(int input_stream_index) override { return Status::OK; } bool ValidateOutputStreamIndex(int stream_index) const override { return true; } diff --git a/packager/media/base/muxer.h b/packager/media/base/muxer.h index 9811b3c169..0aa1dcd6a5 100644 --- a/packager/media/base/muxer.h +++ b/packager/media/base/muxer.h @@ -97,7 +97,7 @@ class Muxer : public MediaHandler { /// @{ Status InitializeInternal() override { return Status::OK; } Status Process(std::unique_ptr stream_data) override; - Status FlushStream(int input_stream_index) override { return Finalize(); } + Status OnFlushRequest(int input_stream_index) override { return Finalize(); } /// @} const MuxerOptions& options() const { return options_; } diff --git a/packager/media/chunking/chunking_handler.cc b/packager/media/chunking/chunking_handler.cc index 9ee98599c1..247a52abb1 100644 --- a/packager/media/chunking/chunking_handler.cc +++ b/packager/media/chunking/chunking_handler.cc @@ -111,7 +111,7 @@ Status ChunkingHandler::Process(std::unique_ptr stream_data) { return Dispatch(std::move(stream_data)); } -Status ChunkingHandler::FlushStream(int input_stream_index) { +Status ChunkingHandler::OnFlushRequest(int input_stream_index) { if (segment_info_[input_stream_index]) { Status status; if (input_stream_index != main_stream_index_) { @@ -128,7 +128,8 @@ Status ChunkingHandler::FlushStream(int input_stream_index) { return status; } } - return MediaHandler::FlushStream(input_stream_index); + const int output_stream_index = input_stream_index; + return FlushDownstream(output_stream_index); } Status ChunkingHandler::ProcessMediaSample(const MediaSample* sample) { diff --git a/packager/media/chunking/chunking_handler.h b/packager/media/chunking/chunking_handler.h index 4db1d74dad..67841efbfd 100644 --- a/packager/media/chunking/chunking_handler.h +++ b/packager/media/chunking/chunking_handler.h @@ -68,7 +68,7 @@ class ChunkingHandler : public MediaHandler { /// @{ Status InitializeInternal() override; Status Process(std::unique_ptr stream_data) override; - Status FlushStream(int input_stream_index) override; + Status OnFlushRequest(int input_stream_index) override; /// @} private: diff --git a/packager/media/chunking/chunking_handler_unittest.cc b/packager/media/chunking/chunking_handler_unittest.cc index 67d92c6977..608b546300 100644 --- a/packager/media/chunking/chunking_handler_unittest.cc +++ b/packager/media/chunking/chunking_handler_unittest.cc @@ -43,8 +43,8 @@ class ChunkingHandlerTest : public MediaHandlerTestBase { return chunking_handler_->Process(std::move(stream_data)); } - Status FlushStream(int stream_index) { - return chunking_handler_->FlushStream(stream_index); + Status OnFlushRequest(int stream_index) { + return chunking_handler_->OnFlushRequest(stream_index); } protected: @@ -80,7 +80,7 @@ TEST_F(ChunkingHandlerTest, AudioNoSubsegmentsThenFlush) { } ClearOutputStreamDataVector(); - ASSERT_OK(FlushStream(kStreamIndex0)); + ASSERT_OK(OnFlushRequest(kStreamIndex0)); EXPECT_THAT(GetOutputStreamDataVector(), ElementsAre(IsSegmentInfo(kStreamIndex0, kDuration1 * 3, kDuration1 * 2, !kIsSubsegment))); @@ -210,7 +210,7 @@ TEST_F(ChunkingHandlerTest, AudioAndVideo) { kDuration1))); ClearOutputStreamDataVector(); - ASSERT_OK(FlushStream(kStreamIndex0)); + ASSERT_OK(OnFlushRequest(kStreamIndex0)); EXPECT_THAT( GetOutputStreamDataVector(), ElementsAre( @@ -220,7 +220,7 @@ TEST_F(ChunkingHandlerTest, AudioAndVideo) { kDuration0 * 3, !kIsSubsegment))); ClearOutputStreamDataVector(); - ASSERT_OK(FlushStream(kStreamIndex1)); + ASSERT_OK(OnFlushRequest(kStreamIndex1)); EXPECT_THAT(GetOutputStreamDataVector(), ElementsAre(IsSegmentInfo(kStreamIndex1, kVideoStartTimestamp + kDuration1 * 3, @@ -228,8 +228,8 @@ TEST_F(ChunkingHandlerTest, AudioAndVideo) { // Flush again will do nothing. ClearOutputStreamDataVector(); - ASSERT_OK(FlushStream(kStreamIndex0)); - ASSERT_OK(FlushStream(kStreamIndex1)); + ASSERT_OK(OnFlushRequest(kStreamIndex0)); + ASSERT_OK(OnFlushRequest(kStreamIndex1)); EXPECT_THAT(GetOutputStreamDataVector(), IsEmpty()); }