1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00
Commit Graph

71 Commits

Author SHA1 Message Date
James Almer
9ea6d2149e avcodec/decode: add a flags parameter to ff_reget_buffer()
Some decoders may not need a writable buffer in some specific cases, but only
a reference to the existing buffer with updated frame properties instead, for
the purpose of returning duplicate frames. For this, the
FF_REGET_BUFFER_FLAG_READONLY flag is added, which will prevent potential
allocations and buffer copies when they are not needed.

Signed-off-by: James Almer <jamrial@gmail.com>
2019-09-04 10:07:12 -03:00
Marton Balint
3a09dbdb4a avcodec: remove some dead assignments
Signed-off-by: Marton Balint <cus@passwd.hu>
2019-08-22 21:38:41 +02:00
Gyan Doshi
3153a6502a avcodec: add AV_CODEC_FLAG_DROPCHANGED to flags
Discard decoded frames which differ from first decoded frame in stream.
2019-04-20 10:38:01 +05:30
Carl Eugen Hoyos
9bcd40c298 lavc/decode: Initialize return value for get_format() failure.
Silences a warning:
libavcodec/decode.c:1378:13: warning: variable 'ret' is used uninitialized whenever 'if' condition is true
2018-12-10 01:50:04 +01:00
Jun Zhao
903f2beafc lavc/decode: Fix the error number report if av_image_fill_pointers fail.
-1 will be map to error number "EPERM", and will be map to the error
message like "Error while decoding stream #0:0: Operation not permitted",
it's a strange error message when debug update_frame_pool fail,
now only return the error code from av_image_fill_pointers in case
of av_image_fill_pointers failure.

Signed-off-by: Jun Zhao <mypopydev@gmail.com>
2018-10-30 13:16:47 +08:00
James Almer
87588caf8c Revert "avcodec/decode: copy the output parameters from the last bsf in the chain back to the AVCodecContext"
This reverts commit f631c328e6.

The avcodec_parameters_to_context() call was freeing and reallocating
AVCodecContext->extradata, essentially taking ownership of it, which according
to the doxy is user owned. This is an API break and has produced crashes in
some library users like Firefox[1].

Revert until a better solution is found to internally propagate the filtered
extradata back into the decoder context, or a decision is made to change the
API.

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1486080

Signed-off-by: James Almer <jamrial@gmail.com>
2018-10-24 16:43:33 -03:00
James Almer
f631c328e6 avcodec/decode: copy the output parameters from the last bsf in the chain back to the AVCodecContext
Certain AVCodecParameters, like the contents of the extradata, may be changed
by the init() function of any of the bitstream filters in the chain.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-08-16 23:43:13 -03:00
James Almer
94fe138de0 avcodec/decode: flush the internal bsfs instead of constantly reinitalizing them
Initialize the bsfs once when opening the codec and uninitialize them once when
closing it, instead of at every codec flush/seek.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-08-16 23:43:12 -03:00
Aman Gupta
37644f0477 avcodec: parse options from AVCodec.bsfs
Fixes a bug that would prevent using multiple comma-separated filters,
and allows options to be passed to each filter.

Based on similar loop in ffmpeg_opt.c's new_output_stream().

Signed-off-by: Aman Gupta <aman@tmm1.net>
2018-07-19 09:15:13 -07:00
Michael Niedermayer
2e205bfc14 avcodec/decode: Consider STRIDE_ALIGN in get_buffer_internal() when checking width
STRIDE_ALIGN is not known in libavutil so av_image_check_size* cannot consider it

