]> git.sesse.net Git - ffmpeg/blob - libavdevice/decklink_common.h
Merge commit 'd1d6230ea3dd2c34bcd121f958706f3177f8d8c5'
[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 class decklink_output_callback;
32 class decklink_input_callback;
33
34 typedef struct AVPacketQueue {
35     AVPacketList *first_pkt, *last_pkt;
36     int nb_packets;
37     unsigned long long size;
38     int abort_request;
39     pthread_mutex_t mutex;
40     pthread_cond_t cond;
41     AVFormatContext *avctx;
42     int64_t max_q_size;
43 } AVPacketQueue;
44
45 struct decklink_ctx {
46     /* DeckLink SDK interfaces */
47     IDeckLink *dl;
48     IDeckLinkOutput *dlo;
49     IDeckLinkInput *dli;
50     IDeckLinkConfiguration *cfg;
51     IDeckLinkAttributes *attr;
52     decklink_output_callback *output_callback;
53     decklink_input_callback *input_callback;
54
55     /* DeckLink mode information */
56     BMDTimeValue bmd_tb_den;
57     BMDTimeValue bmd_tb_num;
58     BMDDisplayMode bmd_mode;
59     BMDVideoConnection video_input;
60     BMDAudioConnection audio_input;
61     int bmd_width;
62     int bmd_height;
63     int bmd_field_dominance;
64
65     /* Capture buffer queue */
66     AVPacketQueue queue;
67
68     /* Streams present */
69     int audio;
70     int video;
71
72     /* Status */
73     int playback_started;
74     int capture_started;
75     int64_t last_pts;
76     unsigned long frameCount;
77     unsigned int dropped;
78     AVStream *audio_st;
79     AVStream *video_st;
80     AVStream *teletext_st;
81
82     /* Options */
83     int list_devices;
84     int list_formats;
85     int64_t teletext_lines;
86     double preroll;
87     int duplex_mode;
88     DecklinkPtsSource audio_pts_source;
89     DecklinkPtsSource video_pts_source;
90     int draw_bars;
91
92     int frames_preroll;
93     int frames_buffer;
94
95     pthread_mutex_t mutex;
96     pthread_cond_t cond;
97     int frames_buffer_available_spots;
98
99     int channels;
100 };
101
102 typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
103
104 #ifdef _WIN32
105 #if BLACKMAGIC_DECKLINK_API_VERSION < 0x0a040000
106 typedef unsigned long buffercount_type;
107 #else
108 typedef unsigned int buffercount_type;
109 #endif
110 IDeckLinkIterator *CreateDeckLinkIteratorInstance(void);
111 #else
112 typedef uint32_t buffercount_type;
113 #endif
114
115 static const BMDAudioConnection decklink_audio_connection_map[] = {
116     (BMDAudioConnection)0,
117     bmdAudioConnectionEmbedded,
118     bmdAudioConnectionAESEBU,
119     bmdAudioConnectionAnalog,
120     bmdAudioConnectionAnalogXLR,
121     bmdAudioConnectionAnalogRCA,
122     bmdAudioConnectionMicrophone,
123 };
124
125 static const BMDVideoConnection decklink_video_connection_map[] = {
126     (BMDVideoConnection)0,
127     bmdVideoConnectionSDI,
128     bmdVideoConnectionHDMI,
129     bmdVideoConnectionOpticalSDI,
130     bmdVideoConnectionComponent,
131     bmdVideoConnectionComposite,
132     bmdVideoConnectionSVideo,
133 };
134
135 HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName);
136 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);
137 int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction, int num);
138 int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs);
139 void ff_decklink_list_devices_legacy(AVFormatContext *avctx, int show_inputs, int show_outputs);
140 int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT);
141 void ff_decklink_cleanup(AVFormatContext *avctx);
142 int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
143
144 #endif /* AVDEVICE_DECKLINK_COMMON_H */