From patchwork Sun Sep 18 19:43:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Langdale X-Patchwork-Id: 616 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp684300vsd; Sun, 18 Sep 2016 12:53:57 -0700 (PDT) X-Received: by 10.28.95.134 with SMTP id t128mr5832066wmb.99.1474228437311; Sun, 18 Sep 2016 12:53:57 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id lz10si5224430wjb.294.2016.09.18.12.53.56; Sun, 18 Sep 2016 12:53:57 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@overt.org; dkim=neutral (body hash did not verify) header.i=@overt.org; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E5FE3689DBA; Sun, 18 Sep 2016 22:53:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from rs224.mailgun.us (rs224.mailgun.us [209.61.151.224]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5995F689CBB for ; Sun, 18 Sep 2016 22:53:33 +0300 (EEST) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=overt.org; q=dns/txt; s=k1; t=1474228426; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=3asLHdqbnImdzWcZCSToD2g+4zSw7NlJBVOtl9rX/2Q=; b=Z3rgMNAOrTHXQKWHSXVIDOlPmCpbnyM4MtX/TBuaevDTt64Dl+c1GAdwLMYaVN0wPL5HJ7Sp m+iI9LOi6FGlu7BAnhtljWnKc4PGklW6OHgaShOV5pQtW03dWoHdcrYIYIkiAhi4uFE/f6EE 0cu7VcB/YE/mp1giiCQ1T5HrtBg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=overt.org; s=k1; q=dns; h=Sender: From: To: Cc: Subject: Date: Message-Id; b=OzRWA7lZqriYSRrnlpAcNDMuMmdcmi48/ehJ5B1V1HP1oln3lQI+ZrJREPub1+Z9lhDpAq umNzJXOiSJcmraJQnBxIKayO2XhuzsPSJi5g04J21kzF9OztnN08vamlo2fkAAOzSe7QN5+/ 8xgGDzSI3q636eEXQ1k5oLwC4zAFc= X-Mailgun-Sending-Ip: 209.61.151.224 X-Mailgun-Sid: WyIyM2Q3MCIsICJmZm1wZWctZGV2ZWxAZmZtcGVnLm9yZyIsICI0YTg5NjEiXQ== Received: from mail.overt.org (155.208.178.107.bc.googleusercontent.com [107.178.208.155]) by mxa.mailgun.org with ESMTP id 57deee62.7f2f10410928-in2; Sun, 18 Sep 2016 19:43:30 -0000 (UTC) Received: from authenticated-user (mail.overt.org [107.178.208.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.overt.org (Postfix) with ESMTPSA id A01E3600AF; Sun, 18 Sep 2016 19:43:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=overt.org; s=mail; t=1474227809; bh=0VuU8blgCVQfyoYEiHaBMM9MirAS1dzPx8qN2wewTmo=; h=From:To:Cc:Subject:Date:From; b=dSLzyTKi1yNO8TFh+exE/CqM4NumHmO8I5/5Qd3F0JJa5ACSdJN2DUWIyBW+BFGFT hmFF9VjlbfpRzbTrSKunULdW+x4KGI46jB2VoZX27buuu9Yl8iK/E7nC+ZWnxFoggl c28JKAGiTbsmjGbWVco7E7OmbKMp8pyEvh5P1/LH5HVW9VGL5FkRgC0G1OODyk2XGO OpiAiiudQLDVSQfDz5vQr5OTOjn6EJj1vRg8NZz7k1hK+CLED+yM9nh4kVIO2VOQSh q8mhk2kAZmSXEADRMURGoeVZAYOJIbx3d5qwnCmZSfZXv4yhnm/oFDmqX4qOTyen33 kz4w6cA1FmZnQ== From: Philip Langdale To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Sep 2016 12:43:25 -0700 Message-Id: <1474227805-19235-1-git-send-email-philipl@overt.org> Subject: [FFmpeg-devel] [PATCH] crystalhd: Use up-to-date bsf API X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Philip Langdale MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Although the old API is supposed to functional, the crystalhd decoder is currently not working for non-annex.b h.264 content. So, let's update to the modern API and make it work again. Signed-off-by: Philip Langdale --- libavcodec/crystalhd.c | 87 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 65 insertions(+), 22 deletions(-) diff --git a/libavcodec/crystalhd.c b/libavcodec/crystalhd.c index d6ebcee..59b14b9 100644 --- a/libavcodec/crystalhd.c +++ b/libavcodec/crystalhd.c @@ -131,7 +131,7 @@ typedef struct { uint8_t *orig_extradata; uint32_t orig_extradata_size; - AVBitStreamFilterContext *bsfc; + AVBSFContext *bsfc; AVCodecParserContext *parser; uint8_t is_70012; @@ -359,7 +359,7 @@ static av_cold int uninit(AVCodecContext *avctx) av_parser_close(priv->parser); if (priv->bsfc) { - av_bitstream_filter_close(priv->bsfc); + av_bsf_free(&priv->bsfc); } av_freep(&priv->sps_pps_buf); @@ -418,30 +418,46 @@ static av_cold int init(AVCodecContext *avctx) switch (subtype) { case BC_MSUBTYPE_AVC1: { - uint8_t *dummy_p; - int dummy_int; + const AVBitStreamFilter *bsf; + int avret; - /* Back up the extradata so it can be restored at close time. */ - priv->orig_extradata = av_malloc(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!priv->orig_extradata) { + bsf = av_bsf_get_by_name("h264_mp4toannexb"); + if (!bsf) { av_log(avctx, AV_LOG_ERROR, - "Failed to allocate copy of extradata\n"); + "Cannot open the h264_mp4toannexb BSF!\n"); + return AVERROR_BSF_NOT_FOUND; + } + avret = av_bsf_alloc(bsf, &priv->bsfc); + if (avret != 0) { + return AVERROR(ENOMEM); + } + avret = avcodec_parameters_from_context(priv->bsfc->par_in, avctx); + if (avret != 0) { + return AVERROR(ENOMEM); + } + avret = av_bsf_init(priv->bsfc); + if (avret != 0) { return AVERROR(ENOMEM); } - priv->orig_extradata_size = avctx->extradata_size; - memcpy(priv->orig_extradata, avctx->extradata, avctx->extradata_size); - priv->bsfc = av_bitstream_filter_init("h264_mp4toannexb"); - if (!priv->bsfc) { + format.metaDataSz = priv->bsfc->par_out->extradata_size; + format.pMetaData = av_malloc(format.metaDataSz + AV_INPUT_BUFFER_PADDING_SIZE); + if (!format.pMetaData) { av_log(avctx, AV_LOG_ERROR, - "Cannot open the h264_mp4toannexb BSF!\n"); - return AVERROR_BSF_NOT_FOUND; + "Failed to allocate copy of extradata\n"); + return AVERROR(ENOMEM); } - av_bitstream_filter_filter(priv->bsfc, avctx, NULL, &dummy_p, - &dummy_int, NULL, 0, 0); + memcpy(format.pMetaData, priv->bsfc->par_out->extradata, format.metaDataSz); + + /* Back up the extradata so it can be restored at close time. */ + priv->orig_extradata = avctx->extradata; + priv->orig_extradata_size = avctx->extradata_size; + avctx->extradata = format.pMetaData; + avctx->extradata_size = format.metaDataSz; } subtype = BC_MSUBTYPE_H264; - // Fall-through + format.startCodeSz = 4; + break; case BC_MSUBTYPE_H264: format.startCodeSz = 4; // Fall-through @@ -901,14 +917,41 @@ static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *a if (len) { int32_t tx_free = (int32_t)DtsTxFreeSize(dev); - if (priv->parser) { + if (priv->bsfc) { int ret = 0; + AVPacket filter_packet = { 0 }; + AVPacket filtered_packet = { 0 }; + + ret = av_packet_ref(&filter_packet, avpkt); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "CrystalHD: mpv4toannexb filter " + "failed to ref input packet\n"); + return ret; + } + + ret = av_bsf_send_packet(priv->bsfc, &filter_packet); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "CrystalHD: mpv4toannexb filter " + "failed to send input packet\n"); + return ret; + } - if (priv->bsfc) { - ret = av_bitstream_filter_filter(priv->bsfc, avctx, NULL, - &in_data, &len, - avpkt->data, len, 0); + ret = av_bsf_receive_packet(priv->bsfc, &filtered_packet); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "CrystalHD: mpv4toannexb filter " + "failed to receive output packet\n"); + return ret; } + + in_data = filtered_packet.data; + len = filtered_packet.size; + + av_packet_unref(&filter_packet); + } + + if (priv->parser) { + int ret = 0; + free_data = ret > 0; if (ret >= 0) {