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