UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
interlace.c
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2012-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
43#include "debug.h"
44
45#include <pthread.h>
46#include <stdlib.h>
47#include "lib_common.h"
48#include "video.h"
49#include "video_display.h"
50#include "vo_postprocess.h"
51
53 ODD = 0,
54 EVEN = 1
55};
56
60
62};
63
64static void usage()
65{
66 printf("-p interlace\n");
67}
68
69static void * interlace_init(const char *config) {
70 if (strcmp(config, "help") == 0) {
71 usage();
72 return NULL;
73 }
74
75 struct state_interlace *s = (struct state_interlace *)
76 malloc(sizeof(struct state_interlace));
77
78 assert(s != NULL);
79 s->odd = NULL;
80 s->even = NULL;
81 s->last = EVEN; // next one will be od
82
83 return s;
84}
85
86static bool interlace_get_property(void *state, int property, void *val, size_t *len)
87{
90 UNUSED(val);
91 UNUSED(len);
92
93 return false;
94}
95
96static bool
98{
99 struct state_interlace *s = (struct state_interlace *) state;
100
101 vf_free(s->odd);
102 vf_free(s->even);
105
106 s->last = EVEN;
107
108 return true;
109}
110
111static struct video_frame * interlace_getf(void *state)
112{
113 struct state_interlace *s = (struct state_interlace *) state;
114 struct video_frame *ret;
115
116 if((s->last + 1) % 2 == 0) {
117 ret = s->odd;
118 } else {
119 ret = s->even;
120 }
121
122 s->last = (s->last + 1) % 2;
123
124 return ret;
125}
126
127static bool interlace_postprocess(void *state, struct video_frame *in, struct video_frame *out, int req_pitch)
128{
129 struct state_interlace *s = (struct state_interlace *) state;
130
131 UNUSED(in); // we know which frame it is
132
133 if(s->last == ODD) {
134 return false;
135 }
136
137 int linesize = vc_get_linesize(s->odd->tiles[0].width, s->odd->color_spec);
138 for(unsigned int tile = 0; tile < out->tile_count; ++tile) {
139 for (unsigned int i = 0; i < out->tiles[0].height; ++i) {
140 memcpy(out->tiles[tile].data + i * req_pitch,
141 (i % 2 == 0 ?
142 s->odd->tiles[tile].data :
143 s->even->tiles[tile].data)
144 + i * linesize, linesize);
145 }
146 }
147
148 return true;
149}
150
151static void interlace_done(void *state)
152{
153 struct state_interlace *s = (struct state_interlace *) state;
154
155 vf_free(s->odd);
156 vf_free(s->even);
157
158 free(state);
159}
160
161static void interlace_get_out_desc(void *state, struct video_desc *out, int *in_display_mode, int *out_frames)
162{
163 struct state_interlace *s = (struct state_interlace *) state;
164
165 out->width = vf_get_tile(s->odd, 0)->width;
166 out->height = vf_get_tile(s->odd, 0)->height;
167 out->color_spec = s->odd->color_spec;
169 out->fps = s->odd->fps / 2.0;
170 out->tile_count = s->odd->tile_count;
171
172 UNUSED(in_display_mode);
173 //*in_display_mode = DISPLAY_PROPERTY_VIDEO_MERGED;
174 *out_frames = 1;
175}
176
186
188
#define UNUSED(x)
void ** state
int void * val
struct video_desc desc
int void size_t * len
int property
void vf_free(struct video_frame *buf)
Frees video_frame structure.
int vc_get_linesize(unsigned int width, codec_t codec)
struct video_frame * vf_alloc_desc_data(struct video_desc desc)
static const struct vo_postprocess_info vo_pp_interlace_info
Definition interlace.c:177
last_frame
Definition interlace.c:52
@ EVEN
Definition interlace.c:54
@ ODD
Definition interlace.c:53
static void interlace_done(void *state)
Definition interlace.c:151
static void interlace_get_out_desc(void *state, struct video_desc *out, int *in_display_mode, int *out_frames)
Definition interlace.c:161
static bool interlace_reconfigure(void *state, struct video_desc desc)
Definition interlace.c:97
static void usage()
Definition interlace.c:64
static struct video_frame * interlace_getf(void *state)
Definition interlace.c:111
static bool interlace_postprocess(void *state, struct video_frame *in, struct video_frame *out, int req_pitch)
Definition interlace.c:127
static void * interlace_init(const char *config)
Definition interlace.c:69
static bool interlace_get_property(void *state, int property, void *val, size_t *len)
Definition interlace.c:86
@ 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
struct video_frame * even
Definition interlace.c:59
struct video_frame * odd
Definition interlace.c:58
enum last_frame last
Definition interlace.c:61
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 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
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
Definition types.h:345
double fps
Definition types.h:308
unsigned int tile_count
Definition types.h:344
codec_t color_spec
Definition types.h:306
@ INTERLACED_MERGED
Columngs of both fields are interlaced together.
Definition types.h:167
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].
#define VO_PP_ABI_VERSION