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/webm/webm_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  transport_stream_timestamp_offset_ms_(
24  packaging_params.transport_stream_timestamp_offset_ms),
25  temp_dir_(packaging_params.temp_dir) {}
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_AC3:
44  case CONTAINER_EAC3:
45  muxer = std::make_shared<PackedAudioWriter>(options);
46  break;
47  case CONTAINER_WEBM:
48  muxer = std::make_shared<webm::WebMMuxer>(options);
49  break;
50  case CONTAINER_MPEG2TS:
51  muxer = std::make_shared<mp2t::TsMuxer>(options);
52  break;
53  case CONTAINER_MOV:
54  muxer = std::make_shared<mp4::MP4Muxer>(options);
55  break;
56  default:
57  LOG(ERROR) << "Cannot support muxing to " << output_format;
58  break;
59  }
60 
61  if (!muxer) {
62  return nullptr;
63  }
64 
65  // We successfully created a muxer, then there is a couple settings
66  // we should set before returning it.
67  if (clock_) {
68  muxer->set_clock(clock_);
69  }
70 
71  return muxer;
72 }
73 
74 void MuxerFactory::OverrideClock(base::Clock* clock) {
75  clock_ = clock;
76 }
77 } // namespace media
78 } // namespace shaka
Defines a single input/output stream.
Definition: packager.h:73
std::string segment_template
Specifies segment template. Can be empty.
Definition: packager.h:85
All the methods that are virtual are virtual for mocking.
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:20
std::shared_ptr< Muxer > CreateMuxer(MediaContainerName output_format, const StreamDescriptor &stream)
Mp4OutputParams mp4_params
MP4 (ISO-BMFF) specific parameters.
Definition: muxer_options.h:25
std::string output
Definition: packager.h:83
void OverrideClock(base::Clock *clock)
std::string temp_dir
Specify temporary directory for intermediate files.
Definition: muxer_options.h:43