Commit Graph

51 Commits

Author SHA1 Message Date
Xu Guangxin
99501b5015 lavc/hevcdec: do not let missing ref frames invovled in dpb process
We will generate a new frame for a missed reference. The frame can only
be used for reference. We assign an invalid decode sequence to it, so
it will not be involved in any dpb process.

Tested-by: Fei Wang <fei.w.wang@intel.com>
Signed-off-by: Fei Wang <fei.w.wang@intel.com>
Signed-off-by: Xu Guangxin <guangxin.xu@intel.com>
2022-07-27 10:54:38 +08:00
Andreas Rheinhardt
247d513beb avcodec/hevcdec: Avoid allocation of common CABAC state
It used to be allocated separately, so that the pointer to it
is copied to all HEVCContexts, so that all slice-threads
use the same. This is completely unnecessary now that there
is only one HEVCContext any more. There is just one minor
complication left: The slice-threads only get a pointer to
const HEVCContext, but they need to modify the common CABAC
state. Fix this by adding a pointer to the common CABAC state
to HEVCLocalContext and document why it exists.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-25 23:35:45 +02:00
Andreas Rheinhardt
ad2b755d3f avcodec/hevcdec: Don't allocate redundant HEVCContexts
The HEVC decoder has both HEVCContext and HEVCLocalContext
structures. The latter is supposed to be the structure
containing the per-slicethread state.

Yet up until now that is not how it is handled in practice:
Each HEVCLocalContext has a unique HEVCContext allocated for it
and each of these coincides except in exactly one field: The
corresponding HEVCLocalContext. This makes it possible to pass
the HEVCContext everywhere where logically a HEVCLocalContext
should be used. And up until recently, this is how it has been done.

Yet the preceding patches changed this, making it possible
to avoid allocating redundant HEVCContexts.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-25 23:32:08 +02:00
Andreas Rheinhardt
13b3e84a4f avcodec/hevc_cabac: Pass HEVCLocalContext when slice-threading
The HEVC decoder has both HEVCContext and HEVCLocalContext
structures. The latter is supposed to be the structure
containing the per-slicethread state.

Yet that is not how it is handled in practice: Each HEVCLocalContext
has a unique HEVCContext allocated for it and each of these
coincides except in exactly one field: The corresponding
HEVCLocalContext. This makes it possible to pass the HEVCContext
everywhere where logically a HEVCLocalContext should be used.

This commit stops doing this for lavc/hevc_cabac.c; it also constifies
everything that is possible in order to ensure that no slice thread
accidentally modifies the main HEVCContext state.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-25 23:31:37 +02:00
Andreas Rheinhardt
72d5ce9fa6 avcodec/hevcdec: Add stat_coeffs to HEVCABACState
The HEVC decoder has both HEVCContext and HEVCLocalContext
structures. The latter is supposed to be the structure
containing the per-slicethread state.

Yet that is not how it is handled in practice: Each HEVCLocalContext
has a unique HEVCContext allocated for it and each of these
coincides with the main HEVCContext except in exactly one field:
The corresponding HEVCLocalContext.
This makes it possible to pass the HEVCContext everywhere where
logically a HEVCLocalContext should be used.

This led to confusion in the first version of what eventually became
commit c8bc0f66a8:
Before said commit, the initialization of the Rice parameter derivation
state was incorrect; the fix for single-threaded as well as
frame-threaded decoding was to add backup stats to HEVCContext
that are used when the cabac state is updated*, see
https://ffmpeg.org/pipermail/ffmpeg-devel/2020-August/268861.html
Yet due to what has been said above, this does not work for
slice-threading, because the each HEVCLocalContext has its own
HEVCContext, so the Rice parameter state would not be transferred
between threads.

This is fixed in c8bc0f66a8
by a hack: It rederives what the previous thread was and accesses
the corresponding HEVCContext.

Fix this by treating the Rice parameter state the same way
the ordinary CABAC parameters are shared between threads:
Make them part of the same struct that is shared between
slice threads. This does not cause races, because
the parts of the code that access these Rice parameters
are a subset of the parts of code that access the CABAC parameters.

