Rename FlushStream to OnFlushRequest; add FlushOutput
Change-Id: I2b37030b0c35aa34e9c72e43825f157924034227
This commit is contained in:
parent
8f2cd6da91
commit
c6cbd73465
|
@ -107,7 +107,7 @@ Status Demuxer::Run() {
|
||||||
|
|
||||||
if (status.error_code() == error::END_OF_STREAM) {
|
if (status.error_code() == error::END_OF_STREAM) {
|
||||||
for (int stream_index : stream_indexes_) {
|
for (int stream_index : stream_indexes_) {
|
||||||
status = FlushStream(stream_index);
|
status = FlushDownstream(stream_index);
|
||||||
if (!status.ok())
|
if (!status.ok())
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,15 +38,11 @@ Status MediaHandler::Initialize() {
|
||||||
return Status::OK;
|
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
|
// The default implementation treats the output stream index to be identical
|
||||||
// to the input stream index, which is true for most handlers.
|
// to the input stream index, which is true for most handlers.
|
||||||
auto handler_it = output_handlers_.find(input_stream_index);
|
const int output_stream_index = input_stream_index;
|
||||||
if (handler_it == output_handlers_.end()) {
|
return FlushDownstream(output_stream_index);
|
||||||
return Status(error::NOT_FOUND,
|
|
||||||
"No output handler exist at the specified index.");
|
|
||||||
}
|
|
||||||
return handler_it->second.first->FlushStream(handler_it->second.second);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MediaHandler::ValidateOutputStreamIndex(int stream_index) const {
|
bool MediaHandler::ValidateOutputStreamIndex(int stream_index) const {
|
||||||
|
@ -64,5 +60,14 @@ Status MediaHandler::Dispatch(std::unique_ptr<StreamData> stream_data) {
|
||||||
return handler_it->second.first->Process(std::move(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 media
|
||||||
} // namespace shaka
|
} // namespace shaka
|
||||||
|
|
|
@ -96,8 +96,8 @@ class MediaHandler {
|
||||||
/// handlers after finishing processing if needed.
|
/// handlers after finishing processing if needed.
|
||||||
virtual Status Process(std::unique_ptr<StreamData> stream_data) = 0;
|
virtual Status Process(std::unique_ptr<StreamData> stream_data) = 0;
|
||||||
|
|
||||||
/// Flush the stream at the specified input stream index.
|
/// Event handler for flush request at the specific input stream index.
|
||||||
virtual Status FlushStream(int input_stream_index);
|
virtual Status OnFlushRequest(int input_stream_index);
|
||||||
|
|
||||||
/// Validate if the stream at the specified index actually exists.
|
/// Validate if the stream at the specified index actually exists.
|
||||||
virtual bool ValidateOutputStreamIndex(int stream_index) const;
|
virtual bool ValidateOutputStreamIndex(int stream_index) const;
|
||||||
|
@ -170,6 +170,9 @@ class MediaHandler {
|
||||||
return Dispatch(std::move(stream_data));
|
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 num_input_streams() const { return num_input_streams_; }
|
||||||
int next_output_stream_index() const { return next_output_stream_index_; }
|
int next_output_stream_index() const { return next_output_stream_index_; }
|
||||||
const std::map<int, std::pair<std::shared_ptr<MediaHandler>, int>>&
|
const std::map<int, std::pair<std::shared_ptr<MediaHandler>, int>>&
|
||||||
|
|
|
@ -73,7 +73,7 @@ class FakeMediaHandler : public MediaHandler {
|
||||||
stream_data_vector_.push_back(std::move(stream_data));
|
stream_data_vector_.push_back(std::move(stream_data));
|
||||||
return Status::OK;
|
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 {
|
bool ValidateOutputStreamIndex(int stream_index) const override {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ class Muxer : public MediaHandler {
|
||||||
/// @{
|
/// @{
|
||||||
Status InitializeInternal() override { return Status::OK; }
|
Status InitializeInternal() override { return Status::OK; }
|
||||||
Status Process(std::unique_ptr<StreamData> stream_data) override;
|
Status Process(std::unique_ptr<StreamData> 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_; }
|
const MuxerOptions& options() const { return options_; }
|
||||||
|
|
|
@ -111,7 +111,7 @@ Status ChunkingHandler::Process(std::unique_ptr<StreamData> stream_data) {
|
||||||
return Dispatch(std::move(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]) {
|
if (segment_info_[input_stream_index]) {
|
||||||
Status status;
|
Status status;
|
||||||
if (input_stream_index != main_stream_index_) {
|
if (input_stream_index != main_stream_index_) {
|
||||||
|
@ -128,7 +128,8 @@ Status ChunkingHandler::FlushStream(int input_stream_index) {
|
||||||
return status;
|
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) {
|
Status ChunkingHandler::ProcessMediaSample(const MediaSample* sample) {
|
||||||
|
|
|
@ -68,7 +68,7 @@ class ChunkingHandler : public MediaHandler {
|
||||||
/// @{
|
/// @{
|
||||||
Status InitializeInternal() override;
|
Status InitializeInternal() override;
|
||||||
Status Process(std::unique_ptr<StreamData> stream_data) override;
|
Status Process(std::unique_ptr<StreamData> stream_data) override;
|
||||||
Status FlushStream(int input_stream_index) override;
|
Status OnFlushRequest(int input_stream_index) override;
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -43,8 +43,8 @@ class ChunkingHandlerTest : public MediaHandlerTestBase {
|
||||||
return chunking_handler_->Process(std::move(stream_data));
|
return chunking_handler_->Process(std::move(stream_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
Status FlushStream(int stream_index) {
|
Status OnFlushRequest(int stream_index) {
|
||||||
return chunking_handler_->FlushStream(stream_index);
|
return chunking_handler_->OnFlushRequest(stream_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -80,7 +80,7 @@ TEST_F(ChunkingHandlerTest, AudioNoSubsegmentsThenFlush) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ClearOutputStreamDataVector();
|
ClearOutputStreamDataVector();
|
||||||
ASSERT_OK(FlushStream(kStreamIndex0));
|
ASSERT_OK(OnFlushRequest(kStreamIndex0));
|
||||||
EXPECT_THAT(GetOutputStreamDataVector(),
|
EXPECT_THAT(GetOutputStreamDataVector(),
|
||||||
ElementsAre(IsSegmentInfo(kStreamIndex0, kDuration1 * 3,
|
ElementsAre(IsSegmentInfo(kStreamIndex0, kDuration1 * 3,
|
||||||
kDuration1 * 2, !kIsSubsegment)));
|
kDuration1 * 2, !kIsSubsegment)));
|
||||||
|
@ -210,7 +210,7 @@ TEST_F(ChunkingHandlerTest, AudioAndVideo) {
|
||||||
kDuration1)));
|
kDuration1)));
|
||||||
|
|
||||||
ClearOutputStreamDataVector();
|
ClearOutputStreamDataVector();
|
||||||
ASSERT_OK(FlushStream(kStreamIndex0));
|
ASSERT_OK(OnFlushRequest(kStreamIndex0));
|
||||||
EXPECT_THAT(
|
EXPECT_THAT(
|
||||||
GetOutputStreamDataVector(),
|
GetOutputStreamDataVector(),
|
||||||
ElementsAre(
|
ElementsAre(
|
||||||
|
@ -220,7 +220,7 @@ TEST_F(ChunkingHandlerTest, AudioAndVideo) {
|
||||||
kDuration0 * 3, !kIsSubsegment)));
|
kDuration0 * 3, !kIsSubsegment)));
|
||||||
|
|
||||||
ClearOutputStreamDataVector();
|
ClearOutputStreamDataVector();
|
||||||
ASSERT_OK(FlushStream(kStreamIndex1));
|
ASSERT_OK(OnFlushRequest(kStreamIndex1));
|
||||||
EXPECT_THAT(GetOutputStreamDataVector(),
|
EXPECT_THAT(GetOutputStreamDataVector(),
|
||||||
ElementsAre(IsSegmentInfo(kStreamIndex1,
|
ElementsAre(IsSegmentInfo(kStreamIndex1,
|
||||||
kVideoStartTimestamp + kDuration1 * 3,
|
kVideoStartTimestamp + kDuration1 * 3,
|
||||||
|
@ -228,8 +228,8 @@ TEST_F(ChunkingHandlerTest, AudioAndVideo) {
|
||||||
|
|
||||||
// Flush again will do nothing.
|
// Flush again will do nothing.
|
||||||
ClearOutputStreamDataVector();
|
ClearOutputStreamDataVector();
|
||||||
ASSERT_OK(FlushStream(kStreamIndex0));
|
ASSERT_OK(OnFlushRequest(kStreamIndex0));
|
||||||
ASSERT_OK(FlushStream(kStreamIndex1));
|
ASSERT_OK(OnFlushRequest(kStreamIndex1));
|
||||||
EXPECT_THAT(GetOutputStreamDataVector(), IsEmpty());
|
EXPECT_THAT(GetOutputStreamDataVector(), IsEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue