@@ -66,7 +66,7 @@ impl EbmlExtension {
66
66
}
67
67
}
68
68
69
- #[ derive( Debug , Clone , PartialEq , Default ) ]
69
+ #[ derive( Debug , Clone , PartialEq ) ]
70
70
pub struct SegmentInfo {
71
71
pub ( crate ) timestamp_scale : u64 ,
72
72
pub ( crate ) muxing_app : String ,
@@ -96,6 +96,17 @@ impl SegmentInfo {
96
96
}
97
97
}
98
98
99
+ impl Default for SegmentInfo {
100
+ fn default ( ) -> Self {
101
+ Self {
102
+ // https://matroska.org/technical/elements.html
103
+ timestamp_scale : 1_000_000 ,
104
+ muxing_app : String :: new ( ) ,
105
+ writing_app : String :: new ( ) ,
106
+ }
107
+ }
108
+ }
109
+
99
110
#[ derive( Debug , Clone , PartialEq , Default ) ]
100
111
pub struct AudioTrackDescriptor {
101
112
pub ( crate ) number : u64 ,
@@ -211,7 +222,7 @@ pub struct EbmlProperties {
211
222
pub ( crate ) header : EbmlHeaderProperties ,
212
223
pub ( crate ) extensions : Vec < EbmlExtension > ,
213
224
pub ( crate ) segment_info : SegmentInfo ,
214
- pub ( crate ) default_audio_track : AudioTrackDescriptor ,
225
+ pub ( crate ) audio_tracks : Vec < AudioTrackDescriptor > ,
215
226
}
216
227
217
228
impl EbmlProperties {
@@ -228,29 +239,44 @@ impl EbmlProperties {
228
239
& self . extensions
229
240
}
230
241
231
- /// Information from the Matroska `\EBML\Segment\Info` element
242
+ /// Information from the `\EBML\Segment\Info` element
232
243
pub fn segment_info ( & self ) -> & SegmentInfo {
233
244
& self . segment_info
234
245
}
235
246
247
+ /// All audio tracks in the file
248
+ ///
249
+ /// This includes all audio tracks in the Matroska `\EBML\Segment\Tracks` element.
250
+ ///
251
+ /// NOTE: The first audio track is **always** the default audio track.
252
+ pub fn audio_tracks ( & self ) -> & [ AudioTrackDescriptor ] {
253
+ & self . audio_tracks
254
+ }
255
+
236
256
/// Information about the default audio track
237
257
///
238
258
/// The information is extracted from the first audio track with its default flag set
239
- /// in the Matroska `\EBML\Segment\Tracks` element.
240
- pub fn default_audio_track ( & self ) -> & AudioTrackDescriptor {
241
- & self . default_audio_track
259
+ /// in the `\EBML\Segment\Tracks` element.
260
+ ///
261
+ /// NOTE: This will always return `Some` unless [`ParseOptions::read_properties`](crate::config::ParseOptions::read_properties) is set to `false`.
262
+ pub fn default_audio_track ( & self ) -> Option < & AudioTrackDescriptor > {
263
+ self . audio_tracks . first ( )
242
264
}
243
265
}
244
266
245
267
impl From < EbmlProperties > for FileProperties {
246
268
fn from ( input : EbmlProperties ) -> Self {
269
+ let Some ( default_audio_track) = input. default_audio_track ( ) else {
270
+ return FileProperties :: default ( ) ;
271
+ } ;
272
+
247
273
Self {
248
274
duration : todo ! ( "Support duration" ) ,
249
275
overall_bitrate : todo ! ( "Support bitrate" ) ,
250
276
audio_bitrate : todo ! ( "Support bitrate" ) ,
251
- sample_rate : Some ( input . default_audio_track . settings . sampling_frequency ) ,
252
- bit_depth : input . default_audio_track . settings . bit_depth ,
253
- channels : Some ( input . default_audio_track . settings . channels ) ,
277
+ sample_rate : Some ( default_audio_track. settings . sampling_frequency ) ,
278
+ bit_depth : default_audio_track. settings . bit_depth ,
279
+ channels : Some ( default_audio_track. settings . channels ) ,
254
280
channel_mask : todo ! ( "Channel mask" ) ,
255
281
}
256
282
}
0 commit comments