vbscript: Handle index read access to array properties.
[wine.git] / dlls / mfplat / mfplat_private.h
blob8418c8eb2ef81b9237f2c98af4edf0165aa648e0
1 /*
2 * Copyright 2019 Nikolay Sivov for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define NONAMELESSUNION
21 #undef INITGUID
22 #include <guiddef.h>
23 #include "mfapi.h"
24 #include "mfidl.h"
25 #include "mferror.h"
26 #include "d3d9types.h"
28 #include "wine/debug.h"
30 struct attribute
32 GUID key;
33 PROPVARIANT value;
36 struct attributes
38 IMFAttributes IMFAttributes_iface;
39 LONG ref;
40 CRITICAL_SECTION cs;
41 struct attribute *attributes;
42 size_t capacity;
43 size_t count;
46 extern HRESULT init_attributes_object(struct attributes *object, UINT32 size) DECLSPEC_HIDDEN;
47 extern void clear_attributes_object(struct attributes *object) DECLSPEC_HIDDEN;
48 extern const char *debugstr_attr(const GUID *guid) DECLSPEC_HIDDEN;
49 extern const char *debugstr_mf_guid(const GUID *guid) DECLSPEC_HIDDEN;
51 extern HRESULT attributes_GetItem(struct attributes *object, REFGUID key, PROPVARIANT *value) DECLSPEC_HIDDEN;
52 extern HRESULT attributes_GetItemType(struct attributes *object, REFGUID key, MF_ATTRIBUTE_TYPE *type) DECLSPEC_HIDDEN;
53 extern HRESULT attributes_CompareItem(struct attributes *object, REFGUID key, REFPROPVARIANT value,
54 BOOL *result) DECLSPEC_HIDDEN;
55 extern HRESULT attributes_Compare(struct attributes *object, IMFAttributes *theirs,
56 MF_ATTRIBUTES_MATCH_TYPE match_type, BOOL *ret) DECLSPEC_HIDDEN;
57 extern HRESULT attributes_GetUINT32(struct attributes *object, REFGUID key, UINT32 *value) DECLSPEC_HIDDEN;
58 extern HRESULT attributes_GetUINT64(struct attributes *object, REFGUID key, UINT64 *value) DECLSPEC_HIDDEN;
59 extern HRESULT attributes_GetDouble(struct attributes *object, REFGUID key, double *value) DECLSPEC_HIDDEN;
60 extern HRESULT attributes_GetGUID(struct attributes *object, REFGUID key, GUID *value) DECLSPEC_HIDDEN;
61 extern HRESULT attributes_GetStringLength(struct attributes *object, REFGUID key, UINT32 *length) DECLSPEC_HIDDEN;
62 extern HRESULT attributes_GetString(struct attributes *object, REFGUID key, WCHAR *value, UINT32 size,
63 UINT32 *length) DECLSPEC_HIDDEN;
64 extern HRESULT attributes_GetAllocatedString(struct attributes *object, REFGUID key, WCHAR **value,
65 UINT32 *length) DECLSPEC_HIDDEN;
66 extern HRESULT attributes_GetBlobSize(struct attributes *object, REFGUID key, UINT32 *size) DECLSPEC_HIDDEN;
67 extern HRESULT attributes_GetBlob(struct attributes *object, REFGUID key, UINT8 *buf, UINT32 bufsize,
68 UINT32 *blobsize) DECLSPEC_HIDDEN;
69 extern HRESULT attributes_GetAllocatedBlob(struct attributes *object, REFGUID key, UINT8 **buf,
70 UINT32 *size) DECLSPEC_HIDDEN;
71 extern HRESULT attributes_GetUnknown(struct attributes *object, REFGUID key, REFIID riid, void **out) DECLSPEC_HIDDEN;
72 extern HRESULT attributes_SetItem(struct attributes *object, REFGUID key, REFPROPVARIANT value) DECLSPEC_HIDDEN;
73 extern HRESULT attributes_DeleteItem(struct attributes *object, REFGUID key) DECLSPEC_HIDDEN;
74 extern HRESULT attributes_DeleteAllItems(struct attributes *object) DECLSPEC_HIDDEN;
75 extern HRESULT attributes_SetUINT32(struct attributes *object, REFGUID key, UINT32 value) DECLSPEC_HIDDEN;
76 extern HRESULT attributes_SetUINT64(struct attributes *object, REFGUID key, UINT64 value) DECLSPEC_HIDDEN;
77 extern HRESULT attributes_SetDouble(struct attributes *object, REFGUID key, double value) DECLSPEC_HIDDEN;
78 extern HRESULT attributes_SetGUID(struct attributes *object, REFGUID key, REFGUID value) DECLSPEC_HIDDEN;
79 extern HRESULT attributes_SetString(struct attributes *object, REFGUID key, const WCHAR *value) DECLSPEC_HIDDEN;
80 extern HRESULT attributes_SetBlob(struct attributes *object, REFGUID key, const UINT8 *buf,
81 UINT32 size) DECLSPEC_HIDDEN;
82 extern HRESULT attributes_SetUnknown(struct attributes *object, REFGUID key, IUnknown *unknown) DECLSPEC_HIDDEN;
83 extern HRESULT attributes_LockStore(struct attributes *object) DECLSPEC_HIDDEN;
84 extern HRESULT attributes_UnlockStore(struct attributes *object) DECLSPEC_HIDDEN;
85 extern HRESULT attributes_GetCount(struct attributes *object, UINT32 *items) DECLSPEC_HIDDEN;
86 extern HRESULT attributes_GetItemByIndex(struct attributes *object, UINT32 index, GUID *key,
87 PROPVARIANT *value) DECLSPEC_HIDDEN;
88 extern HRESULT attributes_CopyAllItems(struct attributes *object, IMFAttributes *dest) DECLSPEC_HIDDEN;
90 static inline BOOL mf_array_reserve(void **elements, size_t *capacity, size_t count, size_t size)
92 size_t new_capacity, max_capacity;
93 void *new_elements;
95 if (count <= *capacity)
96 return TRUE;
98 max_capacity = ~(SIZE_T)0 / size;
99 if (count > max_capacity)
100 return FALSE;
102 new_capacity = max(4, *capacity);
103 while (new_capacity < count && new_capacity <= max_capacity / 2)
104 new_capacity *= 2;
105 if (new_capacity < count)
106 new_capacity = max_capacity;
108 if (!(new_elements = realloc(*elements, new_capacity * size)))
109 return FALSE;
111 *elements = new_elements;
112 *capacity = new_capacity;
114 return TRUE;
117 extern unsigned int mf_format_get_stride(const GUID *subtype, unsigned int width, BOOL *is_yuv) DECLSPEC_HIDDEN;
119 static inline const char *debugstr_propvar(const PROPVARIANT *v)
121 if (!v)
122 return "(null)";
124 switch (v->vt)
126 case VT_EMPTY:
127 return wine_dbg_sprintf("%p {VT_EMPTY}", v);
128 case VT_NULL:
129 return wine_dbg_sprintf("%p {VT_NULL}", v);
130 case VT_UI4:
131 return wine_dbg_sprintf("%p {VT_UI4: %ld}", v, v->ulVal);
132 case VT_UI8:
133 return wine_dbg_sprintf("%p {VT_UI8: %s}", v, wine_dbgstr_longlong(v->uhVal.QuadPart));
134 case VT_I8:
135 return wine_dbg_sprintf("%p {VT_I8: %s}", v, wine_dbgstr_longlong(v->hVal.QuadPart));
136 case VT_R4:
137 return wine_dbg_sprintf("%p {VT_R4: %.8e}", v, v->fltVal);
138 case VT_R8:
139 return wine_dbg_sprintf("%p {VT_R8: %lf}", v, v->dblVal);
140 case VT_CLSID:
141 return wine_dbg_sprintf("%p {VT_CLSID: %s}", v, debugstr_mf_guid(v->puuid));
142 case VT_LPWSTR:
143 return wine_dbg_sprintf("%p {VT_LPWSTR: %s}", v, wine_dbgstr_w(v->pwszVal));
144 case VT_VECTOR | VT_UI1:
145 return wine_dbg_sprintf("%p {VT_VECTOR|VT_UI1: %p}", v, v->caub.pElems);
146 case VT_UNKNOWN:
147 return wine_dbg_sprintf("%p {VT_UNKNOWN: %p}", v, v->punkVal);
148 default:
149 return wine_dbg_sprintf("%p {vt %#x}", v, v->vt);
153 static inline const char *debugstr_fourcc(DWORD format)
155 static const struct format_name
157 unsigned int format;
158 const char *name;
159 } formats[] =
161 { D3DFMT_R8G8B8, "R8G8B8" },
162 { D3DFMT_A8R8G8B8, "A8R8G8B8" },
163 { D3DFMT_X8R8G8B8, "X8R8G8B8" },
164 { D3DFMT_R5G6B5, "R5G6B5" },
165 { D3DFMT_X1R5G5B5, "X1R5G6B5" },
166 { D3DFMT_A2B10G10R10, "A2B10G10R10" },
167 { D3DFMT_P8, "P8" },
168 { D3DFMT_L8, "L8" },
169 { D3DFMT_D16, "D16" },
170 { D3DFMT_L16, "L16" },
171 { D3DFMT_A16B16G16R16F, "A16B16G16R16F" },
173 int i;
175 if ((format & 0xff) == format)
177 for (i = 0; i < ARRAY_SIZE(formats); ++i)
179 if (formats[i].format == format)
180 return wine_dbg_sprintf("%s", wine_dbgstr_an(formats[i].name, -1));
183 return wine_dbg_sprintf("%#lx", format);
186 return wine_dbgstr_an((char *)&format, 4);
189 static inline const char *debugstr_time(LONGLONG time)
191 ULONGLONG abstime = time >= 0 ? time : -time;
192 unsigned int i = 0, j = 0;
193 char buffer[23], rev[23];
195 while (abstime || i <= 8)
197 buffer[i++] = '0' + (abstime % 10);
198 abstime /= 10;
199 if (i == 7) buffer[i++] = '.';
201 if (time < 0) buffer[i++] = '-';
203 while (i--) rev[j++] = buffer[i];
204 while (rev[j-1] == '0' && rev[j-2] != '.') --j;
205 rev[j] = 0;
207 return wine_dbg_sprintf("%s", rev);