Fixes: OOM
Fixes: 8291/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SNOW_fuzzer-5176528009691136

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-06-15 21:51:42 +02:00
wm4
709e0291d6 avcodec/decode: fix warning when decoding pseudo paletted formats
The pseudo palette allocation is optional now. But if it's still
allocated (like the internal get_buffer2 implementation does, for
compatibility), it shouldn't print a warning.
2018-04-05 16:58:40 +02:00
wm4
d6fc031caf avutil/pixdesc: deprecate AV_PIX_FMT_FLAG_PSEUDOPAL
PSEUDOPAL pixel formats are not paletted, but carried a palette with the
intention of allowing code to treat unpaletted formats as paletted. The
palette simply mapped the byte values to the resulting RGB values,
making it some sort of LUT for RGB conversion.

It was used for 1 byte formats only: RGB4_BYTE, BGR4_BYTE, RGB8, BGR8,
GRAY8. The first 4 are awfully obscure, used only by some ancient bitmap
formats. The last one, GRAY8, is more common, but its treatment is
grossly incorrect. It considers full range GRAY8 only, so GRAY8 coming
from typical Y video planes was not mapped to the correct RGB values.
This cannot be fixed, because AVFrame.color_range can be freely changed
at runtime, and there is nothing to ensure the pseudo palette is
updated.

Also, nothing actually used the PSEUDOPAL palette data, except xwdenc
(trivially changed in the previous commit). All other code had to treat
it as a special case, just to ignore or to propagate palette data.

In conclusion, this was just a very strange old mechnaism that has no
real justification to exist anymore (although it may have been nice and
useful in the past). Now it's an artifact that makes the API harder to
use: API users who allocate their own pixel data have to be aware that
they need to allocate the palette, or FFmpeg will crash on them in
_some_ situations. On top of this, there was no API to allocate the
pseuo palette outside of av_frame_get_buffer().

This patch not only deprecates AV_PIX_FMT_FLAG_PSEUDOPAL, but also makes
the pseudo palette optional. Nothing accesses it anymore, though if it's
set, it's propagated. It's still allocated and initialized for
compatibility with API users that rely on this feature. But new API
users do not need to allocate it. This was an explicit goal of this
patch.

Most changes replace AV_PIX_FMT_FLAG_PSEUDOPAL with FF_PSEUDOPAL. I
first tried #ifdefing all code, but it was a mess. The FF_PSEUDOPAL
macro reduces the mess, and still allows defining FF_API_PSEUDOPAL to 0.

Passes FATE with FF_API_PSEUDOPAL enabled and disabled. In addition,
FATE passes with FF_API_PSEUDOPAL set to 1, but with allocation
functions manually changed to not allocating a palette.
2018-04-03 17:53:00 +02:00
wm4
b7d0d912ef avcodec: add a subcharenc mode that disables UTF-8 check
This is for applications which want to explicitly check for invalid
UTF-8 manually, and take actions that are better than dropping invalid
subtitles silently. (It's pretty much silent because sporadic avcodec
error messages are so common that you can't reasonably display them in a
prominent and meaningful way in a application GUI.)
2018-03-25 19:27:02 +02:00
James Almer
23e1bf6e51 avcodec: remove unnecessary calls to ff_init_buffer_info()
And remove the function altogether while at it. It's a duplicate of
another.

Reviewed-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-02-14 20:54:20 -03:00
Mark Thompson
9471122a1b Merge commit 'cad739dace55e3446ef7180de688173cd19fb000'
* commit 'cad739dace55e3446ef7180de688173cd19fb000':
  lavc: Add per-thread surfaces in get_hw_frame_parameters()

Merged-by: Mark Thompson <sw@jkqxz.net>
2018-02-12 22:22:30 +00:00
Mark Thompson
d23fff0d8a Merge commit '5b145290df2998a9836a93eb925289c6c8b63af0'
* commit '5b145290df2998a9836a93eb925289c6c8b63af0':
  lavc: Add support for increasing hardware frame pool sizes

Merged-by: Mark Thompson <sw@jkqxz.net>
2018-02-12 22:19:38 +00:00
Mark Thompson
cad739dace lavc: Add per-thread surfaces in get_hw_frame_parameters()
This number is definitely required when frame threading is enabled, so
add it here rather than forcing all users to handle it themselves.

