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