Shaka Packager SDK
Loading...
Searching...
No Matches
ts_muxer.h
1// Copyright 2016 Google LLC. 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#ifndef PACKAGER_MEDIA_FORMATS_MP2T_TS_MUXER_H_
8#define PACKAGER_MEDIA_FORMATS_MP2T_TS_MUXER_H_
9
10#include <cstddef>
11#include <cstdint>
12#include <memory>
13#include <string>
14
15#include <packager/file.h>
16#include <packager/file/file_closer.h>
17#include <packager/macros/classes.h>
18#include <packager/media/base/buffer_writer.h>
19#include <packager/media/base/encryption_config.h>
20#include <packager/media/base/media_handler.h>
21#include <packager/media/base/muxer.h>
22#include <packager/media/base/muxer_options.h>
23#include <packager/media/formats/mp2t/ts_segmenter.h>
24#include <packager/status.h>
25
26namespace shaka {
27namespace media {
28namespace mp2t {
29
32class TsMuxer : public Muxer {
33 public:
34 explicit TsMuxer(const MuxerOptions& muxer_options);
35 ~TsMuxer() override;
36
37 private:
38 // Muxer implementation.
39 Status InitializeMuxer() override;
40 Status Finalize() override;
41 Status AddMediaSample(size_t stream_id, const MediaSample& sample) override;
42 Status FinalizeSegment(size_t stream_id, const SegmentInfo& sample) override;
43
44 Status WriteSegment(const std::string& segment_path,
45 BufferWriter* segment_buffer);
46 Status CloseFile(std::unique_ptr<File, FileCloser> file);
47
48 // Encrypts |segment_buffer| in-place if AES-128 is active.
49 void EncryptSegmentIfNeeded(BufferWriter* segment_buffer);
50
51 void FireOnMediaStartEvent();
52 void FireOnMediaEndEvent();
53
54 std::unique_ptr<TsSegmenter> segmenter_;
55 // Populated when protection_scheme == kAes128ProtectionScheme.
56 EncryptionConfig aes128_encryption_config_;
57 int64_t sample_durations_[2] = {0, 0};
58 size_t num_samples_ = 0;
59
60 // Used in single segment mode.
61 std::unique_ptr<File, FileCloser> output_file_;
62
63 // Keeps track of segment ranges in single segment mode.
64 MuxerListener::MediaRanges media_ranges_;
65
66 uint64_t total_duration_ = 0;
67
68 DISALLOW_COPY_AND_ASSIGN(TsMuxer);
69};
70
71} // namespace mp2t
72} // namespace media
73} // namespace shaka
74
75#endif // PACKAGER_MEDIA_FORMATS_MP2T_TS_MUXER_H_
Class to hold a media sample.
All the methods that are virtual are virtual for mocking.
This structure contains the list of configuration options for Muxer.