2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2017 Google LLC. All rights reserved.
|
2018-01-03 18:16:08 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/app/muxer_factory.h>
|
2018-01-03 18:16:08 +00:00
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/base/muxer.h>
|
|
|
|
#include <packager/media/formats/mp2t/ts_muxer.h>
|
|
|
|
#include <packager/media/formats/mp4/mp4_muxer.h>
|
|
|
|
#include <packager/media/formats/packed_audio/packed_audio_writer.h>
|
|
|
|
#include <packager/media/formats/ttml/ttml_muxer.h>
|
|
|
|
#include <packager/media/formats/webm/webm_muxer.h>
|
|
|
|
#include <packager/media/formats/webvtt/webvtt_muxer.h>
|
|
|
|
#include <packager/packager.h>
|
2018-01-03 18:16:08 +00:00
|
|
|
|
|
|
|
namespace shaka {
|
|
|
|
namespace media {
|
|
|
|
|
|
|
|
MuxerFactory::MuxerFactory(const PackagingParams& packaging_params)
|
|
|
|
: mp4_params_(packaging_params.mp4_output_params),
|
2020-07-30 21:26:45 +00:00
|
|
|
temp_dir_(packaging_params.temp_dir),
|
2018-07-03 23:52:05 +00:00
|
|
|
transport_stream_timestamp_offset_ms_(
|
2020-07-30 21:26:45 +00:00
|
|
|
packaging_params.transport_stream_timestamp_offset_ms) {}
|
2018-01-03 18:16:08 +00:00
|
|
|
|
|
|
|
std::shared_ptr<Muxer> MuxerFactory::CreateMuxer(
|
|
|
|
MediaContainerName output_format,
|
|
|
|
const StreamDescriptor& stream) {
|
|
|
|
MuxerOptions options;
|
|
|
|
options.mp4_params = mp4_params_;
|
2018-07-03 23:52:05 +00:00
|
|
|
options.transport_stream_timestamp_offset_ms =
|
|
|
|
transport_stream_timestamp_offset_ms_;
|
2018-01-03 18:16:08 +00:00
|
|
|
options.temp_dir = temp_dir_;
|
|
|
|
options.output_file_name = stream.output;
|
|
|
|
options.segment_template = stream.segment_template;
|
|
|
|
options.bandwidth = stream.bandwidth;
|
|
|
|
|
|
|
|
std::shared_ptr<Muxer> muxer;
|
|
|
|
|
|
|
|
switch (output_format) {
|
2018-05-07 23:08:09 +00:00
|
|
|
case CONTAINER_AAC:
|
2020-06-03 00:32:19 +00:00
|
|
|
case CONTAINER_MP3:
|
2018-05-07 23:08:09 +00:00
|
|
|
case CONTAINER_AC3:
|
|
|
|
case CONTAINER_EAC3:
|
|
|
|
muxer = std::make_shared<PackedAudioWriter>(options);
|
|
|
|
break;
|
2018-01-03 18:16:08 +00:00
|
|
|
case CONTAINER_WEBM:
|
|
|
|
muxer = std::make_shared<webm::WebMMuxer>(options);
|
|
|
|
break;
|
2020-10-08 21:46:37 +00:00
|
|
|
case CONTAINER_TTML:
|
|
|
|
muxer = std::make_shared<ttml::TtmlMuxer>(options);
|
|
|
|
break;
|
2020-07-30 21:26:45 +00:00
|
|
|
case CONTAINER_WEBVTT:
|
|
|
|
muxer = std::make_shared<webvtt::WebVttMuxer>(options);
|
|
|
|
break;
|
2018-01-03 18:16:08 +00:00
|
|
|
case CONTAINER_MPEG2TS:
|
|
|
|
muxer = std::make_shared<mp2t::TsMuxer>(options);
|
|
|
|
break;
|
|
|
|
case CONTAINER_MOV:
|
|
|
|
muxer = std::make_shared<mp4::MP4Muxer>(options);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG(ERROR) << "Cannot support muxing to " << output_format;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!muxer) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We successfully created a muxer, then there is a couple settings
|
|
|
|
// we should set before returning it.
|
|
|
|
if (clock_) {
|
|
|
|
muxer->set_clock(clock_);
|
|
|
|
}
|
|
|
|
|
|
|
|
return muxer;
|
|
|
|
}
|
|
|
|
|
2023-11-30 21:42:18 +00:00
|
|
|
void MuxerFactory::OverrideClock(std::shared_ptr<Clock> clock) {
|
2018-01-03 18:16:08 +00:00
|
|
|
clock_ = clock;
|
|
|
|
}
|
|
|
|
} // namespace media
|
|
|
|
} // namespace shaka
|