Consolidate ChunkingParams and ChunkingOptions

Change-Id: Ibbb85981d2b424432b61ca693e28334ef00d475e
This commit is contained in:
KongQun Yang 2017-07-27 10:23:27 -07:00
parent c7c201b00c
commit 9eaf1dcae0
8 changed files with 67 additions and 86 deletions

View File

@ -171,18 +171,6 @@ std::unique_ptr<KeySource> CreateDecryptionKeySource(
return decryption_key_source; return decryption_key_source;
} }
ChunkingOptions GetChunkingOptions(const ChunkingParams& chunking_params) {
ChunkingOptions chunking_options;
chunking_options.segment_duration_in_seconds =
chunking_params.segment_duration_in_seconds;
chunking_options.subsegment_duration_in_seconds =
chunking_params.subsegment_duration_in_seconds;
chunking_options.segment_sap_aligned = chunking_params.segment_sap_aligned;
chunking_options.subsegment_sap_aligned =
chunking_params.subsegment_sap_aligned;
return chunking_options;
}
MuxerOptions GetMuxerOptions(const std::string& temp_dir, MuxerOptions GetMuxerOptions(const std::string& temp_dir,
const Mp4OutputParams& mp4_params) { const Mp4OutputParams& mp4_params) {
MuxerOptions muxer_options; MuxerOptions muxer_options;

View File

@ -50,9 +50,6 @@ std::unique_ptr<KeySource> CreateEncryptionKeySource(
std::unique_ptr<KeySource> CreateDecryptionKeySource( std::unique_ptr<KeySource> CreateDecryptionKeySource(
const DecryptionParams& decryption_params); const DecryptionParams& decryption_params);
/// @return ChunkingOptions from provided command line options.
ChunkingOptions GetChunkingOptions(const ChunkingParams& chunking_params);
/// @return MuxerOptions from provided command line options. /// @return MuxerOptions from provided command line options.
MuxerOptions GetMuxerOptions(const std::string& temp_dir, MuxerOptions GetMuxerOptions(const std::string& temp_dir,
const Mp4OutputParams& mp4_params); const Mp4OutputParams& mp4_params);

View File

@ -18,9 +18,9 @@ int64_t kTimeStampToDispatchAllSamples = -1;
namespace shaka { namespace shaka {
namespace media { namespace media {
ChunkingHandler::ChunkingHandler(const ChunkingOptions& chunking_options) ChunkingHandler::ChunkingHandler(const ChunkingParams& chunking_params)
: chunking_options_(chunking_options), thread_id_(kThreadIdUnset) { : chunking_params_(chunking_params), thread_id_(kThreadIdUnset) {
CHECK_NE(chunking_options.segment_duration_in_seconds, 0u); CHECK_NE(chunking_params.segment_duration_in_seconds, 0u);
} }
ChunkingHandler::~ChunkingHandler() {} ChunkingHandler::~ChunkingHandler() {}
@ -56,9 +56,9 @@ Status ChunkingHandler::Process(std::unique_ptr<StreamData> stream_data) {
if (is_main_stream) { if (is_main_stream) {
main_stream_index_ = stream_data->stream_index; main_stream_index_ = stream_data->stream_index;
segment_duration_ = segment_duration_ =
chunking_options_.segment_duration_in_seconds * time_scale; chunking_params_.segment_duration_in_seconds * time_scale;
subsegment_duration_ = subsegment_duration_ =
chunking_options_.subsegment_duration_in_seconds * time_scale; chunking_params_.subsegment_duration_in_seconds * time_scale;
} else if (stream_data->stream_info->stream_type() == kStreamVideo) { } else if (stream_data->stream_info->stream_type() == kStreamVideo) {
return Status(error::CHUNKING_ERROR, return Status(error::CHUNKING_ERROR,
"Only one video stream is allowed per chunking handler."); "Only one video stream is allowed per chunking handler.");
@ -138,7 +138,7 @@ Status ChunkingHandler::ProcessMediaSample(const MediaSample* sample) {
// Check if we need to terminate the current (sub)segment. // Check if we need to terminate the current (sub)segment.
bool new_segment = false; bool new_segment = false;
bool new_subsegment = false; bool new_subsegment = false;
if (is_key_frame || !chunking_options_.segment_sap_aligned) { if (is_key_frame || !chunking_params_.segment_sap_aligned) {
const int64_t segment_index = timestamp / segment_duration_; const int64_t segment_index = timestamp / segment_duration_;
if (segment_index != current_segment_index_) { if (segment_index != current_segment_index_) {
current_segment_index_ = segment_index; current_segment_index_ = segment_index;
@ -148,7 +148,7 @@ Status ChunkingHandler::ProcessMediaSample(const MediaSample* sample) {
} }
} }
if (!new_segment && subsegment_duration_ > 0 && if (!new_segment && subsegment_duration_ > 0 &&
(is_key_frame || !chunking_options_.subsegment_sap_aligned)) { (is_key_frame || !chunking_params_.subsegment_sap_aligned)) {
const int64_t subsegment_index = const int64_t subsegment_index =
(timestamp - segment_info_[main_stream_index_]->start_timestamp) / (timestamp - segment_info_[main_stream_index_]->start_timestamp) /
subsegment_duration_; subsegment_duration_;

View File

@ -10,30 +10,13 @@
#include <atomic> #include <atomic>
#include "packager/media/base/media_handler.h" #include "packager/media/base/media_handler.h"
#include "packager/media/public/chunking_params.h"
namespace shaka { namespace shaka {
namespace media { namespace media {
struct ChunkingOptions {
/// Segment duration in seconds.
double segment_duration_in_seconds = 0;
/// Subsegment duration in seconds. Should not be larger than the segment
/// duration.
double subsegment_duration_in_seconds = 0;
/// Force segments to begin with stream access points. Actual segment duration
/// may not be exactly what is specified by segment_duration.
bool segment_sap_aligned = true;
/// Force subsegments to begin with stream access points. Actual subsegment
/// duration may not be exactly what is specified by subsegment_duration.
/// Setting to true implies that segment_sap_aligned is true as well.
bool subsegment_sap_aligned = true;
};
/// ChunkingHandler splits the samples into segments / subsegments based on the /// ChunkingHandler splits the samples into segments / subsegments based on the
/// specified chunking options. /// specified chunking params.
/// This handler is a multi-in multi-out handler. If more than one input is /// This handler is a multi-in multi-out handler. If more than one input is
/// provided, there should be one and only one video stream; also, all inputs /// provided, there should be one and only one video stream; also, all inputs
/// should come from the same thread and are synchronized. /// should come from the same thread and are synchronized.
@ -60,7 +43,7 @@ struct ChunkingOptions {
/// are aligned. /// are aligned.
class ChunkingHandler : public MediaHandler { class ChunkingHandler : public MediaHandler {
public: public:
explicit ChunkingHandler(const ChunkingOptions& chunking_options); explicit ChunkingHandler(const ChunkingParams& chunking_params);
~ChunkingHandler() override; ~ChunkingHandler() override;
protected: protected:
@ -87,7 +70,7 @@ class ChunkingHandler : public MediaHandler {
Status DispatchSegmentInfoForAllStreams(); Status DispatchSegmentInfoForAllStreams();
Status DispatchSubsegmentInfoForAllStreams(); Status DispatchSubsegmentInfoForAllStreams();
const ChunkingOptions chunking_options_; const ChunkingParams chunking_params_;
// The inputs are expected to come from the same thread. // The inputs are expected to come from the same thread.
std::atomic<int64_t> thread_id_; std::atomic<int64_t> thread_id_;

View File

@ -33,8 +33,8 @@ const bool kEncrypted = true;
class ChunkingHandlerTest : public MediaHandlerTestBase { class ChunkingHandlerTest : public MediaHandlerTestBase {
public: public:
void SetUpChunkingHandler(int num_inputs, void SetUpChunkingHandler(int num_inputs,
const ChunkingOptions& chunking_options) { const ChunkingParams& chunking_params) {
chunking_handler_.reset(new ChunkingHandler(chunking_options)); chunking_handler_.reset(new ChunkingHandler(chunking_params));
SetUpGraph(num_inputs, num_inputs, chunking_handler_); SetUpGraph(num_inputs, num_inputs, chunking_handler_);
ASSERT_OK(chunking_handler_->Initialize()); ASSERT_OK(chunking_handler_->Initialize());
} }
@ -52,9 +52,9 @@ class ChunkingHandlerTest : public MediaHandlerTestBase {
}; };
TEST_F(ChunkingHandlerTest, AudioNoSubsegmentsThenFlush) { TEST_F(ChunkingHandlerTest, AudioNoSubsegmentsThenFlush) {
ChunkingOptions chunking_options; ChunkingParams chunking_params;
chunking_options.segment_duration_in_seconds = 1; chunking_params.segment_duration_in_seconds = 1;
SetUpChunkingHandler(1, chunking_options); SetUpChunkingHandler(1, chunking_params);
ASSERT_OK(Process(GetAudioStreamInfoStreamData(kStreamIndex0, kTimeScale0))); ASSERT_OK(Process(GetAudioStreamInfoStreamData(kStreamIndex0, kTimeScale0)));
EXPECT_THAT( EXPECT_THAT(
@ -88,10 +88,10 @@ TEST_F(ChunkingHandlerTest, AudioNoSubsegmentsThenFlush) {
} }
TEST_F(ChunkingHandlerTest, AudioWithSubsegments) { TEST_F(ChunkingHandlerTest, AudioWithSubsegments) {
ChunkingOptions chunking_options; ChunkingParams chunking_params;
chunking_options.segment_duration_in_seconds = 1; chunking_params.segment_duration_in_seconds = 1;
chunking_options.subsegment_duration_in_seconds = 0.5; chunking_params.subsegment_duration_in_seconds = 0.5;
SetUpChunkingHandler(1, chunking_options); SetUpChunkingHandler(1, chunking_params);
ASSERT_OK(Process(GetAudioStreamInfoStreamData(kStreamIndex0, kTimeScale0))); ASSERT_OK(Process(GetAudioStreamInfoStreamData(kStreamIndex0, kTimeScale0)));
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
@ -115,10 +115,10 @@ TEST_F(ChunkingHandlerTest, AudioWithSubsegments) {
} }
TEST_F(ChunkingHandlerTest, VideoAndSubsegmentAndNonzeroStart) { TEST_F(ChunkingHandlerTest, VideoAndSubsegmentAndNonzeroStart) {
ChunkingOptions chunking_options; ChunkingParams chunking_params;
chunking_options.segment_duration_in_seconds = 1; chunking_params.segment_duration_in_seconds = 1;
chunking_options.subsegment_duration_in_seconds = 0.3; chunking_params.subsegment_duration_in_seconds = 0.3;
SetUpChunkingHandler(1, chunking_options); SetUpChunkingHandler(1, chunking_params);
ASSERT_OK(Process(GetVideoStreamInfoStreamData(kStreamIndex0, kTimeScale1))); ASSERT_OK(Process(GetVideoStreamInfoStreamData(kStreamIndex0, kTimeScale1)));
const int64_t kVideoStartTimestamp = 12345; const int64_t kVideoStartTimestamp = 12345;
@ -154,10 +154,10 @@ TEST_F(ChunkingHandlerTest, VideoAndSubsegmentAndNonzeroStart) {
} }
TEST_F(ChunkingHandlerTest, AudioAndVideo) { TEST_F(ChunkingHandlerTest, AudioAndVideo) {
ChunkingOptions chunking_options; ChunkingParams chunking_params;
chunking_options.segment_duration_in_seconds = 1; chunking_params.segment_duration_in_seconds = 1;
chunking_options.subsegment_duration_in_seconds = 0.3; chunking_params.subsegment_duration_in_seconds = 0.3;
SetUpChunkingHandler(2, chunking_options); SetUpChunkingHandler(2, chunking_params);
ASSERT_OK(Process(GetAudioStreamInfoStreamData(kStreamIndex0, kTimeScale0))); ASSERT_OK(Process(GetAudioStreamInfoStreamData(kStreamIndex0, kTimeScale0)));
ASSERT_OK(Process(GetVideoStreamInfoStreamData(kStreamIndex1, kTimeScale1))); ASSERT_OK(Process(GetVideoStreamInfoStreamData(kStreamIndex1, kTimeScale1)));

View File

@ -0,0 +1,32 @@
// 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_MEDIA_PUBLIC_CHUNKING_PARAMS_H_
#define PACKAGER_MEDIA_PUBLIC_CHUNKING_PARAMS_H_
namespace shaka {
/// Chunking (segmentation) related parameters.
struct ChunkingParams {
/// Segment duration in seconds.
double segment_duration_in_seconds = 0;
/// Subsegment duration in seconds. Should not be larger than the segment
/// duration.
double subsegment_duration_in_seconds = 0;
/// Force segments to begin with stream access points. Actual segment duration
/// may not be exactly what is specified by segment_duration.
bool segment_sap_aligned = true;
/// Force subsegments to begin with stream access points. Actual subsegment
/// duration may not be exactly what is specified by subsegment_duration.
/// Setting to subsegment_sap_aligned to true but segment_sap_aligned to false
/// is not allowed.
bool subsegment_sap_aligned = true;
};
} // namespace shaka
#endif // PACKAGER_MEDIA_PUBLIC_CHUNKING_PARAMS_H_

View File

@ -315,7 +315,6 @@ std::shared_ptr<Muxer> CreateOutputMuxer(const MuxerOptions& options,
bool CreateRemuxJobs(const StreamDescriptorList& stream_descriptors, bool CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
const PackagingParams& packaging_params, const PackagingParams& packaging_params,
const ChunkingOptions& chunking_options,
const MuxerOptions& muxer_options, const MuxerOptions& muxer_options,
FakeClock* fake_clock, FakeClock* fake_clock,
KeySource* encryption_key_source, KeySource* encryption_key_source,
@ -466,7 +465,8 @@ bool CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
std::vector<std::shared_ptr<MediaHandler>> handlers; std::vector<std::shared_ptr<MediaHandler>> handlers;
auto chunking_handler = std::make_shared<ChunkingHandler>(chunking_options); auto chunking_handler =
std::make_shared<ChunkingHandler>(packaging_params.chunking_params);
handlers.push_back(chunking_handler); handlers.push_back(chunking_handler);
Status status; Status status;
@ -583,8 +583,6 @@ Status Packager::Initialize(
std::unique_ptr<PackagerInternal> internal(new PackagerInternal); std::unique_ptr<PackagerInternal> internal(new PackagerInternal);
ChunkingOptions chunking_options =
media::GetChunkingOptions(packaging_params.chunking_params);
MuxerOptions muxer_options = media::GetMuxerOptions( MuxerOptions muxer_options = media::GetMuxerOptions(
packaging_params.temp_dir, packaging_params.mp4_output_params); packaging_params.temp_dir, packaging_params.mp4_output_params);
@ -636,10 +634,10 @@ Status Packager::Initialize(
for (const StreamDescriptor& descriptor : stream_descriptors) for (const StreamDescriptor& descriptor : stream_descriptors)
stream_descriptor_list.insert(descriptor); stream_descriptor_list.insert(descriptor);
if (!media::CreateRemuxJobs( if (!media::CreateRemuxJobs(
stream_descriptor_list, packaging_params, chunking_options, stream_descriptor_list, packaging_params, muxer_options,
muxer_options, &internal->fake_clock, &internal->fake_clock, internal->encryption_key_source.get(),
internal->encryption_key_source.get(), internal->mpd_notifier.get(), internal->mpd_notifier.get(), internal->hls_notifier.get(),
internal->hls_notifier.get(), &internal->jobs)) { &internal->jobs)) {
return Status(error::INVALID_ARGUMENT, "Failed to create remux jobs."); return Status(error::INVALID_ARGUMENT, "Failed to create remux jobs.");
} }
internal_ = std::move(internal); internal_ = std::move(internal);

View File

@ -12,6 +12,7 @@
#include <vector> #include <vector>
#include "packager/hls/public/hls_playlist_type.h" #include "packager/hls/public/hls_playlist_type.h"
#include "packager/media/public/chunking_params.h"
#include "packager/media/public/crypto_params.h" #include "packager/media/public/crypto_params.h"
#include "packager/status.h" #include "packager/status.h"
@ -39,24 +40,6 @@ struct Mp4OutputParams {
bool use_decoding_timestamp_in_timeline = false; bool use_decoding_timestamp_in_timeline = false;
}; };
/// Chunking (segmentation) related parameters.
struct ChunkingParams {
/// Segment duration in seconds.
double segment_duration_in_seconds = 0;
/// Subsegment duration in seconds. Should not be larger than the segment
/// duration.
double subsegment_duration_in_seconds = 0;
/// Force segments to begin with stream access points. Actual segment duration
/// may not be exactly what is specified by segment_duration.
bool segment_sap_aligned = true;
/// Force subsegments to begin with stream access points. Actual subsegment
/// duration may not be exactly what is specified by subsegment_duration.
/// Setting to subsegment_sap_aligned to true but segment_sap_aligned to false
/// is not allowed.
bool subsegment_sap_aligned = true;
};
/// DASH MPD related parameters. /// DASH MPD related parameters.
struct MpdParams { struct MpdParams {
/// MPD output file path. /// MPD output file path.