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