[FFmpeg-devel] [PATCH] avutil/random_seed: turn off buffering when reading from urandom
Signed-off-by: Marton Balint --- libavutil/random_seed.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c index f167b172f2..6d399cee49 100644 --- a/libavutil/random_seed.c +++ b/libavutil/random_seed.c @@ -59,6 +59,7 @@ static int read_random(uint8_t *dst, size_t len, const char *file) if (!fp) return AVERROR_UNKNOWN; +setvbuf(fp, NULL, _IONBF, 0); err = fread(dst, 1, len, fp); fclose(fp); -- 2.35.3 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg: fix negative timestamps at the beginning of the encoding
On Tue, 4 Jul 2023, Marton Balint wrote: Also fix a couple of possible overflows while at it. Fixes the negative initial timestamps in ticket #10358. Will apply. Regards, Marton Signed-off-by: Marton Balint --- fftools/ffmpeg.c | 26 +- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 435e12a37b..71d4067a6c 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -497,11 +497,12 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti int vid; double bitrate; double speed; -int64_t pts = INT64_MIN + 1; +int64_t pts = AV_NOPTS_VALUE; static int64_t last_time = -1; static int first_report = 1; uint64_t nb_frames_dup = 0, nb_frames_drop = 0; -int hours, mins, secs, us; +int mins, secs, us; +int64_t hours; const char *hours_sign; int ret; float t; @@ -553,7 +554,8 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti } /* compute min output value */ if (ost->last_mux_dts != AV_NOPTS_VALUE) { -pts = FFMAX(pts, ost->last_mux_dts); +if (pts == AV_NOPTS_VALUE || ost->last_mux_dts > pts) +pts = ost->last_mux_dts; if (copy_ts) { if (copy_ts_first_pts == AV_NOPTS_VALUE && pts > 1) copy_ts_first_pts = pts; @@ -566,23 +568,21 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti nb_frames_drop += ost->last_dropped; } -secs = FFABS(pts) / AV_TIME_BASE; -us = FFABS(pts) % AV_TIME_BASE; -mins = secs / 60; -secs %= 60; -hours = mins / 60; -mins %= 60; +us= FFABS64U(pts) % AV_TIME_BASE; +secs = FFABS64U(pts) / AV_TIME_BASE % 60; +mins = FFABS64U(pts) / AV_TIME_BASE / 60 % 60; +hours = FFABS64U(pts) / AV_TIME_BASE / 3600; hours_sign = (pts < 0) ? "-" : ""; -bitrate = pts && total_size >= 0 ? total_size * 8 / (pts / 1000.0) : -1; -speed = t != 0.0 ? (double)pts / AV_TIME_BASE / t : -1; +bitrate = pts != AV_NOPTS_VALUE && pts && total_size >= 0 ? total_size * 8 / (pts / 1000.0) : -1; +speed = pts != AV_NOPTS_VALUE && t != 0.0 ? (double)pts / AV_TIME_BASE / t : -1; if (total_size < 0) av_bprintf(&buf, "size=N/A time="); elseav_bprintf(&buf, "size=%8.0fkB time=", total_size / 1024.0); if (pts == AV_NOPTS_VALUE) { av_bprintf(&buf, "N/A "); } else { -av_bprintf(&buf, "%s%02d:%02d:%02d.%02d ", +av_bprintf(&buf, "%s%02"PRId64":%02d:%02d.%02d ", hours_sign, hours, mins, secs, (100 * us) / AV_TIME_BASE); } @@ -603,7 +603,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti } else { av_bprintf(&buf_script, "out_time_us=%"PRId64"\n", pts); av_bprintf(&buf_script, "out_time_ms=%"PRId64"\n", pts); -av_bprintf(&buf_script, "out_time=%s%02d:%02d:%02d.%06d\n", +av_bprintf(&buf_script, "out_time=%s%02"PRId64":%02d:%02d.%06d\n", hours_sign, hours, mins, secs, us); } -- 2.35.3 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] lavfi/src_movie: stop using AV_CODEC_FLAG_COPY_OPAQUE
That feature is overkill for a constant pointer to AVFilterLink which can be stored in AVCodecContext.opaque (indirectly, because the link is not allocated yet at the time the codec is opened). This also avoid leaking non-NULL AVFrame.opaque to callers. --- libavfilter/src_movie.c | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c index f0d295d4bb..e50ebc99dc 100644 --- a/libavfilter/src_movie.c +++ b/libavfilter/src_movie.c @@ -51,6 +51,7 @@ #include "video.h" typedef struct MovieStream { +AVFilterLink *link; AVStream *st; AVCodecContext *codec_ctx; int64_t discontinuity_threshold; @@ -162,7 +163,8 @@ static AVStream *find_stream(void *log, AVFormatContext *avf, const char *spec) static int get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) { int linesize_align[AV_NUM_DATA_POINTERS]; -AVFilterLink *outlink = frame->opaque; +MovieStream *st = avctx->opaque; +AVFilterLink *outlink = st->link; int w, h, ow, oh, copy = 0; AVFrame *new; @@ -202,7 +204,6 @@ static int get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) av_frame_move_ref(frame, new); av_frame_free(&new); -frame->opaque = outlink; frame->width = ow; frame->height = oh; @@ -224,7 +225,7 @@ static int open_stream(AVFilterContext *ctx, MovieStream *st, int dec_threads) if (!st->codec_ctx) return AVERROR(ENOMEM); -st->codec_ctx->flags |= AV_CODEC_FLAG_COPY_OPAQUE; +st->codec_ctx->opaque = st; st->codec_ctx->get_buffer2 = get_buffer; ret = avcodec_parameters_to_context(st->codec_ctx, st->st->codecpar); if (ret < 0) @@ -469,6 +470,8 @@ static int movie_config_output_props(AVFilterLink *outlink) break; } +st->link = outlink; + return 0; } @@ -581,7 +584,6 @@ static int activate(AVFilterContext *ctx) movie->out_index[movie->pkt->stream_index]; if (pkt_out_id >= 0) { -movie->pkt->opaque = ctx->outputs[pkt_out_id]; ret = decode_packet(ctx, pkt_out_id); } av_packet_unref(movie->pkt); -- 2.40.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 1/3] avcodec/decode: move processing discard samples to its own function
Quoting James Almer (2023-07-08 21:00:36) > -/* > - * The core of the receive_frame_wrapper for the decoders implementing > - * the simple API. Certain decoders might consume partial packets without > - * returning any output, so this function needs to be called in a loop until > it > - * returns EAGAIN. > - **/ > -static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame > *frame, int64_t *discarded_samples) > +static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t > *discarded_samples) > { > -AVCodecInternal *avci = avctx->internal; > -AVPacket *const pkt = avci->in_pkt; > -const FFCodec *const codec = ffcodec(avctx->codec); > -int got_frame, actual_got_frame; > -int ret; > - > -if (!pkt->data && !avci->draining) { > -av_packet_unref(pkt); > -ret = ff_decode_get_packet(avctx, pkt); > -if (ret < 0 && ret != AVERROR_EOF) > -return ret; > -} > - > -// Some codecs (at least wma lossless) will crash when feeding drain > packets > -// after EOF was signaled. > -if (avci->draining_done) > -return AVERROR_EOF; > - > -if (!pkt->data && > -!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY || > - avctx->active_thread_type & FF_THREAD_FRAME)) > -return AVERROR_EOF; > - > -got_frame = 0; > - > -if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) { > -ret = ff_thread_decode_frame(avctx, frame, &got_frame, pkt); > -} else { > -ret = codec->cb.decode(avctx, frame, &got_frame, pkt); > - > -if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS)) > -frame->pkt_dts = pkt->dts; > -if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) { > -#if FF_API_FRAME_PKT > -FF_DISABLE_DEPRECATION_WARNINGS > -if(!avctx->has_b_frames) > -frame->pkt_pos = pkt->pos; > -FF_ENABLE_DEPRECATION_WARNINGS > -#endif > -//FIXME these should be under if(!avctx->has_b_frames) > -/* get_buffer is supposed to set frame parameters */ > -if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) { > -if (!frame->sample_aspect_ratio.num) > frame->sample_aspect_ratio = avctx->sample_aspect_ratio; > -if (!frame->width)frame->width > = avctx->width; > -if (!frame->height) frame->height > = avctx->height; > -if (frame->format == AV_PIX_FMT_NONE) frame->format > = avctx->pix_fmt; > -} > -} > -} > -emms_c(); > -actual_got_frame = got_frame; > +AVCodecInternal *avci = avctx->internal; > +int ret = 0; > > if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) { > if (frame->flags & AV_FRAME_FLAG_DISCARD) > -got_frame = 0; > +ret = AVERROR(EAGAIN); It's quite strange an unexpected for a function called discard_samples() to do anything with video. By leaving video processing in the caller you also save a level of indentation. > } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { > uint8_t *side; > size_t side_size; > @@ -359,16 +304,10 @@ FF_ENABLE_DEPRECATION_WARNINGS > uint8_t skip_reason = 0; > uint8_t discard_reason = 0; > > -if (ret >= 0 && got_frame) { > if (frame->format == AV_SAMPLE_FMT_NONE) > frame->format = avctx->sample_fmt; > -if (!frame->ch_layout.nb_channels) { > -int ret2 = av_channel_layout_copy(&frame->ch_layout, > &avctx->ch_layout); > -if (ret2 < 0) { > -ret = ret2; > -got_frame = 0; > -} > -} > +if (!frame->ch_layout.nb_channels) > +ret = av_channel_layout_copy(&frame->ch_layout, > &avctx->ch_layout); > #if FF_API_OLD_CHANNEL_LAYOUT > FF_DISABLE_DEPRECATION_WARNINGS > if (!frame->channel_layout) > @@ -380,7 +319,6 @@ FF_ENABLE_DEPRECATION_WARNINGS > #endif > if (!frame->sample_rate) > frame->sample_rate = avctx->sample_rate; > -} So the rest of the code below was previously executed even when there is no frame? The change seems correct, but not I wouldn't expect it in a 'move' commit, so perhaps mention it in the commit message. > > side= av_packet_get_side_data(avci->last_pkt_props, > AV_PKT_DATA_SKIP_SAMPLES, &side_size); > if(side && side_size>=10) { > @@ -393,21 +331,21 @@ FF_ENABLE_DEPRECATION_WARNINGS > discard_reason = AV_RL8(side + 9); > } > > -if ((frame->flags & AV_FRAME_FLAG_DISCARD) && got_frame && > +if ((frame->flags & AV_FRAME_FLAG_DISCARD) && !ret && > !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) { > avci->skip_samples = FFMAX(0, avci->skip_samples - > frame->nb_samples); > -
Re: [FFmpeg-devel] [PATCH 3/3] avcodec/decode: fill missing frame fields for all decoders
Quoting James Almer (2023-07-08 21:00:38) > And not just those with the old decode() API. > > Signed-off-by: James Almer > --- > libavcodec/decode.c | 52 +++-- > 1 file changed, 27 insertions(+), 25 deletions(-) Is there a functional reason for this patch? I've been wondering recently about dropping this code entirely, because get_buffer() should always fill those fields. -- 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-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] lavu/random_seed: use getrandom() when available
Quoting Marton Balint (2023-07-07 22:02:26) > > > On Fri, 7 Jul 2023, Anton Khirnov wrote: > > > It is a better interface for /dev/u?random on Linux, which avoids the > > issues associated with opening files. > > > getrandom() actually have the same problem as read(). It can read less > than requested. So you should use it in a loop in that case or if it > returns EINTR. I'm not convinced it's actually a problem. This API is intended for small secrets like keys and such, somebody trying to generate vast quantities of random data is likely misusing it and could just as well use LFG or something. Failing in that case seems like a good thing to me. -- 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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] lavu/random_seed: use getrandom() when available
It is a better interface for /dev/u?random on Linux, which avoids the issues associated with opening files. --- configure | 2 ++ libavutil/random_seed.c | 16 2 files changed, 18 insertions(+) diff --git a/configure b/configure index 0ab0761011..f8c809e491 100755 --- a/configure +++ b/configure @@ -2310,6 +2310,7 @@ SYSTEM_FUNCS=" getauxval getenv gethrtime +getrandom getopt GetModuleHandle GetProcessAffinityMask @@ -6387,6 +6388,7 @@ check_func fcntl check_func fork check_func gethrtime check_func getopt +check_func_headers "sys/random.h" getrandom check_func getrusage check_func gettimeofday check_func isatty diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c index f167b172f2..92bf9ef8e1 100644 --- a/libavutil/random_seed.c +++ b/libavutil/random_seed.c @@ -35,6 +35,9 @@ #elif CONFIG_OPENSSL #include #endif +#if HAVE_GETRANDOM +#include +#endif #include #include #include @@ -51,6 +54,7 @@ #define TEST 0 #endif +#if !HAVE_GETRANDOM static int read_random(uint8_t *dst, size_t len, const char *file) { #if HAVE_UNISTD_H @@ -70,6 +74,7 @@ static int read_random(uint8_t *dst, size_t len, const char *file) return AVERROR(ENOSYS); #endif } +#endif static uint32_t get_generic_seed(void) { @@ -147,7 +152,18 @@ int av_random_bytes(uint8_t* buf, size_t len) return 0; #endif +// getrandom() is a better interface for /dev/(u)random on Linux, +// so it makes no sense to try both +#if HAVE_GETRANDOM +{ +ssize_t read = getrandom(buf, len, GRND_NONBLOCK); +if (read < 0) +return errno == EAGAIN ? AVERROR_EXTERNAL : AVERROR(errno); +return read != len ? AVERROR_UNKNOWN : 0; +} +#else err = read_random(buf, len, "/dev/urandom"); +#endif if (!err) return err; -- 2.40.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [RFC] Release 6.1
Quoting Lynne (2023-07-06 18:04:41) > It's been a while since we've had a release, and we've had > a lot of new features in. > We did say we would make releases more often, and I think > it's about time we have a new release. > > Anything anyone wants to have merged or should we branch > off 6.1 in a few days? I'd like to have '[PATCH 21/22] fftools/ffmpeg: rework -enc_time_base handling' (<20230707094847.25324-21-an...@khirnov.net>), which fixes #10393, in the release. -- 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-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [RFC] Release 6.1
Quoting Michael Niedermayer (2023-07-07 17:06:54) > Hi > > On Thu, Jul 06, 2023 at 06:04:41PM +0200, Lynne wrote: > > It's been a while since we've had a release, and we've had > > a lot of new features in. > > We did say we would make releases more often, and I think > > it's about time we have a new release. > > yes > > > > > > Anything anyone wants to have merged or should we branch > > off 6.1 in a few days? > > libavradio needs testing, at least build testing. > all parts of git master are tested automatically by our user base > but anything in seperate repositories might receive less testing > so we should encourage people to test these seperate repositories > for the release > > also note iam quite busy ATM, its not the best time for me to > do 6.1, so "in a few days" is a bit too optimistic i think How is libavradio related to the release? -- 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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] lavu: add AVVideoHint API
From: Elias Carotti Add side data type to provide hint to the video encoders about unchanged portions of each frame. Signed-off-by: Anton Khirnov --- I've made couple small changes: * rebased against current master * consistently refer to rectangles or AVVideoRect, not blocks * use size_t instead of int for AVVideoHint.nb_rects * build unconditionally -- this is public API, it must always be available regardless of what encoders are or are not available * tweaked documentation If you have no objections to the changes, I'll push this in a few days. --- doc/APIchanges | 3 ++ libavutil/Makefile | 2 + libavutil/frame.h | 10 libavutil/version.h| 2 +- libavutil/video_hint.c | 82 +++ libavutil/video_hint.h | 108 + 6 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 libavutil/video_hint.c create mode 100644 libavutil/video_hint.h diff --git a/doc/APIchanges b/doc/APIchanges index 27f835cfce..0cda51fdee 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09 API changes, most recent first: +2023-07-xx - xx - lavu 58.15.100 - video_hint.h + Add AVVideoHint API. + 2023-07-05 - xx - lavu 58.14.100 - random_seed.h Add av_random_bytes() diff --git a/libavutil/Makefile b/libavutil/Makefile index bd9c6f9e32..7828c94dc5 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -91,6 +91,7 @@ HEADERS = adler32.h \ tea.h \ tx.h \ film_grain_params.h \ + video_hint.h ARCH_HEADERS = bswap.h \ intmath.h\ @@ -181,6 +182,7 @@ OBJS = adler32.o \ uuid.o \ version.o\ video_enc_params.o \ + video_hint.o \ film_grain_params.o \ diff --git a/libavutil/frame.h b/libavutil/frame.h index a491315f25..c0c1b23db7 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -214,6 +214,16 @@ enum AVFrameSideDataType { * Ambient viewing environment metadata, as defined by H.274. */ AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT, + +/** + * Provide encoder-specific hinting information about changed/unchanged + * portions of a frame. It can be used to pass information about which + * macroblocks can be skipped because they didn't change from the + * corresponding ones in the previous frame. This could be useful for + * applications which know this information in advance to speed up + * encoding. + */ +AV_FRAME_DATA_VIDEO_HINT, }; enum AVActiveFormatDescription { diff --git a/libavutil/version.h b/libavutil/version.h index 24af520e08..9e798b0e3f 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 58 -#define LIBAVUTIL_VERSION_MINOR 14 +#define LIBAVUTIL_VERSION_MINOR 15 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ diff --git a/libavutil/video_hint.c b/libavutil/video_hint.c new file mode 100644 index 00..5730ed6cfb --- /dev/null +++ b/libavutil/video_hint.c @@ -0,0 +1,82 @@ +/* + * Copyright 2023 Elias Carotti + * + * 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 "avstring.h" +#include "frame.h" +#include "macros.h" +#include "mem.h" +#include "video_hint.h" + +AVVideoHint *av_video_hint_alloc(size_t nb_rects, + size_t *out_size) +{ +struct TestStruct { +AVVideoHinthint; +AVVideoRectrect; +}; +const size_t rect
Re: [FFmpeg-devel] [PATCH 2/2] lavc/libx264: add mb_info option
Quoting Carotti, Elias (2023-07-03 17:55:40) > On Wed, 2023-06-21 at 15:57 +, Carotti, Elias wrote: > > Hi all, > > please find the second part of the patch set. > > Best, > > Elias > > Hi all, > please find the second part of the patch, updating libavcodec/libx264.c > to use the AVVideoHint side data. This should use the block_size field > to scan the AVVideoRect array. > > Best, > Elias > > > > NICE SRL, viale Monte Grappa 3/5, 20124 Milano, Italia, Registro delle > Imprese di Milano Monza Brianza Lodi REA n. 2096882, Capitale Sociale: > 10.329,14 EUR i.v., Cod. Fisc. e P.IVA 01133050052, Societa con Socio Unico > > > > From 5bdb624d8dbcff96493a63f02f68a3961cf72723 Mon Sep 17 00:00:00 2001 > From: Elias Carotti > Date: Tue, 20 Jun 2023 19:29:08 +0200 > Subject: [PATCH 2/2] lavc/libx264: add mb_info option > > Pass the information about unchanged parts of the frame by means of the > AVVideoHint side data. > --- > Changelog| 1 + > doc/APIchanges | 3 ++ > libavcodec/libx264.c | 94 > libavcodec/version.h | 2 +- > 4 files changed, 99 insertions(+), 1 deletion(-) > > diff --git a/Changelog b/Changelog > index 3876082844..70b0fe94a3 100644 > --- a/Changelog > +++ b/Changelog > @@ -25,6 +25,7 @@ version : > - Raw VVC bitstream parser, muxer and demuxer > - Bitstream filter for editing metadata in VVC streams > - Bitstream filter for converting VVC from MP4 to Annex B > +- support for the P_SKIP hinting to speed up libx264 encoding > > version 6.0: > - Radiance HDR image support > diff --git a/doc/APIchanges b/doc/APIchanges > index bfe04556d2..89ff88af15 100644 > --- a/doc/APIchanges > +++ b/doc/APIchanges > @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09 > > API changes, most recent first: > > +2023-06-21 - xx - lavc 60.23.100 - libx264.c > + Add mb_info option. Do we actually need the option? If the encoder's caller bothered with adding the side data, then I'd think it should always be used, otherwise why is it even there? -- 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-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 3/3] avcodec/decode: fill missing frame fields for all decoders
On 7/9/2023 6:49 AM, Anton Khirnov wrote: Quoting James Almer (2023-07-08 21:00:38) And not just those with the old decode() API. Signed-off-by: James Almer --- libavcodec/decode.c | 52 +++-- 1 file changed, 27 insertions(+), 25 deletions(-) Is there a functional reason for this patch? I've been wondering recently about dropping this code entirely, because get_buffer() should always fill those fields. Decoders that don't use get_buffer at all exist. If they don't fill all frame fields, this would. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 1/3] avcodec/decode: move processing discard samples to its own function
On 7/9/2023 6:48 AM, Anton Khirnov wrote: Quoting James Almer (2023-07-08 21:00:36) -/* - * The core of the receive_frame_wrapper for the decoders implementing - * the simple API. Certain decoders might consume partial packets without - * returning any output, so this function needs to be called in a loop until it - * returns EAGAIN. - **/ -static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples) +static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples) { -AVCodecInternal *avci = avctx->internal; -AVPacket *const pkt = avci->in_pkt; -const FFCodec *const codec = ffcodec(avctx->codec); -int got_frame, actual_got_frame; -int ret; - -if (!pkt->data && !avci->draining) { -av_packet_unref(pkt); -ret = ff_decode_get_packet(avctx, pkt); -if (ret < 0 && ret != AVERROR_EOF) -return ret; -} - -// Some codecs (at least wma lossless) will crash when feeding drain packets -// after EOF was signaled. -if (avci->draining_done) -return AVERROR_EOF; - -if (!pkt->data && -!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY || - avctx->active_thread_type & FF_THREAD_FRAME)) -return AVERROR_EOF; - -got_frame = 0; - -if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) { -ret = ff_thread_decode_frame(avctx, frame, &got_frame, pkt); -} else { -ret = codec->cb.decode(avctx, frame, &got_frame, pkt); - -if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS)) -frame->pkt_dts = pkt->dts; -if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) { -#if FF_API_FRAME_PKT -FF_DISABLE_DEPRECATION_WARNINGS -if(!avctx->has_b_frames) -frame->pkt_pos = pkt->pos; -FF_ENABLE_DEPRECATION_WARNINGS -#endif -//FIXME these should be under if(!avctx->has_b_frames) -/* get_buffer is supposed to set frame parameters */ -if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) { -if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio; -if (!frame->width)frame->width = avctx->width; -if (!frame->height) frame->height = avctx->height; -if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt; -} -} -} -emms_c(); -actual_got_frame = got_frame; +AVCodecInternal *avci = avctx->internal; +int ret = 0; if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) { if (frame->flags & AV_FRAME_FLAG_DISCARD) -got_frame = 0; +ret = AVERROR(EAGAIN); It's quite strange an unexpected for a function called discard_samples() to do anything with video. By leaving video processing in the caller you also save a level of indentation. I could call it discard_samples_or_frame(), or discard_frame(). If i process the video in the caller, it will end up being duplicated in patch 2, which goes against the point of factoring this out. } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { uint8_t *side; size_t side_size; @@ -359,16 +304,10 @@ FF_ENABLE_DEPRECATION_WARNINGS uint8_t skip_reason = 0; uint8_t discard_reason = 0; -if (ret >= 0 && got_frame) { if (frame->format == AV_SAMPLE_FMT_NONE) frame->format = avctx->sample_fmt; -if (!frame->ch_layout.nb_channels) { -int ret2 = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout); -if (ret2 < 0) { -ret = ret2; -got_frame = 0; -} -} +if (!frame->ch_layout.nb_channels) +ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout); #if FF_API_OLD_CHANNEL_LAYOUT FF_DISABLE_DEPRECATION_WARNINGS if (!frame->channel_layout) @@ -380,7 +319,6 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif if (!frame->sample_rate) frame->sample_rate = avctx->sample_rate; -} So the rest of the code below was previously executed even when there is no frame? The change seems correct, but not I wouldn't expect it in a 'move' commit, so perhaps mention it in the commit message. It still is, at least the block immediately after this, exporting avci->skip_samples. I don't know how correct it is to do that, but i did not want to change behavior in this set for decode() API decoders. side= av_packet_get_side_data(avci->last_pkt_props, AV_PKT_DATA_SKIP_SAMPLES, &side_size); if(side && side_size>=10) { @@ -393,21 +331,21 @@ FF_ENABLE_DEPRECATION_WARNINGS discard_reason = AV_RL8(side + 9); } -if ((frame->flag
Re: [FFmpeg-devel] [PATCH 1/3] avcodec/decode: move processing discard samples to its own function
Quoting James Almer (2023-07-09 14:11:14) > > I could call it discard_samples_or_frame(), or discard_frame(). > If i process the video in the caller, it will end up being duplicated in > patch 2, which goes against the point of factoring this out. The duplicated code would be 2 very simple lines. The cost you're paying for avoiding the duplication seems worse to me. -- 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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] HVQM4
Attached. From acdb135770da2c52f3f4f9416b231b1b573cb0ae Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sun, 1 Aug 2021 20:06:24 +0200 Subject: [PATCH 1/3] avformat: add hvqm4 demuxer Signed-off-by: Paul B Mahol --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/hvqm4dec.c | 186 +++ 3 files changed, 188 insertions(+) create mode 100644 libavformat/hvqm4dec.c diff --git a/libavformat/Makefile b/libavformat/Makefile index 4cb00f8700..e2e5f95c8a 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -258,6 +258,7 @@ OBJS-$(CONFIG_EVC_MUXER) += rawenc.o OBJS-$(CONFIG_HLS_DEMUXER) += hls.o hls_sample_encryption.o OBJS-$(CONFIG_HLS_MUXER) += hlsenc.o hlsplaylist.o avc.o OBJS-$(CONFIG_HNM_DEMUXER) += hnm.o +OBJS-$(CONFIG_HVQM4_DEMUXER) += hvqm4dec.o OBJS-$(CONFIG_ICO_DEMUXER) += icodec.o OBJS-$(CONFIG_ICO_MUXER) += icoenc.o OBJS-$(CONFIG_IDCIN_DEMUXER) += idcin.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 6324952bd2..228024c15c 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -212,6 +212,7 @@ extern const FFOutputFormat ff_hevc_muxer; extern const AVInputFormat ff_hls_demuxer; extern const FFOutputFormat ff_hls_muxer; extern const AVInputFormat ff_hnm_demuxer; +extern const AVInputFormat ff_hvqm4_demuxer; extern const AVInputFormat ff_ico_demuxer; extern const FFOutputFormat ff_ico_muxer; extern const AVInputFormat ff_idcin_demuxer; diff --git a/libavformat/hvqm4dec.c b/libavformat/hvqm4dec.c new file mode 100644 index 00..1fee35cf86 --- /dev/null +++ b/libavformat/hvqm4dec.c @@ -0,0 +1,186 @@ +/* + * HVQM4 demuxer + * Copyright (c) 2021 Paul B Mahol + * + * 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 "avformat.h" +#include "internal.h" + +typedef struct HVQM4Block { +int64_t start; +int64_t stop; +} HVQM4Block; + +typedef struct HVQM4Context { +uint32_t nb_blocks; +HVQM4Block *block; +uint32_t current_block; +} HVQM4Context; + +static int hvqm4_probe(const AVProbeData *p) +{ +if (memcmp(p->buf, "HVQM4 1.3", 9) && +memcmp(p->buf, "HVQM4 1.5", 9)) +return 0; + +return AVPROBE_SCORE_MAX; +} + +static int hvqm4_read_header(AVFormatContext *s) +{ +AVIOContext *pb = s->pb; +AVStream *vst, *ast; +uint32_t header_size, usec_per_frame; +int audio_format; + +vst = avformat_new_stream(s, NULL); +if (!vst) +return AVERROR(ENOMEM); + +avio_skip(pb, 16); + +header_size = avio_rb32(pb); +avio_skip(pb, 8); +vst->start_time = 0; +vst->nb_frames = avio_rb32(pb); +vst->duration = vst->nb_frames; +avio_skip(pb, 4); +usec_per_frame = avio_rb32(pb); +avio_skip(pb, 12); + +vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; +vst->codecpar->codec_id = AV_CODEC_ID_HVQM4; +vst->codecpar->width = avio_rb16(pb); +vst->codecpar->height = avio_rb16(pb); + +avio_skip(pb, 2); +avio_skip(pb, 2); + +avpriv_set_pts_info(vst, 64, usec_per_frame, 100); + +ast = avformat_new_stream(s, NULL); +if (!ast) +return AVERROR(ENOMEM); + +ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; +ast->codecpar->ch_layout.nb_channels = avio_r8(pb); +ast->codecpar->bits_per_coded_sample = avio_r8(pb); +audio_format = avio_r8(pb); +switch (audio_format) { +case 0: +ast->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_HVQM4; +break; +case 1: +ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; +break; +} +avio_skip(pb, 1); +ast->codecpar->sample_rate = avio_rb32(pb); + +avio_skip(pb, header_size - avio_tell(pb)); + +return 0; +} + +static int hvqm4_read_packet(AVFormatContext *s, AVPacket *pkt) +{ +HVQM4Context *hvqm4 = s->priv_data; +AVIOContext *pb = s->pb; +int media_type, frame_type, ret, new_block = 1; +int64_t pos, ppos; +int32_t size; + +if (avio_feof(pb)) +return AVERROR_EOF; + +pos = avio_tell(pb); + +for (int i = 0; i < hvqm4->nb_blocks;
[FFmpeg-devel] [PATCH] lavc: deprecate AV_CODEC_FLAG_DROPCHANGED
This decoding flag makes decoders drop all frames after a parameter change, but what exactly constitutes a parameter change is not well defined and will typically depend on the exact use case. This functionality then does not belong in libavcodec, but rather in user code --- doc/APIchanges | 3 +++ libavcodec/avcodec.c | 2 ++ libavcodec/avcodec.h | 7 --- libavcodec/decode.c| 11 +-- libavcodec/internal.h | 2 ++ libavcodec/options_table.h | 2 ++ libavcodec/version_major.h | 1 + 7 files changed, 23 insertions(+), 5 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 0cda51fdee..6217502492 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09 API changes, most recent first: +2023-07-xx - xx - lavc 60 - avcodec.h + Deprecate AV_CODEC_FLAG_DROPCHANGED without replacement. + 2023-07-xx - xx - lavu 58.15.100 - video_hint.h Add AVVideoHint API. diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 8ccc610227..340abe830e 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -456,7 +456,9 @@ av_cold int avcodec_close(AVCodecContext *avctx) av_bsf_free(&avci->bsf); +#if FF_API_DROPCHANGED av_channel_layout_uninit(&avci->initial_ch_layout); +#endif #if CONFIG_LCMS2 ff_icc_context_uninit(&avci->icc); diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index d17bdc360d..fe41ecc3c9 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -226,11 +226,15 @@ typedef struct RcOverride{ * Use qpel MC. */ #define AV_CODEC_FLAG_QPEL(1 << 4) +#if FF_API_DROPCHANGED /** * Don't output frames whose parameters differ from first * decoded frame in stream. + * + * @deprecated callers should implement this functionality in their own code */ #define AV_CODEC_FLAG_DROPCHANGED (1 << 5) +#endif /** * Request the encoder to output reconstructed frames, i.e.\ frames that would * be produced by decoding the encoded bistream. These frames may be retrieved @@ -2713,9 +2717,6 @@ int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt); * no more output frames * @retval AVERROR(EINVAL) codec not opened, or it is an encoder without the * @ref AV_CODEC_FLAG_RECON_FRAME flag enabled - * @retval AVERROR_INPUT_CHANGED current decoded frame has changed parameters with - * respect to first decoded frame. Applicable when flag - * AV_CODEC_FLAG_DROPCHANGED is set. * @retval "other negative error code" legitimate decoding errors */ int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame); diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 269633ce10..40eb7679ca 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -740,7 +740,7 @@ fail: int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame) { AVCodecInternal *avci = avctx->internal; -int ret, changed; +int ret; if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec)) return AVERROR(EINVAL); @@ -770,6 +770,7 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif +#if FF_API_DROPCHANGED if (avctx->flags & AV_CODEC_FLAG_DROPCHANGED) { if (avctx->frame_num == 1) { @@ -790,7 +791,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (avctx->frame_num > 1) { -changed = avci->initial_format != frame->format; +int changed = avci->initial_format != frame->format; switch(avctx->codec_type) { case AVMEDIA_TYPE_VIDEO: @@ -815,6 +816,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } } } +#endif return 0; fail: av_frame_unref(frame); @@ -1739,6 +1741,11 @@ int ff_decode_preinit(AVCodecContext *avctx) if (ret < 0) return ret; +#if FF_API_DROPCHANGED +if (avctx->flags & AV_CODEC_FLAG_DROPCHANGED) +av_log(avctx, AV_LOG_WARNING, "The dropchanged flag is deprecated.\n"); +#endif + return 0; } diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 868dd46b48..4dce9f6fbb 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -135,12 +135,14 @@ typedef struct AVCodecInternal { AVFrame *buffer_frame; int draining_done; +#if FF_API_DROPCHANGED /* used when avctx flag AV_CODEC_FLAG_DROPCHANGED is set */ int changed_frames_dropped; int initial_format; int initial_width, initial_height; int initial_sample_rate; AVChannelLayout initial_ch_layout; +#endif #if CONFIG_LCMS2 FFIccContext icc; /* used to read and write embedded ICC profiles */ diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index f1a9729c0d..d1244bfc1a 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -72,7 +72,9 @@ static
Re: [FFmpeg-devel] [PATCH 3/3] avcodec/decode: fill missing frame fields for all decoders
Quoting James Almer (2023-07-09 14:05:45) > On 7/9/2023 6:49 AM, Anton Khirnov wrote: > > Quoting James Almer (2023-07-08 21:00:38) > >> And not just those with the old decode() API. > >> > >> Signed-off-by: James Almer > >> --- > >> libavcodec/decode.c | 52 +++-- > >> 1 file changed, 27 insertions(+), 25 deletions(-) > > > > Is there a functional reason for this patch? > > > > I've been wondering recently about dropping this code entirely, because > > get_buffer() should always fill those fields. > > Decoders that don't use get_buffer at all exist. If they don't fill all > frame fields, this would. Ah well, there's more of those than I thought. No objections then. -- 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-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] lavu: add AVVideoHint API
Jul 9, 2023, 13:05 by an...@khirnov.net: > From: Elias Carotti > > Add side data type to provide hint to the video encoders about unchanged > portions of each frame. > > Signed-off-by: Anton Khirnov > --- > I've made couple small changes: > * rebased against current master > * consistently refer to rectangles or AVVideoRect, not blocks > * use size_t instead of int for AVVideoHint.nb_rects > * build unconditionally -- this is public API, it must always be > available regardless of what encoders are or are not available > * tweaked documentation > > If you have no objections to the changes, I'll push this in a few days. > --- > doc/APIchanges | 3 ++ > libavutil/Makefile | 2 + > libavutil/frame.h | 10 > libavutil/version.h| 2 +- > libavutil/video_hint.c | 82 +++ > libavutil/video_hint.h | 108 + > 6 files changed, 206 insertions(+), 1 deletion(-) > create mode 100644 libavutil/video_hint.c > create mode 100644 libavutil/video_hint.h > AVVideoHint is a bad name for something like this. Could you borrow some wording from graphics and call it AVVideoDamagedHint or maybe AVVideoChangedAreaHint or a combination of both? I'd prefer the former, damage is standard language in graphics circles about what has changed since the last frame. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 1/3] avcodec/decode: move processing discard samples to its own function
As an intended side effect, avci->skip_samples is no longer being set when no frame is output. Signed-off-by: James Almer --- libavcodec/decode.c | 269 +++- 1 file changed, 138 insertions(+), 131 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 269633ce10..a39af2d014 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -289,6 +289,120 @@ static int64_t guess_correct_pts(AVCodecContext *ctx, return pts; } +static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples) +{ +AVCodecInternal *avci = avctx->internal; +int ret = 0; +uint8_t *side; +size_t side_size; +uint32_t discard_padding = 0; +uint8_t skip_reason = 0; +uint8_t discard_reason = 0; + +if (frame->format == AV_SAMPLE_FMT_NONE) +frame->format = avctx->sample_fmt; +if (!frame->ch_layout.nb_channels) { +int ret2 = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout); +if (ret2 < 0) { +ret = ret2; +} +} +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS +if (!frame->channel_layout) +frame->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? +avctx->ch_layout.u.mask : 0; +if (!frame->channels) +frame->channels = avctx->ch_layout.nb_channels; +FF_ENABLE_DEPRECATION_WARNINGS +#endif +if (!frame->sample_rate) +frame->sample_rate = avctx->sample_rate; + +side = av_packet_get_side_data(avci->last_pkt_props, AV_PKT_DATA_SKIP_SAMPLES, &side_size); +if (side && side_size >= 10) { +avci->skip_samples = AV_RL32(side); +avci->skip_samples = FFMAX(0, avci->skip_samples); +discard_padding = AV_RL32(side + 4); +av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n", + avci->skip_samples, (int)discard_padding); +skip_reason = AV_RL8(side + 8); +discard_reason = AV_RL8(side + 9); +} + +if ((frame->flags & AV_FRAME_FLAG_DISCARD) && +!(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) { +avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples); +*discarded_samples += frame->nb_samples; +return AVERROR(EAGAIN); +} + +if (avci->skip_samples > 0 && +!(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) { +if (frame->nb_samples <= avci->skip_samples){ +*discarded_samples += frame->nb_samples; +avci->skip_samples -= frame->nb_samples; +av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n", + avci->skip_samples); +return AVERROR(EAGAIN); +} else { +av_samples_copy(frame->extended_data, frame->extended_data, 0, avci->skip_samples, +frame->nb_samples - avci->skip_samples, avctx->ch_layout.nb_channels, frame->format); +if (avctx->pkt_timebase.num && avctx->sample_rate) { +int64_t diff_ts = av_rescale_q(avci->skip_samples, + (AVRational){1, avctx->sample_rate}, + avctx->pkt_timebase); +if (frame->pts != AV_NOPTS_VALUE) +frame->pts += diff_ts; +if (frame->pkt_dts != AV_NOPTS_VALUE) +frame->pkt_dts += diff_ts; +if (frame->duration >= diff_ts) +frame->duration -= diff_ts; +} else +av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n"); + +av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n", + avci->skip_samples, frame->nb_samples); +*discarded_samples += avci->skip_samples; +frame->nb_samples -= avci->skip_samples; +avci->skip_samples = 0; +} +} + +if (discard_padding > 0 && discard_padding <= frame->nb_samples && +!(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) { +if (discard_padding == frame->nb_samples) { +*discarded_samples += frame->nb_samples; +return AVERROR(EAGAIN); +} else { +if (avctx->pkt_timebase.num && avctx->sample_rate) { +int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding, + (AVRational){1, avctx->sample_rate}, + avctx->pkt_timebase); +frame->duration = diff_ts; +} else +av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n"); + +av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n", + (int)discard_padding, frame->nb_samples); +frame->nb_samples -= discard_padding; +} +} + +if ((avctx->flags2 & AV_CODEC_FLAG
[FFmpeg-devel] [PATCH v2 2/3] avcodec/decode: check the output frame for discard samples with all decoders
And not just those with the old decode() API. Signed-off-by: James Almer --- libavcodec/decode.c | 8 1 file changed, 8 insertions(+) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index a39af2d014..b3e4b066e5 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -597,6 +597,14 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) { ret = codec->cb.receive_frame(avctx, frame); emms_c(); +if (!ret) { +if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) +ret = (frame->flags & AV_FRAME_FLAG_DISCARD) ? AVERROR(EAGAIN) : 0; +else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { +int64_t discarded_samples = 0; +ret = discard_samples(avctx, frame, &discarded_samples); +} +} } else ret = decode_simple_receive_frame(avctx, frame); -- 2.41.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 3/3] avcodec/decode: fill missing frame fields for all decoders
And not just those with the old decode() API. Signed-off-by: James Almer --- libavcodec/decode.c | 64 +++-- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index b3e4b066e5..080edb5996 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -292,33 +292,12 @@ static int64_t guess_correct_pts(AVCodecContext *ctx, static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples) { AVCodecInternal *avci = avctx->internal; -int ret = 0; uint8_t *side; size_t side_size; uint32_t discard_padding = 0; uint8_t skip_reason = 0; uint8_t discard_reason = 0; -if (frame->format == AV_SAMPLE_FMT_NONE) -frame->format = avctx->sample_fmt; -if (!frame->ch_layout.nb_channels) { -int ret2 = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout); -if (ret2 < 0) { -ret = ret2; -} -} -#if FF_API_OLD_CHANNEL_LAYOUT -FF_DISABLE_DEPRECATION_WARNINGS -if (!frame->channel_layout) -frame->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? -avctx->ch_layout.u.mask : 0; -if (!frame->channels) -frame->channels = avctx->ch_layout.nb_channels; -FF_ENABLE_DEPRECATION_WARNINGS -#endif -if (!frame->sample_rate) -frame->sample_rate = avctx->sample_rate; - side = av_packet_get_side_data(avci->last_pkt_props, AV_PKT_DATA_SKIP_SAMPLES, &side_size); if (side && side_size >= 10) { avci->skip_samples = AV_RL32(side); @@ -400,7 +379,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } } -return ret; +return 0; } /* @@ -450,14 +429,6 @@ FF_DISABLE_DEPRECATION_WARNINGS frame->pkt_pos = pkt->pos; FF_ENABLE_DEPRECATION_WARNINGS #endif -//FIXME these should be under if(!avctx->has_b_frames) -/* get_buffer is supposed to set frame parameters */ -if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) { -if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio; -if (!frame->width)frame->width = avctx->width; -if (!frame->height) frame->height = avctx->height; -if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt; -} } } emms_c(); @@ -619,8 +590,39 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) } if (!ret) { -if (avctx->codec_type != AVMEDIA_TYPE_VIDEO) +if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { +/* get_buffer is supposed to set frame parameters */ +if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) { +if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio; +if (!frame->width)frame->width = avctx->width; +if (!frame->height) frame->height = avctx->height; +if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt; +} +} else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { +if (frame->format == AV_SAMPLE_FMT_NONE) +frame->format = avctx->sample_fmt; +if (!frame->ch_layout.nb_channels) { +ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout); +if (ret < 0) { +av_frame_unref(frame); +return ret; +} +} +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS +if (!frame->channel_layout) +frame->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? +avctx->ch_layout.u.mask : 0; +if (!frame->channels) +frame->channels = avctx->ch_layout.nb_channels; +FF_ENABLE_DEPRECATION_WARNINGS +#endif +if (!frame->sample_rate) +frame->sample_rate = avctx->sample_rate; + frame->flags |= AV_FRAME_FLAG_KEY; +} + #if FF_API_FRAME_KEY FF_DISABLE_DEPRECATION_WARNINGS frame->key_frame = !!(frame->flags & AV_FRAME_FLAG_KEY); -- 2.41.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter/af_adynamicequalizer: simplify calculations
ffmpeg | branch: master | Paul B Mahol https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog>> | Thu Jul 6 16:47:02 2023 +0200| [889c2529cc6ef65bb4c4f10aa79ca7ca0070a1aa] | committer: Paul B Mahol avfilter/af_adynamicequalizer: simplify calculations >/http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=889c2529cc6ef65bb4c4f10aa79ca7ca0070a1aa /--- libavfilter/adynamicequalizer_template.c | 16 ++-- libavfilter/af_adynamicequalizer.c | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/libavfilter/adynamicequalizer_template.c b/libavfilter/adynamicequalizer_template.c index 4f7d58c939..ee9f4a1d5f 100644 --- a/libavfilter/adynamicequalizer_template.c +++ b/libavfilter/adynamicequalizer_template.c @@ -26,6 +26,7 @@ #undef FMIN #undef CLIP #undef SAMPLE_FORMAT +#undef EPSILON #undef FABS #if DEPTH == 32 #define SAMPLE_FORMAT float @@ -39,6 +40,7 @@ #define CLIP av_clipf #define FABS fabsf #define ftype float +#define EPSILON (1.f / (1 << 22)) #else #define SAMPLE_FORMAT double #define SQRT sqrt @@ -51,6 +53,7 @@ #define CLIP av_clipd #define FABS fabs #define ftype double +#define EPSILON (1.0 / (1LL << 51)) #endif You have FLT_EPSILON and DBL_EPSILON for this. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter/af_adynamicequalizer: simplify calculations
On Sun, Jul 9, 2023 at 5:24 PM James Almer wrote: > > ffmpeg | branch: master | Paul B Mahol https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog>> | Thu Jul 6 16:47:02 > 2023 +0200| [889c2529cc6ef65bb4c4f10aa79ca7ca0070a1aa] | committer: Paul B > Mahol > > > > avfilter/af_adynamicequalizer: simplify calculations > > > > >/ > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=889c2529cc6ef65bb4c4f10aa79ca7ca0070a1aa > > /--- > > > > libavfilter/adynamicequalizer_template.c | 16 ++-- > > libavfilter/af_adynamicequalizer.c | 2 +- > > 2 files changed, 11 insertions(+), 7 deletions(-) > > > > diff --git a/libavfilter/adynamicequalizer_template.c > b/libavfilter/adynamicequalizer_template.c > > index 4f7d58c939..ee9f4a1d5f 100644 > > --- a/libavfilter/adynamicequalizer_template.c > > +++ b/libavfilter/adynamicequalizer_template.c > > @@ -26,6 +26,7 @@ > > #undef FMIN > > #undef CLIP > > #undef SAMPLE_FORMAT > > +#undef EPSILON > > #undef FABS > > #if DEPTH == 32 > > #define SAMPLE_FORMAT float > > @@ -39,6 +40,7 @@ > > #define CLIP av_clipf > > #define FABS fabsf > > #define ftype float > > +#define EPSILON (1.f / (1 << 22)) > > #else > > #define SAMPLE_FORMAT double > > #define SQRT sqrt > > @@ -51,6 +53,7 @@ > > #define CLIP av_clipd > > #define FABS fabs > > #define ftype double > > +#define EPSILON (1.0 / (1LL << 51)) > > #endif > > You have FLT_EPSILON and DBL_EPSILON for this. > > Those are of different values. > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] lavu/random_seed: use getrandom() when available
On Sun, 9 Jul 2023, Anton Khirnov wrote: Quoting Marton Balint (2023-07-07 22:02:26) On Fri, 7 Jul 2023, Anton Khirnov wrote: It is a better interface for /dev/u?random on Linux, which avoids the issues associated with opening files. getrandom() actually have the same problem as read(). It can read less than requested. So you should use it in a loop in that case or if it returns EINTR. I'm not convinced it's actually a problem. This API is intended for small secrets like keys and such, somebody trying to generate vast quantities of random data is likely misusing it and could just as well use LFG or something. Failing in that case seems like a good thing to me. This is a very bad argument. If the API should not be used for big secrets, then it should always fail for size > 256 or something, not sometimes fail. And such limitation should be documented. And its not just about big secrets. EINTR can be returned for small secrets as well, and you should handle it. I also question if it is a good idea to use the non blocking mode. Imagine a situation when somebody wants to automatically start a command line after boot which needs a key. It might fail right after boot, but will work after a couple of minutes. IMHO it is better to block (1-2 minute tops) than making the function sometimes work, sometimes not. Regards, Marton ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] lavu/random_seed: use getrandom() when available
On 7/9/2023 1:23 PM, Marton Balint wrote: On Sun, 9 Jul 2023, Anton Khirnov wrote: Quoting Marton Balint (2023-07-07 22:02:26) On Fri, 7 Jul 2023, Anton Khirnov wrote: It is a better interface for /dev/u?random on Linux, which avoids the issues associated with opening files. getrandom() actually have the same problem as read(). It can read less than requested. So you should use it in a loop in that case or if it returns EINTR. I'm not convinced it's actually a problem. This API is intended for small secrets like keys and such, somebody trying to generate vast quantities of random data is likely misusing it and could just as well use LFG or something. Failing in that case seems like a good thing to me. This is a very bad argument. If the API should not be used for big secrets, then it should always fail for size > 256 or something, not sometimes fail. And such limitation should be documented. And its not just about big secrets. EINTR can be returned for small secrets as well, and you should handle it. I also question if it is a good idea to use the non blocking mode. Imagine a situation when somebody wants to automatically start a command line after boot which needs a key. It might fail right after boot, but will work after a couple of minutes. IMHO it is better to block (1-2 minute tops) than making the function sometimes work, sometimes not. If we make the urandom/getrandom() path block and potentially take 1-2 minutes, then I'd prefer if it's last in the function, after all available external implementations (Some of which can fail) were tried first. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] lavu/random_seed: use getrandom() when available
On Sun, 9 Jul 2023, James Almer wrote: On 7/9/2023 1:23 PM, Marton Balint wrote: On Sun, 9 Jul 2023, Anton Khirnov wrote: Quoting Marton Balint (2023-07-07 22:02:26) On Fri, 7 Jul 2023, Anton Khirnov wrote: It is a better interface for /dev/u?random on Linux, which avoids the issues associated with opening files. getrandom() actually have the same problem as read(). It can read less than requested. So you should use it in a loop in that case or if it returns EINTR. I'm not convinced it's actually a problem. This API is intended for small secrets like keys and such, somebody trying to generate vast quantities of random data is likely misusing it and could just as well use LFG or something. Failing in that case seems like a good thing to me. This is a very bad argument. If the API should not be used for big secrets, then it should always fail for size > 256 or something, not sometimes fail. And such limitation should be documented. And its not just about big secrets. EINTR can be returned for small secrets as well, and you should handle it. I also question if it is a good idea to use the non blocking mode. Imagine a situation when somebody wants to automatically start a command line after boot which needs a key. It might fail right after boot, but will work after a couple of minutes. IMHO it is better to block (1-2 minute tops) than making the function sometimes work, sometimes not. If we make the urandom/getrandom() path block and potentially take 1-2 minutes, then I'd prefer if it's last in the function, after all available external implementations (Some of which can fail) were tried first. It will take 1-2 minutes if it is right after boot and if the system has no support for quickly gathering entropy via some hardware feature... So it is not like /dev/random. It only waits until the CSPRNG of /dev/urandom initializes. I doubt external libraries can come up something significantly quicker, since they are also using the same system provided randomness for initialization... Regards, Marton ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avdevice/decklink_enc: use 64bit format string for BMD timebase instead of long long
On Sun, 2 Jul 2023, Marton Balint wrote: BMDTimeValue is defined as LONGLONG on Windows, but int64_t on Linux/Mac. Fixes format string warnings: libavdevice/decklink_enc.cpp: In function ‘void construct_cc(AVFormatContext*, decklink_ctx*, AVPacket*, klvanc_line_set_s*)’: libavdevice/decklink_enc.cpp:424:48: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘BMDTimeValue {aka long int}’ [-Wformat=] ctx->bmd_tb_num, ctx->bmd_tb_den); ~~~ ^ libavdevice/decklink_enc.cpp:424:48: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 5 has type ‘BMDTimeValue {aka long int}’ [-Wformat=] Will apply. Regards, Marton Signed-off-by: Marton Balint --- libavdevice/decklink_enc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp index 1809f79cac..ffd0ad9250 100644 --- a/libavdevice/decklink_enc.cpp +++ b/libavdevice/decklink_enc.cpp @@ -420,7 +420,7 @@ static void construct_cc(AVFormatContext *avctx, struct decklink_ctx *ctx, ret = klvanc_set_framerate_EIA_708B(cdp, ctx->bmd_tb_num, ctx->bmd_tb_den); if (ret) { -av_log(avctx, AV_LOG_ERROR, "Invalid framerate specified: %lld/%lld\n", +av_log(avctx, AV_LOG_ERROR, "Invalid framerate specified: %" PRId64 "/%" PRId64 "\n", ctx->bmd_tb_num, ctx->bmd_tb_den); klvanc_destroy_eia708_cdp(cdp); return; -- 2.35.3 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 1/7] avcodec/av1dec: remove FF_CODEC_CAP_SETS_PKT_DTS flag
It has no effect on receive_frame() decoders. Signed-off-by: James Almer --- libavcodec/av1dec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index e7f98a6c81..cc178464b9 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -1527,8 +1527,7 @@ const FFCodec ff_av1_decoder = { .close = av1_decode_free, FF_CODEC_RECEIVE_FRAME_CB(av1_receive_frame), .p.capabilities= AV_CODEC_CAP_DR1 | AV_CODEC_CAP_AVOID_PROBING, -.caps_internal = FF_CODEC_CAP_INIT_CLEANUP | - FF_CODEC_CAP_SETS_PKT_DTS, +.caps_internal = FF_CODEC_CAP_INIT_CLEANUP, .flush = av1_decode_flush, .p.profiles= NULL_IF_CONFIG_SMALL(ff_av1_profiles), .p.priv_class = &av1_class, -- 2.41.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/7] avcodec/libdav1d: remove FF_CODEC_CAP_SETS_PKT_DTS flag
It has no effect on receive_frame() decoders. Signed-off-by: James Almer --- libavcodec/libdav1d.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index c263157a2a..11cdbca274 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -698,7 +698,7 @@ const FFCodec ff_libdav1d_decoder = { .flush = libdav1d_flush, FF_CODEC_RECEIVE_FRAME_CB(libdav1d_receive_frame), .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS, -.caps_internal = FF_CODEC_CAP_SETS_PKT_DTS | FF_CODEC_CAP_SETS_FRAME_PROPS | +.caps_internal = FF_CODEC_CAP_SETS_FRAME_PROPS | FF_CODEC_CAP_AUTO_THREADS, .p.priv_class = &libdav1d_class, .p.wrapper_name = "libdav1d", -- 2.41.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 3/7] avcodec/mediacodecdec: remove FF_CODEC_CAP_SETS_PKT_DTS flag
It has no effect on receive_frame() decoders. Signed-off-by: James Almer --- libavcodec/mediacodecdec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c index 21464900d1..44f55947be 100644 --- a/libavcodec/mediacodecdec.c +++ b/libavcodec/mediacodecdec.c @@ -577,8 +577,7 @@ const FFCodec ff_ ## short_name ## _mediacodec_decoder = { .flush = mediacodec_decode_flush, \ .close = mediacodec_decode_close, \ .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, \ -.caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE | \ - FF_CODEC_CAP_SETS_PKT_DTS, \ +.caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE, \ .bsfs = bsf, \ .hw_configs = mediacodec_hw_configs, \ .p.wrapper_name = "mediacodec", \ -- 2.41.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 4/7] avcodec/mjpegdec: remove FF_CODEC_CAP_SETS_PKT_DTS flag
It has no effect on receive_frame() decoders. Signed-off-by: James Almer --- libavcodec/mjpegdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index ab7fa73819..b42e75bcdd 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -3110,6 +3110,6 @@ const FFCodec ff_smvjpeg_decoder = { .flush = decode_flush, .p.capabilities = AV_CODEC_CAP_DR1, .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | - FF_CODEC_CAP_SETS_PKT_DTS | FF_CODEC_CAP_INIT_CLEANUP, + FF_CODEC_CAP_INIT_CLEANUP, }; #endif -- 2.41.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 5/7] avcodec/mmaldec: remove FF_CODEC_CAP_SETS_PKT_DTS flag
It has no effect on receive_frame() decoders. Signed-off-by: James Almer --- libavcodec/mmaldec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavcodec/mmaldec.c b/libavcodec/mmaldec.c index 9bfb6778b6..8d67d10cd9 100644 --- a/libavcodec/mmaldec.c +++ b/libavcodec/mmaldec.c @@ -843,8 +843,7 @@ static const AVClass ffmmal_dec_class = { .flush = ffmmal_flush, \ .p.priv_class = &ffmmal_dec_class, \ .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE, \ -.caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE | \ - FF_CODEC_CAP_SETS_PKT_DTS, \ +.caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE \ .p.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_MMAL, \ AV_PIX_FMT_YUV420P, \ AV_PIX_FMT_NONE}, \ -- 2.41.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 6/7] avcodec/v4l2_m2m_dec: remove FF_CODEC_CAP_SETS_PKT_DTS flag
It has no effect on receive_frame() decoders. Signed-off-by: James Almer --- libavcodec/v4l2_m2m_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c index 4944d08511..aa2d759e1e 100644 --- a/libavcodec/v4l2_m2m_dec.c +++ b/libavcodec/v4l2_m2m_dec.c @@ -253,7 +253,7 @@ static const AVOption options[] = { .bsfs = bsf_name, \ .p.capabilities = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING, \ .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE | \ - FF_CODEC_CAP_SETS_PKT_DTS | FF_CODEC_CAP_INIT_CLEANUP, \ + FF_CODEC_CAP_INIT_CLEANUP, \ .p.wrapper_name = "v4l2m2m", \ } -- 2.41.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 7/7] avcodec/test/avcodec: check decoders for FF_CODEC_CAP_SETS_PKT_DTS
Ensure that only decode() callback ones set it. Signed-off-by: James Almer --- libavcodec/tests/avcodec.c | 4 1 file changed, 4 insertions(+) diff --git a/libavcodec/tests/avcodec.c b/libavcodec/tests/avcodec.c index bbf5289af2..08ca507bf0 100644 --- a/libavcodec/tests/avcodec.c +++ b/libavcodec/tests/avcodec.c @@ -175,6 +175,10 @@ int main(void){ !(codec->capabilities & AV_CODEC_CAP_FRAME_THREADS)) ERR("Decoder %s wants allocated progress without supporting" "frame threads\n"); +if (codec2->cb_type != FF_CODEC_CB_TYPE_DECODE && +codec2->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS) +ERR("Decoder %s is marked as setting pkt_dts when it doesn't have" +"any effect\n"); } if (priv_data_size_wrong(codec2)) ERR_EXT("Private context of codec %s is impossibly-sized (size %d).", -- 2.41.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v2 2/3] avcodec/decode: check the output frame for discard samples with all decoders
On 7/9/2023 10:39 AM, James Almer wrote: And not just those with the old decode() API. Signed-off-by: James Almer --- libavcodec/decode.c | 8 1 file changed, 8 insertions(+) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index a39af2d014..b3e4b066e5 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -597,6 +597,14 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) { ret = codec->cb.receive_frame(avctx, frame); emms_c(); +if (!ret) { +if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) +ret = (frame->flags & AV_FRAME_FLAG_DISCARD) ? AVERROR(EAGAIN) : 0; +else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { +int64_t discarded_samples = 0; +ret = discard_samples(avctx, frame, &discarded_samples); +} +} } else ret = decode_simple_receive_frame(avctx, frame); I'm withdrawing this patch for now. discard_samples() uses avci->last_pkt_props to fetch SKIP_SAMPLES packet side data which is not necessarily correct on receive_frame() decoders (like those setting FF_CODEC_CAP_SETS_FRAME_PROPS). ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v5] avformat/ivfenc: Set the "number of frames" in IVF header
Hi, On Thu, Jul 6, 2023 at 9:10 PM Dai, Jianhui J < jianhui.j.dai-at-intel@ffmpeg.org> wrote: > > -Original Message- > > From: ffmpeg-devel On Behalf Of Dai, > > Jianhui J > > Sent: Monday, July 3, 2023 12:26 PM > > To: ffmpeg-devel@ffmpeg.org > > Subject: [FFmpeg-devel] [PATCH v5] avformat/ivfenc: Set the "number of > > frames" in IVF header > > > > Should set "number of frames" to bytes 24-27 of IVF header, not duration. > > It is described by [1], and confirmed by parsing all IVF files in [2]. > > > > This commit also updates the md5sum of refs to pass fate-cbs. > > > > [1] Duck IVF - MultimediaWiki > > https://wiki.multimedia.cx/index.php/Duck_IVF > > > > [2] webm/vp8-test-vectors > > https://chromium.googlesource.com/webm/vp8-test-vectors > [..] > Another friendly ping reviewers to apply. > Some decoders will strictly check this field in IVF header, and it causes > failures for those decoders. > Merged. Ronald ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] libavcodec/ansi: fix ECMA-48 SGR parameter 49
As can be seen in man console_codes this parameter sets the default background color Signed-off-by: Jonas Lindner --- libavcodec/ansi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/ansi.c b/libavcodec/ansi.c index 49c3770c4c..d8d32bafbd 100644 --- a/libavcodec/ansi.c +++ b/libavcodec/ansi.c @@ -330,7 +330,7 @@ FF_ENABLE_DEPRECATION_WARNINGS s->bg = index < 16 ? ansi_to_cga[index] : index; i += 2; } else if (m == 49) { -s->fg = ansi_to_cga[DEFAULT_BG_COLOR]; +s->bg = ansi_to_cga[DEFAULT_BG_COLOR]; } else { avpriv_request_sample(avctx, "Unsupported rendition parameter"); } -- 2.34.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avcodec/decode: Return EAGAIN instead of overwriting unused packet
Should fix #10457, a regression caused by 69516ab3e917a6e91d26e38d04183c60fd71cbab. Signed-off-by: Andreas Rheinhardt --- I am not sure about this one. The problem is that avcodec_send_packet() and avcodec_receive_frame() must not return EAGAIN at the same time. If buffer_frame contains a frame when entering avcodec_send_packet(), the next call to avcodec_receive_frame() will not return EAGAIN. But is this actually guaranteed if buffer_pkt is not empty? libavcodec/decode.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 269633ce10..6595c3ca34 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -666,6 +666,9 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacke if (avpkt && !avpkt->size && avpkt->data) return AVERROR(EINVAL); +if (!AVPACKET_IS_EMPTY(avci->buffer_pkt)) +return AVERROR(EAGAIN); + av_packet_unref(avci->buffer_pkt); if (avpkt && (avpkt->data || avpkt->side_data_elems)) { ret = av_packet_ref(avci->buffer_pkt, avpkt); -- 2.34.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access
On Sat, Jul 08, 2023 at 11:25:13PM +0200, Michael Niedermayer wrote: > Signed-off-by: Michael Niedermayer > --- > libavradio/sdrdemux.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) will apply patchset [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I know you won't believe me, but the highest form of Human Excellence is to question oneself and others. -- Socrates signature.asc Description: PGP signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 1/5] avradio/sdrdemux: Factorize synchronous_am_demodulation* functions
Signed-off-by: Michael Niedermayer --- libavradio/sdrdemux.c | 56 --- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c index 7cc71b2cfb..92b218d899 100644 --- a/libavradio/sdrdemux.c +++ b/libavradio/sdrdemux.c @@ -616,43 +616,39 @@ static double find_am_carrier(SDRContext *sdr, const AVComplexFloat *data, int d } /** - * Demodulate with a carrier that is in the middle of the signal like in AM - * This will normalize the signal based on the carrier amplitude and subtract the carrier + * Demodulate with a carrier that is a N-th of the frequency. + * If N is one the carrier will be subtracted from the signal too. + * N==1 corresponds to classical AM, N>1 are demodulations with suppressed carriers. + * + * For N==1 and N==3 the signal will be normalized. For N==2 it will not be + * This is to avoid a sqrt() and happens to be what we want in the current use cases. + * + * The output will be scaled by the window. */ -static void synchronous_am_demodulation(AVComplexFloat *iblock, AVComplexFloat *icarrier, float *window, int len) +static av_always_inline void synchronous_am_demodulationN(AVComplexFloat *iblock, AVComplexFloat *icarrier, float *window, int len, int N) { +av_assert0(N>=1 && N<=3); //currently supported, trivial to add more if needed + for (int i = 0; i 0); +AVComplexFloat c2= {c.re*c.re, c.im*c.im}; +float den= w/(c2.re + c2.im); + +if (N==2) { +c.im *= c.re + c.re; +c.re = c2.re - c2.im; +} else if (N==3) { +den *= den; +c.re *= c2.re - 3*c2.im; +c.im *= 3*c2.re - c2.im; +} iblock[i].re = ( s.im*c.im + s.re*c.re) * den; iblock[i].im = ( s.im*c.re - s.re*c.im) * den; -iblock[i].re -= w; -} -} - -/** - * Demodulate with a carrier that is half the frequency and reduced amplitude - * This will not normalize the signal based on the carrier amplitude - */ -static void synchronous_am_demodulation2(AVComplexFloat *iblock, AVComplexFloat *icarrier, float *window, int len) -{ -for (int i = 0; i 0); - -c2.re = c.re*c.re - c.im*c.im; -c2.im = c.re*c.im + c.im*c.re; - -iblock[i].re = ( s.im*c2.im + s.re*c2.re) * den; -iblock[i].im = ( s.im*c2.re - s.re*c2.im) * den; +if (N==1) +iblock[i].re -= w; } } @@ -728,7 +724,7 @@ static int demodulate_am(SDRContext *sdr, int stream_index, AVPacket *pkt) sst->block[i] = sdr->block[index + i - len]; sst->ifft(sst->ifft_ctx, sst->icarrier, sst->block, sizeof(AVComplexFloat)); -synchronous_am_demodulation(sst->iblock, sst->icarrier, sst->window, 2*sst->block_size); +synchronous_am_demodulationN(sst->iblock, sst->icarrier, sst->window, 2*sst->block_size, 1); scale = 0.9; } else { // Synchronous demodulation using Macleod based systhesized carrier @@ -997,7 +993,7 @@ static int demodulate_fm(SDRContext *sdr, int stream_index, AVPacket *pkt) apply_deemphasis(sdr, sst->block + i + 2*carrier19_i - 2*shift, sst->block_size_p2, sample_rate_p2, + 1); apply_deemphasis(sdr, sst->block + i + 2*carrier19_i - 2*shift, sst->block_size_p2, sample_rate_p2, - 1); sst->ifft_p2(sst->ifft_p2_ctx, sst->iside , sst->block + i, sizeof(AVComplexFloat)); -synchronous_am_demodulation2(sst->iside, sst->icarrier, sst->window_p2, 2*sst->block_size_p2); +synchronous_am_demodulationN(sst->iside, sst->icarrier, sst->window_p2, 2*sst->block_size_p2, 2); } memset(sst->block + len17_i, 0, (2*sst->block_size_p2 - len17_i) * sizeof(AVComplexFloat)); apply_deemphasis(sdr, sst->block, 2*sst->block_size_p2, sample_rate_p2, + 1); -- 2.31.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/5] avradio/sdrdemux: shift 19khz carrier differntly
This simplifies the following commits Signed-off-by: Michael Niedermayer --- libavradio/sdrdemux.c | 12 +++- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c index 92b218d899..ef8a8a91d3 100644 --- a/libavradio/sdrdemux.c +++ b/libavradio/sdrdemux.c @@ -983,15 +983,17 @@ static int demodulate_fm(SDRContext *sdr, int stream_index, AVPacket *pkt) carrier19_i = lrint(carrier19_i_exact); if (carrier19_i >= 0) { -int shift = carrier19_i/2; i = sst->block_size; memset(sst->block + i, 0, 2*sst->block_size_p2 * sizeof(AVComplexFloat)); -memcpy(sst->block + i + carrier19_i - W - shift , sst->block + carrier19_i - W, sizeof(AVComplexFloat)*(2*W+1)); +memcpy(sst->block + i, sst->block + carrier19_i, sizeof(AVComplexFloat)*(W+1)); +memcpy(sst->block + i + 2*sst->block_size_p2 - W, sst->block + carrier19_i - W, sizeof(AVComplexFloat)*W); sst->ifft_p2(sst->ifft_p2_ctx, sst->icarrier, sst->block + i, sizeof(AVComplexFloat)); -memcpy(sst->block + i + 2*carrier19_i - 2*shift - len17_i, sst->block + 2*carrier19_i - len17_i, sizeof(AVComplexFloat)*2*len17_i); -apply_deemphasis(sdr, sst->block + i + 2*carrier19_i - 2*shift, sst->block_size_p2, sample_rate_p2, + 1); -apply_deemphasis(sdr, sst->block + i + 2*carrier19_i - 2*shift, sst->block_size_p2, sample_rate_p2, - 1); +memcpy(sst->block + i, sst->block + 2*carrier19_i, sizeof(AVComplexFloat)*len17_i); +memcpy(sst->block + i + 2*sst->block_size_p2 - len17_i, sst->block + 2*carrier19_i - len17_i, sizeof(AVComplexFloat)*len17_i); + +apply_deemphasis(sdr, sst->block + i, sst->block_size_p2, sample_rate_p2, + 1); +apply_deemphasis(sdr, sst->block + i + 2*sst->block_size_p2, sst->block_size_p2, sample_rate_p2, - 1); sst->ifft_p2(sst->ifft_p2_ctx, sst->iside , sst->block + i, sizeof(AVComplexFloat)); synchronous_am_demodulationN(sst->iside, sst->icarrier, sst->window_p2, 2*sst->block_size_p2, 2); } -- 2.31.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 3/5] avradio/sdrdemux: only allocare iside and window_p2 when needed
Signed-off-by: Michael Niedermayer --- libavradio/sdrdemux.c | 17 ++--- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c index ef8a8a91d3..36b8aac2fb 100644 --- a/libavradio/sdrdemux.c +++ b/libavradio/sdrdemux.c @@ -1136,16 +1136,23 @@ static int setup_stream(SDRContext *sdr, int stream_index, Station *station) if (ret < 0) return ret; +sst->window_p2 = av_malloc(sizeof(*sst->window_p2)* 2 * sst->block_size_p2); +sst->iside = av_malloc(sizeof(*sst->iside)* 2 * sst->block_size_p2); +if (!sst->iside || !sst->window_p2) +return AVERROR(ENOMEM); + +avpriv_kbd_window_init(sst->window_p2, sdr->kbd_alpha, sst->block_size_p2); +for(int i = sst->block_size_p2; i < 2 * sst->block_size_p2; i++) { +sst->window_p2[i] = sst->window_p2[2*sst->block_size_p2 - i - 1]; +} } sst->out_buf = av_malloc(sizeof(*sst->out_buf) * 2 * sst->block_size); sst->block = av_malloc(sizeof(*sst-> block) * 2 * sst->block_size); sst->iblock= av_malloc(sizeof(*sst->iblock) * 2 * sst->block_size); sst->icarrier = av_malloc(sizeof(*sst->icarrier) * 2 * sst->block_size); -sst->iside = av_malloc(sizeof(*sst->iside)* 2 * sst->block_size_p2); sst->window= av_malloc(sizeof(*sst->window) * 2 * sst->block_size); -sst->window_p2 = av_malloc(sizeof(*sst->window_p2)* 2 * sst->block_size_p2); -if (!sst->out_buf || !sst->block || !sst->iblock || !sst->icarrier || !sst->iside || !sst->window || !sst->window_p2) +if (!sst->out_buf || !sst->block || !sst->iblock || !sst->icarrier || !sst->window) return AVERROR(ENOMEM); avpriv_kbd_window_init(sst->window, sdr->kbd_alpha, sst->block_size); @@ -1153,10 +1160,6 @@ static int setup_stream(SDRContext *sdr, int stream_index, Station *station) sst->window[i] = sst->window[2*sst->block_size - i - 1]; } -avpriv_kbd_window_init(sst->window_p2, sdr->kbd_alpha, sst->block_size_p2); -for(int i = sst->block_size_p2; i < 2 * sst->block_size_p2; i++) { -sst->window_p2[i] = sst->window_p2[2*sst->block_size_p2 - i - 1]; -} sst->am_amplitude = 0; } -- 2.31.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 4/5] avradio/sdrdemux: factor block_time out
Signed-off-by: Michael Niedermayer --- libavradio/sdrdemux.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c index 36b8aac2fb..0cad9a2d3a 100644 --- a/libavradio/sdrdemux.c +++ b/libavradio/sdrdemux.c @@ -1099,6 +1099,7 @@ static int setup_stream(SDRContext *sdr, int stream_index, Station *station) AVFormatContext *s = sdr->avfmt; AVStream *st = s->streams[stream_index]; SDRStream *sst = st->priv_data; +double block_time = sdr->block_size / (double)sdr->sdr_sample_rate; int ret; //For now we expect each station to be only demodulated once, nothing should break though if its done more often @@ -1116,7 +1117,7 @@ static int setup_stream(SDRContext *sdr, int stream_index, Station *station) if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { free_stream(sdr, stream_index); -for (sst->block_size = 4; 2ll *sst->station->bandwidth * sdr->block_size / sdr->sdr_sample_rate > sst->block_size; sst->block_size <<= 1) +for (sst->block_size = 4; 2ll *sst->station->bandwidth * block_time > sst->block_size; sst->block_size <<= 1) ; sst->block_size = FFMIN(sdr->block_size, sst->block_size); @@ -1130,7 +1131,7 @@ static int setup_stream(SDRContext *sdr, int stream_index, Station *station) if (ret < 0) return ret; -for (sst->block_size_p2 = 4; 2ll *sst->station->bandwidth_p2 * sdr->block_size / sdr->sdr_sample_rate > sst->block_size_p2; sst->block_size_p2 <<= 1) +for (sst->block_size_p2 = 4; 2ll *sst->station->bandwidth_p2 * block_time > sst->block_size_p2; sst->block_size_p2 <<= 1) ; ret = av_tx_init(&sst->ifft_p2_ctx, &sst->ifft_p2, AV_TX_FLOAT_FFT, 1, 2*sst->block_size_p2, NULL, 0); if (ret < 0) -- 2.31.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 5/5] avradio: RDS support
Signed-off-by: Michael Niedermayer --- libavradio/Makefile | 4 +- libavradio/rds.c| 203 libavradio/sdr.h| 13 ++- libavradio/sdrdemux.c | 18 +++- libavradio/vissualize.c | 13 ++- 5 files changed, 240 insertions(+), 11 deletions(-) create mode 100644 libavradio/rds.c diff --git a/libavradio/Makefile b/libavradio/Makefile index 40b38f798e..5efc2588c3 100644 --- a/libavradio/Makefile +++ b/libavradio/Makefile @@ -11,5 +11,5 @@ OBJS= allradios.o \ # input/output radios -OBJS-$(CONFIG_SDR_INRADIO) += sdrinradio.o vissualize.o -OBJS-$(CONFIG_SDRFILE_INRADIO) += sdrdemux.o vissualize.o +OBJS-$(CONFIG_SDR_INRADIO) += sdrinradio.o vissualize.o rds.o +OBJS-$(CONFIG_SDRFILE_INRADIO) += sdrdemux.o vissualize.o rds.o diff --git a/libavradio/rds.c b/libavradio/rds.c new file mode 100644 index 00..dd9a934c3c --- /dev/null +++ b/libavradio/rds.c @@ -0,0 +1,203 @@ +/* + * RDS + * Copyright (c) 2023 Michael Niedermayer + * + * 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 + */ + +/** + * @file + * + * + */ + +#include "sdr.h" + +#include +#include "libavutil/avassert.h" +#include "libavutil/ffmath.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/opt.h" +#include "libavformat/avformat.h" +#include "libavformat/demux.h" + +/** + * Check and correct RDS block + * @param[out] group the data bits are returned here + * @param block block nu,ber (0 to 3) + * @return 1 if correctable single bit error, 0 if no error, >99 if non correctable errors + */ +static int check_rds_block(uint16_t group[4], const float diff[104], int block) +{ +#define RDS_G 0x5B9 //101 1011 1001 +static const uint16_t offset[4] = {0x0FC, 0x198, 0x168, 0x1B4}; +unsigned codeword = 0; +unsigned syndrom = 0; +//we carry floats through to here so we can do a soft decission decoder +//ATM lets just do hard decission decoding that should be more than good enough + +//FIXME we could do this more efficiently but does it matter? +for(int i=0; i<26; i++) { +int bit = (diff[i + block*26]<0); +codeword += codeword + bit; +syndrom += syndrom + bit; +if (syndrom & (1<<10)) +syndrom ^= RDS_G; +} +if (block==2 && (group[1]&0x800)) { +syndrom ^= 0x350; +}else +syndrom ^= offset[block]; +//FIXME the spec talks about a special case of a 0 offset used in the USA + +group[block] = codeword >> 10; + +// try correcting some basic errors +if (syndrom) { +for (unsigned e = 1; e <= 2; e ++) { +unsigned mask = 255 >> (8-e); +unsigned syndrom1 = mask; +for(int i=0; i<27-e; i++) { +if (syndrom == syndrom1) { +group[block] ^= (mask<> 10; +return e; +} +syndrom1 += syndrom1; +if (syndrom1 & (1<<10)) +syndrom1 ^= RDS_G; +} +} +return 100; // this is a good place do a 2nd pass with a soft decssion multi bit decoder +} + +return 0; +} + +static int decode_rds_group(SDRContext *sdr, SDRStream *sst, uint16_t group[4]) +{ +Station *station = sst->station; +int pi = group[0]; +int a = group[1] >> 12; +int b = group[1] & 0x800; +int tp = group[1] & 0x400; +int pty= (group[1] >> 5) & 0x1F; + +switch(a) { +case 0: +AV_WB16(station->name + 2*(group[1]&3), group[3]); +break; +case 2: +if (b) { +AV_WB16(station->radiotext + 2*(group[1]&15), group[3]); +} else { +AV_WB16(station->radiotext + 4*(group[1]&15), group[2]); +AV_WB16(station->radiotext + 4*(group[1]&15) + 2, group[3]); +} +break; +case 10: +if (b==0) { +AV_WB16(station->programm_type_name + 4*(group[1]&1), group[2]); +AV_WB16(station->programm_type_name + 4*(group[1]&1) + 2, group[3]); +} +break; +// case 14: +// break; +default: +av_log(sdr->avfmt, AV_LOG_DEBUG, "RDS: PI %X, A %X B %X PTY %X\n",
[FFmpeg-devel] [PATCH] avcodec/hevc_ps: Improve PPS SCC extension bit depth check
>From the spec: "It is a requirement of bitstream conformance that the value of luma_bit_depth_entry_minus8 shall be equal to the value of bit_depth_luma_minus8"; similarly for chroma. Should fix Coverity ticket #1529226. Signed-off-by: Andreas Rheinhardt --- libavcodec/hevc_ps.c | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index 4c4c1e2c17..1db2d3a242 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -1581,11 +1581,13 @@ static int pps_scc_extension(GetBitContext *gb, AVCodecContext *avctx, } pps->monochrome_palette_flag = get_bits1(gb); pps->luma_bit_depth_entry = get_ue_golomb_31(gb) + 8; -if (!pps->monochrome_palette_flag) -pps->chroma_bit_depth_entry = get_ue_golomb_31(gb) + 8; - -if (pps->chroma_bit_depth_entry > 16 || pps->chroma_bit_depth_entry > 16) +if (pps->luma_bit_depth_entry != sps->bit_depth) return AVERROR_INVALIDDATA; +if (!pps->monochrome_palette_flag) { +pps->chroma_bit_depth_entry = get_ue_golomb_31(gb) + 8; +if (pps->chroma_bit_depth_entry != sps->bit_depth_chroma) +return AVERROR_INVALIDDATA; +} num_comps = pps->monochrome_palette_flag ? 1 : 3; for (int comp = 0; comp < num_comps; comp++) { -- 2.34.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avcodec/hevc_ps: Improve PPS SCC extension bit depth check
On 7/9/2023 9:19 PM, Andreas Rheinhardt wrote: From the spec: "It is a requirement of bitstream conformance that the value of luma_bit_depth_entry_minus8 shall be equal to the value of bit_depth_luma_minus8"; similarly for chroma. Should fix Coverity ticket #1529226. Signed-off-by: Andreas Rheinhardt --- libavcodec/hevc_ps.c | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index 4c4c1e2c17..1db2d3a242 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -1581,11 +1581,13 @@ static int pps_scc_extension(GetBitContext *gb, AVCodecContext *avctx, } pps->monochrome_palette_flag = get_bits1(gb); pps->luma_bit_depth_entry = get_ue_golomb_31(gb) + 8; -if (!pps->monochrome_palette_flag) -pps->chroma_bit_depth_entry = get_ue_golomb_31(gb) + 8; - -if (pps->chroma_bit_depth_entry > 16 || pps->chroma_bit_depth_entry > 16) Is Coverity complaining about this duplicate check? If so, you should mention that fixing the Coverity issue is a side effect of the compliance check you're applying, rather than the actual objective of the change. You could also replace one chroma_bit_depth_entry check with luma_bit_depth_entry in one commit, fixing the Coverity issue, then this compliance change in another. +if (pps->luma_bit_depth_entry != sps->bit_depth) return AVERROR_INVALIDDATA; +if (!pps->monochrome_palette_flag) { +pps->chroma_bit_depth_entry = get_ue_golomb_31(gb) + 8; +if (pps->chroma_bit_depth_entry != sps->bit_depth_chroma) +return AVERROR_INVALIDDATA; +} num_comps = pps->monochrome_palette_flag ? 1 : 3; for (int comp = 0; comp < num_comps; comp++) { LGTM either way. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avcodec/hevc_ps: Improve PPS SCC extension bit depth check
James Almer: > On 7/9/2023 9:19 PM, Andreas Rheinhardt wrote: >> From the spec: "It is a requirement of bitstream conformance that >> the value of luma_bit_depth_entry_minus8 shall be equal to >> the value of bit_depth_luma_minus8"; similarly for chroma. >> >> Should fix Coverity ticket #1529226. >> >> Signed-off-by: Andreas Rheinhardt >> --- >> libavcodec/hevc_ps.c | 10 ++ >> 1 file changed, 6 insertions(+), 4 deletions(-) >> >> diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c >> index 4c4c1e2c17..1db2d3a242 100644 >> --- a/libavcodec/hevc_ps.c >> +++ b/libavcodec/hevc_ps.c >> @@ -1581,11 +1581,13 @@ static int pps_scc_extension(GetBitContext >> *gb, AVCodecContext *avctx, >> } >> pps->monochrome_palette_flag = get_bits1(gb); >> pps->luma_bit_depth_entry = get_ue_golomb_31(gb) + 8; >> - if (!pps->monochrome_palette_flag) >> - pps->chroma_bit_depth_entry = get_ue_golomb_31(gb) + 8; >> - >> - if (pps->chroma_bit_depth_entry > 16 || >> pps->chroma_bit_depth_entry > 16) > > Is Coverity complaining about this duplicate check? If so, you should > mention that fixing the Coverity issue is a side effect of the > compliance check you're applying, rather than the actual objective of > the change. It's indeed about this duplicate check. It's how I found this issue. > > You could also replace one chroma_bit_depth_entry check with > luma_bit_depth_entry in one commit, fixing the Coverity issue, then this > compliance change in another. > I don't see why separating this in two commits would be beneficial (except for my commit count, but I don't intentionally maximise that). Patches are typically split into smaller parts to ease reviewing, but this change is trivial either way (but a tiny bit less trivial when split). >> + if (pps->luma_bit_depth_entry != sps->bit_depth) >> return AVERROR_INVALIDDATA; >> + if (!pps->monochrome_palette_flag) { >> + pps->chroma_bit_depth_entry = get_ue_golomb_31(gb) + 8; >> + if (pps->chroma_bit_depth_entry != >> sps->bit_depth_chroma) >> + return AVERROR_INVALIDDATA; >> + } >> num_comps = pps->monochrome_palette_flag ? 1 : 3; >> for (int comp = 0; comp < num_comps; comp++) { > > LGTM either way. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v6 0/1] avformat: add Software Defined Radio support
Jul 3, 2023, 00:46 by mich...@niedermayer.cc: > On Mon, Jul 03, 2023 at 12:03:10AM +0200, Lynne wrote: > >> Jul 2, 2023, 23:15 by mich...@niedermayer.cc: >> >> > On Sun, Jul 02, 2023 at 08:55:40PM +0200, Lynne wrote: >> > >> >> Jul 2, 2023, 13:01 by mich...@niedermayer.cc: >> >> >> >> > On Fri, Jun 30, 2023 at 04:38:46PM +0200, Jean-Baptiste Kempf wrote: >> >> > >> >> >> On Fri, 30 Jun 2023, at 16:08, Michael Niedermayer wrote: >> >> >> > Also as said previously, If there is at least a 2nd developer working >> >> >> > on this then we could & should move this to a seperate libraray >> >> >> > (libavradio) >> >> >> >> >> >> Why wait for a 2nd dev? >> >> >> >> >> > >> >> > as libavradio so far has been the only actionable suggestion. >> >> > ill move the code to that and next revission or the one after that >> >> > will be in libavradio. >> >> > >> >> > thx >> >> > >> >> >> >> Could you move it to another repository which other developers >> >> have access to, like nv-codec-headers? It'll still be an official library >> >> of the project, and patches for it should still be sent to this ML, >> >> but it would keep the main repo from becoming a monorepo. >> >> >> > >> > Yes >> > https://git.ffmpeg.org/libavradio >> > g...@git.ffmpeg.org:libavradio >> > >> > everyone should have acess, but keys a syced from videolan a while ago, so >> > if someones is missing, mail me >> > >> > PS: i found a DAB library that i think can take raw IQ data and return >> > AAC frames. With that adding DAB support should be alot more practical >> > than a full implementation of all layers of DAB >> > >> >> Thanks. I look forward to see what becomes of it. >> Whilst you're at it, could you also make an empty repo >> for my streaming protocol/container, with the same access >> permissions? It should be named "avstream", without "lib", >> as it contains specifications and a reference library, like nut. >> > > created: > https://git.ffmpeg.org/avstream > g...@git.ffmpeg.org:avstream > > you have power do do non fast forward pushes if need arrises > git log mail should go to ffmpeg-cvs...@ffmpeg.org > emailmaxlines= 1 > Thanks Sadly, the name has too many conflicts, both with us and other projects Could you rename the repo to avtransport? I've left it empty, so you can just delete + recreate it. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".