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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::{ffi, EncodingTarget};
use glib::translate::*;

/// Returns the channels of the given AAC stream.
/// ## `audio_config`
/// a pointer to the AudioSpecificConfig
///  as specified in the Elementary Stream Descriptor (esds)
///  in ISO/IEC 14496-1.
///
/// # Returns
///
/// The channels or 0 if the channel could not be determined.
#[doc(alias = "gst_codec_utils_aac_get_channels")]
pub fn codec_utils_aac_get_channels(audio_config: &[u8]) -> u32 {
    assert_initialized_main_thread!();
    let len = audio_config.len() as _;
    unsafe { ffi::gst_codec_utils_aac_get_channels(audio_config.to_glib_none().0, len) }
}

/// Translates the sample rate to the index corresponding to it in AAC spec.
/// ## `rate`
/// Sample rate
///
/// # Returns
///
/// The AAC index for this sample rate, -1 if the rate is not a
/// valid AAC sample rate.
#[doc(alias = "gst_codec_utils_aac_get_index_from_sample_rate")]
pub fn codec_utils_aac_get_index_from_sample_rate(rate: u32) -> i32 {
    assert_initialized_main_thread!();
    unsafe { ffi::gst_codec_utils_aac_get_index_from_sample_rate(rate) }
}

/// Determines the level of a stream as defined in ISO/IEC 14496-3. For AAC LC
/// streams, the constraints from the AAC audio profile are applied. For AAC
/// Main, LTP, SSR and others, the Main profile is used.
///
/// The `audio_config` parameter follows the following format, starting from the
/// most significant bit of the first byte:
///
///  * Bit 0:4 contains the AudioObjectType (if this is 0x5, then the
///  real AudioObjectType is carried after the rate and channel data)
///  * Bit 5:8 contains the sample frequency index (if this is 0xf, then the
///  next 24 bits define the actual sample frequency, and subsequent
///  fields are appropriately shifted).
///  * Bit 9:12 contains the channel configuration
/// ## `audio_config`
/// a pointer to the AudioSpecificConfig
///  as specified in the Elementary Stream Descriptor (esds)
///  in ISO/IEC 14496-1.
///
/// # Returns
///
/// The level as a const string and [`None`] if the level could not be
/// determined.
#[doc(alias = "gst_codec_utils_aac_get_level")]
pub fn codec_utils_aac_get_level(audio_config: &[u8]) -> Result<glib::GString, glib::BoolError> {
    assert_initialized_main_thread!();
    let len = audio_config.len() as _;
    unsafe {
        Option::<_>::from_glib_none(ffi::gst_codec_utils_aac_get_level(
            audio_config.to_glib_none().0,
            len,
        ))
        .ok_or_else(|| glib::bool_error!("Failed to get AAC level"))
    }
}

/// Returns the profile of the given AAC stream as a string. The profile is
/// normally determined using the AudioObjectType field which is in the first
/// 5 bits of `audio_config`
/// ## `audio_config`
/// a pointer to the AudioSpecificConfig
///  as specified in the Elementary Stream Descriptor (esds)
///  in ISO/IEC 14496-1.
///
/// # Returns
///
/// The profile as a const string and [`None`] if the profile could not be
/// determined.
#[doc(alias = "gst_codec_utils_aac_get_profile")]
pub fn codec_utils_aac_get_profile(audio_config: &[u8]) -> Result<glib::GString, glib::BoolError> {
    assert_initialized_main_thread!();
    let len = audio_config.len() as _;
    unsafe {
        Option::<_>::from_glib_none(ffi::gst_codec_utils_aac_get_profile(
            audio_config.to_glib_none().0,
            len,
        ))
        .ok_or_else(|| glib::bool_error!("Failed to get AAC profile"))
    }
}

/// Translates the sample rate index found in AAC headers to the actual sample
/// rate.
/// ## `audio_config`
/// a pointer to the AudioSpecificConfig
///  as specified in the Elementary Stream Descriptor (esds)
///  in ISO/IEC 14496-1.
///
/// # Returns
///
/// The sample rate if sr_idx is valid, 0 otherwise.
#[doc(alias = "gst_codec_utils_aac_get_sample_rate")]
pub fn codec_utils_aac_get_sample_rate(audio_config: &[u8]) -> u32 {
    assert_initialized_main_thread!();
    let len = audio_config.len() as _;
    unsafe { ffi::gst_codec_utils_aac_get_sample_rate(audio_config.to_glib_none().0, len) }
}