DXVA2 contained this addition in specific code as well (therefore being
added twice in the internal case) - just remove it from there.
2018-02-11 22:00:48 +00:00
Mark Thompson
5b145290df lavc: Add support for increasing hardware frame pool sizes
AVCodecContext.extra_hw_frames is added to the size of hardware frame
pools created by libavcodec for APIs which require fixed-size pools.
This allows the user to keep references to a greater number of frames
after decode, which may be necessary for some use-cases.

It is also added to the initial_pool_size value returned by
avcodec_get_hw_frames_parameters() if a fixed-size pool is required.
2018-02-11 22:00:33 +00:00
Mark Thompson
2117725dc5 lavc: Mark all AVHWAccel structures as const 2017-12-19 23:24:24 +00:00
Mark Thompson
39056b5240 lavc: Use hardware config information in ff_get_format()
This removes the dependency that hardware pixel formats previously had on
AVHWAccel instances, meaning only those which actually do something need
exist after this patch.

Also updates avcodec_default_get_format() to be able to choose hardware
formats if either a matching device has been supplied or no additional
external configuration is required, and avcodec_get_hw_frames_parameters()
to use the hardware config rather than searching the old hwaccel list.
2017-12-19 23:21:59 +00:00
James Cowgill
02ba4b91b5 avcodec/decode: reset codec on receiving packet after EOF in compat_decode
In commit 061a0c14bb ("decode: restructure the core decoding code"), the
deprecated avcodec_decode_* APIs were reworked so that they called into the
new avcodec_send_packet / avcodec_receive_frame API. This had the side effect
of prohibiting sending new packets containing data after a drain
packet, but in previous versions of FFmpeg this "worked" and some
applications relied on it.

To restore some compatibility, reset the codec if we receive a new non-drain
packet using the old API after draining has completed. While this does
not give the same behaviour as the old API did, in the majority of cases
it works and it does not require changes to any other part of the decoding
code.

Fixes ticket #6775
Signed-off-by: James Cowgill <jcowgill@debian.org>
Signed-off-by: Marton Balint <cus@passwd.hu>
2017-12-09 21:28:24 +01:00
Mark Thompson
3a71bcc213 lavc: Mark all AVHWAccel structures as const 2017-11-26 21:41:19 +00:00
Mark Thompson
67e81d79cc lavc: Use hardware config information in ff_get_format()
This removes the dependency that hardware pixel formats previously had on
AVHWAccel instances, meaning only those which actually do something need
exist after this patch.

Also updates avcodec_default_get_format() to be able to choose hardware
formats if either a matching device has been supplied or no additional
external configuration is required, and avcodec_get_hw_frames_parameters()
to use the hardware config rather than searching the old hwaccel list.

The FF_CODEC_CAP_HWACCEL_REQUIRE_CLASS mechanism is deleted because it
no longer does anything (the codec already contains the pointers to the
matching hwaccels).
2017-11-26 21:35:53 +00:00
James Almer
48e4eda11d Merge commit 'b46a77f19ddc4b2b5fa3187835ceb602a5244e24'
* commit 'b46a77f19ddc4b2b5fa3187835ceb602a5244e24':
  lavc: external hardware frame pool initialization

Includes the fix from e724bdfffb

Merged-by: James Almer <jamrial@gmail.com>
2017-11-11 20:33:26 -03:00
Timo Rothenpieler
8dd73f68a6 avcodec/decode: always free private_ref
There is no reason to keep this intact when decoding failed, specially
as private_ref is supposed to always be NULL when a frame is returned to
the user.
2017-11-11 14:19:05 +01:00
wm4
0aecc08e5f avcodec/decode: add missing \n to log message 2017-11-10 22:48:34 +01:00
wm4
ae5046e492 avcodec: allow multiple hwaccels for the same codec/pixfmt
Currently, AVHWAccels are looked up using a (codec_id, pixfmt) tuple.
This means it's impossible to have 2 decoders for the same codec and
using the same opaque hardware pixel format.

