mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-21 10:55:51 +02:00
9e86a61870
Purpose: avdevice/decklink: Removed pthread dependency by replacing semaphore used in code appropriately. Doing so makes it easier to build ffmpeg using Visual C++ on Windows. This is a contination of Kyle Schwarz's "avdevice/decklink: Remove pthread dependency" patch that is available at https://patchwork.ffmpeg.org/patch/2654/ . This patch wasn't accepted, and as far as I can tell, there was no follow-up after it was rejected. Notes: Used Visual Studio 2015 (with update 3) for this. Comments: -- configure: Eliminated pthreads dependency for decklink_indev_deps and decklink_outdev_deps and replaced with threads dependency -- libavdevice/decklink_common.cpp / .h: a) Eliminated semaphore and replaced with a combination of a mutex, condition variable, and a counter (frames_buffer_available_spots). b) Removed include of pthread.h and semaphore.h and now using libavutil/thread.h instead. -- libavdevice/decklink_dec.cpp: Eliminated include of pthread.h and semaphore.h. -- libavdevice/decklink_enc.cpp: a) Eliminated include of pthread.h and semaphore.h. b) Replaced use of semaphore with the equivalent using a combination of a mutex, condition variable, and a counter (frames_buffer_available_spots). In theory, libavutil/thread.h and the associated code could have been modified instead to add cross-platform implementations of the sem_ functions, but an inspection of the ffmpeg source base indicates that there are only two cases in which semaphores are used (including this one that was replaced), so it was deemed to not be worth the effort. Signed-off-by: Marton Balint <cus@passwd.hu>
142 lines
4.1 KiB
C++
142 lines
4.1 KiB
C++
/*
|
|
* Blackmagic DeckLink common code
|
|
* Copyright (c) 2013-2014 Ramiro Polla, Luca Barbato, Deti Fliegl
|
|
*
|
|
* 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
|
|
*/
|
|
|
|
#ifndef AVDEVICE_DECKLINK_COMMON_H
|
|
#define AVDEVICE_DECKLINK_COMMON_H
|
|
|
|
#include <DeckLinkAPIVersion.h>
|
|
|
|
#include "libavutil/thread.h"
|
|
#include "decklink_common_c.h"
|
|
|
|
class decklink_output_callback;
|
|
class decklink_input_callback;
|
|
|
|
typedef struct AVPacketQueue {
|
|
AVPacketList *first_pkt, *last_pkt;
|
|
int nb_packets;
|
|
unsigned long long size;
|
|
int abort_request;
|
|
pthread_mutex_t mutex;
|
|
pthread_cond_t cond;
|
|
AVFormatContext *avctx;
|
|
} AVPacketQueue;
|
|
|
|
struct decklink_ctx {
|
|
/* DeckLink SDK interfaces */
|
|
IDeckLink *dl;
|
|
IDeckLinkOutput *dlo;
|
|
IDeckLinkInput *dli;
|
|
IDeckLinkConfiguration *cfg;
|
|
IDeckLinkAttributes *attr;
|
|
decklink_output_callback *output_callback;
|
|
decklink_input_callback *input_callback;
|
|
|
|
/* DeckLink mode information */
|
|
BMDTimeValue bmd_tb_den;
|
|
BMDTimeValue bmd_tb_num;
|
|
BMDDisplayMode bmd_mode;
|
|
BMDVideoConnection video_input;
|
|
BMDAudioConnection audio_input;
|
|
int bmd_width;
|
|
int bmd_height;
|
|
int bmd_field_dominance;
|
|
|
|
/* Capture buffer queue */
|
|
AVPacketQueue queue;
|
|
|
|
/* Streams present */
|
|
int audio;
|
|
int video;
|
|
|
|
/* Status */
|
|
int playback_started;
|
|
int capture_started;
|
|
int64_t last_pts;
|
|
unsigned long frameCount;
|
|
unsigned int dropped;
|
|
AVStream *audio_st;
|
|
AVStream *video_st;
|
|
AVStream *teletext_st;
|
|
|
|
/* Options */
|
|
int list_devices;
|
|
int list_formats;
|
|
int64_t teletext_lines;
|
|
double preroll;
|
|
int duplex_mode;
|
|
DecklinkPtsSource audio_pts_source;
|
|
DecklinkPtsSource video_pts_source;
|
|
int draw_bars;
|
|
|
|
int frames_preroll;
|
|
int frames_buffer;
|
|
|
|
pthread_mutex_t mutex;
|
|
pthread_cond_t cond;
|
|
int frames_buffer_available_spots;
|
|
|
|
int channels;
|
|
};
|
|
|
|
typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
|
|
|
|
#ifdef _WIN32
|
|
#if BLACKMAGIC_DECKLINK_API_VERSION < 0x0a040000
|
|
typedef unsigned long buffercount_type;
|
|
#else
|
|
typedef unsigned int buffercount_type;
|
|
#endif
|
|
IDeckLinkIterator *CreateDeckLinkIteratorInstance(void);
|
|
#else
|
|
typedef uint32_t buffercount_type;
|
|
#endif
|
|
|
|
static const BMDAudioConnection decklink_audio_connection_map[] = {
|
|
(BMDAudioConnection)0,
|
|
bmdAudioConnectionEmbedded,
|
|
bmdAudioConnectionAESEBU,
|
|
bmdAudioConnectionAnalog,
|
|
bmdAudioConnectionAnalogXLR,
|
|
bmdAudioConnectionAnalogRCA,
|
|
bmdAudioConnectionMicrophone,
|
|
};
|
|
|
|
static const BMDVideoConnection decklink_video_connection_map[] = {
|
|
(BMDVideoConnection)0,
|
|
bmdVideoConnectionSDI,
|
|
bmdVideoConnectionHDMI,
|
|
bmdVideoConnectionOpticalSDI,
|
|
bmdVideoConnectionComponent,
|
|
bmdVideoConnectionComposite,
|
|
bmdVideoConnectionSVideo,
|
|
};
|
|
|
|
HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName);
|
|
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 num = 0);
|
|
int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction, int num);
|
|
int ff_decklink_list_devices(AVFormatContext *avctx);
|
|
int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT);
|
|
void ff_decklink_cleanup(AVFormatContext *avctx);
|
|
int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
|
|
|
|
#endif /* AVDEVICE_DECKLINK_COMMON_H */
|