*: And if the persistent_rice_adaptation_enabled_flag is set.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-25 23:31:37 +02:00
Andreas Rheinhardt
8c4f95e1e1 avcodec/hevc_filter: Pass HEVCLocalContext when slice-threading
The HEVC decoder has both HEVCContext and HEVCLocalContext
structures. The latter is supposed to be the structure
containing the per-slicethread state.

Yet that is not how it is handled in practice: Each HEVCLocalContext
has a unique HEVCContext allocated for it and each of these
coincides with the main HEVCContext except in exactly one field:
The corresponding HEVCLocalContext.
This makes it possible to pass the HEVCContext everywhere where
logically a HEVCLocalContext should be used.

This commit stops doing this for lavc/hevc_filter.c; it also constifies
everything that is possible in order to ensure that no slice thread
accidentally modifies the main HEVCContext state.

There are places where this was not possible, namely with the SAOParams
in sao_filter_CTB() or with sao_pixels_buffer_h in copy_CTB_to_hv().
Both of these instances lead to data races, see
https://fate.ffmpeg.org/report.cgi?time=20220629145651&slot=x86_64-archlinux-gcc-tsan-slices

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-25 23:31:37 +02:00
Andreas Rheinhardt
136ada2fc3 avcodec/hevc_mvs: Pass HEVCLocalContext when slice-threading
The HEVC decoder has both HEVCContext and HEVCLocalContext
structures. The latter is supposed to be the structure
containing the per-slicethread state.

Yet that is not how it is handled in practice: Each HEVCLocalContext
has a unique HEVCContext allocated for it and each of these
coincides except in exactly one field: The corresponding
HEVCLocalContext. This makes it possible to pass the HEVCContext
everywhere where logically a HEVCLocalContext should be used.

This commit stops doing this for lavc/hevc_mvs.c; it also constifies
everything that is possible in order to ensure that no slice thread
accidentally modifies the main HEVCContext state.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-25 23:31:12 +02:00
Andreas Rheinhardt
1837ae9d5f avcodec/hevcdec: Add pointers to logctx and parent ctx to HEVCLocalCtx
It is safe for a slice thread to read the main context
and therefore it is safe to add a pointer to const HEVCContext
(namely the parent context) to each HEVCLocalContext.
It is also safe (and actually redundant) to add a pointer
to a logcontext to HEVCLocalContext.

Doing so allows to pass the HEVCLocalContext as context in
the parts of the code that is run slice-threaded when slice-threading
is in use (currently these parts of the code use ordinary
HEVCContext*). This way one is not tempted to modify
the main context from the slice contexts.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-25 17:54:16 +02:00
Andreas Rheinhardt
c34e3920f2 avcodec/hevc_refs: Constify ff_hevc_get_ref_list()
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-09 20:28:02 +02:00
Andreas Rheinhardt
a3b833c3ea avcodec/hevcdec: Remove redundant context_initialized
All contexts are always initialized during init, regardless
of whether frame threading is in use or not.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-06-30 11:06:20 +02:00
Andreas Rheinhardt
02220b88fc avcodec/thread: Don't use ThreadFrame when unnecessary
The majority of frame-threaded decoders (mainly the intra-only)
need exactly one part of ThreadFrame: The AVFrame. They don't
need the owners nor the progress, yet they had to use it because
ff_thread_(get|release)_buffer() requires it.

This commit changes this and makes these functions work with ordinary
AVFrames; the decoders that need the extra fields for progress
use ff_thread_(get|release)_ext_buffer() which work exactly
as ff_thread_(get|release)_buffer() used to do.

This also avoids some unnecessary allocations of progress AVBuffers,
namely for H.264 and HEVC film grain frames: These frames are not
used for synchronization and therefore don't need a ThreadFrame.

Also move the ThreadFrame structure as well as ff_thread_ref_frame()
to threadframe.h, the header for frame-threaded decoders with
inter-frame dependencies.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-09 17:22:35 +01:00
Andreas Rheinhardt
27f22f3383 all: Remove unnecessary libavcodec/internal.h inclusions
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-08 06:16:26 +01:00
Niklas Haas
a538df7eab lavc/hevcdec: Parse DOVI RPU NALs
And expose the parsed values as frame side data. Update FATE results to
match.

It's worth documenting that this relies on the dovi configuration record
being present on the first AVPacket fed to the decoder, which in
practice is the case if if the API user has called something like
av_format_inject_global_side_data, which is unfortunately not the
default.

