DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
muxer.cc
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #include "packager/media/base/muxer.h"
8 
9 #include <algorithm>
10 
11 #include "packager/media/base/media_sample.h"
12 
13 namespace shaka {
14 namespace media {
15 namespace {
16 const bool kInitialEncryptionInfo = true;
17 } // namespace
18 
19 Muxer::Muxer(const MuxerOptions& options)
20  : options_(options), cancelled_(false), clock_(NULL) {}
21 
22 Muxer::~Muxer() {}
23 
24 void Muxer::Cancel() {
25  cancelled_ = true;
26 }
27 
28 void Muxer::SetMuxerListener(std::unique_ptr<MuxerListener> muxer_listener) {
29  muxer_listener_ = std::move(muxer_listener);
30 }
31 
33  std::unique_ptr<ProgressListener> progress_listener) {
34  progress_listener_ = std::move(progress_listener);
35 }
36 
37 Status Muxer::Process(std::unique_ptr<StreamData> stream_data) {
38  Status status;
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()) {
43  const EncryptionConfig& encryption_config =
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  }
50  return InitializeMuxer();
51  case StreamDataType::kSegmentInfo: {
52  auto& segment_info = stream_data->segment_info;
53  if (muxer_listener_) {
54  const EncryptionConfig* encryption_config =
55  segment_info->key_rotation_encryption_config.get();
56  if (encryption_config) {
57  muxer_listener_->OnEncryptionInfoReady(
58  !kInitialEncryptionInfo, encryption_config->protection_scheme,
59  encryption_config->key_id, encryption_config->constant_iv,
60  encryption_config->key_system_info);
61  }
62  if (segment_info->is_encrypted && !encryption_started_) {
63  encryption_started_ = true;
64  muxer_listener_->OnEncryptionStart();
65  }
66  }
67  return FinalizeSegment(stream_data->stream_index,
68  std::move(segment_info));
69  }
70  case StreamDataType::kMediaSample:
71  return AddSample(stream_data->stream_index,
72  std::move(stream_data->media_sample));
73  default:
74  VLOG(3) << "Stream data type "
75  << static_cast<int>(stream_data->stream_data_type) << " ignored.";
76  break;
77  }
78  // No dispatch for muxer.
79  return Status::OK;
80 }
81 
82 } // namespace media
83 } // namespace shaka
void SetProgressListener(std::unique_ptr< ProgressListener > progress_listener)
Definition: muxer.cc:32
Status Process(std::unique_ptr< StreamData > stream_data) override
Definition: muxer.cc:37
void SetMuxerListener(std::unique_ptr< MuxerListener > muxer_listener)
Definition: muxer.cc:28