Skip to content

Commit

Permalink
eia608: allow to prepare a caption without displaying it
Browse files Browse the repository at this point in the history
  • Loading branch information
rasky committed Dec 7, 2024
1 parent eaf8817 commit 609753b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/eia608.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ typedef struct {
eia608_channel_t cc; ///< Caption channel to transmit on (default: EIA608_CC1)
int row; ///< The row to display the caption on, range 1-15 (default: 11)
bool underline; ///< Enable underline for the caption (default: false)
bool hidden; ///< Prepare the caption but don't display it (default: false)
} eia608_captionparms_t;

/** @brief Calculate EIA608 parity for 7-bit value */
Expand Down Expand Up @@ -226,6 +227,20 @@ void eia608_write_ctrl_raw(eia608_ctrl_t ctrl);
*/
void eia608_caption(const char *utf8_str, float duration_secs, eia608_captionparms_t *parms);

/**
* @brief Show a caption that was previously prepared with #eia608_caption
*
* By default, #eia608_caption will prepare the caption and display it right
* away. Transmitting a caption can take a non negligible amount of time
* (it is about 1 second every 60 characters). If you need perfect syncing,
* you can first prepare the caption and keep it hidden, by calling
* #eia608_caption with the \p hidden parameter set to true in \p parms.
* Then, when you are ready to display the caption, call this function.
*
* @param cc Channel in which the caption was prepared.
*/
void eia608_caption_show(eia608_channel_t cc);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 6 additions & 0 deletions src/eia608.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,5 +528,11 @@ void eia608_caption(const char *utf8_str, float duration_secs, eia608_captionpar
}

// Emit end caption command (swap buffers)
if (!parms->hidden)
eia608_caption_show(cc);
}

void eia608_caption_show(eia608_channel_t cc)
{
eia608_write_ctrl_raw(cc == EIA608_CC1 ? EIA608_CC1_EOC : EIA608_CC2_EOC);
}

0 comments on commit 609753b

Please sign in to comment.