Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/upipe-modules/upipe_dup.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ static void upipe_dup_input(struct upipe *upipe, struct uref *uref,
ulist_delete_foreach (&upipe_dup->outputs, uchain, uchain_tmp) {
struct upipe_dup_output *upipe_dup_output =
upipe_dup_output_from_uchain(uchain);
struct upipe *output = upipe_dup_output_to_upipe(upipe_dup_output);
struct upipe *sub = upipe_dup_output_to_upipe(upipe_dup_output);
/* the last sub takes the original when no direct output wants it */
if (ulist_is_last(&upipe_dup->outputs, uchain) && !output) {
upipe_dup_output_output(output, uref, upump_p);
upipe_dup_output_output(sub, uref, upump_p);
uref = NULL;
} else {
struct uref *new_uref = uref_dup(uref);
Expand All @@ -227,7 +228,7 @@ static void upipe_dup_input(struct upipe *upipe, struct uref *uref,
upipe_throw_fatal(upipe, UBASE_ERR_ALLOC);
return;
}
upipe_dup_output_output(output, new_uref, upump_p);
upipe_dup_output_output(sub, new_uref, upump_p);
}
}

Expand Down
6 changes: 4 additions & 2 deletions lib/upipe-ts/upipe_ts_psi_split.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,13 @@ static void upipe_ts_psi_split_input(struct upipe *upipe, struct uref *uref,
if (ubase_check(uref_ts_flow_get_psi_filter(output->flow_def, &filter,
&mask, &size)) &&
ubase_check(uref_block_match(uref, filter, mask, size))) {
if (likely(uchain->next == NULL)) {
/* the list is circular: the last sub is followed by the head */
if (likely(uchain->next == &upipe_ts_psi_split->subs)) {
upipe_ts_psi_split_sub_output(
upipe_ts_psi_split_sub_to_upipe(output), uref,
upump_p);
uref = NULL;
/* the output may have added a sub after this one */
return;
} else {
struct uref *new_uref = uref_dup(uref);
if (likely(new_uref != NULL))
Expand Down
3 changes: 2 additions & 1 deletion lib/upipe-ts/upipe_ts_split.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ static void upipe_ts_split_input(struct upipe *upipe, struct uref *uref,
ulist_delete_foreach(&upipe_ts_split->pids[pid].subs, uchain, uchain_tmp) {
struct upipe_ts_split_sub *output =
upipe_ts_split_sub_from_uchain_pid(uchain);
if (likely(uchain->next == NULL)) {
/* the list is circular: the last sub is followed by the head */
if (likely(uchain->next == &upipe_ts_split->pids[pid].subs)) {
upipe_ts_split_sub_output(upipe_ts_split_sub_to_upipe(output),
uref, upump_p);
uref = NULL;
Expand Down
11 changes: 11 additions & 0 deletions tests/upipe_dup_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#define UPROBE_LOG_LEVEL UPROBE_LOG_DEBUG

static int counter = 0;
/* the uref given to the dup, and how many sinks received it rather than a copy */
static struct uref *original = NULL;
static int originals = 0;
static int flow_foo_counter = 0;
static int flow_bar_counter = 0;

Expand Down Expand Up @@ -71,6 +74,8 @@ static void test_input(struct upipe *upipe, struct uref *uref,
{
assert(uref != NULL);
counter++;
if (uref == original)
originals++;
uref_free(uref);
}

Expand Down Expand Up @@ -154,8 +159,11 @@ int main(int argc, char *argv[])

uref = uref_alloc(uref_mgr);
assert(uref != NULL);
original = uref;
upipe_input(upipe_dup, uref, NULL);
assert(counter == 1);
/* the only sub takes the original: nothing was copied */
assert(originals == 1);
counter = 0;

struct upipe *upipe_dup_output1 = upipe_void_alloc_sub(upipe_dup,
Expand All @@ -172,8 +180,11 @@ int main(int argc, char *argv[])

uref = uref_alloc(uref_mgr);
assert(uref != NULL);
original = uref;
upipe_input(upipe_dup, uref, NULL);
assert(counter == 2);
/* one copy for the first sub, the original to the last */
assert(originals == 2);
assert(flow_foo_counter == 1);
assert(flow_bar_counter == 2);

Expand Down
39 changes: 34 additions & 5 deletions tests/upipe_ts_psi_split_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,33 @@ struct test {
struct upipe upipe;
};

static struct uref_mgr *uref_mgr;
static struct uprobe *uprobe_stdio;
static struct upipe *upipe_ts_psi_split;
static struct upipe *upipe_ts_psi_split_output70 = NULL;

/** adds a sub from inside the output of the last one */
static void test_add_sub70(void)
{
struct uref *flow_def = uref_block_flow_alloc_def(uref_mgr, "mpegtspsi.");
assert(flow_def != NULL);
uint8_t filter[PSI_HEADER_SIZE_SYNTAX1];
memset(filter, 0, PSI_HEADER_SIZE_SYNTAX1);
filter[1] = 0x80;
uint8_t mask[PSI_HEADER_SIZE_SYNTAX1];
memset(mask, 0, PSI_HEADER_SIZE_SYNTAX1);
mask[1] = 0x80;
psi_set_tableid(mask, 0xff);
psi_set_tableid(filter, 70);
ubase_assert(uref_ts_flow_set_psi_filter(flow_def, filter, mask,
PSI_HEADER_SIZE_SYNTAX1));
upipe_ts_psi_split_output70 = upipe_flow_alloc_sub(upipe_ts_psi_split,
uprobe_pfx_alloc(uprobe_use(uprobe_stdio), UPROBE_LOG_LEVEL,
"ts psi split output 70"), flow_def);
assert(upipe_ts_psi_split_output70 != NULL);
uref_free(flow_def);
}

/** helper phony pipe */
static struct upipe *test_alloc(struct upipe_mgr *mgr, struct uprobe *uprobe,
uint32_t signature, va_list args)
Expand Down Expand Up @@ -107,6 +134,8 @@ static void test_input(struct upipe *upipe, struct uref *uref,
}
uref_block_unmap(uref, 0);
uref_free(uref);
if (test->table_id == 69 && upipe_ts_psi_split_output70 == NULL)
test_add_sub70();
}

/** helper phony pipe */
Expand Down Expand Up @@ -145,17 +174,15 @@ int main(int argc, char *argv[])
struct udict_mgr *udict_mgr = udict_inline_mgr_alloc(UDICT_POOL_DEPTH,
umem_mgr, -1, -1);
assert(udict_mgr != NULL);
struct uref_mgr *uref_mgr = uref_std_mgr_alloc(UREF_POOL_DEPTH, udict_mgr,
0);
uref_mgr = uref_std_mgr_alloc(UREF_POOL_DEPTH, udict_mgr, 0);
assert(uref_mgr != NULL);
struct ubuf_mgr *ubuf_mgr = ubuf_block_mem_mgr_alloc(UBUF_POOL_DEPTH,
UBUF_POOL_DEPTH,
umem_mgr, 0, 0, -1, 0);
assert(ubuf_mgr != NULL);
struct uprobe uprobe;
uprobe_init(&uprobe, catch, NULL);
struct uprobe *uprobe_stdio = uprobe_stdio_alloc(&uprobe, stdout,
UPROBE_LOG_LEVEL);
uprobe_stdio = uprobe_stdio_alloc(&uprobe, stdout, UPROBE_LOG_LEVEL);
assert(uprobe_stdio != NULL);

struct uref *uref;
Expand All @@ -164,7 +191,7 @@ int main(int argc, char *argv[])

struct upipe_mgr *upipe_ts_psi_split_mgr = upipe_ts_psi_split_mgr_alloc();
assert(upipe_ts_psi_split_mgr != NULL);
struct upipe *upipe_ts_psi_split = upipe_void_alloc(upipe_ts_psi_split_mgr,
upipe_ts_psi_split = upipe_void_alloc(upipe_ts_psi_split_mgr,
uprobe_pfx_alloc(uprobe_use(uprobe_stdio), UPROBE_LOG_LEVEL,
"ts psi split"));
assert(upipe_ts_psi_split != NULL);
Expand Down Expand Up @@ -248,6 +275,8 @@ int main(int argc, char *argv[])

upipe_release(upipe_ts_psi_split_output68);
upipe_release(upipe_ts_psi_split_output69);
assert(upipe_ts_psi_split_output70 != NULL);
upipe_release(upipe_ts_psi_split_output70);
upipe_release(upipe_ts_psi_split);
upipe_mgr_release(upipe_ts_psi_split_mgr); // nop

Expand Down
Loading