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