UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
mirror.c
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2015-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
44#include "capture_filter.h"
45#include "debug.h"
46#include "lib_common.h"
47#include "utils/color_out.h"
48#include "video.h"
49#include "video_codec.h"
51
52static int init(struct module *parent, const char *cfg, void **state);
53static void done(void *state);
54static struct video_frame *filter(void *state, struct video_frame *in);
55
58};
59
60static int init(struct module *parent, const char *cfg, void **state)
61{
63 if (strlen(cfg) > 0) {
64 color_printf(TRED(TBOLD("mirror")) " capture filter flips the video horizontally (across vertical axis), takes no arguments\n");
65 return strcmp(cfg, "help") == 0 ? 1 : -1;
66 }
67 *state = calloc(1, sizeof(struct state_mirror));
68 return 0;
69}
70
71static void done(void *state)
72{
73 free(state);
74}
75
76static void mirror_line_UYVY(unsigned char *dst, const unsigned char *src, int linesize)
77{
78 dst = dst + linesize;
79 while (linesize > 3) {
80 unsigned char u, y1, v, y2;
81 u = *src++;
82 y1 = *src++;
83 v = *src++;
84 y2 = *src++;
85
86 *--dst = y1;
87 *--dst = v;
88 *--dst = y2;
89 *--dst = u;
90
91 linesize -= 4;
92 }
93}
94
95static struct video_frame *filter(void *state, struct video_frame *in)
96{
97 struct state_mirror *s = state;
98
99 if (in->color_spec != UYVY) {
100 log_msg(LOG_LEVEL_WARNING, "Only supported colorspace for mirror is currently UYVY!\n");
101 return in;
102 }
103
105 if (s->vo_pp_out_buffer) {
106 out->tiles[0].data = s->vo_pp_out_buffer;
107 } else {
108 out->tiles[0].data = (char *) malloc(out->tiles[0].data_len);
110 }
112
113 unsigned char *in_data = (unsigned char *) in->tiles[0].data;
114 unsigned char *out_data = (unsigned char *) out->tiles[0].data;
115
116 int linesize = vc_get_linesize(in->tiles[0].width, in->color_spec);
117 for (unsigned int y = 0; y < in->tiles[0].height; ++y) {
118 mirror_line_UYVY(out_data + y * linesize, in_data + y * linesize, linesize);
119 }
120
122
123 return out;
124}
125
126static void vo_pp_set_out_buffer(void *state, char *buffer)
127{
128 struct state_mirror *s = state;
129 s->vo_pp_out_buffer = buffer;
130}
131
133 .init = init,
134 .done = done,
135 .filter = filter,
136};
137
139// coverity[leaked_storage:SUPPRESS]
141
#define UNUSED(x)
void ** state
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.
#define CAPTURE_FILTER_ABI_VERSION
#define ADD_VO_PP_CAPTURE_FILTER_WRAPPER(name, init, filter, done, set_out_buf, get_prop_callb)
int color_printf(const char *format,...)
#define TRED(x)
Definition color_out.h:75
#define TBOLD(x)
Definition color_out.h:70
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define LOG_LEVEL_WARNING
less severe errors
Definition debug.h:60
@ 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
static struct video_frame * filter(void *state, struct video_frame *in)
Definition mirror.c:95
static void vo_pp_set_out_buffer(void *state, char *buffer)
Definition mirror.c:126
static void mirror_line_UYVY(unsigned char *dst, const unsigned char *src, int linesize)
Definition mirror.c:76
static const struct capture_filter_info capture_filter_mirror
Definition mirror.c:132
static void done(void *state)
Definition mirror.c:71
static int init(struct module *parent, const char *cfg, void **state)
Definition mirror.c:60
const char * parent
Definition settings.cpp:198
char * vo_pp_out_buffer
buffer to write to if we use vo_pp wrapper (otherwise unused)
Definition mirror.c:57
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
void(* data_deleter)(struct video_frame *)
Definition types.h:256
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 tile tiles[FLEXIBLE_ARRAY_MEMBER]
Definition types.h:345
struct video_frame_callbacks callbacks
Definition types.h:324
codec_t color_spec
Definition types.h:306
@ UYVY
YCbCr 422 8-bit - Cb Y0 Cr Y1.
Definition types.h:71
This is an umbrella header for video functions.
#define VIDEO_FRAME_DISPOSE(frame)
Definition video_frame.h:76