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