AV_PKT_DATA_SKIP_SAMPLES gives the samples to skip at the start of a
frame and the padding to discard at its end. When both apply to the same
frame and overlap, the padding was compared with what was left after the
skip, found too large, and ignored, so the padding was output.
Check the padding against the whole frame, then discard what is left of
it after the skip.
The overlapping case of the api-skip-samples test now outputs nothing
instead of the padding.
Add a list that gives each side data type a short handle made of lower case
letters, digits and underscores, so that a filter can let its user name a
type in an option.
The side_data_prefer_packet option of decoders now takes its constants from
this list, which gives the list the names that option has already released.
The option thus accepts every type, with the flags of the option itself
rather than audio only. A decoder warns about a type that has no frame side
data counterpart, as it ignores it.
Each handle is written out rather than derived from the name that
av_packet_side_data_name() returns, as that one is meant for people and may
be reworded.
Text subtitle decoders parse the packet data as a string, but the
padding after it is not required to be zero, and in laced Matroska
blocks it holds the next event. The data is copied only when its first
padding byte is not 0.
The packet data is not NUL terminated.
Fixes: a3ewdvDE2QSe
Fixes: out of array read
Out of array read Replicated through API with ASAN
Found during triage of the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24659
This is not a security issue.
Fixes: e5BUoyG1Jo3N
Fixes: swarm-NULL-pointer-dereference-in-hw_configs-iteration-0b77cc
Regression since: 67e81d79cc
NULL pointer member access Replicated through API with UBSAN
Found-by: zhang xingxing <2388969553@qq.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
In `discard_samples()`, the rescaling operation can evaluate to
AV_NOPTS_VALUE if the rescaling operation overflows. This commit
prevents adjusting timestamp and durations by the invalid value.
pts_correction_num_faulty_pts and pts_correction_num_faulty_dts were not
cleared by ff_decode_flush_buffers(), so they survived avcodec_flush_buffers().
After a seek, guess_correct_pts() therefore kept biasing its reordered-pts vs
dts choice on pre-seek history instead of starting fresh as it does after
ff_decode_preinit(), which already zeroes both counters. This could yield an
incorrect AVFrame.best_effort_timestamp on the frames following a seek.
Reset both counters on flush, next to the existing last_pts/last_dts reset, so
the decoder's timestamp-correction state is fully reinitialized.
Fixes: ticket #11645
Reported-by: keks51
Signed-off-by: Bogdan Lisman <bogdan@pydevsolutions.com>
It is (arguably) a slightly better place for them and avoids
a forward declaration of enum AVExifHeaderMode which is not possible
in ISO C before C23 (and requires specifying the underlying type
with C23).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Avoids the post_process_opaque_free callback; the only user of
this is already a RefStruct reference and presumably other users
would want to use a pool for this, too, so they would use
RefStruct-objects, too.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Leave the existing one for non decoder-specific, post processing usage.
With this, scenarios like nvdec decoding can work algonside lcevc enhancement application.
Signed-off-by: James Almer <jamrial@gmail.com>
Choose the first non-hwaccel format rather than the last one. This
matches the logic in ffmpeg CLI and selects YUVA rather than YUV for
HEVC with alpha.
Not only do some sources not provide an aspect ratio, as is the case of
MPEG-TS, but also some enhanced streams have no change in dimensions, and this
heuristic would generate bugus values.
Instead, we need to parse the LCEVC bitstream for a Global Config process block
in order to get the actual dimensions. This add a little overhead, but it can't
be avoided.
Signed-off-by: James Almer <jamrial@gmail.com>
Normally, this function tries to make sure all threads are saturated with
work to do before returning any frames; and will continue requesting packets
until that is the case.
However, this significantly slows down initial decoding latency when only
requesting a single frame (to e.g. configure the filter graph), and also
wastes a lot of unnecessary memory in the event that the user does not intend
to decode more frames until later.
By introducing a new `flags` paramater and a new flag
`AV_CODEC_RECEIVE_FRAME_FLAG_SYNCHRONOUS` to go along with it, we can allow
users to temporarily bypass this logic.
Makes it easier to see that width and height in DecodeContext is
actually a lcevc field.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Regression since 5acbdd2264, which removed
setting both values from PerThreadContext.
Given the pthread code calls ff_decode_receive_frame_internal() on the frame,
any value set before it will be overwritten, so instead sync each thread's
DecodeContext and let ff_decode_receive_frame_internal() handle these values.
Fixes issue #20534.
Signed-off-by: James Almer <jamrial@gmail.com>
Since 9dc79241d9 we now always pop the
orientation off of the IFD and use a display matrix instead. This means
we should not produce a warning and refuse if the orientation field
indicates a default orientation (i.e. 1).
Signed-off-by: Leo Izen <leo.izen@gmail.com>
Reported-by: Ramiro Polla <ramiro.polla@gmail.com>
Following in the footsteps of the previous commit, this commit adds the
new fields to AVCodecContext so we can start properly setting it on codecs,
as well as limiting the list of supported options to detect a format mismatch
during encode.
This commit also sets up the necessary infrastructure to start using the
newly added field in all codecs.
Extract Orientation and export it as a display matrix if present, and set the
frame's metadata with the remaining Exif entries.
Signed-off-by: James Almer <jamrial@gmail.com>
Otherwise, the user requested priority of packet side data will be ignored.
For this, move the relevant functions to decode.c, as they need access to an
AVCodecContext.
Signed-off-by: James Almer <jamrial@gmail.com>
This reverts commit 1c17061397.
The commit intended to provide certain codecs using *_mp4toannexb
bitstream filters with updated (annex B) extradata (even when
the user-supplied one was ISOBMFF), yet BSFs are allowed to change
way more. The media100_to_mjpegb BSF used by the media100 decoder
changes the codec id; the commit being reverted therefore changed
AVCodecContext.codec_id which is an API violation and broke
media100 decoding with the FFmpeg cli tool.
This commit also made changes from the internal BSF externally
visible. extradata is documented to be "owned by the codec and
freed in avcodec_free_context()" which does not include replacing
it with something else in avcodec_open2() and may surprise users
who think that AVCodecContext.extradata is immutable before
avcodec_free_context(). It also incurred a memdup which is completely
unnecessary for most decoders.
Therefore this commit is reverted. The problem it tried to solve
will be solved differently in the next commit.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
The buffer references may not be writable at this point, as the decoder
calls get_buffer2() with the AV_GET_BUFFER_FLAG_REF flag.
Fixes races as reported by tsan, producing correct output regardless of
threading choices.
Signed-off-by: James Almer <jamrial@gmail.com>
All users (namely HEVC) that use ff_progress_frame_alloc()
should just use ff_thread_get_buffer(). Using
ff_progress_frame_get_buffer() is not a must; it is merely
a convenience wrapper.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>