[FFmpeg-devel] [PATCH] Added support for HEVC in V4L2 avdevice library. Validated with: LD_PRELOAD=$HOME/lib/libavdevice.so ffplay -f video4linux2 -input_format hevc /dev/video0
--- libavdevice/v4l2-common.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavdevice/v4l2-common.c b/libavdevice/v4l2-common.c index b5b4448a31..353e83efdd 100644 --- a/libavdevice/v4l2-common.c +++ b/libavdevice/v4l2-common.c @@ -55,6 +55,9 @@ const struct fmt_map ff_fmt_conversion_table[] = { #ifdef V4L2_PIX_FMT_H264 { AV_PIX_FMT_NONE,AV_CODEC_ID_H264, V4L2_PIX_FMT_H264}, #endif +#ifdef V4L2_PIX_FMT_HEVC +{ AV_PIX_FMT_NONE,AV_CODEC_ID_HEVC, V4L2_PIX_FMT_HEVC}, +#endif #ifdef V4L2_PIX_FMT_MPEG4 { AV_PIX_FMT_NONE,AV_CODEC_ID_MPEG4,V4L2_PIX_FMT_MPEG4 }, #endif -- 2.35.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] avdevice: Added support for HEVC (codec/pixfmt) in V4L2.
--- libavdevice/v4l2-common.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavdevice/v4l2-common.c b/libavdevice/v4l2-common.c index b5b4448a31..353e83efdd 100644 --- a/libavdevice/v4l2-common.c +++ b/libavdevice/v4l2-common.c @@ -55,6 +55,9 @@ const struct fmt_map ff_fmt_conversion_table[] = { #ifdef V4L2_PIX_FMT_H264 { AV_PIX_FMT_NONE,AV_CODEC_ID_H264, V4L2_PIX_FMT_H264}, #endif +#ifdef V4L2_PIX_FMT_HEVC +{ AV_PIX_FMT_NONE,AV_CODEC_ID_HEVC, V4L2_PIX_FMT_HEVC}, +#endif #ifdef V4L2_PIX_FMT_MPEG4 { AV_PIX_FMT_NONE,AV_CODEC_ID_MPEG4,V4L2_PIX_FMT_MPEG4 }, #endif -- 2.35.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 2/5] avcodec/wavpack: Fix overflow in k=31
On Thu, Dec 1, 2022 at 8:56 PM Michael Niedermayer wrote: > On Wed, Nov 30, 2022 at 09:39:44PM +0100, Paul B Mahol wrote: > > On 9/11/22, Michael Niedermayer wrote: > > > Untested with "non fuzzed" samples as i have no such file > > > > > > > Then create it. > > the official WavPack-5.6.0 decoder has 2 alternative optimized codepathes > #ifdef USE_BITMASK_TABLES > extras = bitset [bitcount] - maxcode - 1; > #else > extras = (1 << bitcount) - maxcode - 1; > #endif > > The 2nd path would result in the same 1<<32 which is undefined but luckily > the first seems hardcoded to be used it uses this table: > > const uint32_t bitset [] = { > 1L << 0, 1L << 1, 1L << 2, 1L << 3, > 1L << 4, 1L << 5, 1L << 6, 1L << 7, > 1L << 8, 1L << 9, 1L << 10, 1L << 11, > 1L << 12, 1L << 13, 1L << 14, 1L << 15, > 1L << 16, 1L << 17, 1L << 18, 1L << 19, > 1L << 20, 1L << 21, 1L << 22, 1L << 23, > 1L << 24, 1L << 25, 1L << 26, 1L << 27, > 1L << 28, 1L << 29, 1L << 30, 1L << 31 > }; > > here bitset[32] is out of array > > Given above i suspect no valid file should use this. Otherwise something > seriously odd is going on. > > also the subject has a typo its p=31 not k=31 > > thx > OK > > [...] > > -- > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB > > The real ebay dictionary, page 2 > "100% positive feedback" - "All either got their money back or didnt > complain" > "Best seller ever, very honest" - "Seller refunded buyer after failed scam" > ___ > 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/2] avcodec/jpeg2000dec: Move decoder structs to header files
From: caleb --- libavcodec/jpeg2000dec.c | 96 + libavcodec/jpeg2000dec.h | 126 +++ 2 files changed, 127 insertions(+), 95 deletions(-) create mode 100644 libavcodec/jpeg2000dec.h diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index c2b81ec103..7fc09cb558 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -42,101 +42,7 @@ #include "jpeg2000.h" #include "jpeg2000dsp.h" #include "profiles.h" - -#define JP2_SIG_TYPE0x6A502020 -#define JP2_SIG_VALUE 0x0D0A870A -#define JP2_CODESTREAM 0x6A703263 -#define JP2_HEADER 0x6A703268 - -#define HAD_COC 0x01 -#define HAD_QCC 0x02 - -#define MAX_POCS 32 - -typedef struct Jpeg2000POCEntry { -uint16_t LYEpoc; -uint16_t CSpoc; -uint16_t CEpoc; -uint8_t RSpoc; -uint8_t REpoc; -uint8_t Ppoc; -} Jpeg2000POCEntry; - -typedef struct Jpeg2000POC { -Jpeg2000POCEntry poc[MAX_POCS]; -int nb_poc; -int is_default; -} Jpeg2000POC; - -typedef struct Jpeg2000TilePart { -uint8_t tile_index; // Tile index who refers the tile-part -const uint8_t *tp_end; -GetByteContext header_tpg; // bit stream of header if PPM header is used -GetByteContext tpg; // bit stream in tile-part -} Jpeg2000TilePart; - -/* RMK: For JPEG2000 DCINEMA 3 tile-parts in a tile - * one per component, so tile_part elements have a size of 3 */ -typedef struct Jpeg2000Tile { -Jpeg2000Component *comp; -uint8_t properties[4]; -Jpeg2000CodingStyle codsty[4]; -Jpeg2000QuantStyle qntsty[4]; -Jpeg2000POC poc; -Jpeg2000TileParttile_part[32]; -uint8_t has_ppt;// whether this tile has a ppt marker -uint8_t *packed_headers;// contains packed headers. Used only along with PPT marker -int packed_headers_size;// size in bytes of the packed headers -GetByteContext packed_headers_stream; // byte context corresponding to packed headers -uint16_t tp_idx;// Tile-part index -int coord[2][2];// border coordinates {{x0, x1}, {y0, y1}} -} Jpeg2000Tile; - -typedef struct Jpeg2000DecoderContext { -AVClass *class; -AVCodecContext *avctx; -GetByteContext g; - -int width, height; -int image_offset_x, image_offset_y; -int tile_offset_x, tile_offset_y; -uint8_t cbps[4];// bits per sample in particular components -uint8_t sgnd[4];// if a component is signed -uint8_t properties[4]; - -uint8_t has_ppm; -uint8_t *packed_headers; // contains packed headers. Used only along with PPM marker -int packed_headers_size; -GetByteContext packed_headers_stream; -uint8_t in_tile_headers; - -int cdx[4], cdy[4]; -int precision; -int ncomponents; -int colour_space; -uint32_tpalette[256]; -int8_t pal8; -int cdef[4]; -int tile_width, tile_height; -unsignednumXtiles, numYtiles; -int maxtilelen; -AVRational sar; - -Jpeg2000CodingStyle codsty[4]; -Jpeg2000QuantStyle qntsty[4]; -Jpeg2000POC poc; -uint8_t roi_shift[4]; - -int bit_index; - -int curtileno; - -Jpeg2000Tile*tile; -Jpeg2000DSPContext dsp; - -/*options parameters*/ -int reduction_factor; -} Jpeg2000DecoderContext; +#include "jpeg2000dec.h" /* get_bits functions for JPEG2000 packet bitstream * It is a get_bit function with a bit-stuffing routine. If the value of the diff --git a/libavcodec/jpeg2000dec.h b/libavcodec/jpeg2000dec.h new file mode 100644 index 00..b6410c1432 --- /dev/null +++ b/libavcodec/jpeg2000dec.h @@ -0,0 +1,126 @@ +/* + * JPEG 2000 image decoder + * Copyright (c) 2007 Kamil Nowosad + * Copyright (c) 2013 Nicolas Bertrand + * Copyright (c) 2022 Caleb Etemesi + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_JPEG2000DEC_H
[FFmpeg-devel] [PATCH 2/2] avcodec/jpeg2000dec: Add support for HTJ2K decoding.
From: caleb This patch adds support for HTJ2K decoding in FFMPEG. This is a revised patch with suggested changes from earlier and fixes some bugs that were in the first version. The paper describing HTJ2K can be found at https://htj2k.com/wp-content/uploads/white-paper.pdf --- libavcodec/Makefile|2 +- libavcodec/jpeg2000.h |3 + libavcodec/jpeg2000dec.c | 69 +- libavcodec/jpeg2000dec.h |2 + libavcodec/jpeg2000htdec.c | 1434 libavcodec/jpeg2000htdec.h | 28 + 6 files changed, 1522 insertions(+), 16 deletions(-) create mode 100644 libavcodec/jpeg2000htdec.c create mode 100644 libavcodec/jpeg2000htdec.h diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 98841ed07c..1ba9e09528 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -464,7 +464,7 @@ OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o ass.o OBJS-$(CONFIG_JPEG2000_ENCODER)+= j2kenc.o mqcenc.o mqc.o jpeg2000.o \ jpeg2000dwt.o OBJS-$(CONFIG_JPEG2000_DECODER)+= jpeg2000dec.o jpeg2000.o jpeg2000dsp.o \ - jpeg2000dwt.o mqcdec.o mqc.o + jpeg2000dwt.o mqcdec.o mqc.o jpeg2000htdec.o OBJS-$(CONFIG_JPEGLS_DECODER) += jpeglsdec.o jpegls.o OBJS-$(CONFIG_JPEGLS_ENCODER) += jpeglsenc.o jpegls.o OBJS-$(CONFIG_JV_DECODER) += jvdec.o diff --git a/libavcodec/jpeg2000.h b/libavcodec/jpeg2000.h index e5ecb4cbf9..b2a8e13244 100644 --- a/libavcodec/jpeg2000.h +++ b/libavcodec/jpeg2000.h @@ -189,6 +189,9 @@ typedef struct Jpeg2000Cblk { Jpeg2000Pass *passes; Jpeg2000Layer *layers; int coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} +/*HTJ2K settings */ +int zbp; +int pass_lengths[2]; } Jpeg2000Cblk; // code block typedef struct Jpeg2000Prec { diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 7fc09cb558..5c92baa88e 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -43,6 +43,7 @@ #include "jpeg2000dsp.h" #include "profiles.h" #include "jpeg2000dec.h" +#include "jpeg2000htdec.h" /* get_bits functions for JPEG2000 packet bitstream * It is a get_bit function with a bit-stuffing routine. If the value of the @@ -428,12 +429,13 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c) c->cblk_style = bytestream2_get_byteu(&s->g); if (c->cblk_style != 0) { // cblk style if (c->cblk_style & JPEG2000_CTSY_HTJ2K_M || c->cblk_style & JPEG2000_CTSY_HTJ2K_F) { -av_log(s->avctx, AV_LOG_ERROR, "Support for High throughput JPEG 2000 is not yet available\n"); -return AVERROR_PATCHWELCOME; +av_log(s->avctx,AV_LOG_TRACE,"High Throughput jpeg 2000 codestream.\n"); +s->is_htj2k = 1; +} else { +av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style); +if (c->cblk_style & JPEG2000_CBLK_BYPASS) +av_log(s->avctx, AV_LOG_WARNING, "Selective arithmetic coding bypass\n"); } -av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style); -if (c->cblk_style & JPEG2000_CBLK_BYPASS) -av_log(s->avctx, AV_LOG_WARNING, "Selective arithmetic coding bypass\n"); } c->transform = bytestream2_get_byteu(&s->g); // DWT transformation type /* set integer 9/7 DWT in case of BITEXACT flag */ @@ -1058,13 +1060,15 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile, return incl; if (!cblk->npasses) { -int v = expn[bandno] + numgbits - 1 - -tag_tree_decode(s, prec->zerobits + cblkno, 100); +int zbp = tag_tree_decode(s,prec->zerobits + cblkno, 100); +int v = expn[bandno] + numgbits - 1 - zbp; + if (v < 0 || v > 30) { av_log(s->avctx, AV_LOG_ERROR, "nonzerobits %d invalid or unsupported\n", v); return AVERROR_INVALIDDATA; } +cblk->zbp = zbp; cblk->nonzerobits = v; } if ((newpasses = getnpasses(s)) < 0) @@ -1105,8 +1109,29 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile, } } -if ((ret = get_bits(s, av_log2(newpasses1) + cblk->lblock)) < 0) -return ret; +if (newpasses > 1 && s->is_htj2k) { +// Retrieve pass lengths for each pass +int href_passes = (cblk->npasses + newpasses - 1) % 3; +int segment_passes = newpasses - href_passes; +int pass_bound = 2; +int eb = 0; +int extra_bit = newpasses > 2 ? 1 : 0;
Re: [FFmpeg-devel] [PATCH 1/2] avcodec/jpeg2000dec: Move decoder structs to header files
fre 2022-12-02 klockan 21:10 +0300 skrev etemesica...@gmail.com: > From: caleb Speak of the devil :) > > --- > libavcodec/jpeg2000dec.c | 96 + > libavcodec/jpeg2000dec.h | 126 > +++ > 2 files changed, 127 insertions(+), 95 deletions(-) > create mode 100644 libavcodec/jpeg2000dec.h Looks OK /Tomas ___ 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 2/2] avcodec/jpeg2000dec: Add support for HTJ2K decoding.
fre 2022-12-02 klockan 21:11 +0300 skrev etemesica...@gmail.com: > > +/** > + * Given a precomputed c, checks whether n % d == 0 > + */ > +static av_always_inline uint32_t is_divisible(uint32_t n, uint64_t > c) > +{ > + return n * c <= c - 1; > +} This looks like something that could go in lavu, say intmath.h > + > +/** > + * @brief Refill the buffer backwards in little Endian while > skipping > + * over stuffing bits > + * > + * Stuffing bits are those that appear in the position of any byte > whose > + * LSBs are all 1's if the last consumed byte was larger than 0x8F > + */ > +static int jpeg2000_bitbuf_refill_backwards(StateVars *buffer, > + const uint8_t *array) Don't we already have sufficient bitreading capabilities already? Maybe it doesn't do the necessary unstuffing.. > + /* > + * As an optimization, we can replace modulo operations with > + * checking if a number is divisible , since that's the only > thing we need. > + * this is paired with is_divisible. > + * Credits to Daniel Lemire blog post: > + * > https://lemire.me/blog/2019/02/08/faster-remainders-when-the-divisor-is-a-constant-beating-compilers-and-libdivide/ > + * It's UB on zero, but we can't have a quad being zero, the > spec doesn't allow, > + * so we error out early in case that's the case. > + */ > + > + c = 1 + UINT64_C(0x) / quad_width; Just 0xULL would work > + > + for (int row = 1; row < quad_height; row++) { > + while ((q - (row * quad_width)) < quad_width - 1 && q < > (quad_height * quad_width)) { > + q1 = q; > + q2 = q + 1; > + context1 = sigma_n[4 * (q1 - quad_width) + 1]; > + context1 += sigma_n[4 * (q1 - quad_width) + 3] << 2; // > ne > + > + if (!is_divisible(q1, c)) { These divisibility checks look like they could be even simpler given that q always increases by 2 > + context1 |= sigma_n[4 * (q1 - quad_width) - > 1]; // nw > + context1 += (sigma_n[4 * q1 - 1] | sigma_n[4 * q1 - > 2]) << 1; // sw| q > + } > + if (!is_divisible(q1 + 1, c)) > + context1 |= sigma_n[4 * (q1 - quad_width) + 5] << 2; > + > + if ((ret = jpeg2000_decode_sig_emb(s, mel_state, > mel_stream, vlc_stream, > + dec_CxtVLC_table1, > Dcup, sig_pat, res_off, > + emb_pat_k, emb_pat_1, > J2K_Q1, context1, Lcup, > + Pcup)) > + < 0) > + goto free; > + > + for (int i = 0; i < 4; i++) > + sigma_n[4 * q1 + i] = (sig_pat[J2K_Q1] >> i) & 1; > + > + context2 = sigma_n[4 * (q2 - quad_width) + 1]; > + context2 += sigma_n[4 * (q2 - quad_width) + 3] << 2; > + > + if (!is_divisible(q2, c)) { > + context2 |= sigma_n[4 * (q2 - quad_width) - 1]; > + context2 += (sigma_n[4 * q2 - 1] | sigma_n[4 * q2 - > 2]) << 1; > + } > + if (!is_divisible(q2 + 1, c)) > + context2 |= sigma_n[4 * (q2 - quad_width) + 5] << 2; > + > + if ((ret = jpeg2000_decode_sig_emb(s, mel_state, > mel_stream, vlc_stream, > + dec_CxtVLC_table1, > Dcup, sig_pat, res_off, > + emb_pat_k, emb_pat_1, > J2K_Q2, context2, Lcup, > + Pcup)) > + < 0) > + goto free; > + > + for (int i = 0; i < 4; i++) > + sigma_n[4 * q2 + i] = (sig_pat[J2K_Q2] >> i) & 1; > + > + u[J2K_Q1] = 0; > + u[J2K_Q2] = 0; > + > + jpeg2000_bitbuf_refill_backwards(vlc_stream, vlc_buf); > + > + if (res_off[J2K_Q1] == 1 && res_off[J2K_Q2] == 1) { > + u_pfx[J2K_Q1] = vlc_decode_u_prefix(vlc_stream, > vlc_buf); > + u_pfx[J2K_Q2] = vlc_decode_u_prefix(vlc_stream, > vlc_buf); > + > + u_sfx[J2K_Q1] = vlc_decode_u_suffix(vlc_stream, > u_pfx[J2K_Q1], vlc_buf); > + u_sfx[J2K_Q2] = vlc_decode_u_suffix(vlc_stream, > u_pfx[J2K_Q2], vlc_buf); > + > + u_ext[J2K_Q1] = vlc_decode_u_extension(vlc_stream, > u_sfx[J2K_Q1], vlc_buf); > + u_ext[J2K_Q2] = vlc_decode_u_extension(vlc_stream, > u_sfx[J2K_Q2], vlc_buf); > + > + u[J2K_Q1] = u_pfx[J2K_Q1] + u_sfx[J2K_Q1] + > (u_ext[J2K_Q1] << 2); > + u[J2K_Q2] = u_pfx[J2K_Q2] + u_sfx[J2K_Q2] + > (u_ext[J2K_Q2] << 2); > + > + } else if (res_off[J2K_Q1] == 1 || res_off[J2K_Q2] == 1) > { > + uint8_t pos = res_off[J2K_Q1] == 1 ? 0 : 1; > + > + u_pfx[pos] = vlc_decode_u_prefix(vlc_stream, > vlc_buf); > + u_sfx[pos] = vlc_decode_u_suffix(vlc_s
Re: [FFmpeg-devel] [PATCH 2/2] avcodec/jpeg2000dec: Add support for HTJ2K decoding.
Hi For bit-reading, 1. The spec has some chunks read from back to front,I didn't see that functionality present in get_bits.h(which I assumed contained the bit reading API). 2. It doesn't handle unstuffing correctly. 3. Doesn't handle EOB correctly, the spec has some arrays when there are no more bytes, the bit-reader should be filled with 0, others with 0xFF.. >> These divisibility checks look like they could be even simpler given that q always increases by 2 How so?(I might be failing to see something common here.) >> Could this be done all in one go in the loop above? Writing to mu then reading from it later is not very cache friendly. Open to exploring that path, but to me it seems to add more complexity than the speed up it may provide. Also I do believe it's really not that cache unfriendly, access is linear on the second write and highly predictable. On Fri, Dec 2, 2022 at 9:46 PM Tomas Härdin wrote: > fre 2022-12-02 klockan 21:11 +0300 skrev etemesica...@gmail.com: > > > > +/** > > + * Given a precomputed c, checks whether n % d == 0 > > + */ > > +static av_always_inline uint32_t is_divisible(uint32_t n, uint64_t > > c) > > +{ > > +return n * c <= c - 1; > > +} > > This looks like something that could go in lavu, say intmath.h > > > + > > +/** > > + * @brief Refill the buffer backwards in little Endian while > > skipping > > + * over stuffing bits > > + * > > + * Stuffing bits are those that appear in the position of any byte > > whose > > + * LSBs are all 1's if the last consumed byte was larger than 0x8F > > + */ > > +static int jpeg2000_bitbuf_refill_backwards(StateVars *buffer, > > +const uint8_t *array) > > Don't we already have sufficient bitreading capabilities already? Maybe > it doesn't do the necessary unstuffing.. > > > > +/* > > + * As an optimization, we can replace modulo operations with > > + * checking if a number is divisible , since that's the only > > thing we need. > > + * this is paired with is_divisible. > > + * Credits to Daniel Lemire blog post: > > + * > > > https://lemire.me/blog/2019/02/08/faster-remainders-when-the-divisor-is-a-constant-beating-compilers-and-libdivide/ > > + * It's UB on zero, but we can't have a quad being zero, the > > spec doesn't allow, > > + * so we error out early in case that's the case. > > + */ > > + > > +c = 1 + UINT64_C(0x) / quad_width; > > Just 0xULL would work > > > + > > +for (int row = 1; row < quad_height; row++) { > > +while ((q - (row * quad_width)) < quad_width - 1 && q < > > (quad_height * quad_width)) { > > +q1 = q; > > +q2 = q + 1; > > +context1 = sigma_n[4 * (q1 - quad_width) + 1]; > > +context1 += sigma_n[4 * (q1 - quad_width) + 3] << 2; // > > ne > > + > > +if (!is_divisible(q1, c)) { > > These divisibility checks look like they could be even simpler given > that q always increases by 2 > > > +context1 |= sigma_n[4 * (q1 - quad_width) - > > 1]; // nw > > +context1 += (sigma_n[4 * q1 - 1] | sigma_n[4 * q1 - > > 2]) << 1; // sw| q > > +} > > +if (!is_divisible(q1 + 1, c)) > > +context1 |= sigma_n[4 * (q1 - quad_width) + 5] << 2; > > + > > +if ((ret = jpeg2000_decode_sig_emb(s, mel_state, > > mel_stream, vlc_stream, > > + dec_CxtVLC_table1, > > Dcup, sig_pat, res_off, > > + emb_pat_k, emb_pat_1, > > J2K_Q1, context1, Lcup, > > + Pcup)) > > +< 0) > > +goto free; > > + > > +for (int i = 0; i < 4; i++) > > +sigma_n[4 * q1 + i] = (sig_pat[J2K_Q1] >> i) & 1; > > + > > +context2 = sigma_n[4 * (q2 - quad_width) + 1]; > > +context2 += sigma_n[4 * (q2 - quad_width) + 3] << 2; > > + > > +if (!is_divisible(q2, c)) { > > +context2 |= sigma_n[4 * (q2 - quad_width) - 1]; > > +context2 += (sigma_n[4 * q2 - 1] | sigma_n[4 * q2 - > > 2]) << 1; > > +} > > +if (!is_divisible(q2 + 1, c)) > > +context2 |= sigma_n[4 * (q2 - quad_width) + 5] << 2; > > + > > +if ((ret = jpeg2000_decode_sig_emb(s, mel_state, > > mel_stream, vlc_stream, > > + dec_CxtVLC_table1, > > Dcup, sig_pat, res_off, > > + emb_pat_k, emb_pat_1, > > J2K_Q2, context2, Lcup, > > + Pcup)) > > +< 0) > > +goto free; > > + > > +for (int i = 0; i < 4; i++) > > +sigma_n[4 * q2 + i] = (sig_pat[J2K_Q2] >> i) & 1; > > + > > +u[J2K_Q1] = 0; > > +u[J2K_Q2] = 0; > > + > > +
Re: [FFmpeg-devel] [PATCH 2/2] avcodec/jpeg2000dec: Add support for HTJ2K decoding.
Also thanks for reviewing On Fri, Dec 2, 2022 at 10:34 PM Caleb Etemesi wrote: > Hi > > For bit-reading, > 1. The spec has some chunks read from back to front,I didn't see that > functionality present in get_bits.h(which I assumed contained the bit > reading API). > 2. It doesn't handle unstuffing correctly. > 3. Doesn't handle EOB correctly, the spec has some arrays when there are > no more bytes, the bit-reader should be filled with 0, others with 0xFF.. > > > >> These divisibility checks look like they could be even simpler given > that q always increases by 2 > > How so?(I might be failing to see something common here.) > > >> Could this be done all in one go in the loop above? Writing to mu then > reading from it later is not very cache friendly. > > Open to exploring that path, but to me it seems to add more complexity > than the speed up it may provide. > > Also I do believe it's really not that cache unfriendly, access is linear > on the second write and highly predictable. > > > On Fri, Dec 2, 2022 at 9:46 PM Tomas Härdin wrote: > >> fre 2022-12-02 klockan 21:11 +0300 skrev etemesica...@gmail.com: >> > >> > +/** >> > + * Given a precomputed c, checks whether n % d == 0 >> > + */ >> > +static av_always_inline uint32_t is_divisible(uint32_t n, uint64_t >> > c) >> > +{ >> > +return n * c <= c - 1; >> > +} >> >> This looks like something that could go in lavu, say intmath.h >> >> > + >> > +/** >> > + * @brief Refill the buffer backwards in little Endian while >> > skipping >> > + * over stuffing bits >> > + * >> > + * Stuffing bits are those that appear in the position of any byte >> > whose >> > + * LSBs are all 1's if the last consumed byte was larger than 0x8F >> > + */ >> > +static int jpeg2000_bitbuf_refill_backwards(StateVars *buffer, >> > +const uint8_t *array) >> >> Don't we already have sufficient bitreading capabilities already? Maybe >> it doesn't do the necessary unstuffing.. >> >> >> > +/* >> > + * As an optimization, we can replace modulo operations with >> > + * checking if a number is divisible , since that's the only >> > thing we need. >> > + * this is paired with is_divisible. >> > + * Credits to Daniel Lemire blog post: >> > + * >> > >> https://lemire.me/blog/2019/02/08/faster-remainders-when-the-divisor-is-a-constant-beating-compilers-and-libdivide/ >> > + * It's UB on zero, but we can't have a quad being zero, the >> > spec doesn't allow, >> > + * so we error out early in case that's the case. >> > + */ >> > + >> > +c = 1 + UINT64_C(0x) / quad_width; >> >> Just 0xULL would work >> >> > + >> > +for (int row = 1; row < quad_height; row++) { >> > +while ((q - (row * quad_width)) < quad_width - 1 && q < >> > (quad_height * quad_width)) { >> > +q1 = q; >> > +q2 = q + 1; >> > +context1 = sigma_n[4 * (q1 - quad_width) + 1]; >> > +context1 += sigma_n[4 * (q1 - quad_width) + 3] << 2; // >> > ne >> > + >> > +if (!is_divisible(q1, c)) { >> >> These divisibility checks look like they could be even simpler given >> that q always increases by 2 >> >> > +context1 |= sigma_n[4 * (q1 - quad_width) - >> > 1]; // nw >> > +context1 += (sigma_n[4 * q1 - 1] | sigma_n[4 * q1 - >> > 2]) << 1; // sw| q >> > +} >> > +if (!is_divisible(q1 + 1, c)) >> > +context1 |= sigma_n[4 * (q1 - quad_width) + 5] << 2; >> > + >> > +if ((ret = jpeg2000_decode_sig_emb(s, mel_state, >> > mel_stream, vlc_stream, >> > + dec_CxtVLC_table1, >> > Dcup, sig_pat, res_off, >> > + emb_pat_k, emb_pat_1, >> > J2K_Q1, context1, Lcup, >> > + Pcup)) >> > +< 0) >> > +goto free; >> > + >> > +for (int i = 0; i < 4; i++) >> > +sigma_n[4 * q1 + i] = (sig_pat[J2K_Q1] >> i) & 1; >> > + >> > +context2 = sigma_n[4 * (q2 - quad_width) + 1]; >> > +context2 += sigma_n[4 * (q2 - quad_width) + 3] << 2; >> > + >> > +if (!is_divisible(q2, c)) { >> > +context2 |= sigma_n[4 * (q2 - quad_width) - 1]; >> > +context2 += (sigma_n[4 * q2 - 1] | sigma_n[4 * q2 - >> > 2]) << 1; >> > +} >> > +if (!is_divisible(q2 + 1, c)) >> > +context2 |= sigma_n[4 * (q2 - quad_width) + 5] << 2; >> > + >> > +if ((ret = jpeg2000_decode_sig_emb(s, mel_state, >> > mel_stream, vlc_stream, >> > + dec_CxtVLC_table1, >> > Dcup, sig_pat, res_off, >> > + emb_pat_k, emb_pat_1, >> > J2K_Q2, context2, Lcup, >> > + Pcup)) >> > +< 0) >> >
Re: [FFmpeg-devel] [PATCH 2/5] avcodec/wavpack: Fix overflow in k=31
On Fri, Dec 02, 2022 at 05:14:58PM +0100, Paul B Mahol wrote: > On Thu, Dec 1, 2022 at 8:56 PM Michael Niedermayer > wrote: > > > On Wed, Nov 30, 2022 at 09:39:44PM +0100, Paul B Mahol wrote: > > > On 9/11/22, Michael Niedermayer wrote: > > > > Untested with "non fuzzed" samples as i have no such file > > > > > > > > > > Then create it. > > > > the official WavPack-5.6.0 decoder has 2 alternative optimized codepathes > > #ifdef USE_BITMASK_TABLES > > extras = bitset [bitcount] - maxcode - 1; > > #else > > extras = (1 << bitcount) - maxcode - 1; > > #endif > > > > The 2nd path would result in the same 1<<32 which is undefined but luckily > > the first seems hardcoded to be used it uses this table: > > > > const uint32_t bitset [] = { > > 1L << 0, 1L << 1, 1L << 2, 1L << 3, > > 1L << 4, 1L << 5, 1L << 6, 1L << 7, > > 1L << 8, 1L << 9, 1L << 10, 1L << 11, > > 1L << 12, 1L << 13, 1L << 14, 1L << 15, > > 1L << 16, 1L << 17, 1L << 18, 1L << 19, > > 1L << 20, 1L << 21, 1L << 22, 1L << 23, > > 1L << 24, 1L << 25, 1L << 26, 1L << 27, > > 1L << 28, 1L << 29, 1L << 30, 1L << 31 > > }; > > > > here bitset[32] is out of array > > > > Given above i suspect no valid file should use this. Otherwise something > > seriously odd is going on. > > > > also the subject has a typo its p=31 not k=31 > > > > thx > > > > OK will apply thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The worst form of inequality is to try to make unequal things equal. -- Aristotle 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".
Re: [FFmpeg-devel] [PATCH] avcodec/libsvtav1: don't force a default value for deprecated options
On Tue, Nov 29, 2022 at 4:38 PM James Almer wrote: > Stick to the library's default value instead. > > Should address AOMediaCodec/SVT-AV1 issue #2011. > > Signed-off-by: James Almer > --- > libavcodec/libsvtav1.c | 25 +++-- > 1 file changed, 15 insertions(+), 10 deletions(-) > Ping on this? It would be great since this would allow the library to apply better defaults for the deprecated options. ___ 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/libsvtav1: don't force a default value for deprecated options
On 12/2/2022 8:51 PM, Christopher Degawa wrote: On Tue, Nov 29, 2022 at 4:38 PM James Almer wrote: Stick to the library's default value instead. Should address AOMediaCodec/SVT-AV1 issue #2011. Signed-off-by: James Almer --- libavcodec/libsvtav1.c | 25 +++-- 1 file changed, 15 insertions(+), 10 deletions(-) Ping on this? It would be great since this would allow the library to apply better defaults for the deprecated options. Applied. ___ 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".