vpx_rs/
common.rs

1/*
2 * Copyright (c) 2025, Saso Kiselkov. All rights reserved.
3 *
4 * Use of this source code is governed by the 2-clause BSD license,
5 * which can be found in a file named LICENSE, located at the root
6 * of this source tree.
7 */
8
9/// Stream information retrieved from either an `Encoder` or `Decoder` instance.
10#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
11pub struct StreamInfo {
12    /// The stream's display width in pixels.
13    pub width: u32,
14    /// The stream's display height in pixels.
15    pub height: u32,
16    /// True if the returned decoded frame will be a keyframe.
17    pub is_keyframe: bool,
18}
19
20impl From<vpx_sys::vpx_codec_stream_info> for StreamInfo {
21    fn from(value: vpx_sys::vpx_codec_stream_info) -> Self {
22        Self {
23            width: value.w,
24            height: value.h,
25            is_keyframe: value.is_kf != 0,
26        }
27    }
28}
29
30pub(crate) fn get_stream_info(
31    ctx: &mut vpx_sys::vpx_codec_ctx,
32) -> Option<StreamInfo> {
33    let mut si = vpx_sys::vpx_codec_stream_info {
34        sz: size_of::<vpx_sys::vpx_codec_stream_info>() as _,
35        w: 0,
36        h: 0,
37        is_kf: 0,
38    };
39    let error = unsafe { vpx_sys::vpx_codec_get_stream_info(ctx, &mut si) };
40    (error == vpx_sys::VPX_CODEC_OK).then(|| si.into())
41}