Commit graph

138 commits

Author SHA1 Message Date
tt2468 4eef796f80 deps/media-playback: Fix init of swscale with hw decode
Checking the format of the AVCodecContext will result in using the
format of the hardware-side frames, not the software-side frames. This
uses the software frame parameters itself to initialize the swscale
context.
2024-06-16 02:47:06 +02:00
moocowsheep c9f7a3c325 deps/media-playback: Prioritize CUDA decoder 2024-05-11 20:29:43 -07:00
tt2468 8fd61c2049 deps/media-playback: Detect+handle video res changes with hwaccel 2024-03-19 16:58:20 -07:00
pkv 41f07913e5 deps/media-playback: Fix hardware decoding of streams
Fixes issue #10369.
Since the update to FFmpeg 6.1, streams to a Media Source are broken
if hardware decoding is enabled (both RTMP or SRT have been reported).
The video is black although the audio is decoded fine.
The manual copy of metadata introduced in commit [1] does not work any
more for some unfathomable reasons.
As a fix we call instead the av_frame_copy_props function used in FFmpeg
app in a similar context (hardware decoding) [2].
The metadata are copied without issues.
There is no need to guard the use of that function since it was
introduced 9 years ago in avutil/frame.c.

[1] 22fde5cdcd
[2] https://github.com/FFmpeg/FFmpeg/master/fftools/ffmpeg_dec.c

Signed-off-by: pkv <pkv@obsproject.com>
2024-03-18 14:13:55 -04:00
derrod a029d2ac01 deps/media-playback: Replace circlebuf with deque 2024-01-16 16:45:09 +01:00
PatTheMav aa137f0766 deps: Update CMake target source lists with alphabetic sorting
Also manually updates some CMake script files to make code more
readable.
2023-12-19 17:59:44 -05:00
Stephen Seo 6e080a6806 deps/media-playback: In check for key-frame, use new FFmpeg 6.1 API
Fixes for using FFmpeg 6.1 due to deprecations. Uses `#if` macros to
allow builds for using older versions of FFmpeg.

AVFrame.key_frame was replaced with a flag in AVFrame.flags. The commit
adding the flag is [1] in FFmpeg's repository, and the deprecation is in
commit [2].

In summary of the "key_frame" change, AVFrame.key_frame is deprecated,
and AVFrame.flags indicates with a bit flag if it is a key frame (with
the enum/defined AV_FRAME_FLAG_KEY).

[1]: avutil/frame: add a keyframe flag to AVFrame
cc11191fda

[2]: avutil/frame: deprecate key_frame
3e06f6f040
2023-12-02 17:43:18 -06:00
Stephen Seo 4b5be75c7e deps/media-playback: Use new (nb_)coded_side_data FFmpeg 6.1 API
Fixes for using FFmpeg 6.1 due to deprecations. Uses `#if` macros to
allow builds for using older versions of FFmpeg.

The change in deps/media-playback/media-playback/decode.c is due to
FFmpeg moving "side_data" into AVCodecParameters which is mentioned in
commit [1] in FFmpeg's repository.

In summary of the "side_data" change, AVStream.side_data is deprecated
and replaced with AVStream.codecpar->coded_side_data, and
AVStream.nb_side_data is replaced with
AVStream.codecpar->nb_coded_side_data.

[1]: avcodec/codec_par: add side data to AVCodecParameters
21d7cc6fa9
2023-12-02 17:43:18 -06:00
Neal Gompa bc14a25b15 deps: Add license declaration files 2023-09-19 13:35:49 -04:00
Ryan Foster 41a915db9e deps: Update CMake minimum to 3.22
Since Ubuntu 22.04 is now our minimum supported Ubuntu version, and it
has CMake 3.22, let's make CMake 3.22 the minimum CMake version.
2023-08-05 16:45:46 -07:00
derrod 7731f98d87 deps/media-playback: Remove legacy FFmpeg compatibility 2023-07-12 15:57:43 -04:00
CodeYan01 d1a7070d10 obs-ffmpeg: Prevent media source restart
Some options do not require a media source restart. Saving source
unchanged source settings should also not trigger a restart.

I tried to also make it so speed changes do not require a restart by
manipulating the elapsed timestamp  for the source, but it sometimes
causes the first few milliseconds after saving settings to be rough or
slightly distorted. I am also unsure whether a/v frame buffers should be
cleared on a speed change (and how to) so I made it so restarts are
required for speed changes. Chiyo also mentioned that successive quick
speed changes will cause maximum audio buffering (which I was able to
reproduce once).

Nonlocal file playback is unaffected, and will cause the media source to
restart because I am not aware of the possible consequences and because
there's no restart button for it.

Changing "Apply alpha in linear space" is only visible after a few
milliseconds (when mp_media_next_video is called for new frames).

