diff --git a/include/upipe-ts/upipe_ts_mux.h b/include/upipe-ts/upipe_ts_mux.h index d38294313..8714b510b 100644 --- a/include/upipe-ts/upipe_ts_mux.h +++ b/include/upipe-ts/upipe_ts_mux.h @@ -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, @@ -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 diff --git a/lib/upipe-ts/upipe_ts_mux.c b/lib/upipe-ts/upipe_ts_mux.c index c656c531e..8d69800e0 100644 --- a/lib/upipe-ts/upipe_ts_mux.c +++ b/lib/upipe-ts/upipe_ts_mux.c @@ -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; @@ -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; @@ -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); @@ -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 @@ -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: