libcaption: implement eia608_to_text

This commit is contained in:
Mathieu Duponchelle 2020-11-30 17:49:13 +01:00
parent a7180e3995
commit 6267e00c20
3 changed files with 38 additions and 8 deletions

View file

@ -23,6 +23,7 @@
/**********************************************************************************************/ /**********************************************************************************************/
#include "eia608.h" #include "eia608.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.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; eia608_style_t style;
const char *text = 0; const char *text = 0;
char char1[5], char2[5]; char char1[5], char2[5];
char1[0] = char2[0] = 0; char1[0] = char2[0] = 0;
int row, col, chan, underline; int row, col, chan, underline;
int ret;
if (!eia608_parity_varify (cc_data)) { if (!eia608_parity_varify (cc_data)) {
text = "parity failed"; text = "parity failed";
@ -260,11 +263,9 @@ eia608_dump (uint16_t cc_data)
} else if (eia608_is_norpak (cc_data)) { } else if (eia608_is_norpak (cc_data)) {
text = "norpak"; text = "norpak";
} else if (eia608_is_preamble (cc_data)) { } else if (eia608_is_preamble (cc_data)) {
text = "preamble";
eia608_parse_preamble (cc_data, &row, &col, &style, &chan, &underline); eia608_parse_preamble (cc_data, &row, &col, &style, &chan, &underline);
fprintf (stderr, "preamble %d %d %d %d %d\n", row, col, style, chan, ret = snprintf(buf, size, "cc %04X (%04X) '%s' '%s' (preamble: row: %d col: %d style: %d chan: %d underline: %d)",
underline); cc_data, eia608_parity_strip (cc_data), char1, char2, row, col, style, chan, underline);
} else if (eia608_is_control (cc_data)) { } else if (eia608_is_control (cc_data)) {
switch (eia608_parse_control (cc_data, &chan)) { switch (eia608_parse_control (cc_data, &chan)) {
@ -352,6 +353,23 @@ eia608_dump (uint16_t cc_data)
text = "unhandled"; text = "unhandled";
} }
fprintf (stderr, "cc %04X (%04X) '%s' '%s' (%s)\n", cc_data, if (text != 0) {
eia608_parity_strip (cc_data), char1, char2, text); 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);
} }

View file

@ -27,6 +27,7 @@
extern "C" { extern "C" {
#endif #endif
#include <stdio.h>
#include "eia608_charmap.h" #include "eia608_charmap.h"
#include "utf8.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 \param
*/ */
void eia608_dump(uint16_t cc_data); void eia608_dump(uint16_t cc_data);
/*! \brief
\param
*/
int eia608_to_text (char *buf, ssize_t size, uint16_t cc_data);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -712,6 +712,13 @@ extern "C" {
extern "C" { extern "C" {
pub fn eia608_dump(cc_data: u16); 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)] #[repr(C)]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct xds_t { pub struct xds_t {