1
0
Fork 0
Commit Graph

88 Commits

Author SHA1 Message Date
Andreas Rheinhardt 790f793844 avutil/common: Don't auto-include mem.h
There are lots of files that don't need it: The number of object
files that actually need it went down from 2011 to 884 here.

Keep it for external users in order to not cause breakages.

Also improve the other headers a bit while just at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-31 00:08:43 +01:00
James Almer 7bca8ce422 avcodec: remove deprecated FF_API_VT_HWACCEL_CONTEXT
Signed-off-by: James Almer <jamrial@gmail.com>
2024-03-07 08:53:30 -03:00
Zhao Zhili 7f900a737f avcodec/videotoolbox: specify color range for hw frame ctx
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-01-04 17:33:38 +08:00
Andreas Rheinhardt 2db94a96c8 avcodec/hevc_ps: Use RefStruct API for parameter sets
Avoids allocations and error checks for these allocations;
e.g. syncing buffers across threads can't fail any more
and needn't be checked. It also gets rid of casts and
indirections.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:34:28 +02:00
Andreas Rheinhardt e35dfe864d avcodec/avcodec: Add FFHWAccel, hide internals of AVHWAccel
This commit is the AVHWAccel analogue of commit
20f972701806be20a77f808db332d9489343bb78: It moves the private fields
of AVHWAccel to a new struct FFHWAccel extending AVHWAccel
in an internal header (namely hwaccel_internal.h).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-08-07 09:50:29 +02:00
Jun Zhao 639ded10e3 lavc/videotoolbox: fix warnings
fix mixing declarations and code warnings

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2023-04-09 18:12:26 +08:00
Zhao Zhili 9a180f60a9 avcodec/videotoolbox: don't use av_ prefix for local function
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-01-26 23:48:41 +08:00
Zhao Zhili d6bd980da6 avcodec/videotoolbox: deprecate creating AVVideotoolboxContext by user
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-01-26 23:48:16 +08:00
Zhao Zhili ade89bc6de avcodec/videotoolbox: prefer hw_frames_ctx/hw_device_ctx over hwaccel_context
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-01-26 23:48:08 +08:00
Zhao Zhili 79e9bdf749 avcodec/videotoolbox: fix NULL pointer dereference
In the code path of av_videotoolbox_default_init/init2(),
avctx->internal->hwaccel_priv_data is NULL and passed to
decoder_cb.decompressionOutputRefCon. Then it will be dereferenced
inside videotoolbox_decoder_callback().

Delay videotoolbox_star() until ff_videotoolbox_common_init() to
fix the bug.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-01-26 23:47:42 +08:00
Anton Khirnov 8576c3c5d8 lavc/videotoolbox: deprecate write-only output_callback
This field has never been used for anything, so stop setting it and
deprecate it.
2022-09-19 15:18:20 +02:00
Anton Khirnov d7f4ad88a0 lavc/videotoolbox: do not pass AVCodecContext to decoder output callback
The opaque parameter for the callback is set in videotoolbox_start(),
called when the hwaccel is initialized. When frame threading is used,
avctx will be the context corresponding to the frame thread currently
doing the decoding. Using this same codec context in all subsequent
invocations of the decoder callback (even those triggered by a different
frame thread) is unsafe, and broken after
cc867f2c09, since each frame thread now
cleans up its hwaccel state after decoding each frame.

Fix this by passing hwaccel_priv_data as the opaque parameter, which
exists in a single instance forwarded between all frame threads.

The only other use of AVCodecContext in the decoder output callback is
as a logging context. For this purpose, store a logging context in
hwaccel_priv_data.
2022-09-19 15:18:20 +02:00
rcombs 792a9f2406 lavc/videotoolboxdec: insert emu-prevention bytes for HEVC as well
Fixes decoding of files with sync-fooling sequences in their PSs.

