pub struct MacOsDecoder { /* private fields */ }Expand description
Low-latency H.264/H.265 decoder backed by macOS VideoToolbox.
Implementations§
Source§impl MacOsDecoder
impl MacOsDecoder
Sourcepub fn new(options: DecoderOptions) -> Result<Self, VideoError>
pub fn new(options: DecoderOptions) -> Result<Self, VideoError>
Create a VideoToolbox decoder using the supplied latency policy.
Examples found in repository?
examples/decode_access_unit.rs (lines 30-33)
2fn main() -> Result<(), Box<dyn std::error::Error>> {
3 use std::{
4 env, fs, thread,
5 time::{Duration, Instant},
6 };
7
8 use openipc_video::{
9 DecoderOptions, EncodedAccessUnit, PlatformDecoder, VideoCodec, VideoDecoder,
10 VideoTimestamp,
11 };
12
13 let mut args = env::args().skip(1);
14 let codec =
15 match args.next().as_deref() {
16 Some("h264") => VideoCodec::H264,
17 Some("h265") | Some("hevc") => VideoCodec::H265,
18 _ => return Err(
19 "usage: decode_access_unit <h264|h265> <annex-b-access-unit> [--allow-software]"
20 .into(),
21 ),
22 };
23 let path = args
24 .next()
25 .ok_or("usage: decode_access_unit <h264|h265> <annex-b-access-unit> [--allow-software]")?;
26 let allow_software = args.any(|argument| argument == "--allow-software");
27 let data = fs::read(path)?;
28 let capabilities = PlatformDecoder::probe_capabilities();
29 println!("capabilities={capabilities:?}");
30 let mut decoder = PlatformDecoder::new(DecoderOptions {
31 require_hardware: !allow_software,
32 ..DecoderOptions::default()
33 })?;
34 let outcome = decoder.submit(EncodedAccessUnit::new(
35 codec,
36 data,
37 VideoTimestamp::from_rtp(0),
38 true,
39 ))?;
40 println!("submit={outcome:?}");
41
42 let deadline = Instant::now() + Duration::from_secs(1);
43 while Instant::now() < deadline {
44 if let Some(frame) = decoder.latest_frame() {
45 let dimensions = frame.dimensions();
46 println!(
47 "decoded={}x{} pixel_format={:?}",
48 dimensions.width,
49 dimensions.height,
50 openipc_video::DecodedSurface::pixel_format(&frame.surface),
51 );
52 #[cfg(target_os = "macos")]
53 println!("iosurface={}", frame.surface.is_io_surface_backed());
54 #[cfg(target_os = "linux")]
55 println!(
56 "drm_fourcc={:#010x} pitches={:?}",
57 frame.surface.drm_fourcc(),
58 frame.surface.plane_pitches()
59 );
60 #[cfg(target_os = "windows")]
61 println!(
62 "d3d11_subresource={} texture={:?}",
63 frame.surface.subresource_index(),
64 frame.surface.texture()
65 );
66 return Ok(());
67 }
68 thread::sleep(Duration::from_millis(2));
69 }
70 Err(format!("no decoded frame; stats={:?}", decoder.stats()).into())
71}Sourcepub fn probe_capabilities() -> DecoderCapabilities
pub fn probe_capabilities() -> DecoderCapabilities
Query VideoToolbox H.264 and H.265 hardware support.
Examples found in repository?
examples/decode_access_unit.rs (line 28)
2fn main() -> Result<(), Box<dyn std::error::Error>> {
3 use std::{
4 env, fs, thread,
5 time::{Duration, Instant},
6 };
7
8 use openipc_video::{
9 DecoderOptions, EncodedAccessUnit, PlatformDecoder, VideoCodec, VideoDecoder,
10 VideoTimestamp,
11 };
12
13 let mut args = env::args().skip(1);
14 let codec =
15 match args.next().as_deref() {
16 Some("h264") => VideoCodec::H264,
17 Some("h265") | Some("hevc") => VideoCodec::H265,
18 _ => return Err(
19 "usage: decode_access_unit <h264|h265> <annex-b-access-unit> [--allow-software]"
20 .into(),
21 ),
22 };
23 let path = args
24 .next()
25 .ok_or("usage: decode_access_unit <h264|h265> <annex-b-access-unit> [--allow-software]")?;
26 let allow_software = args.any(|argument| argument == "--allow-software");
27 let data = fs::read(path)?;
28 let capabilities = PlatformDecoder::probe_capabilities();
29 println!("capabilities={capabilities:?}");
30 let mut decoder = PlatformDecoder::new(DecoderOptions {
31 require_hardware: !allow_software,
32 ..DecoderOptions::default()
33 })?;
34 let outcome = decoder.submit(EncodedAccessUnit::new(
35 codec,
36 data,
37 VideoTimestamp::from_rtp(0),
38 true,
39 ))?;
40 println!("submit={outcome:?}");
41
42 let deadline = Instant::now() + Duration::from_secs(1);
43 while Instant::now() < deadline {
44 if let Some(frame) = decoder.latest_frame() {
45 let dimensions = frame.dimensions();
46 println!(
47 "decoded={}x{} pixel_format={:?}",
48 dimensions.width,
49 dimensions.height,
50 openipc_video::DecodedSurface::pixel_format(&frame.surface),
51 );
52 #[cfg(target_os = "macos")]
53 println!("iosurface={}", frame.surface.is_io_surface_backed());
54 #[cfg(target_os = "linux")]
55 println!(
56 "drm_fourcc={:#010x} pitches={:?}",
57 frame.surface.drm_fourcc(),
58 frame.surface.plane_pitches()
59 );
60 #[cfg(target_os = "windows")]
61 println!(
62 "d3d11_subresource={} texture={:?}",
63 frame.surface.subresource_index(),
64 frame.surface.texture()
65 );
66 return Ok(());
67 }
68 thread::sleep(Duration::from_millis(2));
69 }
70 Err(format!("no decoded frame; stats={:?}", decoder.stats()).into())
71}Trait Implementations§
Source§impl Drop for MacOsDecoder
impl Drop for MacOsDecoder
Source§impl VideoDecoder for MacOsDecoder
impl VideoDecoder for MacOsDecoder
Source§type Surface = MacOsVideoFrame
type Surface = MacOsVideoFrame
Native decoded surface type produced by this backend.
Source§fn capabilities(&self) -> DecoderCapabilities
fn capabilities(&self) -> DecoderCapabilities
Query decoder support on the current machine.
Source§fn configure(&mut self, config: CodecConfig) -> Result<(), VideoError>
fn configure(&mut self, config: CodecConfig) -> Result<(), VideoError>
Explicitly configure or reconfigure the platform decoder.
Source§fn submit(
&mut self,
frame: EncodedAccessUnit,
) -> Result<SubmitOutcome, VideoError>
fn submit( &mut self, frame: EncodedAccessUnit, ) -> Result<SubmitOutcome, VideoError>
Submit one complete encoded Annex-B access unit.
Source§fn latest_frame(&mut self) -> Option<DecodedFrame<Self::Surface>>
fn latest_frame(&mut self) -> Option<DecodedFrame<Self::Surface>>
Take the newest decoded frame, if one is ready.
Source§fn stats(&self) -> DecoderStats
fn stats(&self) -> DecoderStats
Read cumulative decoder statistics.
Auto Trait Implementations§
impl !Freeze for MacOsDecoder
impl !RefUnwindSafe for MacOsDecoder
impl !UnwindSafe for MacOsDecoder
impl Send for MacOsDecoder
impl Sync for MacOsDecoder
impl Unpin for MacOsDecoder
impl UnsafeUnpin for MacOsDecoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more