This breaks merging Libav's CUVID hwaccel. FFmpeg has its own CUVID
support, but it's a full stream decoder, using NVIDIA's codec parser.
The Libav one is a true hwaccel, which is based on the builtin software
decoders.

Fix this by introducing another field to disambiguate AVHWAccels, and
use it for our CUVID decoders. FF_CODEC_CAP_HWACCEL_REQUIRE_CLASS makes
this mechanism backwards compatible and optional.
2017-11-10 22:48:34 +01:00
Anton Khirnov
81c021c6a2 decode: add a per-frame private data for hwaccel use
This will be useful in the CUVID hwaccel. It should also eventually
replace current decoder-specific mechanisms used by various other
hwaccels.

Merges Libav commit 704311b294.
2017-11-10 19:48:09 +01:00
Anton Khirnov
7fa64514c8 decode: add a mechanism for performing delayed processing on the decoded frames
This will be useful in the CUVID hwaccel.

Merges Libav commit badf0951f5.
2017-11-10 19:48:05 +01:00
Anton Khirnov
9f1cfd88af decode: add a method for attaching lavc-internal data to frames
Use the AVFrame.private_ref field.

This new struct will be useful in the following commits.

Merges Libav commit 359a8a3e2d.
2017-11-10 16:56:54 +01:00
Anton Khirnov
4776c61424 decode: avoid leaks on failure in ff_get_buffer()
If the get_buffer() call fails, the frame might have some side data
already set. Make sure it gets freed.

Merges Libav commit de77671438.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-10-29 21:25:49 -03:00
wm4
e724bdfffb lavc: fix hw_device_ctx operation
Commit b46a77f19d accidentally broke this (requested change that was
added to the patch later and which was not fully tested).

Signed-off-by: Mark Thompson <sw@jkqxz.net>
2017-10-23 23:35:31 +01:00
James Almer
417d473bde avcodec: remove ABI portion of the side data merging API
The actual API is left in place until the deprecation period ends.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-10-22 00:30:12 -03:00
James Almer
c68a3ab96e Merge commit '7b917041184874e7d7cba4450813de7e0bb28a33'
* commit '7b917041184874e7d7cba4450813de7e0bb28a33':
  lavc: Drop deprecated VDPAU codec capability

Merged-by: James Almer <jamrial@gmail.com>
2017-10-21 23:40:03 -03:00
wm4
b46a77f19d lavc: external hardware frame pool initialization
This adds a new API, which allows the API user to query the required
AVHWFramesContext parameters. This also reduces code duplication across
the hwaccels by introducing ff_decode_get_hw_frames_ctx(), which uses
the new API function. It takes care of initializing the hw_frames_ctx
if needed, and does additional error handling and API usage checking.

Support for VDA and Cuvid missing.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2017-10-19 17:10:59 +02:00
Karthick J
f7b7d51a37 avcodec/decode: Pass on the Closed Captions Side Data
Signed-off-by: Karthick J <kjeyapal@akamai.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2017-09-28 21:12:08 +02:00
James Almer
6cadbb16e9 avcodec: add AV_HWACCEL_CODEC_CAP_EXPERIMENTAL flag
This flag replaces the deprecated, non-prefixed HWACCEL_CODEC_CAP_EXPERIMENTAL
one.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-09-04 17:48:41 -03:00
wm4
caa12027ba lavc, lavu: move frame cropping to a convenience function
Signed-off-by: Anton Khirnov <anton@khirnov.net>

