UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
split.c
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2011-2023 CESNET, z. s. p. o.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, is permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of CESNET nor the names of its contributors may be
21 * used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
26 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifdef HAVE_CONFIG_H
39#include "config.h"
40#include "config_unix.h"
41#include "config_win32.h"
42#endif // HAVE_CONFIG_H
43#include "debug.h"
44
45#include "lib_common.h"
46#include "utils/vf_split.h"
47#include "video.h"
48#include "video_display.h" /* DISPLAY_PROPERTY_VIDEO_SEPARATE_FILES */
49#include "vo_postprocess.h" /* VO_PP_DOES_CHANGE_TILING_MODE */
50#include <pthread.h>
51#include <stdlib.h>
52
53struct state_split {
54 struct video_frame *in;
56};
57
58
59static bool split_get_property(void *state, int property, void *val, size_t *len)
60{
62
63 switch(property) {
65 if(*len >= sizeof(bool)) {
66 *(bool *) val = true;
67 *len = sizeof(bool);
68 } else {
69 *len = 0;
70 }
71 return true;
72 }
73 return false;
74}
75
76static void usage()
77{
78 printf("-p split:<X>:<Y>\n");
79 printf("\tsplit to XxY tiles\n");
80}
81
82static void * split_init(const char *config) {
83 char *save_ptr = NULL;
84 char *item;
85
86 if (strcmp(config, "help") == 0) {
87 usage();
88 return NULL;
89 }
90 struct state_split *s = (struct state_split *)
91 malloc(sizeof(struct state_split));
92
93 char *tmp = strdup(config);
94 assert(tmp != NULL);
95
96 item = strtok_r(tmp, ":", &save_ptr);
97 s->grid_width = atoi(item);
98 item = strtok_r(NULL, ":", &save_ptr);
99 if(!item) {
100 usage();
101 free(s);
102 free(tmp);
103 return NULL;
104 }
105
106 s->grid_height = atoi(item);
107 free(tmp);
108
109 s->in = vf_alloc(1);
110
111 return s;
112}
113
114static bool
116{
117 struct state_split *s = (struct state_split *) state;
118 struct tile *in_tile = vf_get_tile(s->in, 0);
119
121 s->in->fps = desc.fps;
123
124 in_tile->width = desc.width;
125 in_tile->height = desc.height;
126
128 desc.height;
129 in_tile->data = malloc(in_tile->data_len);
130
131 return true;
132}
133
134static struct video_frame * split_getf(void *state)
135{
136 struct state_split *s = (struct state_split *) state;
137
138 return s->in;
139}
140
141static bool split_postprocess(void *state, struct video_frame *in, struct video_frame *out, int req_pitch)
142{
143 struct state_split *s = (struct state_split *) state;
144 UNUSED(req_pitch);
145
146 vf_split(out, in, s->grid_width, s->grid_height, FALSE);
147
148 return true;
149}
150
151static void split_done(void *state)
152{
153 struct state_split *s = (struct state_split *) state;
154
155 free(vf_get_tile(s->in, 0)->data);
156 vf_free(s->in);
157 free(state);
158}
159
160static void split_get_out_desc(void *state, struct video_desc *out, int *in_display_mode, int *out_frames)
161{
162 struct state_split *s = (struct state_split *) state;
163
164 out->width = vf_get_tile(s->in, 0)->width / s->grid_width;
165 out->height = vf_get_tile(s->in, 0)->height / s->grid_height;
166 out->color_spec = s->in->color_spec;
167 out->interlacing = s->in->interlacing;
168 out->fps = s->in->fps;
169 out->tile_count = s->grid_width * s->grid_height;
170
171 *in_display_mode = DISPLAY_PROPERTY_VIDEO_MERGED;
172 *out_frames = 1;
173}
174
184
186
#define UNUSED(x)
void ** state
int void * val
struct video_desc desc
int void size_t * len
int property
struct video_frame * vf_alloc(int count)
Allocates blank video frame.
void vf_free(struct video_frame *buf)
Frees video_frame structure.
int vc_get_linesize(unsigned int width, codec_t codec)
static void usage()
Definition split.c:65
#define FALSE
@ DISPLAY_PROPERTY_VIDEO_MERGED
monolithic framebuffer
@ LIBRARY_CLASS_VIDEO_POSTPROCESS
Definition lib_common.h:83
#define REGISTER_MODULE(name, info, lclass, abi)
Registers module to global modules' registry.
Definition lib_common.h:144
Definition hd-rum.c:27
struct video_frame * in
Definition split.c:54
int grid_width
Definition split.c:55
int grid_height
Definition split.c:55
Struct tile is an area of video_frame.
Definition types.h:279
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
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
enum interlacing_t interlacing
Definition types.h:307
double fps
Definition types.h:308
codec_t color_spec
Definition types.h:306
void vf_split(struct video_frame *out, struct video_frame *src, unsigned int x_count, unsigned int y_count, int preallocate)
Definition vf_split.cpp:51
This is an umbrella header for video functions.
struct tile * vf_get_tile(struct video_frame *buf, int pos)
Returns pointer to n-th tile from video frame Equivalent to &video_frame::tiles[pos].
static bool split_postprocess(void *state, struct video_frame *in, struct video_frame *out, int req_pitch)
Definition split.c:141
static void * split_init(const char *config)
Definition split.c:82
static struct video_frame * split_getf(void *state)
Definition split.c:134
static bool split_postprocess_reconfigure(void *state, struct video_desc desc)
Definition split.c:115
static bool split_get_property(void *state, int property, void *val, size_t *len)
Definition split.c:59
static const struct vo_postprocess_info vo_pp_split_info
Definition split.c:175
static void split_get_out_desc(void *state, struct video_desc *out, int *in_display_mode, int *out_frames)
Definition split.c:160
static void split_done(void *state)
Definition split.c:151
#define VO_PP_DOES_CHANGE_TILING_MODE
#define VO_PP_ABI_VERSION