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 51D8945D3F for ; Thu, 6 Apr 2023 16:47:59 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 988F368BE0C; Thu, 6 Apr 2023 19:47:55 +0300 (EEST) Received: from out203-205-221-191.mail.qq.com (out203-205-221-191.mail.qq.com [203.205.221.191]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8C7B568BE02 for ; Thu, 6 Apr 2023 19:47:47 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1680799659; bh=5IWeJo8YpfBloIIYCmPiXas9bzdJXlzDWGyTC8pFyBo=; h=Subject:From:To:Date:In-Reply-To:References; b=OfS0TPUTjaWPUQdEsdtgrPffhNY+AEVUnKFSSrxSHnXhqXMdTdZsNAAJibXFc28ws Xs6huLE9xvTq13S1SZlPeHmukmxwjWXw5ymPM0hRjqphMFXpBkVE8DgFAkdzYDhR1b 8TCCSZFpn/KgWQVAkQx2mnHu4koFMNYPG3PtTk+Q= Received: from [127.0.0.1] ([113.118.114.37]) by newxmesmtplogicsvrszb6-0.qq.com (NewEsmtp) with SMTP id BE6284C6; Fri, 07 Apr 2023 00:47:38 +0800 X-QQ-mid: xmsmtpt1680799658tnem93wvn Message-ID: X-QQ-XMAILINFO: NJ/+omVLhVga60E0KiHTz0BziHmT9nWK38GSf5HPHMfXXV5TLWt5fHzGo8+57a ciFfsLnAylhmXmLevtupK5weJOuhZR3rvrmepnwKCOJUQGZB9usz3a1zP0K0o1wda02++wQnJlgw bZgGsBco8OLOA90mE12QTUsAExKqcyrj8zJNLm65NQT0jHUQR5FkwEZCc/+qK9LPfEuDmdrAUkQ1 RLyF65wtciJ5otRfons6Wv4gbBJgK4afBvui2C9tC6Q1137jD2rajQZvTS9jFacM8p1VOI9AKTCA UnpiIBY+e5uGPY5e83Jhitqd1QUNLUKxRr3p4X0aeRGNTx6EIRQsnmMOhFbXT9aqsMTKYhKm7BKp gbH3MMf9fpLJCmyD4CiZUSBycRvtLieFzcIvjGZH9kZkYq1F8u47lDIuY2v9Vg82SU3q2Z3YRukK kxdlUKdnTneDe0uiwTq7XyAqUxE0w3THajbR5bCOUczxBqqCN/zdxq+bscXvoB1ehCfoLswK4LKn lqvDNoQSnry54i/YI90v4g48umdNpxgNjMvexIzOIudqY4/3RTnK8uBSdBI602gx/KCQd3+/XgAg dnapQrIQFUEHWKfq7TZk7sNcU/MIdvVsR/NxQQJbxn5kKbzckML7ttFSTc7shU6KUXCHr677iV6k 2AgxNizR30rHAKP+g8k2KQt4Ivn+FRAjM1Qo9QPBsaRvEG2zoHin4fIF0SHJpw8IWUheyylm8GV6 21tJ4i66lTE19FaHX/ScBn//CwizhYiravTXy8Ck2Ab+K+zy3lT12I6StBDhpubqRD4SYjlYPMRp 9rO9ttajJSZ/S5S/N85hpTUwPS01+Oc6vdWgNzzpwOojRqvVT2PALM1lKLVC/kRSxICGD0bKTfot nFacpx+eXn/jPyq5JH69yEt7HorIwE4SzuKwE/WarnwoiCkZAfQiKPBE4I87l2+CbV/4rOQ28WZ8 YmgqP2ZXxVIhmGfvLS1ZQEcIOMSqhoT9TyLMmXymE= X-OQ-MSGID: <780bcd590bf3155fd546554f72a30efde5af2a6d.camel@foxmail.com> From: Zhao Zhili To: James Almer , ffmpeg-devel@ffmpeg.org Date: Fri, 07 Apr 2023 00:47:38 +0800 In-Reply-To: <50bdb166-9799-e0af-c79b-6b2b93288470@gmail.com> References: <50bdb166-9799-e0af-c79b-6b2b93288470@gmail.com> User-Agent: Evolution 3.44.4-0ubuntu1 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH] avformat/flvenc: avoid an extra allocate 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: On Thu, 2023-04-06 at 11:25 -0300, James Almer wrote: > On 4/6/2023 5:11 PM, Zhao Zhili wrote: > > From: Zhao Zhili > > > > --- > > libavformat/flvenc.c | 24 +++++++----------------- > > 1 file changed, 7 insertions(+), 17 deletions(-) > > > > diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c > > index a7b5efde4b..3a686b73d7 100644 > > --- a/libavformat/flvenc.c > > +++ b/libavformat/flvenc.c > > @@ -117,12 +117,9 @@ typedef struct FLVContext { > > AVCodecParameters *data_par; > > > > int flags; > > + uint32_t last_ts[3]; > > I understand that timestamps are 32bit on flv, but things are pretty > inconsistent type wise across the entire file. This used to be int64_t > and you're changing it to uint32_t. Some parameters expect an unsigned > int and others an int64_t. It would be nice to choose a single type and > use it everywhere. > The source for all of them is apparently pkt->dts, which is int64_t, so > I'd use that everywhere and ensure its value is <= INT32_MAX or <= > UINT32_MAX depending on how you store it. I can change it to int64_t. It worths to note that all usecases of it are unsigned (the type of 'ts', the prototype of put_eos_tag()). > > > } FLVContext; > > > > -typedef struct FLVStreamContext { > > - int64_t last_ts; ///< last timestamp for each stream > > -} FLVStreamContext; > > - > > static int get_audio_flags(AVFormatContext *s, AVCodecParameters *par) > > { > > int flags = (par->bits_per_coded_sample == 16) ? FLV_SAMPLESSIZE_16BIT > > @@ -611,7 +608,7 @@ static int flv_init(struct AVFormatContext *s) > > > > for (i = 0; i < s->nb_streams; i++) { > > AVCodecParameters *par = s->streams[i]->codecpar; > > - FLVStreamContext *sc; > > + > > switch (par->codec_type) { > > case AVMEDIA_TYPE_VIDEO: > > if (s->streams[i]->avg_frame_rate.den && > > @@ -675,12 +672,7 @@ static int flv_init(struct AVFormatContext *s) > > return AVERROR(EINVAL); > > } > > avpriv_set_pts_info(s->streams[i], 32, 1, 1000); /* 32 bit pts in ms */ > > - > > - sc = av_mallocz(sizeof(FLVStreamContext)); > > - if (!sc) > > - return AVERROR(ENOMEM); > > - s->streams[i]->priv_data = sc; > > - sc->last_ts = -1; > > + flv->last_ts[i] = -1; > > } > > > > flv->delay = AV_NOPTS_VALUE; > > @@ -783,10 +775,9 @@ end: > > /* Add EOS tag */ > > for (i = 0; i < s->nb_streams; i++) { > > AVCodecParameters *par = s->streams[i]->codecpar; > > - FLVStreamContext *sc = s->streams[i]->priv_data; > > if (par->codec_type == AVMEDIA_TYPE_VIDEO && > > (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4)) > > - put_eos_tag(pb, sc->last_ts, par->codec_id); > > + put_eos_tag(pb, flv->last_ts[i], par->codec_id); > > } > > } > > > > @@ -821,7 +812,6 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) > > AVIOContext *pb = s->pb; > > AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; > > FLVContext *flv = s->priv_data; > > - FLVStreamContext *sc = s->streams[pkt->stream_index]->priv_data; > > unsigned ts; > > int size = pkt->size; > > uint8_t *data = NULL; > > @@ -919,13 +909,13 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) > > } > > > > /* check Speex packet duration */ > > - if (par->codec_id == AV_CODEC_ID_SPEEX && ts - sc->last_ts > 160) > > + if (par->codec_id == AV_CODEC_ID_SPEEX && ts - flv->last_ts[pkt->stream_index] > 160) > > av_log(s, AV_LOG_WARNING, "Warning: Speex stream has more than " > > "8 frames per packet. Adobe Flash " > > "Player cannot handle this!\n"); > > > > - if (sc->last_ts < ts) > > - sc->last_ts = ts; > > + if (flv->last_ts[pkt->stream_index] < ts) > > + flv->last_ts[pkt->stream_index] = ts; > > > > if (size + flags_size >= 1<<24) { > > av_log(s, AV_LOG_ERROR, "Too large packet with size %u >= %u\n", > _______________________________________________ > 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". _______________________________________________ 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".