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 
78 };
79 
84 };
85 
86 struct video_data {
87  uint8_t *data[MAX_AV_PLANES];
89  uint64_t timestamp;
90 };
91 
93  const char *name;
94 
95  enum video_format format;
96  uint32_t fps_num;
97  uint32_t fps_den;
98  uint32_t width;
99  uint32_t height;
100  size_t cache_size;
101 
103  enum video_range_type range;
104 };
105 
106 static inline bool format_is_yuv(enum video_format format)
107 {
108  switch (format) {
109  case VIDEO_FORMAT_I420:
110  case VIDEO_FORMAT_NV12:
111  case VIDEO_FORMAT_I422:
112  case VIDEO_FORMAT_YVYU:
113  case VIDEO_FORMAT_YUY2:
114  case VIDEO_FORMAT_UYVY:
115  case VIDEO_FORMAT_I444:
116  case VIDEO_FORMAT_I40A:
117  case VIDEO_FORMAT_I42A:
118  case VIDEO_FORMAT_YUVA:
119  case VIDEO_FORMAT_AYUV:
120  return true;
121  case VIDEO_FORMAT_NONE:
122  case VIDEO_FORMAT_RGBA:
123  case VIDEO_FORMAT_BGRA:
124  case VIDEO_FORMAT_BGRX:
125  case VIDEO_FORMAT_Y800:
126  case VIDEO_FORMAT_BGR3:
127  return false;
128  }
129 
130  return false;
131 }
132 
133 static inline const char *get_video_format_name(enum video_format format)
134 {
135  switch (format) {
136  case VIDEO_FORMAT_I420:
137  return "I420";
138  case VIDEO_FORMAT_NV12:
139  return "NV12";
140  case VIDEO_FORMAT_I422:
141  return "I422";
142  case VIDEO_FORMAT_YVYU:
143  return "YVYU";
144  case VIDEO_FORMAT_YUY2:
145  return "YUY2";
146  case VIDEO_FORMAT_UYVY:
147  return "UYVY";
148  case VIDEO_FORMAT_RGBA:
149  return "RGBA";
150  case VIDEO_FORMAT_BGRA:
151  return "BGRA";
152  case VIDEO_FORMAT_BGRX:
153  return "BGRX";
154  case VIDEO_FORMAT_I444:
155  return "I444";
156  case VIDEO_FORMAT_Y800:
157  return "Y800";
158  case VIDEO_FORMAT_BGR3:
159  return "BGR3";
160  case VIDEO_FORMAT_I40A:
161  return "I40A";
162  case VIDEO_FORMAT_I42A:
163  return "I42A";
164  case VIDEO_FORMAT_YUVA:
165  return "YUVA";
166  case VIDEO_FORMAT_AYUV:
167  return "AYUV";
168  case VIDEO_FORMAT_NONE:;
169  }
170 
171  return "None";
172 }
173 
174 static inline const char *get_video_colorspace_name(enum video_colorspace cs)
175 {
176  switch (cs) {
177  case VIDEO_CS_709:
178  return "709";
179  case VIDEO_CS_601:
180  case VIDEO_CS_DEFAULT:
181  case VIDEO_CS_SRGB:;
182  }
183 
184  return "601";
185 }
186 
187 static inline enum video_range_type
188 resolve_video_range(enum video_format format, enum video_range_type range)
189 {
190  if (range == VIDEO_RANGE_DEFAULT) {
191  range = format_is_yuv(format) ? VIDEO_RANGE_PARTIAL
193  }
194 
195  return range;
196 }
197 
198 static inline const char *get_video_range_name(enum video_format format,
199  enum video_range_type range)
200 {
201  range = resolve_video_range(format, range);
202  return range == VIDEO_RANGE_FULL ? "Full" : "Partial";
203 }
204 
211 };
212 
214  enum video_format format;
215  uint32_t width;
216  uint32_t height;
217  enum video_range_type range;
219 };
220 
222 
224  enum video_range_type range,
225  float matrix[16], float min_range[3],
226  float max_range[3]);
227 
228 #define VIDEO_OUTPUT_SUCCESS 0
229 #define VIDEO_OUTPUT_INVALIDPARAM -1
230 #define VIDEO_OUTPUT_FAIL -2
231 
234 
235 EXPORT bool
236 video_output_connect(video_t *video, const struct video_scale_info *conversion,
237  void (*callback)(void *param, struct video_data *frame),
238  void *param);
240  void (*callback)(void *param,
241  struct video_data *frame),
242  void *param);
243 
244 EXPORT bool video_output_active(const video_t *video);
245 
246 EXPORT const struct video_output_info *
249  int count, uint64_t timestamp);
254 
256 EXPORT uint32_t video_output_get_width(const video_t *video);
257 EXPORT uint32_t video_output_get_height(const video_t *video);
259 
262 
267 
268 #ifdef __cplusplus
269 }
270 #endif
video_scale_info::height
uint32_t height
Definition: video-io.h:216
video_colorspace
video_colorspace
Definition: video-io.h:73
video_output_info
Definition: video-io.h:92
VIDEO_FORMAT_I420
@ VIDEO_FORMAT_I420
Definition: video-io.h:37
video_data::data
uint8_t * data[MAX_AV_PLANES]
Definition: video-io.h:87
VIDEO_FORMAT_Y800
@ VIDEO_FORMAT_Y800
Definition: video-io.h:49
VIDEO_SCALE_POINT
@ VIDEO_SCALE_POINT
Definition: video-io.h:207
video_output_get_format
EXPORT enum video_format video_output_get_format(const video_t *video)
video_output_info::width
uint32_t width
Definition: video-io.h:98
video_output_info::range
enum video_range_type range
Definition: video-io.h:103
video_output_get_info
EXPORT const struct video_output_info * video_output_get_info(const video_t *video)
video_output_get_frame_rate
EXPORT double video_output_get_frame_rate(const video_t *video)
VIDEO_RANGE_DEFAULT
@ VIDEO_RANGE_DEFAULT
Definition: video-io.h:81
VIDEO_FORMAT_BGRA
@ VIDEO_FORMAT_BGRA
Definition: video-io.h:47
EXPORT
#define EXPORT
Definition: c99defs.h:37
VIDEO_FORMAT_I422
@ VIDEO_FORMAT_I422
Definition: video-io.h:58
video_output_inc_texture_skipped_frames
void video_output_inc_texture_skipped_frames(video_t *video)
VIDEO_FORMAT_YUVA
@ VIDEO_FORMAT_YUVA
Definition: video-io.h:67
video_output_get_width
EXPORT uint32_t video_output_get_width(const video_t *video)
VIDEO_FORMAT_I40A
@ VIDEO_FORMAT_I40A
Definition: video-io.h:61
video_output_info::format
enum video_format format
Definition: video-io.h:95
media-io-defs.h
video_output_info::height
uint32_t height
Definition: video-io.h:99
VIDEO_CS_DEFAULT
@ VIDEO_CS_DEFAULT
Definition: video-io.h:74
VIDEO_RANGE_FULL
@ VIDEO_RANGE_FULL
Definition: video-io.h:83
video_scale_info::format
enum video_format format
Definition: video-io.h:214
video_data::linesize
uint32_t linesize[MAX_AV_PLANES]
Definition: video-io.h:88
video_format_from_fourcc
EXPORT enum video_format video_format_from_fourcc(uint32_t fourcc)
video_output_get_skipped_frames
EXPORT uint32_t video_output_get_skipped_frames(const video_t *video)
VIDEO_FORMAT_NONE
@ VIDEO_FORMAT_NONE
Definition: video-io.h:34
video_output_connect
EXPORT bool video_output_connect(video_t *video, const struct video_scale_info *conversion, void(*callback)(void *param, struct video_data *frame), void *param)
VIDEO_FORMAT_NV12
@ VIDEO_FORMAT_NV12
Definition: video-io.h:38
video_output_active
EXPORT bool video_output_active(const video_t *video)
video_output_info::fps_num
uint32_t fps_num
Definition: video-io.h:96
video_scale_info::colorspace
enum video_colorspace colorspace
Definition: video-io.h:218
video_format_get_parameters
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_data::timestamp
uint64_t timestamp
Definition: video-io.h:89
VIDEO_FORMAT_I42A
@ VIDEO_FORMAT_I42A
Definition: video-io.h:64
VIDEO_CS_601
@ VIDEO_CS_601
Definition: video-io.h:75
video_output_unlock_frame
EXPORT void video_output_unlock_frame(video_t *video)
VIDEO_SCALE_DEFAULT
@ VIDEO_SCALE_DEFAULT
Definition: video-io.h:206
video_scale_type
video_scale_type
Definition: video-io.h:205
video_output_open
EXPORT int video_output_open(video_t **video, struct video_output_info *info)
video_frame
Definition: video-frame.h:23
VIDEO_FORMAT_BGRX
@ VIDEO_FORMAT_BGRX
Definition: video-io.h:48
video_output_info::name
const char * name
Definition: video-io.h:93
VIDEO_SCALE_BILINEAR
@ VIDEO_SCALE_BILINEAR
Definition: video-io.h:209
video_range_type
video_range_type
Definition: video-io.h:80
video_output_get_height
EXPORT uint32_t video_output_get_height(const video_t *video)
video_data
Definition: video-io.h:86
video_scale_info::width
uint32_t width
Definition: video-io.h:215
VIDEO_FORMAT_AYUV
@ VIDEO_FORMAT_AYUV
Definition: video-io.h:70
video_output_disconnect
EXPORT void video_output_disconnect(video_t *video, void(*callback)(void *param, struct video_data *frame), void *param)
video_format
video_format
Definition: video-io.h:33
VIDEO_CS_709
@ VIDEO_CS_709
Definition: video-io.h:76
VIDEO_SCALE_BICUBIC
@ VIDEO_SCALE_BICUBIC
Definition: video-io.h:210
video_output_lock_frame
EXPORT bool video_output_lock_frame(video_t *video, struct video_frame *frame, int count, uint64_t timestamp)
video_t
struct video_output video_t
Definition: video-io.h:31
video_output_inc_texture_frames
void video_output_inc_texture_frames(video_t *video)
MAX_AV_PLANES
#define MAX_AV_PLANES
Definition: media-io-defs.h:20
VIDEO_SCALE_FAST_BILINEAR
@ VIDEO_SCALE_FAST_BILINEAR
Definition: video-io.h:208
VIDEO_FORMAT_YUY2
@ VIDEO_FORMAT_YUY2
Definition: video-io.h:42
video_scale_info
Definition: video-io.h:213
VIDEO_FORMAT_UYVY
@ VIDEO_FORMAT_UYVY
Definition: video-io.h:43
video_output_info::colorspace
enum video_colorspace colorspace
Definition: video-io.h:102
VIDEO_FORMAT_I444
@ VIDEO_FORMAT_I444
Definition: video-io.h:52
VIDEO_FORMAT_YVYU
@ VIDEO_FORMAT_YVYU
Definition: video-io.h:41
video_output_info::cache_size
size_t cache_size
Definition: video-io.h:100
video_output_dec_texture_encoders
void video_output_dec_texture_encoders(video_t *video)
video_output_get_total_frames
EXPORT uint32_t video_output_get_total_frames(const video_t *video)
video_output_stop
EXPORT void video_output_stop(video_t *video)
VIDEO_FORMAT_RGBA
@ VIDEO_FORMAT_RGBA
Definition: video-io.h:46
video_output_stopped
EXPORT bool video_output_stopped(video_t *video)
video_output_get_frame_time
EXPORT uint64_t video_output_get_frame_time(const video_t *video)
video_output_info::fps_den
uint32_t fps_den
Definition: video-io.h:97
video_output_inc_texture_encoders
void video_output_inc_texture_encoders(video_t *video)
VIDEO_FORMAT_BGR3
@ VIDEO_FORMAT_BGR3
Definition: video-io.h:55
VIDEO_CS_SRGB
@ VIDEO_CS_SRGB
Definition: video-io.h:77
video_scale_info::range
enum video_range_type range
Definition: video-io.h:217
VIDEO_RANGE_PARTIAL
@ VIDEO_RANGE_PARTIAL
Definition: video-io.h:82
video_output_close
EXPORT void video_output_close(video_t *video)