/// Translates the sample rate index found in AAC headers to the actual sample
/// rate.
/// ## `sr_idx`
/// Sample rate index as from the AudioSpecificConfig (MPEG-4
///  container) or ADTS frame header
///
/// # Returns
///
/// The sample rate if `sr_idx` is valid, 0 otherwise.
#[doc(alias = "gst_codec_utils_aac_get_sample_rate_from_index")]
pub fn codec_utils_aac_get_sample_rate_from_index(sr_idx: u32) -> u32 {
    assert_initialized_main_thread!();
    unsafe { ffi::gst_codec_utils_aac_get_sample_rate_from_index(sr_idx) }
}

/// Transform a seq_level_idx into the level string
/// ## `seq_level_idx`
/// A seq_level_idx
///
/// # Returns
///
/// the level string or [`None`] if the seq_level_idx is unknown
#[cfg(feature = "v1_26")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
#[doc(alias = "gst_codec_utils_av1_get_level")]
pub fn codec_utils_av1_get_level(seq_level_idx: u8) -> Result<glib::GString, glib::BoolError> {
    assert_initialized_main_thread!();
    unsafe {
        Option::<_>::from_glib_none(ffi::gst_codec_utils_av1_get_level(seq_level_idx))
            .ok_or_else(|| glib::bool_error!("Failed to get AV1 level"))
    }
}

/// Transform a level string from the caps into the seq_level_idx
/// ## `level`
/// A level string from caps
///
/// # Returns
///
/// the seq_level_idx or 31 (max-level) if the level is unknown
#[cfg(feature = "v1_26")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
#[doc(alias = "gst_codec_utils_av1_get_seq_level_idx")]
pub fn codec_utils_av1_get_seq_level_idx(level: &str) -> u8 {
    assert_initialized_main_thread!();
    unsafe { ffi::gst_codec_utils_av1_get_seq_level_idx(level.to_glib_none().0) }
}

/// Converts a RFC 6381 compatible codec string to [`gst::Caps`][crate::gst::Caps]. More than one codec
/// string can be present (separated by `,`).
///
/// Registered codecs can be found at http://mp4ra.org/#/codecs
/// ## `codecs_field`
/// A mime codec string field
///
/// # Returns
///
/// The corresponding [`gst::Caps`][crate::gst::Caps] or [`None`]
#[cfg(feature = "v1_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
#[doc(alias = "gst_codec_utils_caps_from_mime_codec")]
pub fn codec_utils_caps_from_mime_codec(codecs_field: &str) -> Option<gst::Caps> {
    assert_initialized_main_thread!();
    unsafe {
        from_glib_full(ffi::gst_codec_utils_caps_from_mime_codec(
            codecs_field.to_glib_none().0,
        ))
    }
}

/// Converts the level indication (level_idc) in the stream's
/// sequence parameter set into a string. The SPS is expected to have the
/// same format as for [`codec_utils_h264_get_profile()`][crate::codec_utils_h264_get_profile()].
/// ## `sps`
/// Pointer to the sequence parameter set for the stream.
///
/// # Returns
///
/// The level as a const string, or [`None`] if there is an error.
#[doc(alias = "gst_codec_utils_h264_get_level")]
pub fn codec_utils_h264_get_level(sps: &[u8]) -> Result<glib::GString, glib::BoolError> {
    assert_initialized_main_thread!();
    let len = sps.len() as _;
    unsafe {
        Option::<_>::from_glib_none(ffi::gst_codec_utils_h264_get_level(
            sps.to_glib_none().0,
            len,
        ))
        .ok_or_else(|| glib::bool_error!("Failed to get H264 level"))
    }
}

/// Transform a level string from the caps into the level_idc
/// ## `level`
/// A level string from caps
///
/// # Returns
///
/// the level_idc or 0 if the level is unknown
#[doc(alias = "gst_codec_utils_h264_get_level_idc")]
pub fn codec_utils_h264_get_level_idc(level: &str) -> u8 {
    assert_initialized_main_thread!();
    unsafe { ffi::gst_codec_utils_h264_get_level_idc(level.to_glib_none().0) }
}

