mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-06-02 13:29:50 +00:00
0bb626c653
Useful complement to cea708overlay, that can only render native 708. The element isn't an aggregator, and simply parses and renders closed caption meta on its input video buffers. No property is exposed, the rendering is done using a monospace font, over a 32 x 15 grid with the font size fitted to fill as much of the viewport as possible. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/343>
72 lines
2 KiB
Rust
72 lines
2 KiB
Rust
// Copyright (C) 2020 Sebastian Dröge <sebastian@centricular.com>
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
// option. This file may not be copied, modified, or distributed
|
|
// except according to those terms.
|
|
|
|
use super::cea608tott_ffi as ffi;
|
|
use std::mem;
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
#[allow(unused)]
|
|
pub enum Status {
|
|
Ok,
|
|
Ready,
|
|
Clear,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
pub struct Error;
|
|
|
|
pub struct CaptionFrame(ffi::caption_frame_t);
|
|
|
|
unsafe impl Send for CaptionFrame {}
|
|
unsafe impl Sync for CaptionFrame {}
|
|
|
|
impl CaptionFrame {
|
|
pub fn new() -> Self {
|
|
unsafe {
|
|
let mut frame = mem::MaybeUninit::uninit();
|
|
ffi::caption_frame_init(frame.as_mut_ptr());
|
|
Self(frame.assume_init())
|
|
}
|
|
}
|
|
|
|
#[allow(unused)]
|
|
pub fn decode(&mut self, cc_data: u16, timestamp: f64) -> Result<Status, Error> {
|
|
unsafe {
|
|
let res = ffi::caption_frame_decode(&mut self.0, cc_data, timestamp);
|
|
match res {
|
|
ffi::libcaption_stauts_t_LIBCAPTION_OK => Ok(Status::Ok),
|
|
ffi::libcaption_stauts_t_LIBCAPTION_READY => Ok(Status::Ready),
|
|
ffi::libcaption_stauts_t_LIBCAPTION_CLEAR => Ok(Status::Clear),
|
|
_ => Err(Error),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[allow(unused)]
|
|
pub fn to_text(&self, full: bool) -> Result<String, Error> {
|
|
unsafe {
|
|
let mut data = Vec::with_capacity(ffi::CAPTION_FRAME_TEXT_BYTES as usize);
|
|
|
|
let len = ffi::caption_frame_to_text(
|
|
&self.0 as *const _ as *mut _,
|
|
data.as_ptr() as *mut _,
|
|
if full { 1 } else { 0 },
|
|
);
|
|
data.set_len(len as usize);
|
|
|
|
String::from_utf8(data).map_err(|_| Error)
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for CaptionFrame {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|