onix 0.1.0

Decode image files using V4L2
Documentation
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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
use crate::ioctl;
use crate::util;
use crate::vp8::{self, CtrlVp8Frame};
use crate::Request;
use bitflags::bitflags;
use core::ffi::CStr;
use core::fmt;
use nix::errno::Errno;
use std::fs::OpenOptions;
use std::io;
use std::os::fd::{AsFd, AsRawFd, BorrowedFd, OwnedFd, RawFd};
use std::os::raw::{c_char, c_long, c_void};
use std::path::Path;

bitflags! {
    /// Bitflags of capabilities for devices.  See also [`Capability`].
    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
    #[derive(Default)]
    pub struct CapsFlags: u32 {
        const VIDEO_CAPTURE = 0x00000001;
        const VIDEO_OUTPUT = 0x00000002;
        const VIDEO_OVERLAY = 0x00000004;

        const VBI_CAPTURE = 0x00000010;
        const VBI_OUTPUT = 0x00000020;
        const SLICED_VBI_CAPTURE = 0x00000040;
        const SLICED_VBI_OUTPUT = 0x00000080;

        const RDS_CAPTURE = 0x00000100;
        const VIDEO_OUTPUT_OVERLAY = 0x00000200;
        const HW_FREQ_SEEK = 0x00000400;
        const RDS_OUTPUT = 0x00000800;

        const VIDEO_CAPTURE_MPLANE = 0x00001000;
        const VIDEO_OUTPUT_MPLANE = 0x00002000;
        const VIDEO_M2M_MPLANE = 0x00004000;
        const VIDEO_M2M = 0x00008000;

        const TUNER = 0x00010000;
        const AUDIO = 0x00020000;
        const RADIO = 0x00040000;
        const MODULATOR = 0x00080000;

        const SDR_CAPTURE = 0x00100000;
        const EXT_PIX_FORMAT = 0x00200000;
        const SDR_OUTPUT = 0x00400000;
        const META_CAPTURE = 0x00800000;

        const READWRITE = 0x01000000;
        const ASYNCIO = 0x02000000;
        const STREAMING = 0x04000000;
        const META_OUTPUT = 0x08000000;

        const TOUCH = 0x10000000;
        const IO_MC = 0x20000000;
        const DEVICE_CAPS = 0x80000000;
    }
}

bitflags! {
    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
    #[derive(Default)]
    struct BufFlag: u32 {
        /// Buffer is mapped (flag)
        const MAPPED = 0x00000001;

        /// Buffer is queued for processing
        const QUEUED = 0x00000002;

        /// Buffer is ready
        const DONE = 0x00000004;

        /// Image is a keyframe (I-frame)
        const KEYFRAME = 0x00000008;

        /// Image is a P-frame
        const PFRAME = 0x00000010;

        /// Image is a B-frame
        const BFRAME = 0x00000020;

        /// Buffer is ready, but the data contained within is corrupted.
        const ERROR = 0x00000040;

        /// Buffer is added to an unqueued request
        const IN_REQUEST = 0x00000080;

        /// timecode field is valid
        const TIMECODE = 0x00000100;

        /// Don't return the capture buffer until OUTPUT timestamp changes
        const M2M_HOLD_CAPTURE_BUF = 0x00000200;

        /// Buffer is prepared for queuing
        const PREPARED = 0x00000400;

        /// Cache handling flags
        const NO_CACHE_INVALIDATE = 0x00000800;

        const NO_CACHE_CLEAN = 0x00001000;

        /// Timestamp type
        const TIMESTAMP_MASK = 0x0000e000;

        const TIMESTAMP_UNKNOWN = 0x00000000;

        const TIMESTAMP_MONOTONIC = 0x00002000;

        const TIMESTAMP_COPY = 0x00004000;

        /// Timestamp sources.
        const TSTAMP_SRC_MASK = 0x00070000;

        const TSTAMP_SRC_EOF = 0x00000000;

        const TSTAMP_SRC_SOE = 0x00010000;

        /// mem2mem encoder/decoder
        const LAST = 0x00100000;

        /// request_fd is valid
        const REQUEST_FD = 0x00800000;
    }
}

