New upstream version 26.0.0+dfsg1

This commit is contained in:
Sebastian Ramacher 2020-10-01 22:37:41 +02:00
parent 240080891f
commit bc27b6c1ca
31 changed files with 7521 additions and 0 deletions

144
deps/libcaption/caption/caption.h vendored Normal file
View file

@ -0,0 +1,144 @@
/**********************************************************************************************/
/* The MIT License */
/* */
/* Copyright 2016-2017 Twitch Interactive, Inc. or its affiliates. All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
/* in the Software without restriction, including without limitation the rights */
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
/* copies of the Software, and to permit persons to whom the Software is */
/* furnished to do so, subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be included in */
/* all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN */
/* THE SOFTWARE. */
/**********************************************************************************************/
#ifndef LIBCAPTION_H
#define LIBCAPTION_H
#ifdef __cplusplus
extern "C" {
#endif
#include "eia608.h"
#include "utf8.h"
#include "xds.h"
// ssize_t is POSIX and does not exist on Windows
#if defined(_MSC_VER)
#if defined(_WIN64)
typedef signed long ssize_t;
#else
typedef signed int ssize_t;
#endif
#endif
typedef enum {
LIBCAPTION_ERROR = 0,
LIBCAPTION_OK = 1,
LIBCAPTION_READY = 2
} libcaption_stauts_t;
static inline libcaption_stauts_t libcaption_status_update(libcaption_stauts_t old_stat, libcaption_stauts_t new_stat)
{
return (LIBCAPTION_ERROR == old_stat || LIBCAPTION_ERROR == new_stat) ? LIBCAPTION_ERROR : (LIBCAPTION_READY == old_stat) ? LIBCAPTION_READY : new_stat;
}
#define SCREEN_ROWS 15
#define SCREEN_COLS 32
typedef struct {
unsigned int uln : 1; //< underline
unsigned int sty : 3; //< style
utf8_char_t data[5]; //< 4 byte utf8 values plus null term
} caption_frame_cell_t;
typedef struct {
caption_frame_cell_t cell[SCREEN_ROWS][SCREEN_COLS];
} caption_frame_buffer_t;
typedef struct {
unsigned int uln : 1; //< underline
unsigned int sty : 3; //< style
unsigned int rup : 2; //< roll-up line count minus 1
int8_t row, col;
uint16_t cc_data;
} caption_frame_state_t;
// timestamp and duration are in seconds
typedef struct {
double timestamp;
xds_t xds;
caption_frame_state_t state;
caption_frame_buffer_t front;
caption_frame_buffer_t back;
caption_frame_buffer_t* write;
libcaption_stauts_t status;
} caption_frame_t;
/*!
\brief Initializes an allocated caption_frame_t instance
\param frame Pointer to prealocated caption_frame_t object
*/
void caption_frame_init(caption_frame_t* frame);
/*! \brief
\param
*/
static inline int caption_frame_popon(caption_frame_t* frame) { return (frame->write == &frame->back) ? 1 : 0; }
/*! \brief
\param
*/
static inline int caption_frame_painton(caption_frame_t* frame) { return (frame->write == &frame->front) ? 1 : 0; }
/*! \brief
\param
*/
const static int _caption_frame_rollup[] = { 0, 2, 3, 4 };
static inline int caption_frame_rollup(caption_frame_t* frame) { return _caption_frame_rollup[frame->state.rup]; }
/*! \brief
\param
*/
static inline double caption_frame_timestamp(caption_frame_t* frame) { return frame->timestamp; }
/*! \brief Writes a single charcter to a caption_frame_t object
\param frame A pointer to an allocted and initialized caption_frame_t object
\param row Row position to write charcter, must be between 0 and SCREEN_ROWS-1
\param col Column position to write charcter, must be between 0 and SCREEN_ROWS-1
\param style Style to apply to charcter
\param underline Set underline attribute, 0 = off any other value = on
\param c pointer to a single valid utf8 charcter. Bytes are automatically determined, and a NULL terminator is not required
*/
int caption_frame_write_char(caption_frame_t* frame, int row, int col, eia608_style_t style, int underline, const utf8_char_t* c);
/*! \brief
\param
*/
const utf8_char_t* caption_frame_read_char(caption_frame_t* frame, int row, int col, eia608_style_t* style, int* underline);
/*! \brief
\param
*/
libcaption_stauts_t caption_frame_decode(caption_frame_t* frame, uint16_t cc_data, double timestamp);
/*! \brief
\param
*/
int caption_frame_from_text(caption_frame_t* frame, const utf8_char_t* data);
/*! \brief
\param
*/
#define CAPTION_FRAME_TEXT_BYTES (4 * ((SCREEN_COLS + 2) * SCREEN_ROWS) + 1)
size_t caption_frame_to_text(caption_frame_t* frame, utf8_char_t* data);
/*! \brief
\param
*/
#define CAPTION_FRAME_DUMP_BUF_SIZE 8192
size_t caption_frame_dump_buffer(caption_frame_t* frame, utf8_char_t* buf);
void caption_frame_dump(caption_frame_t* frame);
#ifdef __cplusplus
}
#endif
#endif

124
deps/libcaption/caption/cea708.h vendored Normal file
View file

