diff --git a/packager/media/ad_cue_generator/ad_cue_generator.cc b/packager/media/ad_cue_generator/ad_cue_generator.cc index 2f19c86ec2..c46e7328d8 100644 --- a/packager/media/ad_cue_generator/ad_cue_generator.cc +++ b/packager/media/ad_cue_generator/ad_cue_generator.cc @@ -9,11 +9,33 @@ namespace shaka { namespace media { +namespace { + +// The AdCuGenerator only supports single input and single output. +const size_t kStreamIndex = 0; + +} // namespace + AdCueGenerator::AdCueGenerator( const AdCueGeneratorParams& ad_cue_generator_params) : ad_cue_generator_params_(ad_cue_generator_params) {} AdCueGenerator::~AdCueGenerator() {} +Status AdCueGenerator::InitializeInternal() { + return Status::OK; +} + +Status AdCueGenerator::Process(std::unique_ptr stream_data) { + switch (stream_data->stream_data_type) { + case StreamDataType::kStreamInfo: + // TODO(kdevarakonda): dispatch scte35 events. + return DispatchStreamInfo(kStreamIndex, + std::move(stream_data->stream_info)); + default: + return Dispatch(std::move(stream_data)); + } +} + } // namespace media } // namespace shaka diff --git a/packager/media/ad_cue_generator/ad_cue_generator.h b/packager/media/ad_cue_generator/ad_cue_generator.h index afbe86f8ea..59d05c2875 100644 --- a/packager/media/ad_cue_generator/ad_cue_generator.h +++ b/packager/media/ad_cue_generator/ad_cue_generator.h @@ -23,6 +23,9 @@ class AdCueGenerator : public MediaHandler { AdCueGenerator(const AdCueGenerator&) = delete; AdCueGenerator& operator=(const AdCueGenerator&) = delete; + Status InitializeInternal() override; + Status Process(std::unique_ptr stream_data) override; + const AdCueGeneratorParams ad_cue_generator_params_; }; diff --git a/packager/packager.cc b/packager/packager.cc index fb121da173..8a26b0615e 100644 --- a/packager/packager.cc +++ b/packager/packager.cc @@ -21,6 +21,7 @@ #include "packager/file/file.h" #include "packager/hls/base/hls_notifier.h" #include "packager/hls/base/simple_hls_notifier.h" +#include "packager/media/ad_cue_generator/ad_cue_generator.h" #include "packager/media/base/container_names.h" #include "packager/media/base/fourccs.h" #include "packager/media/base/key_source.h" @@ -495,6 +496,8 @@ Status CreateAudioVideoJobs( // Demuxers are shared among all streams with the same input. std::shared_ptr demuxer; + // AdCueGenerator is shared among all streams. + std::shared_ptr ad_cue_generator; // Replicators are shared among all streams with the same input and stream // selector. std::shared_ptr replicator; @@ -506,6 +509,11 @@ Status CreateAudioVideoJobs( // iteration. int stream_number = first_stream_number - 1; + if (!packaging_params.ad_cue_generator_params.cue_points.empty()) { + ad_cue_generator = std::make_shared( + packaging_params.ad_cue_generator_params); + } + for (const StreamDescriptor& stream : streams) { stream_number += 1; @@ -555,16 +563,17 @@ Status CreateAudioVideoJobs( packaging_params, stream, encryption_key_source); Status status; - - // The path is different if there is encryption. Even though there are - // common elements, it is easier to understand the path if they are - // expressed independently of each other. - if (encryptor) { + if (ad_cue_generator) { + status.Update( + demuxer->SetHandler(stream.stream_selector, ad_cue_generator)); + status.Update(ad_cue_generator->AddHandler(chunker)); + } else { status.Update(demuxer->SetHandler(stream.stream_selector, chunker)); + } + if (encryptor) { status.Update(chunker->AddHandler(encryptor)); status.Update(encryptor->AddHandler(replicator)); } else { - status.Update(demuxer->SetHandler(stream.stream_selector, chunker)); status.Update(chunker->AddHandler(replicator)); } diff --git a/packager/packager.gyp b/packager/packager.gyp index aa1f67c5ad..467ec3d94b 100644 --- a/packager/packager.gyp +++ b/packager/packager.gyp @@ -24,8 +24,10 @@ 'dependencies': [ 'file/file.gyp:file', 'hls/hls.gyp:hls_builder', + 'media/ad_cue_generator/ad_cue_generator.gyp:ad_cue_generator', 'media/chunking/chunking.gyp:chunking', 'media/codecs/codecs.gyp:codecs', + 'media/crypto/crypto.gyp:crypto', 'media/demuxer/demuxer.gyp:demuxer', 'media/event/media_event.gyp:media_event', 'media/formats/mp2t/mp2t.gyp:mp2t',