/// Struct containing some info about a video device. See [`Video::querycap()`].
#[derive(Default, Clone)]
#[repr(C)]
pub struct Capability {
    driver: [c_char; 16],
    card: [c_char; 32],
    bus_info: [c_char; 32],
    version: u32,
    capabilities: CapsFlags,
    device_caps: CapsFlags,
    reserved: [u32; 3],
}

impl fmt::Debug for Capability {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.debug_struct("Capability")
            .field("driver", &self.driver())
            .field("card", &self.card())
            .field("bus_info", &self.bus_info())
            .field("version", &self.version())
            .field("capabilities", &self.capabilities)
            .field("device_caps", &self.device_caps)
            .finish()
    }
}

impl Capability {
    // Safety: These from_utf8_unchecked() calls are safe, as the kernel will only ever give us
    // either ASCII or UTF-8.

    /// Get the driver name.
    pub fn driver(&self) -> &str {
        unsafe {
            let c_str = CStr::from_ptr(self.driver.as_ptr());
            std::str::from_utf8_unchecked(c_str.to_bytes())
        }
    }

    /// Get the card name.
    pub fn card(&self) -> &str {
        unsafe {
            let c_str = CStr::from_ptr(self.card.as_ptr());
            std::str::from_utf8_unchecked(c_str.to_bytes())
        }
    }

    /// Get the bus info.
    pub fn bus_info(&self) -> &str {
        unsafe {
            let c_str = CStr::from_ptr(self.bus_info.as_ptr());
            std::str::from_utf8_unchecked(c_str.to_bytes())
        }
    }

    /// Get the kernel version.
    pub fn version(&self) -> String {
        util::format_kernel_version(self.version)
    }

    /// Get the capabilities.
    pub fn capabilities(&self) -> CapsFlags {
        self.capabilities
    }

    /// Get the device capabilities.
    pub fn device_caps(&self) -> CapsFlags {
        self.device_caps
    }
}

bitflags! {
    /// Bitflags of capabilities for devices.  See also [`Capability`].
    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
    #[derive(Default)]
    pub struct FmtFlag: u32 {
        const COMPRESSED = 0x0001;
        const EMULATED = 0x0002;
        const CONTINUOUS_BYTESTREAM = 0x0004;
        const DYN_RESOLUTION = 0x0008;
        const ENC_CAP_FRAME_INTERVAL = 0x0010;
        const CSC_COLORSPACE = 0x0020;
        const CSC_XFER_FUNC = 0x0040;
        const CSC_YCBCR_ENC = 0x0080;
        const CSC_HSV_ENC = FmtFlag::CSC_YCBCR_ENC.bits();
        const CSC_QUANTIZATION = 0x0100;
    }
}

#[derive(Default, Clone)]
#[repr(C)]
pub struct FmtDesc {
    index: u32,
    type_: BufType,
    flags: FmtFlag,
    description: [c_char; 32],
    pixelformat: u32,
    mbus_code: u32,
    reserved: [u32; 3],
}

impl fmt::Debug for FmtDesc {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.debug_struct("FmtDesc")
            .field("index", &self.index)
            .field("type", &self.type_)
            .field("flags", &self.flags)
            .field("pixelformat", &self.pixelformat_to_string())
            .field("mbus_code", &self.mbus_code)
            .field("description", &self.description())
            .finish()
    }
}

impl FmtDesc {
    // Safety: These from_utf8_unchecked() calls are safe, as the kernel will only ever give us
    // either ASCII or UTF-8.

    pub fn description(&self) -> &str {
        unsafe {
            let c_str = CStr::from_ptr(self.description.as_ptr());
            std::str::from_utf8_unchecked(c_str.to_bytes())
        }
    }

    pub fn pixelformat_to_string(&self) -> String {
        let bytes = self.pixelformat.to_ne_bytes();
        unsafe { String::from_utf8_unchecked(bytes.to_vec()) }
    }

    pub fn pixelformat(&self) -> u32 {
        self.pixelformat
    }
}

/// Represents the type of a given buffer.
#[derive(Clone, Copy, Debug)]
#[repr(u32)]
pub enum BufType {
    /// This buffer is used to transfer data from the device to the user.
    VideoCapture = 1,

    /// This buffer is used to transfer data from the user to the device.
    VideoOutput = 2,