If `is_stinger` and `full_decode` are toggled during runtime, even
though it shouldn't be possible as they are not accessible in the UI,
a media restart will be triggered.
2023-06-23 04:39:52 -07:00
Lain 192d33ce86 deps/media-playback: Just null the first frame pointer on decode
memset is a little excessive considering we only check the first
pointer.
2023-05-25 18:34:27 -07:00
Lain 40ce466f4d deps/media-playback: Check is_active when frame preloading
Adds a check to make sure that delayed preload is ignored if the stinger
is restarted/interrupted. Just adds this check to the previous commit to
make sure that it doesn't redundantly try to preload a frame when
playback is restarted.
2023-05-25 18:09:46 -07:00
Lain a12d5812af deps/media-playback: Fix crash when interrupting stingers
The `mp_media::obsframe` varaible is a variable used to store the
current frame, or the first frame on stop. However, it's never cleared,
and while decoding a frame, it's invalid. The variable was added for
delayed preloading of the first frame for stingers.

Now, for more context, when media sources stop, it stores the first
frame of the video so it can set the source's current async texture to
that frame, effectively preloading the first frame into the backend,
making it so that when you play back that media, it's able to start
playback instantly without having to wait for the thread to play back
that frame, causing seamless playback.

Normally, preload happens right when first frame is finished decoding,
thus it wasn't a problem before these variables and delayed preloading
was added. However, with stingers, I delayed that preload further
because stingers are kind of a special case because the stinger does not
clear itself right away on stop. Because of that, it was causing it to
flash the first frame at the end of the stinger. This is why `obsframe`
and `request_preload` were added: it's a way of signaling the media
source to preload the first frame when the stinger itself is fully
completed. It was added to fix that stinger bug.

However, if the user interrupts playback of the stinger (e.g. swaps to
another scene while in the middle of the transition), that
`request_preload` might still be queued and happen while the media
source is still decoding, and thus, while `obsframe` is invalid.

I realize that we should probably refactor and clean up the
media-playback lib.
2023-05-25 18:01:17 -07:00
Lain 106c7aa61f Update copyrights/names 2023-05-20 01:31:18 -07:00
Richard Stanway b9ef64d4eb deps/media-playback: Check if frame can be played before using it
It's possible that frame_ready is false when this function is called,
which implies that the mp_decode frame field is not valid. However we
dereference the frame by counting the number of audio channels before
checking the value of frame_ready, causing a crash.
2023-04-30 16:23:16 -07:00
Richard Stanway 7ceb39bd56 deps/media-playback: Initialize mutex earlier for cached media
mp_cache_stop / mp_cache_free both try to use the mutex so we need to
make sure it's initialized before calling functions that may fail.
2023-04-29 11:30:01 -07:00
tytan652 c53a1b4fb0 media-playback: Add missing license headers 2023-04-24 03:50:40 -07:00
PatTheMav 6e07b86729 cmake: Remove EXCLUDE_FROM_ALL directive from interface libraries 2023-04-04 17:27:54 +00:00
tt2468 57e6053c81 deps/media-playback: Remove unnecessary log line
Every time a media player instance would be initialized, it would
create a new `Set FFmpeg options:` log message. With lots of looping
media sources, this gets incredibly spammy. It's already being logged
by the media source itself, so this line is pretty much unnecessary.
2023-04-02 17:41:34 -07:00
PatTheMav 349372b3b3 cmake: Add changes for CMake build framework 3.0
New code path only taken if OBS_CMAKE_VERSION is set to 3.0.0 or
greater, old functionality remains unchanged.
2023-03-26 18:20:38 -04:00
Jim 35f037da47 deps/media-playback: Fix preloaded videos stopping prematurely
The incorrect variable was used in a comparison, causing playback to
stop prematurely depending on whether the audio data or video data ended
first.

Closes obs-project/obs-studio#8422
2023-03-25 22:51:55 -07:00
derrod 198c2b9e86 media-playback: Fix libavutil version check 2023-03-10 08:15:54 +01:00
Ricardo Tavares 0516371823 deps/media-playback: Enable CUDA HW decoder 2023-03-03 21:47:40 +00:00
pkv 2e79d4c902 obs-ffmpeg: Fix for FFmpeg 6 deprecating a flag
Also modifies libobs & deps/media-playback.
AV_CODEC_CAP_TRUNCATED was removed in avcodec 60 [1].
We ifdef the code depending on it to allow compilation.

[1] avcodec: remove FF_API_FLAG_TRUNCATED
3ceffe7839

Signed-off-by: pkv <pkv@obsproject.com>
2023-03-01 13:23:51 -05:00
Jim 4bf14d09b4 obs-transitions: Add option to preload stinger video to RAM
Stingers -- and especially track matte stingers -- are currently subject
to real time decoding, which can be detrimental in a production
environment where a stinger video may not be able to decode in a timely
fashion.

