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/webm/webm_muxer.h"
15 #include "packager/packager.h"
16 
17 namespace shaka {
18 namespace media {
19 
20 MuxerFactory::MuxerFactory(const PackagingParams& packaging_params)
21  : mp4_params_(packaging_params.mp4_output_params),
22  temp_dir_(packaging_params.temp_dir) {}
23 
24 std::shared_ptr<Muxer> MuxerFactory::CreateMuxer(
25  MediaContainerName output_format,
26  const StreamDescriptor& stream) {
27  MuxerOptions options;
28  options.mp4_params = mp4_params_;
29  options.temp_dir = temp_dir_;
30  options.output_file_name = stream.output;
31  options.segment_template = stream.segment_template;
32  options.bandwidth = stream.bandwidth;
33 
34  std::shared_ptr<Muxer> muxer;
35 
36  switch (output_format) {
37  case CONTAINER_WEBM:
38  muxer = std::make_shared<webm::WebMMuxer>(options);
39  break;
40  case CONTAINER_MPEG2TS:
41  muxer = std::make_shared<mp2t::TsMuxer>(options);
42  break;
43  case CONTAINER_MOV:
44  muxer = std::make_shared<mp4::MP4Muxer>(options);
45  break;
46  default:
47  LOG(ERROR) << "Cannot support muxing to " << output_format;
48  break;
49  }
50 
51  if (!muxer) {
52  return nullptr;
53  }
54 
55  // We successfully created a muxer, then there is a couple settings
56  // we should set before returning it.
57  if (clock_) {
58  muxer->set_clock(clock_);
59  }
60 
61  return muxer;
62 }
63 
64 void MuxerFactory::OverrideClock(base::Clock* clock) {
65  clock_ = clock;
66 }
67 } // namespace media
68 } // 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