Skip to content

Commit

Permalink
upipe_ts_mux: add an option to force PES alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
quarium authored and cmassiot committed Feb 5, 2024
1 parent acfaaa5 commit 24aab53
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/upipe-ts/upipe_ts_mux.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ enum upipe_ts_mux_command {
UPIPE_TS_MUX_SET_PES_MIN_DURATION,
/** returns the default minimum PES duration (uint64_t *) */
UPIPE_TS_MUX_GET_PES_MIN_DURATION,
/** forces PES alignment (int) */
UPIPE_TS_MUX_FORCE_PES_ALIGNMENT,

/** ts_encaps commands begin here */
UPIPE_TS_MUX_ENCAPS = UPIPE_CONTROL_LOCAL + 0x1000,
Expand Down Expand Up @@ -781,6 +783,19 @@ static inline int upipe_ts_mux_set_pes_min_duration(struct upipe *upipe,
UPIPE_TS_MUX_SIGNATURE, duration);
}

/** @@This forces the PES alignment on all outputs.
*
* @param upipe description structure of the pipe
* @param force true if all the output PES must be align
* @return an error code
*/
static inline int upipe_ts_mux_force_pes_alignment(struct upipe *upipe,
bool force)
{
return upipe_control(upipe, UPIPE_TS_MUX_FORCE_PES_ALIGNMENT,
UPIPE_TS_MUX_SIGNATURE, force ? 1 : 0);
}

/** @This stops updating a PSI table upon sub removal.
*
* @param upipe description structure of the pipe
Expand Down
26 changes: 26 additions & 0 deletions lib/upipe-ts/upipe_ts_mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ struct upipe_ts_mux {
size_t mtu;
/** size of the TB buffer */
size_t tb_size;
/** force PES alignment */
bool force_pes_alignment;

/** list of PIDs carrying PSI */
struct uchain psi_pids;
Expand Down Expand Up @@ -1367,6 +1369,10 @@ static int upipe_ts_mux_input_set_flow_def(struct upipe *upipe,
}
}
UBASE_FATAL(upipe, uref_ts_flow_set_pid(flow_def_dup, pid));
if (upipe_ts_mux->force_pes_alignment && !pes_alignment) {
upipe_notice(upipe, "forcing PES alignment");
pes_alignment = true;
}

if (!ubase_ncmp(def, "void.scte35.")) { /* SCTE-35 */
input->cr_sys = UINT64_MAX;
Expand Down Expand Up @@ -2864,6 +2870,7 @@ static struct upipe *upipe_ts_mux_alloc(struct upipe_mgr *mgr,
upipe_ts_mux->required_octetrate = 0;
upipe_ts_mux->octetrate_in_progress = false;
upipe_ts_mux->interval = 0;
upipe_ts_mux->force_pes_alignment = false;

ulist_init(&upipe_ts_mux->psi_pids);
ulist_init(&upipe_ts_mux->psi_pids_splice);
Expand Down Expand Up @@ -4644,6 +4651,20 @@ static int _upipe_ts_mux_get_pes_min_duration(struct upipe *upipe,
return UBASE_ERR_NONE;
}

/** @internal @This forces the PES alignment on all outputs.
*
* @param upipe description structure of the pipe
* @param force true if all the output PES must be align
* @return an error code
*/
static int _upipe_ts_mux_force_pes_alignment(struct upipe *upipe,
bool force)
{
struct upipe_ts_mux *mux = upipe_ts_mux_from_upipe(upipe);
mux->force_pes_alignment = force;
return UBASE_ERR_NONE;
}

/** @internal @This sets the default minimum PES duration.
*
* @param upipe description structure of the pipe
Expand Down Expand Up @@ -4909,6 +4930,11 @@ static int _upipe_ts_mux_control(struct upipe *upipe, int command, va_list args)
uint64_t *duration = va_arg(args, uint64_t *);
return _upipe_ts_mux_get_pes_min_duration(upipe, duration);
}
case UPIPE_TS_MUX_FORCE_PES_ALIGNMENT: {
UBASE_SIGNATURE_CHECK(args, UPIPE_TS_MUX_SIGNATURE)
int force = va_arg(args, int);
return _upipe_ts_mux_force_pes_alignment(upipe, !!force);
}

case UPIPE_TS_MUX_GET_VERSION:
case UPIPE_TS_MUX_SET_VERSION:
Expand Down

0 comments on commit 24aab53

Please sign in to comment.