UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
flip.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
56struct state_flip {
58};
59
60static int init(struct module *parent, const char *cfg, void **state)
61{
63 if (strlen(cfg) > 0) {
64 color_printf(TRED(TBOLD("flip")) " capture filter flips the video vertically (across horizontal axis), takes no arguments\n");
65 return strcmp(cfg, "help") == 0 ? 1 : -1;
66 }
67 *state = calloc(1, sizeof(struct state_flip));
68 return 0;
69}
70
71static void done(void *state)
72{
73 free(state);
74}
75
76static struct video_frame *filter(void *state, struct video_frame *in)
77{
78 struct state_flip *s = state;
80 if (s->vo_pp_out_buffer) {
81 out->tiles[0].data = s->vo_pp_out_buffer;
82 } else {
83 out->tiles[0].data = (char *) (malloc(out->tiles[0].data_len));
85 }
87
88 unsigned char *in_data = (unsigned char *) in->tiles[0].data;
89 unsigned char *out_data = (unsigned char *) out->tiles[0].data;
90
91 int linesize = vc_get_linesize(in->tiles[0].width, in->color_spec);
92 for (unsigned int y = 0; y < in->tiles[0].height; ++y) {
93 memcpy(out_data + (in->tiles[0].height - y - 1) * linesize, in_data + y * linesize, linesize);
94 }
95
97
98 return out;
99}
100
101static void vo_pp_set_out_buffer(void *state, char *buffer)
102{
103 struct state_flip *s = state;
104 s->vo_pp_out_buffer = buffer;
105}
106
108 .init = init,
109 .done = done,
110 .filter = filter,
111};
112
114// coverity[leaked_storage:SUPPRESS]
116
#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
static struct video_frame * filter(void *state, struct video_frame *in)
Definition flip.c:76
static const struct capture_filter_info capture_filter_flip
Definition flip.c:107
static void vo_pp_set_out_buffer(void *state, char *buffer)
Definition flip.c:101
static void done(void *state)
Definition flip.c:71
static int init(struct module *parent, const char *cfg, void **state)
Definition flip.c: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
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 flip.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
This is an umbrella header for video functions.
#define VIDEO_FRAME_DISPOSE(frame)
Definition video_frame.h:76