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) 2019 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
44#include "capture_filter.h"
45
46#include "debug.h"
47#include "lib_common.h"
48#include "utils/color_out.h"
49#include "utils/vf_split.h"
50#include "video.h"
51#include "video_codec.h"
52
53#define MAX_TILES 16
54
55struct module;
56
57static int init(struct module *parent, const char *cfg, void **state);
58static void done(void *state);
59static struct video_frame *filter(void *state, struct video_frame *in);
60
62 int x, y;
63};
64
65static void usage() {
66 printf("Splits frame to XxY tiles:\n\n");
67 printf("split usage:\n");
68 color_printf(TERM_BOLD "\tsplit:x:y\n\n" TERM_RESET);
69}
70
71static int init(struct module *parent, const char *cfg, void **state)
72{
74 int x, y;
75
76 if (!cfg || strchr(cfg, ':') == NULL) {
77 usage();
78 return -1;
79 }
80 if (strcasecmp(cfg, "help") == 0) {
81 usage();
82 return 1;
83 }
84
85 x = atoi(cfg);
86 y = atoi(strchr(cfg, ':') + 1);
87 assert(x > 0 && y > 0);
88
89
90 struct state_split *s = calloc(1, sizeof(struct state_split));
91 s->x = x;
92 s->y = y;
93
94 *state = s;
95 return 0;
96}
97
98static void done(void *state)
99{
100 free(state);
101}
102
103static struct video_frame *filter(void *state, struct video_frame *in)
104{
105 struct state_split *s = state;
106
108 desc.tile_count = s->x * s->y;
109 desc.width /= s->x;
110 desc.height /= s->y;
111 struct video_frame *out = vf_alloc_desc_data(desc);
112 vf_split(out, in, s->x, s->y, 0);
114
116 return out;
117}
118
120 .init = init,
121 .done = done,
122 .filter = filter,
123};
124
126
#define UNUSED(x)
void ** state
struct video_desc desc
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.
struct video_frame * vf_alloc_desc_data(struct video_desc desc)
static struct video_frame * filter(void *state, struct video_frame *in)
Definition split.c:103
static void usage()
Definition split.c:65
static const struct capture_filter_info capture_filter_split
Definition split.c:119
static void done(void *state)
Definition split.c:98
static int init(struct module *parent, const char *cfg, void **state)
Definition split.c:71
#define CAPTURE_FILTER_ABI_VERSION
int color_printf(const char *format,...)
#define TERM_BOLD
Definition color_out.h:48
#define TERM_RESET
Definition color_out.h:47
@ LIBRARY_CLASS_CAPTURE_FILTER
Definition lib_common.h:75
#define REGISTER_MODULE(name, info, lclass, abi)
Registers module to global modules' registry.
Definition lib_common.h:144
const char * parent
Definition settings.cpp:198
int x
Definition split.c:62
int y
Definition split.c:62
unsigned int tile_count
Definition types.h:185
unsigned int width
width of every tile (!)
Definition types.h:179
unsigned int height
height of every tile (!)
Definition types.h:180
void(* dispose)(struct video_frame *)
Definition types.h:245
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
struct video_frame_callbacks callbacks
Definition types.h:324
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.
#define VIDEO_FRAME_DISPOSE(frame)
Definition video_frame.h:76