Open Broadcaster Software
Free, open source software for live streaming and recording
video-io.h
Go to the documentation of this file.
1 /******************************************************************************
2  Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 ******************************************************************************/
17 
18 #pragma once
19 
20 #include "media-io-defs.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 struct video_frame;
27 
28 /* Base video output component. Use this to create a video output track. */
29 
30 struct video_output;
31 typedef struct video_output video_t;
32 
35 
36  /* planar 420 format */
37  VIDEO_FORMAT_I420, /* three-plane */
38  VIDEO_FORMAT_NV12, /* two-plane, luma and packed chroma */
39 
40  /* packed 422 formats */
42  VIDEO_FORMAT_YUY2, /* YUYV */
44 
45  /* packed uncompressed formats */
49  VIDEO_FORMAT_Y800, /* grayscale */
50 
51  /* planar 4:4:4 */
53 
54  /* more packed uncompressed formats */
56 
57  /* planar 4:2:2 */
59 
60  /* planar 4:2:0 with alpha */
62 
63  /* planar 4:2:2 with alpha */
65 
66  /* planar 4:4:4 with alpha */
68 
69  /* packed 4:4:4 with alpha */
71 };
72 
77 };
78 
83 };
84 
85 struct video_data {
89 };
90 
92  const char *name;
93 
99  size_t cache_size;
100 
103 };
104 
105 static inline bool format_is_yuv(enum video_format format)
106 {
107  switch (format) {
108  case VIDEO_FORMAT_I420:
109  case VIDEO_FORMAT_NV12:
110  case VIDEO_FORMAT_I422:
111  case VIDEO_FORMAT_YVYU:
112  case VIDEO_FORMAT_YUY2:
113  case VIDEO_FORMAT_UYVY:
114  case VIDEO_FORMAT_I444:
115  case VIDEO_FORMAT_I40A:
116  case VIDEO_FORMAT_I42A:
117  case VIDEO_FORMAT_YUVA:
118  case VIDEO_FORMAT_AYUV:
119  return true;
120  case VIDEO_FORMAT_NONE:
121  case VIDEO_FORMAT_RGBA:
122  case VIDEO_FORMAT_BGRA:
123  case VIDEO_FORMAT_BGRX:
124  case VIDEO_FORMAT_Y800:
125  case VIDEO_FORMAT_BGR3:
126  return false;
127  }
128 
129  return false;
130 }
131 
132 static inline const char *get_video_format_name(enum video_format format)
133 {
134  switch (format) {
135  case VIDEO_FORMAT_I420:
136  return "I420";
137  case VIDEO_FORMAT_NV12:
138  return "NV12";
139  case VIDEO_FORMAT_I422:
140  return "I422";
141  case VIDEO_FORMAT_YVYU:
142  return "YVYU";
143  case VIDEO_FORMAT_YUY2:
144  return "YUY2";
145  case VIDEO_FORMAT_UYVY:
146  return "UYVY";
147  case VIDEO_FORMAT_RGBA:
148  return "RGBA";
149  case VIDEO_FORMAT_BGRA:
150  return "BGRA";
151  case VIDEO_FORMAT_BGRX:
152  return "BGRX";
153  case VIDEO_FORMAT_I444:
154  return "I444";
155  case VIDEO_FORMAT_Y800:
156  return "Y800";
157  case VIDEO_FORMAT_BGR3:
158  return "BGR3";
159  case VIDEO_FORMAT_I40A:
160  return "I40A";
161  case VIDEO_FORMAT_I42A:
162  return "I42A";
163  case VIDEO_FORMAT_YUVA:
164  return "YUVA";
165  case VIDEO_FORMAT_AYUV:
166  return "AYUV";
167  case VIDEO_FORMAT_NONE:;
168  }
169 
170  return "None";
171 }
172 
173 static inline const char *get_video_colorspace_name(enum video_colorspace cs)
174 {
175  switch (cs) {
176  case VIDEO_CS_709:
177  return "709";
178  case VIDEO_CS_601:
179  case VIDEO_CS_DEFAULT:;
180  }
181 
182  return "601";
183 }
184 
185 static inline enum video_range_type
186 resolve_video_range(enum video_format format, enum video_range_type range)
187 {
188  if (range == VIDEO_RANGE_DEFAULT) {
189  range = format_is_yuv(format) ? VIDEO_RANGE_PARTIAL
191  }
192 
193  return range;
194 }
195 
196 static inline const char *get_video_range_name(enum video_format format,
197  enum video_range_type range)
198 {
199  range = resolve_video_range(format, range);
200  return range == VIDEO_RANGE_FULL ? "Full" : "Partial";
201 }
202 
209 };
210 
217 };
218 
220 
222  enum video_range_type range,
223  float matrix[16], float min_range[3],
224  float max_range[3]);
225 
226 #define VIDEO_OUTPUT_SUCCESS 0
227 #define VIDEO_OUTPUT_INVALIDPARAM -1
228 #define VIDEO_OUTPUT_FAIL -2
229 
230 EXPORT int video_output_open(video_t **video, struct video_output_info *info);
231 EXPORT void video_output_close(video_t *video);
232 
233 EXPORT bool
234 video_output_connect(video_t *video, const struct video_scale_info *conversion,
235  void (*callback)(void *param, struct video_data *frame),
236  void *param);
238  void (*callback)(void *param,
239  struct video_data *frame),
240  void *param);
241 
242 EXPORT bool video_output_active(const video_t *video);
243 
244 EXPORT const struct video_output_info *
245 video_output_get_info(const video_t *video);
246 EXPORT bool video_output_lock_frame(video_t *video, struct video_frame *frame,
247  int count, uint64_t timestamp);
250 EXPORT void video_output_stop(video_t *video);
251 EXPORT bool video_output_stopped(video_t *video);
252 
256 EXPORT double video_output_get_frame_rate(const video_t *video);
257 
260 
261 extern void video_output_inc_texture_encoders(video_t *video);
262 extern void video_output_dec_texture_encoders(video_t *video);
263 extern void video_output_inc_texture_frames(video_t *video);
265 
266 #ifdef __cplusplus
267 }
268 #endif
Definition: video-io.h:75
Definition: video-io.h:64
Definition: video-io.h:58
uint32_t width
Definition: video-io.h:97
uint32_t height
Definition: video-io.h:214
Definition: video-io.h:74
Definition: video-io.h:207
EXPORT int video_output_open(video_t **video, struct video_output_info *info)
void video_output_inc_texture_encoders(video_t *video)
Definition: video-io.h:38
Definition: video-io.h:211
Definition: video-io.h:67
EXPORT void video_output_close(video_t *video)
void video_output_inc_texture_frames(video_t *video)
Definition: video-io.h:52
Definition: video-io.h:41
Definition: video-io.h:47
enum video_range_type range
Definition: video-io.h:102
Definition: video-io.h:34
unsigned uint32_t
Definition: vc_stdint.h:31
enum video_colorspace colorspace
Definition: video-io.h:101
video_format
Definition: video-io.h:33
uint32_t fps_den
Definition: video-io.h:96
Definition: video-io.h:81
uint32_t linesize[MAX_AV_PLANES]
Definition: video-io.h:87
const char * name
Definition: video-io.h:92
unsigned __int64 uint64_t
Definition: vc_stdint.h:33
EXPORT double video_output_get_frame_rate(const video_t *video)
Definition: video-io.h:61
Definition: video-io.h:76
unsigned char uint8_t
Definition: vc_stdint.h:27
uint64_t timestamp
Definition: video-io.h:88
EXPORT bool video_format_get_parameters(enum video_colorspace color_space, enum video_range_type range, float matrix[16], float min_range[3], float max_range[3])
video_scale_type
Definition: video-io.h:203
enum video_colorspace colorspace
Definition: video-io.h:216
EXPORT void video_output_disconnect(video_t *video, void(*callback)(void *param, struct video_data *frame), void *param)
EXPORT enum video_format video_output_get_format(const video_t *video)
EXPORT uint32_t video_output_get_width(const video_t *video)
enum video_format format
Definition: video-io.h:212
EXPORT const struct video_output_info * video_output_get_info(const video_t *video)
#define EXPORT
Definition: c99defs.h:49
EXPORT bool video_output_active(const video_t *video)
Definition: video-io.h:82
EXPORT uint64_t video_output_get_frame_time(const video_t *video)
Definition: video-io.h:48
Definition: video-io.h:208
EXPORT uint32_t video_output_get_skipped_frames(const video_t *video)
video_colorspace
Definition: video-io.h:73
Definition: video-io.h:85
Definition: video-frame.h:23
Definition: video-io.h:43
EXPORT bool video_output_stopped(video_t *video)
Definition: video-io.h:55
Definition: video-io.h:91
EXPORT enum video_format video_format_from_fourcc(uint32_t fourcc)
void video_output_dec_texture_encoders(video_t *video)
uint32_t fps_num
Definition: video-io.h:95
Definition: video-io.h:70
struct video_output video_t
Definition: video-io.h:31
EXPORT void video_output_stop(video_t *video)
enum video_format format
Definition: video-io.h:94
Definition: video-io.h:80
EXPORT bool video_output_lock_frame(video_t *video, struct video_frame *frame, int count, uint64_t timestamp)
uint8_t * data[MAX_AV_PLANES]
Definition: video-io.h:86
#define MAX_AV_PLANES
Definition: media-io-defs.h:20
void video_output_inc_texture_skipped_frames(video_t *video)
EXPORT uint32_t video_output_get_height(const video_t *video)
size_t cache_size
Definition: video-io.h:99
Definition: video-io.h:206
Definition: video-io.h:205
EXPORT void video_output_unlock_frame(video_t *video)
EXPORT uint32_t video_output_get_total_frames(const video_t *video)
uint32_t height
Definition: video-io.h:98
Definition: video-io.h:204
Definition: video-io.h:49
Definition: video-io.h:37
video_range_type
Definition: video-io.h:79
Definition: video-io.h:42
enum video_range_type range
Definition: video-io.h:215
uint32_t width
Definition: video-io.h:213
EXPORT bool video_output_connect(video_t *video, const struct video_scale_info *conversion, void(*callback)(void *param, struct video_data *frame), void *param)
Definition: video-io.h:46