]> git.sesse.net Git - ffmpeg/blob - libavdevice/decklink_common.h
avdevice/decklink_dec: use std::atomic for decklink_input_callback refcounting
[ffmpeg] / libavdevice / decklink_common.h
1 /*
2  * Blackmagic DeckLink common code
3  * Copyright (c) 2013-2014 Ramiro Polla, Luca Barbato, Deti Fliegl
4  * Copyright (c) 2017 Akamai Technologies, Inc.
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22
23 #ifndef AVDEVICE_DECKLINK_COMMON_H
24 #define AVDEVICE_DECKLINK_COMMON_H
25
26 #include <DeckLinkAPIVersion.h>
27
28 #include "libavutil/thread.h"
29 #include "decklink_common_c.h"
30
31 #ifdef _WIN32
32 #define DECKLINK_BOOL BOOL
33 #else
34 #define DECKLINK_BOOL bool
35 #endif
36
37 class decklink_output_callback;
38 class decklink_input_callback;
39
40 typedef struct AVPacketQueue {
41     AVPacketList *first_pkt, *last_pkt;
42     int nb_packets;
43     unsigned long long size;
44     int abort_request;
45     pthread_mutex_t mutex;
46     pthread_cond_t cond;
47     AVFormatContext *avctx;
48     int64_t max_q_size;
49 } AVPacketQueue;
50
51 struct decklink_ctx {
52     /* DeckLink SDK interfaces */
53     IDeckLink *dl;
54     IDeckLinkOutput *dlo;
55     IDeckLinkInput *dli;
56     IDeckLinkConfiguration *cfg;
57     IDeckLinkAttributes *attr;
58     decklink_output_callback *output_callback;
59
60     /* DeckLink mode information */
61     BMDTimeValue bmd_tb_den;
62     BMDTimeValue bmd_tb_num;
63     BMDDisplayMode bmd_mode;
64     BMDVideoConnection video_input;
65     BMDAudioConnection audio_input;
66     int bmd_width;
67     int bmd_height;
68     int bmd_field_dominance;
69
70     /* Capture buffer queue */
71     AVPacketQueue queue;
72
73     /* Streams present */
74     int audio;
75     int video;
76
77     /* Status */
78     int playback_started;
79     int capture_started;
80     int64_t last_pts;
81     unsigned long frameCount;
82     unsigned int dropped;
83     AVStream *audio_st;
84     AVStream *video_st;
85     AVStream *teletext_st;
86
87     /* Options */
88     int list_devices;
89     int list_formats;
90     int64_t teletext_lines;
91     double preroll;
92     int duplex_mode;
93     DecklinkPtsSource audio_pts_source;
94     DecklinkPtsSource video_pts_source;
95     int draw_bars;
96
97     int frames_preroll;
98     int frames_buffer;
99
100     pthread_mutex_t mutex;
101     pthread_cond_t cond;
102     int frames_buffer_available_spots;
103     int autodetect;
104
105     int channels;
106     int audio_depth;
107 };
108
109 typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
110
111 #ifdef _WIN32
112 #if BLACKMAGIC_DECKLINK_API_VERSION < 0x0a040000
113 typedef unsigned long buffercount_type;
114 #else
115 typedef unsigned int buffercount_type;
116 #endif
117 IDeckLinkIterator *CreateDeckLinkIteratorInstance(void);
118 #else
119 typedef uint32_t buffercount_type;
120 #endif
121
122 static const BMDAudioConnection decklink_audio_connection_map[] = {
123     (BMDAudioConnection)0,
124     bmdAudioConnectionEmbedded,
125     bmdAudioConnectionAESEBU,
126     bmdAudioConnectionAnalog,
127     bmdAudioConnectionAnalogXLR,
128     bmdAudioConnectionAnalogRCA,
129     bmdAudioConnectionMicrophone,
130 };
131
132 static const BMDVideoConnection decklink_video_connection_map[] = {
133     (BMDVideoConnection)0,
134     bmdVideoConnectionSDI,
135     bmdVideoConnectionHDMI,
136     bmdVideoConnectionOpticalSDI,
137     bmdVideoConnectionComponent,
138     bmdVideoConnectionComposite,
139     bmdVideoConnectionSVideo,
140 };
141
142 HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName);
143 int ff_decklink_set_configs(AVFormatContext *avctx, decklink_direction_t direction);
144 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);
145 int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction, int num);
146 int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs);
147 void ff_decklink_list_devices_legacy(AVFormatContext *avctx, int show_inputs, int show_outputs);
148 int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT);
149 void ff_decklink_cleanup(AVFormatContext *avctx);
150 int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
151
152 #endif /* AVDEVICE_DECKLINK_COMMON_H */