2014-09-21 23:39:50 +00:00
|
|
|
/*
|
|
|
|
* Blackmagic DeckLink common code
|
|
|
|
* Copyright (c) 2013-2014 Ramiro Polla, Luca Barbato, Deti Fliegl
|
2017-08-10 06:29:30 +00:00
|
|
|
* Copyright (c) 2017 Akamai Technologies, Inc.
|
2014-09-21 23:39:50 +00:00
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2016-01-29 02:00:33 +00:00
|
|
|
#ifndef AVDEVICE_DECKLINK_COMMON_H
|
|
|
|
#define AVDEVICE_DECKLINK_COMMON_H
|
|
|
|
|
2016-01-24 20:42:39 +00:00
|
|
|
#include <DeckLinkAPIVersion.h>
|
2019-03-14 00:37:11 +00:00
|
|
|
#if BLACKMAGIC_DECKLINK_API_VERSION < 0x0b000000
|
|
|
|
#define IID_IDeckLinkProfileAttributes IID_IDeckLinkAttributes
|
|
|
|
#define IDeckLinkProfileAttributes IDeckLinkAttributes
|
|
|
|
#endif
|
2015-07-19 19:32:49 +00:00
|
|
|
|
2021-12-16 00:49:39 +00:00
|
|
|
extern "C" {
|
|
|
|
#include "libavcodec/packet_internal.h"
|
2023-05-05 19:09:07 +00:00
|
|
|
#include "libavfilter/ccfifo.h"
|
2021-12-16 00:49:39 +00:00
|
|
|
}
|
2017-04-15 06:41:46 +00:00
|
|
|
#include "libavutil/thread.h"
|
2014-09-21 23:39:50 +00:00
|
|
|
#include "decklink_common_c.h"
|
2018-09-07 19:40:25 +00:00
|
|
|
#if CONFIG_LIBKLVANC
|
|
|
|
#include "libklvanc/vanc.h"
|
|
|
|
#endif
|
2014-09-21 23:39:50 +00:00
|
|
|
|
2017-10-27 06:30:23 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define DECKLINK_BOOL BOOL
|
|
|
|
#else
|
|
|
|
#define DECKLINK_BOOL bool
|
|
|
|
#endif
|
|
|
|
|
2018-05-25 18:41:06 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
static char *dup_wchar_to_utf8(wchar_t *w)
|
|
|
|
{
|
|
|
|
char *s = NULL;
|
|
|
|
int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
|
|
|
|
s = (char *) av_malloc(l);
|
|
|
|
if (s)
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
#define DECKLINK_STR OLECHAR *
|
|
|
|
#define DECKLINK_STRDUP dup_wchar_to_utf8
|
|
|
|
#define DECKLINK_FREE(s) SysFreeString(s)
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
static char *dup_cfstring_to_utf8(CFStringRef w)
|
|
|
|
{
|
|
|
|
char s[256];
|
|
|
|
CFStringGetCString(w, s, 255, kCFStringEncodingUTF8);
|
|
|
|
return av_strdup(s);
|
|
|
|
}
|
|
|
|
#define DECKLINK_STR const __CFString *
|
|
|
|
#define DECKLINK_STRDUP dup_cfstring_to_utf8
|
|
|
|
#define DECKLINK_FREE(s) CFRelease(s)
|
|
|
|
#else
|
|
|
|
#define DECKLINK_STR const char *
|
|
|
|
#define DECKLINK_STRDUP av_strdup
|
|
|
|
/* free() is needed for a string returned by the DeckLink SDL. */
|
|
|
|
#define DECKLINK_FREE(s) free((void *) s)
|
|
|
|
#endif
|
|
|
|
|
2014-09-21 23:39:50 +00:00
|
|
|
class decklink_output_callback;
|
|
|
|
class decklink_input_callback;
|
|
|
|
|
2023-04-28 18:40:51 +00:00
|
|
|
typedef struct DecklinkPacketQueue {
|
2021-12-16 00:49:39 +00:00
|
|
|
PacketList pkt_list;
|
2014-09-21 23:39:50 +00:00
|
|
|
int nb_packets;
|
|
|
|
unsigned long long size;
|
|
|
|
int abort_request;
|
|
|
|
pthread_mutex_t mutex;
|
|
|
|
pthread_cond_t cond;
|
|
|
|
AVFormatContext *avctx;
|
2017-08-10 06:29:30 +00:00
|
|
|
int64_t max_q_size;
|
2023-04-28 18:40:51 +00:00
|
|
|
} DecklinkPacketQueue;
|
2014-09-21 23:39:50 +00:00
|
|
|
|
|
|
|
struct decklink_ctx {
|
|
|
|
/* DeckLink SDK interfaces */
|
|
|
|
IDeckLink *dl;
|
|
|
|
IDeckLinkOutput *dlo;
|
|
|
|
IDeckLinkInput *dli;
|
2016-06-11 11:41:29 +00:00
|
|
|
IDeckLinkConfiguration *cfg;
|
2019-03-14 00:37:11 +00:00
|
|
|
IDeckLinkProfileAttributes *attr;
|
2014-09-21 23:39:50 +00:00
|
|
|
decklink_output_callback *output_callback;
|
|
|
|
|
|
|
|
/* DeckLink mode information */
|
|
|
|
BMDTimeValue bmd_tb_den;
|
|
|
|
BMDTimeValue bmd_tb_num;
|
|
|
|
BMDDisplayMode bmd_mode;
|
2016-06-18 10:04:15 +00:00
|
|
|
BMDVideoConnection video_input;
|
|
|
|
BMDAudioConnection audio_input;
|
2018-05-31 09:45:07 +00:00
|
|
|
BMDTimecodeFormat tc_format;
|
2014-09-21 23:39:50 +00:00
|
|
|
int bmd_width;
|
|
|
|
int bmd_height;
|
|
|
|
int bmd_field_dominance;
|
2018-09-07 19:40:25 +00:00
|
|
|
int supports_vanc;
|
2014-09-21 23:39:50 +00:00
|
|
|
|
|
|
|
/* Capture buffer queue */
|
2023-04-28 18:40:51 +00:00
|
|
|
DecklinkPacketQueue queue;
|
2014-09-21 23:39:50 +00:00
|
|
|
|
2023-05-11 17:34:57 +00:00
|
|
|
CCFifo cc_fifo; ///< closed captions
|
2023-05-05 19:09:07 +00:00
|
|
|
|
2023-06-30 21:14:39 +00:00
|
|
|
/* Output VANC queue */
|
|
|
|
DecklinkPacketQueue vanc_queue;
|
|
|
|
|
2014-09-21 23:39:50 +00:00
|
|
|
/* Streams present */
|
|
|
|
int audio;
|
|
|
|
int video;
|
|
|
|
|
|
|
|
/* Status */
|
|
|
|
int playback_started;
|
2023-03-03 21:08:13 +00:00
|
|
|
int64_t first_pts;
|
2014-09-21 23:39:50 +00:00
|
|
|
int64_t last_pts;
|
|
|
|
unsigned long frameCount;
|
|
|
|
unsigned int dropped;
|
|
|
|
AVStream *audio_st;
|
|
|
|
AVStream *video_st;
|
2020-06-08 09:56:37 +00:00
|
|
|
AVStream *klv_st;
|
2016-01-12 02:09:37 +00:00
|
|
|
AVStream *teletext_st;
|
2018-09-07 19:40:25 +00:00
|
|
|
uint16_t cdp_sequence_num;
|
2014-09-21 23:39:50 +00:00
|
|
|
|
|
|
|
/* Options */
|
|
|
|
int list_devices;
|
|
|
|
int list_formats;
|
2020-06-08 09:56:37 +00:00
|
|
|
int enable_klv;
|
2016-01-12 02:09:37 +00:00
|
|
|
int64_t teletext_lines;
|
2014-09-21 23:39:50 +00:00
|
|
|
double preroll;
|
2016-06-11 11:41:29 +00:00
|
|
|
int duplex_mode;
|
2021-08-08 23:43:34 +00:00
|
|
|
BMDLinkConfiguration link;
|
2016-06-18 22:35:44 +00:00
|
|
|
DecklinkPtsSource audio_pts_source;
|
|
|
|
DecklinkPtsSource video_pts_source;
|
2016-10-13 21:56:45 +00:00
|
|
|
int draw_bars;
|
2018-09-07 19:40:25 +00:00
|
|
|
BMDPixelFormat raw_format;
|
2014-09-21 23:39:50 +00:00
|
|
|
|
|
|
|
int frames_preroll;
|
|
|
|
int frames_buffer;
|
|
|
|
|
2017-04-15 06:41:46 +00:00
|
|
|
pthread_mutex_t mutex;
|
|
|
|
pthread_cond_t cond;
|
|
|
|
int frames_buffer_available_spots;
|
2017-10-27 06:30:23 +00:00
|
|
|
int autodetect;
|
2014-09-21 23:39:50 +00:00
|
|
|
|
2018-09-07 19:40:25 +00:00
|
|
|
#if CONFIG_LIBKLVANC
|
|
|
|
struct klvanc_context_s *vanc_ctx;
|
|
|
|
#endif
|
|
|
|
|
2014-09-21 23:39:50 +00:00
|
|
|
int channels;
|
2017-10-18 19:21:46 +00:00
|
|
|
int audio_depth;
|
2019-09-09 13:03:09 +00:00
|
|
|
unsigned long tc_seen; // used with option wait_for_tc
|
2014-09-21 23:39:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
|
|
|
|
|
2020-11-19 04:16:47 +00:00
|
|
|
static const BMDPixelFormat decklink_raw_format_map[] = {
|
|
|
|
(BMDPixelFormat)0,
|
|
|
|
bmdFormat8BitYUV,
|
|
|
|
bmdFormat10BitYUV,
|
|
|
|
bmdFormat8BitARGB,
|
|
|
|
bmdFormat8BitBGRA,
|
|
|
|
bmdFormat10BitRGB,
|
|
|
|
};
|
|
|
|
|
2016-06-18 10:04:15 +00:00
|
|
|
static const BMDAudioConnection decklink_audio_connection_map[] = {
|
2016-06-26 23:11:50 +00:00
|
|
|
(BMDAudioConnection)0,
|
2016-06-18 10:04:15 +00:00
|
|
|
bmdAudioConnectionEmbedded,
|
|
|
|
bmdAudioConnectionAESEBU,
|
|
|
|
bmdAudioConnectionAnalog,
|
|
|
|
bmdAudioConnectionAnalogXLR,
|
|
|
|
bmdAudioConnectionAnalogRCA,
|
|
|
|
bmdAudioConnectionMicrophone,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const BMDVideoConnection decklink_video_connection_map[] = {
|
2016-06-26 23:11:50 +00:00
|
|
|
(BMDVideoConnection)0,
|
2016-06-18 10:04:15 +00:00
|
|
|
bmdVideoConnectionSDI,
|
|
|
|
bmdVideoConnectionHDMI,
|
|
|
|
bmdVideoConnectionOpticalSDI,
|
|
|
|
bmdVideoConnectionComponent,
|
|
|
|
bmdVideoConnectionComposite,
|
|
|
|
bmdVideoConnectionSVideo,
|
|
|
|
};
|
2014-09-21 23:39:50 +00:00
|
|
|
|
2018-05-31 09:45:07 +00:00
|
|
|
static const BMDTimecodeFormat decklink_timecode_format_map[] = {
|
|
|
|
(BMDTimecodeFormat)0,
|
|
|
|
bmdTimecodeRP188VITC1,
|
|
|
|
bmdTimecodeRP188VITC2,
|
|
|
|
bmdTimecodeRP188LTC,
|
|
|
|
bmdTimecodeRP188Any,
|
|
|
|
bmdTimecodeVITC,
|
|
|
|
bmdTimecodeVITCField2,
|
|
|
|
bmdTimecodeSerial,
|
2020-09-05 19:18:17 +00:00
|
|
|
#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
|
|
|
|
bmdTimecodeRP188HighFrameRate,
|
|
|
|
#else
|
|
|
|
(BMDTimecodeFormat)0,
|
|
|
|
#endif
|
2018-05-31 09:45:07 +00:00
|
|
|
};
|
|
|
|
|
2021-08-08 23:43:34 +00:00
|
|
|
static const BMDLinkConfiguration decklink_link_conf_map[] = {
|
|
|
|
(BMDLinkConfiguration)0,
|
|
|
|
bmdLinkConfigurationSingleLink,
|
|
|
|
bmdLinkConfigurationDualLink,
|
|
|
|
bmdLinkConfigurationQuadLink
|
|
|
|
};
|
|
|
|
|
2021-08-13 02:47:28 +00:00
|
|
|
#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
|
|
|
|
static const BMDProfileID decklink_profile_id_map[] = {
|
|
|
|
(BMDProfileID)0,
|
|
|
|
bmdProfileTwoSubDevicesHalfDuplex,
|
|
|
|
bmdProfileOneSubDeviceFullDuplex,
|
|
|
|
bmdProfileOneSubDeviceHalfDuplex,
|
|
|
|
bmdProfileTwoSubDevicesFullDuplex,
|
|
|
|
bmdProfileFourSubDevicesHalfDuplex,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2017-11-07 04:02:23 +00:00
|
|
|
int ff_decklink_set_configs(AVFormatContext *avctx, decklink_direction_t direction);
|
2019-08-21 20:40:11 +00:00
|
|
|
int ff_decklink_set_format(AVFormatContext *avctx, int width, int height, int tb_num, int tb_den, enum AVFieldOrder field_order, decklink_direction_t direction = DIRECTION_OUT);
|
|
|
|
int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction);
|
2017-10-06 12:55:43 +00:00
|
|
|
int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs);
|
|
|
|
void ff_decklink_list_devices_legacy(AVFormatContext *avctx, int show_inputs, int show_outputs);
|
2014-09-21 23:39:50 +00:00
|
|
|
int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT);
|
2016-06-18 13:49:01 +00:00
|
|
|
void ff_decklink_cleanup(AVFormatContext *avctx);
|
2016-06-18 14:55:47 +00:00
|
|
|
int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
|
2014-09-21 23:39:50 +00:00
|
|
|
|
2023-06-30 21:14:38 +00:00
|
|
|
void ff_decklink_packet_queue_init(AVFormatContext *avctx, DecklinkPacketQueue *q, int64_t queue_size);
|
2023-04-28 18:40:51 +00:00
|
|
|
void ff_decklink_packet_queue_flush(DecklinkPacketQueue *q);
|
|
|
|
void ff_decklink_packet_queue_end(DecklinkPacketQueue *q);
|
|
|
|
unsigned long long ff_decklink_packet_queue_size(DecklinkPacketQueue *q);
|
|
|
|
int ff_decklink_packet_queue_put(DecklinkPacketQueue *q, AVPacket *pkt);
|
|
|
|
int ff_decklink_packet_queue_get(DecklinkPacketQueue *q, AVPacket *pkt, int block);
|
2023-06-30 21:14:39 +00:00
|
|
|
int64_t ff_decklink_packet_queue_peekpts(DecklinkPacketQueue *q);
|
2023-04-28 18:40:51 +00:00
|
|
|
|
2016-01-29 11:49:46 +00:00
|
|
|
#endif /* AVDEVICE_DECKLINK_COMMON_H */
|