@ -0,0 +1,124 @@
/**********************************************************************************************/
/* The MIT License */
/* */
/* Copyright 2016-2017 Twitch Interactive, Inc. or its affiliates. All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
/* in the Software without restriction, including without limitation the rights */
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
/* copies of the Software, and to permit persons to whom the Software is */
/* furnished to do so, subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be included in */
/* all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN */
/* THE SOFTWARE. */
/**********************************************************************************************/
#ifndef LIBCAPTION_CEA708_H
#define LIBCAPTION_CEA708_H
#ifdef __cplusplus
extern "C" {
#endif
#include "caption.h"
#define CEA608_MAX_SIZE (255)
////////////////////////////////////////////////////////////////////////////////
typedef enum {
cc_type_ntsc_cc_field_1 = 0,
cc_type_ntsc_cc_field_2 = 1,
cc_type_dtvcc_packet_data = 2,
cc_type_dtvcc_packet_start = 3,
} cea708_cc_type_t;
typedef struct {
unsigned int marker_bits : 5;
unsigned int cc_valid : 1;
unsigned int cc_type : 2; // castable to cea708_cc_type_t
unsigned int cc_data : 16;
} cc_data_t;
typedef struct {
unsigned int process_em_data_flag : 1;
unsigned int process_cc_data_flag : 1;
unsigned int additional_data_flag : 1;
unsigned int cc_count : 5;
unsigned int em_data : 8;
cc_data_t cc_data[32];
} user_data_t;
/*! \brief
\param
*/
cc_data_t cea708_encode_cc_data(int cc_valid, cea708_cc_type_t type, uint16_t cc_data);
/*! \brief
\param
*/
int cea708_cc_count(user_data_t* data);
/*! \brief
\param
*/
uint16_t cea708_cc_data(user_data_t* data, int index, int* valid, cea708_cc_type_t* type);
////////////////////////////////////////////////////////////////////////////////
typedef enum {
country_united_states = 181,
} itu_t_t35_country_code_t;
typedef enum {
t35_provider_direct_tv = 47,
t35_provider_atsc = 49,
} itu_t_t35_provider_code_t;
typedef struct {
itu_t_t35_country_code_t country;
itu_t_t35_provider_code_t provider;
uint32_t user_identifier;
uint8_t user_data_type_code;
uint8_t directv_user_data_length;
user_data_t user_data;
double timestamp;
} cea708_t;
const static uint32_t GA94 = (('G' << 24) | ('A' << 16) | ('9' << 8) | '4');
const static uint32_t DTG1 = (('D' << 24) | ('T' << 16) | ('G' << 8) | '1');
/*! \brief
\param
*/
int cea708_init(cea708_t* cea708, double timestamp); // will confgure using HLS compatiable defaults
/*! \brief
\param
*/
libcaption_stauts_t cea708_parse_h264(const uint8_t* data, size_t size, cea708_t* cea708);
/*! \brief
\param
*/
libcaption_stauts_t cea708_parse_h262(const uint8_t* data, size_t size, cea708_t* cea708);
/*! \brief
\param
*/
libcaption_stauts_t cea708_to_caption_frame(caption_frame_t* frame, cea708_t* cea708);
/*! \brief
\param
*/
int cea708_add_cc_data(cea708_t* cea708, int valid, cea708_cc_type_t type, uint16_t cc_data);
/*! \brief
\param
*/
int cea708_render(cea708_t* cea708, uint8_t* data, size_t size);
/*! \brief
\param
*/
void cea708_dump(cea708_t* cea708);
#ifdef __cplusplus
}
#endif
#endif

21
deps/libcaption/caption/dvtcc.h vendored Normal file
View file

