From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 7/9] avcodec/cbs_jpeg: Use table-based alloc/free
Date: Thu, 4 Aug 2022 19:36:53 +0200
Message-ID: <DB6PR0101MB22141DB54A980711B3A03F9E8F9F9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com> (raw)
In-Reply-To: <DB6PR0101MB221469434BA24DD3BADA3B648F9F9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com>
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".
next prev parent reply other threads:[~2022-08-04 17:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Andreas Rheinhardt [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DB6PR0101MB22141DB54A980711B3A03F9E8F9F9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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