diff options
author | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2016-04-17 18:47:25 +0100 |
---|---|---|
committer | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2016-04-17 18:47:40 +0100 |
commit | af9cac1be1750ecc0e12c6788a3aeed1f1a778be (patch) | |
tree | 2e34226dbd4010774f6ffef448aab4b7d4f88544 /libavcodec/mjpeg2jpeg_bsf.c | |
parent | 6d160afab2fa8d3bfb216fee96d3537ffc9e86e8 (diff) | |
parent | 33d18982fa03feb061c8f744a4f0a9175c1f63ab (diff) | |
download | ffmpeg-af9cac1be1750ecc0e12c6788a3aeed1f1a778be.tar.gz |
Merge commit '33d18982fa03feb061c8f744a4f0a9175c1f63ab'
* commit '33d18982fa03feb061c8f744a4f0a9175c1f63ab':
lavc: add a new bitstream filtering API
Conversions-by: Hendrik Leppkes <h.leppkes@gmail.com>
Conversions-by: Derek Buitenguis <derek.buitenhuis@gmail.com>
Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavcodec/mjpeg2jpeg_bsf.c')
-rw-r--r-- | libavcodec/mjpeg2jpeg_bsf.c | 75 |
1 files changed, 47 insertions, 28 deletions
diff --git a/libavcodec/mjpeg2jpeg_bsf.c b/libavcodec/mjpeg2jpeg_bsf.c index 92dc3ca230..2d4cee2ac1 100644 --- a/libavcodec/mjpeg2jpeg_bsf.c +++ b/libavcodec/mjpeg2jpeg_bsf.c @@ -31,6 +31,7 @@ #include "libavutil/intreadwrite.h" #include "avcodec.h" +#include "bsf.h" #include "jpegtables.h" #include "mjpeg.h" @@ -77,46 +78,64 @@ static uint8_t *append_dht_segment(uint8_t *buf) return buf; } -static int mjpeg2jpeg_filter(AVBitStreamFilterContext *bsfc, - AVCodecContext *avctx, const char *args, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size, - int keyframe) +static int mjpeg2jpeg_filter(AVBSFContext *ctx, AVPacket *out) { + AVPacket *in; + int ret = 0; int input_skip, output_size; - uint8_t *output, *out; + uint8_t *output; - if (buf_size < 12) { - av_log(avctx, AV_LOG_ERROR, "input is truncated\n"); - return AVERROR_INVALIDDATA; + ret = ff_bsf_get_packet(ctx, &in); + + if (in->size < 12) { + av_log(ctx, AV_LOG_ERROR, "input is truncated\n"); + ret = AVERROR_INVALIDDATA; + goto fail; } - if (AV_RB16(buf) != 0xffd8) { - av_log(avctx, AV_LOG_ERROR, "input is not MJPEG\n"); - return AVERROR_INVALIDDATA; + if (AV_RB16(in->data) != 0xffd8) { + av_log(ctx, AV_LOG_ERROR, "input is not MJPEG\n"); + ret = AVERROR_INVALIDDATA; + goto fail; } - if (buf[2] == 0xff && buf[3] == APP0) { - input_skip = (buf[4] << 8) + buf[5] + 4; + if (in->data[2] == 0xff && in->data[3] == APP0) { + input_skip = (in->data[4] << 8) + in->data[5] + 4; } else { input_skip = 2; } - if (buf_size < input_skip) { - av_log(avctx, AV_LOG_ERROR, "input is truncated\n"); - return AVERROR_INVALIDDATA; + if (in->size < input_skip) { + av_log(ctx, AV_LOG_ERROR, "input is truncated\n"); + ret = AVERROR_INVALIDDATA; + goto fail; } - output_size = buf_size - input_skip + + output_size = in->size - input_skip + sizeof(jpeg_header) + dht_segment_size; - output = out = av_malloc(output_size); - if (!output) - return AVERROR(ENOMEM); - out = append(out, jpeg_header, sizeof(jpeg_header)); - out = append_dht_segment(out); - out = append(out, buf + input_skip, buf_size - input_skip); - *poutbuf = output; - *poutbuf_size = output_size; - return 1; + ret = av_new_packet(out, output_size); + if (ret < 0) + goto fail; + + output = out->data; + + output = append(output, jpeg_header, sizeof(jpeg_header)); + output = append_dht_segment(output); + output = append(output, in->data + input_skip, in->size - input_skip); + + ret = av_packet_copy_props(out, in); + if (ret < 0) + goto fail; + +fail: + if (ret < 0) + av_packet_unref(out); + av_packet_free(&in); + return ret; } -AVBitStreamFilter ff_mjpeg2jpeg_bsf = { +static const enum AVCodecID codec_ids[] = { + AV_CODEC_ID_MJPEG, AV_CODEC_ID_NONE, +}; + +const AVBitStreamFilter ff_mjpeg2jpeg_bsf = { .name = "mjpeg2jpeg", .filter = mjpeg2jpeg_filter, + .codec_ids = codec_ids, }; |