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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
|
/*
* Copyright (c) 2007 Intel Corporation. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <va/va_backend.h>
#include "dummy_drv_video.h"
#include "assert.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#define ASSERT assert
#define INIT_DRIVER_DATA struct dummy_driver_data *driver_data = (struct dummy_driver_data *) ctx->pDriverData;
#define CONFIG(id) ((object_config_p) object_heap_lookup( &driver_data->config_heap, id ))
#define CONTEXT(id) ((object_context_p) object_heap_lookup( &driver_data->context_heap, id ))
#define SURFACE(id) ((object_surface_p) object_heap_lookup( &driver_data->surface_heap, id ))
#define BUFFER(id) ((object_buffer_p) object_heap_lookup( &driver_data->buffer_heap, id ))
#define CONFIG_ID_OFFSET 0x01000000
#define CONTEXT_ID_OFFSET 0x02000000
#define SURFACE_ID_OFFSET 0x04000000
#define BUFFER_ID_OFFSET 0x08000000
static void dummy__error_message(const char *msg, ...)
{
va_list args;
fprintf(stderr, "dummy_drv_video error: ");
va_start(args, msg);
vfprintf(stderr, msg, args);
va_end(args);
}
static void dummy__information_message(const char *msg, ...)
{
va_list args;
fprintf(stderr, "dummy_drv_video: ");
va_start(args, msg);
vfprintf(stderr, msg, args);
va_end(args);
}
VAStatus dummy_QueryConfigProfiles(
VADriverContextP ctx,
VAProfile *profile_list, /* out */
int *num_profiles /* out */
)
{
INIT_DRIVER_DATA
int i = 0;
profile_list[i++] = VAProfileMPEG2Simple;
profile_list[i++] = VAProfileMPEG2Main;
profile_list[i++] = VAProfileMPEG4Simple;
profile_list[i++] = VAProfileMPEG4AdvancedSimple;
profile_list[i++] = VAProfileMPEG4Main;
profile_list[i++] = VAProfileH264Baseline;
profile_list[i++] = VAProfileH264Main;
profile_list[i++] = VAProfileH264High;
profile_list[i++] = VAProfileVC1Simple;
profile_list[i++] = VAProfileVC1Main;
profile_list[i++] = VAProfileVC1Advanced;
/* If the assert fails then DUMMY_MAX_PROFILES needs to be bigger */
ASSERT(i <= DUMMY_MAX_PROFILES);
*num_profiles = i;
return VA_STATUS_SUCCESS;
}
VAStatus dummy_QueryConfigEntrypoints(
VADriverContextP ctx,
VAProfile profile,
VAEntrypoint *entrypoint_list, /* out */
int *num_entrypoints /* out */
)
{
INIT_DRIVER_DATA
switch (profile) {
case VAProfileMPEG2Simple:
case VAProfileMPEG2Main:
*num_entrypoints = 2;
entrypoint_list[0] = VAEntrypointVLD;
entrypoint_list[1] = VAEntrypointMoComp;
break;
case VAProfileMPEG4Simple:
case VAProfileMPEG4AdvancedSimple:
case VAProfileMPEG4Main:
*num_entrypoints = 1;
entrypoint_list[0] = VAEntrypointVLD;
break;
case VAProfileH264Baseline:
case VAProfileH264Main:
case VAProfileH264High:
*num_entrypoints = 1;
entrypoint_list[0] = VAEntrypointVLD;
break;
case VAProfileVC1Simple:
case VAProfileVC1Main:
case VAProfileVC1Advanced:
*num_entrypoints = 1;
entrypoint_list[0] = VAEntrypointVLD;
break;
default:
*num_entrypoints = 0;
break;
}
/* If the assert fails then DUMMY_MAX_ENTRYPOINTS needs to be bigger */
ASSERT(*num_entrypoints <= DUMMY_MAX_ENTRYPOINTS);
return VA_STATUS_SUCCESS;
}
VAStatus dummy_GetConfigAttributes(
VADriverContextP ctx,
VAProfile profile,
VAEntrypoint entrypoint,
VAConfigAttrib *attrib_list, /* in/out */
int num_attribs
)
{
INIT_DRIVER_DATA
int i;
/* Other attributes don't seem to be defined */
/* What to do if we don't know the attribute? */
for (i = 0; i < num_attribs; i++)
{
switch (attrib_list[i].type)
{
case VAConfigAttribRTFormat:
attrib_list[i].value = VA_RT_FORMAT_YUV420;
break;
default:
/* Do nothing */
attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
break;
}
}
return VA_STATUS_SUCCESS;
}
static VAStatus dummy__update_attribute(object_config_p obj_config, VAConfigAttrib *attrib)
{
int i;
/* Check existing attrbiutes */
for(i = 0; obj_config->attrib_count < i; i++)
{
if (obj_config->attrib_list[i].type == attrib->type)
{
/* Update existing attribute */
obj_config->attrib_list[i].value = attrib->value;
return VA_STATUS_SUCCESS;
}
}
if (obj_config->attrib_count < DUMMY_MAX_CONFIG_ATTRIBUTES)
{
i = obj_config->attrib_count;
obj_config->attrib_list[i].type = attrib->type;
obj_config->attrib_list[i].value = attrib->value;
obj_config->attrib_count++;
return VA_STATUS_SUCCESS;
}
return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
}
VAStatus dummy_CreateConfig(
VADriverContextP ctx,
VAProfile profile,
VAEntrypoint entrypoint,
VAConfigAttrib *attrib_list,
int num_attribs,
VAConfigID *config_id /* out */
)
{
INIT_DRIVER_DATA
VAStatus vaStatus;
int configID;
object_config_p obj_config;
int i;
/* Validate profile & entrypoint */
switch (profile) {
case VAProfileMPEG2Simple:
case VAProfileMPEG2Main:
if ((VAEntrypointVLD == entrypoint) ||
(VAEntrypointMoComp == entrypoint))
{
vaStatus = VA_STATUS_SUCCESS;
}
else
{
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
}
break;
case VAProfileMPEG4Simple:
case VAProfileMPEG4AdvancedSimple:
case VAProfileMPEG4Main:
if (VAEntrypointVLD == entrypoint)
{
vaStatus = VA_STATUS_SUCCESS;
}
else
{
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
}
break;
case VAProfileH264Baseline:
case VAProfileH264Main:
case VAProfileH264High:
if (VAEntrypointVLD == entrypoint)
{
vaStatus = VA_STATUS_SUCCESS;
}
else
{
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
}
break;
case VAProfileVC1Simple:
case VAProfileVC1Main:
case VAProfileVC1Advanced:
if (VAEntrypointVLD == entrypoint)
{
vaStatus = VA_STATUS_SUCCESS;
}
else
{
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
}
break;
default:
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
break;
}
if (VA_STATUS_SUCCESS != vaStatus)
{
return vaStatus;
}
configID = object_heap_allocate( &driver_data->config_heap );
obj_config = CONFIG(configID);
if (NULL == obj_config)
{
vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
return vaStatus;
}
obj_config->profile = profile;
obj_config->entrypoint = entrypoint;
obj_config->attrib_list[0].type = VAConfigAttribRTFormat;
obj_config->attrib_list[0].value = VA_RT_FORMAT_YUV420;
obj_config->attrib_count = 1;
for(i = 0; i < num_attribs; i++)
{
vaStatus = dummy__update_attribute(obj_config, &(attrib_list[i]));
if (VA_STATUS_SUCCESS != vaStatus)
{
break;
}
}
/* Error recovery */
if (VA_STATUS_SUCCESS != vaStatus)
{
object_heap_free( &driver_data->config_heap, (object_base_p) obj_config);
}
else
{
*config_id = configID;
}
return vaStatus;
}
VAStatus dummy_DestroyConfig(
VADriverContextP ctx,
VAConfigID config_id
)
{
INIT_DRIVER_DATA
VAStatus vaStatus;
object_config_p obj_config;
obj_config = CONFIG(config_id);
if (NULL == obj_config)
{
vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
return vaStatus;
}
object_heap_free( &driver_data->config_heap, (object_base_p) obj_config);
return VA_STATUS_SUCCESS;
}
VAStatus dummy_QueryConfigAttributes(
VADriverContextP ctx,
VAConfigID config_id,
VAProfile *profile, /* out */
VAEntrypoint *entrypoint, /* out */
VAConfigAttrib *attrib_list, /* out */
int *num_attribs /* out */
)
{
INIT_DRIVER_DATA
VAStatus vaStatus = VA_STATUS_SUCCESS;
object_config_p obj_config;
int i;
obj_config = CONFIG(config_id);
ASSERT(obj_config);
*profile = obj_config->profile;
*entrypoint = obj_config->entrypoint;
*num_attribs = obj_config->attrib_count;
for(i = 0; i < obj_config->attrib_count; i++)
{
attrib_list[i] = obj_config->attrib_list[i];
}
return vaStatus;
}
VAStatus dummy_CreateSurfaces(
VADriverContextP ctx,
int width,
int height,
int format,
int num_surfaces,
VASurfaceID *surfaces /* out */
)
{
INIT_DRIVER_DATA
VAStatus vaStatus = VA_STATUS_SUCCESS;
int i;
/* We only support one format */
if (VA_RT_FORMAT_YUV420 != format)
{
return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
}
for (i = 0; i < num_surfaces; i++)
{
int surfaceID = object_heap_allocate( &driver_data->surface_heap );
object_surface_p obj_surface = SURFACE(surfaceID);
if (NULL == obj_surface)
{
vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
break;
}
obj_surface->surface_id = surfaceID;
surfaces[i] = surfaceID;
}
/* Error recovery */
if (VA_STATUS_SUCCESS != vaStatus)
{
/* surfaces[i-1] was the last successful allocation */
for(; i--; )
{
object_surface_p obj_surface = SURFACE(surfaces[i]);
surfaces[i] = VA_INVALID_SURFACE;
ASSERT(obj_surface);
object_heap_free( &driver_data->surface_heap, (object_base_p) obj_surface);
}
}
return vaStatus;
}
VAStatus dummy_DestroySurfaces(
VADriverContextP ctx,
VASurfaceID *surface_list,
int num_surfaces
)
{
INIT_DRIVER_DATA
int i;
for(i = num_surfaces; i--; )
{
object_surface_p obj_surface = SURFACE(surface_list[i]);
ASSERT(obj_surface);
object_heap_free( &driver_data->surface_heap, (object_base_p) obj_surface);
}
return VA_STATUS_SUCCESS;
}
VAStatus dummy_QueryImageFormats(
VADriverContextP ctx,
VAImageFormat *format_list, /* out */
int *num_formats /* out */
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_CreateImage(
VADriverContextP ctx,
VAImageFormat *format,
int width,
int height,
VAImage *image /* out */
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_DeriveImage(
VADriverContextP ctx,
VASurfaceID surface,
VAImage *image /* out */
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_DestroyImage(
VADriverContextP ctx,
VAImageID image
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_SetImagePalette(
VADriverContextP ctx,
VAImageID image,
unsigned char *palette
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_GetImage(
VADriverContextP ctx,
VASurfaceID surface,
int x, /* coordinates of the upper left source pixel */
int y,
unsigned int width, /* width and height of the region */
unsigned int height,
VAImageID image
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_PutImage(
VADriverContextP ctx,
VASurfaceID surface,
VAImageID image,
int src_x,
int src_y,
unsigned int src_width,
unsigned int src_height,
int dest_x,
int dest_y,
unsigned int dest_width,
unsigned int dest_height
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_QuerySubpictureFormats(
VADriverContextP ctx,
VAImageFormat *format_list, /* out */
unsigned int *flags, /* out */
unsigned int *num_formats /* out */
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_CreateSubpicture(
VADriverContextP ctx,
VAImageID image,
VASubpictureID *subpicture /* out */
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_DestroySubpicture(
VADriverContextP ctx,
VASubpictureID subpicture
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_SetSubpictureImage(
VADriverContextP ctx,
VASubpictureID subpicture,
VAImageID image
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_SetSubpicturePalette(
VADriverContextP ctx,
VASubpictureID subpicture,
/*
* pointer to an array holding the palette data. The size of the array is
* num_palette_entries * entry_bytes in size. The order of the components
* in the palette is described by the component_order in VASubpicture struct
*/
unsigned char *palette
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_SetSubpictureChromakey(
VADriverContextP ctx,
VASubpictureID subpicture,
unsigned int chromakey_min,
unsigned int chromakey_max,
unsigned int chromakey_mask
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_SetSubpictureGlobalAlpha(
VADriverContextP ctx,
VASubpictureID subpicture,
float global_alpha
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_AssociateSubpicture(
VADriverContextP ctx,
VASubpictureID subpicture,
VASurfaceID *target_surfaces,
int num_surfaces,
short src_x, /* upper left offset in subpicture */
short src_y,
unsigned short src_width,
unsigned short src_height,
short dest_x, /* upper left offset in surface */
short dest_y,
unsigned short dest_width,
unsigned short dest_height,
/*
* whether to enable chroma-keying or global-alpha
* see VA_SUBPICTURE_XXX values
*/
unsigned int flags
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_DeassociateSubpicture(
VADriverContextP ctx,
VASubpictureID subpicture,
VASurfaceID *target_surfaces,
int num_surfaces
)
{
INIT_DRIVER_DATA
/* TODO */
return VA_STATUS_SUCCESS;
}
VAStatus dummy_CreateContext(
VADriverContextP ctx,
VAConfigID config_id,
int picture_width,
int picture_height,
int flag,
VASurfaceID *render_targets,
int num_render_targets,
VAContextID *context /* out */
)
{
INIT_DRIVER_DATA
VAStatus vaStatus = VA_STATUS_SUCCESS;
object_config_p obj_config;
int i;
obj_config = CONFIG(config_id);
if (NULL == obj_config)
{
vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
return vaStatus;
}
/* Validate flag */
/* Validate picture dimensions */
int contextID = object_heap_allocate( &driver_data->context_heap );
object_context_p obj_context = CONTEXT(contextID);
if (NULL == obj_context)
{
vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
return vaStatus;
}
obj_context->context_id = contextID;
*context = contextID;
obj_context->current_render_target = -1;
obj_context->config_id = config_id;
obj_context->picture_width = picture_width;
obj_context->picture_height = picture_height;
obj_context->num_render_targets = num_render_targets;
obj_context->render_targets = (VASurfaceID *) malloc(num_render_targets * sizeof(VASurfaceID));
if (obj_context->render_targets == NULL)
{
vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
return vaStatus;
}
for(i = 0; i < num_render_targets; i++)
{
if (NULL == SURFACE(render_targets[i]))
{
vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
break;
}
obj_context->render_targets[i] = render_targets[i];
}
obj_context->flags = flag;
/* Error recovery */
if (VA_STATUS_SUCCESS != vaStatus)
{
obj_context->context_id = -1;
obj_context->config_id = -1;
free(obj_context->render_targets);
obj_context->render_targets = NULL;
obj_context->num_render_targets = 0;
obj_context->flags = 0;
object_heap_free( &driver_data->context_heap, (object_base_p) obj_context);
}
return vaStatus;
}
VAStatus dummy_DestroyContext(
VADriverContextP ctx,
VAContextID context
)
{
INIT_DRIVER_DATA
object_context_p obj_context = CONTEXT(context);
ASSERT(obj_context);
obj_context->context_id = -1;
obj_context->config_id = -1;
obj_context->picture_width = 0;
obj_context->picture_height = 0;
if (obj_context->render_targets)
{
free(obj_context->render_targets);
}
obj_context->render_targets = NULL;
obj_context->num_render_targets = 0;
obj_context->flags = 0;
obj_context->current_render_target = -1;
object_heap_free( &driver_data->context_heap, (object_base_p) obj_context);
return VA_STATUS_SUCCESS;
}
static VAStatus dummy__allocate_buffer(object_buffer_p obj_buffer, int size)
{
VAStatus vaStatus = VA_STATUS_SUCCESS;
obj_buffer->buffer_data = realloc(obj_buffer->buffer_data, size);
if (NULL == obj_buffer->buffer_data)
{
vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
}
return vaStatus;
}
VAStatus dummy_CreateBuffer(
VADriverContextP ctx,
VAContextID context, /* in */
VABufferType type, /* in */
unsigned int size, /* in */
unsigned int num_elements, /* in */
void *data, /* in */
VABufferID *buf_id /* out */
)
{
INIT_DRIVER_DATA
VAStatus vaStatus = VA_STATUS_SUCCESS;
int bufferID;
object_buffer_p obj_buffer;
/* Validate type */
switch (type)
{
case VAPictureParameterBufferType:
case VAIQMatrixBufferType:
case VABitPlaneBufferType:
case VASliceGroupMapBufferType:
case VASliceParameterBufferType:
case VASliceDataBufferType:
case VAMacroblockParameterBufferType:
case VAResidualDataBufferType:
case VADeblockingParameterBufferType:
case VAImageBufferType:
/* Ok */
break;
default:
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
return vaStatus;
}
bufferID = object_heap_allocate( &driver_data->buffer_heap );
obj_buffer = BUFFER(bufferID);
if (NULL == obj_buffer)
{
vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
return vaStatus;
}
obj_buffer->buffer_data = NULL;
vaStatus = dummy__allocate_buffer(obj_buffer, size * num_elements);
if (VA_STATUS_SUCCESS == vaStatus)
{
obj_buffer->max_num_elements = num_elements;
obj_buffer->num_elements = num_elements;
if (data)
{
memcpy(obj_buffer->buffer_data, data, size * num_elements);
}
}
if (VA_STATUS_SUCCESS == vaStatus)
{
*buf_id = bufferID;
}
return vaStatus;
}
VAStatus dummy_BufferSetNumElements(
VADriverContextP ctx,
VABufferID buf_id, /* in */
unsigned int num_elements /* in */
)
{
INIT_DRIVER_DATA
VAStatus vaStatus = VA_STATUS_SUCCESS;
object_buffer_p obj_buffer = BUFFER(buf_id);
ASSERT(obj_buffer);
if ((num_elements < 0) || (num_elements > obj_buffer->max_num_elements))
{
vaStatus = VA_STATUS_ERROR_UNKNOWN;
}
if (VA_STATUS_SUCCESS == vaStatus)
{
obj_buffer->num_elements = num_elements;
}
return vaStatus;
}
VAStatus dummy_MapBuffer(
VADriverContextP ctx,
VABufferID buf_id, /* in */
void **pbuf /* out */
)
{
INIT_DRIVER_DATA
VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
object_buffer_p obj_buffer = BUFFER(buf_id);
ASSERT(obj_buffer);
if (NULL == obj_buffer)
{
vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
return vaStatus;
}
if (NULL != obj_buffer->buffer_data)
{
*pbuf = obj_buffer->buffer_data;
vaStatus = VA_STATUS_SUCCESS;
}
return vaStatus;
}
VAStatus dummy_UnmapBuffer(
VADriverContextP ctx,
VABufferID buf_id /* in */
)
{
/* Do nothing */
return VA_STATUS_SUCCESS;
}
static void dummy__destroy_buffer(struct dummy_driver_data *driver_data, object_buffer_p obj_buffer)
{
if (NULL != obj_buffer->buffer_data)
{
free(obj_buffer->buffer_data);
obj_buffer->buffer_data = NULL;
}
object_heap_free( &driver_data->buffer_heap, (object_base_p) obj_buffer);
}
VAStatus dummy_DestroyBuffer(
VADriverContextP ctx,
VABufferID buffer_id
)
{
INIT_DRIVER_DATA
object_buffer_p obj_buffer = BUFFER(buffer_id);
ASSERT(obj_buffer);
dummy__destroy_buffer(driver_data, obj_buffer);
return VA_STATUS_SUCCESS;
}
VAStatus dummy_BeginPicture(
VADriverContextP ctx,
VAContextID context,
VASurfaceID render_target
)
{
INIT_DRIVER_DATA
VAStatus vaStatus = VA_STATUS_SUCCESS;
object_context_p obj_context;
object_surface_p obj_surface;
obj_context = CONTEXT(context);
ASSERT(obj_context);
obj_surface = SURFACE(render_target);
ASSERT(obj_surface);
obj_context->current_render_target = obj_surface->base.id;
return vaStatus;
}
VAStatus dummy_RenderPicture(
VADriverContextP ctx,
VAContextID context,
VABufferID *buffers,
int num_buffers
)
{
INIT_DRIVER_DATA
VAStatus vaStatus = VA_STATUS_SUCCESS;
object_context_p obj_context;
object_surface_p obj_surface;
int i;
obj_context = CONTEXT(context);
ASSERT(obj_context);
obj_surface = SURFACE(obj_context->current_render_target);
ASSERT(obj_surface);
/* verify that we got valid buffer references */
for(i = 0; i < num_buffers; i++)
{
object_buffer_p obj_buffer = BUFFER(buffers[i]);
ASSERT(obj_buffer);
if (NULL == obj_buffer)
{
vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
break;
}
}
/* Release buffers */
for(i = 0; i < num_buffers; i++)
{
object_buffer_p obj_buffer = BUFFER(buffers[i]);
ASSERT(obj_buffer);
dummy__destroy_buffer(driver_data, obj_buffer);
}
return vaStatus;
}
VAStatus dummy_EndPicture(
VADriverContextP ctx,
VAContextID context
)
{
INIT_DRIVER_DATA
VAStatus vaStatus = VA_STATUS_SUCCESS;
object_context_p obj_context;
object_surface_p obj_surface;
obj_context = CONTEXT(context);
ASSERT(obj_context);
obj_surface = SURFACE(obj_context->current_render_target);
ASSERT(obj_surface);
// For now, assume that we are done with rendering right away
obj_context->current_render_target = -1;
return vaStatus;
}
VAStatus dummy_SyncSurface(
VADriverContextP ctx,
VASurfaceID render_target
)
{
INIT_DRIVER_DATA
VAStatus vaStatus = VA_STATUS_SUCCESS;
object_surface_p obj_surface;
obj_surface = SURFACE(render_target);
ASSERT(obj_surface);
return vaStatus;
}
VAStatus dummy_QuerySurfaceStatus(
VADriverContextP ctx,
VASurfaceID render_target,
VASurfaceStatus *status /* out */
)
{
INIT_DRIVER_DATA
VAStatus vaStatus = VA_STATUS_SUCCESS;
object_surface_p obj_surface;
obj_surface = SURFACE(render_target);
ASSERT(obj_surface);
*status = VASurfaceReady;
return vaStatus;
}
VAStatus dummy_PutSurface(
VADriverContextP ctx,
VASurfaceID surface,
Drawable draw, /* X Drawable */
short srcx,
short srcy,
unsigned short srcw,
unsigned short srch,
short destx,
short desty,
unsigned short destw,
unsigned short desth,
VARectangle *cliprects, /* client supplied clip list */
unsigned int number_cliprects, /* number of clip rects in the clip list */
unsigned int flags /* de-interlacing flags */
)
{
/* TODO */
return VA_STATUS_ERROR_UNKNOWN;
}
/*
* Query display attributes
* The caller must provide a "attr_list" array that can hold at
* least vaMaxNumDisplayAttributes() entries. The actual number of attributes
* returned in "attr_list" is returned in "num_attributes".
*/
VAStatus dummy_QueryDisplayAttributes (
VADriverContextP ctx,
VADisplayAttribute *attr_list, /* out */
int *num_attributes /* out */
)
{
/* TODO */
return VA_STATUS_ERROR_UNKNOWN;
}
/*
* Get display attributes
* This function returns the current attribute values in "attr_list".
* Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
* from vaQueryDisplayAttributes() can have their values retrieved.
*/
VAStatus dummy_GetDisplayAttributes (
VADriverContextP ctx,
VADisplayAttribute *attr_list, /* in/out */
int num_attributes
)
{
/* TODO */
return VA_STATUS_ERROR_UNKNOWN;
}
/*
* Set display attributes
* Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
* from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
* the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
*/
VAStatus dummy_SetDisplayAttributes (
VADriverContextP ctx,
VADisplayAttribute *attr_list,
int num_attributes
)
{
/* TODO */
return VA_STATUS_ERROR_UNKNOWN;
}
VAStatus dummy_CopySurfaceToBuffer(
VADriverContextP ctx,
VASurfaceID surface,
unsigned int *fourcc, /* following are output argument */
unsigned int *luma_stride,
unsigned int *chroma_u_stride,
unsigned int *chroma_v_stride,
unsigned int *luma_offset,
unsigned int *chroma_u_offset,
unsigned int *chroma_v_offset,
void **buffer
)
{
/* TODO */
return VA_STATUS_ERROR_UNKNOWN;
}
VAStatus dummy_Terminate( VADriverContextP ctx )
{
INIT_DRIVER_DATA
object_buffer_p obj_buffer;
object_surface_p obj_surface;
object_context_p obj_context;
object_config_p obj_config;
object_heap_iterator iter;
/* Clean up left over buffers */
obj_buffer = (object_buffer_p) object_heap_first( &driver_data->buffer_heap, &iter);
while (obj_buffer)
{
dummy__information_message("vaTerminate: bufferID %08x still allocated, destroying\n", obj_buffer->base.id);
dummy__destroy_buffer(driver_data, obj_buffer);
obj_buffer = (object_buffer_p) object_heap_next( &driver_data->buffer_heap, &iter);
}
object_heap_destroy( &driver_data->buffer_heap );
/* TODO cleanup */
object_heap_destroy( &driver_data->surface_heap );
/* TODO cleanup */
object_heap_destroy( &driver_data->context_heap );
/* Clean up configIDs */
obj_config = (object_config_p) object_heap_first( &driver_data->config_heap, &iter);
while (obj_config)
{
object_heap_free( &driver_data->config_heap, (object_base_p) obj_config);
obj_config = (object_config_p) object_heap_next( &driver_data->config_heap, &iter);
}
object_heap_destroy( &driver_data->config_heap );
free(ctx->pDriverData);
ctx->pDriverData = NULL;
return VA_STATUS_SUCCESS;
}
VAStatus __vaDriverInit_0_31( VADriverContextP ctx )
{
object_base_p obj;
int result;
struct dummy_driver_data *driver_data;
int i;
ctx->version_major = VA_MAJOR_VERSION;
ctx->version_minor = VA_MINOR_VERSION;
ctx->max_profiles = DUMMY_MAX_PROFILES;
ctx->max_entrypoints = DUMMY_MAX_ENTRYPOINTS;
ctx->max_attributes = DUMMY_MAX_CONFIG_ATTRIBUTES;
ctx->max_image_formats = DUMMY_MAX_IMAGE_FORMATS;
ctx->max_subpic_formats = DUMMY_MAX_SUBPIC_FORMATS;
ctx->max_display_attributes = DUMMY_MAX_DISPLAY_ATTRIBUTES;
ctx->str_vendor = DUMMY_STR_VENDOR;
ctx->vtable.vaTerminate = dummy_Terminate;
ctx->vtable.vaQueryConfigEntrypoints = dummy_QueryConfigEntrypoints;
ctx->vtable.vaQueryConfigProfiles = dummy_QueryConfigProfiles;
ctx->vtable.vaQueryConfigEntrypoints = dummy_QueryConfigEntrypoints;
ctx->vtable.vaQueryConfigAttributes = dummy_QueryConfigAttributes;
ctx->vtable.vaCreateConfig = dummy_CreateConfig;
ctx->vtable.vaDestroyConfig = dummy_DestroyConfig;
ctx->vtable.vaGetConfigAttributes = dummy_GetConfigAttributes;
ctx->vtable.vaCreateSurfaces = dummy_CreateSurfaces;
ctx->vtable.vaDestroySurfaces = dummy_DestroySurfaces;
ctx->vtable.vaCreateContext = dummy_CreateContext;
ctx->vtable.vaDestroyContext = dummy_DestroyContext;
ctx->vtable.vaCreateBuffer = dummy_CreateBuffer;
ctx->vtable.vaBufferSetNumElements = dummy_BufferSetNumElements;
ctx->vtable.vaMapBuffer = dummy_MapBuffer;
ctx->vtable.vaUnmapBuffer = dummy_UnmapBuffer;
ctx->vtable.vaDestroyBuffer = dummy_DestroyBuffer;
ctx->vtable.vaBeginPicture = dummy_BeginPicture;
ctx->vtable.vaRenderPicture = dummy_RenderPicture;
ctx->vtable.vaEndPicture = dummy_EndPicture;
ctx->vtable.vaSyncSurface = dummy_SyncSurface;
ctx->vtable.vaQuerySurfaceStatus = dummy_QuerySurfaceStatus;
ctx->vtable.vaPutSurface = dummy_PutSurface;
ctx->vtable.vaQueryImageFormats = dummy_QueryImageFormats;
ctx->vtable.vaCreateImage = dummy_CreateImage;
ctx->vtable.vaDeriveImage = dummy_DeriveImage;
ctx->vtable.vaDestroyImage = dummy_DestroyImage;
ctx->vtable.vaSetImagePalette = dummy_SetImagePalette;
ctx->vtable.vaGetImage = dummy_GetImage;
ctx->vtable.vaPutImage = dummy_PutImage;
ctx->vtable.vaQuerySubpictureFormats = dummy_QuerySubpictureFormats;
ctx->vtable.vaCreateSubpicture = dummy_CreateSubpicture;
ctx->vtable.vaDestroySubpicture = dummy_DestroySubpicture;
ctx->vtable.vaSetSubpictureImage = dummy_SetSubpictureImage;
ctx->vtable.vaSetSubpictureChromakey = dummy_SetSubpictureChromakey;
ctx->vtable.vaSetSubpictureGlobalAlpha = dummy_SetSubpictureGlobalAlpha;
ctx->vtable.vaAssociateSubpicture = dummy_AssociateSubpicture;
ctx->vtable.vaDeassociateSubpicture = dummy_DeassociateSubpicture;
ctx->vtable.vaQueryDisplayAttributes = dummy_QueryDisplayAttributes;
ctx->vtable.vaGetDisplayAttributes = dummy_GetDisplayAttributes;
ctx->vtable.vaSetDisplayAttributes = dummy_SetDisplayAttributes;
ctx->vtable.vaCopySurfaceToBuffer = dummy_CopySurfaceToBuffer;
driver_data = (struct dummy_driver_data *) malloc( sizeof(*driver_data) );
ctx->pDriverData = (void *) driver_data;
result = object_heap_init( &driver_data->config_heap, sizeof(struct object_config), CONFIG_ID_OFFSET );
ASSERT( result == 0 );
result = object_heap_init( &driver_data->context_heap, sizeof(struct object_context), CONTEXT_ID_OFFSET );
ASSERT( result == 0 );
result = object_heap_init( &driver_data->surface_heap, sizeof(struct object_surface), SURFACE_ID_OFFSET );
ASSERT( result == 0 );
result = object_heap_init( &driver_data->buffer_heap, sizeof(struct object_buffer), BUFFER_ID_OFFSET );
ASSERT( result == 0 );
return VA_STATUS_SUCCESS;
}
|