Implement ldap_search* functions.
[wine/multimedia.git] / dlls / quartz / avisplit.c
blobf282dd1c39ff31badfff4196fd291823e4dd13df
1 /*
2 * AVI Splitter Filter
4 * Copyright 2003 Robert Shearman
5 * Copyright 2004-2005 Christian Costa
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library 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 GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* FIXME:
22 * - we don't do anything with indices yet (we could use them when seeking)
23 * - we don't support multiple RIFF sections (i.e. large AVI files > 2Gb)
26 #include "quartz_private.h"
27 #include "control_private.h"
28 #include "pin.h"
30 #include "uuids.h"
31 #include "aviriff.h"
32 #include "mmreg.h"
33 #include "vfwmsgs.h"
34 #include "amvideo.h"
36 #include "fourcc.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 #include <math.h>
42 #include <assert.h>
44 #include "parser.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
48 typedef struct AVISplitterImpl
50 ParserImpl Parser;
51 IMediaSample * pCurrentSample;
52 RIFFCHUNK CurrentChunk;
53 LONGLONG CurrentChunkOffset; /* in media time */
54 LONGLONG EndOfFile;
55 AVIMAINHEADER AviHeader;
56 } AVISplitterImpl;
58 static HRESULT AVISplitter_NextChunk(LONGLONG * pllCurrentChunkOffset, RIFFCHUNK * pCurrentChunk, const REFERENCE_TIME * tStart, const REFERENCE_TIME * tStop, const BYTE * pbSrcStream, int inner)
60 if (inner)
61 *pllCurrentChunkOffset += MEDIATIME_FROM_BYTES(sizeof(RIFFLIST));
62 else
63 *pllCurrentChunkOffset += MEDIATIME_FROM_BYTES(sizeof(RIFFCHUNK) + RIFFROUND(pCurrentChunk->cb));
65 if (*pllCurrentChunkOffset >= *tStop)
66 return S_FALSE; /* no more data - we couldn't even get the next chunk header! */
67 else if (*pllCurrentChunkOffset + MEDIATIME_FROM_BYTES(sizeof(RIFFCHUNK)) >= *tStop)
69 memcpy(pCurrentChunk, pbSrcStream + (DWORD)BYTES_FROM_MEDIATIME(*pllCurrentChunkOffset - *tStart), (DWORD)BYTES_FROM_MEDIATIME(*tStop - *pllCurrentChunkOffset));
70 return S_FALSE; /* no more data */
72 else
73 memcpy(pCurrentChunk, pbSrcStream + (DWORD)BYTES_FROM_MEDIATIME(*pllCurrentChunkOffset - *tStart), sizeof(RIFFCHUNK));
75 return S_OK;
78 static HRESULT AVISplitter_Sample(LPVOID iface, IMediaSample * pSample)
80 AVISplitterImpl *This = (AVISplitterImpl *)iface;
81 LPBYTE pbSrcStream = NULL;
82 long cbSrcStream = 0;
83 REFERENCE_TIME tStart, tStop;
84 HRESULT hr;
85 BOOL bMoreData = TRUE;
87 hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
89 hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
91 cbSrcStream = IMediaSample_GetActualDataLength(pSample);
93 /* trace removed for performance reasons */
94 /* TRACE("(%p)\n", pSample); */
96 assert(BYTES_FROM_MEDIATIME(tStop - tStart) == cbSrcStream);
98 if (This->CurrentChunkOffset <= tStart && This->CurrentChunkOffset + MEDIATIME_FROM_BYTES(sizeof(RIFFCHUNK)) > tStart)
100 DWORD offset = (DWORD)BYTES_FROM_MEDIATIME(tStart - This->CurrentChunkOffset);
101 assert(offset <= sizeof(RIFFCHUNK));
102 memcpy((BYTE *)&This->CurrentChunk + offset, pbSrcStream, sizeof(RIFFCHUNK) - offset);
104 else if (This->CurrentChunkOffset > tStart)
106 DWORD offset = (DWORD)BYTES_FROM_MEDIATIME(This->CurrentChunkOffset - tStart);
107 if (offset >= (DWORD)cbSrcStream)
109 FIXME("large offset\n");
110 hr = S_OK;
111 goto skip;
114 memcpy(&This->CurrentChunk, pbSrcStream + offset, sizeof(RIFFCHUNK));
117 assert(This->CurrentChunkOffset + MEDIATIME_FROM_BYTES(sizeof(RIFFCHUNK)) < tStop);
119 while (bMoreData)
121 BYTE * pbDstStream;
122 long cbDstStream;
123 long chunk_remaining_bytes = 0;
124 long offset_src;
125 WORD streamId;
126 Parser_OutputPin * pOutputPin;
127 BOOL bSyncPoint = TRUE;
129 if (This->CurrentChunkOffset >= tStart)
130 offset_src = (long)BYTES_FROM_MEDIATIME(This->CurrentChunkOffset - tStart) + sizeof(RIFFCHUNK);
131 else
132 offset_src = 0;
134 switch (This->CurrentChunk.fcc)
136 case ckidJUNK:
137 case aviFCC('i','d','x','1'): /* Index is not handled */
138 /* silently ignore */
139 if (S_FALSE == AVISplitter_NextChunk(&This->CurrentChunkOffset, &This->CurrentChunk, &tStart, &tStop, pbSrcStream, FALSE))
140 bMoreData = FALSE;
141 continue;
142 case ckidLIST:
143 /* We only handle the 'rec ' list which contains the stream data */
144 if ((*(DWORD*)(pbSrcStream + BYTES_FROM_MEDIATIME(This->CurrentChunkOffset-tStart) + sizeof(RIFFCHUNK))) == aviFCC('r','e','c',' '))
146 /* FIXME: We only advanced to the first chunk inside the list without keeping track that we are in it.
147 * This is not clean and the parser should be improved for that but it is enough for most AVI files. */
148 if (S_FALSE == AVISplitter_NextChunk(&This->CurrentChunkOffset, &This->CurrentChunk, &tStart, &tStop, pbSrcStream, TRUE))
150 bMoreData = FALSE;
151 continue;
153 This->CurrentChunk = *(RIFFCHUNK*) (pbSrcStream + BYTES_FROM_MEDIATIME(This->CurrentChunkOffset-tStart));
154 offset_src = (long)BYTES_FROM_MEDIATIME(This->CurrentChunkOffset - tStart) + sizeof(RIFFCHUNK);
155 break;
157 else if (S_FALSE == AVISplitter_NextChunk(&This->CurrentChunkOffset, &This->CurrentChunk, &tStart, &tStop, pbSrcStream, FALSE))
158 bMoreData = FALSE;
159 continue;
160 default:
161 break;
162 #if 0 /* According to the AVI specs, a stream data chunk should be ABXX where AB is the stream number and X means don't care */
163 switch (TWOCCFromFOURCC(This->CurrentChunk.fcc))
165 case cktypeDIBcompressed:
166 bSyncPoint = FALSE;
167 /* fall-through */
168 case cktypeDIBbits:
169 /* FIXME: check that pin is of type video */
170 break;
171 case cktypeWAVEbytes:
172 /* FIXME: check that pin is of type audio */
173 break;
174 case cktypePALchange:
175 FIXME("handle palette change\n");
176 break;
177 default:
178 FIXME("Skipping unknown chunk type: %s at file offset 0x%lx\n", debugstr_an((LPSTR)&This->CurrentChunk.fcc, 4), (DWORD)BYTES_FROM_MEDIATIME(This->CurrentChunkOffset));
179 if (S_FALSE == AVISplitter_NextChunk(&This->CurrentChunkOffset, &This->CurrentChunk, &tStart, &tStop, pbSrcStream, FALSE))
180 bMoreData = FALSE;
181 continue;
183 #endif
186 streamId = StreamFromFOURCC(This->CurrentChunk.fcc);
188 if (streamId > This->Parser.cStreams)
190 ERR("Corrupted AVI file (contains stream id %d, but supposed to only have %ld streams)\n", streamId, This->Parser.cStreams);
191 hr = E_FAIL;
192 break;
195 pOutputPin = (Parser_OutputPin *)This->Parser.ppPins[streamId + 1];
197 if (!This->pCurrentSample)
199 /* cache media sample until it is ready to be despatched
200 * (i.e. we reach the end of the chunk) */
201 hr = OutputPin_GetDeliveryBuffer(&pOutputPin->pin, &This->pCurrentSample, NULL, NULL, 0);
203 if (SUCCEEDED(hr))
205 hr = IMediaSample_SetActualDataLength(This->pCurrentSample, 0);
206 assert(hr == S_OK);
208 else
210 TRACE("Skipping sending sample for stream %02d due to error (%lx)\n", streamId, hr);
211 This->pCurrentSample = NULL;
212 if (S_FALSE == AVISplitter_NextChunk(&This->CurrentChunkOffset, &This->CurrentChunk, &tStart, &tStop, pbSrcStream, FALSE))
213 bMoreData = FALSE;
214 continue;
218 hr = IMediaSample_GetPointer(This->pCurrentSample, &pbDstStream);
220 if (SUCCEEDED(hr))
222 cbDstStream = IMediaSample_GetSize(This->pCurrentSample);
224 chunk_remaining_bytes = (long)BYTES_FROM_MEDIATIME(This->CurrentChunkOffset + MEDIATIME_FROM_BYTES(This->CurrentChunk.cb + sizeof(RIFFCHUNK)) - tStart) - offset_src;
226 assert(chunk_remaining_bytes >= 0);
227 assert(chunk_remaining_bytes <= cbDstStream - IMediaSample_GetActualDataLength(This->pCurrentSample));
229 /* trace removed for performance reasons */
230 /* TRACE("chunk_remaining_bytes: 0x%lx, cbSrcStream: 0x%lx, offset_src: 0x%lx\n", chunk_remaining_bytes, cbSrcStream, offset_src); */
233 if (chunk_remaining_bytes <= cbSrcStream - offset_src)
235 if (SUCCEEDED(hr))
237 memcpy(pbDstStream + IMediaSample_GetActualDataLength(This->pCurrentSample), pbSrcStream + offset_src, chunk_remaining_bytes);
238 hr = IMediaSample_SetActualDataLength(This->pCurrentSample, chunk_remaining_bytes + IMediaSample_GetActualDataLength(This->pCurrentSample));
239 assert(hr == S_OK);
242 if (SUCCEEDED(hr))
244 REFERENCE_TIME tAviStart, tAviStop;
246 /* FIXME: hack */
247 if (pOutputPin->dwSamplesProcessed == 0)
248 IMediaSample_SetDiscontinuity(This->pCurrentSample, TRUE);
250 IMediaSample_SetSyncPoint(This->pCurrentSample, bSyncPoint);
252 pOutputPin->dwSamplesProcessed++;
254 if (pOutputPin->dwSampleSize)
255 tAviStart = (LONGLONG)ceil(10000000.0 * (float)(pOutputPin->dwSamplesProcessed - 1) * (float)IMediaSample_GetActualDataLength(This->pCurrentSample) / ((float)pOutputPin->dwSampleSize * pOutputPin->fSamplesPerSec));
256 else
257 tAviStart = (LONGLONG)ceil(10000000.0 * (float)(pOutputPin->dwSamplesProcessed - 1) / (float)pOutputPin->fSamplesPerSec);
258 if (pOutputPin->dwSampleSize)
259 tAviStop = (LONGLONG)ceil(10000000.0 * (float)pOutputPin->dwSamplesProcessed * (float)IMediaSample_GetActualDataLength(This->pCurrentSample) / ((float)pOutputPin->dwSampleSize * pOutputPin->fSamplesPerSec));
260 else
261 tAviStop = (LONGLONG)ceil(10000000.0 * (float)pOutputPin->dwSamplesProcessed / (float)pOutputPin->fSamplesPerSec);
263 IMediaSample_SetTime(This->pCurrentSample, &tAviStart, &tAviStop);
265 hr = OutputPin_SendSample(&pOutputPin->pin, This->pCurrentSample);
266 if (hr != S_OK && hr != VFW_E_NOT_CONNECTED)
267 ERR("Error sending sample (%lx)\n", hr);
270 if (This->pCurrentSample)
271 IMediaSample_Release(This->pCurrentSample);
273 This->pCurrentSample = NULL;
275 if (S_FALSE == AVISplitter_NextChunk(&This->CurrentChunkOffset, &This->CurrentChunk, &tStart, &tStop, pbSrcStream, FALSE))
276 bMoreData = FALSE;
278 else
280 if (SUCCEEDED(hr))
282 memcpy(pbDstStream + IMediaSample_GetActualDataLength(This->pCurrentSample), pbSrcStream + offset_src, cbSrcStream - offset_src);
283 IMediaSample_SetActualDataLength(This->pCurrentSample, cbSrcStream - offset_src + IMediaSample_GetActualDataLength(This->pCurrentSample));
285 bMoreData = FALSE;
289 skip:
290 if (tStop >= This->EndOfFile)
292 int i;
294 TRACE("End of file reached\n");
296 for (i = 0; i < This->Parser.cStreams; i++)
298 IPin* ppin;
299 HRESULT hr;
301 TRACE("Send End Of Stream to output pin %d\n", i);
303 hr = IPin_ConnectedTo(This->Parser.ppPins[i+1], &ppin);
304 if (SUCCEEDED(hr))
306 hr = IPin_EndOfStream(ppin);
307 IPin_Release(ppin);
309 if (FAILED(hr))
311 ERR("%lx\n", hr);
312 break;
316 /* Force the pullpin thread to stop */
317 hr = S_FALSE;
320 return hr;
323 static HRESULT AVISplitter_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
325 if (IsEqualIID(&pmt->majortype, &MEDIATYPE_Stream) && IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_Avi))
326 return S_OK;
327 return S_FALSE;
330 static HRESULT AVISplitter_ProcessStreamList(AVISplitterImpl * This, const BYTE * pData, DWORD cb)
332 PIN_INFO piOutput;
333 const RIFFCHUNK * pChunk;
334 HRESULT hr;
335 AM_MEDIA_TYPE amt;
336 float fSamplesPerSec = 0.0f;
337 DWORD dwSampleSize = 0;
338 DWORD dwLength = 0;
339 ALLOCATOR_PROPERTIES props;
340 static const WCHAR wszStreamTemplate[] = {'S','t','r','e','a','m',' ','%','0','2','d',0};
342 props.cbAlign = 1;
343 props.cbPrefix = 0;
344 props.cbBuffer = 0x20000;
345 props.cBuffers = 2;
347 ZeroMemory(&amt, sizeof(amt));
348 piOutput.dir = PINDIR_OUTPUT;
349 piOutput.pFilter = (IBaseFilter *)This;
350 wsprintfW(piOutput.achName, wszStreamTemplate, This->Parser.cStreams);
352 for (pChunk = (const RIFFCHUNK *)pData;
353 ((const BYTE *)pChunk >= pData) && ((const BYTE *)pChunk + sizeof(RIFFCHUNK) < pData + cb) && (pChunk->cb > 0);
354 pChunk = (const RIFFCHUNK *)((const BYTE*)pChunk + sizeof(RIFFCHUNK) + pChunk->cb)
357 switch (pChunk->fcc)
359 case ckidSTREAMHEADER:
361 const AVISTREAMHEADER * pStrHdr = (const AVISTREAMHEADER *)pChunk;
362 TRACE("processing stream header\n");
364 fSamplesPerSec = (float)pStrHdr->dwRate / (float)pStrHdr->dwScale;
366 switch (pStrHdr->fccType)
368 case streamtypeVIDEO:
369 memcpy(&amt.formattype, &FORMAT_VideoInfo, sizeof(GUID));
370 amt.pbFormat = NULL;
371 amt.cbFormat = 0;
372 break;
373 case streamtypeAUDIO:
374 memcpy(&amt.formattype, &FORMAT_WaveFormatEx, sizeof(GUID));
375 break;
376 default:
377 memcpy(&amt.formattype, &FORMAT_None, sizeof(GUID));
379 memcpy(&amt.majortype, &MEDIATYPE_Video, sizeof(GUID));
380 amt.majortype.Data1 = pStrHdr->fccType;
381 memcpy(&amt.subtype, &MEDIATYPE_Video, sizeof(GUID));
382 amt.subtype.Data1 = pStrHdr->fccHandler;
383 TRACE("Subtype FCC: %.04s\n", (LPCSTR)&pStrHdr->fccHandler);
384 amt.lSampleSize = pStrHdr->dwSampleSize;
385 amt.bFixedSizeSamples = (amt.lSampleSize != 0);
387 /* FIXME: Is this right? */
388 if (!amt.lSampleSize)
390 amt.lSampleSize = 1;
391 dwSampleSize = 1;
394 amt.bTemporalCompression = IsEqualGUID(&amt.majortype, &MEDIATYPE_Video); /* FIXME? */
395 dwSampleSize = pStrHdr->dwSampleSize;
396 dwLength = pStrHdr->dwLength;
397 if (!dwLength)
398 dwLength = This->AviHeader.dwTotalFrames;
400 if (pStrHdr->dwSuggestedBufferSize)
401 props.cbBuffer = pStrHdr->dwSuggestedBufferSize;
403 break;
405 case ckidSTREAMFORMAT:
406 TRACE("processing stream format data\n");
407 if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo))
409 VIDEOINFOHEADER * pvi;
410 /* biCompression member appears to override the value in the stream header.
411 * i.e. the stream header can say something completely contradictory to what
412 * is in the BITMAPINFOHEADER! */
413 if (pChunk->cb < sizeof(BITMAPINFOHEADER))
415 ERR("Not enough bytes for BITMAPINFOHEADER\n");
416 return E_FAIL;
418 amt.cbFormat = sizeof(VIDEOINFOHEADER) - sizeof(BITMAPINFOHEADER) + pChunk->cb;
419 amt.pbFormat = CoTaskMemAlloc(amt.cbFormat);
420 ZeroMemory(amt.pbFormat, amt.cbFormat);
421 pvi = (VIDEOINFOHEADER *)amt.pbFormat;
422 pvi->AvgTimePerFrame = (LONGLONG)(10000000.0 / fSamplesPerSec);
423 CopyMemory(&pvi->bmiHeader, (const BYTE *)(pChunk + 1), pChunk->cb);
424 if (pvi->bmiHeader.biCompression)
425 amt.subtype.Data1 = pvi->bmiHeader.biCompression;
427 else
429 amt.cbFormat = pChunk->cb;
430 amt.pbFormat = CoTaskMemAlloc(amt.cbFormat);
431 CopyMemory(amt.pbFormat, (const BYTE *)(pChunk + 1), amt.cbFormat);
433 break;
434 case ckidSTREAMNAME:
435 TRACE("processing stream name\n");
436 /* FIXME: this doesn't exactly match native version (we omit the "##)" prefix), but hey... */
437 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(pChunk + 1), pChunk->cb, piOutput.achName, sizeof(piOutput.achName) / sizeof(piOutput.achName[0]));
438 break;
439 case ckidSTREAMHANDLERDATA:
440 FIXME("process stream handler data\n");
441 break;
442 case ckidJUNK:
443 TRACE("JUNK chunk ignored\n");
444 break;
445 default:
446 FIXME("unknown chunk type \"%.04s\" ignored\n", (LPCSTR)&pChunk->fcc);
450 if (IsEqualGUID(&amt.formattype, &FORMAT_WaveFormatEx))
452 memcpy(&amt.subtype, &MEDIATYPE_Video, sizeof(GUID));
453 amt.subtype.Data1 = ((WAVEFORMATEX *)amt.pbFormat)->wFormatTag;
456 dump_AM_MEDIA_TYPE(&amt);
457 TRACE("fSamplesPerSec = %f\n", (double)fSamplesPerSec);
458 TRACE("dwSampleSize = %lx\n", dwSampleSize);
459 TRACE("dwLength = %lx\n", dwLength);
461 hr = Parser_AddPin(&(This->Parser), &piOutput, &props, &amt, fSamplesPerSec, dwSampleSize, dwLength);
463 return hr;
466 /* FIXME: fix leaks on failure here */
467 static HRESULT AVISplitter_InputPin_PreConnect(IPin * iface, IPin * pConnectPin)
469 PullPin *This = (PullPin *)iface;
470 HRESULT hr;
471 RIFFLIST list;
472 LONGLONG pos = 0; /* in bytes */
473 BYTE * pBuffer;
474 RIFFCHUNK * pCurrentChunk;
475 AVISplitterImpl * pAviSplit = (AVISplitterImpl *)This->pin.pinInfo.pFilter;
477 hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(list), (BYTE *)&list);
478 pos += sizeof(list);
480 if (list.fcc != ckidRIFF)
482 ERR("Input stream not a RIFF file\n");
483 return E_FAIL;
485 if (list.cb > 1 * 1024 * 1024 * 1024) /* cannot be more than 1Gb in size */
487 ERR("Input stream violates RIFF spec\n");
488 return E_FAIL;
490 if (list.fccListType != ckidAVI)
492 ERR("Input stream not an AVI RIFF file\n");
493 return E_FAIL;
496 hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(list), (BYTE *)&list);
497 if (list.fcc != ckidLIST)
499 ERR("Expected LIST chunk, but got %.04s\n", (LPSTR)&list.fcc);
500 return E_FAIL;
502 if (list.fccListType != ckidHEADERLIST)
504 ERR("Header list expected. Got: %.04s\n", (LPSTR)&list.fccListType);
505 return E_FAIL;
508 pBuffer = HeapAlloc(GetProcessHeap(), 0, list.cb - sizeof(RIFFLIST) + sizeof(RIFFCHUNK));
509 hr = IAsyncReader_SyncRead(This->pReader, pos + sizeof(list), list.cb - sizeof(RIFFLIST) + sizeof(RIFFCHUNK), pBuffer);
511 pAviSplit->AviHeader.cb = 0;
513 for (pCurrentChunk = (RIFFCHUNK *)pBuffer; (BYTE *)pCurrentChunk + sizeof(*pCurrentChunk) < pBuffer + list.cb; pCurrentChunk = (RIFFCHUNK *)(((BYTE *)pCurrentChunk) + sizeof(*pCurrentChunk) + pCurrentChunk->cb))
515 RIFFLIST * pList;
517 switch (pCurrentChunk->fcc)
519 case ckidMAINAVIHEADER:
520 /* AVIMAINHEADER includes the structure that is pCurrentChunk at the moment */
521 memcpy(&pAviSplit->AviHeader, pCurrentChunk, sizeof(pAviSplit->AviHeader));
522 break;
523 case ckidLIST:
524 pList = (RIFFLIST *)pCurrentChunk;
525 switch (pList->fccListType)
527 case ckidSTREAMLIST:
528 hr = AVISplitter_ProcessStreamList(pAviSplit, (BYTE *)pCurrentChunk + sizeof(RIFFLIST), pCurrentChunk->cb + sizeof(RIFFCHUNK) - sizeof(RIFFLIST));
529 break;
530 case ckidODML:
531 FIXME("process ODML header\n");
532 break;
534 break;
535 case ckidJUNK:
536 /* ignore */
537 break;
538 default:
539 FIXME("unrecognised header list type: %.04s\n", (LPSTR)&pCurrentChunk->fcc);
542 HeapFree(GetProcessHeap(), 0, pBuffer);
544 if (pAviSplit->AviHeader.cb != sizeof(pAviSplit->AviHeader) - sizeof(RIFFCHUNK))
546 ERR("Avi Header wrong size!\n");
547 return E_FAIL;
550 pos += sizeof(RIFFCHUNK) + list.cb;
551 hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(list), (BYTE *)&list);
553 if (list.fcc == ckidJUNK)
555 pos += sizeof(RIFFCHUNK) + list.cb;
556 hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(list), (BYTE *)&list);
559 if (list.fcc != ckidLIST)
561 ERR("Expected LIST, but got %.04s\n", (LPSTR)&list.fcc);
562 return E_FAIL;
564 if (list.fccListType != ckidAVIMOVIE)
566 ERR("Expected AVI movie list, but got %.04s\n", (LPSTR)&list.fccListType);
567 return E_FAIL;
570 if (hr == S_OK)
572 pAviSplit->CurrentChunkOffset = MEDIATIME_FROM_BYTES(pos + sizeof(RIFFLIST));
573 pAviSplit->EndOfFile = MEDIATIME_FROM_BYTES(pos + list.cb + sizeof(RIFFLIST));
574 hr = IAsyncReader_SyncRead(This->pReader, BYTES_FROM_MEDIATIME(pAviSplit->CurrentChunkOffset), sizeof(pAviSplit->CurrentChunk), (BYTE *)&pAviSplit->CurrentChunk);
577 if (hr != S_OK)
578 return E_FAIL;
580 TRACE("AVI File ok\n");
582 return hr;
585 HRESULT AVISplitter_create(IUnknown * pUnkOuter, LPVOID * ppv)
587 HRESULT hr;
588 AVISplitterImpl * This;
590 TRACE("(%p, %p)\n", pUnkOuter, ppv);
592 *ppv = NULL;
594 if (pUnkOuter)
595 return CLASS_E_NOAGGREGATION;
597 /* Note: This memory is managed by the transform filter once created */
598 This = CoTaskMemAlloc(sizeof(AVISplitterImpl));
600 This->pCurrentSample = NULL;
602 hr = Parser_Create(&(This->Parser), &CLSID_AviSplitter, AVISplitter_Sample, AVISplitter_QueryAccept, AVISplitter_InputPin_PreConnect);
604 if (FAILED(hr))
605 return hr;
607 *ppv = (LPVOID)This;
609 return hr;