UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
aja_win32_utils.cpp
Go to the documentation of this file.
1
10/*
11 * Copyright (c) 2017-2021 CESNET z.s.p.o.
12 * All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, is permitted provided that the following conditions
16 * are met:
17 *
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 *
25 * 3. Neither the name of CESNET nor the names of its contributors may be
26 * used to endorse or promote products derived from this software without
27 * specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
31 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
32 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
33 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
34 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
39 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 */
42
43#define WIN32
44#include "config_msvc.h"
45#include "config_win32.h"
46
47#include <assert.h>
48#include <stdlib.h>
49#include <string.h>
50
51#include "video.h"
52#include "audio/types.h"
53#include "audio/utils.h"
54
55void remux_channel(char *out, const char *in, int bps, int in_len, int in_stream_channels, int out_stream_channels, int pos_in_stream, int pos_out_stream)
56{
57 int samples = in_len / (in_stream_channels * bps);
58 int i;
59
60 assert (bps <= 4);
61
62 in += pos_in_stream * bps;
63 out += pos_out_stream * bps;
64
65 for (i = 0; i < samples; ++i) {
66 memcpy(out, in, bps);
67
68 out += bps * out_stream_channels;
69 in += bps * in_stream_channels;
70
71 }
72}
73
74int vc_get_linesize(unsigned int width, codec_t codec)
75{
76 int bpp;
77 switch (codec) {
78 case v210:
79 width = (width + 47) / 48 * 48;
80 return width * 8 / 3;
81 case UYVY:
82 case YUYV:
83 bpp = 2;
84 break;
85 case RGB:
86 case BGR:
87 bpp = 3;
88 break;
89 case R10k:
90 case RGBA:
91 bpp = 4;
92 break;
93 default:
94 fprintf(stderr, "[AJA] Unimplemented codec. Please report a bug.");
95 abort();
96 }
97 return width * bpp;
98}
99
101{
102 struct video_frame *buf;
103 assert(count > 0);
104
105 buf = (struct video_frame *) calloc(1, offsetof (struct video_frame, tiles[count]));
106 assert(buf != NULL);
107
108 buf->tile_count = count;
109
110 return buf;
111}
112
114{
115 struct video_frame *buf;
116 assert(desc.tile_count > 0);
117
118 buf = vf_alloc(desc.tile_count);
119 if(!buf) return NULL;
120
123 buf->fps = desc.fps;
124 // tile_count already filled
125 for(unsigned int i = 0u; i < desc.tile_count; ++i) {
126 buf->tiles[i].width = desc.width;
127 buf->tiles[i].height = desc.height;
129 }
130
131 return buf;
132}
133
135{
136 struct video_frame *buf;
137
138 buf = vf_alloc_desc(desc);
139
140 if (!buf) {
141 return NULL;
142 }
143 for(unsigned int i = 0; i < desc.tile_count; ++i) {
146 desc.height;
147 buf->tiles[i].data = (char *) malloc(buf->tiles[i].data_len);
148 assert(buf->tiles[i].data != NULL);
149 }
150
152 buf->callbacks.recycle = NULL;
153
154 return buf;
155}
156
158{
159 if(!buf)
160 return;
161
162 for(unsigned int i = 0u; i < buf->tile_count; ++i) {
163 free(buf->tiles[i].data);
164 }
165}
166
167void vf_free(struct video_frame *buf)
168{
169 if(!buf)
170 return;
171 if (buf->callbacks.data_deleter) {
172 buf->callbacks.data_deleter(buf);
173 }
174 free(buf);
175}
176
178 switch (codec) {
179 case UYVY: return "UYVY";
180 case YUYV: return "YUYV";
181 case v210: return "v210";
182 case RGBA: return "RGBA";
183 case RGB: return "RGB";
184 case BGR: return "BGR";
185 case R10k: return "R10k";
186 default:
187 fprintf(stderr, "\nError getting codec name for codec ID %d - unsupported in Windows, report to "
188 "ultragrid-dev@cesnet.cz\n", (int) codec);
189 return "_UNSUPPORTED_";
190 }
191}
192
194 if (strcmp(name, "UYVY") == 0) return UYVY;
195 else if (strcmp(name, "YUYV") == 0) return YUYV;
196 else if (strcmp(name, "v210") == 0) return v210;
197 else if (strcmp(name, "RGBA") == 0) return RGBA;
198 else if (strcmp(name, "RGB") == 0) return RGB;
199 else if (strcmp(name, "BGR") == 0) return BGR;
200 else if (strcmp(name, "R10k") == 0) return R10k;
201 else {
202 fprintf(stderr, "\nError getting codec from name \"%s\" - unsupported in Windows, report to "
203 "ultragrid-dev@cesnet.cz\n", name);
204 return VIDEO_CODEC_NONE;
205 }
206}
207
209{
210 struct video_desc desc;
211
212 assert(frame != NULL);
213
214 desc.width = frame->tiles[0].width;
217 desc.fps = frame->fps;
220
221 return desc;
222}
223
struct video_desc desc
struct video_frame * frame
struct video_frame * vf_alloc(int count)
Allocates blank video frame.
void vf_free(struct video_frame *buf)
Frees video_frame structure.
struct video_desc video_desc_from_frame(const struct video_frame *frame)
Returns struct video_desc from video frame.
void vf_data_deleter(struct video_frame *buf)
int vc_get_linesize(unsigned int width, codec_t codec)
struct video_frame * vf_alloc_desc(struct video_desc desc)
Allocates video frame accordig given desc.
struct video_frame * vf_alloc_desc_data(struct video_desc desc)
const char * get_codec_name(codec_t codec)
void remux_channel(char *out, const char *in, int bps, int in_len, int in_stream_channels, int out_stream_channels, int pos_in_stream, int pos_out_stream)
codec_t get_codec_from_name(const char *name)
This file contains definition of some common audio types.
int count
Definition hd-rum.c:44
const char * name
Definition settings.cpp:193
unsigned int width
Definition types.h:280
char * data
Raw tile data. Pointer must be at least 4B aligned.
Definition types.h:287
unsigned int data_len
length of the data
Definition types.h:288
unsigned int height
Definition types.h:281
unsigned int tile_count
Definition types.h:185
codec_t color_spec
Definition types.h:182
enum interlacing_t interlacing
Definition types.h:184
double fps
Definition types.h:183
unsigned int width
width of every tile (!)
Definition types.h:179
unsigned int height
height of every tile (!)
Definition types.h:180
void(* data_deleter)(struct video_frame *)
Definition types.h:256
void(* recycle)(struct video_frame *)
Definition types.h:263
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
enum interlacing_t interlacing
Definition types.h:307
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
Definition types.h:345
double fps
Definition types.h:308
unsigned int tile_count
Definition types.h:344
struct video_frame_callbacks callbacks
Definition types.h:324
codec_t color_spec
Definition types.h:306
codec_t
Definition types.h:65
@ YUYV
YCbCr 422 8-bit - Y0 Cb Y1 Cr.
Definition types.h:72
@ R10k
RGB 10-bit packed - RGBX, big-endian (2 bit padding)
Definition types.h:73
@ RGB
RGB 8-bit (packed into 24-bit word)
Definition types.h:80
@ UYVY
YCbCr 422 8-bit - Cb Y0 Cr Y1.
Definition types.h:71
@ VIDEO_CODEC_NONE
dummy color spec
Definition types.h:66
@ BGR
8-bit BGR
Definition types.h:88
@ RGBA
RGBA 8-bit, big-endian.
Definition types.h:70
@ v210
YCbCr 422 10-bit - xVY0U|xY2UY1|xUY3V|xY5VY4, little-endian (2 bit padding /'x'/),...
Definition types.h:75
This is an umbrella header for video functions.