dwrite: Always initialize output glyph count in GetGlyphs().
[wine.git] / dlls / wineqtdecoder / qtdatahandler.c
blob30b5161427607af9088e0cd2b53e2cc6e002f3ab
1 /*
2 * QuickTime Data Handler
4 * Copyright 2011 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #define ULONG CoreFoundation_ULONG
24 #define HRESULT CoreFoundation_HRESULT
26 #define LoadResource __carbon_LoadResource
27 #define CompareString __carbon_CompareString
28 #define GetCurrentThread __carbon_GetCurrentThread
29 #define GetCurrentProcess __carbon_GetCurrentProcess
30 #define AnimatePalette __carbon_AnimatePalette
31 #define EqualRgn __carbon_EqualRgn
32 #define FillRgn __carbon_FillRgn
33 #define FrameRgn __carbon_FrameRgn
34 #define GetPixel __carbon_GetPixel
35 #define InvertRgn __carbon_InvertRgn
36 #define LineTo __carbon_LineTo
37 #define OffsetRgn __carbon_OffsetRgn
38 #define PaintRgn __carbon_PaintRgn
39 #define Polygon __carbon_Polygon
40 #define ResizePalette __carbon_ResizePalette
41 #define SetRectRgn __carbon_SetRectRgn
43 #define CheckMenuItem __carbon_CheckMenuItem
44 #define DeleteMenu __carbon_DeleteMenu
45 #define DrawMenuBar __carbon_DrawMenuBar
46 #define EnableMenuItem __carbon_EnableMenuItem
47 #define EqualRect __carbon_EqualRect
48 #define FillRect __carbon_FillRect
49 #define FrameRect __carbon_FrameRect
50 #define GetCursor __carbon_GetCursor
51 #define GetMenu __carbon_GetMenu
52 #define InvertRect __carbon_InvertRect
53 #define IsWindowVisible __carbon_IsWindowVisible
54 #define MoveWindow __carbon_MoveWindow
55 #define OffsetRect __carbon_OffsetRect
56 #define PtInRect __carbon_PtInRect
57 #define SetCursor __carbon_SetCursor
58 #define SetRect __carbon_SetRect
59 #define ShowCursor __carbon_ShowCursor
60 #define ShowWindow __carbon_ShowWindow
61 #define UnionRect __carbon_UnionRect
63 #include <QuickTime/QuickTimeComponents.h>
65 #undef LoadResource
66 #undef CompareString
67 #undef GetCurrentThread
68 #undef _CDECL
69 #undef GetCurrentProcess
70 #undef AnimatePalette
71 #undef EqualRgn
72 #undef FillRgn
73 #undef FrameRgn
74 #undef GetPixel
75 #undef InvertRgn
76 #undef LineTo
77 #undef OffsetRgn
78 #undef PaintRgn
79 #undef Polygon
80 #undef ResizePalette
81 #undef SetRectRgn
82 #undef CheckMenuItem
83 #undef DeleteMenu
84 #undef DrawMenuBar
85 #undef EnableMenuItem
86 #undef EqualRect
87 #undef FillRect
88 #undef FrameRect
89 #undef GetCursor
90 #undef GetMenu
91 #undef InvertRect
92 #undef IsWindowVisible
93 #undef MoveWindow
94 #undef OffsetRect
95 #undef PtInRect
96 #undef SetCursor
97 #undef SetRect
98 #undef ShowCursor
99 #undef ShowWindow
100 #undef UnionRect
102 #undef ULONG
103 #undef HRESULT
104 #undef STDMETHODCALLTYPE
106 #include <assert.h>
107 #include <stdio.h>
108 #include <stdarg.h>
110 #define NONAMELESSSTRUCT
111 #define NONAMELESSUNION
112 #define COBJMACROS
114 #include "windef.h"
115 #include "winbase.h"
116 #include "wtypes.h"
117 #include "winuser.h"
118 #include "dshow.h"
120 #include "wine/unicode.h"
121 #include "wine/debug.h"
123 #include "qtprivate.h"
125 WINE_DEFAULT_DEBUG_CHANNEL(qtdatahandler);
127 static ComponentDescription myType =
129 'dhlr',
130 'WINE',
131 'WINE',
136 typedef struct DHData
138 WineDataRefRecord dataRef;
140 Ptr AsyncPtr;
141 long AsyncRefCon;
142 DataHCompletionUPP AsyncCompletionRtn;
143 } DHData;
145 static pascal ComponentResult myComponentRoutineProc ( ComponentParameters *
146 cp, Handle componentStorage);
148 void RegisterWineDataHandler( void )
150 ComponentRoutineUPP MyComponentRoutineUPP;
152 MyComponentRoutineUPP = NewComponentRoutineUPP(&myComponentRoutineProc);
153 RegisterComponent( &myType , MyComponentRoutineUPP, 0, NULL, NULL, NULL);
156 static pascal ComponentResult myDataHCanUseDataRef ( DataHandler dh,
157 Handle dataRef,
158 long *useFlags
161 WineDataRefRecord *record = (WineDataRefRecord*)(*dataRef);
162 TRACE("%p %p %p\n",dh,dataRef,useFlags);
163 if (record->pReader == NULL)
164 return badComponentSelector;
165 *useFlags = kDataHCanRead;
166 return noErr;
169 static pascal ComponentResult myDataHSetDataRef ( DataHandler dh, Handle dataRef)
171 Handle storage = GetComponentInstanceStorage(dh);
172 DHData *data = (DHData*)*storage;
173 WineDataRefRecord* newRef = (WineDataRefRecord*)(*dataRef);
174 TRACE("\n");
175 if (newRef->pReader != data->dataRef.pReader)
176 IAsyncReader_AddRef(newRef->pReader);
177 data->dataRef = *newRef;
178 return noErr;
181 static pascal ComponentResult myDataHGetAvailableFileSize ( DataHandler dh,
182 long *fileSize)
184 Handle storage = GetComponentInstanceStorage(dh);
185 DHData *data = (DHData*)*storage;
186 LONGLONG total;
187 LONGLONG available;
189 TRACE("%p\n",dh);
191 IAsyncReader_Length(data->dataRef.pReader,&total,&available);
192 *fileSize = available;
193 return noErr;
196 static pascal ComponentResult myDataHGetFileSize ( DataHandler dh, long *fileSize)
198 Handle storage = GetComponentInstanceStorage(dh);
199 DHData *data = (DHData*)*storage;
200 LONGLONG total;
201 LONGLONG available;
203 TRACE("%p\n",dh);
205 IAsyncReader_Length(data->dataRef.pReader,&total,&available);
206 *fileSize = total;
207 return noErr;
210 static pascal ComponentResult myDataHScheduleData ( DataHandler dh,
211 Ptr PlaceToPutDataPtr,
212 long FileOffset,
213 long DataSize,
214 long RefCon,
215 DataHSchedulePtr scheduleRec,
216 DataHCompletionUPP CompletionRtn)
218 Handle storage = GetComponentInstanceStorage(dh);
219 DHData *data = (DHData*)*storage;
220 HRESULT hr;
221 LONGLONG offset = FileOffset;
222 BYTE* buffer = (BYTE*)PlaceToPutDataPtr;
224 TRACE("%p %p %li %li %li %p %p\n",dh, PlaceToPutDataPtr, FileOffset, DataSize, RefCon, scheduleRec, CompletionRtn);
226 hr = IAsyncReader_SyncRead(data->dataRef.pReader, offset, DataSize, buffer);
227 TRACE("result %x\n",hr);
228 if (CompletionRtn)
230 if (data->AsyncCompletionRtn)
231 InvokeDataHCompletionUPP(data->AsyncPtr, data->AsyncRefCon, noErr, data->AsyncCompletionRtn);
233 data->AsyncPtr = PlaceToPutDataPtr;
234 data->AsyncRefCon = RefCon;
235 data->AsyncCompletionRtn = CompletionRtn;
238 return noErr;
241 static pascal ComponentResult myDataHFinishData (DataHandler dh, Ptr PlaceToPutDataPtr, Boolean Cancel)
243 Handle storage = GetComponentInstanceStorage(dh);
244 DHData *data = (DHData*)*storage;
245 if (!data->AsyncCompletionRtn)
246 return noErr;
247 if (!PlaceToPutDataPtr || PlaceToPutDataPtr == data->AsyncPtr)
249 if (!Cancel)
250 InvokeDataHCompletionUPP(data->AsyncPtr, data->AsyncRefCon, noErr, data->AsyncCompletionRtn);
251 data->AsyncPtr = NULL;
252 data->AsyncRefCon = 0;
253 data->AsyncCompletionRtn = NULL;
255 return noErr;
258 static pascal ComponentResult myDataHGetData ( DataHandler dh,
259 Handle h,
260 long hOffset,
261 long offset,
262 long size)
264 Handle storage = GetComponentInstanceStorage(dh);
265 DHData *data = (DHData*)*storage;
266 BYTE *target = (BYTE*)*h;
267 LONGLONG off = offset;
268 HRESULT hr;
270 TRACE("%p %p %li %li %li\n",dh, h, hOffset, offset, size);
271 hr = IAsyncReader_SyncRead(data->dataRef.pReader, off, size, target+hOffset);
272 TRACE("result %x\n",hr);
274 return noErr;
277 static pascal ComponentResult myDataHCompareDataRef ( DataHandler dh,
278 Handle dataRef, Boolean *equal)
280 WineDataRefRecord *ptr1;
281 Handle storage = GetComponentInstanceStorage(dh);
282 DHData *data = (DHData*)*storage;
283 TRACE("\n");
285 ptr1 = (WineDataRefRecord*)dataRef;
287 *equal = (ptr1->pReader == data->dataRef.pReader);
288 return noErr;
291 static pascal ComponentResult myDataHGetDataRef ( DataHandler dh, Handle *dataRef)
293 Handle storage = GetComponentInstanceStorage(dh);
294 TRACE("\n");
295 *dataRef = storage;
296 HandToHand(dataRef);
297 return noErr;
300 static pascal ComponentResult myDataHGetScheduleAheadTime ( DataHandler dh,
301 long *millisecs)
303 TRACE("\n");
304 *millisecs = 1000;
305 return noErr;
308 static pascal ComponentResult myDataHGetInfoFlags ( DataHandler dh, UInt32 *flags)
310 TRACE("\n");
311 *flags = 0;
312 return noErr;
315 static pascal ComponentResult myDataHGetFileTypeOrdering ( DataHandler dh,
316 DataHFileTypeOrderingHandle *orderingListHandle)
318 OSType orderlist[1] = {kDataHFileTypeExtension};
319 TRACE("\n");
320 PtrToHand( &orderlist, (Handle*)orderingListHandle, sizeof(OSType));
321 return noErr;
324 typedef struct {
325 const char *const fname;
326 const int sig_length;
327 const BYTE sig[10];
328 } signature;
330 static const signature stream_sigs[] = {
331 {"video.asf",4,{0x30,0x26,0xb2,0x75}},
332 {"video.mov",8,{0x00,0x00,0x00,0x14,0x66,0x74,0x79,0x70}},
333 {"video.mp4",8,{0x00,0x00,0x00,0x18,0x66,0x74,0x79,0x70}},
334 {"video.m4v",8,{0x00,0x00,0x00,0x1c,0x66,0x74,0x79,0x70}},
335 {"video.flv",4,{0x46,0x4C,0x56,0x01}},
336 {"video.mpg",3,{0x00,0x00,0x01}},
337 {"avideo.rm",4,{0x2E,0x52,0x4D,0x46}}
340 static pascal ComponentResult myDataHGetFileName ( DataHandler dh, Str255 str)
342 Handle storage = GetComponentInstanceStorage(dh);
343 DHData *data = (DHData*)*storage;
344 TRACE("%p %s\n",str,debugstr_guid(&data->dataRef.streamSubtype));
346 /* Todo Expand this list */
347 if (IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_MPEG1Video) ||
348 IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_MPEG1System))
349 CFStringGetPascalString(CFSTR("video.mpg"),str,256,kCFStringEncodingMacRoman);
350 else if(IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_Asf))
351 CFStringGetPascalString(CFSTR("video.asf"),str,256,kCFStringEncodingMacRoman);
352 else if(IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_Avi))
353 CFStringGetPascalString(CFSTR("video.avi"),str,256,kCFStringEncodingMacRoman);
354 else if(IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_QTMovie))
355 CFStringGetPascalString(CFSTR("video.mov"),str,256,kCFStringEncodingMacRoman);
356 else
358 BYTE header[10] = {0,0,0,0,0,0,0,0,0,0};
359 int i;
360 IAsyncReader_SyncRead(data->dataRef.pReader, 0, 8, header);
362 for (i = 0; i < ARRAY_SIZE(stream_sigs); i++)
363 if (memcmp(header, stream_sigs[i].sig, stream_sigs[i].sig_length)==0)
365 str[0] = strlen(stream_sigs[i].fname);
366 memcpy(str + 1, stream_sigs[i].fname, str[0]);
367 return noErr;
370 return badComponentSelector;
373 return noErr;
376 static pascal ComponentResult myDataHOpenForRead(DataHandler dh)
378 TRACE("\n");
379 return noErr;
382 static pascal ComponentResult myDataHTask(DataHandler dh)
384 Handle storage = GetComponentInstanceStorage(dh);
385 DHData *data = (DHData*)*storage;
387 if (data->AsyncCompletionRtn)
389 TRACE("Sending Completion\n");
390 InvokeDataHCompletionUPP(data->AsyncPtr, data->AsyncRefCon, noErr, data->AsyncCompletionRtn);
391 data->AsyncPtr = NULL;
392 data->AsyncRefCon = 0;
393 data->AsyncCompletionRtn = NULL;
395 return noErr;
398 static pascal ComponentResult myDataHPlaybackHints(DataHandler dh, long flags,
399 unsigned long minFileOffset, unsigned long maxFileOffset,
400 long bytesPerSecond)
402 TRACE("%lu %lu %li\n",minFileOffset, maxFileOffset, bytesPerSecond);
403 return noErr;
406 static pascal ComponentResult myDataHPlaybackHints64(DataHandler dh, long flags,
407 wide *minFileOffset, wide *maxFileOffset,
408 long bytesPerSecond)
410 if (TRACE_ON(qtdatahandler))
412 SInt64 minFileOffset64 = WideToSInt64(*minFileOffset);
413 LONGLONG minFileOffsetLL = minFileOffset64;
414 SInt64 maxFileOffset64 = WideToSInt64(*maxFileOffset);
415 LONGLONG maxFileOffsetLL = maxFileOffset64;
417 TRACE("%s %s %li\n",wine_dbgstr_longlong(minFileOffsetLL), wine_dbgstr_longlong(maxFileOffsetLL), bytesPerSecond);
419 return noErr;
422 static pascal ComponentResult myDataHGetFileSize64(DataHandler dh, wide * fileSize)
424 Handle storage = GetComponentInstanceStorage(dh);
425 DHData *data = (DHData*)*storage;
426 LONGLONG total;
427 LONGLONG available;
428 SInt64 total64;
430 TRACE("%p\n",dh);
432 IAsyncReader_Length(data->dataRef.pReader,&total,&available);
433 total64 = total;
434 *fileSize = SInt64ToWide(total64);
435 return noErr;
438 static pascal ComponentResult myDataHGetFileSizeAsync ( DataHandler dh, wide *fileSize, DataHCompletionUPP CompletionRtn, long RefCon )
440 Handle storage = GetComponentInstanceStorage(dh);
441 DHData *data = (DHData*)*storage;
442 LONGLONG total;
443 LONGLONG available;
444 SInt64 total64;
446 TRACE("%p\n",dh);
448 IAsyncReader_Length(data->dataRef.pReader,&total,&available);
449 total64 = total;
450 *fileSize = SInt64ToWide(total64);
452 if (CompletionRtn)
454 if (data->AsyncCompletionRtn)
455 InvokeDataHCompletionUPP(data->AsyncPtr, data->AsyncRefCon, noErr, data->AsyncCompletionRtn);
457 data->AsyncPtr = (Ptr)fileSize;
458 data->AsyncRefCon = RefCon;
459 data->AsyncCompletionRtn = CompletionRtn;
462 return noErr;
465 static pascal ComponentResult myDataHGetAvailableFileSize64(DataHandler dh, wide * fileSize)
467 Handle storage = GetComponentInstanceStorage(dh);
468 DHData *data = (DHData*)*storage;
469 LONGLONG total;
470 LONGLONG available;
471 SInt64 total64;
473 TRACE("%p\n",dh);
475 IAsyncReader_Length(data->dataRef.pReader,&total,&available);
476 total64 = available;
477 *fileSize = SInt64ToWide(total64);
478 return noErr;
481 static pascal ComponentResult myDataHScheduleData64( DataHandler dh,
482 Ptr PlaceToPutDataPtr,
483 const wide * FileOffset,
484 long DataSize,
485 long RefCon,
486 DataHSchedulePtr scheduleRec,
487 DataHCompletionUPP CompletionRtn)
489 Handle storage = GetComponentInstanceStorage(dh);
490 DHData *data = (DHData*)*storage;
491 HRESULT hr;
492 SInt64 fileOffset64 = WideToSInt64(*FileOffset);
493 LONGLONG offset = fileOffset64;
494 BYTE* buffer = (BYTE*)PlaceToPutDataPtr;
496 TRACE("%p %p %s %li %li %p %p\n",dh, PlaceToPutDataPtr, wine_dbgstr_longlong(offset), DataSize, RefCon, scheduleRec, CompletionRtn);
498 hr = IAsyncReader_SyncRead(data->dataRef.pReader, offset, DataSize, buffer);
499 TRACE("result %x\n",hr);
500 if (CompletionRtn)
502 if (data->AsyncCompletionRtn)
503 InvokeDataHCompletionUPP(data->AsyncPtr, data->AsyncRefCon, noErr, data->AsyncCompletionRtn);
505 data->AsyncPtr = PlaceToPutDataPtr;
506 data->AsyncRefCon = RefCon;
507 data->AsyncCompletionRtn = CompletionRtn;
510 return noErr;
513 static const struct { LPVOID proc; ProcInfoType type;} componentFunctions[] =
515 {NULL, 0}, /* 0 */
516 {NULL, 0}, /* 1 */
517 {myDataHGetData, kPascalStackBased
518 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
519 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
520 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
521 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))
522 | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
523 | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(long)))
524 }, /* kDataHGetDataSelect */
525 {NULL, 0}, /* kDataHPutDataSelect */
526 {NULL, 0}, /* kDataHFlushDataSelect */
527 {NULL, 0}, /* kDataHOpenForWriteSelect */
528 {NULL, 0}, /* kDataHCloseForWriteSelect */
529 {NULL, 0}, /* 7 */
530 {myDataHOpenForRead, kPascalStackBased
531 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
532 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
533 }, /* kDataHOpenForReadSelect
535 {NULL, 0}, /* kDataHCloseForReadSelect */
536 {myDataHSetDataRef, kPascalStackBased
537 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
538 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
539 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
540 }, /* kDataHSetDataRefSelect */
541 {myDataHGetDataRef, kPascalStackBased
542 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
543 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
544 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
545 }, /* kDataHGetDataRefSelect */
546 {myDataHCompareDataRef, kPascalStackBased
547 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
548 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
549 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
550 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Boolean*)))
551 }, /* kDataHCompareDataRefSelect */
552 {myDataHTask, kPascalStackBased
553 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
554 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
555 }, /* kDataHTaskSelect */
556 {myDataHScheduleData, kPascalStackBased
557 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
558 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
559 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Ptr)))
560 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))
561 | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
562 | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(long)))
563 | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(DataHSchedulePtr)))
564 | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(DataHCompletionUPP)))
565 }, /* kDataHScheduleDataSelect */
566 {myDataHFinishData, kPascalStackBased
567 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
568 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
569 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Ptr)))
570 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Boolean)))
571 }, /* kDataHFinishDataSelect */
572 {NULL, 0}, /* kDataHFlushCacheSelect 0x10 */
573 {NULL, 0}, /* kDataHResolveDataRefSelect */
574 {myDataHGetFileSize, kPascalStackBased
575 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
576 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
577 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long*)))
578 }, /* kDataHGetFileSizeSelect */
579 {myDataHCanUseDataRef, kPascalStackBased
580 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
581 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
582 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
583 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long*)))
584 }, /* kDataHCanUseDataRefSelect */
585 {NULL, 0}, /* kDataHGetVolumeListSelect */
586 {NULL, 0}, /* kDataHWriteSelect */
587 {NULL, 0}, /* kDataHPreextendSelect */
588 {NULL, 0}, /* kDataHSetFileSizeSelect */
589 {NULL, 0}, /* kDataHGetFreeSpaceSelect */
590 {NULL, 0}, /* kDataHCreateFileSelect */
591 {NULL, 0}, /* kDataHGetPreferredBlockSizeSelect */
592 {NULL, 0}, /* kDataHGetDeviceIndexSelect */
593 {NULL, 0}, /* kDataHIsStreamingDataHandlerSelect */
594 {NULL, 0}, /* kDataHGetDataInBufferSelect */
595 {myDataHGetScheduleAheadTime, kPascalStackBased
596 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
597 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
598 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long*)))
599 }, /* kDataHGetScheduleAheadTimeSelect */
600 /* End of Required List */
601 {NULL, 0}, /* kDataHSetCacheSizeLimitSelect */
602 {NULL, 0}, /* kDataHGetCacheSizeLimitSelect 0x20 */
603 {NULL, 0}, /* kDataHGetMovieSelect */
604 {NULL, 0}, /* kDataHAddMovieSelect */
605 {NULL, 0}, /* kDataHUpdateMovieSelect */
606 {NULL, 0}, /* kDataHDoesBufferSelect */
607 {myDataHGetFileName, kPascalStackBased
608 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
609 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
610 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Str255*)))
611 }, /* kDataHGetFileNameSelect */
612 {myDataHGetAvailableFileSize, kPascalStackBased
613 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
614 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
615 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long*)))
616 }, /* kDataHGetAvailableFileSizeSelect */
617 {NULL, 0}, /* kDataHGetMacOSFileTypeSelect */
618 {NULL, 0}, /* kDataHGetMIMETypeSelect */
619 {NULL, 0}, /* kDataHSetDataRefWithAnchorSelect */
620 {NULL, 0}, /* kDataHGetDataRefWithAnchorSelect */
621 {NULL, 0}, /* kDataHSetMacOSFileTypeSelect */
622 {NULL, 0}, /* kDataHSetTimeBaseSelect */
623 {myDataHGetInfoFlags, kPascalStackBased
624 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
625 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
626 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(UInt32*)))
627 }, /* kDataHGetInfoFlagsSelect */
628 {myDataHScheduleData64, kPascalStackBased
629 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
630 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
631 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Ptr)))
632 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(wide*)))
633 | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
634 | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(long)))
635 | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(DataHSchedulePtr)))
636 | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(DataHCompletionUPP)))
637 }, /* kDataHScheduleData64Select */
638 {NULL, 0}, /* kDataHWrite64Select */
639 {myDataHGetFileSize64, kPascalStackBased
640 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
641 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
642 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(wide*)))
643 }, /* kDataHGetFileSize64Select 0x30 */
644 {NULL, 0}, /* kDataHPreextend64Select */
645 {NULL, 0}, /* kDataHSetFileSize64Select */
646 {NULL, 0}, /* kDataHGetFreeSpace64Select */
647 {NULL, 0}, /* kDataHAppend64Select */
648 {NULL, 0}, /* kDataHReadAsyncSelect */
649 {NULL, 0}, /* kDataHPollReadSelect */
650 {NULL, 0}, /* kDataHGetDataAvailabilitySelect */
651 {NULL, 0}, /* 0x0038 */
652 {NULL, 0}, /* 0x0039 */
653 {myDataHGetFileSizeAsync, kPascalStackBased
654 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
655 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
656 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(wide*)))
657 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(DataHCompletionUPP)))
658 | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
659 }, /* kDataHGetFileSizeAsyncSelect */
660 {NULL, 0}, /* kDataHGetDataRefAsTypeSelect */
661 {NULL, 0}, /* kDataHSetDataRefExtensionSelect */
662 {NULL, 0}, /* kDataHGetDataRefExtensionSelect */
663 {NULL, 0}, /* kDataHGetMovieWithFlagsSelect */
664 {NULL, 0}, /* 0x3F */
665 {myDataHGetFileTypeOrdering, kPascalStackBased
666 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
667 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
668 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DataHFileTypeOrderingHandle*)))
669 }, /* kDataHGetFileTypeOrderingSelect 0x40 */
670 {NULL, 0}, /* kDataHCreateFileWithFlagsSelect */
671 {NULL, 0}, /* kDataHGetMIMETypeAsyncSelect */
672 {NULL, 0}, /* kDataHGetInfoSelect */
673 {NULL, 0}, /* kDataHSetIdleManagerSelect */
674 {NULL, 0}, /* kDataHDeleteFileSelect */
675 {NULL, 0}, /* kDataHSetMovieUsageFlagsSelect */
676 {NULL, 0}, /* kDataHUseTemporaryDataRefSelect */
677 {NULL, 0}, /* kDataHGetTemporaryDataRefCapabilitiesSelect */
678 {NULL, 0}, /* kDataHRenameFileSelect */
679 {NULL, 0}, /* 0x4A */
680 {NULL, 0}, /* 0x4B */
681 {NULL, 0}, /* 0x4C */
682 {NULL, 0}, /* 0x4D */
683 {myDataHGetAvailableFileSize64, kPascalStackBased
684 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
685 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
686 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(wide*)))
687 }, /* kDataHGetAvailableFileSize64Select */
688 {NULL, 0}, /* kDataHGetDataAvailability64Select */
691 static const struct { LPVOID proc; ProcInfoType type;} componentFunctions_2[] =
693 {myDataHPlaybackHints, kPascalStackBased
694 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
695 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
696 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long)))
697 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(unsigned long)))
698 | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(unsigned long)))
699 | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(long)))
700 }, /* kDataHPlaybackHintsSelect 0x103 */
701 {myDataHPlaybackHints64, kPascalStackBased
702 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
703 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
704 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long)))
705 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(wide*)))
706 | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(wide*)))
707 | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(long)))
708 }, /* kDataHPlaybackHints64Select 0x10E */
709 {NULL, 0}, /* kDataHGetDataRateSelect 0x110 */
710 {NULL, 0}, /* kDataHSetTimeHintsSelect 0x111 */
713 /* Component Functions */
715 static pascal ComponentResult myComponentOpen(ComponentInstance ci, ComponentInstance self)
717 DHData myData;
718 Handle storage;
720 ZeroMemory(&myData,sizeof(DHData));
721 PtrToHand( &myData, &storage, sizeof(DHData));
722 SetComponentInstanceStorage(self,storage);
724 return noErr;
727 static pascal ComponentResult myComponentClose(ComponentInstance ci, ComponentInstance self)
729 Handle storage = GetComponentInstanceStorage(self);
730 DHData *data;
731 if (storage)
733 data = (DHData*)*storage;
734 if (data && data->dataRef.pReader != NULL)
735 IAsyncReader_Release(data->dataRef.pReader);
736 DisposeHandle(storage);
737 SetComponentInstanceStorage(self,NULL);
739 return noErr;
742 static pascal ComponentResult myComponentCanDo(ComponentInstance ci, SInt16 ftnNumber)
744 TRACE("test 0x%x\n",ftnNumber);
745 if (ftnNumber <= kComponentOpenSelect && ftnNumber >= kComponentCanDoSelect)
746 return TRUE;
747 if (ftnNumber == kDataHPlaybackHintsSelect)
748 return TRUE;
749 if (ftnNumber == kDataHPlaybackHints64Select)
750 return TRUE;
751 if (ftnNumber > kDataHGetDataAvailability64Select)
752 return FALSE;
753 TRACE("impl? %i\n",(componentFunctions[ftnNumber].proc != NULL));
754 return (componentFunctions[ftnNumber].proc != NULL);
757 /* Main Proc */
759 static ComponentResult callOurFunction(LPVOID proc, ProcInfoType type, ComponentParameters * cp)
761 ComponentRoutineUPP myUUP;
762 ComponentResult result;
764 myUUP = NewComponentFunctionUPP(proc, type);
765 result = CallComponentFunction(cp, myUUP);
766 DisposeComponentFunctionUPP(myUUP);
767 return result;
770 static pascal ComponentResult myComponentRoutineProc ( ComponentParameters * cp,
771 Handle componentStorage)
773 switch (cp->what)
775 case kComponentOpenSelect:
776 return callOurFunction(myComponentOpen, uppCallComponentOpenProcInfo, cp);
777 case kComponentCloseSelect:
778 return callOurFunction(myComponentClose, uppCallComponentOpenProcInfo, cp);
779 case kComponentCanDoSelect:
780 return callOurFunction(myComponentCanDo, uppCallComponentCanDoProcInfo, cp);
781 case kDataHPlaybackHintsSelect:
782 return callOurFunction(componentFunctions_2[0].proc, componentFunctions_2[0].type, cp);
783 case kDataHPlaybackHints64Select:
784 return callOurFunction(componentFunctions_2[1].proc, componentFunctions_2[1].type, cp);
787 if (cp->what > 0 && cp->what <=kDataHGetDataAvailability64Select && componentFunctions[cp->what].proc)
788 return callOurFunction(componentFunctions[cp->what].proc, componentFunctions[cp->what].type, cp);
790 FIXME("unhandled select 0x%x\n",cp->what);
791 return badComponentSelector;