Shaka Packager SDK
muxer_factory.cc
1 // Copyright 2017 Google LLC. 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/app/muxer_factory.h>
8 
9 #include <packager/media/base/muxer.h>
10 #include <packager/media/formats/mp2t/ts_muxer.h>
11 #include <packager/media/formats/mp4/mp4_muxer.h>
12 #include <packager/media/formats/packed_audio/packed_audio_writer.h>
13 #include <packager/media/formats/ttml/ttml_muxer.h>
14 #include <packager/media/formats/webm/webm_muxer.h>
15 #include <packager/media/formats/webvtt/webvtt_muxer.h>
16 #include <packager/packager.h>
17 
18 namespace shaka {
19 namespace media {
20 
21 MuxerFactory::MuxerFactory(const PackagingParams& packaging_params)
22  : mp4_params_(packaging_params.mp4_output_params),
23  temp_dir_(packaging_params.temp_dir),
24  transport_stream_timestamp_offset_ms_(
25  packaging_params.transport_stream_timestamp_offset_ms) {}
26 
27 std::shared_ptr<Muxer> MuxerFactory::CreateMuxer(
28  MediaContainerName output_format,
29  const StreamDescriptor& stream) {
30  MuxerOptions options;
31  options.mp4_params = mp4_params_;
32  options.transport_stream_timestamp_offset_ms =
33  transport_stream_timestamp_offset_ms_;
34  options.temp_dir = temp_dir_;
35  options.output_file_name = stream.output;
36  options.segment_template = stream.segment_template;
37  options.bandwidth = stream.bandwidth;
38 
39  std::shared_ptr<Muxer> muxer;
40 
41  switch (output_format) {
42  case CONTAINER_AAC:
43  case CONTAINER_MP3:
44  case CONTAINER_AC3:
45  case CONTAINER_EAC3:
46  muxer = std::make_shared<PackedAudioWriter>(options);
47  break;
48  case CONTAINER_WEBM:
49  muxer = std::make_shared<webm::WebMMuxer>(options);
50  break;
51  case CONTAINER_TTML:
52  muxer = std::make_shared<ttml::TtmlMuxer>(options);
53  break;
54  case CONTAINER_WEBVTT:
55  muxer = std::make_shared<webvtt::WebVttMuxer>(options);
56  break;
57  case CONTAINER_MPEG2TS:
58  muxer = std::make_shared<mp2t::TsMuxer>(options);
59  break;
60  case CONTAINER_MOV:
61  muxer = std::make_shared<mp4::MP4Muxer>(options);
62  break;
63  default:
64  LOG(ERROR) << "Cannot support muxing to " << output_format;
65  break;
66  }
67 
68  if (!muxer) {
69  return nullptr;
70  }
71 
72  // We successfully created a muxer, then there is a couple settings
73  // we should set before returning it.
74  if (clock_) {
75  muxer->set_clock(clock_);
76  }
77 
78  return muxer;
79 }
80 
81 void MuxerFactory::OverrideClock(std::shared_ptr<Clock> clock) {
82  clock_ = clock;
83 }
84 } // namespace media
85 } // namespace shaka
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:19
std::string temp_dir
Specify temporary directory for intermediate files.
Definition: muxer_options.h:42
Mp4OutputParams mp4_params
MP4 (ISO-BMFF) specific parameters.
Definition: muxer_options.h:24