    /// This buffer is used to transfer data from the device to the user, but using the multi-planar API.
    VideoCaptureMplane = 9,

    /// This buffer is used to transfer data from the user to the device, but using the multi-planar API.
    VideoOutputMplane = 10,
    // TODO: …
}

impl Default for BufType {
    fn default() -> BufType {
        BufType::VideoCapture
    }
}

/// Where the memory of a given [`Buffer`] is stored and allocated from.
#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(u32)]
pub enum Memory {
    /// The kernel allocates this memory.
    Mmap = 1,

    /// Userland has to allocate this memory.
    UserPtr = 2,

    Overlay = 3,

    /// A device owns this memory.
    Dmabuf = 4,
}

impl Default for Memory {
    fn default() -> Memory {
        Memory::Mmap
    }
}

bitflags! {
    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
    #[derive(Default)]
    struct BufCap: u32 {
        const SUPPORTS_MMAP = 0x01;
        const SUPPORTS_USERPTR = 0x02;
        const SUPPORTS_DMABUF = 0x04;
        const SUPPORTS_REQUESTS = 0x08;
        const SUPPORTS_ORPHANED_BUFS = 0x10;
        const SUPPORTS_M2M_HOLD_CAPTURE_BUF = 0x20;
        const SUPPORTS_MMAP_CACHE_HINTS = 0x40;
    }
}

#[derive(Clone, Debug)]
#[repr(C)]
pub struct RequestBuffers {
    count: u32,
    type_: BufType,
    memory: Memory,
    capabilities: BufCap,
    flags: u8,
    reserved: [u8; 3],
}

// TODO: what about __USE_TIME_BITS64?
#[derive(Default, Clone, Debug)]
#[repr(C)]
struct Timeval {
    tv_sec: u64,
    tv_nsec: u64,
}

#[derive(Default, Clone, Debug)]
#[repr(C)]
struct Timespec {
    tv_sec: c_long,
    tv_nsec: c_long,
}

#[derive(Default, Clone, Debug)]
#[repr(C)]
struct Timecode {
    type_: u32,
    flags: u32,
    frames: u8,
    seconds: u8,
    minutes: u8,
    hours: u8,
    userbits: [u8; 4],
}

union M {
    offset: u32,
    userptr: usize,
    planes: *mut c_void,
    fd: RawFd,
}

impl Default for M {
    fn default() -> M {
        M { offset: 0 }
    }
}

impl fmt::Debug for M {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.debug_struct("M")
            .field("offset", &unsafe { self.offset })
            .finish()
    }
}

/// Struct representing a buffer, with which to interact with the kernel.
#[derive(Default, Debug)]
#[repr(C)]
pub struct Buffer {
    index: u32,
    type_: BufType,
    bytesused: u32,
    flags: BufFlag,
    field: u32,
    timestamp: Timeval,
    timecode: Timecode,
    sequence: u32,
    memory: Memory,
    m: M,
    length: u32,
    reserved2: u32,
    request_fd: RawFd,
}

impl Buffer {
    /// Create a new buffer of the given type.
    pub fn new(type_: BufType) -> Buffer {
        let mut buf = Buffer::default();
        buf.type_ = type_;
        buf.memory = Memory::Mmap;
        buf
    }

    /// Set a request fd to be passed alongside this buffer.
    pub fn set_request(&mut self, request: &Request) {
        self.flags |= BufFlag::REQUEST_FD;
        self.request_fd = request.as_raw_fd();
    }

    /// Set the bytesused field.
    pub fn set_bytesused(&mut self, bytesused: usize) {
        self.bytesused = bytesused as u32;
    }

    /// Get the bytesused field.
    pub fn bytesused(&mut self) -> u32 {
        self.bytesused
    }

    /// Get the length field.
    pub fn length(&self) -> u32 {
        self.length
    }

    /// Set the m.offset field.
    pub fn set_offset(&mut self, offset: u32) {
        self.m.offset = offset;
    }

    /// Determines whether there has been an error on this buffer.
    pub fn is_error(&self) -> bool {
        self.flags.contains(BufFlag::ERROR)
    }

    /// Get the m.offset field.
    pub fn offset(&self) -> u32 {
        assert_eq!(self.memory, Memory::Mmap);
        unsafe { self.m.offset }
    }

