2023-12-01 17:32:19 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-02-14 23:21:05 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_FORMATS_MP4_MP4_MUXER_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_MP4_MP4_MUXER_H_
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <optional>
|
2013-12-12 23:49:31 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/macros/classes.h>
|
|
|
|
#include <packager/media/base/muxer.h>
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-11-12 20:37:58 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class AudioStreamInfo;
|
|
|
|
class StreamInfo;
|
2015-11-23 23:12:04 +00:00
|
|
|
class TextStreamInfo;
|
2013-11-12 20:37:58 +00:00
|
|
|
class VideoStreamInfo;
|
|
|
|
|
|
|
|
namespace mp4 {
|
|
|
|
|
2014-04-08 20:21:07 +00:00
|
|
|
class Segmenter;
|
2013-11-12 20:37:58 +00:00
|
|
|
|
|
|
|
struct ProtectionSchemeInfo;
|
|
|
|
struct Track;
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Implements MP4 Muxer for ISO-BMFF. Please refer to ISO/IEC 14496-12: ISO
|
|
|
|
/// base media file format for details.
|
2013-11-12 20:37:58 +00:00
|
|
|
class MP4Muxer : public Muxer {
|
|
|
|
public:
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Create a MP4Muxer object from MuxerOptions.
|
2014-01-14 01:38:34 +00:00
|
|
|
explicit MP4Muxer(const MuxerOptions& options);
|
2015-07-22 23:40:45 +00:00
|
|
|
~MP4Muxer() override;
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2014-04-09 17:34:55 +00:00
|
|
|
private:
|
|
|
|
// Muxer implementation overrides.
|
2017-02-21 18:36:50 +00:00
|
|
|
Status InitializeMuxer() override;
|
2015-07-22 23:40:45 +00:00
|
|
|
Status Finalize() override;
|
2020-07-30 21:26:45 +00:00
|
|
|
Status AddMediaSample(size_t stream_id, const MediaSample& sample) override;
|
2017-03-03 00:10:30 +00:00
|
|
|
Status FinalizeSegment(size_t stream_id,
|
2017-09-12 17:24:24 +00:00
|
|
|
const SegmentInfo& segment_info) override;
|
2013-11-12 20:37:58 +00:00
|
|
|
|
Add support for EditLists in ISO-BMFF
- EditLists in input files are parsed and applied to sample timestamps.
- An EditList will be inserted in the ISO-BMFF output if
- There is an offset between the initial presentation timestamp (pts)
and decoding timestamp (dts). Chrome, as of M67, still uses dts in
buffered range API [1], which creates various problems when buffered
range by pts does not align with buffered range by dts. There is
another bug in Chrome that applies EditList to pts only [2]. This
means that we can insert an EditList to align pts range and dts range.
- MediaSamples have negative timestamps (e.g. for Audio Priming).
You may notice the below change on some contents:
- Some media duration is reduced by one or two frames. This is because
EditList in the input file was ignored in the previous code, so video
streams start with a zero dts and a non-zero pts; the smaller of dts
and pts was used as the starting timestamp (related to the earlier
workaround for Chrome's dts bug), so the calculated duration was
actually a bit larger than the actual duration. Now with EditList
applied, the initial pts is reduced to zero, so the media duration is
also reduced to reflect the actual and correct media duration.
It may also result in negative timestamps in TS/HLS Packed Audio, which
will be addressed in a follow up CL.
Fixes #112.
Partially address b/110782437.
[1] https://crbug.com/718641, fixed but behind MseBufferByPts.
[2] https://crbug.com/354518. Chrome is planning to enable the fix for
[1] before addressing this bug, so we are safe.
Change-Id: I59317740ad3807ca66fa74b3a18fdf7f32c96aeb
2018-07-03 00:52:25 +00:00
|
|
|
Status DelayInitializeMuxer();
|
|
|
|
Status UpdateEditListOffsetFromSample(const MediaSample& sample);
|
|
|
|
|
2015-12-21 18:34:21 +00:00
|
|
|
// Generate Audio/Video Track box.
|
2013-11-12 20:37:58 +00:00
|
|
|
void InitializeTrak(const StreamInfo* info, Track* trak);
|
2020-07-15 21:14:15 +00:00
|
|
|
bool GenerateAudioTrak(const AudioStreamInfo* audio_info, Track* trak);
|
|
|
|
bool GenerateVideoTrak(const VideoStreamInfo* video_info, Track* trak);
|
|
|
|
bool GenerateTextTrak(const TextStreamInfo* video_info, Track* trak);
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2013-12-12 23:49:31 +00:00
|
|
|
// Gets |start| and |end| initialization range. Returns true if there is an
|
|
|
|
// init range and sets start-end byte-range-spec specified in RFC2616.
|
2023-12-01 17:32:19 +00:00
|
|
|
std::optional<Range> GetInitRangeStartAndEnd();
|
2013-12-12 23:49:31 +00:00
|
|
|
|
|
|
|
// Gets |start| and |end| index range. Returns true if there is an index range
|
|
|
|
// and sets start-end byte-range-spec specified in RFC2616.
|
2023-12-01 17:32:19 +00:00
|
|
|
std::optional<Range> GetIndexRangeStartAndEnd();
|
2013-12-12 23:49:31 +00:00
|
|
|
|
|
|
|
// Fire events if there are no errors and Muxer::muxer_listener() is not NULL.
|
|
|
|
void FireOnMediaStartEvent();
|
|
|
|
void FireOnMediaEndEvent();
|
|
|
|
|
2014-02-28 02:39:52 +00:00
|
|
|
// Get time in seconds since midnight, Jan. 1, 1904, in UTC Time.
|
2014-09-30 21:52:21 +00:00
|
|
|
uint64_t IsoTimeNow();
|
2014-02-28 02:39:52 +00:00
|
|
|
|
Add support for EditLists in ISO-BMFF
- EditLists in input files are parsed and applied to sample timestamps.
- An EditList will be inserted in the ISO-BMFF output if
- There is an offset between the initial presentation timestamp (pts)
and decoding timestamp (dts). Chrome, as of M67, still uses dts in
buffered range API [1], which creates various problems when buffered
range by pts does not align with buffered range by dts. There is
another bug in Chrome that applies EditList to pts only [2]. This
means that we can insert an EditList to align pts range and dts range.
- MediaSamples have negative timestamps (e.g. for Audio Priming).
You may notice the below change on some contents:
- Some media duration is reduced by one or two frames. This is because
EditList in the input file was ignored in the previous code, so video
streams start with a zero dts and a non-zero pts; the smaller of dts
and pts was used as the starting timestamp (related to the earlier
workaround for Chrome's dts bug), so the calculated duration was
actually a bit larger than the actual duration. Now with EditList
applied, the initial pts is reduced to zero, so the media duration is
also reduced to reflect the actual and correct media duration.
It may also result in negative timestamps in TS/HLS Packed Audio, which
will be addressed in a follow up CL.
Fixes #112.
Partially address b/110782437.
[1] https://crbug.com/718641, fixed but behind MseBufferByPts.
[2] https://crbug.com/354518. Chrome is planning to enable the fix for
[1] before addressing this bug, so we are safe.
Change-Id: I59317740ad3807ca66fa74b3a18fdf7f32c96aeb
2018-07-03 00:52:25 +00:00
|
|
|
// Assumes single stream (multiplexed a/v not supported yet).
|
|
|
|
bool to_be_initialized_ = true;
|
2023-12-01 17:32:19 +00:00
|
|
|
std::optional<int64_t> edit_list_offset_;
|
Add support for EditLists in ISO-BMFF
- EditLists in input files are parsed and applied to sample timestamps.
- An EditList will be inserted in the ISO-BMFF output if
- There is an offset between the initial presentation timestamp (pts)
and decoding timestamp (dts). Chrome, as of M67, still uses dts in
buffered range API [1], which creates various problems when buffered
range by pts does not align with buffered range by dts. There is
another bug in Chrome that applies EditList to pts only [2]. This
means that we can insert an EditList to align pts range and dts range.
- MediaSamples have negative timestamps (e.g. for Audio Priming).
You may notice the below change on some contents:
- Some media duration is reduced by one or two frames. This is because
EditList in the input file was ignored in the previous code, so video
streams start with a zero dts and a non-zero pts; the smaller of dts
and pts was used as the starting timestamp (related to the earlier
workaround for Chrome's dts bug), so the calculated duration was
actually a bit larger than the actual duration. Now with EditList
applied, the initial pts is reduced to zero, so the media duration is
also reduced to reflect the actual and correct media duration.
It may also result in negative timestamps in TS/HLS Packed Audio, which
will be addressed in a follow up CL.
Fixes #112.
Partially address b/110782437.
[1] https://crbug.com/718641, fixed but behind MseBufferByPts.
[2] https://crbug.com/354518. Chrome is planning to enable the fix for
[1] before addressing this bug, so we are safe.
Change-Id: I59317740ad3807ca66fa74b3a18fdf7f32c96aeb
2018-07-03 00:52:25 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<Segmenter> segmenter_;
|
2013-11-12 20:37:58 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MP4Muxer);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mp4
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#endif // PACKAGER_MEDIA_FORMATS_MP4_MP4_MUXER_H_
|