Shaka Packager SDK
mp4_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 #ifndef PACKAGER_MEDIA_FORMATS_MP4_MP4_MUXER_H_
8 #define PACKAGER_MEDIA_FORMATS_MP4_MP4_MUXER_H_
9 
10 #include <optional>
11 #include <vector>
12 
13 #include <packager/macros/classes.h>
14 #include <packager/media/base/muxer.h>
15 
16 namespace shaka {
17 namespace media {
18 
19 class AudioStreamInfo;
20 class StreamInfo;
21 class TextStreamInfo;
22 class VideoStreamInfo;
23 
24 namespace mp4 {
25 
26 class Segmenter;
27 
28 struct ProtectionSchemeInfo;
29 struct Track;
30 
33 class MP4Muxer : public Muxer {
34  public:
36  explicit MP4Muxer(const MuxerOptions& options);
37  ~MP4Muxer() override;
38 
39  private:
40  // Muxer implementation overrides.
41  Status InitializeMuxer() override;
42  Status Finalize() override;
43  Status AddMediaSample(size_t stream_id, const MediaSample& sample) override;
44  Status FinalizeSegment(size_t stream_id,
45  const SegmentInfo& segment_info) override;
46 
47  Status DelayInitializeMuxer();
48  Status UpdateEditListOffsetFromSample(const MediaSample& sample);
49 
50  // Generate Audio/Video Track box.
51  void InitializeTrak(const StreamInfo* info, Track* trak);
52  bool GenerateAudioTrak(const AudioStreamInfo* audio_info, Track* trak);
53  bool GenerateVideoTrak(const VideoStreamInfo* video_info, Track* trak);
54  bool GenerateTextTrak(const TextStreamInfo* video_info, Track* trak);
55 
56  // Gets |start| and |end| initialization range. Returns true if there is an
57  // init range and sets start-end byte-range-spec specified in RFC2616.
58  std::optional<Range> GetInitRangeStartAndEnd();
59 
60  // Gets |start| and |end| index range. Returns true if there is an index range
61  // and sets start-end byte-range-spec specified in RFC2616.
62  std::optional<Range> GetIndexRangeStartAndEnd();
63 
64  // Fire events if there are no errors and Muxer::muxer_listener() is not NULL.
65  void FireOnMediaStartEvent();
66  void FireOnMediaEndEvent();
67 
68  // Get time in seconds since midnight, Jan. 1, 1904, in UTC Time.
69  uint64_t IsoTimeNow();
70 
71  // Assumes single stream (multiplexed a/v not supported yet).
72  bool to_be_initialized_ = true;
73  std::optional<int64_t> edit_list_offset_;
74 
75  std::unique_ptr<Segmenter> segmenter_;
76 
77  DISALLOW_COPY_AND_ASSIGN(MP4Muxer);
78 };
79 
80 } // namespace mp4
81 } // namespace media
82 } // namespace shaka
83 
84 #endif // PACKAGER_MEDIA_FORMATS_MP4_MP4_MUXER_H_
Holds audio stream information.
Class to hold a media sample.
Definition: media_sample.h:25
Abstract class holds stream information.
Definition: stream_info.h:71
Holds video stream information.
MP4Muxer(const MuxerOptions &options)
Create a MP4Muxer object from MuxerOptions.
Definition: mp4_muxer.cc:169
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:19