UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
3d-interlaced.c
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2011-2015 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 <pthread.h>
45#include <stdlib.h>
46
47#include "debug.h"
48#include "lib_common.h"
49#include "video.h"
50#include "video_display.h" /* DISPLAY_PROPERTY_VIDEO_SEPARATE_FILES */
51#include "vo_postprocess.h"
52
53#define MOD_NAME "[interlaced_3d] "
54
56 struct video_frame *in;
57};
58
59static bool interlaced_3d_get_property(void *state, int property, void *val, size_t *len)
60{
63 UNUSED(val);
64 UNUSED(len);
65
66 return false;
67}
68
69
70static void * interlaced_3d_init(const char *config) {
71 if (strcmp(config, "help") == 0) {
72 printf("3d-interlaced takes no parameters.\n");
73 return NULL;
74 }
75#ifdef __SSE2__
76 struct state_interlaced_3d *s = (struct state_interlaced_3d *)
77 malloc(sizeof(struct state_interlaced_3d));
78 s->in = vf_alloc(2);
79 return s;
80#else
81 log_msg(LOG_LEVEL_ERROR, MOD_NAME "SSE2 not supported on this platform!\n");
82 return NULL;
83#endif
84}
85
86static bool
88{
89 struct state_interlaced_3d *s = (struct state_interlaced_3d *) state;
90
91 assert(desc.tile_count == 2);
92
94 s->in->fps = desc.fps;
96 vf_get_tile(s->in, 0)->width =
97 vf_get_tile(s->in, 1)->width = desc.width;
98 vf_get_tile(s->in, 0)->height =
100
101 vf_get_tile(s->in, 0)->data_len =
103 * desc.height;
104 vf_get_tile(s->in, 0)->data = malloc(vf_get_tile(s->in, 0)->data_len);
105 vf_get_tile(s->in, 1)->data = malloc(vf_get_tile(s->in, 1)->data_len);
106
107 return true;
108}
109
111{
112 struct state_interlaced_3d *s = (struct state_interlaced_3d *) state;
113
114 return s->in;
115}
116
125static bool interlaced_3d_postprocess(void *state, struct video_frame *in, struct video_frame *out, int req_pitch)
126{
127 UNUSED (state);
128 UNUSED (req_pitch);
129
130#ifdef __SSE2__
131 char *out_data = vf_get_tile(out, 0)->data;
132 int linesize = vc_get_linesize(vf_get_tile(out, 0)->width, out->color_spec);
133
134 /* we compute avg from line k/2*2 and k/2*2+1 for left eye and put
135 * to (k/2*2)th line. Than we compute avg of same lines number
136 * and put it to the following line, which creates interlaced stereo */
137 for (unsigned int x = 0; x < vf_get_tile(out, 0)->height; ++x) {
138 int linepos;
139 char *line1 = vf_get_tile(in, x % 2)->data + (x / 2) * 2 * linesize;
140 char *line2 = vf_get_tile(in, x % 2)->data + ((x / 2) * 2 + 1) * linesize;
141
142 for(linepos = 0; linepos < linesize; linepos += 16) {
143 asm volatile ("movdqu (%0), %%xmm0\n"
144 "pavgb (%1), %%xmm0\n"
145 "movdqu %%xmm0, (%2)\n"
146 ::"r" ((unsigned long *)(void *)
147 line1),
148 "r"((unsigned long *)(void *) line2),
149 "r"((unsigned long *)(void *) out_data));
150 out_data += 16;
151 line1 += 16;
152 line2 += 16;
153 }
154 }
155
156 return true;
157#else
158 UNUSED(in);
159 UNUSED(out);
160 return false;
161#endif
162}
163
164static void interlaced_3d_done(void *state)
165{
166 struct state_interlaced_3d *s = (struct state_interlaced_3d *) state;
167
168 free(vf_get_tile(s->in, 0)->data);
169 free(vf_get_tile(s->in, 1)->data);
170 vf_free(s->in);
171 free(state);
172}
173
174static void interlaced_3d_get_out_desc(void *state, struct video_desc *out, int *in_display_mode, int *out_frames)
175{
176 struct state_interlaced_3d *s = (struct state_interlaced_3d *) state;
177
178 out->width = vf_get_tile(s->in, 0)->width; /* not *2 !!!!!!*/
179 out->height = vf_get_tile(s->in, 0)->height;
180 out->color_spec = s->in->color_spec;
181 out->interlacing = s->in->interlacing;
182 out->fps = s->in->fps;
183 out->tile_count = 1;
184
185 *in_display_mode = DISPLAY_PROPERTY_VIDEO_SEPARATE_TILES;
186 *out_frames = 1;
187}
188
198
200
static void * interlaced_3d_init(const char *config)
static struct video_frame * interlaced_3d_getf(void *state)
static bool interlaced_3d_postprocess(void *state, struct video_frame *in, struct video_frame *out, int req_pitch)
static void interlaced_3d_done(void *state)
static void interlaced_3d_get_out_desc(void *state, struct video_desc *out, int *in_display_mode, int *out_frames)
static bool interlaced_3d_get_property(void *state, int property, void *val, size_t *len)
static bool interlaced_3d_postprocess_reconfigure(void *state, struct video_desc desc)
#define MOD_NAME
static const struct vo_postprocess_info vo_pp_interlaced_3d_info
#define UNUSED(x)
void ** state
int void * val
struct video_desc desc
int void size_t * len
int property
struct video_frame * vf_alloc(int count)
Allocates blank video frame.
void vf_free(struct video_frame *buf)
Frees video_frame structure.
int vc_get_linesize(unsigned int width, codec_t codec)
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define LOG_LEVEL_ERROR
general errors
Definition debug.h:59
@ DISPLAY_PROPERTY_VIDEO_SEPARATE_TILES
framebuffer consists of separate tiles
@ 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 * in
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
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
enum interlacing_t interlacing
Definition types.h:307
double fps
Definition types.h:308
codec_t color_spec
Definition types.h:306
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