/** @internal @This tries to find TS packets in the buffered input urefs. * * @param upipe description structure of the pipe * @param uref uref structure * @param upump_p reference to pump that generated the buffer */ static void upipe_ts_check_input(struct upipe *upipe, struct uref *uref, struct upump **upump_p) { struct upipe_ts_check *upipe_ts_check = upipe_ts_check_from_upipe(upipe); size_t size; if (unlikely(!ubase_check(uref_block_size(uref, &size)))) { uref_free(uref); upipe_throw_fatal(upipe, UBASE_ERR_ALLOC); return; } bool first = true; while (size > upipe_ts_check->output_size) { struct uref *output = uref_block_splice(uref, 0, upipe_ts_check->output_size); if (unlikely(output == NULL)) { uref_free(uref); upipe_throw_fatal(upipe, UBASE_ERR_ALLOC); return; } if (!first) uref_flow_delete_discontinuity(output); first = false; if (!upipe_ts_check_check(upipe, output, upump_p)) { uref_free(uref); return; } uref_block_resize(uref, upipe_ts_check->output_size, -1); size -= upipe_ts_check->output_size; } if (!first) uref_flow_delete_discontinuity(uref); if (size == upipe_ts_check->output_size) upipe_ts_check_check(upipe, uref, upump_p); }
static void upipe_rtp_h264_input(struct upipe *upipe, struct uref *uref, struct upump **upump_p) { size_t bz = 0; if (!ubase_check(uref_block_size(uref, &bz))) { upipe_err(upipe, "fail to get uref block size"); return upipe_rtp_h264_drop(upipe, uref); } uint8_t buf[bz]; int size = bz; if (unlikely(!ubase_check(uref_block_extract(uref, 0, size, buf)))) { upipe_err(upipe, "fail to read from uref"); return upipe_rtp_h264_drop(upipe, uref); } uint8_t s_len; const uint8_t *s = upipe_mpeg_scan(buf, buf + size, &s_len); if (s != buf) { upipe_err(upipe, "uref does not start with a mpeg start code"); return upipe_rtp_h264_drop(upipe, uref); } while (s < buf + size) { uint8_t e_len = 0; const uint8_t *e = upipe_mpeg_scan(s + s_len, buf + size, &e_len); if (!e) e = buf + size; struct uref *part = uref_block_splice(uref, s - buf + s_len + 1, e - (s + s_len + 1)); upipe_rtp_h264_output_nalu(upipe, *(s + s_len), part, upump_p); s = e; s_len = e_len; } uref_free(uref); }