/// Converts the profile indication (profile_idc) in the stream's
/// sequence parameter set into a string. The SPS is expected to have the
/// following format, as defined in the H.264 specification. The SPS is viewed
/// as a bitstream here, with bit 0 being the most significant bit of the first
/// byte.
///
/// * Bit 0:7 - Profile indication
/// * Bit 8 - constraint_set0_flag
/// * Bit 9 - constraint_set1_flag
/// * Bit 10 - constraint_set2_flag
/// * Bit 11 - constraint_set3_flag
/// * Bit 12 - constraint_set3_flag
/// * Bit 13:15 - Reserved
/// * Bit 16:24 - Level indication
/// ## `sps`
/// Pointer to the sequence parameter set for the stream.
///
/// # Returns
///
/// The profile as a const string, or [`None`] if there is an error.
#[doc(alias = "gst_codec_utils_h264_get_profile")]
pub fn codec_utils_h264_get_profile(sps: &[u8]) -> Result<glib::GString, glib::BoolError> {
    assert_initialized_main_thread!();
    let len = sps.len() as _;
    unsafe {
        Option::<_>::from_glib_none(ffi::gst_codec_utils_h264_get_profile(
            sps.to_glib_none().0,
            len,
        ))
        .ok_or_else(|| glib::bool_error!("Failed to get H264 profile"))
    }
}

/// Converts the level indication (general_level_idc) in the stream's
/// profile_tier_level structure into a string. The profiel_tier_level is
/// expected to have the same format as for [`codec_utils_h264_get_profile()`][crate::codec_utils_h264_get_profile()].
/// ## `profile_tier_level`
/// Pointer to the profile_tier_level
///  for the stream
///
/// # Returns
///
/// The level as a const string, or [`None`] if there is an error.
#[doc(alias = "gst_codec_utils_h265_get_level")]
pub fn codec_utils_h265_get_level(
    profile_tier_level: &[u8],
) -> Result<glib::GString, glib::BoolError> {
    assert_initialized_main_thread!();
    let len = profile_tier_level.len() as _;
    unsafe {
        Option::<_>::from_glib_none(ffi::gst_codec_utils_h265_get_level(
            profile_tier_level.to_glib_none().0,
            len,
        ))
        .ok_or_else(|| glib::bool_error!("Failed to get H265 level"))
    }
}

/// Transform a level string from the caps into the level_idc
/// ## `level`
/// A level string from caps
///
/// # Returns
///
/// the level_idc or 0 if the level is unknown
#[doc(alias = "gst_codec_utils_h265_get_level_idc")]
pub fn codec_utils_h265_get_level_idc(level: &str) -> u8 {
    assert_initialized_main_thread!();
    unsafe { ffi::gst_codec_utils_h265_get_level_idc(level.to_glib_none().0) }
}

/// Converts the profile indication (general_profile_idc) in the stream's
/// profile_level_tier structure into a string. The profile_tier_level is
/// expected to have the following format, as defined in the H.265
/// specification. The profile_tier_level is viewed as a bitstream here,
/// with bit 0 being the most significant bit of the first byte.
///
/// * Bit 0:1 - general_profile_space
/// * Bit 2 - general_tier_flag
/// * Bit 3:7 - general_profile_idc
/// * Bit 8:39 - gernal_profile_compatibility_flags
/// * Bit 40 - general_progressive_source_flag
/// * Bit 41 - general_interlaced_source_flag
/// * Bit 42 - general_non_packed_constraint_flag
/// * Bit 43 - general_frame_only_constraint_flag
/// * Bit 44:87 - See below
/// * Bit 88:95 - general_level_idc
/// ## `profile_tier_level`
/// Pointer to the profile_tier_level
///  structure for the stream.
///
/// # Returns
///
/// The profile as a const string, or [`None`] if there is an error.
#[doc(alias = "gst_codec_utils_h265_get_profile")]
pub fn codec_utils_h265_get_profile(
    profile_tier_level: &[u8],
) -> Result<glib::GString, glib::BoolError> {
    assert_initialized_main_thread!();
    let len = profile_tier_level.len() as _;
    unsafe {
        Option::<_>::from_glib_none(ffi::gst_codec_utils_h265_get_profile(
            profile_tier_level.to_glib_none().0,
            len,
        ))
        .ok_or_else(|| glib::bool_error!("Failed to get H265 profile"))
    }
}