    /// Get the m.fd dmabuf.
    pub fn dmabuf(&self) -> RawFd {
        assert_eq!(self.memory, Memory::Dmabuf);
        unsafe { self.m.fd }
    }
}

/// Export of video buffer as DMABUF file descriptor.
#[derive(Debug)]
#[repr(C)]
pub struct ExportBuffer {
    type_: BufType,
    index: u32,
    plane: u32,
    flags: u32,
    fd: Option<OwnedFd>,
    reserved: [u32; 11],
}

impl ExportBuffer {
    pub fn new(type_: BufType, index: u32, flags: u32) -> ExportBuffer {
        ExportBuffer {
            type_,
            index,
            plane: 0,
            flags,
            fd: None,
            reserved: Default::default(),
        }
    }

    /// Borrow the fd.
    pub fn into_fd(self) -> OwnedFd {
        self.fd.unwrap()
    }
}

#[derive(Default, Clone, Copy, Debug)]
#[repr(C)]
struct PixFormat {
    width: u32,
    height: u32,
    pixelformat: u32,
    field: u32,
    bytesperline: u32,
    sizeimage: u32,
    colorspace: u32,
    priv_: u32,
    flags: u32,
    enc: u32,
    quantization: u32,
    xfer_func: u32,
}

#[cfg_attr(target_pointer_width = "32", repr(C))]
#[cfg_attr(target_pointer_width = "64", repr(C, align(8)))]
union Fmt {
    pix: PixFormat,
    raw_data: [u8; 200],
}

/// Represents a given format.
#[repr(C)]
pub struct Format {
    type_: BufType,
    fmt: Fmt,
}

impl fmt::Debug for Format {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.debug_struct("Format")
            .field("type", &self.type_)
            .field(
                "pix",
                &match self.type_ {
                    BufType::VideoCapture | BufType::VideoOutput => unsafe { self.fmt.pix },
                    type_ => todo!("Add multiplanar API for {type_:?}"),
                },
            )
            .finish()
    }
}

impl Format {
    /// Create a new format.
    pub fn new(
        type_: BufType,
        width: u32,
        height: u32,
        pixelformat: u32,
        sizeimage: u32,
    ) -> Format {
        match type_ {
            BufType::VideoCapture => {
                let fmt = Fmt {
                    pix: PixFormat {
                        width,
                        height,
                        pixelformat,
                        sizeimage,
                        ..Default::default()
                    },
                };
                Format { type_, fmt }
            }
            BufType::VideoOutput => {
                let fmt = Fmt {
                    pix: PixFormat {
                        width,
                        height,
                        pixelformat,
                        sizeimage,
                        ..Default::default()
                    },
                };
                Format { type_, fmt }
            }
            type_ => todo!("type: {:?}", type_),
        }
    }

    pub fn width(&self) -> u32 {
        unsafe { self.fmt.pix }.width
    }

    pub fn height(&self) -> u32 {
        unsafe { self.fmt.pix }.height
    }

    pub fn bytesperline(&self) -> u32 {
        unsafe { self.fmt.pix }.bytesperline
    }
}

#[derive(Clone, Debug)]
#[repr(C, packed)]
pub struct ExtControl {
    id: u32,
    size: u32,
    reserved: u32,
    vp8_frame: *mut CtrlVp8Frame,
}

impl ExtControl {
    pub fn new(id: u32, vp8_frame: *mut CtrlVp8Frame) -> ExtControl {
        let size = std::mem::size_of::<CtrlVp8Frame>() as u32;
        ExtControl {
            id,
            size,
            reserved: 0,
            vp8_frame,
        }
    }
}

#[derive(Clone, Debug)]
#[repr(C)]
pub struct ExtControls {
    which: u32,
    count: u32,
    error_idx: u32,
    request_fd: RawFd,
    reserved: u32,
    controls: *mut ExtControl,
}

impl ExtControls {
    pub fn new(request: Option<&Request>, count: u32, controls: *mut ExtControl) -> ExtControls {
        let (which, request_fd) = match request {
            Some(request) => (vp8::uapi::V4L2_CTRL_WHICH_REQUEST_VAL, request.as_raw_fd()),
            None => (vp8::uapi::V4L2_CTRL_WHICH_CUR_VAL, 0),
        };
        ExtControls {
            which,
            count,
            error_idx: 0,
            request_fd,
            reserved: 0,
            controls,
        }
    }
}

