1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
// Copyright (C) 2022 Sebastian Dröge <sebastian@centricular.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public License, v2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// <https://mozilla.org/MPL/2.0/>.
//
// SPDX-License-Identifier: MPL-2.0
use gst::glib;
use gst::prelude::*;
mod boxes;
mod imp;
glib::wrapper! {
pub(crate) struct MP4MuxPad(ObjectSubclass<imp::MP4MuxPad>) @extends gst_base::AggregatorPad, gst::Pad, gst::Object;
}
glib::wrapper! {
pub(crate) struct MP4Mux(ObjectSubclass<imp::MP4Mux>) @extends gst_base::Aggregator, gst::Element, gst::Object;
}
glib::wrapper! {
pub(crate) struct ISOMP4Mux(ObjectSubclass<imp::ISOMP4Mux>) @extends MP4Mux, gst_base::Aggregator, gst::Element, gst::Object;
}
glib::wrapper! {
pub(crate) struct ONVIFMP4Mux(ObjectSubclass<imp::ONVIFMP4Mux>) @extends MP4Mux, gst_base::Aggregator, gst::Element, gst::Object;
}
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
#[cfg(feature = "doc")]
{
MP4Mux::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty());
MP4MuxPad::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty());
}
gst::Element::register(
Some(plugin),
"isomp4mux",
gst::Rank::Marginal,
ISOMP4Mux::static_type(),
)?;
gst::Element::register(
Some(plugin),
"onvifmp4mux",
gst::Rank::Marginal,
ONVIFMP4Mux::static_type(),
)?;
Ok(())
}
#[derive(Debug, Copy, Clone)]
pub(crate) enum DeltaFrames {
/// Only single completely decodable frames
IntraOnly,
/// Frames may depend on past frames
PredictiveOnly,
/// Frames may depend on past or future frames
Bidirectional,
}
impl DeltaFrames {
/// Whether dts is required to order samples differently from presentation order
pub(crate) fn requires_dts(&self) -> bool {
matches!(self, Self::Bidirectional)
}
/// Whether this coding structure does not allow delta flags on samples
pub(crate) fn intra_only(&self) -> bool {
matches!(self, Self::IntraOnly)
}
}
#[derive(Debug)]
pub(crate) struct Sample {
/// Sync point
sync_point: bool,
/// Sample duration
duration: gst::ClockTime,
/// Composition time offset
///
/// This is `None` for streams that have no concept of DTS.
composition_time_offset: Option<i64>,
/// Size
size: u32,
}
#[derive(Debug)]
pub(crate) struct Chunk {
/// Chunk start offset
offset: u64,
/// Samples of this stream that are part of this chunk
samples: Vec<Sample>,
}
#[derive(Debug)]
pub(crate) struct Stream {
/// Caps of this stream
caps: gst::Caps,
/// If this stream has delta frames, and if so if it can have B frames.
delta_frames: DeltaFrames,
/// Pre-defined trak timescale if not 0.
trak_timescale: u32,
/// Start DTS
///
/// If this is negative then an edit list entry is needed to
/// make all sample times positive.
///
/// This is `None` for streams that have no concept of DTS.
start_dts: Option<gst::Signed<gst::ClockTime>>,
/// Earliest PTS
///
/// If this is >0 then an edit list entry is needed to shift
earliest_pts: gst::ClockTime,
/// End PTS
end_pts: gst::ClockTime,
/// All the chunks stored for this stream
chunks: Vec<Chunk>,
}
#[derive(Debug)]
pub(crate) struct Header {
#[allow(dead_code)]
variant: Variant,
/// Pre-defined movie timescale if not 0.
movie_timescale: u32,
streams: Vec<Stream>,
}
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Variant {
ISO,
ONVIF,
}
|