/// Converts the tier indication (general_tier_flag) in the stream's
/// profile_tier_level structure into a string. The profile_tier_level
/// is expected to have the same format as for [`codec_utils_h264_get_profile()`][crate::codec_utils_h264_get_profile()].
/// ## `profile_tier_level`
/// Pointer to the profile_tier_level
///  for the stream.
///
/// # Returns
///
/// The tier as a const string, or [`None`] if there is an error.
#[doc(alias = "gst_codec_utils_h265_get_tier")]
pub fn codec_utils_h265_get_tier(
    profile_tier_level: &[u8],
) -> Result<glib::GString, glib::BoolError> {
    assert_initialized_main_thread!();
    let len = profile_tier_level.len() as _;
    unsafe {
        Option::<_>::from_glib_none(ffi::gst_codec_utils_h265_get_tier(
            profile_tier_level.to_glib_none().0,
            len,
        ))
        .ok_or_else(|| glib::bool_error!("Failed to get H265 tier"))
    }
}

/// Converts the level indication in the stream's visual object sequence into
/// a string. `vis_obj_seq` is expected to be the data following the visual
/// object sequence start code. Only the first byte
/// (profile_and_level_indication) is used.
/// ## `vis_obj_seq`
/// Pointer to the visual object
///  sequence for the stream.
///
/// # Returns
///
/// The level as a const string, or NULL if there is an error.
#[doc(alias = "gst_codec_utils_mpeg4video_get_level")]
pub fn codec_utils_mpeg4video_get_level(
    vis_obj_seq: &[u8],
) -> Result<glib::GString, glib::BoolError> {
    assert_initialized_main_thread!();
    let len = vis_obj_seq.len() as _;
    unsafe {
        Option::<_>::from_glib_none(ffi::gst_codec_utils_mpeg4video_get_level(
            vis_obj_seq.to_glib_none().0,
            len,
        ))
        .ok_or_else(|| glib::bool_error!("Failed to get MPEG4 video level"))
    }
}

/// Converts the profile indication in the stream's visual object sequence into
/// a string. `vis_obj_seq` is expected to be the data following the visual
/// object sequence start code. Only the first byte
/// (profile_and_level_indication) is used.
/// ## `vis_obj_seq`
/// Pointer to the visual object
///  sequence for the stream.
///
/// # Returns
///
/// The profile as a const string, or NULL if there is an error.
#[doc(alias = "gst_codec_utils_mpeg4video_get_profile")]
pub fn codec_utils_mpeg4video_get_profile(
    vis_obj_seq: &[u8],
) -> Result<glib::GString, glib::BoolError> {
    assert_initialized_main_thread!();
    let len = vis_obj_seq.len() as _;
    unsafe {
        Option::<_>::from_glib_none(ffi::gst_codec_utils_mpeg4video_get_profile(
            vis_obj_seq.to_glib_none().0,
            len,
        ))
        .ok_or_else(|| glib::bool_error!("Failed to get MPEG4 video profile"))
    }
}

/// List all available [`EncodingTarget`][crate::EncodingTarget] for the specified category, or all categories
/// if `categoryname` is [`None`].
/// ## `categoryname`
/// The category, for ex: `GST_ENCODING_CATEGORY_DEVICE`.
/// Can be [`None`].
///
/// # Returns
///
/// The list of [`EncodingTarget`][crate::EncodingTarget]
#[doc(alias = "gst_encoding_list_all_targets")]
pub fn encoding_list_all_targets(categoryname: Option<&str>) -> Vec<EncodingTarget> {
    assert_initialized_main_thread!();
    unsafe {
        FromGlibPtrContainer::from_glib_full(ffi::gst_encoding_list_all_targets(
            categoryname.to_glib_none().0,
        ))
    }
}

/// Lists all [`EncodingTarget`][crate::EncodingTarget] categories present on disk.
///
/// # Returns
///
/// A list
/// of [`EncodingTarget`][crate::EncodingTarget] categories.
#[doc(alias = "gst_encoding_list_available_categories")]
pub fn encoding_list_available_categories() -> Vec<glib::GString> {
    assert_initialized_main_thread!();
    unsafe { FromGlibPtrContainer::from_glib_full(ffi::gst_encoding_list_available_categories()) }
}

