mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-02-09 14:14:39 +02:00
avcodec/cbs_jpeg: Use table-based alloc/free
cbs_jpeg was the last user of CBS that didn't use CodedBitstreamUnitTypeDescriptors. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
9638f5b1a2
commit
2d722b6638
@ -197,6 +197,13 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
.content_type = CBS_CONTENT_TYPE_POD, \
|
.content_type = CBS_CONTENT_TYPE_POD, \
|
||||||
.content_size = sizeof(structure), \
|
.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) { \
|
#define CBS_UNIT_TYPES_INTERNAL_REF(types, structure, ref_field) { \
|
||||||
.nb_unit_types = FF_ARRAY_ELEMS((CodedBitstreamUnitType[])TYPE_LIST types), \
|
.nb_unit_types = FF_ARRAY_ELEMS((CodedBitstreamUnitType[])TYPE_LIST types), \
|
||||||
|
@ -82,27 +82,6 @@
|
|||||||
#undef xu
|
#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,
|
static int cbs_jpeg_split_fragment(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag,
|
CodedBitstreamFragment *frag,
|
||||||
int header)
|
int header)
|
||||||
@ -248,41 +227,26 @@ static int cbs_jpeg_read_unit(CodedBitstreamContext *ctx,
|
|||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (unit->type >= JPEG_MARKER_SOF0 &&
|
err = ff_cbs_alloc_unit_content2(ctx, unit);
|
||||||
unit->type <= JPEG_MARKER_SOF3) {
|
|
||||||
err = ff_cbs_alloc_unit_content(unit,
|
|
||||||
sizeof(JPEGRawFrameHeader),
|
|
||||||
NULL);
|
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
if (unit->type >= JPEG_MARKER_SOF0 &&
|
||||||
|
unit->type <= JPEG_MARKER_SOF3) {
|
||||||
err = cbs_jpeg_read_frame_header(ctx, &gbc, unit->content);
|
err = cbs_jpeg_read_frame_header(ctx, &gbc, unit->content);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
} else if (unit->type >= JPEG_MARKER_APPN &&
|
} else if (unit->type >= JPEG_MARKER_APPN &&
|
||||||
unit->type <= JPEG_MARKER_APPN + 15) {
|
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);
|
err = cbs_jpeg_read_application_data(ctx, &gbc, unit->content);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
} else if (unit->type == JPEG_MARKER_SOS) {
|
} else if (unit->type == JPEG_MARKER_SOS) {
|
||||||
JPEGRawScan *scan;
|
JPEGRawScan *scan = unit->content;
|
||||||
int pos;
|
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);
|
err = cbs_jpeg_read_scan_header(ctx, &gbc, &scan->header);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
@ -299,21 +263,17 @@ static int cbs_jpeg_read_unit(CodedBitstreamContext *ctx,
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
switch (unit->type) {
|
switch (unit->type) {
|
||||||
#define SEGMENT(marker, type, func, free) \
|
#define SEGMENT(marker, func) \
|
||||||
case JPEG_MARKER_ ## marker: \
|
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); \
|
err = cbs_jpeg_read_ ## func(ctx, &gbc, unit->content); \
|
||||||
if (err < 0) \
|
if (err < 0) \
|
||||||
return err; \
|
return err; \
|
||||||
} \
|
} \
|
||||||
break
|
break
|
||||||
SEGMENT(DQT, JPEGRawQuantisationTableSpecification, dqt, NULL);
|
SEGMENT(DQT, dqt);
|
||||||
SEGMENT(DHT, JPEGRawHuffmanTableSpecification, dht, NULL);
|
SEGMENT(DHT, dht);
|
||||||
SEGMENT(COM, JPEGRawComment, comment, &cbs_jpeg_free_comment);
|
SEGMENT(COM, comment);
|
||||||
#undef SEGMENT
|
#undef SEGMENT
|
||||||
default:
|
default:
|
||||||
return AVERROR(ENOSYS);
|
return AVERROR(ENOSYS);
|
||||||
@ -456,9 +416,27 @@ static int cbs_jpeg_assemble_fragment(CodedBitstreamContext *ctx,
|
|||||||
return 0;
|
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 = {
|
const CodedBitstreamType ff_cbs_type_jpeg = {
|
||||||
.codec_id = AV_CODEC_ID_MJPEG,
|
.codec_id = AV_CODEC_ID_MJPEG,
|
||||||
|
|
||||||
|
.unit_types = cbs_jpeg_unit_types,
|
||||||
|
|
||||||
.split_fragment = &cbs_jpeg_split_fragment,
|
.split_fragment = &cbs_jpeg_split_fragment,
|
||||||
.read_unit = &cbs_jpeg_read_unit,
|
.read_unit = &cbs_jpeg_read_unit,
|
||||||
.write_unit = &cbs_jpeg_write_unit,
|
.write_unit = &cbs_jpeg_write_unit,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user