1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
#include <assert.h>
#include <X11/Xlib.h>
#include <X11/extensions/XvMC.h>
#include <vl_context.h>
#include <vl_surface.h>
static enum VL_PICTURE PictureToVL(int xvmc_pic)
{
enum VL_PICTURE vl_pic;
switch (xvmc_pic)
{
case XVMC_TOP_FIELD:
{
vl_pic = VL_TOP_FIELD;
break;
}
case XVMC_BOTTOM_FIELD:
{
vl_pic = VL_BOTTOM_FIELD;
break;
}
case XVMC_FRAME_PICTURE:
{
vl_pic = VL_FRAME_PICTURE;
break;
}
default:
assert(0);
}
return vl_pic;
}
static enum VL_MC_TYPE MotionToVL(int xvmc_motion_type)
{
enum VL_MC_TYPE vl_mc_type;
switch (xvmc_motion_type)
{
case XVMC_PREDICTION_FRAME:
{
vl_mc_type = VL_FRAME_MC;
break;
}
case XVMC_PREDICTION_FIELD:
{
vl_mc_type = VL_FIELD_MC;
break;
}
case XVMC_PREDICTION_DUAL_PRIME:
{
vl_mc_type = VL_DUAL_PRIME_MC;
break;
}
default:
assert(0);
}
return vl_mc_type;
}
Status XvMCCreateSurface(Display *display, XvMCContext *context, XvMCSurface *surface)
{
struct VL_CONTEXT *vl_ctx;
struct VL_SURFACE *vl_sfc;
assert(display);
if (!context)
return XvMCBadContext;
if (!surface)
return XvMCBadSurface;
vl_ctx = context->privData;
assert(display == vl_ctx->display);
vlCreateSurface(vl_ctx, &vl_sfc);
surface->surface_id = XAllocID(display);
surface->context_id = context->context_id;
surface->surface_type_id = context->surface_type_id;
surface->width = context->width;
surface->height = context->height;
surface->privData = vl_sfc;
return Success;
}
Status XvMCRenderSurface
(
Display *display,
XvMCContext *context,
unsigned int picture_structure,
XvMCSurface *target_surface,
XvMCSurface *past_surface,
XvMCSurface *future_surface,
unsigned int flags,
unsigned int num_macroblocks,
unsigned int first_macroblock,
XvMCMacroBlockArray *macroblocks,
XvMCBlockArray *blocks
)
{
struct VL_CONTEXT *vl_ctx;
struct VL_SURFACE *target_vl_surface;
struct VL_SURFACE *past_vl_surface;
struct VL_SURFACE *future_vl_surface;
unsigned int i;
assert(display);
if (!context)
return XvMCBadContext;
if (!target_surface)
return XvMCBadSurface;
if
(
picture_structure != XVMC_TOP_FIELD &&
picture_structure != XVMC_BOTTOM_FIELD &&
picture_structure != XVMC_FRAME_PICTURE
)
return BadValue;
if (future_surface && !past_surface)
return BadMatch;
vl_ctx = context->privData;
assert(display == vl_ctx->display);
target_vl_surface = target_surface->privData;
past_vl_surface = past_surface ? past_surface->privData : NULL;
future_vl_surface = future_surface ? future_surface->privData : NULL;
assert(vl_ctx == target_vl_surface->context);
assert(!past_vl_surface || vl_ctx == past_vl_surface->context);
assert(!future_vl_surface || vl_ctx == future_vl_surface->context);
assert(macroblocks);
assert(blocks);
assert(macroblocks->context_id == context->context_id);
assert(blocks->context_id == context->context_id);
assert(flags == 0 || flags == XVMC_SECOND_FIELD);
/* TODO: Batch macroblocks by type (I,P,B) */
for (i = first_macroblock; i < first_macroblock + num_macroblocks; ++i)
if (macroblocks->macro_blocks[i].macroblock_type & XVMC_MB_TYPE_INTRA)
vlRenderIMacroBlock
(
PictureToVL(picture_structure),
flags == XVMC_SECOND_FIELD ? VL_FIELD_SECOND : VL_FIELD_FIRST,
macroblocks->macro_blocks[i].x,
macroblocks->macro_blocks[i].y,
macroblocks->macro_blocks[i].coded_block_pattern,
macroblocks->macro_blocks[i].dct_type == XVMC_DCT_TYPE_FIELD ? VL_DCT_FIELD_CODED : VL_DCT_FRAME_CODED,
blocks->blocks + (macroblocks->macro_blocks[i].index * 64),
target_vl_surface
);
else if
(
(macroblocks->macro_blocks[i].macroblock_type & (XVMC_MB_TYPE_MOTION_FORWARD | XVMC_MB_TYPE_MOTION_BACKWARD))
== XVMC_MB_TYPE_MOTION_FORWARD
)
{
struct VL_MOTION_VECTOR motion_vector =
{
{
macroblocks->macro_blocks[i].PMV[0][0][0],
macroblocks->macro_blocks[i].PMV[0][0][1],
},
{
macroblocks->macro_blocks[i].PMV[1][0][0],
macroblocks->macro_blocks[i].PMV[1][0][1],
}
};
vlRenderPMacroBlock
(
PictureToVL(picture_structure),
flags == XVMC_SECOND_FIELD ? VL_FIELD_SECOND : VL_FIELD_FIRST,
macroblocks->macro_blocks[i].x,
macroblocks->macro_blocks[i].y,
MotionToVL(macroblocks->macro_blocks[i].motion_type),
&motion_vector,
macroblocks->macro_blocks[i].coded_block_pattern,
macroblocks->macro_blocks[i].dct_type == XVMC_DCT_TYPE_FIELD ? VL_DCT_FIELD_CODED : VL_DCT_FRAME_CODED,
blocks->blocks + (macroblocks->macro_blocks[i].index * 64),
past_vl_surface,
target_vl_surface
);
}
else if
(
(macroblocks->macro_blocks[i].macroblock_type & (XVMC_MB_TYPE_MOTION_FORWARD | XVMC_MB_TYPE_MOTION_BACKWARD))
== XVMC_MB_TYPE_MOTION_BACKWARD
)
{
struct VL_MOTION_VECTOR motion_vector =
{
{
macroblocks->macro_blocks[i].PMV[0][1][0],
macroblocks->macro_blocks[i].PMV[0][1][1],
},
{
macroblocks->macro_blocks[i].PMV[1][1][0],
macroblocks->macro_blocks[i].PMV[1][1][1],
}
};
vlRenderPMacroBlock
(
PictureToVL(picture_structure),
flags == XVMC_SECOND_FIELD ? VL_FIELD_SECOND : VL_FIELD_FIRST,
macroblocks->macro_blocks[i].x,
macroblocks->macro_blocks[i].y,
MotionToVL(macroblocks->macro_blocks[i].motion_type),
&motion_vector,
macroblocks->macro_blocks[i].coded_block_pattern,
macroblocks->macro_blocks[i].dct_type == XVMC_DCT_TYPE_FIELD ? VL_DCT_FIELD_CODED : VL_DCT_FRAME_CODED,
blocks->blocks + (macroblocks->macro_blocks[i].index * 64),
future_vl_surface,
target_vl_surface
);
}
else if
(
(macroblocks->macro_blocks[i].macroblock_type & (XVMC_MB_TYPE_MOTION_FORWARD | XVMC_MB_TYPE_MOTION_BACKWARD))
== (XVMC_MB_TYPE_MOTION_FORWARD | XVMC_MB_TYPE_MOTION_BACKWARD)
)
{
struct VL_MOTION_VECTOR motion_vector[2] =
{
{
{
macroblocks->macro_blocks[i].PMV[0][0][0],
macroblocks->macro_blocks[i].PMV[0][0][1],
},
{
macroblocks->macro_blocks[i].PMV[1][0][0],
macroblocks->macro_blocks[i].PMV[1][0][1],
}
},
{
{
macroblocks->macro_blocks[i].PMV[0][1][0],
macroblocks->macro_blocks[i].PMV[0][1][1],
},
{
macroblocks->macro_blocks[i].PMV[1][1][0],
macroblocks->macro_blocks[i].PMV[1][1][1],
}
}
};
vlRenderBMacroBlock
(
PictureToVL(picture_structure),
flags == XVMC_SECOND_FIELD ? VL_FIELD_SECOND : VL_FIELD_FIRST,
macroblocks->macro_blocks[i].x,
macroblocks->macro_blocks[i].y,
MotionToVL(macroblocks->macro_blocks[i].motion_type),
motion_vector,
macroblocks->macro_blocks[i].coded_block_pattern,
macroblocks->macro_blocks[i].dct_type == XVMC_DCT_TYPE_FIELD ? VL_DCT_FIELD_CODED : VL_DCT_FRAME_CODED,
blocks->blocks + (macroblocks->macro_blocks[i].index * 64),
past_vl_surface,
future_vl_surface,
target_vl_surface
);
}
else
fprintf(stderr, "Unrecognized macroblock\n");
return Success;
}
Status XvMCFlushSurface(Display *display, XvMCSurface *surface)
{
assert(display);
if (!surface)
return XvMCBadSurface;
/* TODO: Check display & surface match */
return Success;
}
Status XvMCSyncSurface(Display *display, XvMCSurface *surface)
{
assert(display);
if (!surface)
return XvMCBadSurface;
return Success;
}
Status XvMCPutSurface
(
Display *display,
XvMCSurface *surface,
Drawable drawable,
short srcx,
short srcy,
unsigned short srcw,
unsigned short srch,
short destx,
short desty,
unsigned short destw,
unsigned short desth,
int flags
)
{
Window root;
int x, y;
unsigned int width, height;
unsigned int border_width;
unsigned int depth;
struct VL_SURFACE *vl_sfc;
assert(display);
if (!surface)
return XvMCBadSurface;
if (XGetGeometry(display, drawable, &root, &x, &y, &width, &height, &border_width, &depth) == BadDrawable)
return BadDrawable;
assert(flags == XVMC_TOP_FIELD || flags == XVMC_BOTTOM_FIELD || flags == XVMC_FRAME_PICTURE);
/* TODO: Correct for negative srcx,srcy & destx,desty by clipping */
assert(srcx + srcw - 1 < surface->width);
assert(srcy + srch - 1 < surface->height);
assert(destx + destw - 1 < width);
assert(desty + desth - 1 < height);
vl_sfc = surface->privData;
vlPutSurface(vl_sfc, drawable, srcx, srcy, srcw, srch, destx, desty, destw, desth, PictureToVL(flags));
return Success;
}
Status XvMCGetSurfaceStatus(Display *display, XvMCSurface *surface, int *status)
{
struct VL_CONTEXT *vl_ctx;
struct VL_SURFACE *vl_sfc;
assert(display);
if (!surface)
return XvMCBadSurface;
assert(status);
vl_sfc = surface->privData;
vl_ctx = vl_sfc->context;
assert(display == vl_ctx->display);
/* TODO */
*status = 0;
return Success;
}
Status XvMCDestroySurface(Display *display, XvMCSurface *surface)
{
struct VL_CONTEXT *vl_ctx;
struct VL_SURFACE *vl_sfc;
assert(display);
if (!surface)
return XvMCBadSurface;
vl_sfc = surface->privData;
vl_ctx = vl_sfc->context;
assert(display == vl_ctx->display);
vlDestroySurface(vl_sfc);
return Success;
}
Status XvMCHideSurface(Display *display, XvMCSurface *surface)
{
struct VL_CONTEXT *vl_ctx;
struct VL_SURFACE *vl_sfc;
assert(display);
if (!surface)
return XvMCBadSurface;
vl_sfc = surface->privData;
vl_ctx = vl_sfc->context;
assert(display == vl_ctx->display);
/* No op, only for overlaid rendering */
return Success;
}
|