/// Represents a video device, such as `/dev/video0`.
pub struct Video {
    fd: OwnedFd,
}

impl AsFd for Video {
    fn as_fd(&self) -> BorrowedFd {
        self.fd.as_fd()
    }
}

impl Video {
    /// Opens a new file descriptor to the given video device file path.
    pub fn open<P: AsRef<Path>>(filename: P) -> io::Result<Video> {
        let file = OpenOptions::new().read(true).write(true).open(filename)?;
        let fd = file.into();
        Ok(Video { fd })
    }

    /// Query the capabilities of this video device.
    pub fn querycap(&self) -> Result<Capability, Errno> {
        let mut capability = Capability::default();
        unsafe { ioctl::querycap(self.fd.as_raw_fd(), &mut capability) }?;
        Ok(capability)
    }

    /// List the formats supported by this video device.
    pub fn enum_fmts(&self, type_: BufType) -> Result<Vec<FmtDesc>, Errno> {
        let mut vec = Vec::new();
        let mut fmt = FmtDesc::default();
        fmt.type_ = type_;
        loop {
            match unsafe { ioctl::enum_fmt(self.fd.as_raw_fd(), &mut fmt) } {
                Ok(_) => vec.push(fmt.clone()),
                Err(errno) if errno == Errno::EINVAL => break,
                Err(errno) => return Err(errno),
            }
            fmt.index += 1;
        }
        Ok(vec)
    }

    /// Set the input format.
    pub fn s_fmt(&self, format: &mut Format) -> Result<(), Errno> {
        unsafe { ioctl::s_fmt(self.fd.as_raw_fd(), format) }?;
        Ok(())
    }

    /// Allocate buffers.
    pub fn reqbufs(&self, memory: Memory, type_: BufType, count: usize) -> Result<(), Errno> {
        let count = count as u32;
        let mut buffers = RequestBuffers {
            memory,
            type_,
            count,
            capabilities: BufCap::empty(),
            flags: 0,
            reserved: Default::default(),
        };
        unsafe { ioctl::reqbufs(self.fd.as_raw_fd(), &mut buffers) }?;
        Ok(())
    }

    /// Query a buffer, previously allocated by reqbufs().
    pub fn querybuf(&self, buf: &mut Buffer) -> Result<(), Errno> {
        unsafe { ioctl::querybuf(self.fd.as_raw_fd(), buf) }?;
        Ok(())
    }

    /// Queue a buffer.
    pub fn qbuf(&self, buf: &mut Buffer) -> Result<(), Errno> {
        unsafe { ioctl::qbuf(self.fd.as_raw_fd(), buf) }?;
        Ok(())
    }

    /// Export a buffer.
    pub fn expbuf(&self, expbuf: &mut ExportBuffer) -> Result<(), Errno> {
        unsafe { ioctl::expbuf(self.fd.as_raw_fd(), expbuf) }?;
        Ok(())
    }

    /// Dequeue a buffer.
    pub fn dqbuf(&self, buf: &mut Buffer) -> Result<(), Errno> {
        unsafe { ioctl::dqbuf(self.fd.as_raw_fd(), buf) }?;
        Ok(())
    }

    /// Start streaming for a specific buffer type.
    pub fn streamon(&self, type_: BufType) -> Result<(), Errno> {
        unsafe { ioctl::streamon(self.fd.as_raw_fd(), &type_) }?;
        Ok(())
    }

    /// Stop streaming for a specific buffer type.
    pub fn streamoff(&self, type_: BufType) -> Result<(), Errno> {
        unsafe { ioctl::streamoff(self.fd.as_raw_fd(), &type_) }?;
        Ok(())
    }

    pub fn s_ext_ctrls(&self, ctrl: &mut ExtControls) -> Result<(), Errno> {
        unsafe { ioctl::s_ext_ctrls(self.fd.as_raw_fd(), ctrl) }?;
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    macro_rules! assert_size (
        ($t:ty, $sz:expr) => (
            assert_eq!(::std::mem::size_of::<$t>(), $sz);
        );
    );

    #[test]
    fn size() {
        assert_size!(Video, 4);
    }
}