2023-12-01 17:32:19 +00:00
|
|
|
// Copyright 2016 Google LLC. All rights reserved.
|
2016-03-21 23:33:00 +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
|
|
|
|
|
|
|
|
#ifndef PACKAGER_MEDIA_FORMATS_MP2T_TS_MUXER_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_MP2T_TS_MUXER_H_
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/macros/classes.h>
|
|
|
|
#include <packager/media/base/muxer.h>
|
|
|
|
#include <packager/media/formats/mp2t/ts_segmenter.h>
|
2016-03-21 23:33:00 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2016-03-21 23:33:00 +00:00
|
|
|
namespace media {
|
|
|
|
namespace mp2t {
|
|
|
|
|
|
|
|
/// MPEG2 TS muxer.
|
|
|
|
/// This is a single program, single elementary stream TS muxer.
|
|
|
|
class TsMuxer : public Muxer {
|
|
|
|
public:
|
|
|
|
explicit TsMuxer(const MuxerOptions& muxer_options);
|
|
|
|
~TsMuxer() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Muxer implementation.
|
2017-02-21 18:36:50 +00:00
|
|
|
Status InitializeMuxer() override;
|
2016-03-21 23:33:00 +00:00
|
|
|
Status Finalize() override;
|
2020-07-30 21:26:45 +00:00
|
|
|
Status AddMediaSample(size_t stream_id, const MediaSample& sample) override;
|
2017-03-03 00:10:30 +00:00
|
|
|
Status FinalizeSegment(size_t stream_id,
|
2017-09-12 17:24:24 +00:00
|
|
|
const SegmentInfo& sample) override;
|
2016-03-21 23:33:00 +00:00
|
|
|
|
2024-02-23 23:28:11 +00:00
|
|
|
Status WriteSegment(const std::string& segment_path,
|
|
|
|
BufferWriter* segment_buffer);
|
|
|
|
Status CloseFile(std::unique_ptr<File, FileCloser> file);
|
|
|
|
|
2016-04-16 22:58:47 +00:00
|
|
|
void FireOnMediaStartEvent();
|
|
|
|
void FireOnMediaEndEvent();
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<TsSegmenter> segmenter_;
|
2020-09-02 21:27:02 +00:00
|
|
|
int64_t sample_durations_[2];
|
|
|
|
int64_t num_samples_ = 0;
|
2016-03-21 23:33:00 +00:00
|
|
|
|
2024-02-23 23:28:11 +00:00
|
|
|
// Used in multi-segment mode for segment template.
|
|
|
|
uint64_t segment_number_ = 0;
|
|
|
|
|
|
|
|
// Used in single segment mode.
|
|
|
|
std::unique_ptr<File, FileCloser> output_file_;
|
|
|
|
|
|
|
|
// Keeps track of segment ranges in single segment mode.
|
|
|
|
MuxerListener::MediaRanges media_ranges_;
|
|
|
|
|
|
|
|
uint64_t total_duration_ = 0;
|
|
|
|
|
2016-03-21 23:33:00 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(TsMuxer);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mp2t
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2016-03-21 23:33:00 +00:00
|
|
|
|
|
|
|
#endif // PACKAGER_MEDIA_FORMATS_MP2T_TS_MUXER_H_
|