@ -0,0 +1,21 @@
#ifndef LIBCAPTION_CEA708_H
#define LIBCAPTION_CEA708_H
#ifdef __cplusplus
extern "C" {
#endif
////////////////////////////////////////////////////////////////////////////////
struct dtvcc_packet_t {
unsigned int sequence_number;
unsigned int packet_size;
unsigned int serice_number;
};
#defing DVTCC_SERVICE_NUMBER_UNKNOWN
// static inline size_t dvtvcc_packet_size_bytes(const struct dtvcc_packet_t *dvtcc) { return dvtcc->packet_size*2-1;}
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif
#endif

208
deps/libcaption/caption/eia608.h vendored Normal file
View file

@ -0,0 +1,208 @@
/**********************************************************************************************/
/* The MIT License */
/* */
/* Copyright 2016-2017 Twitch Interactive, Inc. or its affiliates. All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
/* in the Software without restriction, including without limitation the rights */
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
/* copies of the Software, and to permit persons to whom the Software is */
/* furnished to do so, subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be included in */
/* all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN */
/* THE SOFTWARE. */
/**********************************************************************************************/
#ifndef LIBCAPTION_EIA608_H
#define LIBCAPTION_EIA608_H
#ifdef __cplusplus
extern "C" {
#endif
#include "eia608_charmap.h"
#include "utf8.h"
////////////////////////////////////////////////////////////////////////////////
// Parity
#define EIA608_BX(B, X) (((B) << (X)) & 0x80)
#define EIA608_BP(B) ((B)&0x7F) | (0x80 ^ EIA608_BX((B), 1) ^ EIA608_BX((B), 2) ^ EIA608_BX((B), 3) ^ EIA608_BX((B), 4) ^ EIA608_BX((B), 5) ^ EIA608_BX((B), 6) ^ EIA608_BX((B), 7))
#define EIA608_B2(B) EIA608_BP((B) + 0), EIA608_BP((B) + 1), EIA608_BP((B) + 2), EIA608_BP((B) + 3), EIA608_BP((B) + 4), EIA608_BP((B) + 5), EIA608_BP((B) + 6), EIA608_BP((B) + 7)
#define EIA608_B1(B) EIA608_B2((B) + 0), EIA608_B2((B) + 8), EIA608_B2((B) + 16), EIA608_B2((B) + 24), EIA608_B2((B) + 32), EIA608_B2((B) + 40), EIA608_B2((B) + 48), EIA608_B2((B) + 56)
static const uint8_t eia608_parity_table[] = { EIA608_B1(0), EIA608_B1(64) };
extern const char* eia608_style_map[];
#ifdef _MSC_VER
#ifndef inline
#define inline __inline
#endif
#endif
/*! \brief
\param
*/
static inline uint8_t eia608_parity_byte(uint8_t cc_data) { return eia608_parity_table[0x7F & cc_data]; }
/*! \brief
\param
*/
static inline uint16_t eia608_parity_word(uint16_t cc_data) { return (uint16_t)((eia608_parity_byte((uint8_t)(cc_data >> 8)) << 8) | eia608_parity_byte((uint8_t)cc_data)); }
/*! \brief
\param
*/
static inline uint16_t eia608_parity(uint16_t cc_data) { return eia608_parity_word(cc_data); }
/*! \brief
\param
*/
static inline int eia608_parity_varify(uint16_t cc_data) { return eia608_parity_word(cc_data) == cc_data ? 1 : 0; }
/*! \brief
\param
*/
static inline int eia608_parity_strip(uint16_t cc_data) { return cc_data & 0x7F7F; }
/*! \brief
\param
*/
static inline int eia608_test_second_channel_bit(uint16_t cc_data) { return (cc_data & 0x0800); }
////////////////////////////////////////////////////////////////////////////////
// cc_data types
/*! \brief
\param
*/
static inline int eia608_is_basicna(uint16_t cc_data) { return 0x0000 != (0x6000 & cc_data); /*&& 0x1F00 < (0x7F00 & cc_data);*/ }
/*! \brief
\param
*/
static inline int eia608_is_preamble(uint16_t cc_data) { return 0x1040 == (0x7040 & cc_data); }
/*! \brief
\param
*/
static inline int eia608_is_midrowchange(uint16_t cc_data) { return 0x1120 == (0x7770 & cc_data); }
/*! \brief
\param
*/
static inline int eia608_is_specialna(uint16_t cc_data) { return 0x1130 == (0x7770 & cc_data); }
/*! \brief
\param
*/
static inline int eia608_is_xds(uint16_t cc_data) { return 0x0000 == (0x7070 & cc_data) && 0x0000 != (0x0F0F & cc_data); }
/*! \brief
\param
*/
static inline int eia608_is_westeu(uint16_t cc_data) { return 0x1220 == (0x7660 & cc_data); }
/*! \brief
\param
*/
static inline int eia608_is_control(uint16_t cc_data) { return 0x1420 == (0x7670 & cc_data) || 0x1720 == (0x7770 & cc_data); }
/*! \brief
\param
*/
static inline int eia608_is_norpak(uint16_t cc_data) { return 0x1724 == (0x777C & cc_data) || 0x1728 == (0x777C & cc_data); }
/*! \brief
\param
*/
static inline int eia608_is_padding(uint16_t cc_data) { return 0x8080 == cc_data; }
////////////////////////////////////////////////////////////////////////////////
// preamble
typedef enum {
eia608_style_white = 0,
eia608_style_green = 1,
eia608_style_blue = 2,
eia608_style_cyan = 3,
eia608_style_red = 4,
eia608_style_yellow = 5,
eia608_style_magenta = 6,
eia608_style_italics = 7,
} eia608_style_t;
/*! \brief
\param
*/
int eia608_parse_preamble(uint16_t cc_data, int* row, int* col, eia608_style_t* style, int* chan, int* underline);
/*! \brief
\param
*/
int eia608_parse_midrowchange(uint16_t cc_data, int* chan, eia608_style_t* style, int* underline);
/*! \brief
\param
*/
uint16_t eia608_row_column_pramble(int row, int col, int chan, int underline);
/*! \brief
\param
*/
uint16_t eia608_row_style_pramble(int row, int chan, eia608_style_t style, int underline);
/*! \brief
\param
*/
uint16_t eia608_midrow_change(int chan, eia608_style_t style, int underline);
////////////////////////////////////////////////////////////////////////////////
// control command
typedef enum {
eia608_tab_offset_0 = 0x1720,
eia608_tab_offset_1 = 0x1721,
eia608_tab_offset_2 = 0x1722,
eia608_tab_offset_3 = 0x1723,
eia608_control_resume_caption_loading = 0x1420,
eia608_control_backspace = 0x1421,
eia608_control_alarm_off = 0x1422,
eia608_control_alarm_on = 0x1423,
eia608_control_delete_to_end_of_row = 0x1424,
eia608_control_roll_up_2 = 0x1425,
eia608_control_roll_up_3 = 0x1426,
eia608_control_roll_up_4 = 0x1427,
eia608_control_resume_direct_captioning = 0x1429,
eia608_control_text_restart = 0x142A,
eia608_control_text_resume_text_display = 0x142B,
eia608_control_erase_display_memory = 0x142C,
eia608_control_carriage_return = 0x142D,
eia608_control_erase_non_displayed_memory = 0x142E,
eia608_control_end_of_caption = 0x142F,
} eia608_control_t;
/*! \brief
\param
*/
uint16_t eia608_control_command(eia608_control_t cmd, int cc);
/*! \brief
\param
*/
static inline uint16_t eia608_tab(int size, int cc) { return eia608_control_command((eia608_control_t)(eia608_tab_offset_0 | (size & 0x0F)), cc); }
/*! \brief
\param
*/
eia608_control_t eia608_parse_control(uint16_t cc_data, int* cc);
////////////////////////////////////////////////////////////////////////////////
// text
/*! \brief
\param c
*/
uint16_t eia608_from_utf8_1(const utf8_char_t* c, int chan);
/*! \brief
\param
*/
uint16_t eia608_from_utf8_2(const utf8_char_t* c1, const utf8_char_t* c2);
/*! \brief
\param
*/
uint16_t eia608_from_basicna(uint16_t bna1, uint16_t bna2);
/*! \brief
\param
*/
int eia608_to_utf8(uint16_t c, int* chan, utf8_char_t* char1, utf8_char_t* char2);
////////////////////////////////////////////////////////////////////////////////
/*! \brief
\param
*/
void eia608_dump(uint16_t cc_data);
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif
#endif

236
deps/libcaption/caption/eia608_charmap.h vendored Normal file
View file

@ -0,0 +1,236 @@
/**********************************************************************************************/
/* The MIT License */
/* */
/* Copyright 2016-2017 Twitch Interactive, Inc. or its affiliates. All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
/* in the Software without restriction, including without limitation the rights */
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
/* copies of the Software, and to permit persons to whom the Software is */
/* furnished to do so, subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be included in */
/* all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN */
/* THE SOFTWARE. */
/**********************************************************************************************/
#ifndef LIBCAPTION_EIA608_CHARMAP_H
#define LIBCAPTION_EIA608_CHARMAP_H
#ifdef __cplusplus
extern "C" {
#endif
#define EIA608_CHAR_COUNT 176
extern const char* eia608_char_map[EIA608_CHAR_COUNT];
// Helper char
#define EIA608_CHAR_NULL ""
// Basic North American character set
#define EIA608_CHAR_SPACE "\x20"
#define EIA608_CHAR_EXCLAMATION_MARK "\x21"
#define EIA608_CHAR_QUOTATION_MARK "\x22"
#define EIA608_CHAR_NUMBER_SIGN "\x23"
#define EIA608_CHAR_DOLLAR_SIGN "\x24"
#define EIA608_CHAR_PERCENT_SIGN "\x25"
#define EIA608_CHAR_AMPERSAND "\x26"
#define EIA608_CHAR_LEFT_SINGLE_QUOTATION_MARK "\xE2\x80\x98"
#define EIA608_CHAR_LEFT_PARENTHESIS "\x28"
#define EIA608_CHAR_RIGHT_PARENTHESIS "\x29"
#define EIA608_CHAR_LATIN_SMALL_LETTER_A_WITH_ACUTE "\xC3\xA1"
#define EIA608_CHAR_PLUS_SIGN "\x2B"
#define EIA608_CHAR_COMMA "\x2C"
#define EIA608_CHAR_HYPHEN_MINUS "\x2D"
#define EIA608_CHAR_FULL_STOP "\x2E"
#define EIA608_CHAR_SOLIDUS "\x2F"
// Basic North American character set
#define EIA608_CHAR_DIGIT_ZERO "\x30"
#define EIA608_CHAR_DIGIT_ONE "\x31"
#define EIA608_CHAR_DIGIT_TWO "\x32"
#define EIA608_CHAR_DIGIT_THREE "\x33"
#define EIA608_CHAR_DIGIT_FOUR "\x34"
#define EIA608_CHAR_DIGIT_FIVE "\x35"
#define EIA608_CHAR_DIGIT_SIX "\x36"
#define EIA608_CHAR_DIGIT_SEVEN "\x37"
#define EIA608_CHAR_DIGIT_EIGHT "\x38"
#define EIA608_CHAR_DIGIT_NINE "\x39"
#define EIA608_CHAR_COLON "\x3A"
#define EIA608_CHAR_SEMICOLON "\x3B"
#define EIA608_CHAR_LESS_THAN_SIGN "\x3C"
#define EIA608_CHAR_EQUALS_SIGN "\x3D"
#define EIA608_CHAR_GREATER_THAN_SIGN "\x3E"
#define EIA608_CHAR_QUESTION_MARK "\x3F"
// Basic North American character set
#define EIA608_CHAR_COMMERCIAL_AT "\x40"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_A "\x41"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_B "\x42"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_C "\x43"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_D "\x44"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_E "\x45"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_F "\x46"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_G "\x47"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_H "\x48"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_I "\x49"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_J "\x4A"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_K "\x4B"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_L "\x4C"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_M "\x4D"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_N "\x4E"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_O "\x4F"
// Basic North American character set
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_P "\x50"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_Q "\x51"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_R "\x52"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_S "\x53"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_T "\x54"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_U "\x55"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_V "\x56"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_W "\x57"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_X "\x58"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_Y "\x59"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_Z "\x5A"
#define EIA608_CHAR_LEFT_SQUARE_BRACKET "\x5B"
#define EIA608_CHAR_LATIN_SMALL_LETTER_E_WITH_ACUTE "\xC3\xA9"
#define EIA608_CHAR_RIGHT_SQUARE_BRACKET "\x5D"
#define EIA608_CHAR_LATIN_SMALL_LETTER_I_WITH_ACUTE "\xC3\xAD"
#define EIA608_CHAR_LATIN_SMALL_LETTER_O_WITH_ACUTE "\xC3\xB3"
// Basic North American character set
#define EIA608_CHAR_LATIN_SMALL_LETTER_U_WITH_ACUTE "\xC3\xBA"
#define EIA608_CHAR_LATIN_SMALL_LETTER_A "\x61"
#define EIA608_CHAR_LATIN_SMALL_LETTER_B "\x62"
#define EIA608_CHAR_LATIN_SMALL_LETTER_C "\x63"
#define EIA608_CHAR_LATIN_SMALL_LETTER_D "\x64"
#define EIA608_CHAR_LATIN_SMALL_LETTER_E "\x65"
#define EIA608_CHAR_LATIN_SMALL_LETTER_F "\x66"
#define EIA608_CHAR_LATIN_SMALL_LETTER_G "\x67"
#define EIA608_CHAR_LATIN_SMALL_LETTER_H "\x68"
#define EIA608_CHAR_LATIN_SMALL_LETTER_I "\x69"
#define EIA608_CHAR_LATIN_SMALL_LETTER_J "\x6A"
#define EIA608_CHAR_LATIN_SMALL_LETTER_K "\x6B"
#define EIA608_CHAR_LATIN_SMALL_LETTER_L "\x6C"
#define EIA608_CHAR_LATIN_SMALL_LETTER_M "\x6D"
#define EIA608_CHAR_LATIN_SMALL_LETTER_N "\x6E"
#define EIA608_CHAR_LATIN_SMALL_LETTER_O "\x6F"
// Basic North American character set
#define EIA608_CHAR_LATIN_SMALL_LETTER_P "\x70"
#define EIA608_CHAR_LATIN_SMALL_LETTER_Q "\x71"
#define EIA608_CHAR_LATIN_SMALL_LETTER_R "\x72"
#define EIA608_CHAR_LATIN_SMALL_LETTER_S "\x73"
#define EIA608_CHAR_LATIN_SMALL_LETTER_T "\x74"
#define EIA608_CHAR_LATIN_SMALL_LETTER_U "\x75"
#define EIA608_CHAR_LATIN_SMALL_LETTER_V "\x76"
#define EIA608_CHAR_LATIN_SMALL_LETTER_W "\x77"
#define EIA608_CHAR_LATIN_SMALL_LETTER_X "\x78"
#define EIA608_CHAR_LATIN_SMALL_LETTER_Y "\x79"
#define EIA608_CHAR_LATIN_SMALL_LETTER_Z "\x7A"
#define EIA608_CHAR_LATIN_SMALL_LETTER_C_WITH_CEDILLA "\xC3\xA7"
#define EIA608_CHAR_DIVISION_SIGN "\xC3\xB7"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_N_WITH_TILDE "\xC3\x91"
#define EIA608_CHAR_LATIN_SMALL_LETTER_N_WITH_TILDE "\xC3\xB1"
#define EIA608_CHAR_FULL_BLOCK "\xE2\x96\x88"
// Special North American character set[edit]
#define EIA608_CHAR_REGISTERED_SIGN "\xC2\xAE"
#define EIA608_CHAR_DEGREE_SIGN "\xC2\xB0"
#define EIA608_CHAR_VULGAR_FRACTION_ONE_HALF "\xC2\xBD"
#define EIA608_CHAR_INVERTED_QUESTION_MARK "\xC2\xBF"
#define EIA608_CHAR_TRADE_MARK_SIGN "\xE2\x84\xA2"
#define EIA608_CHAR_CENT_SIGN "\xC2\xA2"
#define EIA608_CHAR_POUND_SIGN "\xC2\xA3"
#define EIA608_CHAR_EIGHTH_NOTE "\xE2\x99\xAA"
#define EIA608_CHAR_LATIN_SMALL_LETTER_A_WITH_GRAVE "\xC3\xA0"
#define EIA608_CHAR_NO_BREAK_SPACE "\xC2\xA0"
#define EIA608_CHAR_LATIN_SMALL_LETTER_E_WITH_GRAVE "\xC3\xA8"
#define EIA608_CHAR_LATIN_SMALL_LETTER_A_WITH_CIRCUMFLEX "\xC3\xA2"
#define EIA608_CHAR_LATIN_SMALL_LETTER_E_WITH_CIRCUMFLEX "\xC3\xAA"
#define EIA608_CHAR_LATIN_SMALL_LETTER_I_WITH_CIRCUMFLEX "\xC3\xAE"
#define EIA608_CHAR_LATIN_SMALL_LETTER_O_WITH_CIRCUMFLEX "\xC3\xB4"
#define EIA608_CHAR_LATIN_SMALL_LETTER_U_WITH_CIRCUMFLEX "\xC3\xBB"
// Extended Western European character set : Extended Spanish/Miscellaneous
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_A_WITH_ACUTE "\xC3\x81"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_E_WITH_ACUTE "\xC3\x89"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_O_WITH_ACUTE "\xC3\x93"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_U_WITH_ACUTE "\xC3\x9A"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_U_WITH_DIAERESIS "\xC3\x9C"
#define EIA608_CHAR_LATIN_SMALL_LETTER_U_WITH_DIAERESIS "\xC3\xBC"
#define EIA608_CHAR_RIGHT_SINGLE_QUOTATION_MARK "\xE2\x80\x99"
#define EIA608_CHAR_INVERTED_EXCLAMATION_MARK "\xC2\xA1"
#define EIA608_CHAR_ASTERISK "\x2A"
#define EIA608_CHAR_APOSTROPHE "\x27"
#define EIA608_CHAR_EM_DASH "\xE2\x80\x94"
#define EIA608_CHAR_COPYRIGHT_SIGN "\xC2\xA9"
#define EIA608_CHAR_SERVICE_MARK "\xE2\x84\xA0"
#define EIA608_CHAR_BULLET "\xE2\x80\xA2"
#define EIA608_CHAR_LEFT_DOUBLE_QUOTATION_MARK "\xE2\x80\x9C"
#define EIA608_CHAR_RIGHT_DOUBLE_QUOTATION_MARK "\xE2\x80\x9D"
// Extended Western European character set : Extended French
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_A_WITH_GRAVE "\xC3\x80"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_A_WITH_CIRCUMFLEX "\xC3\x82"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_C_WITH_CEDILLA "\xC3\x87"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_E_WITH_GRAVE "\xC3\x88"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_E_WITH_CIRCUMFLEX "\xC3\x8A"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_E_WITH_DIAERESIS "\xC3\x8B"
#define EIA608_CHAR_LATIN_SMALL_LETTER_E_WITH_DIAERESIS "\xC3\xAB"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_I_WITH_CIRCUMFLEX "\xC3\x8E"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_I_WITH_DIAERESIS "\xC3\x8F"
#define EIA608_CHAR_LATIN_SMALL_LETTER_I_WITH_DIAERESIS "\xC3\xAF"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_O_WITH_CIRCUMFLEX "\xC3\x94"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_U_WITH_GRAVE "\xC3\x99"
#define EIA608_CHAR_LATIN_SMALL_LETTER_U_WITH_GRAVE "\xC3\xB9"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_U_WITH_CIRCUMFLEX "\xC3\x9B"
#define EIA608_CHAR_LEFT_POINTING_DOUBLE_ANGLE_QUOTATION_MARK "\xC2\xAB"
#define EIA608_CHAR_RIGHT_POINTING_DOUBLE_ANGLE_QUOTATION_MARK "\xC2\xBB"
// Extended Western European character set : Portuguese
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_A_WITH_TILDE "\xC3\x83"
#define EIA608_CHAR_LATIN_SMALL_LETTER_A_WITH_TILDE "\xC3\xA3"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_I_WITH_ACUTE "\xC3\x8D"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_I_WITH_GRAVE "\xC3\x8C"
#define EIA608_CHAR_LATIN_SMALL_LETTER_I_WITH_GRAVE "\xC3\xAC"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_O_WITH_GRAVE "\xC3\x92"
#define EIA608_CHAR_LATIN_SMALL_LETTER_O_WITH_GRAVE "\xC3\xB2"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_O_WITH_TILDE "\xC3\x95"
#define EIA608_CHAR_LATIN_SMALL_LETTER_O_WITH_TILDE "\xC3\xB5"
#define EIA608_CHAR_LEFT_CURLY_BRACKET "\x7B"
#define EIA608_CHAR_RIGHT_CURLY_BRACKET "\x7D"
#define EIA608_CHAR_REVERSE_SOLIDUS "\x5C"
#define EIA608_CHAR_CIRCUMFLEX_ACCENT "\x5E"
#define EIA608_CHAR_LOW_LINE "\x5F"
#define EIA608_CHAR_VERTICAL_LINE "\x7C"
#define EIA608_CHAR_TILDE "\x7E"
// Extended Western European character set : German/Danish
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_A_WITH_DIAERESIS "\xC3\x84"
#define EIA608_CHAR_LATIN_SMALL_LETTER_A_WITH_DIAERESIS "\xC3\xA4"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_O_WITH_DIAERESIS "\xC3\x96"
#define EIA608_CHAR_LATIN_SMALL_LETTER_O_WITH_DIAERESIS "\xC3\xB6"
#define EIA608_CHAR_LATIN_SMALL_LETTER_SHARP_S "\xC3\x9F"
#define EIA608_CHAR_YEN_SIGN "\xC2\xA5"
#define EIA608_CHAR_CURRENCY_SIGN "\xC2\xA4"
#define EIA608_CHAR_BROKEN_BAR "\xC2\xA6"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_A_WITH_RING_ABOVE "\xC3\x85"
#define EIA608_CHAR_LATIN_SMALL_LETTER_A_WITH_RING_ABOVE "\xC3\xA5"
#define EIA608_CHAR_LATIN_CAPITAL_LETTER_O_WITH_STROKE "\xC3\x98"
#define EIA608_CHAR_LATIN_SMALL_LETTER_O_WITH_STROKE "\xC3\xB8"
#define EIA608_CHAR_BOX_DRAWINGS_LIGHT_DOWN_AND_RIGHT "\xE2\x94\x8C" // top left
#define EIA608_CHAR_BOX_DRAWINGS_LIGHT_DOWN_AND_LEFT "\xE2\x94\x90" // top right
#define EIA608_CHAR_BOX_DRAWINGS_LIGHT_UP_AND_RIGHT "\xE2\x94\x94" // lower left
#define EIA608_CHAR_BOX_DRAWINGS_LIGHT_UP_AND_LEFT "\xE2\x94\x98" // bottom right
#ifdef __cplusplus
}
#endif
#endif

212
deps/libcaption/caption/mpeg.h vendored Normal file
View file

@ -0,0 +1,212 @@
/**********************************************************************************************/
/* The MIT License */
/* */
/* Copyright 2016-2017 Twitch Interactive, Inc. or its affiliates. All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
/* in the Software without restriction, including without limitation the rights */
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
/* copies of the Software, and to permit persons to whom the Software is */
/* furnished to do so, subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be included in */
/* all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN */
/* THE SOFTWARE. */
/**********************************************************************************************/
#ifndef LIBCAPTION_MPEG_H
#define LIBCAPTION_MPEG_H
#ifdef __cplusplus
extern "C" {
#endif
#include "caption.h"
#include "cea708.h"
#include "scc.h"
#include <float.h>
#include <stddef.h>
////////////////////////////////////////////////////////////////////////////////
#define STREAM_TYPE_H262 0x02
#define STREAM_TYPE_H264 0x1B
#define STREAM_TYPE_H265 0x24
#define H262_SEI_PACKET 0xB2
#define H264_SEI_PACKET 0x06
#define H265_SEI_PACKET 0x27 // There is also 0x28
#define MAX_NALU_SIZE (6 * 1024 * 1024)
#define MAX_REFRENCE_FRAMES 64
typedef struct {
size_t size;
uint8_t data[MAX_NALU_SIZE + 1];
double dts, cts;
libcaption_stauts_t status;
// Priority queue for out of order frame processing
// Should probablly be a linked list
size_t front;
size_t latent;
cea708_t cea708[MAX_REFRENCE_FRAMES];
} mpeg_bitstream_t;
void mpeg_bitstream_init(mpeg_bitstream_t* packet);
////////////////////////////////////////////////////////////////////////////////
// TODO make convenience functions for flv/mp4
/*! \brief
\param
*/
size_t mpeg_bitstream_parse(mpeg_bitstream_t* packet, caption_frame_t* frame, const uint8_t* data, size_t size, unsigned stream_type, double dts, double cts);
/*! \brief
\param
*/
static inline libcaption_stauts_t mpeg_bitstream_status(mpeg_bitstream_t* packet) { return packet->status; }
/*! \brief
Flushes latent packets caused by out or order frames.
Returns number of latent frames remaining, 0 when complete;
\param
*/
size_t mpeg_bitstream_flush(mpeg_bitstream_t* packet, caption_frame_t* frame);
////////////////////////////////////////////////////////////////////////////////
typedef enum {
sei_type_buffering_period = 0,
sei_type_pic_timing = 1,
sei_type_pan_scan_rect = 2,
sei_type_filler_payload = 3,
sei_type_user_data_registered_itu_t_t35 = 4,
sei_type_user_data_unregistered = 5,
sei_type_recovery_point = 6,
sei_type_dec_ref_pic_marking_repetition = 7,
sei_type_spare_pic = 8,
sei_type_scene_info = 9,
sei_type_sub_seq_info = 10,
sei_type_sub_seq_layer_characteristics = 11,
sei_type_sub_seq_characteristics = 12,
sei_type_full_frame_freeze = 13,
sei_type_full_frame_freeze_release = 14,
sei_type_full_frame_snapshot = 15,
sei_type_progressive_refinement_segment_start = 16,
sei_type_progressive_refinement_segment_end = 17,
sei_type_motion_constrained_slice_group_set = 18,
sei_type_film_grain_characteristics = 19,
sei_type_deblocking_filter_display_preference = 20,
sei_type_stereo_video_info = 21,
} sei_msgtype_t;
////////////////////////////////////////////////////////////////////////////////
typedef struct _sei_message_t {
size_t size;
sei_msgtype_t type;
struct _sei_message_t* next;
} sei_message_t;
typedef struct {
double timestamp;
sei_message_t* head;
sei_message_t* tail;
} sei_t;
/*! \brief
\param
*/
void sei_init(sei_t* sei, double timestamp);
/*! \brief
\param
*/
void sei_free(sei_t* sei);
/*! \brief
\param
*/
void sei_cat(sei_t* to, sei_t* from, int itu_t_t35);
/*! \brief
\param
*/
void sei_message_append(sei_t* sei, sei_message_t* msg);
/*! \brief
\param
*/
libcaption_stauts_t sei_parse(sei_t* sei, const uint8_t* data, size_t size, double timestamp);
/*! \brief
\param
*/
static inline sei_message_t* sei_message_head(sei_t* sei) { return sei->head; }
/*! \brief
\param
*/
static inline sei_message_t* sei_message_tail(sei_t* sei) { return sei->tail; }
/*! \brief
\param
*/
sei_message_t* sei_message_next(sei_message_t* msg);
/*! \brief
\param
*/
sei_msgtype_t sei_message_type(sei_message_t* msg);
/*! \brief
\param
*/
size_t sei_message_size(sei_message_t* msg);
/*! \brief
\param
*/
uint8_t* sei_message_data(sei_message_t* msg);
/*! \brief
\param
*/
sei_message_t* sei_message_new(sei_msgtype_t type, uint8_t* data, size_t size);
/*! \brief
\param
*/
static inline sei_message_t* sei_message_copy(sei_message_t* msg)
{
return sei_message_new(sei_message_type(msg), sei_message_data(msg), sei_message_size(msg));
}
/**
Free message and all accoiated data. Messaged added to sei_t by using sei_append_message MUST NOT be freed
These messages will be freed by calling sei_free()
*/
/*! \brief
\param
*/
void sei_message_free(sei_message_t* msg);
////////////////////////////////////////////////////////////////////////////////
/*! \brief
\param
*/
size_t sei_render_size(sei_t* sei);
/*! \brief
\param
*/
size_t sei_render(sei_t* sei, uint8_t* data);
/*! \brief
\param
*/
void sei_dump(sei_t* sei);
/*! \brief
\param
*/
void sei_dump_messages(sei_message_t* head, double timestamp);
////////////////////////////////////////////////////////////////////////////////
/*! \brief
\param
*/
libcaption_stauts_t sei_from_scc(sei_t* sei, const scc_t* scc);
/*! \brief
\param
*/
libcaption_stauts_t sei_from_caption_frame(sei_t* sei, caption_frame_t* frame);
/*! \brief
\param
*/
libcaption_stauts_t sei_from_caption_clear(sei_t* sei);
/*! \brief
\param
*/
libcaption_stauts_t sei_to_caption_frame(sei_t* sei, caption_frame_t* frame);
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif
#endif

47
deps/libcaption/caption/scc.h vendored Normal file
View file

@ -0,0 +1,47 @@
/**********************************************************************************************/
/* The MIT License */
/* */
/* Copyright 2016-2017 Twitch Interactive, Inc. or its affiliates. All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
/* in the Software without restriction, including without limitation the rights */
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
/* copies of the Software, and to permit persons to whom the Software is */
/* furnished to do so, subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be included in */
/* all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN */
/* THE SOFTWARE. */
/**********************************************************************************************/
#ifndef LIBCAPTION_SCC_H
#define LIBCAPTION_SCC_H
#ifdef __cplusplus
extern "C" {
#endif
#include "eia608.h"
typedef struct _scc_t {
double timestamp;
unsigned int cc_aloc;
unsigned int cc_size;
uint16_t cc_data[];
} scc_t;
scc_t* scc_new(int cc_count);
scc_t* scc_free(scc_t* scc);
size_t scc_to_608(scc_t** scc, const utf8_char_t* data);
#ifdef __cplusplus
}
#endif
#endif

95
deps/libcaption/caption/srt.h vendored Normal file
View file

@ -0,0 +1,95 @@
/**********************************************************************************************/
/* The MIT License */
/* */
/* Copyright 2016-2017 Twitch Interactive, Inc. or its affiliates. All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
/* in the Software without restriction, including without limitation the rights */
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
/* copies of the Software, and to permit persons to whom the Software is */
/* furnished to do so, subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be included in */
/* all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN */
/* THE SOFTWARE. */
/**********************************************************************************************/
#ifndef LIBCAPTION_SRT_H
#define LIBCAPTION_SRT_H
#ifdef __cplusplus
extern "C" {
#endif
#include "caption.h"
#include "eia608.h"
#include "vtt.h"
// timestamp and duration are in seconds
typedef vtt_t srt_t;
typedef vtt_block_t srt_cue_t;
/*! \brief
\param
*/
srt_t* srt_new();
/*! \brief
\param
*/
srt_t* srt_free_head(srt_t* head);
// returns the head of the link list. must bee freed when done
/*! \brief
\param
*/
srt_t* srt_parse(const utf8_char_t* data, size_t size);
/*! \brief
\param
*/
void srt_free(srt_t* srt);
/*! \brief
\param
*/
static inline vtt_block_t* srt_next(vtt_block_t* srt) { return srt->next; }
/*! \brief
\param
*/
static inline utf8_char_t* srt_cue_data(srt_cue_t* cue) { return vtt_block_data(cue); }
/*! \brief
\param
*/
static inline srt_cue_t* srt_cue_from_caption_frame(caption_frame_t* frame, srt_t* srt) { return vtt_cue_from_caption_frame(frame, srt); };
/*! \brief
\param
*/
static inline void srt_cue_free_head(srt_t* srt) { vtt_cue_free_head(srt); };
/*! \brief
\param
*/
static inline srt_cue_t* srt_cue_new(srt_t* srt, const utf8_char_t* data, size_t size) { return vtt_block_new(srt, data, size, VTT_CUE); };
/*! \brief
\param
*/
static inline int srt_cue_to_caption_frame(srt_cue_t* cue, caption_frame_t* frame) { return vtt_cue_to_caption_frame(cue, frame); };
void srt_dump(srt_t* srt);
/*! \brief
\param
*/
void vtt_dump(srt_t* srt);
#ifdef __cplusplus
}
#endif
#endif

128
deps/libcaption/caption/utf8.h vendored Normal file
View file

@ -0,0 +1,128 @@
/**********************************************************************************************/
/* The MIT License */
/* */
/* Copyright 2016-2017 Twitch Interactive, Inc. or its affiliates. All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
/* in the Software without restriction, including without limitation the rights */
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
/* copies of the Software, and to permit persons to whom the Software is */
/* furnished to do so, subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be included in */
/* all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN */
/* THE SOFTWARE. */
/**********************************************************************************************/
#ifndef LIBCAPTION_UTF8_H
#define LIBCAPTION_UTF8_H
#ifdef __cplusplus
extern "C" {
#endif
#include <inttypes.h>
#include <stddef.h>
// These types exist to make the code more self dcoumenting
// utf8_char_t point is a null teminate string of utf8 encodecd chars
//
// utf8_size_t is the length of a string in chars
// size_t is bytes
typedef char utf8_char_t;
typedef size_t utf8_size_t;
/*! \brief
\param
Skiped continuation bytes
*/
const utf8_char_t* utf8_char_next(const utf8_char_t* c);
/*! \brief
\param
returnes the length of the char in bytes
*/
size_t utf8_char_length(const utf8_char_t* c);
/*! \brief
\param
returns 1 if first charcter is white space
*/
int utf8_char_whitespace(const utf8_char_t* c);
/*! \brief
\param
returns length of the string in bytes
size is number of charcter to count (0 to count until NULL term)
*/
size_t utf8_string_length(const utf8_char_t* data, utf8_size_t size);
/*! \brief
\param
*/
size_t utf8_char_copy(utf8_char_t* dst, const utf8_char_t* src);
/*! \brief
\param
returnes the number of utf8 charcters in a string givne the numbe of bytes
to coutn until the a null terminator, pass 0 for size
*/
utf8_size_t utf8_char_count(const char* data, size_t size);
/*! \brief
\param
returnes the length of the line in bytes triming not printable characters at the end
*/
utf8_size_t utf8_trimmed_length(const utf8_char_t* data, utf8_size_t charcters);
/*! \brief
\param
returns the length in bytes of the line including the new line charcter(s)
auto detects between windows(CRLF), unix(LF), mac(CR) and riscos (LFCR) line endings
*/
size_t utf8_line_length(const utf8_char_t* data);
/*! \brief
\param
returns number of chars to include before split
*/
utf8_size_t utf8_wrap_length(const utf8_char_t* data, utf8_size_t size);
/*! \brief
\param
returns number of new lines in the string
*/
int utf8_line_count(const utf8_char_t* data);
/*! \brief
\param
size in/out. In the the max seize, out is the size read;
returns number of new lins in teh string
*/
#define UFTF_DEFAULT_MAX_FILE_SIZE = (50 * 1024 * 1024);
utf8_char_t* utf8_load_text_file(const char* path, size_t* size);
/*! \brief
\param
Compares 2 strings up to max len
*/
#ifndef strnstr
char* strnstr(const char* string1, const char* string2, size_t len);
#endif
#ifdef __cplusplus
}
#endif
#endif

145
deps/libcaption/caption/vtt.h vendored Normal file
View file

@ -0,0 +1,145 @@
/**********************************************************************************************/
/* The MIT License */
/* */
/* Copyright 2016-2017 Twitch Interactive, Inc. or its affiliates. All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
/* in the Software without restriction, including without limitation the rights */
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
/* copies of the Software, and to permit persons to whom the Software is */
/* furnished to do so, subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be included in */
/* all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN */
/* THE SOFTWARE. */
/**********************************************************************************************/
#ifndef LIBCAPTION_VTT_H
#define LIBCAPTION_VTT_H
#ifdef __cplusplus
extern "C" {
#endif
#include "caption.h"
#include "eia608.h"
enum VTT_BLOCK_TYPE {
VTT_REGION = 0,
VTT_STYLE = 1,
VTT_NOTE = 2,
VTT_CUE = 3
};
// CUE represents a block of caption text
typedef struct _vtt_block_t {
struct _vtt_block_t* next;
enum VTT_BLOCK_TYPE type;
// CUE-Only
double timestamp;
double duration; // -1.0 for no duration
char* cue_settings;
char* cue_id;
// Standard block data
size_t text_size;
char* block_text;
} vtt_block_t;
// VTT files are a collection of REGION, STYLE and CUE blocks.
// XXX: Comments (NOTE blocks) are ignored
typedef struct _vtt_t {
vtt_block_t* region_head;
vtt_block_t* region_tail;
vtt_block_t* style_head;
vtt_block_t* style_tail;
vtt_block_t* cue_head;
vtt_block_t* cue_tail;
} vtt_t;
/*! \brief
\param
*/
vtt_t* vtt_new();
/*! \brief
\param
*/
void vtt_free(vtt_t* vtt);
/*! \brief
\param
*/
vtt_block_t* vtt_block_new(vtt_t* vtt, const utf8_char_t* data, size_t size, enum VTT_BLOCK_TYPE type);
/*! \brief
\param
*/
void vtt_cue_free_head(vtt_t* vtt);
/*! \brief
\param
*/
void vtt_style_free_head(vtt_t* vtt);
/*! \brief
\param
*/
void vtt_region_free_head(vtt_t* vtt);
// returns a vtt_t, containing linked lists of blocks. must be freed when done
/*! \brief
\param
*/
vtt_t* vtt_parse(const utf8_char_t* data, size_t size);
/*! \brief
\param
*/
vtt_t* _vtt_parse(const utf8_char_t* data, size_t size, int srt_mode);
/*! \brief
\param
*/
static inline vtt_block_t* vtt_cue_next(vtt_block_t* block) { return block->next; }
/*! \brief
\param
*/
static inline utf8_char_t* vtt_block_data(vtt_block_t* block) { return (utf8_char_t*)(block) + sizeof(vtt_block_t); }
/*! \brief
\param
*/
static inline void vtt_crack_time(double tt, int* hh, int* mm, int* ss, int* ms)
{
(*ms) = (int)((int64_t)(tt * 1000) % 1000);
(*ss) = (int)((int64_t)(tt) % 60);
(*mm) = (int)((int64_t)(tt / (60)) % 60);
(*hh) = (int)((int64_t)(tt / (60 * 60)));
}
// This only converts the current CUE, it does not walk the list
/*! \brief
\param
*/
int vtt_cue_to_caption_frame(vtt_block_t* cue, caption_frame_t* frame);
// returns the new cue
/*! \brief
\param
*/
vtt_block_t* vtt_cue_from_caption_frame(caption_frame_t* frame, vtt_t* vtt);
/*! \brief
\param
*/
void vtt_dump(vtt_t* vtt);
#ifdef __cplusplus
}
#endif
#endif

48
deps/libcaption/caption/xds.h vendored Normal file
View file

@ -0,0 +1,48 @@
/**********************************************************************************************/
/* The MIT License */
/* */
/* Copyright 2016-2017 Twitch Interactive, Inc. or its affiliates. All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
/* in the Software without restriction, including without limitation the rights */
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
/* copies of the Software, and to permit persons to whom the Software is */
/* furnished to do so, subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be included in */
/* all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN */
/* THE SOFTWARE. */
/**********************************************************************************************/
#ifndef LIBCAPTION_XDS_H
#define LIBCAPTION_XDS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <inttypes.h>
#include <stddef.h>
typedef struct {
int state;
uint8_t class_code;
uint8_t type;
uint32_t size;
uint8_t content[32];
uint8_t checksum;
} xds_t;
void xds_init(xds_t* xds);
int xds_decode(xds_t* xds, uint16_t cc);
#ifdef __cplusplus
}
#endif
#endif