Commits 0cd75dbfa0 and 27e94281d1 added QueryInterface()
implementations that compare the requested interface against
IID_IUnknown. The Linux SDK defines it in LinuxCOM.h and the Windows
SDK gets it from the platform COM headers, but the macOS SDK uses
CoreFoundation's COM types from <CoreFoundation/CFPlugInCOM.h>, which
only provide IUnknownUUID as a CFUUIDRef. Since then, building with
--enable-decklink on macOS fails:
libavdevice/decklink_dec.cpp:138:43: error: use of undeclared
identifier 'IID_IUnknown'
libavdevice/decklink_dec.cpp:603:43: error: use of undeclared
identifier 'IID_IUnknown'
libavdevice/decklink_enc.cpp:120:39: error: use of undeclared
identifier 'IID_IUnknown'
libavdevice/decklink_enc.cpp:181:39: error: use of undeclared
identifier 'IID_IUnknown'
On macOS, REFIID is CFUUIDBytes, so derive IID_IUnknown from
IUnknownUUID with CFUUIDGetUUIDBytes(), the same definition used by
the macOS samples shipped with the DeckLink SDK. This avoids
duplicating the GUID bytes, and CFUUIDGetConstantUUIDWithBytes()
returns a constant that must not be released. The definition is
limited to __APPLE__, so Linux and Windows builds are unchanged.
Tested with DeckLink SDK 16.0 and Apple clang 21 on macOS arm64.
Signed-off-by: Jake Fineman <jake@wave.online>
ALSA capture can assemble a packet from multiple successful reads, possibly
across EAGAIN returns. The timestamp calculation still uses the frame count
from the final read, so it subtracts too little audio time. The same count
also supplies the wrong interval to the next time-filter update.
Use the completed packet's frame count for both calculations. A 7680-frame
packet assembled from two 3840-frame reads at 48 kHz otherwise receives a
first PTS 80 ms too late. Single-read packets retain the same calculation.
Reproduced with real ALSA short returns under ARM64 QEMU: a capture PCM
was primed by half a period, then read in nonblocking mode or interrupted
by SIGALRM while waiting for the remainder. No read return values were
changed in those tests. The fix also passes deterministic sample-order,
PTS, EAGAIN and XRUN recovery checks at 44.1, 48, 96 and 192 kHz.
Signed-off-by: Joonho Lee <mynameisjune111@gmail.com>
A packet referencing a driver buffer has no AV_INPUT_BUFFER_PADDING_SIZE
Fixes: 7ZY4JenXTFy4
Fixes: out of array read
Out of array read Replicated through UnModified FFmpeg with v4l2loopback and an LD_PRELOAD guard page behind the mmap buffers
Found during the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24659
Formats with the same dimensions may expose different frame rates. The
selection loop previously updated selected_format for every size match but
kept selected_range from an earlier format. This could apply a range to a
format that does not support it and make device configuration fail.
Only update selected_format together with its matching range. Track a
size-only match separately so the muxed-device fallback remains unchanged.
Reported-by: MW-de <mw-de@noreply.code.ffmpeg.org>
Suggested-by: MW-de <mw-de@noreply.code.ffmpeg.org>
Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/22694
Signed-off-by: iSold Leo <s@qwqlog.com>
This fixes building for iOS after commit
c2802e520a.
On iOS, the fallback define kIOMasterPortDefault is never available.
The newer define kIOMainPortDefault is available since iOS 15.
However, if building with older iOS SDKs (iOS 15 SDK or older) then
IOKit is entirely missing. This caused compilation to succeed if
building with such older versions of the iOS SDK.
If building with a newer iOS SDK/Xcode but targeting an older version
of iOS, then IOKit is available, but compilation would fail as
kIOMasterPortDefault wasn't available.
Thus, this fixes compilation for iOS with iOS 16 SDKs and newer,
which was previously broken.
c2802e520a selected kIOMainPortDefault whenever the SDK is new enough
(__MAC_OS_X_VERSION_MAX_ALLOWED), but that symbol is only available
since macOS 12, so building with a newer SDK against an older
deployment target failed with -Wunguarded-availability-new.
Check the deployment target (__MAC_OS_X_VERSION_MIN_REQUIRED) instead
and keep using the equivalent kIOMasterPortDefault when targeting
older releases.
See: https://lists.ffmpeg.org/archives/list/ffmpeg-devel@ffmpeg.org/thread/S7PGVSGNLIZ2WRYV6VOBAD3RWYUNWA3H/
Reported-by: Helmut K. C. Tessarek <tessarek@evermeet.cx>
Signed-off-by: Gabriel Balaich <ffmpeg@ninbura.com>
A capture device could previously be selected only by index or by name.
Both are unreliable when multiple audio/video devices share a name or
across reboots. AVFoundation reorders the device indices, and the USB
video uniqueID embeds the macOS locationID, which can be reassigned on
reboot or replug and can then resolve to a different physical device.
Add -video_device_id and -audio_device_id, which take a prefixed
identifier: uid:<unique ID> or serial:<USB serial number>.
The USB serial number is the only identifier that stays pegged to a
given physical unit. For video it is resolved to the device's current
locationID via IOKit. For audio it is matched against the uniqueID,
which already embeds it. The unique ID covers devices that have no
serial, such as virtual camera/audio devices.
-list_devices additionally prints each device's uniqueID and USB serial
so the values can be discovered. IOKit is detected in configure and used
only when available.
Signed-off-by: Gabriel Balaich <ffmpeg@ninbura.com>
ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS metadata is an
int32[n*4] array (one 4-tuple per stream config: format, width,
height, input/output flag). ACameraMetadata_const_entry.count is the
total number of int32_t elements, not the number of tuples. The loop
bound must be count/4 to avoid iterating past the end of the array.
Similarly, ACAMERA_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES is an
int32[n*2] array (min/max pairs). The loop bound must be count/2.
Without this fix, both loops over-iterate and read heap memory
beyond the metadata array bounds.
Signed-off-by: Mirko Visontai <mirkov@google.com>
ff_codec_id_to_pulse_format() returns PA_SAMPLE_INVALID for
unsupported codecs (e.g. AAC, FLAC, Opus). Without validation,
the invalid format propagates to pa_frame_size() and other PA
calls, causing assertion failures or division-by-zero.
Add pa_sample_spec_valid() check, matching the existing guard
in pulse_audio_enc.c.
Signed-off-by: zhanghongyuan <zhanghongyuan@uniontech.com>
The capture callback dropped the previous frame instead of waiting for it
to be consumed, so frames were lost when avf_read_packet() fell behind;
39fbd06314 (return EAGAIN instead of waiting) made it easy to hit.
Add back a condition variable: the capture callback blocks until
avf_read_packet() takes the current frame, and the reader waits on it when
no frame is ready. An is_stopping flag set in destroy_context() wakes both
sides so teardown cannot deadlock. observed_quit is now set under the lock
and broadcast as well, so a blocked reader wakes and returns EOF when a
transport-control device stops delivering frames.
Based on a patch by Zhongxin Zhuang <zx.zhuang@hotmail.com>; here
unlock_frames() only broadcasts and unlocks, so a read no longer releases
the other stream's still-unconsumed frame.
Verified by capturing camera+mic for 8s and comparing delivered packet
counts before/after this change:
ffmpeg -f avfoundation -pixel_format nv12 -framerate 30 -i "0:0" -t 8 \
-vf "scale=2560:1440,hqdn3d" -c:v libx264 -preset medium \
-c:a aac out.mp4
ffprobe -count_packets -show_entries stream=nb_read_packets out.mp4
slow consumer (ideal: video ~240, audio ~375)
video audio
before (EAGAIN) 174 163 (audio ~57% dropped)
after (condvar) 234 376 (no drops)
fast consumer (-preset ultrafast, no filter)
before 240 328
after 238 376
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
The avpriv_packet_list_put/get/free() functions and the PacketList type
were implemented in libavcodec and exported via the avpriv_ mechanism
solely so that libavformat (and decklink in libavdevice) could use them;
libavcodec itself has no users of them. Exporting them across the library
boundary has the usual drawbacks for shared builds (export/import overhead
and having to keep them around for ABI stability even once unneeded).
Move the implementation and the PacketList/PacketListEntry types to
libavformat and rename the functions to ff_packet_list_*(). libavformat is
the primary user and compiles the new packet_list.c directly; decklink,
the only libavdevice user, gets a private copy for shared builds via the
SHLIBOBJS scheme already used for reverse.o and ccfifo.o (static builds
resolve the symbols from libavformat).
AVPACKET_IS_EMPTY() and ff_side_data_set_prft() remain in
libavcodec/packet_internal.h as they are libavcodec-internal.
Move window creation and event processing to a dedicated thread.
GetMessage only processes events from the calling thread's message
queue. Because gdigrab_read_header and gdigrab_read_packet don't run on
the same thread, the message queue was not being drained.
Fixes: #11539
This reduces the number of malloc() & free() calls, and structures the
data for the buffers a bit neatly.
In case more per-buffer data needs to be added, having a separate struct
is useful.
Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
In the loop which allocates the buffers for a V4L2 device, if failure
occurs for a certain buffer (e.g. 3rd of 4 buffers), then the previously
allocated buffers (and the buffer array) would not be free'd in
the mmap_init(). This would cause a leak.
This change handles the error cases of that loop to free all allocated
resources, so that when mmap_init() fails nothing is leaked.
Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
This patch adds support for DeckLink SDK 14.3 and newer by using
the legacy interfaces in the header <DeckLinkAPI_v14_2_1.h>.
The missing QueryInterface implementations are also provided.
Playback to a decklink device with a newer version of the
DeckLink SDK (14.3) stalls because the driver code calls
IDeckLinkVideoFrame::QueryInterface, which is not
implemented by ffmpeg.
This patch implements decklink_frame::QueryInterface,
so that playback works with both older (12.x) and
newer (>= 14.3) drivers.
Note: The patch still does not allow the code to compile
with DeckLink SDK 14.3 or newer, as the API has changed.
Can't read alignment from packet, codecpar or decoded frame linesizes, so don't
set it. My test device redmi k60 produces images in 4624x3472, not 32 aligned
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
Commit 00b64fca55 introduced configure
detection for HAVE_POSIX_IOCTL but unfortunately this conflicts with
v4l-utils version 1.30, which itself checks for #ifdef HAVE_POSIX_IOCTL
in a public header and erroneously determines it to be true because we
define this to be 0.
Since this is only used for avdevice/v4l2, we rename this to something
else, namely ioctl_posix, simply to prevent the name conflict with the
file /usr/include/libv4l2.h at least until they can upstream a fix on
their end.
Signed-off-by: Leo Izen <leo.izen@gmail.com>
E.g. tvOS doesn't have devicesWithMediaType.
In principle, we could probably disable building the whole
input device on such OSes, but that would either require
testing explicitly for the OS type in configure (which we don't
do anywhere so far), or test for individual objective C methods.
This approach allows the code to compile, but no input devices
will be found at runtime.
Signed-off-by: Martin Storsjö <martin@martin.st>
SDL2's headers #define HAVE_PTHREAD_SETNAME_NP (to one here);
we also have a config define which leads the compiler to
warn about this when the values are distinct (as they are here).
Suppress this warning by including config.h before SDL.h.
The latter will then redefine our define which doesn't matter
and which does not lead to warnings because compilers don't warn
about system headers by default (depending upon -Wsystem-headers).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>