xine-lib 1.2.13-20230125hg15249
mem_frame.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012-2022 the xine project
3 * Copyright (C) 2012 Christophe Thommeret <hftom@free.fr>
4 *
5 * This file is part of xine, a free video player.
6 *
7 * xine is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * xine is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 *
22 * mem_frame.h, generic memory backed frame
23 *
24 *
25 */
26
27#ifndef XINE_MEM_FRAME_H
28#define XINE_MEM_FRAME_H
29
30#include <xine/xineutils.h>
31
37
38static void _mem_frame_proc_slice(vo_frame_t *vo_img, uint8_t **src)
39{
40 (void)src;
41 vo_img->proc_called = 1;
42}
43
44static void _mem_frame_field(vo_frame_t *vo_img, int which_field)
45{
46 (void)vo_img;
47 (void)which_field;
48}
49
51{
52 xine_freep_aligned (&vo_img->base[0]);
53 vo_img->base[1] = NULL;
54 vo_img->base[2] = NULL;
55 vo_img->pitches[0] = vo_img->pitches[1] = vo_img->pitches[2] = 0;
56}
57
58static void _mem_frame_dispose(vo_frame_t *vo_img)
59{
61 pthread_mutex_destroy (&vo_img->mutex);
62 free (vo_img);
63}
64
65static void _mem_frame_init(mem_frame_t *frame, vo_driver_t *driver)
66{
67 frame->vo_frame.base[0] = frame->vo_frame.base[1] = frame->vo_frame.base[2] = NULL;
68 frame->width = frame->height = frame->format = frame->flags = 0;
69 frame->ratio = 0.0;
70
71 pthread_mutex_init (&frame->vo_frame.mutex, NULL);
72
74 frame->vo_frame.proc_frame = NULL;
77 frame->vo_frame.driver = driver;
78}
79
80static vo_frame_t *_mem_frame_alloc_frame(vo_driver_t *this_gen, size_t frame_size)
81{
82 mem_frame_t *frame;
83
84 frame = calloc(1, frame_size);
85
86 if (!frame)
87 return NULL;
88
89 _mem_frame_init(frame, this_gen);
90
91 return &frame->vo_frame;
92}
93
95{
96 return _mem_frame_alloc_frame(this_gen, sizeof(mem_frame_t));
97}
98
99static inline void *_memset32(void *mem, uint32_t val, size_t n)
100{
101 uint32_t *m32 = mem, *ret = mem;
102 size_t i;
103 for (i = n; i; i--)
104 *m32++ = val;
105 return ret;
106}
107
108static inline void mem_frame_update_frame_format(vo_driver_t *this_gen, vo_frame_t *frame_gen,
109 uint32_t width, uint32_t height, double ratio, int format, int flags)
110{
111 mem_frame_t *frame = xine_container_of(frame_gen, mem_frame_t, vo_frame);
112
113 (void)this_gen;
114
115 /* vo_none and vo_opengl2 need no buffer adjustment for these. */
116 frame->flags = flags;
117 frame->ratio = ratio;
118
119 /* Check frame size and format and reallocate if necessary (rare case). */
120 if (!((frame->width ^ width) | (frame->height ^ height) | (frame->format ^ format)))
121 return;
122
123 frame->width = width;
124 frame->height = height;
125 frame->format = format;
126
127 /* (re-) allocate render space */
128 _mem_frame_free_framedata(frame_gen);
129
130 if (format == XINE_IMGFMT_YV12) {
131 uint32_t w = (width + 15) & ~15;
132 uint32_t ysize = w * height;
133 uint32_t uvsize = (w >> 1) * ((height + 1) >> 1);
134
135 frame->vo_frame.base[0] = xine_malloc_aligned (ysize + 2 * uvsize);
136 if (frame->vo_frame.base[0]) {
137 frame->vo_frame.base[1] = frame->vo_frame.base[0] + ysize;
138 frame->vo_frame.base[2] = frame->vo_frame.base[1] + uvsize;
139 frame->vo_frame.pitches[0] = w;
140 frame->vo_frame.pitches[1] = w >> 1;
141 frame->vo_frame.pitches[2] = w >> 1;
142
143 memset (frame->vo_frame.base[0], 0, ysize);
144 memset (frame->vo_frame.base[1], 128, 2 * uvsize);
145 }
146
147 } else if (format == XINE_IMGFMT_YV12_DEEP) {
148 unsigned w = (width + 15) & ~15;
149 unsigned ysize = 2 * w * height;
150 unsigned uvsize = w * ((height + 1) >> 1);
151
152 frame->vo_frame.base[0] = xine_malloc_aligned (ysize + 2 * uvsize);
153 if (frame->vo_frame.base[0]) {
154 unsigned depth = VO_GET_FLAGS_DEPTH(flags);
155 uint32_t black = 0x00010001U * (1U << (depth - 1));
156
157 frame->vo_frame.base[1] = frame->vo_frame.base[0] + ysize;
158 frame->vo_frame.base[2] = frame->vo_frame.base[1] + uvsize;
159 frame->vo_frame.pitches[0] = w * 2;
160 frame->vo_frame.pitches[1] = w;
161 frame->vo_frame.pitches[2] = w;
162
163 memset (frame->vo_frame.base[0], 0, ysize);
164 _memset32 (frame->vo_frame.base[1], black, 2 * uvsize / sizeof(uint32_t));
165 }
166
167 } else if (format == XINE_IMGFMT_NV12) {
168 uint32_t w = (width + 15) & ~15;
169 uint32_t ysize = w * height;
170 uint32_t uvsize = w * ((height + 1) >> 1);
171
172 frame->vo_frame.base[0] = xine_malloc_aligned (ysize + uvsize);
173 if (frame->vo_frame.base[0]) {
174 frame->vo_frame.base[1] = frame->vo_frame.base[0] + ysize;
175 frame->vo_frame.pitches[0] = w;
176 frame->vo_frame.pitches[1] = w;
177
178 memset (frame->vo_frame.base[0], 0, ysize);
179 memset (frame->vo_frame.base[1], 128, uvsize);
180 }
181
182 } else if (format == XINE_IMGFMT_YUY2) {
183 uint32_t w = (width + 15) & ~15;
184 frame->vo_frame.base[0] = xine_malloc_aligned ((w << 1) * height);
185 if (frame->vo_frame.base[0]) {
186 const union {uint8_t bytes[4]; uint32_t word;} black = {{0, 128, 0, 128}};
187 frame->vo_frame.pitches[0] = w << 1;
188 _memset32 (frame->vo_frame.base[0], black.word, frame->vo_frame.pitches[0] * height / sizeof(uint32_t));
189 }
190 }
191
192 if (!frame->vo_frame.base[0]) {
193 /* tell vo_get_frame () to retry later */
194 frame->width = 0;
195 frame->vo_frame.width = 0;
196 }
197}
198
199#endif /* XINE_MEM_FRAME_H */
unsigned int height
Definition gfontrle.c:5
unsigned int width
Definition gfontrle.c:4
#define VO_GET_FLAGS_DEPTH(flags)
Definition video_out.h:321
struct mem_frame_t mem_frame_t
static void mem_frame_update_frame_format(vo_driver_t *this_gen, vo_frame_t *frame_gen, uint32_t width, uint32_t height, double ratio, int format, int flags)
Definition mem_frame.h:108
static void * _memset32(void *mem, uint32_t val, size_t n)
Definition mem_frame.h:99
static vo_frame_t * _mem_frame_alloc_frame(vo_driver_t *this_gen, size_t frame_size)
Definition mem_frame.h:80
static vo_frame_t * mem_frame_alloc_frame(vo_driver_t *this_gen)
Definition mem_frame.h:94
static void _mem_frame_field(vo_frame_t *vo_img, int which_field)
Definition mem_frame.h:44
static void _mem_frame_init(mem_frame_t *frame, vo_driver_t *driver)
Definition mem_frame.h:65
static void _mem_frame_dispose(vo_frame_t *vo_img)
Definition mem_frame.h:58
static void _mem_frame_proc_slice(vo_frame_t *vo_img, uint8_t **src)
Definition mem_frame.h:38
static void _mem_frame_free_framedata(vo_frame_t *vo_img)
Definition mem_frame.h:50
Definition mem_frame.h:32
vo_frame_t vo_frame
Definition mem_frame.h:33
int format
Definition mem_frame.h:34
int flags
Definition mem_frame.h:34
int height
Definition mem_frame.h:34
int width
Definition mem_frame.h:34
double ratio
Definition mem_frame.h:35
Definition video_out.h:50
Definition video_out.h:70
void(* proc_slice)(vo_frame_t *vo_img, uint8_t **src)
Definition video_out.h:94
int pitches[3]
Definition video_out.h:128
int proc_called
Definition video_out.h:155
int width
Definition video_out.h:149
void(* proc_frame)(vo_frame_t *vo_img)
Definition video_out.h:90
pthread_mutex_t mutex
Definition video_out.h:143
void(* field)(vo_frame_t *vo_img, int which_field)
Definition video_out.h:97
vo_driver_t * driver
Definition video_out.h:162
uint8_t * base[3]
Definition video_out.h:127
void(* dispose)(vo_frame_t *vo_img)
Definition video_out.h:114
void * xine_malloc_aligned(size_t size)
Definition utils.c:869
#define XINE_IMGFMT_YV12
Definition xine.h:498
#define XINE_IMGFMT_YUY2
Definition xine.h:500
#define XINE_IMGFMT_YV12_DEEP
Definition xine.h:505
#define XINE_IMGFMT_NV12
Definition xine.h:499
NULL
Definition xine_plugin.c:78
#define xine_container_of(ptr, type, member)
Definition xineutils.h:257
#define xine_freep_aligned(xinefreepptr)
Definition xineutils.h:304