From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id C7F8747CF0 for ; Wed, 18 Oct 2023 14:42:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A015968CA60; Wed, 18 Oct 2023 17:42:15 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 059A368C9E2 for ; Wed, 18 Oct 2023 17:42:10 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 842A5240498 for ; Wed, 18 Oct 2023 16:42:09 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id JzJsktt61zHO for ; Wed, 18 Oct 2023 16:42:09 +0200 (CEST) Received: from lain.khirnov.net (lain.khirnov.net [IPv6:2001:67c:1138:4306::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "lain.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 0CEC72400FF for ; Wed, 18 Oct 2023 16:42:09 +0200 (CEST) Received: by lain.khirnov.net (Postfix, from userid 1000) id F29DA1601B9; Wed, 18 Oct 2023 16:42:01 +0200 (CEST) From: Anton Khirnov To: FFmpeg development discussions and patches In-Reply-To: <7504e36707a4deaddc61e489839637137f7db7e5.1697615459.git.pross@xvid.org> References: <04cb126b825dc1e39c3b4140af8813ddfd03dfdb.1697615459.git.pross@xvid.org> <7504e36707a4deaddc61e489839637137f7db7e5.1697615459.git.pross@xvid.org> Mail-Followup-To: FFmpeg development discussions and patches Date: Wed, 18 Oct 2023 16:42:01 +0200 Message-ID: <169764012197.32606.9720568022455222835@lain.khirnov.net> User-Agent: alot/0.8.1 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH 2/3] avcodec/rv60: RealVideo 6.0 decoder 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Quoting Peter Ross (2023-10-18 10:03:54) > +static int rv60_decode_frame(AVCodecContext *avctx, AVFrame * frame, > + int * got_frame, AVPacket * avpkt) > +{ > + RV60Context *s = avctx->priv_data; > + GetBitContext gb; > + int ret, header_size, width, height, ofs; > + > + if (avpkt->size == 0) { > + if (s->last_frame[NEXT_PIC]->data[0] && !s->got_last_frame_output) { > + if ((ret = av_frame_ref(frame, s->last_frame[NEXT_PIC])) < 0) > + return ret; > + s->got_last_frame_output = 1; > + *got_frame = 1; > + } I think you can simplify this into: if (s->last_frame[NEXT_PIC]->data[0]) { av_frame_move_ref(frame, s->last_frame[NEXT_PIC]); *got_frame = 1; } > + return 0; > + } > + > + if (avpkt->size < 9) > + return AVERROR_INVALIDDATA; > + > + header_size = avpkt->data[0] * 8 + 9; > + if (avpkt->size < header_size) > + return AVERROR_INVALIDDATA; > + > + init_get_bits8(&gb, avpkt->data + header_size, avpkt->size - header_size); > + > + if ((ret = read_frame_header(s, &gb, &width, &height)) < 0) > + return ret; > + > + if (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B || > + avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I || > + avctx->skip_frame >= AVDISCARD_ALL) > + return avpkt->size; > + > + if (s->pict_type != AV_PICTURE_TYPE_B) > + FFSWAP(AVFrame *, s->last_frame[NEXT_PIC], s->last_frame[LAST_PIC]); > + > + if ((s->pict_type == AV_PICTURE_TYPE_P && !s->last_frame[LAST_PIC]->data[0]) || > + (s->pict_type == AV_PICTURE_TYPE_B && (!s->last_frame[LAST_PIC]->data[0] || !s->last_frame[NEXT_PIC]->data[0]))) { > + av_log(s->avctx, AV_LOG_ERROR, "missing reference frame\n"); > + return AVERROR_INVALIDDATA; > + } > + > + av_frame_unref(s->last_frame[CUR_PIC]); > + > + s->last_frame[CUR_PIC]->pict_type = s->pict_type; > + if (s->pict_type == AV_PICTURE_TYPE_I) > + s->last_frame[CUR_PIC]->flags |= AV_FRAME_FLAG_KEY; > + > + if ((ret = update_dimensions_clear_info(s, width, height)) < 0) > + return ret; > + > + if ((ret = ff_reget_buffer(avctx, s->last_frame[CUR_PIC], 0)) < 0) You just unreffed the frame above, what is the point of using reget_buffer()? > + return ret; > + > + if ((ret = read_slice_sizes(s, &gb)) < 0) > + return ret; > + > + ofs = get_bits_count(&gb) / 8; > + > + for (int i = 0; i < s->cu_height; i++) { > + s->slice[i].data = avpkt->data + header_size + ofs; > + s->slice[i].data_size = FFMIN(s->slice[i].size, avpkt->size - header_size - ofs); > + ofs += s->slice[i].size; > + } > + > + if (ffcodec(avctx->codec)->update_thread_context) > + ff_thread_finish_setup(avctx); > + > + ret = ff_slice_thread_allocz_entries(s->avctx, s->cu_height); > + if (ret < 0) > + return ret; > + > + s->avctx->execute2(s->avctx, decode_slice, s->last_frame[CUR_PIC], NULL, s->cu_height); > + > + frame->pkt_dts = avpkt->dts; The generic code should be doing this already. > + > + ret = 0; > + if (s->pict_type == AV_PICTURE_TYPE_B) > + ret = av_frame_ref(frame, s->last_frame[CUR_PIC]); You could change this into av_frame_move_ref() and drop the unref below. > + else if (s->last_frame[LAST_PIC]->data[0]) > + ret = av_frame_ref(frame, s->last_frame[LAST_PIC]); > + if (ret < 0) > + return ret; > + > + if (s->last_frame[LAST_PIC]->data[0]) > + *got_frame = 1; > + > + if (s->pict_type != AV_PICTURE_TYPE_B) > + FFSWAP(AVFrame *, s->last_frame[CUR_PIC], s->last_frame[NEXT_PIC]); > + else > + av_frame_unref(s->last_frame[CUR_PIC]); > + > + if (s->pict_type != AV_PICTURE_TYPE_B) { > + s->ref_pts[0] = s->ref_pts[1]; > + s->ref_pts[1] = avpkt->pts; > + > + s->ref_ts[0] = s->ref_ts[1]; > + s->ref_ts[1] = s->ts; > + > + if (s->ref_pts[1] > s->ref_pts[0] && s->ref_ts[1] > s->ref_ts[0]) > + s->ts_scale = (s->ref_pts[1] - s->ref_pts[0]) / (s->ref_ts[1] - s->ref_ts[0]); > + } else { > + frame->pts = s->ref_pts[0] + (s->ts - s->ref_ts[0]) * s->ts_scale; This looks immensely evil. Isn't ff_get_buffer() already setting the timestamps correctly? -- Anton Khirnov _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".