Skip to content

Commit

Permalink
upipe_id3v2f: compute maximum octetrate
Browse files Browse the repository at this point in the history
  • Loading branch information
quarium authored and cmassiot committed Jul 22, 2024
1 parent 25f0b43 commit fb51c14
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions lib/upipe-framers/upipe_id3v2_framer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 EasyTools
* Copyright (C) 2023-2024 EasyTools
*
* Authors: Arnaud de Turckheim
*
Expand Down Expand Up @@ -77,6 +77,11 @@ struct upipe_id3v2f {
* sequence header) */
bool acquired;

/** max octetrate */
uint64_t max_octetrate;
/** last output dts */
uint64_t last_dts;

/** public upipe structure */
struct upipe upipe;
};
Expand Down Expand Up @@ -112,6 +117,8 @@ static struct upipe *upipe_id3v2f_alloc(struct upipe_mgr *mgr,
upipe_id3v2f_init_flow_def(upipe);
upipe_id3v2f->next_uref = NULL;
upipe_id3v2f->next_uref_size = 0;
upipe_id3v2f->max_octetrate = 0;
upipe_id3v2f->last_dts = UINT64_MAX;
uref_init(&upipe_id3v2f->au_uref_s);
upipe_throw_ready(upipe);
return upipe;
Expand Down Expand Up @@ -145,20 +152,8 @@ static void upipe_id3v2f_work(struct upipe *upipe, struct upump **upump_p)
goto upipe_id3v2f_work_err;
}

UBASE_FATAL(upipe, uref_flow_set_complete(flow_def))
UBASE_FATAL(upipe, uref_flow_set_def(flow_def, "block.id3.metadata"))

flow_def = upipe_id3v2f_store_flow_def_attr(upipe, flow_def);
if (unlikely(flow_def == NULL)) {
upipe_throw_fatal(upipe, UBASE_ERR_ALLOC);
uref_free(upipe_id3v2f->next_uref);
goto upipe_id3v2f_work_err;
}
upipe_id3v2f_store_flow_def(upipe, flow_def);
upipe_id3v2f_sync_acquired(upipe);

/* We work on encoded data so in the DTS domain. Rebase on DTS */
uint64_t date;
uint64_t date = UINT64_MAX;
struct urational drift_rate = { 0, 0 };
uref_clock_get_rate(upipe_id3v2f->next_uref, &drift_rate);
#define SET_DATE(dv) \
Expand All @@ -173,6 +168,32 @@ static void upipe_id3v2f_work(struct upipe *upipe, struct upump **upump_p)
SET_DATE(orig)
#undef SET_DATE

UBASE_FATAL(upipe, uref_flow_set_complete(flow_def))
UBASE_FATAL(upipe, uref_flow_set_def(flow_def, "block.id3.metadata."))

flow_def = upipe_id3v2f_store_flow_def_attr(upipe, flow_def);
if (unlikely(flow_def == NULL)) {
upipe_throw_fatal(upipe, UBASE_ERR_ALLOC);
uref_free(upipe_id3v2f->next_uref);
goto upipe_id3v2f_work_err;
}

uint64_t octetrate = upipe_id3v2f->next_uref_size;
if (upipe_id3v2f->last_dts != UINT64_MAX && date != UINT64_MAX &&
date > upipe_id3v2f->last_dts) {
octetrate = upipe_id3v2f->next_uref_size * UCLOCK_FREQ /
(date - upipe_id3v2f->last_dts);
}
octetrate = ((octetrate >> 10) + 1) << 10;
if (octetrate > upipe_id3v2f->max_octetrate) {
upipe_notice_va(upipe, "increase max octetrate to %"PRIu64, octetrate);
upipe_id3v2f->max_octetrate = octetrate;
}
upipe_id3v2f->last_dts = date;
uref_block_flow_set_max_octetrate(flow_def, upipe_id3v2f->max_octetrate);
upipe_id3v2f_store_flow_def(upipe, flow_def);
upipe_id3v2f_sync_acquired(upipe);

uref_clock_set_dts_pts_delay(upipe_id3v2f->next_uref, 0);
if (drift_rate.den)
uref_clock_set_rate(upipe_id3v2f->next_uref, drift_rate);
Expand Down

0 comments on commit fb51c14

Please sign in to comment.