This commit is not the time and place to change that behavior, though.

Signed-off-by: Niklas Haas <git@haasn.dev>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-04 12:08:18 +01:00
Derek Buitenhuis
bc68fd1050 avcodec/hevcdec: Export Dolby Vision RPUs as side data
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2021-11-17 14:12:51 +00:00
Limin Wang
06548e6045 avcodec/hevcdec: remove unused code
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-10-17 16:57:43 +08:00
Niklas Haas
3cc3f5de2a avcodec/hevcdec: apply H.274 film grain
Similar in spirit and design to 66845cffc3, but slightly simpler due
to the lack of interlaced frames in HEVC. See that commit for more
details.

For the seed value, since no specification for this appears to exist, I
semi-arbitrarily decided to base it off the POC id alone, since there's
no analog of the idr_pic_id in HEVC's I-frames. This design is stable
across remuxes and seeks, but changes for adjacent frames with a period
that's typically long enough not to be noticeable, which makes it
satisfy all of the requirements that a film grain seed should have.

Tested with and without threading, using a patch to insert film grain
metadata artificially (for lack of real files containing film grain).
2021-10-15 11:55:45 -03:00
Xu Guangxin
c8bc0f66a8 avcodec/hevcdec: fix stat_coeff save/load for persistent_rice_adaptation_enabled_flag
It's required by the 9.3.1 TableStatCoeff* section.

Following clips have this feature:
WPP_HIGH_TP_444_8BIT_RExt_Apple_2.bit
Bitdepth_A_RExt_Sony_1.bin
Bitdepth_B_RExt_Sony_1.bin
EXTPREC_HIGHTHROUGHPUT_444_16_INTRA_10BIT_RExt_Sony_1.bit
EXTPREC_HIGHTHROUGHPUT_444_16_INTRA_12BIT_RExt_Sony_1.bit
EXTPREC_HIGHTHROUGHPUT_444_16_INTRA_8BIT_RExt_Sony_1.bit
EXTPREC_MAIN_444_16_INTRA_10BIT_RExt_Sony_1.bit
EXTPREC_MAIN_444_16_INTRA_12BIT_RExt_Sony_1.bit
EXTPREC_MAIN_444_16_INTRA_8BIT_RExt_Sony_1.bit
WPP_AND_TILE_10Bit422Test_HIGH_TP_444_10BIT_RExt_Apple_2.bit
WPP_AND_TILE_AND_CABAC_BYPASS_ALIGN_0_HIGH_TP_444_14BIT_RExt_Apple_2.bit
WPP_AND_TILE_AND_CABAC_BYPASS_ALIGN_1_HIGH_TP_444_14BIT_RExt_Apple_2.bit
WPP_AND_TILE_HIGH_TP_444_8BIT_RExt_Apple_2.bit

you can download them from:
https://www.itu.int/wftp3/av-arch/jctvc-site/bitstream_exchange/draft_conformance/RExt/

Signed-off-by: Xu Guangxin <oddstone@gmail.com>
Signed-off-by: Linjie Fu <linjie.justin.fu@gmail.com>
2021-01-04 15:18:19 +00:00
Anton Khirnov
e15371061d lavu/mem: move the DECLARE_ALIGNED macro family to mem_internal on next+1 bump
They are not properly namespaced and not intended for public use.
2021-01-01 14:14:57 +01:00
Nuo Mi
d4751d8c63 avcodec/hevcdec: dynamic allocate sList and HEVClcList
following comandline will crash the ffmpeg
ffmpeg -threads 17 -thread_type slice -i WPP_A_ericsson_MAIN_2.bit out.yuv -y

the HEVCContext->sList size is MAX_NB_THREADS(16), any > 16 thread number will crash the application

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2020-12-10 09:44:11 +01:00
Anton Khirnov
b7e1821284 hevc: move SliceHeader and LongTermRPS back to hevcdec.h
They are no longer necessary there and have nothing to do with parameter
sets, so do not belong in hevc_ps.h.

