From patchwork Sat Jun 24 04:38:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 42288 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:be15:b0:121:b37c:e101 with SMTP id ge21csp4053745pzb; Fri, 23 Jun 2023 21:39:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5PE81yE0nFALdA8GYUPfDoK2XqHZjlLmZ6PKrlWHfzhn3r345NbFf8MJdr/7g2THVN1GKh X-Received: by 2002:a17:907:25c3:b0:978:6a95:512d with SMTP id ae3-20020a17090725c300b009786a95512dmr21287316ejc.11.1687581560795; Fri, 23 Jun 2023 21:39:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687581560; cv=none; d=google.com; s=arc-20160816; b=cJD2xYzlcZowvWAZTN3OYU7BlN3WebPE4vTG64Zz9+BtJDTCywy9OKdImywuHiWd44 I12rM0NLGh2VpyPLsMSJPvxXyw4LKmY+WjFWzcdyxVJSJBt06/n4QSVkhM5NfAbomtNs QDhSPlMIbZdB+ZmEYYGKnNV0oduAYksN7h+LCNxm5WDEiAKy+pQ+YSzg+aR8LwY5pJif bsPofiz9ijWu7ec+lg+S2Y8t2qlCKcKFBxevFNlk4d6ReQFWK6vHhA61JvEt+cMm/SZA tm4TKCaUNAWVCRxJ7eJp56z97psqce/lnKvCftPHPoKgC8HsS/E44mRmtDZPiOI5vD9O nDlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=mZGkHBNOBOSsIk5oPhto9gApthuo073PSpKe/16GHx0=; fh=+bdjGe20eEUjtjncwA1dnEEVYNfJL4vyhV+sIRR4l+g=; b=V3S45cfDFlZVY9pl4nczsqu6eZo8jJcdzqzrr/rl2rTTwaGzvLFSoGGqRlK9+QT55W A62IgwTqeLRbrvFbmOBBEuv0xjco9mtWwhDEOdAhPuZ61nGNFXbIp0r/z5DVFTZ3KBOF VWYOObdMv/Sderjrsb0PVSv/Hm4XoaB9M+/xnx0YalGPah0YAtRW6B1YeWpqKgY7X/nA DgpjPed8rdjuG9oD9HhMYEavk3UAdkAL96hFtGG/a8blhLyaC2pgO1PHB3l4gL6QTyxE roYKNr3O6cSjphSRkhg9mRShhYzdcYD6rPt/M4B/o+a+VUuBKQUS51ddBvGc1mNG7RcV iExg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=cn6gQdUt; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id pg1-20020a170907204100b0098865a8b937si416481ejb.193.2023.06.23.21.39.20; Fri, 23 Jun 2023 21:39:20 -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=@gmail.com header.s=20221208 header.b=cn6gQdUt; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CFE8B68BFE0; Sat, 24 Jun 2023 07:39:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 26C0168B838 for ; Sat, 24 Jun 2023 07:38:57 +0300 (EEST) Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-7576b53e75eso29342285a.1 for ; Fri, 23 Jun 2023 21:38:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687581536; x=1690173536; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y7cr8TDWfam2sZdgJ6lp3BZf9VZHH//dn/mZB7/Y5Fg=; b=cn6gQdUt7xF01Jjl7BDAXfHiSIz/qz7KyzFexEoMGC9YdAy+u0WrJ/uuAlpaCWUAFL 6eB3YFGTivVBOgFfU4HI9OioXAPgyhSFVufPQdJypYYu8yqbfAto1V8fBkWSqDZqTiB1 MGZkKFdc1PsATT4r3O4hE7ffJhp6sl+bQWN9y7+uWJia6wKswt3y8Hh7AnB/i/AMftBZ ieAw3irIXP84M5f4cpJ7pF6fS0SxvXW/K4n2RUpRQOMjd9MVwnTAgh1bAusAnQbcE1DU s3zd4CXuAqeOTCDrYuQmDhlbYwxl6Ka7eJuPS0mzKYhUpVVxpbS4CdVimDGd4OlWdP9H aZvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687581536; x=1690173536; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y7cr8TDWfam2sZdgJ6lp3BZf9VZHH//dn/mZB7/Y5Fg=; b=QX3lBkSCACKirN3ebiMFWDZKHSMgAz5nSA4SWyEICwCoBTgRfgXV9TWBvpQhtYK3Ez xxKLdTv3fOwWaiDf8VGKMh06neiIQOJlpNtlWa5iDLhWbu+ZBeUOe6+85pbiU9FVIfKd nwThwW1nqd7mMi3VpCGMDSvv07y0M4WH1FLc1H3kIDmn6I3nIElQGzfI4k2mIA8A0esc p9mvJtCYICMR5b2pVyqiLEhxhYO1ximckeMcJNMvArWdba+AQVa9uXJM/j084saY78fb qtZXvUtdM0wcy++M9byAEpyKVyeupv7er1eFm0gtOrTE1VZeHs7dz+wXiEB+iRsaqitV SDCA== X-Gm-Message-State: AC+VfDy85t3wqU3U1Y6IskxOGjGCxPLQ3rG/9SV8O0LUcXFlM2tVYxnC C+cSMG2vqdH6Ne/aXRgVKi2ucBXbf1k= X-Received: by 2002:a05:620a:171f:b0:75d:e31a:a015 with SMTP id az31-20020a05620a171f00b0075de31aa015mr27203374qkb.2.1687581535776; Fri, 23 Jun 2023 21:38:55 -0700 (PDT) Received: from gauss.local (c-98-224-219-15.hsd1.mi.comcast.net. [98.224.219.15]) by smtp.gmail.com with ESMTPSA id m11-20020a0dca0b000000b0055aafcef659sm173719ywd.5.2023.06.23.21.38.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 21:38:55 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Jun 2023 00:38:50 -0400 Message-ID: <20230624043853.12237-2-leo.izen@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230624043853.12237-1-leo.izen@gmail.com> References: <20230624043853.12237-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/4] avcodec/libjxldec: use internal AVFrame as buffered space X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Leo Izen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: tEvoA2sEOUTR Before this commit, the decoder erroneously assumes that the AVFrame passed to the receive_frame is the same one each time. Now it keeps an internal AVFrame to write into, and copies it over when it's done. --- libavcodec/libjxldec.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c index 50417bcb02..cea7ea0d3b 100644 --- a/libavcodec/libjxldec.c +++ b/libavcodec/libjxldec.c @@ -58,6 +58,7 @@ typedef struct LibJxlDecodeContext { int64_t frame_duration; int prev_is_last; AVRational timebase; + AVFrame *frame; } LibJxlDecodeContext; static int libjxl_init_jxl_decoder(AVCodecContext *avctx) @@ -104,6 +105,9 @@ static av_cold int libjxl_decode_init(AVCodecContext *avctx) ctx->avpkt = avctx->internal->in_pkt; ctx->pts = 0; + ctx->frame = av_frame_alloc(); + if (!ctx->frame) + return AVERROR(ENOMEM); return libjxl_init_jxl_decoder(avctx); } @@ -351,10 +355,12 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) size_t remaining; if (!pkt->size) { + av_log(avctx, AV_LOG_DEBUG, "Fetching new packet\n"); av_packet_unref(pkt); ret = ff_decode_get_packet(avctx, pkt); if (ret < 0 && ret != AVERROR_EOF) return ret; + av_log(avctx, AV_LOG_DEBUG, "Fetched packet of size: %d\n", pkt->size); if (!pkt->size) { /* jret set by the last iteration of the loop */ if (jret == JXL_DEC_NEED_MORE_INPUT) { @@ -389,10 +395,6 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) return AVERROR_INVALIDDATA; case JXL_DEC_NEED_MORE_INPUT: av_log(avctx, AV_LOG_DEBUG, "NEED_MORE_INPUT event emitted\n"); - if (!pkt->size) { - av_packet_unref(pkt); - return AVERROR(EAGAIN); - } continue; case JXL_DEC_BASIC_INFO: av_log(avctx, AV_LOG_DEBUG, "BASIC_INFO event emitted\n"); @@ -421,16 +423,18 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) continue; case JXL_DEC_COLOR_ENCODING: av_log(avctx, AV_LOG_DEBUG, "COLOR_ENCODING event emitted\n"); - if ((ret = libjxl_color_encoding_event(avctx, frame)) < 0) + if ((ret = libjxl_color_encoding_event(avctx, ctx->frame)) < 0) return ret; continue; case JXL_DEC_NEED_IMAGE_OUT_BUFFER: av_log(avctx, AV_LOG_DEBUG, "NEED_IMAGE_OUT_BUFFER event emitted\n"); - if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) + ret = ff_get_buffer(avctx, ctx->frame, 0); + if (ret < 0) return ret; - ctx->jxl_pixfmt.align = frame->linesize[0]; - if (JxlDecoderSetImageOutBuffer(ctx->decoder, &ctx->jxl_pixfmt, frame->data[0], frame->buf[0]->size) - != JXL_DEC_SUCCESS) { + ctx->jxl_pixfmt.align = ctx->frame->linesize[0]; + if (JxlDecoderSetImageOutBuffer(ctx->decoder, &ctx->jxl_pixfmt, + ctx->frame->data[0], ctx->frame->buf[0]->size) + != JXL_DEC_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Bad libjxl dec need image out buffer event\n"); return AVERROR_EXTERNAL; } @@ -444,8 +448,8 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) case JXL_DEC_FRAME: av_log(avctx, AV_LOG_DEBUG, "FRAME event emitted\n"); if (!ctx->basic_info.have_animation || ctx->prev_is_last) { - frame->pict_type = AV_PICTURE_TYPE_I; - frame->flags |= AV_FRAME_FLAG_KEY; + ctx->frame->pict_type = AV_PICTURE_TYPE_I; + ctx->frame->flags |= AV_FRAME_FLAG_KEY; } if (ctx->basic_info.have_animation) { JxlFrameHeader header; @@ -464,20 +468,21 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) /* full image is one frame, even if animated */ av_log(avctx, AV_LOG_DEBUG, "FULL_IMAGE event emitted\n"); if (ctx->iccp) { - AVFrameSideData *sd = av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_ICC_PROFILE, ctx->iccp); + AVFrameSideData *sd = av_frame_new_side_data_from_buf(ctx->frame, AV_FRAME_DATA_ICC_PROFILE, ctx->iccp); if (!sd) return AVERROR(ENOMEM); /* ownership is transfered, and it is not ref-ed */ ctx->iccp = NULL; } if (avctx->pkt_timebase.num) { - frame->pts = av_rescale_q(ctx->pts, ctx->timebase, avctx->pkt_timebase); - frame->duration = av_rescale_q(ctx->frame_duration, ctx->timebase, avctx->pkt_timebase); + ctx->frame->pts = av_rescale_q(ctx->pts, ctx->timebase, avctx->pkt_timebase); + ctx->frame->duration = av_rescale_q(ctx->frame_duration, ctx->timebase, avctx->pkt_timebase); } else { - frame->pts = ctx->pts; - frame->duration = ctx->frame_duration; + ctx->frame->pts = ctx->pts; + ctx->frame->duration = ctx->frame_duration; } ctx->pts += ctx->frame_duration; + av_frame_move_ref(frame, ctx->frame); return 0; case JXL_DEC_SUCCESS: av_log(avctx, AV_LOG_DEBUG, "SUCCESS event emitted\n"); @@ -508,6 +513,7 @@ static av_cold int libjxl_decode_close(AVCodecContext *avctx) JxlDecoderDestroy(ctx->decoder); ctx->decoder = NULL; av_buffer_unref(&ctx->iccp); + av_frame_free(&ctx->frame); return 0; } @@ -521,7 +527,7 @@ const FFCodec ff_libjxl_decoder = { .init = libjxl_decode_init, FF_CODEC_RECEIVE_FRAME_CB(libjxl_receive_frame), .close = libjxl_decode_close, - .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_OTHER_THREADS, + .p.capabilities = AV_CODEC_CAP_OTHER_THREADS, .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE | FF_CODEC_CAP_AUTO_THREADS | FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_ICC_PROFILES, From patchwork Sat Jun 24 04:38:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 42289 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:be15:b0:121:b37c:e101 with SMTP id ge21csp4053778pzb; Fri, 23 Jun 2023 21:39:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5uWd9TB0btlrThW6MO9DnFMoC2yDBYrKxOmYIhqirMRWJhdtHCDqEsUbEmv9awKbWdxx9x X-Received: by 2002:a17:907:16a6:b0:978:66bd:d771 with SMTP id hc38-20020a17090716a600b0097866bdd771mr23618713ejc.55.1687581569655; Fri, 23 Jun 2023 21:39:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687581569; cv=none; d=google.com; s=arc-20160816; b=r7YKXq0cCZifBEDRy3Jo5Lnsz0lSnpyiQnJtn545gF5k3QyhCzm/JDMZo5hyYOA4eu Jjdcpu5RenNMSwX5op0F7NgPrhb3LOPKXpFymjQUEhXY5O29DHV7EIZ7NH8CjUwVSgw8 M1C2qumyjXnydBO7LufoBWhEYc28dLHps0n8bpfT+acvVxuvyvn/icHKKvbYdY5tPmNC XlmKSg3XZorvgmNT9U45uPcOBzhxiG46bMwv+MOCx+b3RYb4elu+chdKcBvnkSjsW1ue gJ0qFLI5iMbRk58BsHvw+lOPCurWaKOocP09c+HtCQBgJPvQnvOE3f8lDJU4xXQFsL6P Y/mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=dztxwe48UB1TkUJL0J6NYF088NTmZb2ICW2T+Udmwaw=; fh=+bdjGe20eEUjtjncwA1dnEEVYNfJL4vyhV+sIRR4l+g=; b=p3hV2xUmysysrXsCIfAnTIAvSQrgcIwSOib6dZ29a0zSBX70zzQjxVKsxK4tN1vxIq I2nxLgTu+K6kD7lC06JPBd85ZKRLqg/QHQZK3iURXMOIIAV8cdfuzMPD6BSBfsilvf/A nFNyLR2ZD4fF3vce27tpCg/x6U7ziD/+2KlhCsWZHVQM3Uc+1VseNtgfU2f+OFW/+rCx 3eZFDWDIFb82B0JtKpa5QPD07BK+V2O+O9qmGeTaKXwkZ+oD5j4qPtr2os9NxIWaTN9Y wooeu29y5woyH8+iiF1+WHdskRqqKp/uttX5xH8Hq4IsvKwGxJkkJ2k75dmfamP5X9rm Ahig== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b="EtLt/Bl4"; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g15-20020aa7d1cf000000b0051878e1bd81si264387edp.591.2023.06.23.21.39.29; Fri, 23 Jun 2023 21:39:29 -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=@gmail.com header.s=20221208 header.b="EtLt/Bl4"; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D831968C1A9; Sat, 24 Jun 2023 07:39:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F401C68B838 for ; Sat, 24 Jun 2023 07:38:57 +0300 (EEST) Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7576b53e75eso29342585a.1 for ; Fri, 23 Jun 2023 21:38:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687581536; x=1690173536; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qMFq63XOnG3tQrrj0hCHUgBjYevItNMwA6vmN67Ml08=; b=EtLt/Bl4DjZ8frDBoBCEVq7GMZYcPVvOVLG8xu2OuRDWjIevERXjLH82DIty4QBG2y 6EGiDRta/n7ZVohOdxH+y9NbnCDE3KrP/J3QAphz0KlriD+p3SXQpqG+j/YjoNGnWvM3 EGuErmrG/lennCSG1roIKogAyPJcBPl1NauX11jglIZWeiwR5FC/dq+pEIQYqfMUHsqr qnW3iZgQbKBxgLWnZLju8MEOgMU35suianX7wcvaDxlrJEtRGLSUrz1liDPAvOt27js0 z/Ta/96mw66nYLuTG8ffWXljWtSfnnqDWF9pwI2sZUvLDPl1kuFz6y6cq28ea5Izi8/O l49A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687581536; x=1690173536; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qMFq63XOnG3tQrrj0hCHUgBjYevItNMwA6vmN67Ml08=; b=hra/nXHj+R4yLw08evlqDE+JPdHwDzcLKqbGpumBEF/qg6tLXJFiWFEiAx4idefgYt qrM6WKsI/qL6LNHpJt5Bx8btZWXiyRS6jEb605LeZ8vXdhORxfPKLWmOQrBaAjlbwv43 Pue36++g57DqlUKiQ0VFRgt8Jjc8u9KOTYP9KJEjpUiS3ALUjQpoZCphJ6rGPQwfvvcR M7JyAW/6qndoBBMBJFWMxcGs0SkEqBNQbiXzBqyG7zAvp3rOdVQjiY2uz29XxzTe5cMc Qs9c7yWJ6VsoTU0dQwlzFABBZdWHL/v3klF3bl6J0UjvMcYuiv+8ptvJzL8aQw+Dv61/ CoXA== X-Gm-Message-State: AC+VfDyIOnOAOG2V62uNxPSMpGS66mg+WJVubYTHsQUuh2M9+gGl+6At 4ijVztgkLKTO46vKh969g6A9NLW0bnc= X-Received: by 2002:a05:620a:86cc:b0:763:bcd7:6abf with SMTP id pr12-20020a05620a86cc00b00763bcd76abfmr10958961qkn.1.1687581536478; Fri, 23 Jun 2023 21:38:56 -0700 (PDT) Received: from gauss.local (c-98-224-219-15.hsd1.mi.comcast.net. [98.224.219.15]) by smtp.gmail.com with ESMTPSA id m11-20020a0dca0b000000b0055aafcef659sm173719ywd.5.2023.06.23.21.38.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 21:38:56 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Jun 2023 00:38:51 -0400 Message-ID: <20230624043853.12237-3-leo.izen@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230624043853.12237-1-leo.izen@gmail.com> References: <20230624043853.12237-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 2/4] avcodec/jpegxl_parser: add JPEG XL parser X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Leo Izen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: WSZmE2MCNAOW Add a parser to libavcodec for AV_CODEC_ID_JPEGXL. It doesn't find the end of the stream in order to packetize the codec, but it does look at the headers to set preliminary information like dimensions and pixel format. Note that much of this code is duplicated from avformat/jpegxl_probe.c, but that code will be removed and call this instead in the next commit. Signed-off-by: --- libavcodec/Makefile | 1 + libavcodec/jpegxl.h | 72 ++++++ libavcodec/jpegxl_parse.c | 495 +++++++++++++++++++++++++++++++++++++ libavcodec/jpegxl_parse.h | 63 +++++ libavcodec/jpegxl_parser.c | 182 ++++++++++++++ libavcodec/parsers.c | 1 + libavcodec/version.h | 2 +- 7 files changed, 815 insertions(+), 1 deletion(-) create mode 100644 libavcodec/jpegxl.h create mode 100644 libavcodec/jpegxl_parse.c create mode 100644 libavcodec/jpegxl_parse.h create mode 100644 libavcodec/jpegxl_parser.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 0e4d27f37b..683373919a 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1184,6 +1184,7 @@ OBJS-$(CONFIG_HEVC_PARSER) += hevc_parser.o hevc_data.o OBJS-$(CONFIG_HDR_PARSER) += hdr_parser.o OBJS-$(CONFIG_IPU_PARSER) += ipu_parser.o OBJS-$(CONFIG_JPEG2000_PARSER) += jpeg2000_parser.o +OBJS-$(CONFIG_JPEGXL_PARSER) += jpegxl_parser.o jpegxl_parse.o OBJS-$(CONFIG_MISC4_PARSER) += misc4_parser.o OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg_parser.o OBJS-$(CONFIG_MLP_PARSER) += mlp_parse.o mlp_parser.o mlp.o diff --git a/libavcodec/jpegxl.h b/libavcodec/jpegxl.h new file mode 100644 index 0000000000..d6faf1a8bd --- /dev/null +++ b/libavcodec/jpegxl.h @@ -0,0 +1,72 @@ +/* + * JPEG XL Common Header Definitions + * Copyright (c) 2023 Leo Izen + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_JPEGXL_H +#define AVCODEC_JPEGXL_H + +#define FF_JPEGXL_CODESTREAM_SIGNATURE_LE 0x0aff +#define FF_JPEGXL_CONTAINER_SIGNATURE_LE 0x204c584a0c000000 + +typedef enum FFJXLExtraChannelType { + JPEGXL_CT_ALPHA = 0, + JPEGXL_CT_DEPTH, + JPEGXL_CT_SPOT_COLOR, + JPEGXL_CT_SELECTION_MASK, + JPEGXL_CT_BLACK, + JPEGXL_CT_CFA, + JPEGXL_CT_THERMAL, + JPEGXL_CT_NON_OPTIONAL = 15, + JPEGXL_CT_OPTIONAL +} FFJXLExtraChannelType; + +typedef enum FFJXLColorSpace { + JPEGXL_CS_RGB = 0, + JPEGXL_CS_GRAY, + JPEGXL_CS_XYB, + JPEGXL_CS_UNKNOWN +} FFJXLColorSpace; + +typedef enum FFJXLWhitePoint { + JPEGXL_WP_D65 = 1, + JPEGXL_WP_CUSTOM, + JPEGXL_WP_E = 10, + JPEGXL_WP_DCI = 11 +} FFJXLWhitePoint; + +typedef enum FFJXLPrimaries { + JPEGXL_PR_SRGB = 1, + JPEGXL_PR_CUSTOM, + JPEGXL_PR_2100 = 9, + JPEGXL_PR_P3 = 11, +} FFJXLPrimaries; + +typedef enum FFJXLTransferCharacteristic { + JPEGXL_TR_BT709 = 1, + JPEGXL_TR_UNKNOWN, + JPEGXL_TR_LINEAR = 8, + JPEGXL_TR_SRGB = 13, + JPEGXL_TR_PQ = 16, + JPEGXL_TR_DCI, + JPEGXL_TR_HLG, + JPEGXL_TR_GAMMA = 1 << 24, +} FFJXLTransferCharacteristic; + +#endif /* AVCODEC_JPEGXL_H */ diff --git a/libavcodec/jpegxl_parse.c b/libavcodec/jpegxl_parse.c new file mode 100644 index 0000000000..023e6adf07 --- /dev/null +++ b/libavcodec/jpegxl_parse.c @@ -0,0 +1,495 @@ +/* + * JPEG XL Header Parser + * Copyright (c) 2023 Leo Izen + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "bytestream.h" +#define UNCHECKED_BITSTREAM_READER 0 +#define BITSTREAM_READER_LE +#include "get_bits.h" +#include "jpegxl.h" +#include "jpegxl_parse.h" + +/* read a U32(c_i + u(u_i)) */ +static av_always_inline uint32_t jxl_u32(GetBitContext *gb, + uint32_t c0, uint32_t c1, uint32_t c2, uint32_t c3, + uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3) +{ + const uint32_t constants[4] = {c0, c1, c2, c3}; + const uint32_t ubits [4] = {u0, u1, u2, u3}; + uint32_t ret, choice = get_bits(gb, 2); + + ret = constants[choice]; + if (ubits[choice]) + ret += get_bits_long(gb, ubits[choice]); + + return ret; +} + +static av_always_inline uint32_t jxl_enum(GetBitContext *gb) +{ + return jxl_u32(gb, 0, 1, 2, 18, 0, 0, 4, 6); +} + +/* read a U64() */ +static uint64_t jpegxl_u64(GetBitContext *gb) +{ + uint64_t shift = 12, ret; + + switch (get_bits(gb, 2)) { + case 1: + ret = 1 + get_bits(gb, 4); + break; + case 2: + ret = 17 + get_bits(gb, 8); + break; + case 3: + ret = get_bits(gb, 12); + while (get_bits1(gb)) { + if (shift < 60) { + ret |= (uint64_t)get_bits(gb, 8) << shift; + shift += 8; + } else { + ret |= (uint64_t)get_bits(gb, 4) << shift; + break; + } + } + break; + default: + ret = 0; + } + + return ret; +} + +static uint32_t jpegxl_width_from_ratio(uint32_t height, int ratio) +{ + uint64_t height64 = height; /* avoid integer overflow */ + switch (ratio) { + case 1: + return height; + case 2: + return (uint32_t)((height64 * 12) / 10); + case 3: + return (uint32_t)((height64 * 4) / 3); + case 4: + return (uint32_t)((height64 * 3) / 2); + case 5: + return (uint32_t)((height64 * 16) / 9); + case 6: + return (uint32_t)((height64 * 5) / 4); + case 7: + return (uint32_t)(height64 * 2); + default: + break; + } + + return 0; /* manual width */ +} + +/** + * validate a Jpeg XL Size Header + * @return >= 0 upon valid size, < 0 upon invalid size found + */ +static int jpegxl_read_size_header(GetBitContext *gb, FFJXLMetadata *meta) +{ + uint32_t width, height; + + if (get_bits1(gb)) { + /* small size header */ + height = (get_bits(gb, 5) + 1) << 3; + width = jpegxl_width_from_ratio(height, get_bits(gb, 3)); + if (!width) + width = (get_bits(gb, 5) + 1) << 3; + } else { + /* large size header */ + height = 1 + jxl_u32(gb, 0, 0, 0, 0, 9, 13, 18, 30); + width = jpegxl_width_from_ratio(height, get_bits(gb, 3)); + if (!width) + width = 1 + jxl_u32(gb, 0, 0, 0, 0, 9, 13, 18, 30); + } + if (width > (1 << 18) || height > (1 << 18) + || (width >> 4) * (height >> 4) > (1 << 20)) + return -1; + + if (meta) { + meta->width = width; + meta->height = height; + } + + return 0; +} + +/** + * validate a Jpeg XL Preview Header + * @return >= 0 upon valid size, < 0 upon invalid size found + */ +static int jpegxl_read_preview_header(GetBitContext *gb) +{ + uint32_t width, height; + + if (get_bits1(gb)) { + /* coded height and width divided by eight */ + height = jxl_u32(gb, 16, 32, 1, 33, 0, 0, 5, 9) << 3; + width = jpegxl_width_from_ratio(height, get_bits(gb, 3)); + if (!width) + width = jxl_u32(gb, 16, 32, 1, 33, 0, 0, 5, 9) << 3; + } else { + /* full height and width coded */ + height = jxl_u32(gb, 1, 65, 321, 1345, 6, 8, 10, 12); + width = jpegxl_width_from_ratio(height, get_bits(gb, 3)); + if (!width) + width = jxl_u32(gb, 1, 65, 321, 1345, 6, 8, 10, 12); + } + if (width > 4096 || height > 4096) + return -1; + + return 0; +} + +/** + * get a Jpeg XL BitDepth Header. These cannot be invalid. + */ +static void jpegxl_get_bit_depth(GetBitContext *gb, FFJXLMetadata *meta) +{ + int bit_depth; + if (get_bits1(gb)) { + /* float samples */ + bit_depth = jxl_u32(gb, 32, 16, 24, 1, 0, 0, 0, 6); /* mantissa */ + skip_bits_long(gb, 4); /* exponent */ + } else { + /* integer samples */ + bit_depth = jxl_u32(gb, 8, 10, 12, 1, 0, 0, 0, 6); + } + if (meta) + meta->bit_depth = bit_depth; +} + +/** + * validate a Jpeg XL Extra Channel Info bundle + * @return >= 0 upon valid, < 0 upon invalid + */ +static int jpegxl_read_extra_channel_info(GetBitContext *gb, int validate_level, FFJXLMetadata *meta) +{ + int all_default = get_bits1(gb); + uint32_t type, name_len = 0; + + if (!all_default) { + type = jxl_enum(gb); + if (type > 63) + return -1; /* enum types cannot be 64+ */ + if (type == JPEGXL_CT_BLACK && validate_level) + return -1; + jpegxl_get_bit_depth(gb, NULL); + jxl_u32(gb, 0, 3, 4, 1, 0, 0, 0, 3); /* dim-shift */ + /* max of name_len is 1071 = 48 + 2^10 - 1 */ + name_len = jxl_u32(gb, 0, 0, 16, 48, 0, 4, 5, 10); + } else { + type = JPEGXL_CT_ALPHA; + } + + /* skip over the name */ + skip_bits_long(gb, 8 * name_len); + + if (!all_default && type == JPEGXL_CT_ALPHA) + skip_bits1(gb); + + if (type == JPEGXL_CT_SPOT_COLOR) + skip_bits_long(gb, 16 * 4); + + if (type == JPEGXL_CT_CFA) + jxl_u32(gb, 1, 0, 3, 19, 0, 2, 4, 8); + + if (meta && type == JPEGXL_CT_ALPHA) + meta->have_alpha = 1; + + return 0; +} + +int ff_jpegxl_parse_codestream_header(const uint8_t *buf, int buflen, int validate_level, FFJXLMetadata *meta) +{ + GetBitContext gbi, *gb = &gbi; + int all_default, extra_fields = 0; + int xyb_encoded = 1, have_icc_profile = 0; + int animation_offset = 0; + AVRational tb; + uint32_t num_extra_channels; + uint64_t extensions; + int ret; + + ret = init_get_bits8(gb, buf, buflen); + if (ret < 0) + return ret; + + if (get_bits_long(gb, 16) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE) + return -1; + + ret = jpegxl_read_size_header(gb, meta); + if (ret < 0 && validate_level) + return ret; + + all_default = get_bits1(gb); + if (!all_default) + extra_fields = get_bits1(gb); + + if (extra_fields) { + int orientation = get_bits(gb, 3); + if (orientation > 3 && meta) + FFSWAP(uint32_t, meta->width, meta->height); + + /* + * intrinstic size + * any size header here is valid, but as it + * is variable length we have to read it + */ + if (get_bits1(gb)) + jpegxl_read_size_header(gb, NULL); + + /* preview header */ + if (get_bits1(gb)) { + ret = jpegxl_read_preview_header(gb); + if (ret < 0) + return ret; + } + + /* animation header */ + if (get_bits1(gb)) { + animation_offset = get_bits_count(gb); + tb.den = jxl_u32(gb, 100, 1000, 1, 1, 0, 0, 10, 30); + tb.num = jxl_u32(gb, 1, 1001, 1, 1, 0, 0, 8, 10); + jxl_u32(gb, 0, 0, 0, 0, 0, 3, 16, 32); + skip_bits_long(gb, 1); + } + } + + if (animation_offset && meta) { + meta->animation_offset = animation_offset; + meta->timebase = tb; + } + + if (get_bits_left(gb) < 1) + return AVERROR_INVALIDDATA; + + if (!all_default) { + jpegxl_get_bit_depth(gb, meta); + + /* modular_16bit_buffers must equal 1 */ + if (!get_bits1(gb) && validate_level) + return -1; + + num_extra_channels = jxl_u32(gb, 0, 1, 2, 1, 0, 0, 4, 12); + if (num_extra_channels > 4 && validate_level) + return -1; + for (uint32_t i = 0; i < num_extra_channels; i++) { + ret = jpegxl_read_extra_channel_info(gb, validate_level, meta); + if (ret < 0) + return ret; + if (get_bits_left(gb) < 1) + return AVERROR_INVALIDDATA; + } + + xyb_encoded = get_bits1(gb); + + /* color encoding bundle */ + if (!get_bits1(gb)) { + uint32_t color_space; + have_icc_profile = get_bits1(gb); + color_space = jxl_enum(gb); + if (color_space > 63) + return -1; + if (meta) + meta->csp = color_space; + if (!have_icc_profile) { + if (color_space != JPEGXL_CS_XYB) { + uint32_t white_point = jxl_enum(gb); + if (white_point > 63) + return -1; + if (meta) + meta->wp = white_point; + if (white_point == JPEGXL_WP_CUSTOM) { + /* ux and uy values */ + jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21); + jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21); + } + if (color_space != JPEGXL_CS_GRAY) { + /* primaries */ + uint32_t primaries = jxl_enum(gb); + if (primaries > 63) + return -1; + if (meta) + meta->primaries = primaries; + if (primaries == JPEGXL_PR_CUSTOM) { + /* ux/uy values for r,g,b */ + for (int i = 0; i < 6; i++) { + jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21); + if (get_bits_left(gb) < 1) + return AVERROR_INVALIDDATA; + } + } + } + } + + /* transfer characteristics */ + if (get_bits1(gb)) { + /* gamma */ + uint32_t trc = get_bits(gb, 24); + if (meta) + meta->trc = trc; + } else { + /* transfer function */ + uint32_t trc = jxl_enum(gb); + if (trc > 63) + return -1; + if (meta) + meta->trc = trc + (1U << 24); + } + + /* rendering intent */ + if (jxl_enum(gb) > 63) + return -1; + } + } + + /* tone mapping bundle */ + if (extra_fields && !get_bits1(gb)) + skip_bits_long(gb, 16 + 16 + 1 + 16); + + extensions = jpegxl_u64(gb); + if (get_bits_left(gb) < 1) + return AVERROR_INVALIDDATA; + if (extensions) { + for (int i = 0; i < 64; i++) { + if (extensions & (UINT64_C(1) << i)) + jpegxl_u64(gb); + if (get_bits_left(gb) < 1) + return AVERROR_INVALIDDATA; + } + } + } + + if (meta) { + if (!meta->bit_depth) + meta->bit_depth = 8; + if (!meta->csp) + meta->csp = JPEGXL_CS_RGB; + if (!meta->wp && !have_icc_profile) + meta->wp = JPEGXL_WP_D65; + if (!meta->primaries && !have_icc_profile) + meta->primaries = JPEGXL_PR_SRGB; + if (!meta->trc && !have_icc_profile) + meta->trc = JPEGXL_TR_SRGB + (1U << 24); + } + + /* default transform */ + if (!get_bits1(gb)) { + /* opsin inverse matrix */ + if (xyb_encoded && !get_bits1(gb)) + skip_bits_long(gb, 16 * 16); + /* cw_mask and default weights */ + if (get_bits1(gb)) + skip_bits_long(gb, 16 * 15); + if (get_bits1(gb)) + skip_bits_long(gb, 16 * 55); + if (get_bits1(gb)) + skip_bits_long(gb, 16 * 210); + } + + if (!have_icc_profile) { + int bits_remaining = 7 - (get_bits_count(gb) - 1) % 8; + if (bits_remaining && get_bits(gb, bits_remaining)) + return -1; + } + + if (get_bits_left(gb) < 0) + return -1; + + return 0; +} + +/* + * copies as much of the codestream into the buffer as possible + * pass a shorter buflen to request less + * returns the number of bytes consumed from input, may be greater than input_len + * if the input doesn't end on an ISOBMFF-box boundary + */ +int ff_jpegxl_collect_codestream_header(const uint8_t *input_buffer, int input_len, + uint8_t *buffer, int buflen, int *copied) +{ + GetByteContext gb; + int pos = 0; + bytestream2_init(&gb, input_buffer, input_len); + + while (1) { + uint64_t size; + uint32_t tag; + int head_size = 8; + + if (bytestream2_get_bytes_left(&gb) < 16) + break; + + size = bytestream2_get_be32(&gb); + if (size == 1) { + size = bytestream2_get_be64(&gb); + head_size = 16; + } + /* invalid ISOBMFF size */ + if (size && size <= head_size) + return AVERROR_INVALIDDATA; + if (size) + size -= head_size; + + tag = bytestream2_get_le32(&gb); + if (tag == MKTAG('j', 'x', 'l', 'p')) { + if (bytestream2_get_bytes_left(&gb) < 4) + break; + bytestream2_skip(&gb, 4); + if (size) { + if (size <= 4) + return AVERROR_INVALIDDATA; + size -= 4; + } + } + /* + * size = 0 means "until EOF". this is legal but uncommon + * here we just set it to the remaining size of the probe buffer + */ + if (!size) + size = bytestream2_get_bytes_left(&gb); + + pos += size + head_size; + + if (tag == MKTAG('j', 'x', 'l', 'c') || tag == MKTAG('j', 'x', 'l', 'p')) { + if (size > buflen - *copied) + size = buflen - *copied; + /* + * arbitrary chunking of the payload makes this memcpy hard to avoid + * in practice this will only be performed one or two times at most + */ + *copied += bytestream2_get_buffer(&gb, buffer + *copied, size); + } else { + bytestream2_skip(&gb, size); + } + if (bytestream2_get_bytes_left(&gb) <= 0 || *copied >= buflen) + break; + } + + return pos; +} diff --git a/libavcodec/jpegxl_parse.h b/libavcodec/jpegxl_parse.h new file mode 100644 index 0000000000..091e249d56 --- /dev/null +++ b/libavcodec/jpegxl_parse.h @@ -0,0 +1,63 @@ +/* + * JPEG XL Header Parser + * Copyright (c) 2023 Leo Izen + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_JPEGXL_PARSE_H +#define AVCODEC_JPEGXL_PARSE_H + +#include + +#include "libavutil/rational.h" + +#include "jpegxl.h" + +typedef struct FFJXLMetadata { + uint32_t width; + uint32_t height; + int bit_depth; + int have_alpha; + /* + * offset, in bits, of the animation header + * zero if not animated + */ + int animation_offset; + AVRational timebase; + FFJXLColorSpace csp; + FFJXLWhitePoint wp; + FFJXLPrimaries primaries; + FFJXLTransferCharacteristic trc; +} FFJXLMetadata; + +/* + * copies as much of the codestream into the buffer as possible + * pass a shorter buflen to request less + * returns the number of bytes consumed from input, may be greater than input_len + * if the input doesn't end on an ISOBMFF-box boundary + */ +int ff_jpegxl_collect_codestream_header(const uint8_t *input_buffer, int input_len, + uint8_t *buffer, int buflen, int *copied); + +/* + * Parse the codestream header with the provided buffer. Returns negative upon failure, + * zero upon success. The FFJXLMetadata parameter may be NULL, in which case it's ignored. + */ +int ff_jpegxl_parse_codestream_header(const uint8_t *buf, int buflen, int validate_level, FFJXLMetadata *meta); + +#endif /* AVCODEC_JPEGXL_PARSE_H */ diff --git a/libavcodec/jpegxl_parser.c b/libavcodec/jpegxl_parser.c new file mode 100644 index 0000000000..30599d1ae1 --- /dev/null +++ b/libavcodec/jpegxl_parser.c @@ -0,0 +1,182 @@ +/* + * JPEG XL Codec Parser + * Copyright (c) 2023 Leo Izen + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/intreadwrite.h" + +#include "codec_id.h" +#include "jpegxl.h" +#include "jpegxl_parse.h" +#include "parser.h" + +typedef struct JXLParseContext { + FFJXLMetadata meta; + int parsed_header; + int container; + uint8_t codestream_header[4096]; + int copied; + int skip; +} JXLParseContext; + +static void populate_fields(AVCodecParserContext *s, AVCodecContext *avctx, JXLParseContext *ctx) +{ + s->width = ctx->meta.width; + s->height = ctx->meta.height; + + switch (ctx->meta.csp) { + case JPEGXL_CS_RGB: + case JPEGXL_CS_XYB: + avctx->colorspace = AVCOL_SPC_RGB; + break; + default: + avctx->colorspace = AVCOL_SPC_UNSPECIFIED; + } + + if (ctx->meta.wp == JPEGXL_WP_D65) { + switch (ctx->meta.primaries) { + case JPEGXL_PR_SRGB: + avctx->color_primaries = AVCOL_PRI_BT709; + break; + case JPEGXL_PR_P3: + avctx->color_primaries = AVCOL_PRI_SMPTE432; + break; + case JPEGXL_PR_2100: + avctx->color_primaries = AVCOL_PRI_BT2020; + break; + default: + avctx->color_primaries = AVCOL_PRI_UNSPECIFIED; + } + } else if (ctx->meta.wp == JPEGXL_WP_DCI && ctx->meta.primaries == JPEGXL_PR_P3) { + avctx->color_primaries = AVCOL_PRI_SMPTE431; + } else { + avctx->color_primaries = AVCOL_PRI_UNSPECIFIED; + } + + if (ctx->meta.trc > JPEGXL_TR_GAMMA) { + FFJXLTransferCharacteristic trc = ctx->meta.trc - JPEGXL_TR_GAMMA; + switch (trc) { + case JPEGXL_TR_BT709: + avctx->color_trc = AVCOL_TRC_BT709; + break; + case JPEGXL_TR_LINEAR: + avctx->color_trc = AVCOL_TRC_LINEAR; + break; + case JPEGXL_TR_SRGB: + avctx->color_trc = AVCOL_TRC_IEC61966_2_1; + break; + case JPEGXL_TR_PQ: + avctx->color_trc = AVCOL_TRC_SMPTEST2084; + break; + case JPEGXL_TR_DCI: + avctx->color_trc = AVCOL_TRC_SMPTE428; + break; + case JPEGXL_TR_HLG: + avctx->color_trc = AVCOL_TRC_ARIB_STD_B67; + break; + default: + avctx->color_trc = AVCOL_TRC_UNSPECIFIED; + } + } else if (ctx->meta.trc > 0) { + if (ctx->meta.trc > 45355 && ctx->meta.trc < 45555) + avctx->color_trc = AVCOL_TRC_GAMMA22; + else if (ctx->meta.trc > 35614 && ctx->meta.trc < 35814) + avctx->color_trc = AVCOL_TRC_GAMMA28; + else + avctx->color_trc = AVCOL_TRC_UNSPECIFIED; + } else { + avctx->color_trc = AVCOL_TRC_UNSPECIFIED; + } + + if (ctx->meta.csp == JPEGXL_CS_GRAY) { + if (ctx->meta.bit_depth <= 8) + avctx->pix_fmt = s->format = ctx->meta.have_alpha ? AV_PIX_FMT_YA8 : AV_PIX_FMT_GRAY8; + else if (ctx->meta.bit_depth <= 16) + avctx->pix_fmt = s->format = ctx->meta.have_alpha ? AV_PIX_FMT_YA16 : AV_PIX_FMT_GRAY16; + else + avctx->pix_fmt = s->format = ctx->meta.have_alpha ? AV_PIX_FMT_NONE : AV_PIX_FMT_GRAYF32; + } else { + if (ctx->meta.bit_depth <= 8) + avctx->pix_fmt = s->format = ctx->meta.have_alpha ? AV_PIX_FMT_RGBA : AV_PIX_FMT_RGB24; + else if (ctx->meta.bit_depth <= 16) + avctx->pix_fmt = s->format = ctx->meta.have_alpha ? AV_PIX_FMT_RGBA64 : AV_PIX_FMT_RGB48; + else + avctx->pix_fmt = s->format = ctx->meta.have_alpha ? AV_PIX_FMT_RGBAF32 : AV_PIX_FMT_RGBF32; + } +} + +static int jpegxl_parse(AVCodecParserContext *s, AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + JXLParseContext *ctx = s->priv_data; + int ret; + + *poutbuf = NULL; + *poutbuf_size = 0; + + if (!ctx->parsed_header) { + if (ctx->container || AV_RL64(buf) == FF_JPEGXL_CONTAINER_SIGNATURE_LE) { + ctx->container = 1; + if (ctx->copied) { + int copy = FFMIN3(buf_size, ctx->skip, sizeof(ctx->codestream_header) - ctx->copied); + if (copy > 0) { + memcpy(ctx->codestream_header + ctx->copied, buf, copy); + ctx->copied += copy; + } else { + ctx->parsed_header = 1; + } + } else { + if (ctx->skip > buf_size) { + ctx->skip -= buf_size; + } else { + ret = ff_jpegxl_collect_codestream_header(buf + ctx->skip, buf_size - ctx->skip, + ctx->codestream_header, sizeof(ctx->codestream_header), + &ctx->copied); + if (ret < 0) + ctx->parsed_header = 1; + ctx->skip = FFMAX(0, ret - (buf_size - ctx->skip)); + } + } + if (ctx->copied) { + ret = ff_jpegxl_parse_codestream_header(ctx->codestream_header, ctx->copied, 0, &ctx->meta); + if (ret >= 0) { + populate_fields(s, avctx, ctx); + ctx->parsed_header = 1; + } + } + } else { + ret = ff_jpegxl_parse_codestream_header(buf, buf_size, 1, &ctx->meta); + if (ret >= 0) + populate_fields(s, avctx, ctx); + ctx->parsed_header = 1; + } + } + + *poutbuf = buf; + *poutbuf_size = buf_size; + + return buf_size; +} + +const AVCodecParser ff_jpegxl_parser = { + .codec_ids = { AV_CODEC_ID_JPEGXL }, + .priv_data_size = sizeof(JXLParseContext), + .parser_parse = jpegxl_parse, +}; diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c index 2c077ec3ae..aa2d0b0122 100644 --- a/libavcodec/parsers.c +++ b/libavcodec/parsers.c @@ -55,6 +55,7 @@ extern const AVCodecParser ff_hevc_parser; extern const AVCodecParser ff_hdr_parser; extern const AVCodecParser ff_ipu_parser; extern const AVCodecParser ff_jpeg2000_parser; +extern const AVCodecParser ff_jpegxl_parser; extern const AVCodecParser ff_misc4_parser; extern const AVCodecParser ff_mjpeg_parser; extern const AVCodecParser ff_mlp_parser; diff --git a/libavcodec/version.h b/libavcodec/version.h index da6f3a84ac..9411511e04 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #include "version_major.h" -#define LIBAVCODEC_VERSION_MINOR 21 +#define LIBAVCODEC_VERSION_MINOR 22 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ From patchwork Sat Jun 24 04:38:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 42291 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:be15:b0:121:b37c:e101 with SMTP id ge21csp4053858pzb; Fri, 23 Jun 2023 21:39:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4p1JiqeIXB2pZRDkyRmTl4GAR0KgANNXtt5f269nszf33Nd+xfoMV8z38Zp+9oNxvbsN9t X-Received: by 2002:aa7:ccc3:0:b0:51d:7e6b:7aa1 with SMTP id y3-20020aa7ccc3000000b0051d7e6b7aa1mr482457edt.11.1687581588310; Fri, 23 Jun 2023 21:39:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687581588; cv=none; d=google.com; s=arc-20160816; b=brwVodeTTj7UH5rW/TY5Z7LOkIB8BRd4TwioP6pctdRRsggcj/0WRnT2veJjCy/KX3 QYncBUobq5wXkUnwdP3qlWqYS8ICrY7TRkL8HzCXFvdG6VZcQu+xVOr/+kiqEFHffd8M 9vYOG0vWF6xhxybIbPvsJa6XGGd89IYkrzJHI9NVsPQRQJI2Iw05I6lnOzFAl2qzb+cm LifMWsthw9hg3/L+PyNZx4P8FydV5+o7UJFN3c3as82aRf0BbtQTBgNLPAETghBB6JYy xVXHhigstj+WkK3XGrZdi4PDaDLK9wc1Tf/6Cv5Mm7ebeku/wof+fUlfgRoCw0qmJE1Y 3SDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=yYDj93d6YA7sbTHnUTUu5FBMrwA3y5K9e1OteDus0fE=; fh=+bdjGe20eEUjtjncwA1dnEEVYNfJL4vyhV+sIRR4l+g=; b=nSxAZfoGqbT4knZpuYFKRVSwqGsL9f+wTHtm8LoNb1X9d4+r8BpCxEirasfanWN85E d3Wk2U3x4iOUf4KpcGdIqfCfdBjmYnqPwdODoXCeGiHcHlGvGelnuuUvMYFbALZ0OAkD Ob9JhajRrZeWhD/9s9IvQzJMB6W45/VniVUWGI+OuqTERFQLjJcrPYB4jXPmfZnLsa1B Ex065095zQPDrCMX9O8o9TpgE8c89RVuMR8l/pWI1Vb3yAhRSqj3vfddP1fK4gJYYehd Y2or5oIKkeGrwryBE7IFr2npCYVEV+9FbNnOqXV7dvWeqwgRTqGD7Jn3tMzkPrIxwUFJ lLLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=kJNODrlW; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f2-20020a056402150200b0051bdf2d9a3esi245251edw.466.2023.06.23.21.39.48; Fri, 23 Jun 2023 21:39:48 -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=@gmail.com header.s=20221208 header.b=kJNODrlW; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A75AF68C20B; Sat, 24 Jun 2023 07:39:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9A3F168C16A for ; Sat, 24 Jun 2023 07:38:59 +0300 (EEST) Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-c00173ea5f3so129117276.0 for ; Fri, 23 Jun 2023 21:38:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687581537; x=1690173537; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4UYFvPK55OGpBG4+bThcwvobZC0XMCgE0tdJQf4uYBw=; b=kJNODrlWfHPeXNoU/D2LRSti7dORXE554UczWF//vs/QubS9uK50guAByKK6ccuLll DdiWKC1YSIvHng7wIyKtFN6DEHWEfo2U/j2bL4RVgwjwqTRoaQmGwofPEkJPb5gBII9e vseOh/E+GqRwIOcLDdYAhb/+Ec8zAAwFRTrNUMmAk3fSugrcDqvIWvZLP0FjsepBTZys prb0sJRZTMucoWR2/wnFQBx+g6YyqYJAMAB4NloYixqvM8WarwTLMA/+0A/OdY660Vob 9bBlLJnaslFEsKTUtZfyXFLD7gu4XJKYdcrtyla0TH0nDQi5jZ+rVhrjd2hhHB+sVDTx 0UsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687581537; x=1690173537; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4UYFvPK55OGpBG4+bThcwvobZC0XMCgE0tdJQf4uYBw=; b=ItrYaSZTKmIFFGNfXlIz1wp0RQtYiyZdOeQDTaB2wDTxPBdo7jLZAnbEvGKNBXAj6w 0ia+x0zwGM0WaTC1O0M1rIXPUOZ/vIOx9m2botFEngzKqCGxCDMhSfuKo7tpD3dXFsEy ufOdDO60S9vMZjy9o4USG4MOD7KuQ5fd8XAAV8vx2u8OwdcyuFHKduyUUb7uCMmNCjkc 5jsjw68I7IfmBiCnK9GLaKIHZH0fa+qk3R7syvEBj2KqJ51zk3tpBxAuQ+DlSYmQbcti spqJobrV4Ri3qNEW7ERD0GCJCW7TGV1Hro3hOntldV+DPbgu1aaBS3CPCSxDFMdxEdNV ZFsA== X-Gm-Message-State: AC+VfDy/oprA0OzuWY/Lx22Xc7JptOPt2Mn8i6uYNsVKh4PuTb/AGHsC hzprmTUsn291UYm+Q/kMC9y6eWGFOmI= X-Received: by 2002:a81:1a10:0:b0:565:5228:44f7 with SMTP id a16-20020a811a10000000b00565522844f7mr12334330ywa.4.1687581537163; Fri, 23 Jun 2023 21:38:57 -0700 (PDT) Received: from gauss.local (c-98-224-219-15.hsd1.mi.comcast.net. [98.224.219.15]) by smtp.gmail.com with ESMTPSA id m11-20020a0dca0b000000b0055aafcef659sm173719ywd.5.2023.06.23.21.38.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 21:38:56 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Jun 2023 00:38:52 -0400 Message-ID: <20230624043853.12237-4-leo.izen@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230624043853.12237-1-leo.izen@gmail.com> References: <20230624043853.12237-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 3/4] avformat/jpegxl: remove jpegxl_probe, instead call avcodec/jpegxl_parse X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Leo Izen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: WI6/ZXzlYb0w This prevents code duplication in the source form by calling the parse code that was moved to avcodec last commit. The code will be duplicated in binary form for shared builds (it's not that large), but for source code it will only exist in one location now. Signed-off-by: --- libavformat/Makefile | 5 +- libavformat/img2dec.c | 4 +- libavformat/jpegxl_anim_dec.c | 114 +---- .../{jpegxl_probe.h => jpegxl_parse.c} | 21 +- libavformat/jpegxl_probe.c | 412 ------------------ 5 files changed, 28 insertions(+), 528 deletions(-) rename libavformat/{jpegxl_probe.h => jpegxl_parse.c} (55%) delete mode 100644 libavformat/jpegxl_probe.c diff --git a/libavformat/Makefile b/libavformat/Makefile index 2b90b788c0..0637199c9d 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -283,7 +283,7 @@ OBJS-$(CONFIG_IMAGE_HDR_PIPE_DEMUXER) += img2dec.o img2.o OBJS-$(CONFIG_IMAGE_J2K_PIPE_DEMUXER) += img2dec.o img2.o OBJS-$(CONFIG_IMAGE_JPEG_PIPE_DEMUXER) += img2dec.o img2.o OBJS-$(CONFIG_IMAGE_JPEGLS_PIPE_DEMUXER) += img2dec.o img2.o -OBJS-$(CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER) += img2dec.o img2.o jpegxl_probe.o +OBJS-$(CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER) += img2dec.o img2.o jpegxl_parse.o OBJS-$(CONFIG_IMAGE_PAM_PIPE_DEMUXER) += img2dec.o img2.o OBJS-$(CONFIG_IMAGE_PBM_PIPE_DEMUXER) += img2dec.o img2.o OBJS-$(CONFIG_IMAGE_PCX_PIPE_DEMUXER) += img2dec.o img2.o @@ -320,7 +320,7 @@ OBJS-$(CONFIG_IVF_MUXER) += ivfenc.o OBJS-$(CONFIG_IVR_DEMUXER) += rmdec.o rm.o rmsipr.o OBJS-$(CONFIG_JACOSUB_DEMUXER) += jacosubdec.o subtitles.o OBJS-$(CONFIG_JACOSUB_MUXER) += jacosubenc.o rawenc.o -OBJS-$(CONFIG_JPEGXL_ANIM_DEMUXER) += jpegxl_anim_dec.o jpegxl_probe.o +OBJS-$(CONFIG_JPEGXL_ANIM_DEMUXER) += jpegxl_anim_dec.o jpegxl_parse.o OBJS-$(CONFIG_JV_DEMUXER) += jvdec.o OBJS-$(CONFIG_KUX_DEMUXER) += flvdec.o OBJS-$(CONFIG_KVAG_DEMUXER) += kvag.o @@ -715,6 +715,7 @@ SHLIBOBJS += log2_tab.o to_upper4.o SHLIBOBJS-$(CONFIG_ISO_MEDIA) += mpegaudiotabs.o SHLIBOBJS-$(CONFIG_FLV_MUXER) += mpeg4audio_sample_rates.o SHLIBOBJS-$(CONFIG_HLS_DEMUXER) += ac3_channel_layout_tab.o +SHLIBOBJS-$(CONFIG_JPEGXL_ANIM_DEMUXER) += jpegxl_parse.o SHLIBOBJS-$(CONFIG_MATROSKA_DEMUXER) += mpeg4audio_sample_rates.o SHLIBOBJS-$(CONFIG_MOV_DEMUXER) += ac3_channel_layout_tab.o SHLIBOBJS-$(CONFIG_MP3_MUXER) += mpegaudiotabs.o diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index b986d3a502..72b2c76405 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -36,7 +36,7 @@ #include "avio_internal.h" #include "internal.h" #include "img2.h" -#include "jpegxl_probe.h" +#include "libavcodec/jpegxl_parse.h" #include "libavcodec/mjpeg.h" #include "libavcodec/vbn.h" #include "libavcodec/xwd.h" @@ -850,7 +850,7 @@ static int jpegxl_probe(const AVProbeData *p) if (AV_RL16(b) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE) return 0; #if CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER - if (ff_jpegxl_verify_codestream_header(p->buf, p->buf_size, 1) >= 0) + if (ff_jpegxl_parse_codestream_header(p->buf, p->buf_size, 1, NULL) >= 0) return AVPROBE_SCORE_MAX - 2; #endif return 0; diff --git a/libavformat/jpegxl_anim_dec.c b/libavformat/jpegxl_anim_dec.c index 956b56c1d8..b178b74ff0 100644 --- a/libavformat/jpegxl_anim_dec.c +++ b/libavformat/jpegxl_anim_dec.c @@ -28,96 +28,28 @@ #include #include -#include "libavcodec/bytestream.h" -#define BITSTREAM_READER_LE -#include "libavcodec/get_bits.h" - +#include "libavcodec/jpegxl.h" +#include "libavcodec/jpegxl_parse.h" #include "libavutil/intreadwrite.h" #include "libavutil/opt.h" #include "avformat.h" #include "internal.h" -#include "jpegxl_probe.h" typedef struct JXLAnimDemuxContext { AVBufferRef *initial; } JXLAnimDemuxContext; -/* - * copies as much of the codestream into the buffer as possible - * pass a shorter buflen to request less - * returns the number of bytes consumed from input, may be greater than input_len - * if the input doesn't end on an ISOBMFF-box boundary - */ -static int jpegxl_collect_codestream_header(const uint8_t *input_buffer, int input_len, - uint8_t *buffer, int buflen, int *copied) { - GetByteContext gb; - *copied = 0; - bytestream2_init(&gb, input_buffer, input_len); - - while (1) { - uint64_t size; - uint32_t tag; - int head_size = 8; - - if (bytestream2_get_bytes_left(&gb) < 16) - break; - - size = bytestream2_get_be32(&gb); - if (size == 1) { - size = bytestream2_get_be64(&gb); - head_size = 16; - } - /* invalid ISOBMFF size */ - if (size && size <= head_size) - return AVERROR_INVALIDDATA; - if (size) - size -= head_size; - - tag = bytestream2_get_le32(&gb); - if (tag == MKTAG('j', 'x', 'l', 'p')) { - if (bytestream2_get_bytes_left(&gb) < 4) - break; - bytestream2_skip(&gb, 4); - if (size) { - if (size <= 4) - return AVERROR_INVALIDDATA; - size -= 4; - } - } - /* - * size = 0 means "until EOF". this is legal but uncommon - * here we just set it to the remaining size of the probe buffer - */ - if (!size) - size = bytestream2_get_bytes_left(&gb); - - if (tag == MKTAG('j', 'x', 'l', 'c') || tag == MKTAG('j', 'x', 'l', 'p')) { - if (size > buflen - *copied) - size = buflen - *copied; - /* - * arbitrary chunking of the payload makes this memcpy hard to avoid - * in practice this will only be performed one or two times at most - */ - *copied += bytestream2_get_buffer(&gb, buffer + *copied, size); - } else { - bytestream2_skip(&gb, size); - } - if (bytestream2_get_bytes_left(&gb) <= 0 || *copied >= buflen) - break; - } - - return bytestream2_tell(&gb); -} - static int jpegxl_anim_probe(const AVProbeData *p) { uint8_t buffer[4096 + AV_INPUT_BUFFER_PADDING_SIZE]; - int copied; + int copied = 0, ret; + FFJXLMetadata meta = { 0 }; /* this is a raw codestream */ if (AV_RL16(p->buf) == FF_JPEGXL_CODESTREAM_SIGNATURE_LE) { - if (ff_jpegxl_verify_codestream_header(p->buf, p->buf_size, 1) >= 1) + ret = ff_jpegxl_parse_codestream_header(p->buf, p->buf_size, 1, &meta); + if (ret >= 0 && meta.animation_offset > 0) return AVPROBE_SCORE_MAX; return 0; @@ -127,10 +59,13 @@ static int jpegxl_anim_probe(const AVProbeData *p) if (AV_RL64(p->buf) != FF_JPEGXL_CONTAINER_SIGNATURE_LE) return 0; - if (jpegxl_collect_codestream_header(p->buf, p->buf_size, buffer, sizeof(buffer) - AV_INPUT_BUFFER_PADDING_SIZE, &copied) <= 0 || copied <= 0) + if (ff_jpegxl_collect_codestream_header(p->buf, p->buf_size, buffer, + sizeof(buffer) - AV_INPUT_BUFFER_PADDING_SIZE, &copied) <= 0 + || copied <= 0) return 0; - if (ff_jpegxl_verify_codestream_header(buffer, copied, 0) >= 1) + ret = ff_jpegxl_parse_codestream_header(buffer, copied, 0, &meta); + if (ret >= 0 && meta.animation_offset > 0) return AVPROBE_SCORE_MAX; return 0; @@ -141,13 +76,10 @@ static int jpegxl_anim_read_header(AVFormatContext *s) JXLAnimDemuxContext *ctx = s->priv_data; AVIOContext *pb = s->pb; AVStream *st; - int offset = 0; uint8_t head[256 + AV_INPUT_BUFFER_PADDING_SIZE]; const int sizeofhead = sizeof(head) - AV_INPUT_BUFFER_PADDING_SIZE; - int headsize = 0; - int ctrl; - AVRational tb; - GetBitContext gbi, *gb = &gbi; + int headsize = 0, ret; + FFJXLMetadata meta = { 0 }; uint64_t sig16 = avio_rl16(pb); if (sig16 == FF_JPEGXL_CODESTREAM_SIGNATURE_LE) { @@ -167,7 +99,7 @@ static int jpegxl_anim_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; avio_skip(pb, 2); // first box always 12 bytes while (1) { - int copied; + int copied = 0; uint8_t buf[4096]; int read = avio_read(pb, buf, sizeof(buf)); if (read < 0) @@ -183,7 +115,7 @@ static int jpegxl_anim_read_header(AVFormatContext *s) if (av_buffer_realloc(&ctx->initial, ctx->initial->size + read) < 0) return AVERROR(ENOMEM); } - jpegxl_collect_codestream_header(buf, read, head + headsize, sizeofhead - headsize, &copied); + ff_jpegxl_collect_codestream_header(buf, read, head + headsize, sizeofhead - headsize, &copied); memcpy(ctx->initial->data + (ctx->initial->size - read), buf, read); headsize += copied; if (headsize >= sizeofhead || read < sizeof(buf)) @@ -191,12 +123,9 @@ static int jpegxl_anim_read_header(AVFormatContext *s) } } /* offset in bits of the animation header */ - offset = ff_jpegxl_verify_codestream_header(head, headsize, 0); - if (offset <= 0) - return AVERROR_INVALIDDATA; - if (init_get_bits8(gb, head, headsize) < 0) + ret = ff_jpegxl_parse_codestream_header(head, headsize, 0, &meta); + if (ret < 0 || meta.animation_offset <= 0) return AVERROR_INVALIDDATA; - skip_bits_long(gb, offset); st = avformat_new_stream(s, NULL); if (!st) @@ -204,11 +133,8 @@ static int jpegxl_anim_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_JPEGXL; - ctrl = get_bits(gb, 2); - tb.den = (const uint32_t[]){100, 1000, 1, 1}[ctrl] + get_bits_long(gb, (const uint32_t[]){0, 0, 10, 30}[ctrl]); - ctrl = get_bits(gb, 2); - tb.num = (const uint32_t[]){1, 1001, 1, 1}[ctrl] + get_bits_long(gb, (const uint32_t[]){0, 0, 8, 10}[ctrl]); - avpriv_set_pts_info(st, 1, tb.num, tb.den); + avpriv_set_pts_info(st, 1, meta.timebase.num, meta.timebase.den); + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; return 0; } @@ -265,7 +191,7 @@ const AVInputFormat ff_jpegxl_anim_demuxer = { .read_packet = jpegxl_anim_read_packet, .read_close = jpegxl_anim_close, .flags_internal = FF_FMT_INIT_CLEANUP, - .flags = AVFMT_GENERIC_INDEX, + .flags = AVFMT_GENERIC_INDEX | AVFMT_NOTIMESTAMPS, .mime_type = "image/jxl", .extensions = "jxl", }; diff --git a/libavformat/jpegxl_probe.h b/libavformat/jpegxl_parse.c similarity index 55% rename from libavformat/jpegxl_probe.h rename to libavformat/jpegxl_parse.c index 496445fbce..1be5fd716f 100644 --- a/libavformat/jpegxl_probe.h +++ b/libavformat/jpegxl_parse.c @@ -1,6 +1,6 @@ /* - * Jpeg XL header verification - * Copyright (c) 2022 Leo Izen + * JPEG XL Header Parser + * Copyright (c) 2023 Leo Izen * * This file is part of FFmpeg. * @@ -19,19 +19,4 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVFORMAT_JPEGXL_PROBE_H -#define AVFORMAT_JPEGXL_PROBE_H - -#include - -#define FF_JPEGXL_CODESTREAM_SIGNATURE_LE 0x0aff -#define FF_JPEGXL_CONTAINER_SIGNATURE_LE 0x204c584a0c000000 - -/** - * @brief verify that a codestream header is valid - * @return Negative upon error, 0 upon verifying that the codestream is not animated, - * and 1 upon verifying that it is animated - */ -int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int validate_level); - -#endif /* AVFORMAT_JPEGXL_PROBE_H */ + #include "libavcodec/jpegxl_parse.c" diff --git a/libavformat/jpegxl_probe.c b/libavformat/jpegxl_probe.c deleted file mode 100644 index 88492cb772..0000000000 --- a/libavformat/jpegxl_probe.c +++ /dev/null @@ -1,412 +0,0 @@ -/* - * Jpeg XL header verification - * Copyright (c) 2022 Leo Izen - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "jpegxl_probe.h" - -#define UNCHECKED_BITSTREAM_READER 0 -#define BITSTREAM_READER_LE -#include "libavcodec/get_bits.h" - -enum JpegXLExtraChannelType { - FF_JPEGXL_CT_ALPHA = 0, - FF_JPEGXL_CT_DEPTH, - FF_JPEGXL_CT_SPOT_COLOR, - FF_JPEGXL_CT_SELECTION_MASK, - FF_JPEGXL_CT_BLACK, - FF_JPEGXL_CT_CFA, - FF_JPEGXL_CT_THERMAL, - FF_JPEGXL_CT_NON_OPTIONAL = 15, - FF_JPEGXL_CT_OPTIONAL -}; - -enum JpegXLColorSpace { - FF_JPEGXL_CS_RGB = 0, - FF_JPEGXL_CS_GRAY, - FF_JPEGXL_CS_XYB, - FF_JPEGXL_CS_UNKNOWN -}; - -enum JpegXLWhitePoint { - FF_JPEGXL_WP_D65 = 1, - FF_JPEGXL_WP_CUSTOM, - FF_JPEGXL_WP_E = 10, - FF_JPEGXL_WP_DCI = 11 -}; - -enum JpegXLPrimaries { - FF_JPEGXL_PR_SRGB = 1, - FF_JPEGXL_PR_CUSTOM, - FF_JPEGXL_PR_2100 = 9, - FF_JPEGXL_PR_P3 = 11, -}; - -/* read a U32(c_i + u(u_i)) */ -static av_always_inline uint32_t jxl_u32(GetBitContext *gb, - uint32_t c0, uint32_t c1, uint32_t c2, uint32_t c3, - uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3) -{ - const uint32_t constants[4] = {c0, c1, c2, c3}; - const uint32_t ubits [4] = {u0, u1, u2, u3}; - uint32_t ret, choice = get_bits(gb, 2); - - ret = constants[choice]; - if (ubits[choice]) - ret += get_bits_long(gb, ubits[choice]); - - return ret; -} - -static av_always_inline uint32_t jxl_enum(GetBitContext *gb) -{ - return jxl_u32(gb, 0, 1, 2, 18, 0, 0, 4, 6); -} - -/* read a U64() */ -static uint64_t jpegxl_u64(GetBitContext *gb) -{ - uint64_t shift = 12, ret; - - switch (get_bits(gb, 2)) { - case 0: - ret = 0; - break; - case 1: - ret = 1 + get_bits(gb, 4); - break; - case 2: - ret = 17 + get_bits(gb, 8); - break; - case 3: - ret = get_bits(gb, 12); - while (get_bits1(gb)) { - if (shift < 60) { - ret |= (uint64_t)get_bits(gb, 8) << shift; - shift += 8; - } else { - ret |= (uint64_t)get_bits(gb, 4) << shift; - break; - } - } - break; - } - - return ret; -} - -static uint32_t jpegxl_width_from_ratio(uint32_t height, int ratio) -{ - uint64_t height64 = height; /* avoid integer overflow */ - switch (ratio) { - case 1: - return height; - case 2: - return (uint32_t)((height64 * 12) / 10); - case 3: - return (uint32_t)((height64 * 4) / 3); - case 4: - return (uint32_t)((height64 * 3) / 2); - case 5: - return (uint32_t)((height64 * 16) / 9); - case 6: - return (uint32_t)((height64 * 5) / 4); - case 7: - return (uint32_t)(height64 * 2); - default: - break; - } - - return 0; /* manual width */ -} - -/** - * validate a Jpeg XL Size Header - * @return >= 0 upon valid size, < 0 upon invalid size found - */ -static int jpegxl_read_size_header(GetBitContext *gb) -{ - uint32_t width, height; - - if (get_bits1(gb)) { - /* small size header */ - height = (get_bits(gb, 5) + 1) << 3; - width = jpegxl_width_from_ratio(height, get_bits(gb, 3)); - if (!width) - width = (get_bits(gb, 5) + 1) << 3; - } else { - /* large size header */ - height = 1 + jxl_u32(gb, 0, 0, 0, 0, 9, 13, 18, 30); - width = jpegxl_width_from_ratio(height, get_bits(gb, 3)); - if (!width) - width = 1 + jxl_u32(gb, 0, 0, 0, 0, 9, 13, 18, 30); - } - if (width > (1 << 18) || height > (1 << 18) - || (width >> 4) * (height >> 4) > (1 << 20)) - return -1; - - return 0; -} - -/** - * validate a Jpeg XL Preview Header - * @return >= 0 upon valid size, < 0 upon invalid size found - */ -static int jpegxl_read_preview_header(GetBitContext *gb) -{ - uint32_t width, height; - - if (get_bits1(gb)) { - /* coded height and width divided by eight */ - height = jxl_u32(gb, 16, 32, 1, 33, 0, 0, 5, 9) << 3; - width = jpegxl_width_from_ratio(height, get_bits(gb, 3)); - if (!width) - width = jxl_u32(gb, 16, 32, 1, 33, 0, 0, 5, 9) << 3; - } else { - /* full height and width coded */ - height = jxl_u32(gb, 1, 65, 321, 1345, 6, 8, 10, 12); - width = jpegxl_width_from_ratio(height, get_bits(gb, 3)); - if (!width) - width = jxl_u32(gb, 1, 65, 321, 1345, 6, 8, 10, 12); - } - if (width > 4096 || height > 4096) - return -1; - - return 0; -} - -/** - * skip a Jpeg XL BitDepth Header. These cannot be invalid. - */ -static void jpegxl_skip_bit_depth(GetBitContext *gb) -{ - if (get_bits1(gb)) { - /* float samples */ - jxl_u32(gb, 32, 16, 24, 1, 0, 0, 0, 6); /* mantissa */ - skip_bits_long(gb, 4); /* exponent */ - } else { - /* integer samples */ - jxl_u32(gb, 8, 10, 12, 1, 0, 0, 0, 6); - } -} - -/** - * validate a Jpeg XL Extra Channel Info bundle - * @return >= 0 upon valid, < 0 upon invalid - */ -static int jpegxl_read_extra_channel_info(GetBitContext *gb, int validate_level) -{ - int all_default = get_bits1(gb); - uint32_t type, name_len = 0; - - if (!all_default) { - type = jxl_enum(gb); - if (type > 63) - return -1; /* enum types cannot be 64+ */ - if (type == FF_JPEGXL_CT_BLACK && validate_level) - return -1; - jpegxl_skip_bit_depth(gb); - jxl_u32(gb, 0, 3, 4, 1, 0, 0, 0, 3); /* dim-shift */ - /* max of name_len is 1071 = 48 + 2^10 - 1 */ - name_len = jxl_u32(gb, 0, 0, 16, 48, 0, 4, 5, 10); - } else { - type = FF_JPEGXL_CT_ALPHA; - } - - /* skip over the name */ - skip_bits_long(gb, 8 * name_len); - - if (!all_default && type == FF_JPEGXL_CT_ALPHA) - skip_bits1(gb); - - if (type == FF_JPEGXL_CT_SPOT_COLOR) - skip_bits_long(gb, 16 * 4); - - if (type == FF_JPEGXL_CT_CFA) - jxl_u32(gb, 1, 0, 3, 19, 0, 2, 4, 8); - - return 0; -} - -int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int validate_level) -{ - GetBitContext gbi, *gb = &gbi; - int all_default, extra_fields = 0; - int xyb_encoded = 1, have_icc_profile = 0; - int animation_offset = 0; - uint32_t num_extra_channels; - uint64_t extensions; - int ret; - - ret = init_get_bits8(gb, buf, buflen); - if (ret < 0) - return ret; - - if (get_bits_long(gb, 16) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE) - return -1; - - if ((ret = jpegxl_read_size_header(gb)) < 0 && validate_level) - return ret; - - all_default = get_bits1(gb); - if (!all_default) - extra_fields = get_bits1(gb); - - if (extra_fields) { - skip_bits_long(gb, 3); /* orientation */ - - /* - * intrinstic size - * any size header here is valid, but as it - * is variable length we have to read it - */ - if (get_bits1(gb)) - jpegxl_read_size_header(gb); - - /* preview header */ - if (get_bits1(gb)) { - ret = jpegxl_read_preview_header(gb); - if (ret < 0) - return ret; - } - - /* animation header */ - if (get_bits1(gb)) { - animation_offset = get_bits_count(gb); - jxl_u32(gb, 100, 1000, 1, 1, 0, 0, 10, 30); - jxl_u32(gb, 1, 1001, 1, 1, 0, 0, 8, 10); - jxl_u32(gb, 0, 0, 0, 0, 0, 3, 16, 32); - skip_bits_long(gb, 1); - } - } - if (get_bits_left(gb) < 1) - return AVERROR_INVALIDDATA; - - if (!all_default) { - jpegxl_skip_bit_depth(gb); - - /* modular_16bit_buffers must equal 1 */ - if (!get_bits1(gb) && validate_level) - return -1; - - num_extra_channels = jxl_u32(gb, 0, 1, 2, 1, 0, 0, 4, 12); - if (num_extra_channels > 4 && validate_level) - return -1; - for (uint32_t i = 0; i < num_extra_channels; i++) { - ret = jpegxl_read_extra_channel_info(gb, validate_level); - if (ret < 0) - return ret; - if (get_bits_left(gb) < 1) - return AVERROR_INVALIDDATA; - } - - xyb_encoded = get_bits1(gb); - - /* color encoding bundle */ - if (!get_bits1(gb)) { - uint32_t color_space; - have_icc_profile = get_bits1(gb); - color_space = jxl_enum(gb); - if (color_space > 63) - return -1; - - if (!have_icc_profile) { - if (color_space != FF_JPEGXL_CS_XYB) { - uint32_t white_point = jxl_enum(gb); - if (white_point > 63) - return -1; - if (white_point == FF_JPEGXL_WP_CUSTOM) { - /* ux and uy values */ - jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21); - jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21); - } - if (color_space != FF_JPEGXL_CS_GRAY) { - /* primaries */ - uint32_t primaries = jxl_enum(gb); - if (primaries > 63) - return -1; - if (primaries == FF_JPEGXL_PR_CUSTOM) { - /* ux/uy values for r,g,b */ - for (int i = 0; i < 6; i++) { - jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21); - if (get_bits_left(gb) < 1) - return AVERROR_INVALIDDATA; - } - } - } - } - - /* transfer characteristics */ - if (get_bits1(gb)) { - /* gamma */ - skip_bits_long(gb, 24); - } else { - /* transfer function */ - if (jxl_enum(gb) > 63) - return -1; - } - - /* rendering intent */ - if (jxl_enum(gb) > 63) - return -1; - } - } - - /* tone mapping bundle */ - if (extra_fields && !get_bits1(gb)) - skip_bits_long(gb, 16 + 16 + 1 + 16); - - extensions = jpegxl_u64(gb); - if (get_bits_left(gb) < 1) - return AVERROR_INVALIDDATA; - if (extensions) { - for (int i = 0; i < 64; i++) { - if (extensions & (UINT64_C(1) << i)) - jpegxl_u64(gb); - if (get_bits_left(gb) < 1) - return AVERROR_INVALIDDATA; - } - } - } - - /* default transform */ - if (!get_bits1(gb)) { - /* opsin inverse matrix */ - if (xyb_encoded && !get_bits1(gb)) - skip_bits_long(gb, 16 * 16); - /* cw_mask and default weights */ - if (get_bits1(gb)) - skip_bits_long(gb, 16 * 15); - if (get_bits1(gb)) - skip_bits_long(gb, 16 * 55); - if (get_bits1(gb)) - skip_bits_long(gb, 16 * 210); - } - - if (!have_icc_profile) { - int bits_remaining = 7 - (get_bits_count(gb) - 1) % 8; - if (bits_remaining && get_bits(gb, bits_remaining)) - return -1; - } - - if (get_bits_left(gb) < 0) - return -1; - - return animation_offset; -} From patchwork Sat Jun 24 04:38:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 42290 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:be15:b0:121:b37c:e101 with SMTP id ge21csp4053817pzb; Fri, 23 Jun 2023 21:39:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5QBnL+w+BNbD2eX/6D8gnr2G5YAEVTzHhixVOKYRITuxfPe4xlToMwQnUIry5DKnJ2CtKP X-Received: by 2002:a17:907:9453:b0:987:47b3:6e34 with SMTP id dl19-20020a170907945300b0098747b36e34mr16796157ejc.67.1687581579203; Fri, 23 Jun 2023 21:39:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687581579; cv=none; d=google.com; s=arc-20160816; b=Z5MmsN/OdxDsMfNih//SZn3h7v+dN8fkPhhmxvNuGvgD3AmOb/1al0YiUPP0is2YNg PvSjnAAHpdVDTQwd/xyg2T8QiUFOZDG9tOy/jTM2O9m8h+0sxeS2XQBMLTwEfMlBWJ6Z Z28E+EWLSmGBXRTQ9VgSvNRG8u2f4ylb4UPtQMoNt7KpkY80V9rpYgqDYjlJuwLr5uCJ 7vbumzOKz1DPDBuh6qpemoQaoxApaAUxC4rRQ8EyWyuoSkwI/xKyntke3HN6B2Evvgd8 aOSipinxcSjNb4/PRC2xJDn1m5gTmh9cDjyxHrBvCksuwVfW2fmD8IOnOb3OHDY0II+K LOCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=hh/3nPhmIwsxdWN3zcl4QCn72x1EOFQ8MQo0rd6sfLM=; fh=+bdjGe20eEUjtjncwA1dnEEVYNfJL4vyhV+sIRR4l+g=; b=P9wzuKWtllUWedxjwsl9Yy5FxcwlGInXFrCqeKUp52190nV2+HW6zuE3Ywbztp0DEd KsZwQla1BkhF7Xga/erLPKiX7kbmEDM9wf/G1B5rGEUi4y0pD9/tgCBAuyu0pT9EEyba mfz0WecvxVZnSk/FHtA3yWAwve1L1Qv14KMpun6ENy4xsP7RehAzln2Nsj8d7wsxAC5u aAyGIaHBBVM0M18cyAfrtImjB0cPWonH1XYGE0IROVJRhxKGMnYJ12kgrHGTXNQ4Fs9Q vegI+wgYXyml9UFOdyuhWY7vLC8QFOfGHXwxyV/4tSqeH29Fnzh73Yx6FWDXJJh4+jBf pOaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=BMOQUg2P; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id bt24-20020a170906b15800b0098879dbe312si393499ejb.431.2023.06.23.21.39.38; Fri, 23 Jun 2023 21:39:39 -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=@gmail.com header.s=20221208 header.b=BMOQUg2P; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B7D4A68C1E8; Sat, 24 Jun 2023 07:39:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 47C3B68C02C for ; Sat, 24 Jun 2023 07:38:59 +0300 (EEST) Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-7654ba0c914so22803185a.0 for ; Fri, 23 Jun 2023 21:38:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687581538; x=1690173538; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7t9rrIe1f8nURz3Y2dGVNkj+qFCb/9hTfOC8G2hZ99E=; b=BMOQUg2PSoS7kQtNbTxqS6xYg2varRguqyBYtZL02JPhKaeBeppGq4PPO9jkKjD4lR HvaHE717xZehAk/FSNAIsuTFGDmiPFmR9Kg9m9wKkHk0R8I+xUNkpVO+4FAVBwt1vkGa en7N155Q9oLD4QtXs3SFZ1rfN0+u5dnZuvNEmQUbL7Xg487nytkDh0eIr5T/uS6XlkFf 4bUfTUKK24ykg8LrQxfzQQ0/xlX1Exsn6+E/BJKht/qDxGeyHtAqfAKtE5tUcom1Uice Fy6/I9p0yDU1R4Dm2fak3FO4GT5ZBrD3Ja7gCcHLJDoUs0Qc3QFQHp6vim9021IcoFR8 Diyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687581538; x=1690173538; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7t9rrIe1f8nURz3Y2dGVNkj+qFCb/9hTfOC8G2hZ99E=; b=EyemN0tojP/XqsDREmy4Ux4pOtjji4IpXAA1s5gzt2WaW9xjEF8XC0Fnz31zKBHvcJ Xyd4r2LBzAcOqQsSMmQMxp6PkxLeY8dYFtYz33YKr4SPvQqYqmPipm1tAc7eeoJOrmF+ Z6JGZVhOr8Hk2KbukRDi7SH5ecTADBnVSyAoOq5WOG45VNXVjsLkjm3ZUaBPck8JdUw4 z/riJUs2bY3Xf7lAAC7FGWtnObgaay4XQodnZdA29LqNRag5xjDp8OBkIrp7neqo523x Uaoh+QpD/HddrXerUQ4/N1GQd1+rd9WPwcbAHA1Yh8IlA05adZUEP/vbP7Wxw2va1Jsh LOeQ== X-Gm-Message-State: AC+VfDzugJxTLHysnZ0y8hqasiHMQSCoUYoSE20wW9RbORDRQnSNV7gf FlcoyHFdWiNSDiAWZ/OacoZoRwz7utQ= X-Received: by 2002:a05:620a:4086:b0:765:57dc:7ec6 with SMTP id f6-20020a05620a408600b0076557dc7ec6mr2447260qko.3.1687581537969; Fri, 23 Jun 2023 21:38:57 -0700 (PDT) Received: from gauss.local (c-98-224-219-15.hsd1.mi.comcast.net. [98.224.219.15]) by smtp.gmail.com with ESMTPSA id m11-20020a0dca0b000000b0055aafcef659sm173719ywd.5.2023.06.23.21.38.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 21:38:57 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Jun 2023 00:38:53 -0400 Message-ID: <20230624043853.12237-5-leo.izen@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230624043853.12237-1-leo.izen@gmail.com> References: <20230624043853.12237-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 4/4] fate/jpegxl_anim: add demuxer fate test for jpegxl_anim X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Leo Izen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: HgmMsnYO0oaA Adds a fate test for the jpegxl_anim demuxer, that should allow testing for true positives and false positives for animated jpegxl files. Note that two of the test cases are not animated, in order to help sort out false positives. Signed-off-by: --- tests/Makefile | 1 + tests/fate/jxl.mak | 16 ++++++++++++++++ tests/ref/fate/jxl-anim-demux-belgium | 6 ++++++ tests/ref/fate/jxl-anim-demux-icos4d | 6 ++++++ tests/ref/fate/jxl-anim-demux-lenna256 | 7 +++++++ tests/ref/fate/jxl-anim-demux-newton | 6 ++++++ 6 files changed, 42 insertions(+) create mode 100644 tests/fate/jxl.mak create mode 100644 tests/ref/fate/jxl-anim-demux-belgium create mode 100644 tests/ref/fate/jxl-anim-demux-icos4d create mode 100644 tests/ref/fate/jxl-anim-demux-lenna256 create mode 100644 tests/ref/fate/jxl-anim-demux-newton diff --git a/tests/Makefile b/tests/Makefile index e09f30a0fc..7b80762e81 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -201,6 +201,7 @@ include $(SRC_PATH)/tests/fate/image.mak include $(SRC_PATH)/tests/fate/imf.mak include $(SRC_PATH)/tests/fate/indeo.mak include $(SRC_PATH)/tests/fate/jpeg2000.mak +include $(SRC_PATH)/tests/fate/jxl.mak include $(SRC_PATH)/tests/fate/libavcodec.mak include $(SRC_PATH)/tests/fate/libavdevice.mak include $(SRC_PATH)/tests/fate/libavformat.mak diff --git a/tests/fate/jxl.mak b/tests/fate/jxl.mak new file mode 100644 index 0000000000..057d3be0e1 --- /dev/null +++ b/tests/fate/jxl.mak @@ -0,0 +1,16 @@ +# These two are animated JXL files +FATE_JPEGXL_ANIM_DEMUX += fate-jxl-anim-demux-newton +fate-jxl-anim-demux-newton: CMD = framecrc -i $(TARGET_SAMPLES)/jxl/newton.jxl -c copy +FATE_JPEGXL_ANIM_DEMUX += fate-jxl-anim-demux-icos4d +fate-jxl-anim-demux-icos4d: CMD = framecrc -i $(TARGET_SAMPLES)/jxl/icos4d.jxl -c copy + +# These two are not animated JXL. They are here to check false positives. +FATE_JPEGXL_ANIM_DEMUX += fate-jxl-anim-demux-belgium +fate-jxl-anim-demux-belgium: CMD = framecrc -i $(TARGET_SAMPLES)/jxl/belgium.jxl -c copy +FATE_JPEGXL_ANIM_DEMUX += fate-jxl-anim-demux-lenna256 +fate-jxl-anim-demux-lenna256: CMD = framecrc -i $(TARGET_SAMPLES)/jxl/lenna-256.jxl -c copy + +FATE_JPEGXL_ANIM_DEMUX += $(FATE_JPEGXL_ANIM_DEMUX-yes) + +FATE_SAMPLES_FFMPEG-$(call FRAMECRC, JPEGXL_ANIM) += $(FATE_JPEGXL_ANIM_DEMUX) +fate-jxl-anim-demux: $(FATE_JPEGXL_ANIM_DEMUX) diff --git a/tests/ref/fate/jxl-anim-demux-belgium b/tests/ref/fate/jxl-anim-demux-belgium new file mode 100644 index 0000000000..b2fe5035ac --- /dev/null +++ b/tests/ref/fate/jxl-anim-demux-belgium @@ -0,0 +1,6 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: jpegxl +#dimensions 0: 768x512 +#sar 0: 0/1 +0, 0, 0, 1, 32, 0xa2930a20 diff --git a/tests/ref/fate/jxl-anim-demux-icos4d b/tests/ref/fate/jxl-anim-demux-icos4d new file mode 100644 index 0000000000..eff6ff1f1b --- /dev/null +++ b/tests/ref/fate/jxl-anim-demux-icos4d @@ -0,0 +1,6 @@ +#tb 0: 1/1000 +#media_type 0: video +#codec_id 0: jpegxl +#dimensions 0: 48x48 +#sar 0: 0/1 +0, 0, 0, 0, 67898, 0x53b6516b diff --git a/tests/ref/fate/jxl-anim-demux-lenna256 b/tests/ref/fate/jxl-anim-demux-lenna256 new file mode 100644 index 0000000000..0bd286a451 --- /dev/null +++ b/tests/ref/fate/jxl-anim-demux-lenna256 @@ -0,0 +1,7 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: jpegxl +#dimensions 0: 256x256 +#sar 0: 0/1 +0, 0, 0, 1, 4096, 0x2409e9e3 +0, 1, 1, 1, 3992, 0x966dbfcb diff --git a/tests/ref/fate/jxl-anim-demux-newton b/tests/ref/fate/jxl-anim-demux-newton new file mode 100644 index 0000000000..6fcb85c41e --- /dev/null +++ b/tests/ref/fate/jxl-anim-demux-newton @@ -0,0 +1,6 @@ +#tb 0: 1/1000 +#media_type 0: video +#codec_id 0: jpegxl +#dimensions 0: 128x96 +#sar 0: 0/1 +0, 0, 0, 0, 43376, 0xb2296182