Signed-off-by: rcombs <rcombs@rcombs.me>
2022-06-01 19:38:50 -05:00
rcombs a465e2c39e lavc/videotoolboxdec: fix writing too many 1 bits for the reserved fields
Signed-off-by: rcombs <rcombs@rcombs.me>
2022-06-01 19:38:50 -05:00
rcombs 928b22edfe lavc/videotoolboxdec: fix generating HEVC general_profile_compatibility_flags
We store this as an array of bools, not a bitfield.

Signed-off-by: rcombs <rcombs@rcombs.me>
2022-06-01 19:38:50 -05:00
rcombs 686b64e155 lavc/videotoolboxdec: fix escaping sequential zero sequences
This ensure that e.g. 0000000000 becomes 00000300 000300,
rather than 00000300 0000.

Signed-off-by: rcombs <rcombs@rcombs.me>
2022-06-01 19:38:50 -05:00
rcombs dfbc921f9f lavc/videotoolboxdec: warn on nonzero status in the callback
Signed-off-by: rcombs <rcombs@rcombs.me>
2022-06-01 19:38:50 -05:00
Martin Storsjö a78f136f3f configure: Use a separate config_components.h header for $ALL_COMPONENTS
This avoids unnecessary rebuilds of most source files if only the
list of enabled components has changed, but not the other properties
of the build, set in config.h.

Signed-off-by: Martin Storsjö <martin@martin.st>
2022-03-16 14:12:49 +02:00
Limin Wang d15f65c469 avcodec/videotoolbox: add internal.h for header depenedency
Fixes build failures for videotoolbox

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-14 09:19:27 +01:00
Limin Wang 46f43f222e avcodec/videotoolbox: Fix undefined symbol with minimal configuration
Please reproduced with the following minimal configure command:
./configure --enable-shared --disable-all --enable-avcodec --enable-decoder=h264 --enable-hwaccel=h264_videotoolbox

You'll get below error:

Undefined symbols for architecture x86_64:
  "_ff_videotoolbox_vpcc_extradata_create", referenced from:
      _videotoolbox_start in videotoolbox.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Reported-by: Cameron Gutman <aicommander@gmail.com>
Tested-by: Cameron Gutman <aicommander@gmail.com>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2022-01-05 09:26:52 +08:00
rcombs b04601ed6a lavc/videotoolbox: set attachments on decoded buffers
VideoToolbox internally sets all the colorspace parameters to BT709,
regardless of what the bitstream actually indicates, so we need to
replace that with what we've parsed.
2021-12-22 18:43:34 -06:00
Limin Wang a7df966c82 avcodec/videotoolbox: fix use of unknown builtin '__builtin_available'
Old system is:
OSX version: 10.11.6
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-12-04 08:32:31 +08:00
James Almer 0d924d6e5a avcodec/videotoolbox: silence some -Wimplicit-fallthrough warnings
Signed-off-by: James Almer <jamrial@gmail.com>
2021-11-28 20:23:26 -03:00
rcombs c7e527f7f3 lavc/videotoolbox: fix build on pre-10.14 SDKs
Also fixes handling of future codec tags (needed to bswap)
2021-11-28 17:15:36 -06:00
rcombs da0179b262 lavc/proresdec: add videotoolbox hwaccel 2021-11-28 16:40:58 -06:00
rcombs 350eb59f8c videotoolbox: add alpha support 2021-11-28 16:40:58 -06:00
rcombs a41a2efc85 lavc/videotoolbox: add VP9 hardware acceleration
On M1 Max, this supports profiles 0 and 2, but not 1 and 3.
2021-11-28 16:40:58 -06:00
rcombs e3c6cc96cf lavc/videotoolbox: call VTRegisterSupplementalVideoDecoderIfAvailable
This is required for VP9 to work.
2021-11-28 16:40:44 -06:00
rcombs 530c4a7ea9 lavc/videotoolbox: expose some functions as lavc-internal 2021-11-28 16:40:44 -06:00
rcombs f0952f87bc lavc/videotoolbox: select 4:2:2 and 4:4:4 formats when applicable 2021-11-28 16:40:43 -06:00
rcombs b0c07f2938 lavc/videotoolbox: fix format computation
Use sw_pix_fmt instead of pix_fmt (consistent with other hwaccels)
2021-11-28 16:40:43 -06:00
rcombs 79e51d6c0f lavc/videotoolbox: escape 0x00000[0-3]s in avcC PSs 2021-11-28 16:40:43 -06:00
Jan Ekström ed524136e0 avcodec/videotoolbox: make FFmpeg-to-VT mapping error more informative
Now logs the actual failed-to-map pixel format as well as range.
2021-01-02 14:36:22 +02:00
Steven Liu 4aa391388a avcodec/videotoolbox: add logging context to log
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-10-08 13:47:25 +08:00
Rodger Combs 77937a42e7 lavc/videotoolboxdec: fix crop handling when multithreaded
This was partially fixed by 233cd89, but it made changes to AVFrame fields
from within end_frame, which doesn't work consistently when multithreading
is enabled. This is what the post_process function is for.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-15 11:13:29 -07:00
Akemi 2a9d461abc avcodec/videotoolbox: add support for full range pixel formats
Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-04 10:51:20 -07:00
Pavel Koshevoy 22a14ee753 avcodec/videotoolbox_hevc: avoid leaking cached_hw_frames_ctx
vtctx->cached_hw_frames_ctx is unref'd in videotoolbox_uninit,
but videotoolbox_hevc used ff_videotoolbox_uninit which
doesn't unref cache_hw_frames_ctx.