This effectively reverts 4aaace8b25.
2020-06-08 10:51:56 +02:00
Steven Liu
36ed8ae52c avcodec/hevcdec: remove unneeded code
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-10-22 10:51:37 +08:00
Michael Niedermayer
1a89ae1df8 avcodec/hevcdec: Check for overlapping slices
Fixes: Timeout
Fixes: 10108/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-6222384351674368

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-12-01 02:17:19 +01:00
Mark Wu
10bc4c3a7d avcodec/hevcdec: fix non-ref frame judgement
After inspecting the source code of x265, mpv and ffmpeg, I've found that
ffmpeg mistakenly regards EVC_NAL_BLA_N_LP and HEVC_NAL_IDR_N_LP as non-
reference frames, which are acutally reference frames according to the
specification in x265, and drops them.

This patch should address the problem. I have tested it with mpv.

Signed-off-by: Mark Wu <wfwf1997@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-11-10 14:32:17 -03:00
Timo Rothenpieler
46c1ee1917 avcodec/hevcdec: make ff_hevc_frame_nb_refs take a const pointer 2018-05-10 18:41:56 +02:00
sfan5
a428f2fcd9 libavcodec/hevc_filter: move AVDISCARD_NONREF switch-case into function
In preparation for implementation of skip_frame.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-12-08 20:02:16 +01:00
James Almer
b1ab02895b Merge commit 'c3f0357bdf7d3c542aad2c58b94184b9f56edc41'
* commit 'c3f0357bdf7d3c542aad2c58b94184b9f56edc41':
  hevcdec: move the MD5 context out of HEVCSEIPictureHash back into HEVCContext

Merged-by: James Almer <jamrial@gmail.com>
2017-10-31 12:48:36 -03:00
James Almer
bd8f1fa100 avcodec/hevc_sei: rename HEVCSEIContext to HEVCSEI
Cosmetic change skipped in 0b30cb8dae
by mistake.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-10-31 12:27:57 -03:00
Mark Thompson
4dee92f6bc hevc: Fix aligned array declarations
(cherry picked from commit d41e10c148)
2017-10-21 22:19:50 +01:00
Michael Niedermayer
933aa91e31 avcodec/hevcdec: check ff_init_cabac_decoder() for failure
Fixes: runtime error: left shift of 1965559808 by 4 places cannot be represented in type 'int'
Fixes: 2333/clusterfuzz-testcase-minimized-5223935677300736

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-06-24 22:17:15 +02:00
James Almer
000fb61a71 avcodec/hevcdec: export cropping information instead of handling it internally
This merges commit a02ae1c683 from libav,
originally written by Anton Khirnov and skipped in
fc63d5ceb3.

 libavcodec/hevc_parser.c |  6 ++++--
 libavcodec/hevc_ps.c     | 31 ++++++++++++-------------------
 libavcodec/hevc_ps.h     |  2 --
 libavcodec/hevc_refs.c   | 18 +++++-------------
 libavcodec/hevcdec.c     |  7 ++++---
 libavcodec/hevcdec.h     |  2 --
 6 files changed, 25 insertions(+), 41 deletions(-)

Signed-off-by: James Almer <jamrial@gmail.com>
2017-05-26 11:15:45 -03:00
Anton Khirnov
c3f0357bdf hevcdec: move the MD5 context out of HEVCSEIPictureHash back into HEVCContext
HEVCSEIPictureHash should store only the information extracted from the
bitstream and exported to the higher layer (the decoder or the parser).
The MD5 context is allocated, used and freed by this higher layer, so it
makes more sense for it to also be stored there.
2017-05-20 09:41:30 +02:00
James Almer
cfd25488bf hevcdec: move SEI message parsing into a separate header
It doesn't depend on hevcdec anymore.

Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2017-05-09 13:42:20 +02:00
James Almer
648a0b4503 hevcdec: remove HEVCContext usage from hevc_sei
Based on the H264 SEI implementation.

