caption_frame_decode: rework API

* pop_on mode requires incrementing the frame timestamp until
  end_of_caption is encountered.

* caption_frame_decode now always updates the timestamp of the
  frame when the timestamp parameter != -1. This requires that callers
  only pass a valid timestamp when a new one is encountered, for
  example with SCC the timestamp at the start of the cue, then -1
  until the next new timestamp.

* A new enum member is added for the return value, LIBCAPTION_CLEAR.
  It allows the caller to determine that closed captions should not
  be displayed anymore, in order to finish the previous cue earlier
  than the start of the next cue.
This commit is contained in:
Mathieu Duponchelle 2020-03-18 22:06:33 +01:00
parent 09f332f31f
commit 96cfcff4cf
3 changed files with 15 additions and 11 deletions

View file

@ -238,7 +238,7 @@ caption_frame_decode_control (caption_frame_t * frame, uint16_t cc_data)
case eia608_control_erase_display_memory:
caption_frame_buffer_clear (&frame->front);
return LIBCAPTION_READY;
return LIBCAPTION_CLEAR;
// ROLL-UP
case eia608_control_roll_up_2:
@ -333,16 +333,18 @@ caption_frame_decode (caption_frame_t * frame, uint16_t cc_data,
return frame->status;
}
if (0 > frame->timestamp || frame->timestamp == timestamp
|| LIBCAPTION_READY == frame->status) {
frame->timestamp = timestamp;
frame->status = LIBCAPTION_OK;
}
// skip duplicate controll commands. We also skip duplicate specialna to match the behaviour of iOS/vlc
if ((eia608_is_specialna (cc_data) || eia608_is_control (cc_data))
&& cc_data == frame->state.cc_data) {
frame->status = LIBCAPTION_OK;
return frame->status;
if ((eia608_is_specialna(cc_data) || eia608_is_control(cc_data)) && cc_data == frame->state.cc_data) {
if (timestamp < 0 && caption_frame_popon (frame))
frame->timestamp += (1 / 29.97);
return LIBCAPTION_OK;
}
if (timestamp >= 0) {
frame->timestamp = timestamp;
frame->status = LIBCAPTION_OK;
} else if (caption_frame_popon (frame)) {
frame->timestamp += (1 / 29.97);
}
frame->state.cc_data = cc_data;

View file

@ -43,7 +43,8 @@ typedef signed int ssize_t;
typedef enum {
LIBCAPTION_ERROR = 0,
LIBCAPTION_OK = 1,
LIBCAPTION_READY = 2
LIBCAPTION_READY = 2,
LIBCAPTION_CLEAR = 3,
} libcaption_stauts_t;
static inline libcaption_stauts_t libcaption_status_update(libcaption_stauts_t old_stat, libcaption_stauts_t new_stat)

View file

@ -812,6 +812,7 @@ extern "C" {
pub const libcaption_stauts_t_LIBCAPTION_ERROR: libcaption_stauts_t = 0;
pub const libcaption_stauts_t_LIBCAPTION_OK: libcaption_stauts_t = 1;
pub const libcaption_stauts_t_LIBCAPTION_READY: libcaption_stauts_t = 2;
pub const libcaption_stauts_t_LIBCAPTION_CLEAR: libcaption_stauts_t = 3;
pub type libcaption_stauts_t = u32;
#[repr(C)]
#[repr(align(4))]