Signed-off-by: Pavel Koshevoy <pkoshevoy@gmail.com>
2019-08-23 23:54:27 -06:00
fumoboy007 036b4b0f85 avcodec/videotoolbox: add support for 10bit pixel format
this patch was originally posted on issue #7704 and was slightly
adjusted to check for the availability of the pixel format.
2019-04-16 03:43:06 +03:00
Rodger Combs ce6301a46f avcodec/vt_hevc: fix crash if vps_list[0] or sps_list[0] are null
Instead of assuming id 0 is used, use the same logic as used for PPS,
where all available entries in the list are emitted.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-03-19 14:56:21 -07:00
Akemi 233cd89056 lavc/videotoolbox: Fix cropping with HEVC and H264 videos
videotoolbox returns an already cropped stream which led to double
cropping. this issue was introduced with the refactor of the cropping
mechanism in commit 07596e4 for h264 and 000fb61 for HEVC.

to fix this we set the cropping of the frame and the output frame to 0.

Tested-by: ponpon
Fixes ticket #7544.
2018-11-12 12:32:17 +01:00
Aman Gupta 8f146b526f avcodec/videotoolbox: fix decoding of some HEVC videos
In a normal hwaccel, the AVHWFramesContext sets AVFrame.hw_frames_ctx
when it initializes a new AVFrame in av_hwframe_get_buffer().

But the VT hwaccel doesn't know what hw_frames_ctx to assign when
the AVFrame is first created, because it depends on the format of
the pixbuf that the decoder eventually decides to return. Thus
newly created AVFrames always have a NULL hw_frames_ctx, and the
hwaccel would only assign the ctx once a frame was done decoding.
This worked fine with the H264 decoder, but with the HEVC decoder
the frame's data may be moved to another empty AVFrame. Since the
empty AVFrame never had hw_frames_ctx set, a frame with a NULL
ctx could be returned to the API user.

This patch works around the issue by moving the derived
hw_frames_ctx from the AVFrame to a new VTHWFrame which now holds
both the CVPixelBufferRef and the AVBuffer. The hw_frames_ctx
is only copied to the AVFrame right before it is about to be
returned to the user in videotoolbox_postproc_frame() (since
in the case of VT, the hw_frames_ctx is only there for the API
user anyway).