/// Returns a localised string describing the given element, for use in
/// error dialogs or other messages to be seen by the user.
///
/// This function is mainly for internal use, applications would typically
/// use `gst_missing_plugin_message_get_description()` to get a description of
/// a missing feature from a missing-plugin message.
/// ## `factory_name`
/// the name of the element, e.g. "giosrc"
///
/// # Returns
///
/// a newly-allocated description string. Free
///  string with `g_free()` when not needed any longer.
#[doc(alias = "gst_pb_utils_get_element_description")]
pub fn pb_utils_get_element_description(factory_name: &str) -> glib::GString {
    assert_initialized_main_thread!();
    unsafe {
        from_glib_full(ffi::gst_pb_utils_get_element_description(
            factory_name.to_glib_none().0,
        ))
    }
}

/// Returns a localised string describing a sink element handling the protocol
/// specified in `protocol`, for use in error dialogs or other messages to be
/// seen by the user.
///
/// This function is mainly for internal use, applications would typically
/// use `gst_missing_plugin_message_get_description()` to get a description of
/// a missing feature from a missing-plugin message.
/// ## `protocol`
/// the protocol the sink element needs to handle, e.g. "http"
///
/// # Returns
///
/// a newly-allocated description string. Free
///  string with `g_free()` when not needed any longer.
#[doc(alias = "gst_pb_utils_get_sink_description")]
pub fn pb_utils_get_sink_description(protocol: &str) -> glib::GString {
    assert_initialized_main_thread!();
    unsafe {
        from_glib_full(ffi::gst_pb_utils_get_sink_description(
            protocol.to_glib_none().0,
        ))
    }
}

/// Returns a localised string describing a source element handling the protocol
/// specified in `protocol`, for use in error dialogs or other messages to be
/// seen by the user.
///
/// This function is mainly for internal use, applications would typically
/// use `gst_missing_plugin_message_get_description()` to get a description of
/// a missing feature from a missing-plugin message.
/// ## `protocol`
/// the protocol the source element needs to handle, e.g. "http"
///
/// # Returns
///
/// a newly-allocated description string. Free
///  string with `g_free()` when not needed any longer.
#[doc(alias = "gst_pb_utils_get_source_description")]
pub fn pb_utils_get_source_description(protocol: &str) -> glib::GString {
    assert_initialized_main_thread!();
    unsafe {
        from_glib_full(ffi::gst_pb_utils_get_source_description(
            protocol.to_glib_none().0,
        ))
    }
}

/// Gets the version number of the GStreamer Plugins Base libraries.
///
/// # Returns
///
///
/// ## `major`
/// pointer to a guint to store the major version number, or [`None`]
///
/// ## `minor`
/// pointer to a guint to store the minor version number, or [`None`]
///
/// ## `micro`
/// pointer to a guint to store the micro version number, or [`None`]
///
/// ## `nano`
/// pointer to a guint to store the nano version number, or [`None`]
#[doc(alias = "gst_plugins_base_version")]
pub fn plugins_base_version() -> (u32, u32, u32, u32) {
    skip_assert_initialized!();
    unsafe {
        let mut major = std::mem::MaybeUninit::uninit();
        let mut minor = std::mem::MaybeUninit::uninit();
        let mut micro = std::mem::MaybeUninit::uninit();
        let mut nano = std::mem::MaybeUninit::uninit();
        ffi::gst_plugins_base_version(
            major.as_mut_ptr(),
            minor.as_mut_ptr(),
            micro.as_mut_ptr(),
            nano.as_mut_ptr(),
        );
        (
            major.assume_init(),
            minor.assume_init(),
            micro.assume_init(),
            nano.assume_init(),
        )
    }
}

/// This function returns a string that is useful for describing this version
/// of GStreamer's gst-plugins-base libraries to the outside world: user agent
/// strings, logging, about dialogs ...
///
/// # Returns
///
/// a newly allocated string describing this version of gst-plugins-base
#[doc(alias = "gst_plugins_base_version_string")]
pub fn plugins_base_version_string() -> glib::GString {
    skip_assert_initialized!();
    unsafe { from_glib_full(ffi::gst_plugins_base_version_string()) }
}