This will be mainly useful once support for SEI messages that can be
used by the hevc parser are implemented, like Picture Timing.

Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2017-05-09 13:42:20 +02:00
James Almer
4aaace8b25 avcodec/hevcdec: move SliceHeader struct definition to hevc_ps
This is in preparation for a following patch.

Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com>
Reviewed-by: Aaron Levinson <alevinsn@aracnet.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-05-05 17:30:36 -03:00
James Almer
1d53b8e907 avcodec/hevcdec: remove HEVCContext usage from ff_hevc_compute_poc()
Move it to hevc_ps as well. This is in preparation for a following patch.

Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com>
Reviewed-by: Aaron Levinson <alevinsn@aracnet.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-05-05 17:30:36 -03:00
James Almer
a687fb9970 avcodec/hevcdec: move SEI message parsing into a separate header
It doesn't depend on hevcdec anymore.

Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com>
Reviewed-by: Aaron Levinson <alevinsn@aracnet.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-05-05 17:30:35 -03:00
James Almer
c4b08c8a4e avcodec/hevcdec: remove HEVCContext usage from hevc_sei
Based on the H264 SEI implementation.

Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com>
Reviewed-by: Aaron Levinson <alevinsn@aracnet.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-05-05 17:30:35 -03:00
James Almer
4588063f3e avcodec/hevcdec: remove duplicate extradata parsing function
Use ff_hevc_decode_extradata() instead, which correctly only tries
to decode parameter set NAL units and not any other NAL that may be
present in extradata.

Reviewed-by: nevcairiel
Signed-off-by: James Almer <jamrial@gmail.com>
2017-04-09 14:09:05 -03:00
Steve Lhomme
157e57a181 lavc: Add Content Light Level side metadata found in HEVC
These data are necessary when transmitting HDR over HDMI.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-04-06 11:38:15 -03:00
James Almer
dc39ccdc3b Merge commit '0bfdcce4d42a6e654c00ea5f9237dc987626457f'
* commit '0bfdcce4d42a6e654c00ea5f9237dc987626457f':
  hevc: move the SliceType enum to hevc.h

Merged-by: James Almer <jamrial@gmail.com>
2017-03-23 20:02:11 -03:00
James Almer
4a5810b659 Merge commit 'f6e2f8a9ffda2247bffba991450990d075ea68e3'
* commit 'f6e2f8a9ffda2247bffba991450990d075ea68e3':
  hevcdec: move parameter set parsing into a separate header

Merged-by: James Almer <jamrial@gmail.com>
2017-03-23 15:53:00 -03:00
James Almer
b29c8c995f Merge commit '150c896a9e46b23b97debb0a5f66fbaeaa32f153'
* commit '150c896a9e46b23b97debb0a5f66fbaeaa32f153':
  hevcdec: split ff_hevc_diag_scan* declarations into a separate header

Merged-by: James Almer <jamrial@gmail.com>
2017-03-23 15:14:06 -03:00
James Almer
6397815be0 Merge commit 'c359d624d3efc3fd1d83210d78c4152bd329b765'
* commit 'c359d624d3efc3fd1d83210d78c4152bd329b765':
  hevcdec: move decoder-independent declarations into a separate header

Merged-by: James Almer <jamrial@gmail.com>
2017-03-23 14:27:48 -03:00
Clément Bœsch
038e6aef7a Merge commit '4abe3b049d987420eb891f74a35af2cebbf52144'
* commit '4abe3b049d987420eb891f74a35af2cebbf52144':
  hevc: rename hevc.[ch] to hevcdec.[ch]

Merged-by: Clément Bœsch <u@pkh.me>
2017-03-23 16:48:41 +01:00
Anton Khirnov
a02ae1c683 hevcdec: export cropping information instead of handling it internally 2017-01-12 16:27:56 +01:00
Anton Khirnov
0bfdcce4d4 hevc: move the SliceType enum to hevc.h
Those values are decoder-independent and are also use by the VA-API
encoder.
2016-10-21 10:11:20 +02:00
Anton Khirnov
f6e2f8a9ff hevcdec: move parameter set parsing into a separate header
This code is independent from the decoder, so it makes more sense for it
to to have its own header.
2016-10-16 20:26:47 +02:00
Anton Khirnov
150c896a9e hevcdec: split ff_hevc_diag_scan* declarations into a separate header
This will be useful in the following commits.
2016-10-16 20:26:40 +02:00
Anton Khirnov
645c6ff423 hevcdec: drop the prototype of a non-existing function 2016-10-16 20:26:35 +02:00
Anton Khirnov
c359d624d3 hevcdec: move decoder-independent declarations into a separate header
This way they can be reused by other code without including the whole
decoder-specific hevcdec.h
Also, add the HEVC_ prefix to them, since similarly named values exist
for H.264 as well and are sometimes used in the same code.
2016-10-16 20:26:28 +02:00