1#![cfg_attr(
17 not(any(target_os = "linux", target_os = "macos", target_os = "windows")),
18 allow(dead_code, unused_variables, clippy::needless_pass_by_value)
19)]
20
21#[cfg(target_os = "windows")]
22mod d3d12va;
23#[cfg(target_os = "macos")]
24mod videotoolbox;
25#[cfg(target_os = "linux")]
26mod vulkan;
27
28use std::sync::atomic::{AtomicU64, Ordering};
29
30use alpha2_media::{ColorMetadata, EncodeError, VideoRateControl};
31use alpha2_time::{FrameRate, MediaTime};
32
33#[cfg(all(test, target_os = "windows"))]
34pub(crate) use d3d12va::encode_no_rate_control_frames;
35#[cfg(target_os = "windows")]
36pub(crate) use d3d12va::probe_d3d12va_rate_control;
37#[cfg(target_os = "windows")]
38pub use d3d12va::{
39 D3D12EncodeProbe, D3D12RateControlOpen, D3D12RateControlRunner, D3D12TestEncodeRunner,
40 D3D12VA_TEST_ENCODE_SIZE, d3d12va_busy, d3d12va_encoder, d3d12va_timeouts,
41 open_d3d12va_rate_control, probe_d3d12va_encode, set_d3d12va_rate_control_runner,
42 set_d3d12va_test_encode_runner,
43};
44#[cfg(target_os = "macos")]
45pub use videotoolbox::{VideoToolboxEncodeProbe, probe_videotoolbox_encode};
46#[cfg(target_os = "linux")]
47pub(crate) use vulkan::probe_vulkan_rate_control;
48#[cfg(target_os = "linux")]
49pub use vulkan::{VulkanEncodeProbe, probe_vulkan_encode};
50
51use crate::{EncodeStageTimings, NativeVideoCodec, NativeVideoEncoderSelection};
52
53#[derive(Copy, Clone, Debug, Eq, PartialEq)]
55pub enum HardwareEncodeBackend {
56 Vulkan,
58 VideoToolbox,
60 D3D12Va,
62}
63
64impl HardwareEncodeBackend {
65 #[must_use]
67 pub const fn as_str(self) -> &'static str {
68 match self {
69 Self::Vulkan => "vulkan",
70 Self::VideoToolbox => "videotoolbox",
71 Self::D3D12Va => "d3d12va",
72 }
73 }
74}
75
76#[derive(Copy, Clone, Debug, Eq, PartialEq)]
78pub enum EncoderInputLayout {
79 Nv12,
81}
82
83impl EncoderInputLayout {
84 #[must_use]
86 pub const fn as_str(self) -> &'static str {
87 match self {
88 Self::Nv12 => "nv12",
89 }
90 }
91
92 #[must_use]
94 pub const fn frame_bytes(self, width: u32, height: u32) -> u64 {
95 match self {
96 Self::Nv12 => {
97 let luma = width as u64 * height as u64;
98 luma + luma / 2
99 }
100 }
101 }
102}
103
104#[derive(Copy, Clone, Debug, Eq, PartialEq)]
106pub enum EncoderInputHandoff {
107 GpuCopy,
109 DirectTarget,
111}
112
113impl EncoderInputHandoff {
114 #[must_use]
116 pub const fn as_str(self) -> &'static str {
117 match self {
118 Self::GpuCopy => "gpu-copy",
119 Self::DirectTarget => "direct-target",
120 }
121 }
122}
123
124#[derive(Clone, Debug, Eq, PartialEq)]
126pub struct HardwareEncodeCapability {
127 pub backend: HardwareEncodeBackend,
129 pub encoder: &'static str,
131 pub codec: NativeVideoCodec,
133 pub gpu_input_only: bool,
136 pub input_layout: EncoderInputLayout,
138 pub handoff: EncoderInputHandoff,
140 pub shares_renderer_device: bool,
143 pub minimum: (u32, u32),
145 pub maximum: (u32, u32),
147 pub granularity: (u32, u32),
149 pub max_p_picture_l0_references: Option<u32>,
151 pub max_b_picture_l0_references: Option<u32>,
154 pub max_l1_references: Option<u32>,
156 pub rate_control_modes: Vec<&'static str>,
159 pub plane_ring_slots: usize,
162 pub handoff_retained_surfaces: usize,
165 pub codec_retained_surfaces: usize,
167 pub default_channel_depth: usize,
170}
171
172impl HardwareEncodeCapability {
173 #[must_use]
175 pub const fn retained_surfaces(&self) -> usize {
176 self.handoff_retained_surfaces
177 .saturating_add(self.codec_retained_surfaces)
178 }
179}
180
181impl HardwareEncodeCapability {
182 #[must_use]
184 pub const fn coded(&self, width: u32, height: u32) -> (u32, u32) {
185 (
186 align_up(width, self.granularity.0),
187 align_up(height, self.granularity.1),
188 )
189 }
190
191 pub fn accepts(&self, width: u32, height: u32) -> Result<(), String> {
196 if !width.is_multiple_of(2) || !height.is_multiple_of(2) {
197 return Err(format!(
198 "a {width}x{height} output has no 4:2:0 chroma plane"
199 ));
200 }
201 let coded = self.coded(width, height);
202 if coded.0 < self.minimum.0
203 || coded.1 < self.minimum.1
204 || coded.0 > self.maximum.0
205 || coded.1 > self.maximum.1
206 {
207 return Err(format!(
208 "a {width}x{height} output codes as {}x{}, outside {}'s {}x{}..{}x{}",
209 coded.0,
210 coded.1,
211 self.encoder,
212 self.minimum.0,
213 self.minimum.1,
214 self.maximum.0,
215 self.maximum.1
216 ));
217 }
218 Ok(())
219 }
220}
221
222const fn align_up(value: u32, granularity: u32) -> u32 {
223 if granularity <= 1 {
224 return value;
225 }
226 value.div_ceil(granularity).saturating_mul(granularity)
227}
228
229#[derive(Clone)]
231pub struct HardwareEncodeDevice {
232 #[cfg(target_os = "linux")]
233 vulkan: alpha2_native_gpu::SharedVulkanContext,
234 #[cfg(target_os = "macos")]
235 metal: alpha2_native_gpu::SharedMetalContext,
236 #[cfg(target_os = "windows")]
237 d3d12: alpha2_native_gpu::SharedD3D12Context,
238}
239
240impl std::fmt::Debug for HardwareEncodeDevice {
241 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
242 formatter
243 .debug_struct("HardwareEncodeDevice")
244 .finish_non_exhaustive()
245 }
246}
247
248#[derive(Clone, Debug)]
250pub struct HardwareEncodeRequest<'a> {
251 pub width: u32,
253 pub height: u32,
255 pub codec: NativeVideoCodec,
257 pub frame_rate: FrameRate,
259 pub rate_control: VideoRateControl,
261 pub color: ColorMetadata,
263 pub output: &'a crate::OutputTarget,
266 pub container: alpha2_media::Container,
268 pub audio: Option<crate::AudioStreamConfig>,
270}
271
272pub(crate) fn session_frame_rate(rate: FrameRate) -> Result<(i32, i32), EncodeError> {
275 match (
276 i32::try_from(rate.numerator()),
277 i32::try_from(rate.denominator()),
278 ) {
279 (Ok(numerator), Ok(denominator)) => Ok((numerator, denominator)),
280 _ => Err(EncodeError::Adapter(format!(
281 "frame rate {}/{} is out of range",
282 rate.numerator(),
283 rate.denominator()
284 ))),
285 }
286}
287
288#[cfg(any(target_os = "linux", target_os = "macos"))]
291fn open_refusal(
292 encoder: &str,
293 mark: alpha2_ffmpeg_bridge::LogMark,
294 error: &EncodeError,
295) -> HardwareEncodeOpenError {
296 let lines = alpha2_ffmpeg_bridge::log_since(mark, &[encoder]);
297 let error = error.to_string();
298 let reason = format!("{error}{}", alpha2_ffmpeg_bridge::log_detail(&lines));
299 match crate::capabilities::classify_open_failure(encoder, &error, &lines) {
300 alpha2_media::OpenFailureKind::Busy => HardwareEncodeOpenError::Busy(reason),
301 _ => HardwareEncodeOpenError::Refused(reason),
302 }
303}
304
305#[derive(Debug)]
307pub enum HardwareEncodeOpenError {
308 Refused(String),
310 Busy(String),
313 Failed(EncodeError),
315}
316
317impl std::fmt::Display for HardwareEncodeOpenError {
318 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
319 match self {
320 Self::Refused(reason) | Self::Busy(reason) => formatter.write_str(reason),
321 Self::Failed(error) => write!(formatter, "{error}"),
322 }
323 }
324}
325
326impl HardwareEncodeDevice {
327 #[cfg(target_os = "linux")]
329 #[must_use]
330 pub const fn vulkan(context: alpha2_native_gpu::SharedVulkanContext) -> Self {
331 Self { vulkan: context }
332 }
333
334 #[cfg(target_os = "macos")]
336 #[must_use]
337 pub const fn metal(context: alpha2_native_gpu::SharedMetalContext) -> Self {
338 Self { metal: context }
339 }
340
341 #[cfg(target_os = "windows")]
343 #[must_use]
344 pub const fn d3d12(context: alpha2_native_gpu::SharedD3D12Context) -> Self {
345 Self { d3d12: context }
346 }
347
348 #[cfg_attr(
355 not(any(target_os = "linux", target_os = "macos", target_os = "windows")),
356 allow(clippy::unused_self)
357 )]
358 pub fn capability(&self, codec: NativeVideoCodec) -> Result<HardwareEncodeCapability, String> {
359 #[cfg(target_os = "windows")]
360 return d3d12va::capability(&self.d3d12, codec);
361 #[cfg(target_os = "linux")]
362 return vulkan::capability(&self.vulkan, codec);
363 #[cfg(target_os = "macos")]
364 {
365 let capability = self.preferred_capability()?;
366 if capability.codec == codec {
367 Ok(capability)
368 } else {
369 Err(format!(
370 "{} encodes {}, not {}",
371 capability.encoder,
372 capability.codec.as_str(),
373 codec.as_str()
374 ))
375 }
376 }
377 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
378 Err("this platform has no hardware encode backend yet".to_owned())
379 }
380
381 #[cfg_attr(
387 not(any(target_os = "linux", target_os = "macos", target_os = "windows")),
388 allow(clippy::unused_self)
389 )]
390 pub fn preferred_capability(&self) -> Result<HardwareEncodeCapability, String> {
391 #[cfg(target_os = "linux")]
392 return vulkan::preferred_capability(&self.vulkan);
393 #[cfg(target_os = "macos")]
394 return videotoolbox::capability(&self.metal);
395 #[cfg(target_os = "windows")]
396 return d3d12va::preferred_capability(&self.d3d12);
397 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
398 Err("this platform has no hardware encode backend yet".to_owned())
399 }
400
401 #[cfg_attr(
407 not(any(target_os = "linux", target_os = "macos", target_os = "windows")),
408 allow(clippy::unused_self)
409 )]
410 pub fn open(
411 &self,
412 request: &HardwareEncodeRequest<'_>,
413 ) -> Result<(HardwareEncodeSession, HardwareEncodeInput), HardwareEncodeOpenError> {
414 let generation = NEXT_POOL_GENERATION.fetch_add(1, Ordering::Relaxed);
415 #[cfg(any(target_os = "linux", target_os = "macos"))]
417 self.capability(request.codec)
418 .map_err(HardwareEncodeOpenError::Refused)?;
419 #[cfg(target_os = "linux")]
420 {
421 let (session, input) = vulkan::open(&self.vulkan, request, generation)?;
422 Ok((
423 HardwareEncodeSession(SessionBackend::Vulkan(session)),
424 HardwareEncodeInput {
425 backend: InputBackend::Vulkan(input),
426 generation,
427 },
428 ))
429 }
430 #[cfg(target_os = "macos")]
431 {
432 let (session, input) = videotoolbox::open(&self.metal, request, generation)?;
433 Ok((
434 HardwareEncodeSession(SessionBackend::VideoToolbox(session)),
435 HardwareEncodeInput {
436 backend: InputBackend::VideoToolbox(input),
437 generation,
438 },
439 ))
440 }
441 #[cfg(target_os = "windows")]
442 {
443 let (session, input) = d3d12va::open(&self.d3d12, request, generation)?;
444 Ok((
445 HardwareEncodeSession(SessionBackend::D3D12(session)),
446 HardwareEncodeInput {
447 backend: InputBackend::D3D12(input),
448 generation,
449 },
450 ))
451 }
452 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
453 {
454 let _ = (request, generation);
455 Err(HardwareEncodeOpenError::Refused(
456 "this platform has no hardware encode backend yet".to_owned(),
457 ))
458 }
459 }
460}
461
462static NEXT_POOL_GENERATION: AtomicU64 = AtomicU64::new(1);
465
466#[derive(Copy, Clone, Debug, Eq, PartialEq)]
468pub struct EncoderSurfaceDescriptor {
469 pub backend: HardwareEncodeBackend,
471 pub pool_generation: u64,
473 pub layout: EncoderInputLayout,
475 pub visible: (u32, u32),
477 pub color: ColorMetadata,
479}
480
481pub struct EncoderSurface {
486 descriptor: EncoderSurfaceDescriptor,
487 backing: SurfaceBacking,
488}
489
490enum SurfaceBacking {
491 #[cfg(target_os = "linux")]
492 Vulkan(vulkan::VulkanEncoderFrame),
493 #[cfg(target_os = "macos")]
494 VideoToolbox(videotoolbox::VideoToolboxEncoderFrame),
495 #[cfg(target_os = "windows")]
496 D3D12(d3d12va::D3D12EncoderFrame),
497 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
498 Unsupported(std::convert::Infallible),
499}
500
501impl EncoderSurface {
502 #[must_use]
504 pub const fn descriptor(&self) -> &EncoderSurfaceDescriptor {
505 &self.descriptor
506 }
507}
508
509#[must_use = "a begun frame must be submitted, or its planes stay claimed"]
511pub struct InputFrame {
512 #[cfg(any(target_os = "linux", target_os = "windows"))]
514 slot: usize,
515 #[cfg(target_os = "macos")]
517 pixel_buffer: usize,
518}
519
520#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
522pub struct EncoderPoolStats {
523 pub acquired: u64,
525 pub allocated: u64,
528 pub copy_operations: u64,
530 pub copy_bytes: u64,
532}
533
534pub struct HardwareEncodeInput {
536 backend: InputBackend,
537 generation: u64,
538}
539
540enum InputBackend {
541 #[cfg(target_os = "linux")]
542 Vulkan(vulkan::VulkanEncodeInput),
543 #[cfg(target_os = "macos")]
544 VideoToolbox(videotoolbox::VideoToolboxEncodeInput),
545 #[cfg(target_os = "windows")]
546 D3D12(d3d12va::D3D12EncodeInput),
547 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
548 Unsupported(std::convert::Infallible),
549}
550
551impl HardwareEncodeInput {
552 pub fn acquire_surface(&mut self) -> Result<EncoderSurface, EncodeError> {
559 match &mut self.backend {
560 #[cfg(target_os = "linux")]
561 InputBackend::Vulkan(input) => {
562 let frame = input.acquire_frame()?;
563 Ok(EncoderSurface {
564 descriptor: input.descriptor(self.generation),
565 backing: SurfaceBacking::Vulkan(frame),
566 })
567 }
568 #[cfg(target_os = "macos")]
569 InputBackend::VideoToolbox(input) => {
570 let frame = input.acquire_frame()?;
571 Ok(EncoderSurface {
572 descriptor: input.descriptor(self.generation),
573 backing: SurfaceBacking::VideoToolbox(frame),
574 })
575 }
576 #[cfg(target_os = "windows")]
577 InputBackend::D3D12(input) => {
578 let frame = input.acquire_frame()?;
579 Ok(EncoderSurface {
580 descriptor: input.descriptor(self.generation),
581 backing: SurfaceBacking::D3D12(frame),
582 })
583 }
584 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
585 InputBackend::Unsupported(never) => match *never {},
586 }
587 }
588
589 pub fn begin_frame(&mut self, surface: &EncoderSurface) -> Result<InputFrame, EncodeError> {
596 self.check(surface)?;
597 match &mut self.backend {
598 #[cfg(target_os = "linux")]
599 InputBackend::Vulkan(input) => input.begin_frame(),
600 #[cfg(target_os = "macos")]
601 InputBackend::VideoToolbox(input) => match &surface.backing {
602 SurfaceBacking::VideoToolbox(backing) => input.begin_frame(backing),
603 },
604 #[cfg(target_os = "windows")]
605 InputBackend::D3D12(input) => input.begin_frame(),
606 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
607 InputBackend::Unsupported(never) => match *never {},
608 }
609 }
610
611 #[must_use]
613 pub fn planes(&self, frame: &InputFrame) -> (&wgpu::Texture, &wgpu::Texture) {
614 match &self.backend {
615 #[cfg(target_os = "linux")]
616 InputBackend::Vulkan(input) => input.planes(frame),
617 #[cfg(target_os = "macos")]
618 InputBackend::VideoToolbox(input) => input.planes(frame),
619 #[cfg(target_os = "windows")]
620 InputBackend::D3D12(input) => input.planes(frame),
621 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
622 InputBackend::Unsupported(never) => match *never {},
623 }
624 }
625
626 pub fn submit(
632 &mut self,
633 frame: InputFrame,
634 surface: &mut EncoderSurface,
635 ) -> Result<(), EncodeError> {
636 self.check(surface)?;
637 match (&mut self.backend, &mut surface.backing) {
638 #[cfg(target_os = "linux")]
639 (InputBackend::Vulkan(input), SurfaceBacking::Vulkan(backing)) => {
640 input.submit(frame, backing)
641 }
642 #[cfg(target_os = "macos")]
643 (InputBackend::VideoToolbox(input), SurfaceBacking::VideoToolbox(backing)) => {
644 input.submit(frame, backing)
645 }
646 #[cfg(target_os = "windows")]
647 (InputBackend::D3D12(input), SurfaceBacking::D3D12(backing)) => {
648 input.submit(frame, backing)
649 }
650 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
651 (InputBackend::Unsupported(never), _) => match *never {},
652 }
653 }
654
655 pub fn set_time(&self, surface: &mut EncoderSurface, time: MediaTime) {
657 match (&self.backend, &mut surface.backing) {
658 #[cfg(target_os = "linux")]
659 (InputBackend::Vulkan(input), SurfaceBacking::Vulkan(backing)) => {
660 backing.set_pts(input.timestamp(time));
661 }
662 #[cfg(target_os = "macos")]
663 (InputBackend::VideoToolbox(input), SurfaceBacking::VideoToolbox(backing)) => {
664 backing.set_pts(input.timestamp(time));
665 }
666 #[cfg(target_os = "windows")]
667 (InputBackend::D3D12(input), SurfaceBacking::D3D12(backing)) => {
668 backing.set_pts(input.timestamp(time));
669 }
670 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
671 (InputBackend::Unsupported(never), _) => match *never {},
672 }
673 }
674
675 #[must_use]
677 pub fn stats(&self) -> EncoderPoolStats {
678 match &self.backend {
679 #[cfg(target_os = "linux")]
680 InputBackend::Vulkan(input) => input.stats(),
681 #[cfg(target_os = "macos")]
682 InputBackend::VideoToolbox(input) => input.stats(),
683 #[cfg(target_os = "windows")]
684 InputBackend::D3D12(input) => input.stats(),
685 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
686 InputBackend::Unsupported(never) => match *never {},
687 }
688 }
689
690 pub fn finish(self) -> Result<(), EncodeError> {
695 match self.backend {
696 #[cfg(target_os = "linux")]
697 InputBackend::Vulkan(input) => input.finish(),
698 #[cfg(target_os = "macos")]
699 InputBackend::VideoToolbox(input) => input.finish(),
700 #[cfg(target_os = "windows")]
701 InputBackend::D3D12(input) => input.finish(),
702 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
703 InputBackend::Unsupported(never) => match never {},
704 }
705 }
706
707 fn check(&self, surface: &EncoderSurface) -> Result<(), EncodeError> {
708 if surface.descriptor.pool_generation == self.generation {
709 Ok(())
710 } else {
711 Err(EncodeError::Adapter(format!(
712 "encoder surface from pool {} reached pool {}",
713 surface.descriptor.pool_generation, self.generation
714 )))
715 }
716 }
717}
718
719pub struct HardwareEncodeSession(SessionBackend);
721
722enum SessionBackend {
723 #[cfg(target_os = "linux")]
724 Vulkan(vulkan::VulkanEncodeSession),
725 #[cfg(target_os = "macos")]
726 VideoToolbox(videotoolbox::VideoToolboxEncodeSession),
727 #[cfg(target_os = "windows")]
728 D3D12(d3d12va::D3D12EncodeSession),
729 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
730 Unsupported(std::convert::Infallible),
731}
732
733impl HardwareEncodeSession {
734 #[must_use]
736 pub fn selection(&self) -> &NativeVideoEncoderSelection {
737 match &self.0 {
738 #[cfg(target_os = "linux")]
739 SessionBackend::Vulkan(session) => session.selection(),
740 #[cfg(target_os = "macos")]
741 SessionBackend::VideoToolbox(session) => session.selection(),
742 #[cfg(target_os = "windows")]
743 SessionBackend::D3D12(session) => session.selection(),
744 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
745 SessionBackend::Unsupported(never) => match *never {},
746 }
747 }
748
749 #[must_use]
751 pub fn stage_timings(&self) -> EncodeStageTimings {
752 match &self.0 {
753 #[cfg(target_os = "linux")]
754 SessionBackend::Vulkan(session) => session.stage_timings(),
755 #[cfg(target_os = "macos")]
756 SessionBackend::VideoToolbox(session) => session.stage_timings(),
757 #[cfg(target_os = "windows")]
758 SessionBackend::D3D12(session) => session.stage_timings(),
759 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
760 SessionBackend::Unsupported(never) => match *never {},
761 }
762 }
763
764 pub fn encode(&mut self, surface: &EncoderSurface) -> Result<(), EncodeError> {
769 match (&mut self.0, &surface.backing) {
770 #[cfg(target_os = "linux")]
771 (SessionBackend::Vulkan(session), SurfaceBacking::Vulkan(frame)) => {
772 session.encode(surface.descriptor.pool_generation, frame)
773 }
774 #[cfg(target_os = "macos")]
775 (SessionBackend::VideoToolbox(session), SurfaceBacking::VideoToolbox(frame)) => {
776 session.encode(surface.descriptor.pool_generation, frame)
777 }
778 #[cfg(target_os = "windows")]
779 (SessionBackend::D3D12(session), SurfaceBacking::D3D12(frame)) => {
780 session.encode(surface.descriptor.pool_generation, frame)
781 }
782 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
783 (SessionBackend::Unsupported(never), _) => match *never {},
784 }
785 }
786
787 pub fn write_audio(&mut self, block: &alpha2_media::AudioBlock) -> Result<(), EncodeError> {
792 match &mut self.0 {
793 #[cfg(target_os = "linux")]
794 SessionBackend::Vulkan(session) => session.write_audio(block),
795 #[cfg(target_os = "macos")]
796 SessionBackend::VideoToolbox(session) => session.write_audio(block),
797 #[cfg(target_os = "windows")]
798 SessionBackend::D3D12(session) => session.write_audio(block),
799 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
800 SessionBackend::Unsupported(never) => match *never {},
801 }
802 }
803
804 pub fn finish(&mut self, cancel: &alpha2_media::CancelToken) -> Result<(), EncodeError> {
811 match &mut self.0 {
812 #[cfg(target_os = "linux")]
813 SessionBackend::Vulkan(session) => session.finish(cancel),
814 #[cfg(target_os = "macos")]
815 SessionBackend::VideoToolbox(session) => session.finish(cancel),
816 #[cfg(target_os = "windows")]
817 SessionBackend::D3D12(session) => session.finish(cancel),
818 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
819 SessionBackend::Unsupported(never) => match *never {},
820 }
821 }
822
823 #[must_use]
825 pub fn publish_report(&self) -> Option<crate::PublishReport> {
826 match &self.0 {
827 #[cfg(target_os = "linux")]
828 SessionBackend::Vulkan(session) => session.publish_report(),
829 #[cfg(target_os = "macos")]
830 SessionBackend::VideoToolbox(session) => session.publish_report(),
831 #[cfg(target_os = "windows")]
832 SessionBackend::D3D12(session) => session.publish_report(),
833 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
834 SessionBackend::Unsupported(never) => match *never {},
835 }
836 }
837
838 pub fn abort(&mut self) {
840 match &mut self.0 {
841 #[cfg(target_os = "linux")]
842 SessionBackend::Vulkan(session) => session.abort(),
843 #[cfg(target_os = "macos")]
844 SessionBackend::VideoToolbox(session) => session.abort(),
845 #[cfg(target_os = "windows")]
846 SessionBackend::D3D12(session) => session.abort(),
847 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
848 SessionBackend::Unsupported(never) => match *never {},
849 }
850 }
851}