Shaka Packager SDK
Loading...
Searching...
No Matches
muxer.h
1// Copyright 2014 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// Defines the muxer interface.
8
9#ifndef PACKAGER_MEDIA_BASE_MUXER_H_
10#define PACKAGER_MEDIA_BASE_MUXER_H_
11
12#include <cstdint>
13#include <memory>
14#include <vector>
15
16#include <packager/media/base/media_handler.h>
17#include <packager/media/base/muxer_options.h>
18#include <packager/media/event/muxer_listener.h>
19#include <packager/media/event/progress_listener.h>
20#include <packager/mpd/base/mpd_builder.h>
21#include <packager/status.h>
22
23namespace shaka {
24namespace media {
25
26class MediaSample;
27
31class Muxer : public MediaHandler {
32 public:
33 explicit Muxer(const MuxerOptions& options);
34 virtual ~Muxer();
35
38 void Cancel();
39
42 void SetMuxerListener(std::unique_ptr<MuxerListener> muxer_listener);
43
46 void SetProgressListener(std::unique_ptr<ProgressListener> progress_listener);
47
48 const std::vector<std::shared_ptr<const StreamInfo>>& streams() const {
49 return streams_;
50 }
51
58 void set_clock(std::shared_ptr<Clock> clock) { clock_ = clock; }
59
60 protected:
63 Status InitializeInternal() override { return Status::OK; }
64 Status Process(std::unique_ptr<StreamData> stream_data) override;
65 Status OnFlushRequest(size_t input_stream_index) override;
67
68 const MuxerOptions& options() const { return options_; }
69 MuxerListener* muxer_listener() { return muxer_listener_.get(); }
70 ProgressListener* progress_listener() { return progress_listener_.get(); }
71
72 uint64_t Now() const {
73 auto duration = clock_->now().time_since_epoch();
74 auto seconds =
75 std::chrono::duration_cast<std::chrono::seconds>(duration).count();
76 return static_cast<uint64_t>(seconds);
77 }
78
79 private:
80 Muxer(const Muxer&) = delete;
81 Muxer& operator=(const Muxer&) = delete;
82
83 // Initialize the muxer. InitializeMuxer may be called multiple times with
84 // |options()| updated between calls, which is used to support separate file
85 // per Representation per Period for Ad Insertion.
86 virtual Status InitializeMuxer() = 0;
87
88 // Final clean up.
89 virtual Status Finalize() = 0;
90
91 // Add a new media sample. This does nothing by default; so subclasses that
92 // handle media samples will need to replace this.
93 virtual Status AddMediaSample(size_t stream_id, const MediaSample& sample);
94
95 // Add a new text sample. This does nothing by default; so subclasses that
96 // handle text samples will need to replace this.
97 virtual Status AddTextSample(size_t stream_id, const TextSample& sample);
98
99 // Finalize the segment or subsegment.
100 virtual Status FinalizeSegment(
101 size_t stream_id,
102 const SegmentInfo& segment_info) = 0;
103
104 // Re-initialize Muxer. Could be called on StreamInfo or CueEvent.
105 // |timestamp| may be used to set the output file name.
106 Status ReinitializeMuxer(int64_t timestamp);
107
108 MuxerOptions options_;
109 std::vector<std::shared_ptr<const StreamInfo>> streams_;
110 std::vector<uint8_t> current_key_id_;
111 bool encryption_started_ = false;
112 bool cancelled_ = false;
113
114 std::unique_ptr<MuxerListener> muxer_listener_;
115 std::unique_ptr<ProgressListener> progress_listener_;
116 std::shared_ptr<Clock> clock_;
117
118 // In VOD single segment case with Ad Cues, |output_file_name| is allowed to
119 // be a template. In this case, there will be NumAdCues + 1 files generated.
120 std::string output_file_template_;
121 size_t output_file_index_ = 1;
122};
123
124} // namespace media
125} // namespace shaka
126
127#endif // PACKAGER_MEDIA_BASE_MUXER_H_
void SetMuxerListener(std::unique_ptr< MuxerListener > muxer_listener)
Definition muxer.cc:39
void SetProgressListener(std::unique_ptr< ProgressListener > progress_listener)
Definition muxer.cc:43
Status InitializeInternal() override
Definition muxer.h:63
void set_clock(std::shared_ptr< Clock > clock)
Definition muxer.h:58
Status OnFlushRequest(size_t input_stream_index) override
Event handler for flush request at the specific input stream index.
Definition muxer.cc:106
Status Process(std::unique_ptr< StreamData > stream_data) override
Definition muxer.cc:48
All the methods that are virtual are virtual for mocking.
This structure contains the list of configuration options for Muxer.