diff --git a/libavcodec/crystalhd.c b/libavcodec/crystalhd.c index 4fd2cdf0c0..632d774dfa 100644 --- a/libavcodec/crystalhd.c +++ b/libavcodec/crystalhd.c @@ -794,7 +794,9 @@ static int decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *a CopyRet rec_ret; CHDContext *priv = avctx->priv_data; HANDLE dev = priv->dev; + uint8_t *in_data = avpkt->data; int len = avpkt->size; + int free_data = 0; uint8_t pic_type = 0; av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: decode_frame\n"); @@ -819,15 +821,14 @@ static int decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *a int32_t tx_free = (int32_t)DtsTxFreeSize(dev); if (priv->parser) { - uint8_t *in_data = avpkt->data; - int in_len = len; int ret = 0; if (priv->bsfc) { ret = av_bitstream_filter_filter(priv->bsfc, avctx, NULL, - &in_data, &in_len, + &in_data, &len, avpkt->data, len, 0); } + free_data = ret > 0; if (ret >= 0) { uint8_t *pout; @@ -836,13 +837,13 @@ static int decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *a H264Context *h = priv->parser->priv_data; index = av_parser_parse2(priv->parser, avctx, &pout, &psize, - in_data, in_len, avctx->pkt->pts, + in_data, len, avctx->pkt->pts, avctx->pkt->dts, 0); if (index < 0) { av_log(avctx, AV_LOG_WARNING, "CrystalHD: Failed to parse h.264 packet to " "detect interlacing.\n"); - } else if (index != in_len) { + } else if (index != len) { av_log(avctx, AV_LOG_WARNING, "CrystalHD: Failed to parse h.264 packet " "completely. Interlaced frames may be " @@ -859,9 +860,6 @@ static int decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *a "packet. Interlaced frames may be incorrectly " "detected.\n"); } - if (ret > 0) { - av_freep(&in_data); - } } if (len < tx_free - 1024) { @@ -876,11 +874,17 @@ static int decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *a */ uint64_t pts = opaque_list_push(priv, avctx->pkt->pts, pic_type); if (!pts) { + if (free_data) { + av_freep(&in_data); + } return AVERROR(ENOMEM); } av_log(priv->avctx, AV_LOG_VERBOSE, "input \"pts\": %"PRIu64"\n", pts); - ret = DtsProcInput(dev, avpkt->data, len, pts, 0); + ret = DtsProcInput(dev, in_data, len, pts, 0); + if (free_data) { + av_freep(&in_data); + } if (ret == BC_STS_BUSY) { av_log(avctx, AV_LOG_WARNING, "CrystalHD: ProcInput returned busy\n");