Merged from Libav commit 47399ccdfd.
2017-08-08 13:35:09 +02:00
Anton Khirnov
704311b294 decode: add a per-frame private data for hwaccel use
This will be useful in the CUVID hwaccel. It should also eventually
replace current decoder-specific mechanisms used by various other
hwaccels.
2017-07-26 23:24:14 +02:00
Anton Khirnov
badf0951f5 decode: add a mechanism for performing delayed processing on the decoded frames
This will be useful in the CUVID hwaccel.
2017-07-26 23:24:07 +02:00
Anton Khirnov
359a8a3e2d decode: add a method for attaching lavc-internal data to frames
Use the AVFrame.opaque_ref field. The original user's opaque_ref is
wrapped in the lavc struct and then unwrapped before the frame is
returned to the caller.

This new struct will be useful in the following commits.
2017-07-26 23:23:58 +02:00
Anton Khirnov
de77671438 decode: avoid leaks on failure in ff_get_buffer()
If the get_buffer() call fails, the frame might have some side data
already set. Make sure it gets freed.

CC: libav-stable@libav.org
2017-07-26 23:23:47 +02:00
wm4
47399ccdfd lavc, lavu: move frame cropping to a convenience function
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2017-07-26 23:20:40 +02:00
Anton Khirnov
d14179e3d4 hwframe: Allow hwaccel frame allocators to align surface sizes
Hardware accelerated decoding generally uses AVHWFramesContext for pool
allocation of hardware surfaces. These are setup to allocate surfaces
aligned to hardware and hwaccel API requirements. Due to the
architecture, av_hwframe_get_buffer() will return AVFrames with
the dimensions set to the aligned sizes.

This causes some decoders (like hevc) return these aligned size as
final frame size, instead of cropping them to the video's actual
dimensions. To make sure this doesn't happen, crop the frame to the
size the decoder expects when ff_get_buffer() is called.

Merges Libav commit 3fdf50f9e8.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2017-06-27 18:05:02 +02:00
wm4
865360ba63 lavc: set avctx->hwaccel before init
So a hwaccel can access avctx->hwaccel in init for whatever reason. This
is for the new d3d hwaccel API. We could create separate entrypoints for
each of the 3 hwaccel types (dxva2, d3d11va, new d3d11va), but this
seems nicer.

Merges Libav commit bd747b9226.

Signed-off-by: Diego Biurrun <diego@biurrun.de>
2017-06-27 18:05:02 +02:00
Anton Khirnov
3fdf50f9e8 hwframe: Allow hwaccel frame allocators to align surface sizes
Hardware accelerated decoding generally uses AVHWFramesContext for pool
allocation of hardware surfaces. These are setup to allocate surfaces
aligned to hardware and hwaccel API requirements. Due to the
architecture, av_hwframe_get_buffer() will return AVFrames with
the dimensions set to the aligned sizes.

This causes some decoders (like hevc) return these aligned size as
final frame size, instead of cropping them to the video's actual
dimensions. To make sure this doesn't happen, crop the frame to the
size the decoder expects when ff_get_buffer() is called.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2017-06-27 00:23:12 +02:00
John Rummell
966a0a814d avcodec/decode: Update decode_simple_internal() to get the side data correctly.
Use avci->last_pkt_props to get the side data. Using |pkt| doesn't work
when FF_API_MERGE_SD is set, as the compressed side data is expanded into
|tmp|, leaving the original |pkt| unchanged.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-06-20 17:14:17 -03:00
wm4
bd747b9226 lavc: set avctx->hwaccel before init
So a hwaccel can access avctx->hwaccel in init for whatever reason. This
is for the new d3d hwaccel API. We could create separate entrypoints for
each of the 3 hwaccel types (dxva2, d3d11va, new d3d11va), but this
seems nicer.

Signed-off-by: Diego Biurrun <diego@biurrun.de>
2017-06-08 20:55:45 +02:00
James Almer
f20161d899 avcodec/decode: fix function name 2017-05-20 13:17:12 -03:00
Anton Khirnov
02327d1237 decode: fix the code reducing cropping to preserve alignment
Currently it does not work at all.

Libav Bug-Id: 1058
(cherry picked from commit 8652a2c248)
2017-05-20 13:13:10 -03:00