* [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API
@ 2022-08-04 17:31 Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 2/9] avcodec/cbs: Avoid code duplication for making unit refcounted/writable Andreas Rheinhardt
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Andreas Rheinhardt @ 2022-08-04 17:31 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
These buffers are not shared in any way.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/error_resilience.c | 18 +++++++++---------
libavcodec/error_resilience.h | 4 ++--
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index f957c68d2c..2aa6f1d864 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -946,17 +946,17 @@ void ff_er_frame_end(ERContext *s)
av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\n");
for (i = 0; i < 2; i++) {
- s->ref_index_buf[i] = av_buffer_allocz(s->mb_stride * s->mb_height * 4 * sizeof(uint8_t));
- s->motion_val_buf[i] = av_buffer_allocz((size + 4) * 2 * sizeof(uint16_t));
- if (!s->ref_index_buf[i] || !s->motion_val_buf[i])
+ s->ref_index[i] = av_calloc(s->mb_stride * s->mb_height, 4 * sizeof(uint8_t));
+ s->motion_val_base[i] = av_calloc(size + 4, 2 * sizeof(uint16_t));
+ if (!s->ref_index[i] || !s->motion_val_base[i])
break;
- s->cur_pic.ref_index[i] = s->ref_index_buf[i]->data;
- s->cur_pic.motion_val[i] = (int16_t (*)[2])s->motion_val_buf[i]->data + 4;
+ s->cur_pic.ref_index[i] = s->ref_index[i];
+ s->cur_pic.motion_val[i] = s->motion_val_base[i] + 4;
}
if (i < 2) {
for (i = 0; i < 2; i++) {
- av_buffer_unref(&s->ref_index_buf[i]);
- av_buffer_unref(&s->motion_val_buf[i]);
+ av_freep(&s->ref_index[i]);
+ av_freep(&s->motion_val_base[i]);
s->cur_pic.ref_index[i] = NULL;
s->cur_pic.motion_val[i] = NULL;
}
@@ -1343,8 +1343,8 @@ void ff_er_frame_end(ERContext *s)
}
for (i = 0; i < 2; i++) {
- av_buffer_unref(&s->ref_index_buf[i]);
- av_buffer_unref(&s->motion_val_buf[i]);
+ av_freep(&s->ref_index[i]);
+ av_freep(&s->motion_val_base[i]);
s->cur_pic.ref_index[i] = NULL;
s->cur_pic.motion_val[i] = NULL;
}
diff --git a/libavcodec/error_resilience.h b/libavcodec/error_resilience.h
index 53e5cf2621..47cc8a4fc6 100644
--- a/libavcodec/error_resilience.h
+++ b/libavcodec/error_resilience.h
@@ -75,8 +75,8 @@ typedef struct ERContext {
ERPicture last_pic;
ERPicture next_pic;
- AVBufferRef *ref_index_buf[2];
- AVBufferRef *motion_val_buf[2];
+ int8_t *ref_index[2];
+ int16_t (*motion_val_base[2])[2];
uint16_t pp_time;
uint16_t pb_time;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 2/9] avcodec/cbs: Avoid code duplication for making unit refcounted/writable
2022-08-04 17:31 [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API Andreas Rheinhardt
@ 2022-08-04 17:36 ` Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 3/9] avcodec/cbs: Remove redundant assignment Andreas Rheinhardt
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andreas Rheinhardt @ 2022-08-04 17:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/cbs.c | 74 ++++++++++++++++--------------------------------
1 file changed, 25 insertions(+), 49 deletions(-)
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 8c0a5b5719..f715e463a1 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -921,9 +921,9 @@ int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx,
return 0;
}
-static int cbs_clone_unit_content(AVBufferRef **clone_ref,
- CodedBitstreamUnit *unit,
- const CodedBitstreamUnitTypeDescriptor *desc)
+static int cbs_clone_internal_refs_unit_content(AVBufferRef **clone_ref,
+ const CodedBitstreamUnit *unit,
+ const CodedBitstreamUnitTypeDescriptor *desc)
{
uint8_t *src, *copy;
uint8_t **src_ptr, **copy_ptr;
@@ -987,19 +987,18 @@ fail:
return err;
}
-int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
- CodedBitstreamUnit *unit)
+/*
+ * On success, unit->content and unit->content_ref are updated with
+ * the new content; unit is untouched on failure.
+ * Any old content_ref is simply overwritten and not freed.
+ */
+static int cbs_clone_unit_content(CodedBitstreamContext *ctx,
+ CodedBitstreamUnit *unit)
{
const CodedBitstreamUnitTypeDescriptor *desc;
AVBufferRef *ref;
int err;
- av_assert0(unit->content);
- if (unit->content_ref) {
- // Already refcounted, nothing to do.
- return 0;
- }
-
desc = cbs_find_unit_type_desc(ctx, unit);
if (!desc)
return AVERROR(ENOSYS);
@@ -1014,7 +1013,7 @@ int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
break;
case CBS_CONTENT_TYPE_INTERNAL_REFS:
- err = cbs_clone_unit_content(&ref, unit, desc);
+ err = cbs_clone_internal_refs_unit_content(&ref, unit, desc);
break;
case CBS_CONTENT_TYPE_COMPLEX:
@@ -1035,51 +1034,28 @@ int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
return 0;
}
+int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
+ CodedBitstreamUnit *unit)
+{
+ av_assert0(unit->content);
+ if (unit->content_ref)
+ return 0;
+ return cbs_clone_unit_content(ctx, unit);
+}
+
int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
CodedBitstreamUnit *unit)
{
- const CodedBitstreamUnitTypeDescriptor *desc;
- AVBufferRef *ref;
+ AVBufferRef *ref = unit->content_ref;
int err;
- // This can only be applied to refcounted units.
- err = ff_cbs_make_unit_refcounted(ctx, unit);
- if (err < 0)
- return err;
- av_assert0(unit->content && unit->content_ref);
-
- if (av_buffer_is_writable(unit->content_ref))
+ av_assert0(unit->content);
+ if (ref && av_buffer_is_writable(ref))
return 0;
- desc = cbs_find_unit_type_desc(ctx, unit);
- if (!desc)
- return AVERROR(ENOSYS);
-
- switch (desc->content_type) {
- case CBS_CONTENT_TYPE_POD:
- err = av_buffer_make_writable(&unit->content_ref);
- break;
-
- case CBS_CONTENT_TYPE_INTERNAL_REFS:
- err = cbs_clone_unit_content(&ref, unit, desc);
- break;
-
- case CBS_CONTENT_TYPE_COMPLEX:
- if (!desc->content_clone)
- return AVERROR_PATCHWELCOME;
- err = desc->content_clone(&ref, unit);
- break;
-
- default:
- av_assert0(0 && "Invalid content type.");
- }
+ err = cbs_clone_unit_content(ctx, unit);
if (err < 0)
return err;
-
- if (desc->content_type != CBS_CONTENT_TYPE_POD) {
- av_buffer_unref(&unit->content_ref);
- unit->content_ref = ref;
- }
- unit->content = unit->content_ref->data;
+ av_buffer_unref(&ref);
return 0;
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 3/9] avcodec/cbs: Remove redundant assignment
2022-08-04 17:31 [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 2/9] avcodec/cbs: Avoid code duplication for making unit refcounted/writable Andreas Rheinhardt
@ 2022-08-04 17:36 ` Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 4/9] avcodec/cbs: Use smaller scope for variables, add const Andreas Rheinhardt
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andreas Rheinhardt @ 2022-08-04 17:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The code just creates new references without allocating
new buffers for the subobjects; therefore the actual data pointer
stays valid and need not be updated.
Also remove an assert that ensured that the calculation
for updating the pointer makes sense.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/cbs.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index f715e463a1..43329a14a4 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -955,17 +955,11 @@ static int cbs_clone_internal_refs_unit_content(AVBufferRef **clone_ref,
goto fail;
}
- // src_ptr is required to point somewhere inside src_buf. If it
- // doesn't, there is a bug somewhere.
- av_assert0(*src_ptr >= (*src_buf)->data &&
- *src_ptr < (*src_buf)->data + (*src_buf)->size);
-
*copy_buf = av_buffer_ref(*src_buf);
if (!*copy_buf) {
err = AVERROR(ENOMEM);
goto fail;
}
- *copy_ptr = (*copy_buf)->data + (*src_ptr - (*src_buf)->data);
}
*clone_ref = av_buffer_create(copy, desc->content_size,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 4/9] avcodec/cbs: Use smaller scope for variables, add const
2022-08-04 17:31 [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 2/9] avcodec/cbs: Avoid code duplication for making unit refcounted/writable Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 3/9] avcodec/cbs: Remove redundant assignment Andreas Rheinhardt
@ 2022-08-04 17:36 ` Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 5/9] avcodec/cbs_internal, cbs_h2645: Add and use new descriptor macros Andreas Rheinhardt
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andreas Rheinhardt @ 2022-08-04 17:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
And also avoid an unnecessary indirection for src_buf.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/cbs.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 43329a14a4..c81297ec93 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -925,9 +925,8 @@ static int cbs_clone_internal_refs_unit_content(AVBufferRef **clone_ref,
const CodedBitstreamUnit *unit,
const CodedBitstreamUnitTypeDescriptor *desc)
{
- uint8_t *src, *copy;
- uint8_t **src_ptr, **copy_ptr;
- AVBufferRef **src_buf, **copy_buf;
+ const uint8_t *src;
+ uint8_t *copy;
int err, i;
av_assert0(unit->content);
@@ -938,16 +937,16 @@ static int cbs_clone_internal_refs_unit_content(AVBufferRef **clone_ref,
return AVERROR(ENOMEM);
for (i = 0; i < desc->nb_ref_offsets; i++) {
- src_ptr = (uint8_t**)(src + desc->ref_offsets[i]);
- src_buf = (AVBufferRef**)(src_ptr + 1);
- copy_ptr = (uint8_t**)(copy + desc->ref_offsets[i]);
- copy_buf = (AVBufferRef**)(copy_ptr + 1);
+ const uint8_t *const *src_ptr = (const uint8_t* const*)(src + desc->ref_offsets[i]);
+ const AVBufferRef *src_buf = *(AVBufferRef**)(src_ptr + 1);
+ uint8_t **copy_ptr = (uint8_t**)(copy + desc->ref_offsets[i]);
+ AVBufferRef **copy_buf = (AVBufferRef**)(copy_ptr + 1);
if (!*src_ptr) {
- av_assert0(!*src_buf);
+ av_assert0(!src_buf);
continue;
}
- if (!*src_buf) {
+ if (!src_buf) {
// We can't handle a non-refcounted pointer here - we don't
// have enough information to handle whatever structure lies
// at the other end of it.
@@ -955,7 +954,7 @@ static int cbs_clone_internal_refs_unit_content(AVBufferRef **clone_ref,
goto fail;
}
- *copy_buf = av_buffer_ref(*src_buf);
+ *copy_buf = av_buffer_ref(src_buf);
if (!*copy_buf) {
err = AVERROR(ENOMEM);
goto fail;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 5/9] avcodec/cbs_internal, cbs_h2645: Add and use new descriptor macros
2022-08-04 17:31 [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API Andreas Rheinhardt
` (2 preceding siblings ...)
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 4/9] avcodec/cbs: Use smaller scope for variables, add const Andreas Rheinhardt
@ 2022-08-04 17:36 ` Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 6/9] avcodec/cbs_internal: Use unions to shrink size of descriptors Andreas Rheinhardt
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andreas Rheinhardt @ 2022-08-04 17:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/cbs_h2645.c | 56 ++++++++-------------------------------
libavcodec/cbs_internal.h | 31 +++++++++++++++++-----
2 files changed, 35 insertions(+), 52 deletions(-)
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 12e38c80b5..117b609dc3 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1396,18 +1396,9 @@ static const CodedBitstreamUnitTypeDescriptor cbs_h264_unit_types[] = {
CBS_UNIT_TYPE_INTERNAL_REF(H264_NAL_PPS, H264RawPPS, slice_group_id),
- {
- .nb_unit_types = 3,
- .unit_types = {
- H264_NAL_IDR_SLICE,
- H264_NAL_SLICE,
- H264_NAL_AUXILIARY_SLICE,
- },
- .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS,
- .content_size = sizeof(H264RawSlice),
- .nb_ref_offsets = 1,
- .ref_offsets = { offsetof(H264RawSlice, data) },
- },
+ CBS_UNIT_TYPES_INTERNAL_REF((H264_NAL_IDR_SLICE,
+ H264_NAL_SLICE,
+ H264_NAL_AUXILIARY_SLICE), H264RawSlice, data),
CBS_UNIT_TYPE_POD(H264_NAL_AUD, H264RawAUD),
CBS_UNIT_TYPE_POD(H264_NAL_FILLER_DATA, H264RawFiller),
@@ -1433,40 +1424,15 @@ static const CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[] = {
CBS_UNIT_TYPE_POD(HEVC_NAL_AUD, H265RawAUD),
- {
- // Slices of non-IRAP pictures.
- .nb_unit_types = CBS_UNIT_TYPE_RANGE,
- .unit_type_range_start = HEVC_NAL_TRAIL_N,
- .unit_type_range_end = HEVC_NAL_RASL_R,
-
- .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS,
- .content_size = sizeof(H265RawSlice),
- .nb_ref_offsets = 1,
- .ref_offsets = { offsetof(H265RawSlice, data) },
- },
+ // Slices of non-IRAP pictures.
+ CBS_UNIT_RANGE_INTERNAL_REF(HEVC_NAL_TRAIL_N, HEVC_NAL_RASL_R,
+ H265RawSlice, data),
+ // Slices of IRAP pictures.
+ CBS_UNIT_RANGE_INTERNAL_REF(HEVC_NAL_BLA_W_LP, HEVC_NAL_CRA_NUT,
+ H265RawSlice, data),
- {
- // Slices of IRAP pictures.
- .nb_unit_types = CBS_UNIT_TYPE_RANGE,
- .unit_type_range_start = HEVC_NAL_BLA_W_LP,
- .unit_type_range_end = HEVC_NAL_CRA_NUT,
-
- .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS,
- .content_size = sizeof(H265RawSlice),
- .nb_ref_offsets = 1,
- .ref_offsets = { offsetof(H265RawSlice, data) },
- },
-
- {
- .nb_unit_types = 2,
- .unit_types = {
- HEVC_NAL_SEI_PREFIX,
- HEVC_NAL_SEI_SUFFIX
- },
- .content_type = CBS_CONTENT_TYPE_COMPLEX,
- .content_size = sizeof(H265RawSEI),
- .content_free = &cbs_h265_free_sei,
- },
+ CBS_UNIT_TYPES_COMPLEX((HEVC_NAL_SEI_PREFIX, HEVC_NAL_SEI_SUFFIX),
+ H265RawSEI, cbs_h265_free_sei),
CBS_UNIT_TYPE_END_OF_LIST
};
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index f853086fa3..314d54daea 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -181,28 +181,45 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
// range_min in the above functions.
#define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
-
+#define TYPE_LIST(...) { __VA_ARGS__ }
#define CBS_UNIT_TYPE_POD(type, structure) { \
.nb_unit_types = 1, \
.unit_types = { type }, \
.content_type = CBS_CONTENT_TYPE_POD, \
.content_size = sizeof(structure), \
}
-#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field) { \
- .nb_unit_types = 1, \
- .unit_types = { type }, \
+
+#define CBS_UNIT_TYPES_INTERNAL_REF(types, structure, ref_field) { \
+ .nb_unit_types = FF_ARRAY_ELEMS((CodedBitstreamUnitType[])TYPE_LIST types), \
+ .unit_types = TYPE_LIST types, \
.content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \
.content_size = sizeof(structure), \
.nb_ref_offsets = 1, \
.ref_offsets = { offsetof(structure, ref_field) }, \
}
-#define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func) { \
- .nb_unit_types = 1, \
- .unit_types = { type }, \
+#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field) \
+ CBS_UNIT_TYPES_INTERNAL_REF((type), structure, ref_field)
+
+#define CBS_UNIT_RANGE_INTERNAL_REF(range_start, range_end, structure, ref_field) { \
+ .nb_unit_types = CBS_UNIT_TYPE_RANGE, \
+ .unit_type_range_start = range_start, \
+ .unit_type_range_end = range_end, \
+ .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \
+ .content_size = sizeof(structure), \
+ .nb_ref_offsets = 1, \
+ .ref_offsets = { offsetof(structure, ref_field) }, \
+ }
+
+#define CBS_UNIT_TYPES_COMPLEX(types, structure, free_func) { \
+ .nb_unit_types = FF_ARRAY_ELEMS((CodedBitstreamUnitType[])TYPE_LIST types), \
+ .unit_types = TYPE_LIST types, \
.content_type = CBS_CONTENT_TYPE_COMPLEX, \
.content_size = sizeof(structure), \
.content_free = free_func, \
}
+#define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func) \
+ CBS_UNIT_TYPES_COMPLEX((type), structure, free_func)
+
#define CBS_UNIT_TYPE_END_OF_LIST { .nb_unit_types = 0 }
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 6/9] avcodec/cbs_internal: Use unions to shrink size of descriptors
2022-08-04 17:31 [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API Andreas Rheinhardt
` (3 preceding siblings ...)
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 5/9] avcodec/cbs_internal, cbs_h2645: Add and use new descriptor macros Andreas Rheinhardt
@ 2022-08-04 17:36 ` Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 7/9] avcodec/cbs_jpeg: Use table-based alloc/free Andreas Rheinhardt
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andreas Rheinhardt @ 2022-08-04 17:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/cbs.c | 26 +++++++--------
libavcodec/cbs_internal.h | 69 ++++++++++++++++++++++-----------------
libavcodec/cbs_mpeg2.c | 10 +++---
3 files changed, 57 insertions(+), 48 deletions(-)
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index c81297ec93..57b57238ed 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -857,8 +857,8 @@ static void cbs_default_free_unit_content(void *opaque, uint8_t *data)
const CodedBitstreamUnitTypeDescriptor *desc = opaque;
if (desc->content_type == CBS_CONTENT_TYPE_INTERNAL_REFS) {
int i;
- for (i = 0; i < desc->nb_ref_offsets; i++) {
- void **ptr = (void**)(data + desc->ref_offsets[i]);
+ for (i = 0; i < desc->type.ref.nb_offsets; i++) {
+ void **ptr = (void**)(data + desc->type.ref.offsets[i]);
av_buffer_unref((AVBufferRef**)(ptr + 1));
}
}
@@ -880,12 +880,12 @@ static const CodedBitstreamUnitTypeDescriptor
if (desc->nb_unit_types == 0)
break;
if (desc->nb_unit_types == CBS_UNIT_TYPE_RANGE) {
- if (unit->type >= desc->unit_type_range_start &&
- unit->type <= desc->unit_type_range_end)
+ if (unit->type >= desc->unit_type.range.start &&
+ unit->type <= desc->unit_type.range.end)
return desc;
} else {
for (j = 0; j < desc->nb_unit_types; j++) {
- if (desc->unit_types[j] == unit->type)
+ if (desc->unit_type.list[j] == unit->type)
return desc;
}
}
@@ -910,7 +910,8 @@ int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx,
unit->content_ref =
av_buffer_create(unit->content, desc->content_size,
- desc->content_free ? desc->content_free
+ desc->content_type == CBS_CONTENT_TYPE_COMPLEX
+ ? desc->type.complex.content_free
: cbs_default_free_unit_content,
(void*)desc, 0);
if (!unit->content_ref) {
@@ -936,10 +937,10 @@ static int cbs_clone_internal_refs_unit_content(AVBufferRef **clone_ref,
if (!copy)
return AVERROR(ENOMEM);
- for (i = 0; i < desc->nb_ref_offsets; i++) {
- const uint8_t *const *src_ptr = (const uint8_t* const*)(src + desc->ref_offsets[i]);
+ for (i = 0; i < desc->type.ref.nb_offsets; i++) {
+ const uint8_t *const *src_ptr = (const uint8_t* const*)(src + desc->type.ref.offsets[i]);
const AVBufferRef *src_buf = *(AVBufferRef**)(src_ptr + 1);
- uint8_t **copy_ptr = (uint8_t**)(copy + desc->ref_offsets[i]);
+ uint8_t **copy_ptr = (uint8_t**)(copy + desc->type.ref.offsets[i]);
AVBufferRef **copy_buf = (AVBufferRef**)(copy_ptr + 1);
if (!*src_ptr) {
@@ -962,7 +963,6 @@ static int cbs_clone_internal_refs_unit_content(AVBufferRef **clone_ref,
}
*clone_ref = av_buffer_create(copy, desc->content_size,
- desc->content_free ? desc->content_free :
cbs_default_free_unit_content,
(void*)desc, 0);
if (!*clone_ref) {
@@ -974,7 +974,7 @@ static int cbs_clone_internal_refs_unit_content(AVBufferRef **clone_ref,
fail:
for (--i; i >= 0; i--)
- av_buffer_unref((AVBufferRef**)(copy + desc->ref_offsets[i]));
+ av_buffer_unref((AVBufferRef**)(copy + desc->type.ref.offsets[i]));
av_freep(©);
*clone_ref = NULL;
return err;
@@ -1010,9 +1010,9 @@ static int cbs_clone_unit_content(CodedBitstreamContext *ctx,
break;
case CBS_CONTENT_TYPE_COMPLEX:
- if (!desc->content_clone)
+ if (!desc->type.complex.content_clone)
return AVERROR_PATCHWELCOME;
- err = desc->content_clone(&ref, unit);
+ err = desc->type.complex.content_clone(&ref, unit);
break;
default:
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 314d54daea..4030b76f1c 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -60,13 +60,16 @@ typedef const struct CodedBitstreamUnitTypeDescriptor {
// used instead.
int nb_unit_types;
- // Array of unit types that this entry describes.
- const CodedBitstreamUnitType unit_types[CBS_MAX_UNIT_TYPES];
-
- // Start and end of unit type range, used if nb_unit_types is
- // CBS_UNIT_TYPE_RANGE.
- const CodedBitstreamUnitType unit_type_range_start;
- const CodedBitstreamUnitType unit_type_range_end;
+ union {
+ // Array of unit types that this entry describes.
+ CodedBitstreamUnitType list[CBS_MAX_UNIT_TYPES];
+ // Start and end of unit type range, used if nb_unit_types is
+ // CBS_UNIT_TYPE_RANGE.
+ struct {
+ CodedBitstreamUnitType start;
+ CodedBitstreamUnitType end;
+ } range;
+ } unit_type;
// The type of content described.
enum CBSContentType content_type;
@@ -74,18 +77,24 @@ typedef const struct CodedBitstreamUnitTypeDescriptor {
// the decomposed content of this type of unit.
size_t content_size;
- // Number of entries in the ref_offsets array. Only used if the
- // content_type is CBS_CONTENT_TYPE_INTERNAL_REFS.
- int nb_ref_offsets;
- // The structure must contain two adjacent elements:
- // type *field;
- // AVBufferRef *field_ref;
- // where field points to something in the buffer referred to by
- // field_ref. This offset is then set to offsetof(struct, field).
- size_t ref_offsets[CBS_MAX_REF_OFFSETS];
-
- void (*content_free)(void *opaque, uint8_t *data);
- int (*content_clone)(AVBufferRef **ref, CodedBitstreamUnit *unit);
+ union {
+ struct {
+ // Number of entries in the ref_offsets array. Only nonzero
+ // if the content_type is CBS_CONTENT_TYPE_INTERNAL_REFS.
+ int nb_offsets;
+ // The structure must contain two adjacent elements:
+ // type *field;
+ // AVBufferRef *field_ref;
+ // where field points to something in the buffer referred to by
+ // field_ref. This offset is then set to offsetof(struct, field).
+ size_t offsets[CBS_MAX_REF_OFFSETS];
+ } ref;
+
+ struct {
+ void (*content_free)(void *opaque, uint8_t *data);
+ int (*content_clone)(AVBufferRef **ref, CodedBitstreamUnit *unit);
+ } complex;
+ } type;
} CodedBitstreamUnitTypeDescriptor;
typedef struct CodedBitstreamType {
@@ -184,38 +193,38 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
#define TYPE_LIST(...) { __VA_ARGS__ }
#define CBS_UNIT_TYPE_POD(type, structure) { \
.nb_unit_types = 1, \
- .unit_types = { type }, \
+ .unit_type.list = { type }, \
.content_type = CBS_CONTENT_TYPE_POD, \
.content_size = sizeof(structure), \
}
#define CBS_UNIT_TYPES_INTERNAL_REF(types, structure, ref_field) { \
.nb_unit_types = FF_ARRAY_ELEMS((CodedBitstreamUnitType[])TYPE_LIST types), \
- .unit_types = TYPE_LIST types, \
+ .unit_type.list = TYPE_LIST types, \
.content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \
.content_size = sizeof(structure), \
- .nb_ref_offsets = 1, \
- .ref_offsets = { offsetof(structure, ref_field) }, \
+ .type.ref = { .nb_offsets = 1, \
+ .offsets = { offsetof(structure, ref_field) } }, \
}
#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field) \
CBS_UNIT_TYPES_INTERNAL_REF((type), structure, ref_field)
#define CBS_UNIT_RANGE_INTERNAL_REF(range_start, range_end, structure, ref_field) { \
- .nb_unit_types = CBS_UNIT_TYPE_RANGE, \
- .unit_type_range_start = range_start, \
- .unit_type_range_end = range_end, \
+ .nb_unit_types = CBS_UNIT_TYPE_RANGE, \
+ .unit_type.range.start = range_start, \
+ .unit_type.range.end = range_end, \
.content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \
.content_size = sizeof(structure), \
- .nb_ref_offsets = 1, \
- .ref_offsets = { offsetof(structure, ref_field) }, \
+ .type.ref = { .nb_offsets = 1, \
+ .offsets = { offsetof(structure, ref_field) } }, \
}
#define CBS_UNIT_TYPES_COMPLEX(types, structure, free_func) { \
.nb_unit_types = FF_ARRAY_ELEMS((CodedBitstreamUnitType[])TYPE_LIST types), \
- .unit_types = TYPE_LIST types, \
+ .unit_type.list = TYPE_LIST types, \
.content_type = CBS_CONTENT_TYPE_COMPLEX, \
.content_size = sizeof(structure), \
- .content_free = free_func, \
+ .type.complex = { .content_free = free_func }, \
}
#define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func) \
CBS_UNIT_TYPES_COMPLEX((type), structure, free_func)
diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 33bd3e0998..1c9519cdaf 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -392,14 +392,14 @@ static const CodedBitstreamUnitTypeDescriptor cbs_mpeg2_unit_types[] = {
{
.nb_unit_types = CBS_UNIT_TYPE_RANGE,
- .unit_type_range_start = 0x01,
- .unit_type_range_end = 0xaf,
+ .unit_type.range.start = 0x01,
+ .unit_type.range.end = 0xaf,
.content_type = CBS_CONTENT_TYPE_INTERNAL_REFS,
.content_size = sizeof(MPEG2RawSlice),
- .nb_ref_offsets = 2,
- .ref_offsets = { offsetof(MPEG2RawSlice, header.extra_information_slice.extra_information),
- offsetof(MPEG2RawSlice, data) },
+ .type.ref = { .nb_offsets = 2,
+ .offsets = { offsetof(MPEG2RawSlice, header.extra_information_slice.extra_information),
+ offsetof(MPEG2RawSlice, data) } },
},
CBS_UNIT_TYPE_INTERNAL_REF(MPEG2_START_USER_DATA, MPEG2RawUserData,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 7/9] avcodec/cbs_jpeg: Use table-based alloc/free
2022-08-04 17:31 [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API Andreas Rheinhardt
` (4 preceding siblings ...)
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 6/9] avcodec/cbs_internal: Use unions to shrink size of descriptors Andreas Rheinhardt
@ 2022-08-04 17:36 ` Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 8/9] avcodec/cbs: Remove ff_cbs_alloc_unit_content Andreas Rheinhardt
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andreas Rheinhardt @ 2022-08-04 17:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
cbs_jpeg was the last user of CBS that didn't use
CodedBitstreamUnitTypeDescriptors.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/cbs_internal.h | 7 ++++
libavcodec/cbs_jpeg.c | 76 ++++++++++++++-------------------------
2 files changed, 34 insertions(+), 49 deletions(-)
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 4030b76f1c..5ccba3c901 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -197,6 +197,13 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
.content_type = CBS_CONTENT_TYPE_POD, \
.content_size = sizeof(structure), \
}
+#define CBS_UNIT_RANGE_POD(range_start, range_end, structure) { \
+ .nb_unit_types = CBS_UNIT_TYPE_RANGE, \
+ .unit_type.range.start = range_start, \
+ .unit_type.range.end = range_end, \
+ .content_type = CBS_CONTENT_TYPE_POD, \
+ .content_size = sizeof(structure), \
+ }
#define CBS_UNIT_TYPES_INTERNAL_REF(types, structure, ref_field) { \
.nb_unit_types = FF_ARRAY_ELEMS((CodedBitstreamUnitType[])TYPE_LIST types), \
diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c
index da7ee808cf..2afeecfa79 100644
--- a/libavcodec/cbs_jpeg.c
+++ b/libavcodec/cbs_jpeg.c
@@ -82,27 +82,6 @@
#undef xu
-static void cbs_jpeg_free_application_data(void *opaque, uint8_t *content)
-{
- JPEGRawApplicationData *ad = (JPEGRawApplicationData*)content;
- av_buffer_unref(&ad->Ap_ref);
- av_freep(&content);
-}
-
-static void cbs_jpeg_free_comment(void *opaque, uint8_t *content)
-{
- JPEGRawComment *comment = (JPEGRawComment*)content;
- av_buffer_unref(&comment->Cm_ref);
- av_freep(&content);
-}
-
-static void cbs_jpeg_free_scan(void *opaque, uint8_t *content)
-{
- JPEGRawScan *scan = (JPEGRawScan*)content;
- av_buffer_unref(&scan->data_ref);
- av_freep(&content);
-}
-
static int cbs_jpeg_split_fragment(CodedBitstreamContext *ctx,
CodedBitstreamFragment *frag,
int header)
@@ -248,41 +227,26 @@ static int cbs_jpeg_read_unit(CodedBitstreamContext *ctx,
if (err < 0)
return err;
+ err = ff_cbs_alloc_unit_content2(ctx, unit);
+ if (err < 0)
+ return err;
+
if (unit->type >= JPEG_MARKER_SOF0 &&
unit->type <= JPEG_MARKER_SOF3) {
- err = ff_cbs_alloc_unit_content(unit,
- sizeof(JPEGRawFrameHeader),
- NULL);
- if (err < 0)
- return err;
-
err = cbs_jpeg_read_frame_header(ctx, &gbc, unit->content);
if (err < 0)
return err;
} else if (unit->type >= JPEG_MARKER_APPN &&
unit->type <= JPEG_MARKER_APPN + 15) {
- err = ff_cbs_alloc_unit_content(unit,
- sizeof(JPEGRawApplicationData),
- &cbs_jpeg_free_application_data);
- if (err < 0)
- return err;
-
err = cbs_jpeg_read_application_data(ctx, &gbc, unit->content);
if (err < 0)
return err;
} else if (unit->type == JPEG_MARKER_SOS) {
- JPEGRawScan *scan;
+ JPEGRawScan *scan = unit->content;
int pos;
- err = ff_cbs_alloc_unit_content(unit,
- sizeof(JPEGRawScan),
- &cbs_jpeg_free_scan);
- if (err < 0)
- return err;
- scan = unit->content;
-
err = cbs_jpeg_read_scan_header(ctx, &gbc, &scan->header);
if (err < 0)
return err;
@@ -299,21 +263,17 @@ static int cbs_jpeg_read_unit(CodedBitstreamContext *ctx,
} else {
switch (unit->type) {
-#define SEGMENT(marker, type, func, free) \
+#define SEGMENT(marker, func) \
case JPEG_MARKER_ ## marker: \
{ \
- err = ff_cbs_alloc_unit_content(unit, \
- sizeof(type), free); \
- if (err < 0) \
- return err; \
err = cbs_jpeg_read_ ## func(ctx, &gbc, unit->content); \
if (err < 0) \
return err; \
} \
break
- SEGMENT(DQT, JPEGRawQuantisationTableSpecification, dqt, NULL);
- SEGMENT(DHT, JPEGRawHuffmanTableSpecification, dht, NULL);
- SEGMENT(COM, JPEGRawComment, comment, &cbs_jpeg_free_comment);
+ SEGMENT(DQT, dqt);
+ SEGMENT(DHT, dht);
+ SEGMENT(COM, comment);
#undef SEGMENT
default:
return AVERROR(ENOSYS);
@@ -456,9 +416,27 @@ static int cbs_jpeg_assemble_fragment(CodedBitstreamContext *ctx,
return 0;
}
+static const CodedBitstreamUnitTypeDescriptor cbs_jpeg_unit_types[] = {
+ CBS_UNIT_RANGE_POD(JPEG_MARKER_SOF0, JPEG_MARKER_SOF3, JPEGRawFrameHeader),
+
+ CBS_UNIT_RANGE_INTERNAL_REF(JPEG_MARKER_APPN, JPEG_MARKER_APPN + 15,
+ JPEGRawApplicationData, Ap),
+
+ CBS_UNIT_TYPE_INTERNAL_REF(JPEG_MARKER_SOS, JPEGRawScan, data),
+
+ CBS_UNIT_TYPE_POD(JPEG_MARKER_DQT, JPEGRawQuantisationTableSpecification),
+ CBS_UNIT_TYPE_POD(JPEG_MARKER_DHT, JPEGRawHuffmanTableSpecification),
+
+ CBS_UNIT_TYPE_INTERNAL_REF(JPEG_MARKER_COM, JPEGRawComment, Cm),
+
+ CBS_UNIT_TYPE_END_OF_LIST
+};
+
const CodedBitstreamType ff_cbs_type_jpeg = {
.codec_id = AV_CODEC_ID_MJPEG,
+ .unit_types = cbs_jpeg_unit_types,
+
.split_fragment = &cbs_jpeg_split_fragment,
.read_unit = &cbs_jpeg_read_unit,
.write_unit = &cbs_jpeg_write_unit,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 8/9] avcodec/cbs: Remove ff_cbs_alloc_unit_content
2022-08-04 17:31 [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API Andreas Rheinhardt
` (5 preceding siblings ...)
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 7/9] avcodec/cbs_jpeg: Use table-based alloc/free Andreas Rheinhardt
@ 2022-08-04 17:36 ` Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 9/9] avcodec/cbs_h2645: Remove always-false check Andreas Rheinhardt
2022-08-06 8:25 ` [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API Andreas Rheinhardt
8 siblings, 0 replies; 10+ messages in thread
From: Andreas Rheinhardt @ 2022-08-04 17:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It is no longer used.
Also rename ff_cbs_alloc_unit_content2 to ff_cbs_alloc_unit_content.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/cbs.c | 24 ++----------------------
libavcodec/cbs.h | 13 ++-----------
libavcodec/cbs_av1.c | 2 +-
libavcodec/cbs_h2645.c | 4 ++--
libavcodec/cbs_jpeg.c | 2 +-
libavcodec/cbs_mpeg2.c | 2 +-
libavcodec/cbs_sei.c | 2 +-
libavcodec/cbs_vp9.c | 2 +-
8 files changed, 11 insertions(+), 40 deletions(-)
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 57b57238ed..07ae658a4c 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -695,26 +695,6 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
}
-int ff_cbs_alloc_unit_content(CodedBitstreamUnit *unit,
- size_t size,
- void (*free)(void *opaque, uint8_t *data))
-{
- av_assert0(!unit->content && !unit->content_ref);
-
- unit->content = av_mallocz(size);
- if (!unit->content)
- return AVERROR(ENOMEM);
-
- unit->content_ref = av_buffer_create(unit->content, size,
- free, NULL, 0);
- if (!unit->content_ref) {
- av_freep(&unit->content);
- return AVERROR(ENOMEM);
- }
-
- return 0;
-}
-
static int cbs_insert_unit(CodedBitstreamFragment *frag,
int position)
{
@@ -893,8 +873,8 @@ static const CodedBitstreamUnitTypeDescriptor
return NULL;
}
-int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx,
- CodedBitstreamUnit *unit)
+int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx,
+ CodedBitstreamUnit *unit)
{
const CodedBitstreamUnitTypeDescriptor *desc;
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 5583063b5e..ee21623dac 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -363,22 +363,13 @@ void ff_cbs_fragment_reset(CodedBitstreamFragment *frag);
*/
void ff_cbs_fragment_free(CodedBitstreamFragment *frag);
-/**
- * Allocate a new internal content buffer of the given size in the unit.
- *
- * The content will be zeroed.
- */
-int ff_cbs_alloc_unit_content(CodedBitstreamUnit *unit,
- size_t size,
- void (*free)(void *opaque, uint8_t *content));
-
/**
* Allocate a new internal content buffer matching the type of the unit.
*
* The content will be zeroed.
*/
-int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx,
- CodedBitstreamUnit *unit);
+int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx,
+ CodedBitstreamUnit *unit);
/**
* Insert a new unit into a fragment with the given content.
diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 1229480567..154d9156cf 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -878,7 +878,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
GetBitContext gbc;
int err, start_pos, end_pos;
- err = ff_cbs_alloc_unit_content2(ctx, unit);
+ err = ff_cbs_alloc_unit_content(ctx, unit);
if (err < 0)
return err;
obu = unit->content;
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 117b609dc3..e0c617e81d 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -702,7 +702,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx,
if (err < 0)
return err;
- err = ff_cbs_alloc_unit_content2(ctx, unit);
+ err = ff_cbs_alloc_unit_content(ctx, unit);
if (err < 0)
return err;
@@ -821,7 +821,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx,
if (err < 0)
return err;
- err = ff_cbs_alloc_unit_content2(ctx, unit);
+ err = ff_cbs_alloc_unit_content(ctx, unit);
if (err < 0)
return err;
diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c
index 2afeecfa79..5921d624a1 100644
--- a/libavcodec/cbs_jpeg.c
+++ b/libavcodec/cbs_jpeg.c
@@ -227,7 +227,7 @@ static int cbs_jpeg_read_unit(CodedBitstreamContext *ctx,
if (err < 0)
return err;
- err = ff_cbs_alloc_unit_content2(ctx, unit);
+ err = ff_cbs_alloc_unit_content(ctx, unit);
if (err < 0)
return err;
diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 1c9519cdaf..04b0c7f87d 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -204,7 +204,7 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx,
if (err < 0)
return err;
- err = ff_cbs_alloc_unit_content2(ctx, unit);
+ err = ff_cbs_alloc_unit_content(ctx, unit);
if (err < 0)
return err;
diff --git a/libavcodec/cbs_sei.c b/libavcodec/cbs_sei.c
index 141e97ec58..50a513f592 100644
--- a/libavcodec/cbs_sei.c
+++ b/libavcodec/cbs_sei.c
@@ -179,7 +179,7 @@ static int cbs_sei_get_unit(CodedBitstreamContext *ctx,
unit = &au->units[position];
unit->type = sei_type;
- err = ff_cbs_alloc_unit_content2(ctx, unit);
+ err = ff_cbs_alloc_unit_content(ctx, unit);
if (err < 0)
return err;
diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c
index ae7f88a8a3..184fdcade6 100644
--- a/libavcodec/cbs_vp9.c
+++ b/libavcodec/cbs_vp9.c
@@ -489,7 +489,7 @@ static int cbs_vp9_read_unit(CodedBitstreamContext *ctx,
if (err < 0)
return err;
- err = ff_cbs_alloc_unit_content2(ctx, unit);
+ err = ff_cbs_alloc_unit_content(ctx, unit);
if (err < 0)
return err;
frame = unit->content;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 9/9] avcodec/cbs_h2645: Remove always-false check
2022-08-04 17:31 [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API Andreas Rheinhardt
` (6 preceding siblings ...)
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 8/9] avcodec/cbs: Remove ff_cbs_alloc_unit_content Andreas Rheinhardt
@ 2022-08-04 17:36 ` Andreas Rheinhardt
2022-08-06 8:25 ` [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API Andreas Rheinhardt
8 siblings, 0 replies; 10+ messages in thread
From: Andreas Rheinhardt @ 2022-08-04 17:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The functions to replace parameter sets are only called
after the respective parameter set has just been read or
has just been written; all of these functions check
that the id field is within the appropriate range.
So the checks in the replace-functions can be removed.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/cbs_h2645.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index e0c617e81d..4ee06003c3 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -666,13 +666,7 @@ static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \
CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \
H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \
unsigned int id = ps_var->id_element; \
- int err; \
- if (id >= FF_ARRAY_ELEMS(priv->ps_var)) { \
- av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid " #ps_name \
- " id : %d.\n", id); \
- return AVERROR_INVALIDDATA; \
- } \
- err = ff_cbs_make_unit_refcounted(ctx, unit); \
+ int err = ff_cbs_make_unit_refcounted(ctx, unit); \
if (err < 0) \
return err; \
if (priv->ps_var[id] == priv->active_ ## ps_var) \
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API
2022-08-04 17:31 [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API Andreas Rheinhardt
` (7 preceding siblings ...)
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 9/9] avcodec/cbs_h2645: Remove always-false check Andreas Rheinhardt
@ 2022-08-06 8:25 ` Andreas Rheinhardt
8 siblings, 0 replies; 10+ messages in thread
From: Andreas Rheinhardt @ 2022-08-06 8:25 UTC (permalink / raw)
To: ffmpeg-devel
Andreas Rheinhardt:
> These buffers are not shared in any way.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> libavcodec/error_resilience.c | 18 +++++++++---------
> libavcodec/error_resilience.h | 4 ++--
> 2 files changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
> index f957c68d2c..2aa6f1d864 100644
> --- a/libavcodec/error_resilience.c
> +++ b/libavcodec/error_resilience.c
> @@ -946,17 +946,17 @@ void ff_er_frame_end(ERContext *s)
> av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\n");
>
> for (i = 0; i < 2; i++) {
> - s->ref_index_buf[i] = av_buffer_allocz(s->mb_stride * s->mb_height * 4 * sizeof(uint8_t));
> - s->motion_val_buf[i] = av_buffer_allocz((size + 4) * 2 * sizeof(uint16_t));
> - if (!s->ref_index_buf[i] || !s->motion_val_buf[i])
> + s->ref_index[i] = av_calloc(s->mb_stride * s->mb_height, 4 * sizeof(uint8_t));
> + s->motion_val_base[i] = av_calloc(size + 4, 2 * sizeof(uint16_t));
> + if (!s->ref_index[i] || !s->motion_val_base[i])
> break;
> - s->cur_pic.ref_index[i] = s->ref_index_buf[i]->data;
> - s->cur_pic.motion_val[i] = (int16_t (*)[2])s->motion_val_buf[i]->data + 4;
> + s->cur_pic.ref_index[i] = s->ref_index[i];
> + s->cur_pic.motion_val[i] = s->motion_val_base[i] + 4;
> }
> if (i < 2) {
> for (i = 0; i < 2; i++) {
> - av_buffer_unref(&s->ref_index_buf[i]);
> - av_buffer_unref(&s->motion_val_buf[i]);
> + av_freep(&s->ref_index[i]);
> + av_freep(&s->motion_val_base[i]);
> s->cur_pic.ref_index[i] = NULL;
> s->cur_pic.motion_val[i] = NULL;
> }
> @@ -1343,8 +1343,8 @@ void ff_er_frame_end(ERContext *s)
> }
>
> for (i = 0; i < 2; i++) {
> - av_buffer_unref(&s->ref_index_buf[i]);
> - av_buffer_unref(&s->motion_val_buf[i]);
> + av_freep(&s->ref_index[i]);
> + av_freep(&s->motion_val_base[i]);
> s->cur_pic.ref_index[i] = NULL;
> s->cur_pic.motion_val[i] = NULL;
> }
> diff --git a/libavcodec/error_resilience.h b/libavcodec/error_resilience.h
> index 53e5cf2621..47cc8a4fc6 100644
> --- a/libavcodec/error_resilience.h
> +++ b/libavcodec/error_resilience.h
> @@ -75,8 +75,8 @@ typedef struct ERContext {
> ERPicture last_pic;
> ERPicture next_pic;
>
> - AVBufferRef *ref_index_buf[2];
> - AVBufferRef *motion_val_buf[2];
> + int8_t *ref_index[2];
> + int16_t (*motion_val_base[2])[2];
>
> uint16_t pp_time;
> uint16_t pb_time;
Will apply this patchset tomorrow unless there are objections.
- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-08-06 9:53 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-04 17:31 [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 2/9] avcodec/cbs: Avoid code duplication for making unit refcounted/writable Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 3/9] avcodec/cbs: Remove redundant assignment Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 4/9] avcodec/cbs: Use smaller scope for variables, add const Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 5/9] avcodec/cbs_internal, cbs_h2645: Add and use new descriptor macros Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 6/9] avcodec/cbs_internal: Use unions to shrink size of descriptors Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 7/9] avcodec/cbs_jpeg: Use table-based alloc/free Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 8/9] avcodec/cbs: Remove ff_cbs_alloc_unit_content Andreas Rheinhardt
2022-08-04 17:36 ` [FFmpeg-devel] [PATCH 9/9] avcodec/cbs_h2645: Remove always-false check Andreas Rheinhardt
2022-08-06 8:25 ` [FFmpeg-devel] [PATCH 1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API Andreas Rheinhardt
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git