7 #include "packager/media/base/muxer.h" 11 #include "packager/media/base/media_sample.h" 16 const bool kInitialEncryptionInfo =
true;
19 Muxer::Muxer(
const MuxerOptions& options)
20 : options_(options), cancelled_(false), clock_(NULL) {}
29 muxer_listener_ = std::move(muxer_listener);
33 std::unique_ptr<ProgressListener> progress_listener) {
34 progress_listener_ = std::move(progress_listener);
39 switch (stream_data->stream_data_type) {
40 case StreamDataType::kStreamInfo:
41 streams_.push_back(std::move(stream_data->stream_info));
42 if (muxer_listener_ && streams_.back()->is_encrypted()) {
44 streams_.back()->encryption_config();
45 muxer_listener_->OnEncryptionInfoReady(
46 kInitialEncryptionInfo, encryption_config.protection_scheme,
47 encryption_config.key_id, encryption_config.constant_iv,
48 encryption_config.key_system_info);
49 current_key_id_ = encryption_config.key_id;
51 return InitializeMuxer();
52 case StreamDataType::kSegmentInfo: {
53 const auto& segment_info = *stream_data->segment_info;
54 if (muxer_listener_ && segment_info.is_encrypted) {
56 segment_info.key_rotation_encryption_config.get();
58 if (encryption_config && encryption_config->key_id != current_key_id_) {
59 muxer_listener_->OnEncryptionInfoReady(
60 !kInitialEncryptionInfo, encryption_config->protection_scheme,
61 encryption_config->key_id, encryption_config->constant_iv,
62 encryption_config->key_system_info);
63 current_key_id_ = encryption_config->key_id;
65 if (!encryption_started_) {
66 encryption_started_ =
true;
67 muxer_listener_->OnEncryptionStart();
70 return FinalizeSegment(stream_data->stream_index, segment_info);
72 case StreamDataType::kMediaSample:
73 return AddSample(stream_data->stream_index, *stream_data->media_sample);
74 case StreamDataType::kCueEvent:
75 if (muxer_listener_) {
76 const int64_t time_scale =
77 streams_[stream_data->stream_index]->time_scale();
78 const double time_in_seconds = stream_data->cue_event->time_in_seconds;
79 const int64_t scaled_time =
80 static_cast<int64_t
>(time_in_seconds * time_scale);
81 muxer_listener_->OnCueEvent(scaled_time,
82 stream_data->cue_event->cue_data);
86 VLOG(3) <<
"Stream data type " 87 <<
static_cast<int>(stream_data->stream_data_type) <<
" ignored.";
All the methods that are virtual are virtual for mocking.