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  temp_dir_(packaging_params.temp_dir) {}
24 
25 std::shared_ptr<Muxer> MuxerFactory::CreateMuxer(
26  MediaContainerName output_format,
27  const StreamDescriptor& stream) {
28  MuxerOptions options;
29  options.mp4_params = mp4_params_;
30  options.temp_dir = temp_dir_;
31  options.output_file_name = stream.output;
32  options.segment_template = stream.segment_template;
33  options.bandwidth = stream.bandwidth;
34 
35  std::shared_ptr<Muxer> muxer;
36 
37  switch (output_format) {
38  case CONTAINER_AAC:
39  case CONTAINER_AC3:
40  case CONTAINER_EAC3:
41  muxer = std::make_shared<PackedAudioWriter>(options);
42  break;
43  case CONTAINER_WEBM:
44  muxer = std::make_shared<webm::WebMMuxer>(options);
45  break;
46  case CONTAINER_MPEG2TS:
47  muxer = std::make_shared<mp2t::TsMuxer>(options);
48  break;
49  case CONTAINER_MOV:
50  muxer = std::make_shared<mp4::MP4Muxer>(options);
51  break;
52  default:
53  LOG(ERROR) << "Cannot support muxing to " << output_format;
54  break;
55  }
56 
57  if (!muxer) {
58  return nullptr;
59  }
60 
61  // We successfully created a muxer, then there is a couple settings
62  // we should set before returning it.
63  if (clock_) {
64  muxer->set_clock(clock_);
65  }
66 
67  return muxer;
68 }
69 
70 void MuxerFactory::OverrideClock(base::Clock* clock) {
71  clock_ = clock;
72 }
73 } // namespace media
74 } // namespace shaka
Defines a single input/output stream.
Definition: packager.h:69
std::string segment_template
Specifies segment template. Can be empty.
Definition: packager.h:81
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:79
void OverrideClock(base::Clock *clock)
std::string temp_dir
Specify temporary directory for intermediate files.
Definition: muxer_options.h:39