Skip to main content

zng_view_api/
video.rs

1//! Video types.
2//!
3//! # Under Development
4//!
5//! This API is not ready yet, the types here are only the basics to
6//! avoid a breaking change release when video is implemented.
7
8use serde::{Deserialize, Serialize};
9use zng_txt::Txt;
10
11crate::declare_id! {
12    /// Id of a decoded or streaming video in the cache.
13    ///
14    /// The View Process defines the ID.
15    pub struct VideoId(_);
16
17    /// Id of a video playing in a renderer.
18    ///
19    /// The View Process defines the ID.
20    pub struct VideoTextureId(_);
21
22    /// Id of a video encode task.
23    ///
24    /// The View Process defines the ID.
25    pub struct VideoEncodeId(_);
26}
27
28/// Represents a video load/decode request.
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[non_exhaustive]
31pub struct VideoRequest<D> {
32    /// Video data format.
33    pub format: VideoDataFormat,
34
35    /// Video data.
36    ///
37    /// Bytes layout depends on the `format`, data structure is [`IpcReadHandle`] or [`IpcReceiver<IpcBytes>`] in the view API.
38    ///
39    /// [`IpcReadHandle`]: zng_task::channel::IpcReadHandle
40    /// [`IpcReceiver<IpcBytes>`]: zng_task::channel::IpcReceiver
41    pub data: D,
42}
43
44/// Format of the video bytes.
45#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
46#[non_exhaustive]
47pub enum VideoDataFormat {
48    /// The video is encoded.
49    ///
50    /// This file extension maybe identifies the format. Fallback to `Unknown` handling if the file extension
51    /// is unknown or the file header does not match.
52    FileExtension(Txt),
53
54    /// The video is encoded.
55    ///
56    /// This MIME type maybe identifies the format. Fallback to `Unknown` handling if the file extension
57    /// is unknown or the file header does not match.
58    MimeType(Txt),
59
60    /// The image is encoded.
61    ///
62    /// A decoder will be selected using the "magic number" at the start of the bytes buffer.
63    Unknown,
64}