Shaka Packager SDK
Loading...
Searching...
No Matches
ts_segmenter.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_SEGMENTER_H_
8#define PACKAGER_MEDIA_FORMATS_MP2T_TS_SEGMENTER_H_
9
10#include <cstdint>
11#include <memory>
12
13#include <packager/file.h>
14#include <packager/macros/classes.h>
15#include <packager/media/base/muxer_options.h>
16#include <packager/media/formats/mp2t/pes_packet_generator.h>
17#include <packager/media/formats/mp2t/ts_writer.h>
18#include <packager/status.h>
19
20namespace shaka {
21namespace media {
22
23class KeySource;
24class MuxerListener;
25
26namespace mp2t {
27
29 public:
30 // TODO(rkuroiwa): Add progress listener?
35 TsSegmenter(const MuxerOptions& options, MuxerListener* listener);
37
41 Status Initialize(const StreamInfo& stream_info);
42
45 Status Finalize();
46
49 Status AddSample(const MediaSample& sample);
50
59 // TODO(kqyang): Remove the usage of segment start timestamp and duration in
60 // xx_segmenter, which could cause confusions on which is the source of truth
61 // as the segment start timestamp and duration could be tracked locally.
62 Status FinalizeSegment(int64_t start_timestamp, int64_t duration);
63
65 void InjectTsWriterForTesting(std::unique_ptr<TsWriter> writer);
66
69 std::unique_ptr<PesPacketGenerator> generator);
70
72 void SetSegmentStartedForTesting(bool value);
73
74 int64_t segment_start_timestamp() const { return segment_start_timestamp_; }
75 BufferWriter* segment_buffer() { return &segment_buffer_; }
76 void set_segment_started(bool value) { segment_started_ = value; }
77 bool segment_started() const { return segment_started_; }
78
79 double timescale() const { return timescale_scale_; }
80 uint32_t transport_stream_timestamp_offset() const {
81 return transport_stream_timestamp_offset_;
82 }
83
84 private:
85 Status StartSegmentIfNeeded(int64_t next_pts);
86
87 // Writes PES packets (carried in TsPackets) to a buffer.
88 Status WritePesPackets();
89
90 MuxerListener* const listener_;
91
92 // Codec for the stream.
93 Codec codec_ = kUnknownCodec;
94 std::vector<uint8_t> audio_codec_config_;
95
96 const int32_t transport_stream_timestamp_offset_ = 0;
97 // Scale used to scale the input stream to TS's timesccale (which is 90000).
98
99 // Used for calculating the duration in seconds fo the current segment.
100 double timescale_scale_ = 1.0;
101
102 std::unique_ptr<TsWriter> ts_writer_;
103
104 BufferWriter segment_buffer_;
105
106 // Set to true if segment_buffer_ is initialized, set to false after
107 // FinalizeSegment() succeeds in ts_muxer.
108 bool segment_started_ = false;
109 std::unique_ptr<PesPacketGenerator> pes_packet_generator_;
110
111 int64_t segment_start_timestamp_ = -1;
112 DISALLOW_COPY_AND_ASSIGN(TsSegmenter);
113};
114
115} // namespace mp2t
116} // namespace media
117} // namespace shaka
118#endif // PACKAGER_MEDIA_FORMATS_MP2T_TS_SEGMENTER_H_
Class to hold a media sample.
Abstract class holds stream information.
Definition stream_info.h:72
Status FinalizeSegment(int64_t start_timestamp, int64_t duration)
void SetSegmentStartedForTesting(bool value)
Only for testing.
Status Initialize(const StreamInfo &stream_info)
void InjectPesPacketGeneratorForTesting(std::unique_ptr< PesPacketGenerator > generator)
Only for testing.
Status AddSample(const MediaSample &sample)
void InjectTsWriterForTesting(std::unique_ptr< TsWriter > writer)
Only for testing.
All the methods that are virtual are virtual for mocking.
This structure contains the list of configuration options for Muxer.