Fixes playback on macOS and iOS of some hevc videos like
https://s3.amazonaws.com/tmm1/videotoolbox/germany-hevc-zdf.ts

Signed-off-by: Aman Gupta <aman@tmm1.net>
2018-05-18 12:38:51 -07:00
Aman Gupta 07d175d0b0 avcodec/videotoolbox: split h264/hevc callbacks
Previously the shared callbacks were trying to interpret
avctx->priv_data as H264Context*

Signed-off-by: Aman Gupta <aman@tmm1.net>
2018-05-09 12:26:31 -07:00
Aman Gupta dd77cca1c4 avcodec/videotoolbox: cleanups
No functional changes.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2018-05-09 12:26:31 -07:00
Aman Gupta bcff983dc3 avcodec/videotoolbox: fix kVTCouldNotFindVideoDecoderErr trying to decode HEVC on iOS
Older iOS devices don't have a hardware HEVC decoder, but the
software decoder offered by VideoToolbox is well-optimized and
performs much better than the ffmpeg decoder.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2018-05-04 18:24:49 -07:00
Aman Gupta 84e03db9a3 avcodec/videotoolbox: improve logging of decoder errors
Signed-off-by: Aman Gupta <aman@tmm1.net>
2018-05-04 18:24:49 -07:00
Rodger Combs 4c0798578c lavc/videotoolbox: fix failure to decode PAFF
Signed-off-by: Aman Gupta <aman@tmm1.net>
2018-04-10 10:24:28 -07:00
Rodger Combs 63d875772d lavc/videotoolbox: fix threaded decoding
AVHWAccel.end_frame can run on a worker thread. The assumption of the
frame threading code is that the worker thread will change the AVFrame
image data, not the AVFrame fields. So the AVFrame fields are not synced
back to the main thread. But this breaks videotoolbox due to its special
requirements (everything else is fine). It actually wants to update
AVFrame fields.

The actual videotoolbox frame is now stored in the dummy AVBufferRef, so
it mimics what happens in non-videotoolbox cases. (Changing the
AVBufferRef contents is a bit like changing the image data.) The
post_process callback copies that reference to the proper AVFrame field.

Based on a patch by wm4.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2018-03-08 14:04:25 -08:00
Aman Gupta b5d56d8ef1 avcodec/videotoolbox: fix SEGV when hwaccel decoding h264 with ffmpeg.c
Signed-off-by: Aman Gupta <aman@tmm1.net>
2017-11-28 08:50:13 -08:00
Mark Thompson 3a71bcc213 lavc: Mark all AVHWAccel structures as const 2017-11-26 21:41:19 +00:00
Aman Gupta 259dc4e013 libavcodec/videotoolbox: fix decoding of h264 streams with minor SPS changes
Previously the codec kept an entire copy of the SPS, and restarted the VT decoder
session whenever it changed. This fixed decoding errors in [1], as
described in 9519983c. On further inspection, that sample features an SPS change
from High/4.0 to High/3.2 while moving from one scene to another.

Yesterday I received [2], which contains minor SPS changes where the
profile and level do not change. These occur frequently and are not associated with
scene changes. After 9519983c, the VT decoder session is recreated unnecessarily when
these are encountered causing visual glitches.

This commit simplifies the state kept in the VTContext to include just the first three
bytes of the SPS, containing the profile and level details. This is populated initially
when the VT decoder session is created, and used to detect changes and force a restart.

This means minor SPS changes are fed directly into the existing decoder, whereas
profile/level changes force the decoder session to be recreated with the new parameters.

After this commit, both samples [1] and [2] playback as expected.

[1] https://s3.amazonaws.com/tmm1/videotoolbox/spschange.ts
[2] https://s3.amazonaws.com/tmm1/videotoolbox/spschange2.ts

Signed-off-by: Aman Gupta <aman@tmm1.net>
2017-11-20 10:23:43 -08:00