UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
capture_filter_wrapper.h
Go to the documentation of this file.
1
10/*
11 * Copyright (c) 2020 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#ifndef CAPTURE_FILTER_WRAPPER_H_4106D5BE_4B1D_4367_B506_67B358514C50
44#define CAPTURE_FILTER_WRAPPER_H_4106D5BE_4B1D_4367_B506_67B358514C50
45
46#include <assert.h>
47#include <stdint.h>
48
49#include "capture_filter.h"
50#include "utils/macros.h"
51#include "video_display.h"
52#include "vo_postprocess.h"
53
54#define CFW_MAGIC to_fourcc('V', 'P', 'C', 'F')
55
62
63#define CF_WRAPPER_MERGE(a,b) a##b
64
65#define ADD_VO_PP_CAPTURE_FILTER_WRAPPER(name, init, filter, done, set_out_buf, get_prop_callb) \
66static void *CF_WRAPPER_MERGE(vo_pp_init_, name)(const char *cfg) {\
67 void *state;\
68 if (init(NULL, cfg, &state) != 0) {\
69 return NULL;\
70 }\
71 struct vo_pp_capture_filter_wrapper *s = (struct vo_pp_capture_filter_wrapper *) \
72 calloc(1, sizeof(struct vo_pp_capture_filter_wrapper));\
73 s->magic = CFW_MAGIC;\
74 s->state = state;\
75 s->get_property = get_prop_callb;\
76 return s;\
77}\
78\
79static bool CF_WRAPPER_MERGE(vo_pp_reconfigure_, name)(void *state, struct video_desc desc) {\
80 struct vo_pp_capture_filter_wrapper *s = (struct vo_pp_capture_filter_wrapper *) state;\
81 s->f = vf_alloc_desc_data(desc);\
82 return true;\
83}\
84\
85static bool CF_WRAPPER_MERGE(vo_pp_get_property_, name)(void *state, int property, void *val, size_t *len) {\
86 struct vo_pp_capture_filter_wrapper *s = (struct vo_pp_capture_filter_wrapper *) state;\
87 assert(s->magic == CFW_MAGIC);\
88 if (s->get_property == 0) {\
89 return false;\
90 }\
91 return s->get_property(s->state, property, val, len);\
92}\
93static struct video_frame *CF_WRAPPER_MERGE(vo_pp_getf_, name)(void *state) {\
94 struct vo_pp_capture_filter_wrapper *s = (struct vo_pp_capture_filter_wrapper *) state;\
95 return s->f;\
96}\
97\
98static bool CF_WRAPPER_MERGE(vo_pp_postprocess_, name)(void *state, struct video_frame *in, struct video_frame *out, int req_out_pitch) {\
99 struct vo_pp_capture_filter_wrapper *s = (struct vo_pp_capture_filter_wrapper *) state;\
100 assert(req_out_pitch == vc_get_linesize(out->tiles[0].width, out->color_spec));\
101 set_out_buf(s->state, out->tiles[0].data);\
102 struct video_frame *dst = filter(s->state, in);\
103 VIDEO_FRAME_DISPOSE(dst);\
104 UNUSED(req_out_pitch);\
105 return true;\
106}\
107static void CF_WRAPPER_MERGE(vo_pp_get_out_desc_, name)(void *state, struct video_desc *out, int *in_tile_mode, int *out_frame_count) {\
108 struct vo_pp_capture_filter_wrapper *s = (struct vo_pp_capture_filter_wrapper *) state;\
109 struct video_frame *tmp_out = filter(s->state, s->f);\
110 *out = video_desc_from_frame(tmp_out);\
111 VIDEO_FRAME_DISPOSE(tmp_out);\
112\
113 *in_tile_mode = DISPLAY_PROPERTY_VIDEO_MERGED;\
114 *out_frame_count = 1;\
115\
116 UNUSED(in_tile_mode);\
117}\
118static void CF_WRAPPER_MERGE(vo_pp_get_out_desc_, done)(void *state) {\
119 struct vo_pp_capture_filter_wrapper *s = (struct vo_pp_capture_filter_wrapper *) state;\
120 done(s->state);\
121 vf_free(s->f);\
122 free(s);\
123}\
124\
125static const struct vo_postprocess_info CF_WRAPPER_MERGE(vo_pp_, name) = {\
126 CF_WRAPPER_MERGE(vo_pp_init_, name),\
127 CF_WRAPPER_MERGE(vo_pp_reconfigure_, name),\
128 CF_WRAPPER_MERGE(vo_pp_getf_, name),\
129 CF_WRAPPER_MERGE(vo_pp_get_out_desc_, name),\
130 CF_WRAPPER_MERGE(vo_pp_get_property_, name),\
131 CF_WRAPPER_MERGE(vo_pp_postprocess_, name),\
132 CF_WRAPPER_MERGE(vo_pp_get_out_desc_, done)\
133};\
134REGISTER_MODULE(name, &CF_WRAPPER_MERGE(vo_pp_, name), LIBRARY_CLASS_VIDEO_POSTPROCESS, VO_PP_ABI_VERSION);
135
136#endif // defined CAPTURE_FILTER_WRAPPER_H_4106D5BE_4B1D_4367_B506_67B358514C50
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
vo_postprocess_get_property_t get_property
void * state
capture filter state
bool(* vo_postprocess_get_property_t)(void *state, int property, void *val, size_t *len)