To remedy this, this change adds an option to fully decode stingers
immediately and cache the decoded video/audio in RAM for playback to
greatly improve stinger performance.
2023-02-25 18:13:11 -08:00
PatTheMav cfa0dc573e media-playback: Fix non-exhaustive switch statement 2023-02-18 15:22:33 -08:00
tytan652 918c0c0aeb deps/media-playback: Fix deprecation warning 2023-01-28 23:20:41 -08:00
pkv ce2d1ffab7 obs-ffmpeg: Fix deprecation of channels member of several structs
This fixes deprecation warnings since the channels member of
AVCodecContext is marked as deprecated [1], as well as the channels
member of AVFrame [2].
In all instances where a warning appear, a switch to the new API is
done.
[1] lavc: switch to the new channel layout API
FFmpeg/FFmpeg@548aeb9
[2] Bump minor versions after the channel layout changes
FFmpeg/FFmpeg@cdba98bb80

Signed-off-by: pkv <pkv@obsproject.com>
2022-11-10 19:37:07 -05:00
jpark37 d3bd511d4d media-playback: Fix crash on free
Need to call mp_decode_clear_packets before destroying orig_pkt in case
packet_pending is true.
2022-08-01 09:20:26 -07:00
jpark37 d8551e444b media-playback: Compute HDR colorspace
Figure out colorspace from TRC and primaries if necessary. AMF in
particular doesn't seem to provide full metadata.
2022-07-30 17:25:37 -07:00
tytan652 17ba8359e4 deps,libobs,plugins: Fix discarded-qualifiers warnings with FFmpeg 5 2022-07-22 08:50:36 -04:00
mvji f0b3593349 deps/media-playback: Fix invalid seek at reset
When AVFormatContext->startime is set to AV_NO_PTS
mp_media_reset try to seek to INT64_MIN
use 0 instead.
Fix loop with aac file
2022-07-16 16:29:02 -07:00
jpark37 22fde5cdcd deps/media-playback: Fix metadata for hw_accel
av_hwframe_transfer_data doesn't seem to transfer metadata, so do it
manually.
2022-06-18 16:03:34 -07:00
jpark37 54f09fe6a7 deps/media-playback: Use metadata for HDR EETF
Used in situations where source luminance is greater than HDR nominal
peak setting to avoid clipping by applying BT.2408 maxRGB EETF.
2022-05-27 14:56:47 -07:00
jpark37 226249e1c3 deps/media-playback: Fix video looping
Previous FFmpeg deprecation fix, and optimization attempt causes short
videos to loop badly. Keep deprecation fix, and fix the rest later.

Fixes d528f6cafa
2022-05-21 15:28:08 -07:00
stopforumspam 3215189c97 deps/media-playback: Add support for FFmpeg options for media playback 2022-05-16 15:17:13 -04:00
Jim 952988d9ec
Merge pull request #6231 from mvji/prores_pix_fmt
Add support for GPU conversion of YUV422P10LE, YUV444P12LE, YUVA444P12LE
2022-05-04 02:01:27 -07:00
tytan652 865a358a52 media-playback: Fix unused-parameter warning 2022-05-04 01:37:10 -07:00
mvji 93490da4c2 obs-ffmpeg: Use YVYU for FFmpeg pix fmt YVYU422
This commit also modifies deps/media-playback and libobs.
2022-04-19 19:39:22 +02:00
mvji 5f35e73d8b deps/media-playback: Use YUV422 for planar 422 pix fmt
Instead of UYVY422
2022-04-19 19:39:05 +02:00
mvji ae94c35152 obs-ffmpeg: Add support for YUV422P10LE, YUV444P12LE, YUVA444P12LE
This commit also modifies deps/media-playback
2022-04-19 19:38:28 +02:00
jpark37 05b673381f deps/media-playback: Add P010 to closest_format
Used by HDR media playback with hardware decode.
2022-04-18 05:23:13 -07:00
wangshaohui d2fb302e5c deps/media-playback: Use avcodec_free_context to free AVCodecContext 2022-04-16 16:23:58 -07:00
jpark37 59dbc3eb81 libobs: Rename Rec. 2020 to Rec. 2100
Rec. 2020 is really an SDR spec, but I think HDR10 made it okay to slap
PQ on it, call it an HDR spec. Rec. 2100 came along after and formally
allowed the use of PQ/HLG, so we should use 2100 instead.
2022-04-10 00:13:52 -07:00
jpark37 6ed2edde71 deps/media-playback: Fix AVColorSpace usages
More completeness and consistency.
2022-04-09 21:20:10 -07:00
jpark37 007ed2c355 deps/media-playback: Add more accurate TRC hints
Allows us to tell the difference between HDR and high-precision SDR.
2022-04-08 17:19:23 -07:00
jpark37 848e128435 libobs,plugins: Replace video matrix function
video_format_get_parameters_for_format provides a more accurate matrix
than video_format_get_parameters.
2022-04-07 19:28:51 -07:00
wangshaohui db8145e8a2 obs-ffmpeg, win-dshow, deps/media-playback: Use recommended API for AVCodecContext 2022-04-07 01:59:30 -07:00