On 15/06/18 01:52, Xiang, Haihao wrote: > On Fri, 2018-06-08 at 00:43 +0100, Mark Thompson wrote: >> --- >> configure | 2 + >> libavcodec/Makefile | 1 + >> libavcodec/cbs.c | 6 + >> libavcodec/cbs_internal.h | 1 + >> libavcodec/cbs_jpeg.c | 513 >> ++++++++++++++++++++++++++++++++++ >> libavcodec/cbs_jpeg.h | 128 +++++++++ >> libavcodec/cbs_jpeg_syntax_template.c | 191 +++++++++++++ >> 7 files changed, 842 insertions(+) >> create mode 100644 libavcodec/cbs_jpeg.c >> create mode 100644 libavcodec/cbs_jpeg.h >> create mode 100644 libavcodec/cbs_jpeg_syntax_template.c >> >> ... >> diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c >> new file mode 100644 >> index 0000000000..365db73394 >> --- /dev/null >> +++ b/libavcodec/cbs_jpeg.c >> ... >> +static int cbs_jpeg_read_unit(CodedBitstreamContext *ctx, >> + CodedBitstreamUnit *unit) >> +{ >> + GetBitContext gbc; >> + int err; >> + >> + err = init_get_bits(&gbc, unit->data, 8 * unit->data_size); >> + if (err < 0) >> + return err; >> + >> + if (unit->type >= JPEG_MARKER_SOF0 && >> + unit->type <= JPEG_MARKER_SOF3) { >> + err = ff_cbs_alloc_unit_content(ctx, 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(ctx, 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; >> + int pos; >> + >> + err = ff_cbs_alloc_unit_content(ctx, 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; >> + >> + pos = get_bits_count(&gbc); >> + av_assert0(pos % 8 == 0); >> + if (pos > 0) { >> + scan->data_size = unit->data_size - pos / 8; >> + scan->data_ref = av_buffer_ref(unit->data_ref); >> + if (!scan->data_ref) >> + return AVERROR(ENOMEM); >> + scan->data = unit->data + pos / 8; >> + } >> + >> + } else { >> + switch (unit->type) { >> +#define SEGMENT(marker, type, func) \ >> + case JPEG_MARKER_ ## marker: \ >> + { \ >> + err = ff_cbs_alloc_unit_content(ctx, unit, \ >> + sizeof(type), NULL); \ >> + if (err < 0) \ >> + return err; \ >> + err = cbs_jpeg_read_ ## func(ctx, &gbc, unit->content); \ >> + if (err < 0) \ >> + return err; \ >> + } \ >> + break >> + SEGMENT(DQT, JPEGRawQuantisationTableSpecification, dqt); >> + SEGMENT(DHT, JPEGRawHuffmanTableSpecification, dht); >> + SEGMENT(COM, JPEGRawComment, comment); > > A free function should be provided for JPEGRawComment as JPEGRawComment > includes > a AVBufferRef pointer.
Yep, fixed. >> +#undef SEGMENT >> + default: >> + return AVERROR(ENOSYS); >> + } >> + } >> + >> + return 0; >> +} >> ... Thanks, - Mark _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel