2 * Copyright 2002 Michael Günnewig
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #define COM_NO_WINDOWS_H
31 #include "avifile_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(avifile
);
37 /***********************************************************************/
39 static HRESULT WINAPI
ACMStream_fnQueryInterface(IAVIStream
*iface
,REFIID refiid
,LPVOID
*obj
);
40 static ULONG WINAPI
ACMStream_fnAddRef(IAVIStream
*iface
);
41 static ULONG WINAPI
ACMStream_fnRelease(IAVIStream
* iface
);
42 static HRESULT WINAPI
ACMStream_fnCreate(IAVIStream
*iface
,LPARAM lParam1
,LPARAM lParam2
);
43 static HRESULT WINAPI
ACMStream_fnInfo(IAVIStream
*iface
,AVISTREAMINFOW
*psi
,LONG size
);
44 static LONG WINAPI
ACMStream_fnFindSample(IAVIStream
*iface
,LONG pos
,LONG flags
);
45 static HRESULT WINAPI
ACMStream_fnReadFormat(IAVIStream
*iface
,LONG pos
,LPVOID format
,LONG
*formatsize
);
46 static HRESULT WINAPI
ACMStream_fnSetFormat(IAVIStream
*iface
,LONG pos
,LPVOID format
,LONG formatsize
);
47 static HRESULT WINAPI
ACMStream_fnRead(IAVIStream
*iface
,LONG start
,LONG samples
,LPVOID buffer
,LONG buffersize
,LONG
*bytesread
,LONG
*samplesread
);
48 static HRESULT WINAPI
ACMStream_fnWrite(IAVIStream
*iface
,LONG start
,LONG samples
,LPVOID buffer
,LONG buffersize
,DWORD flags
,LONG
*sampwritten
,LONG
*byteswritten
);
49 static HRESULT WINAPI
ACMStream_fnDelete(IAVIStream
*iface
,LONG start
,LONG samples
);
50 static HRESULT WINAPI
ACMStream_fnReadData(IAVIStream
*iface
,DWORD fcc
,LPVOID lp
,LONG
*lpread
);
51 static HRESULT WINAPI
ACMStream_fnWriteData(IAVIStream
*iface
,DWORD fcc
,LPVOID lp
,LONG size
);
52 static HRESULT WINAPI
ACMStream_fnSetInfo(IAVIStream
*iface
,AVISTREAMINFOW
*info
,LONG infolen
);
54 struct ICOM_VTABLE(IAVIStream
) iacmst
= {
55 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
56 ACMStream_fnQueryInterface
,
61 ACMStream_fnFindSample
,
62 ACMStream_fnReadFormat
,
63 ACMStream_fnSetFormat
,
68 ACMStream_fnWriteData
,
72 typedef struct _IAVIStreamImpl
{
74 ICOM_VFIELD(IAVIStream
);
77 /* IAVIStream stuff */
83 LPWAVEFORMATEX lpInFormat
;
86 LPWAVEFORMATEX lpOutFormat
;
89 ACMSTREAMHEADER acmStreamHdr
;
92 /***********************************************************************/
94 #define CONVERT_STREAM_to_THIS(a) { \
95 acmStreamSize(This->has,(a)*This->lpInFormat->nBlockAlign,\
96 &(a), ACM_STREAMSIZEF_SOURCE); \
97 (a) /= This->lpOutFormat->nBlockAlign; }
98 #define CONVERT_THIS_to_STREAM(a) { \
99 acmStreamSize(This->has,(a)*This->lpOutFormat->nBlockAlign,\
100 &(a), ACM_STREAMSIZEF_DESTINATION); \
101 (a) /= This->lpInFormat->nBlockAlign; }
103 static HRESULT
AVIFILE_OpenCompressor(IAVIStreamImpl
*This
);
105 HRESULT
AVIFILE_CreateACMStream(REFIID riid
, LPVOID
*ppv
)
107 IAVIStreamImpl
*pstream
;
110 assert(riid
!= NULL
&& ppv
!= NULL
);
114 pstream
= (IAVIStreamImpl
*)LocalAlloc(LPTR
, sizeof(IAVIStreamImpl
));
116 return AVIERR_MEMORY
;
118 pstream
->lpVtbl
= &iacmst
;
120 hr
= IUnknown_QueryInterface((IUnknown
*)pstream
, riid
, ppv
);
122 LocalFree((HLOCAL
)pstream
);
127 static HRESULT WINAPI
ACMStream_fnQueryInterface(IAVIStream
*iface
,
128 REFIID refiid
, LPVOID
*obj
)
130 ICOM_THIS(IAVIStreamImpl
,iface
);
132 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(refiid
), obj
);
134 if (IsEqualGUID(&IID_IUnknown
, refiid
) ||
135 IsEqualGUID(&IID_IAVIStream
, refiid
)) {
137 IAVIStream_AddRef(iface
);
142 return OLE_E_ENUM_NOMORE
;
145 static ULONG WINAPI
ACMStream_fnAddRef(IAVIStream
*iface
)
147 ICOM_THIS(IAVIStreamImpl
,iface
);
149 TRACE("(%p) -> %ld\n", iface
, This
->ref
+ 1);
151 /* also add reference to the nested stream */
152 if (This
->pStream
!= NULL
)
153 IAVIStream_AddRef(This
->pStream
);
155 return ++(This
->ref
);
158 static ULONG WINAPI
ACMStream_fnRelease(IAVIStream
* iface
)
160 ICOM_THIS(IAVIStreamImpl
,iface
);
162 TRACE("(%p) -> %ld\n", iface
, This
->ref
- 1);
164 if (This
->ref
== 0) {
166 if (This
->has
!= NULL
) {
167 if (This
->acmStreamHdr
.fdwStatus
& ACMSTREAMHEADER_STATUSF_PREPARED
)
168 acmStreamUnprepareHeader(This
->has
, &This
->acmStreamHdr
, 0);
169 acmStreamClose(This
->has
, 0);
172 if (This
->acmStreamHdr
.pbSrc
!= NULL
) {
173 GlobalFreePtr(This
->acmStreamHdr
.pbSrc
);
174 This
->acmStreamHdr
.pbSrc
= NULL
;
176 if (This
->acmStreamHdr
.pbDst
!= NULL
) {
177 GlobalFreePtr(This
->acmStreamHdr
.pbDst
);
178 This
->acmStreamHdr
.pbDst
= NULL
;
180 if (This
->lpInFormat
!= NULL
) {
181 GlobalFreePtr(This
->lpInFormat
);
182 This
->lpInFormat
= NULL
;
183 This
->cbInFormat
= 0;
185 if (This
->lpOutFormat
!= NULL
) {
186 GlobalFreePtr(This
->lpOutFormat
);
187 This
->lpOutFormat
= NULL
;
188 This
->cbOutFormat
= 0;
190 if (This
->pStream
!= NULL
) {
191 IAVIStream_Release(This
->pStream
);
192 This
->pStream
= NULL
;
194 LocalFree((HLOCAL
)This
);
199 /* also release reference to the nested stream */
200 if (This
->pStream
!= NULL
)
201 IAVIStream_Release(This
->pStream
);
206 /* lParam1: PAVISTREAM
207 * lParam2: LPAVICOMPRESSOPTIONS -- even if doc's say LPWAVEFORMAT
209 static HRESULT WINAPI
ACMStream_fnCreate(IAVIStream
*iface
, LPARAM lParam1
,
212 ICOM_THIS(IAVIStreamImpl
,iface
);
214 TRACE("(%p,0x%08lX,0x%08lX)\n", iface
, lParam1
, lParam2
);
216 /* check for swapped parameters */
217 if ((LPVOID
)lParam1
!= NULL
&&
218 ((LPAVICOMPRESSOPTIONS
)lParam1
)->fccType
== streamtypeAUDIO
) {
219 register LPARAM tmp
= lParam1
;
225 if ((LPVOID
)lParam1
== NULL
)
226 return AVIERR_BADPARAM
;
228 IAVIStream_Info((PAVISTREAM
)lParam1
, &This
->sInfo
, sizeof(This
->sInfo
));
229 if (This
->sInfo
.fccType
!= streamtypeAUDIO
)
230 return AVIERR_ERROR
; /* error in registry or AVIMakeCompressedStream */
232 This
->sInfo
.fccHandler
= 0; /* be paranoid */
234 /* FIXME: check ACM version? Which version does we need? */
236 if ((LPVOID
)lParam2
!= NULL
) {
237 /* We only need the format from the compress-options */
238 if (((LPAVICOMPRESSOPTIONS
)lParam2
)->fccType
== streamtypeAUDIO
)
239 lParam2
= (LPARAM
)((LPAVICOMPRESSOPTIONS
)lParam2
)->lpFormat
;
241 if (((LPWAVEFORMATEX
)lParam2
)->wFormatTag
!= WAVE_FORMAT_PCM
)
242 This
->cbOutFormat
= sizeof(WAVEFORMATEX
) + ((LPWAVEFORMATEX
)lParam2
)->cbSize
;
244 This
->cbOutFormat
= sizeof(PCMWAVEFORMAT
);
246 This
->lpOutFormat
= (LPWAVEFORMATEX
)GlobalAllocPtr(GHND
, This
->cbOutFormat
);
247 if (This
->lpOutFormat
== NULL
)
248 return AVIERR_MEMORY
;
250 memcpy(This
->lpOutFormat
, (LPVOID
)lParam2
, This
->cbOutFormat
);
252 This
->lpOutFormat
= NULL
;
253 This
->cbOutFormat
= 0;
256 This
->pStream
= (PAVISTREAM
)lParam1
;
257 IAVIStream_AddRef(This
->pStream
);
262 static HRESULT WINAPI
ACMStream_fnInfo(IAVIStream
*iface
,LPAVISTREAMINFOW psi
,
265 ICOM_THIS(IAVIStreamImpl
,iface
);
267 TRACE("(%p,%p,%ld)\n", iface
, psi
, size
);
270 return AVIERR_BADPARAM
;
272 return AVIERR_BADSIZE
;
274 /* Need codec to correct some values in structure */
275 if (This
->has
== NULL
) {
276 HRESULT hr
= AVIFILE_OpenCompressor(This
);
282 memcpy(psi
, &This
->sInfo
, min(size
, (LONG
)sizeof(This
->sInfo
)));
284 if (size
< (LONG
)sizeof(This
->sInfo
))
285 return AVIERR_BUFFERTOOSMALL
;
289 static LONG WINAPI
ACMStream_fnFindSample(IAVIStream
*iface
, LONG pos
,
292 ICOM_THIS(IAVIStreamImpl
,iface
);
294 TRACE("(%p,%ld,0x%08lX)\n",iface
,pos
,flags
);
296 if (flags
& FIND_FROM_START
) {
297 pos
= This
->sInfo
.dwStart
;
298 flags
&= ~(FIND_FROM_START
|FIND_PREV
);
302 /* convert pos from our 'space' to This->pStream's one */
303 CONVERT_THIS_to_STREAM(pos
);
306 pos
= IAVIStream_FindSample(This
->pStream
, pos
, flags
);
309 /* convert pos back to our 'space' if it's no size or physical pos */
310 if ((flags
& FIND_RET
) == 0)
311 CONVERT_STREAM_to_THIS(pos
);
317 static HRESULT WINAPI
ACMStream_fnReadFormat(IAVIStream
*iface
, LONG pos
,
318 LPVOID format
, LONG
*formatsize
)
320 ICOM_THIS(IAVIStreamImpl
,iface
);
322 TRACE("(%p,%ld,%p,%p)\n", iface
, pos
, format
, formatsize
);
324 if (formatsize
== NULL
)
325 return AVIERR_BADPARAM
;
327 if (This
->has
== NULL
) {
328 HRESULT hr
= AVIFILE_OpenCompressor(This
);
334 /* only interested in needed buffersize? */
335 if (format
== NULL
|| *formatsize
<= 0) {
336 *formatsize
= This
->cbOutFormat
;
341 /* copy initial format (only as much as will fit) */
342 memcpy(format
, This
->lpOutFormat
, min(*formatsize
, This
->cbOutFormat
));
343 if (*formatsize
< This
->cbOutFormat
) {
344 *formatsize
= This
->cbOutFormat
;
345 return AVIERR_BUFFERTOOSMALL
;
348 *formatsize
= This
->cbOutFormat
;
352 static HRESULT WINAPI
ACMStream_fnSetFormat(IAVIStream
*iface
, LONG pos
,
353 LPVOID format
, LONG formatsize
)
355 ICOM_THIS(IAVIStreamImpl
,iface
);
359 TRACE("(%p,%ld,%p,%ld)\n", iface
, pos
, format
, formatsize
);
361 /* check parameters */
362 if (format
== NULL
|| formatsize
<= 0)
363 return AVIERR_BADPARAM
;
365 /* Input format already known?
366 * Changing is unsupported, but be quiet if it's the same */
367 if (This
->lpInFormat
!= NULL
) {
368 if (This
->cbInFormat
!= formatsize
||
369 memcmp(format
, This
->lpInFormat
, formatsize
) != 0)
370 return AVIERR_UNSUPPORTED
;
375 /* Does the nested stream support writing? */
376 if ((This
->sInfo
.dwCaps
& AVIFILECAPS_CANWRITE
) == 0)
377 return AVIERR_READONLY
;
379 This
->lpInFormat
= (LPWAVEFORMATEX
)GlobalAllocPtr(GMEM_MOVEABLE
, formatsize
);
380 if (This
->lpInFormat
== NULL
)
381 return AVIERR_MEMORY
;
382 This
->cbInFormat
= formatsize
;
383 memcpy(This
->lpInFormat
, format
, formatsize
);
385 /* initialize formats and get compressor */
386 hr
= AVIFILE_OpenCompressor(This
);
390 CONVERT_THIS_to_STREAM(pos
);
392 /* tell the nested stream the new format */
393 return IAVIStream_SetFormat(This
->pStream
, pos
, This
->lpOutFormat
,
397 static HRESULT WINAPI
ACMStream_fnRead(IAVIStream
*iface
, LONG start
,
398 LONG samples
, LPVOID buffer
,
399 LONG buffersize
, LPLONG bytesread
,
402 ICOM_THIS(IAVIStreamImpl
,iface
);
407 TRACE("(%p,%ld,%ld,%p,%ld,%p,%p)\n", iface
, start
, samples
, buffer
,
408 buffersize
, bytesread
, samplesread
);
410 /* clear return parameters if given */
411 if (bytesread
!= NULL
)
413 if (samplesread
!= NULL
)
416 /* Do we have our compressor? */
417 if (This
->has
== NULL
) {
418 hr
= AVIFILE_OpenCompressor(This
);
424 /* only need to pass through? */
425 if (This
->cbInFormat
== This
->cbOutFormat
&&
426 memcmp(This
->lpInFormat
, This
->lpOutFormat
, This
->cbInFormat
) == 0) {
427 return IAVIStream_Read(This
->pStream
, start
, samples
, buffer
, buffersize
,
428 bytesread
, samplesread
);
431 /* read as much as fit? */
433 samples
= buffersize
/ This
->lpOutFormat
->nBlockAlign
;
434 /* limit to buffersize */
435 if (samples
* This
->lpOutFormat
->nBlockAlign
> buffersize
)
436 samples
= buffersize
/ This
->lpOutFormat
->nBlockAlign
;
438 /* only return needed size? */
439 if (buffer
== NULL
|| buffersize
<= 0 || samples
== 0) {
440 if (bytesread
== NULL
&& samplesread
== NULL
)
441 return AVIERR_BADPARAM
;
443 if (bytesread
!= NULL
)
444 *bytesread
= samples
* This
->lpOutFormat
->nBlockAlign
;
445 if (samplesread
!= NULL
)
446 *samplesread
= samples
;
451 /* map our positions to pStream positions */
452 CONVERT_THIS_to_STREAM(start
);
454 /* our needed internal buffersize */
455 size
= samples
* This
->lpInFormat
->nBlockAlign
;
457 /* Need to free destination buffer used for writing? */
458 if (This
->acmStreamHdr
.pbDst
!= NULL
) {
459 GlobalFreePtr(This
->acmStreamHdr
.pbDst
);
460 This
->acmStreamHdr
.pbDst
= NULL
;
461 This
->acmStreamHdr
.dwDstUser
= 0;
464 /* need bigger source buffer? */
465 if (This
->acmStreamHdr
.pbSrc
== NULL
||
466 This
->acmStreamHdr
.dwSrcUser
< size
) {
467 This
->acmStreamHdr
.pbSrc
= GlobalReAllocPtr(This
->acmStreamHdr
.pbSrc
,
468 size
, GMEM_MOVEABLE
);
469 if (This
->acmStreamHdr
.pbSrc
== NULL
)
470 return AVIERR_MEMORY
;
471 This
->acmStreamHdr
.dwSrcUser
= size
;
474 This
->acmStreamHdr
.cbStruct
= sizeof(This
->acmStreamHdr
);
475 This
->acmStreamHdr
.cbSrcLengthUsed
= 0;
476 This
->acmStreamHdr
.cbDstLengthUsed
= 0;
477 This
->acmStreamHdr
.cbSrcLength
= size
;
479 /* read source data */
480 hr
= IAVIStream_Read(This
->pStream
, start
, -1, This
->acmStreamHdr
.pbSrc
,
481 This
->acmStreamHdr
.cbSrcLength
,
482 &This
->acmStreamHdr
.cbSrcLength
, NULL
);
483 if (FAILED(hr
) || This
->acmStreamHdr
.cbSrcLength
== 0)
486 /* need to prepare stream? */
487 This
->acmStreamHdr
.pbDst
= buffer
;
488 This
->acmStreamHdr
.cbDstLength
= buffersize
;
489 if ((This
->acmStreamHdr
.fdwStatus
& ACMSTREAMHEADER_STATUSF_PREPARED
) == 0) {
490 if (acmStreamPrepareHeader(This
->has
, &This
->acmStreamHdr
, 0) != S_OK
) {
491 This
->acmStreamHdr
.pbDst
= NULL
;
492 This
->acmStreamHdr
.cbDstLength
= 0;
493 return AVIERR_COMPRESSOR
;
497 /* now do the conversion */
498 /* FIXME: use ACM_CONVERTF_* flags */
499 if (acmStreamConvert(This
->has
, &This
->acmStreamHdr
, 0) != S_OK
)
500 hr
= AVIERR_COMPRESSOR
;
502 This
->acmStreamHdr
.pbDst
= NULL
;
503 This
->acmStreamHdr
.cbDstLength
= 0;
505 /* fill out return parameters if given */
506 if (bytesread
!= NULL
)
507 *bytesread
= This
->acmStreamHdr
.cbDstLengthUsed
;
508 if (samplesread
!= NULL
)
510 This
->acmStreamHdr
.cbDstLengthUsed
/ This
->lpOutFormat
->nBlockAlign
;
515 static HRESULT WINAPI
ACMStream_fnWrite(IAVIStream
*iface
, LONG start
,
516 LONG samples
, LPVOID buffer
,
517 LONG buffersize
, DWORD flags
,
521 ICOM_THIS(IAVIStreamImpl
,iface
);
526 TRACE("(%p,%ld,%ld,%p,%ld,0x%08lX,%p,%p)\n", iface
, start
, samples
,
527 buffer
, buffersize
, flags
, sampwritten
, byteswritten
);
529 /* clear return parameters if given */
530 if (sampwritten
!= NULL
)
532 if (byteswritten
!= NULL
)
535 /* check parameters */
536 if (buffer
== NULL
&& (buffersize
> 0 || samples
> 0))
537 return AVIERR_BADPARAM
;
539 /* Have we write capability? */
540 if ((This
->sInfo
.dwCaps
& AVIFILECAPS_CANWRITE
) == 0)
541 return AVIERR_READONLY
;
543 /* also need a compressor */
544 if (This
->has
== NULL
)
545 return AVIERR_NOCOMPRESSOR
;
547 /* map our sizes to pStream sizes */
549 CONVERT_THIS_to_STREAM(size
);
550 CONVERT_THIS_to_STREAM(start
);
552 /* no bytes to write? -- short circuit */
554 return IAVIStream_Write(This
->pStream
, -1, samples
, buffer
, size
,
555 flags
, sampwritten
, byteswritten
);
558 /* Need to free source buffer used for reading? */
559 if (This
->acmStreamHdr
.pbSrc
!= NULL
) {
560 GlobalFreePtr(This
->acmStreamHdr
.pbSrc
);
561 This
->acmStreamHdr
.pbSrc
= NULL
;
562 This
->acmStreamHdr
.dwSrcUser
= 0;
565 /* Need bigger destination buffer? */
566 if (This
->acmStreamHdr
.pbDst
== NULL
||
567 This
->acmStreamHdr
.dwDstUser
< size
) {
568 This
->acmStreamHdr
.pbDst
= GlobalReAllocPtr(This
->acmStreamHdr
.pbDst
,
569 size
, GMEM_MOVEABLE
);
570 if (This
->acmStreamHdr
.pbDst
== NULL
)
571 return AVIERR_MEMORY
;
572 This
->acmStreamHdr
.dwDstUser
= size
;
574 This
->acmStreamHdr
.cbStruct
= sizeof(This
->acmStreamHdr
);
575 This
->acmStreamHdr
.cbSrcLengthUsed
= 0;
576 This
->acmStreamHdr
.cbDstLengthUsed
= 0;
577 This
->acmStreamHdr
.cbDstLength
= This
->acmStreamHdr
.dwDstUser
;
579 /* need to prepare stream? */
580 This
->acmStreamHdr
.pbSrc
= buffer
;
581 This
->acmStreamHdr
.cbSrcLength
= buffersize
;
582 if ((This
->acmStreamHdr
.fdwStatus
& ACMSTREAMHEADER_STATUSF_PREPARED
) == 0) {
583 if (acmStreamPrepareHeader(This
->has
, &This
->acmStreamHdr
, 0) != S_OK
) {
584 This
->acmStreamHdr
.pbSrc
= NULL
;
585 This
->acmStreamHdr
.cbSrcLength
= 0;
586 return AVIERR_COMPRESSOR
;
590 /* now do the conversion */
591 /* FIXME: use ACM_CONVERTF_* flags */
592 if (acmStreamConvert(This
->has
, &This
->acmStreamHdr
, 0) != S_OK
)
593 hr
= AVIERR_COMPRESSOR
;
597 This
->acmStreamHdr
.pbSrc
= NULL
;
598 This
->acmStreamHdr
.cbSrcLength
= 0;
603 return IAVIStream_Write(This
->pStream
,-1,This
->acmStreamHdr
.cbDstLengthUsed
/
604 This
->lpOutFormat
->nBlockAlign
,This
->acmStreamHdr
.pbDst
,
605 This
->acmStreamHdr
.cbDstLengthUsed
,flags
,sampwritten
,
609 static HRESULT WINAPI
ACMStream_fnDelete(IAVIStream
*iface
, LONG start
,
612 ICOM_THIS(IAVIStreamImpl
,iface
);
614 TRACE("(%p,%ld,%ld)\n", iface
, start
, samples
);
616 /* check parameters */
617 if (start
< 0 || samples
< 0)
618 return AVIERR_BADPARAM
;
620 /* Delete before start of stream? */
621 if ((DWORD
)(start
+ samples
) < This
->sInfo
.dwStart
)
624 /* Delete after end of stream? */
625 if ((DWORD
)start
> This
->sInfo
.dwLength
)
628 /* For the rest we need write capability */
629 if ((This
->sInfo
.dwCaps
& AVIFILECAPS_CANWRITE
) == 0)
630 return AVIERR_READONLY
;
632 /* A compressor is also necessary */
633 if (This
->has
== NULL
)
634 return AVIERR_NOCOMPRESSOR
;
636 /* map our positions to pStream positions */
637 CONVERT_THIS_to_STREAM(start
);
638 CONVERT_THIS_to_STREAM(samples
);
640 return IAVIStream_Delete(This
->pStream
, start
, samples
);
643 static HRESULT WINAPI
ACMStream_fnReadData(IAVIStream
*iface
, DWORD fcc
,
644 LPVOID lp
, LPLONG lpread
)
646 ICOM_THIS(IAVIStreamImpl
,iface
);
648 TRACE("(%p,0x%08lX,%p,%p)\n", iface
, fcc
, lp
, lpread
);
650 assert(This
->pStream
!= NULL
);
652 return IAVIStream_ReadData(This
->pStream
, fcc
, lp
, lpread
);
655 static HRESULT WINAPI
ACMStream_fnWriteData(IAVIStream
*iface
, DWORD fcc
,
656 LPVOID lp
, LONG size
)
658 ICOM_THIS(IAVIStreamImpl
,iface
);
660 TRACE("(%p,0x%08lx,%p,%ld)\n", iface
, fcc
, lp
, size
);
662 assert(This
->pStream
!= NULL
);
664 return IAVIStream_WriteData(This
->pStream
, fcc
, lp
, size
);
667 static HRESULT WINAPI
ACMStream_fnSetInfo(IAVIStream
*iface
,
668 LPAVISTREAMINFOW info
, LONG infolen
)
670 FIXME("(%p,%p,%ld): stub\n", iface
, info
, infolen
);
675 /***********************************************************************/
677 static HRESULT
AVIFILE_OpenCompressor(IAVIStreamImpl
*This
)
682 assert(This
!= NULL
);
683 assert(This
->pStream
!= NULL
);
685 if (This
->has
!= NULL
)
688 if (This
->lpInFormat
== NULL
) {
689 /* decode or encode the data from pStream */
690 hr
= AVIStreamFormatSize(This
->pStream
, This
->sInfo
.dwStart
, &This
->cbInFormat
);
693 This
->lpInFormat
= (LPWAVEFORMATEX
)GlobalAllocPtr(GMEM_MOVEABLE
, This
->cbInFormat
);
694 if (This
->lpInFormat
== NULL
)
695 return AVIERR_MEMORY
;
697 hr
= IAVIStream_ReadFormat(This
->pStream
, This
->sInfo
.dwStart
,
698 This
->lpInFormat
, &This
->cbInFormat
);
702 if (This
->lpOutFormat
== NULL
) {
703 /* we must decode to default format */
704 This
->cbOutFormat
= sizeof(PCMWAVEFORMAT
);
705 This
->lpOutFormat
= (LPWAVEFORMATEX
)GlobalAllocPtr(GHND
, This
->cbOutFormat
);
706 if (This
->lpOutFormat
== NULL
)
707 return AVIERR_MEMORY
;
709 This
->lpOutFormat
->wFormatTag
= WAVE_FORMAT_PCM
;
710 if (acmFormatSuggest(NULL
, This
->lpInFormat
, This
->lpOutFormat
,
711 This
->cbOutFormat
, ACM_FORMATSUGGESTF_WFORMATTAG
) != S_OK
)
712 return AVIERR_NOCOMPRESSOR
;
714 } else if (This
->lpOutFormat
== NULL
)
715 return AVIERR_ERROR
; /* To what should I encode? */
717 if (acmStreamOpen(&This
->has
, NULL
, This
->lpInFormat
, This
->lpOutFormat
,
718 NULL
, 0, 0, ACM_STREAMOPENF_NONREALTIME
) != S_OK
)
719 return AVIERR_NOCOMPRESSOR
;
721 /* update AVISTREAMINFO structure */
722 This
->sInfo
.dwSampleSize
= This
->lpOutFormat
->nBlockAlign
;
723 This
->sInfo
.dwScale
= This
->lpOutFormat
->nBlockAlign
;
724 This
->sInfo
.dwRate
= This
->lpOutFormat
->nAvgBytesPerSec
;
725 This
->sInfo
.dwQuality
= (DWORD
)ICQUALITY_DEFAULT
;
726 SetRectEmpty(&This
->sInfo
.rcFrame
);
728 /* convert positions ansd sizes to output format */
729 CONVERT_STREAM_to_THIS(This
->sInfo
.dwStart
);
730 CONVERT_STREAM_to_THIS(This
->sInfo
.dwLength
);
731 CONVERT_STREAM_to_THIS(This
->sInfo
.dwSuggestedBufferSize
);