diff options
author | Mathieu Duponchelle <mathieu@centricular.com> | 2020-11-30 19:49:13 +0300 |
---|---|---|
committer | Mathieu Duponchelle <mathieu@centricular.com> | 2021-01-19 18:40:00 +0300 |
commit | 6267e00c20785ff637192f6a94c367f3e382ce90 (patch) | |
tree | a2be58aaf68c5dbf0e89a2cc8aa88b0e7273d6a3 | |
parent | a7180e3995295a7083d16f79b0f0bd45d4fa1cdc (diff) |
libcaption: implement eia608_to_text
-rw-r--r-- | video/closedcaption/src/c/eia608.c | 34 | ||||
-rw-r--r-- | video/closedcaption/src/c/eia608.h | 5 | ||||
-rw-r--r-- | video/closedcaption/src/ffi.rs | 7 |
3 files changed, 38 insertions, 8 deletions
diff --git a/video/closedcaption/src/c/eia608.c b/video/closedcaption/src/c/eia608.c index 9cb63f832..078d55bb3 100644 --- a/video/closedcaption/src/c/eia608.c +++ b/video/closedcaption/src/c/eia608.c @@ -23,6 +23,7 @@ /**********************************************************************************************/ #include "eia608.h" #include <stdio.h> +#include <stdlib.h> #include <string.h> //////////////////////////////////////////////////////////////////////////////// @@ -231,14 +232,16 @@ eia608_from_utf8_2 (const utf8_char_t * c1, const utf8_char_t * c2) } //////////////////////////////////////////////////////////////////////////////// -void -eia608_dump (uint16_t cc_data) + +int +eia608_to_text (char *buf, ssize_t size, uint16_t cc_data) { eia608_style_t style; const char *text = 0; char char1[5], char2[5]; char1[0] = char2[0] = 0; int row, col, chan, underline; + int ret; if (!eia608_parity_varify (cc_data)) { text = "parity failed"; @@ -260,11 +263,9 @@ eia608_dump (uint16_t cc_data) } else if (eia608_is_norpak (cc_data)) { text = "norpak"; } else if (eia608_is_preamble (cc_data)) { - text = "preamble"; eia608_parse_preamble (cc_data, &row, &col, &style, &chan, &underline); - fprintf (stderr, "preamble %d %d %d %d %d\n", row, col, style, chan, - underline); - + ret = snprintf(buf, size, "cc %04X (%04X) '%s' '%s' (preamble: row: %d col: %d style: %d chan: %d underline: %d)", + cc_data, eia608_parity_strip (cc_data), char1, char2, row, col, style, chan, underline); } else if (eia608_is_control (cc_data)) { switch (eia608_parse_control (cc_data, &chan)) { @@ -352,6 +353,23 @@ eia608_dump (uint16_t cc_data) text = "unhandled"; } - fprintf (stderr, "cc %04X (%04X) '%s' '%s' (%s)\n", cc_data, - eia608_parity_strip (cc_data), char1, char2, text); + if (text != 0) { + ret = snprintf (buf, size, "cc %04X (%04X) '%s' '%s' (%s)", cc_data, eia608_parity_strip (cc_data), char1, char2, text); + } + + return ret; +} + +void +eia608_dump (uint16_t cc_data) +{ + char *text = NULL; + int bufsz; + + bufsz = eia608_to_text (NULL, 0, cc_data); + text = malloc(bufsz + 1); + eia608_to_text (text, bufsz + 1, cc_data); + fprintf (stderr, "%s\n", text); + + free (text); } diff --git a/video/closedcaption/src/c/eia608.h b/video/closedcaption/src/c/eia608.h index 668a6fd94..10cd00982 100644 --- a/video/closedcaption/src/c/eia608.h +++ b/video/closedcaption/src/c/eia608.h @@ -27,6 +27,7 @@ extern "C" { #endif +#include <stdio.h> #include "eia608_charmap.h" #include "utf8.h" //////////////////////////////////////////////////////////////////////////////// @@ -201,6 +202,10 @@ int eia608_to_utf8(uint16_t c, int* chan, utf8_char_t* char1, utf8_char_t* char2 \param */ void eia608_dump(uint16_t cc_data); +/*! \brief + \param +*/ +int eia608_to_text (char *buf, ssize_t size, uint16_t cc_data); //////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } diff --git a/video/closedcaption/src/ffi.rs b/video/closedcaption/src/ffi.rs index a59e87fca..b4145fa6b 100644 --- a/video/closedcaption/src/ffi.rs +++ b/video/closedcaption/src/ffi.rs @@ -712,6 +712,13 @@ extern "C" { extern "C" { pub fn eia608_dump(cc_data: u16); } +extern "C" { + pub fn eia608_to_text( + buf: *mut ::std::os::raw::c_char, + s: usize, + cc_data: u16, + ) -> ::std::os::raw::c_int; +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct xds_t { |