Skip to content

Commit 9c667b9

Browse files
committed
uref: add priv2 member
1 parent cdc37cb commit 9c667b9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

include/upipe/uref.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ struct uref {
129129
uint64_t rap_cr_delay;
130130
/** private for local pipe user */
131131
uint64_t priv;
132+
/** small buffer for miscellaneous use */
133+
uint8_t priv2[128];
132134
};
133135

134136
UBASE_FROM_TO(uref, uchain, uchain, uchain)
@@ -193,6 +195,7 @@ static inline void uref_init(struct uref *uref)
193195
uref->cr_dts_delay = UINT64_MAX;
194196
uref->rap_cr_delay = UINT64_MAX;
195197
uref->priv = UINT64_MAX;
198+
memset(uref->priv2, 0, sizeof uref->priv2);
196199
}
197200

198201
/** @This allocates and initializes a new uref.
@@ -284,6 +287,7 @@ static inline struct uref *uref_dup_inner(struct uref *uref)
284287
new_uref->cr_dts_delay = uref->cr_dts_delay;
285288
new_uref->rap_cr_delay = uref->rap_cr_delay;
286289
new_uref->priv = uref->priv;
290+
memcpy(new_uref->priv2, uref->priv2, sizeof uref->priv2);
287291

288292
return new_uref;
289293
}
@@ -351,6 +355,37 @@ static inline struct uref *uref_fork(struct uref *uref, struct ubuf *ubuf)
351355
return new_uref;
352356
}
353357

358+
/** @This copies from the given buffer into priv2 and clears the remaining space.
359+
*
360+
* @param uref destination uref structure
361+
* @param buf data to be copied
362+
* @param size how much to be copied
363+
* @return error if the size is too large
364+
*/
365+
static inline int uref_set_priv2(struct uref *uref, const void *buf, const size_t size)
366+
{
367+
if (size > sizeof uref->priv2)
368+
return UBASE_ERR_INVALID;
369+
memcpy(uref->priv2, buf, size);
370+
memset(uref->priv2 + size, 0, sizeof uref->priv2 - size);
371+
return UBASE_ERR_NONE;
372+
}
373+
374+
/** @This copies into the given buffer from priv2.
375+
*
376+
* @param buf destination buffer
377+
* @param uref source uref structure
378+
* @param size how much to be copied
379+
* @return error if the size is too large
380+
*/
381+
static inline int uref_get_priv2(void *buf, const struct uref *uref, const size_t size)
382+
{
383+
if (size > sizeof uref->priv2)
384+
return UBASE_ERR_INVALID;
385+
memcpy(buf, uref->priv2, size);
386+
return UBASE_ERR_NONE;
387+
}
388+
354389
/** @This increments the reference count of a uref manager.
355390
*
356391
* @param mgr pointer to uref manager

0 commit comments

Comments
 (0)