2003-11-18 21:47:48 +01:00
|
|
|
/*
|
|
|
|
* AVI Splitter Filter
|
|
|
|
*
|
|
|
|
* Copyright 2003 Robert Shearman
|
2005-02-08 14:43:59 +01:00
|
|
|
* Copyright 2004-2005 Christian Costa
|
2008-04-11 23:02:26 +02:00
|
|
|
* Copyright 2008 Maarten Lankhorst
|
2003-11-18 21:47:48 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-11-18 21:47:48 +01:00
|
|
|
*/
|
|
|
|
/* FIXME:
|
2008-07-20 23:51:31 +02:00
|
|
|
* - Reference leaks, if they still exist
|
2008-07-05 03:44:14 +02:00
|
|
|
* - Files without an index are not handled correctly yet.
|
|
|
|
* - When stopping/starting, a sample is lost. This should be compensated by
|
|
|
|
* keeping track of previous index/position.
|
|
|
|
* - Debugging channels are noisy at the moment, especially with thread
|
|
|
|
* related messages, however this is the only correct thing to do right now,
|
|
|
|
* since wine doesn't correctly handle all messages yet.
|
2003-11-18 21:47:48 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "quartz_private.h"
|
|
|
|
#include "control_private.h"
|
|
|
|
#include "pin.h"
|
|
|
|
|
|
|
|
#include "uuids.h"
|
2008-04-11 00:45:32 +02:00
|
|
|
#include "vfw.h"
|
2003-11-18 21:47:48 +01:00
|
|
|
#include "aviriff.h"
|
|
|
|
#include "vfwmsgs.h"
|
|
|
|
#include "amvideo.h"
|
|
|
|
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2005-02-08 14:43:59 +01:00
|
|
|
#include "parser.h"
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-04-11 00:45:32 +02:00
|
|
|
#define TWOCCFromFOURCC(fcc) HIWORD(fcc)
|
|
|
|
|
|
|
|
/* four character codes used in AVI files */
|
|
|
|
#define ckidINFO mmioFOURCC('I','N','F','O')
|
|
|
|
#define ckidREC mmioFOURCC('R','E','C',' ')
|
|
|
|
|
2005-02-08 14:43:59 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-03-19 00:05:00 +01:00
|
|
|
typedef struct StreamData
|
|
|
|
{
|
|
|
|
DWORD dwSampleSize;
|
|
|
|
FLOAT fSamplesPerSec;
|
|
|
|
DWORD dwLength;
|
2008-04-16 05:39:36 +02:00
|
|
|
|
2008-04-17 03:23:50 +02:00
|
|
|
AVISTREAMHEADER streamheader;
|
2008-04-16 05:39:36 +02:00
|
|
|
DWORD entries;
|
|
|
|
AVISTDINDEX **stdindex;
|
2008-04-17 03:23:50 +02:00
|
|
|
DWORD frames;
|
2008-07-05 03:44:14 +02:00
|
|
|
DWORD seek;
|
|
|
|
|
|
|
|
/* Position, in index units */
|
|
|
|
DWORD pos, pos_next, index, index_next;
|
|
|
|
|
|
|
|
/* Packet handling: a thread is created and waits on the packet event handle
|
|
|
|
* On an event acquire the sample lock, addref the sample and set it to NULL,
|
|
|
|
* then queue a new packet.
|
|
|
|
*/
|
|
|
|
HANDLE thread, packet_queued;
|
|
|
|
IMediaSample *sample;
|
|
|
|
|
|
|
|
/* Amount of preroll samples for this stream */
|
|
|
|
DWORD preroll;
|
2008-03-19 00:05:00 +01:00
|
|
|
} StreamData;
|
|
|
|
|
2005-02-08 14:43:59 +01:00
|
|
|
typedef struct AVISplitterImpl
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
2005-02-08 14:43:59 +01:00
|
|
|
ParserImpl Parser;
|
2003-11-18 21:47:48 +01:00
|
|
|
RIFFCHUNK CurrentChunk;
|
|
|
|
LONGLONG CurrentChunkOffset; /* in media time */
|
|
|
|
LONGLONG EndOfFile;
|
|
|
|
AVIMAINHEADER AviHeader;
|
2008-04-16 05:39:36 +02:00
|
|
|
AVIEXTHEADER ExtHeader;
|
|
|
|
|
|
|
|
AVIOLDINDEX *oldindex;
|
2008-04-17 03:23:50 +02:00
|
|
|
DWORD offset;
|
2008-04-16 05:39:36 +02:00
|
|
|
|
2008-03-19 00:05:00 +01:00
|
|
|
StreamData *streams;
|
2005-02-08 14:43:59 +01:00
|
|
|
} AVISplitterImpl;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
struct thread_args {
|
|
|
|
AVISplitterImpl *This;
|
|
|
|
DWORD stream;
|
|
|
|
};
|
|
|
|
|
2010-10-11 17:15:35 +02:00
|
|
|
static inline AVISplitterImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
|
|
|
|
{
|
|
|
|
return (AVISplitterImpl *)((char*)iface - FIELD_OFFSET(AVISplitterImpl, Parser.sourceSeeking.lpVtbl));
|
|
|
|
}
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
/* The threading stuff cries for an explanation
|
|
|
|
*
|
|
|
|
* PullPin starts processing and calls AVISplitter_first_request
|
|
|
|
* AVISplitter_first_request creates a thread for each stream
|
|
|
|
* A stream can be audio, video, subtitles or something undefined.
|
|
|
|
*
|
|
|
|
* AVISplitter_first_request loads a single packet to each but one stream,
|
|
|
|
* and queues it for that last stream. This is to prevent WaitForNext to time
|
|
|
|
* out badly.
|
|
|
|
*
|
|
|
|
* The processing loop is entered. It calls IAsyncReader_WaitForNext in the
|
|
|
|
* PullPin. Every time it receives a packet, it will call AVISplitter_Sample
|
|
|
|
* AVISplitter_Sample will signal the relevant thread that a new sample is
|
|
|
|
* arrived, when that thread is ready it will read the packet and transmits
|
|
|
|
* it downstream with AVISplitter_Receive
|
|
|
|
*
|
|
|
|
* Threads terminate upon receiving NULL as packet or when ANY error code
|
|
|
|
* != S_OK occurs. This means that any error is fatal to processing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static HRESULT AVISplitter_SendEndOfFile(AVISplitterImpl *This, DWORD streamnumber)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
IPin* ppin = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("End of file reached\n");
|
|
|
|
|
|
|
|
hr = IPin_ConnectedTo(This->Parser.ppPins[streamnumber+1], &ppin);
|
|
|
|
if (SUCCEEDED(hr))
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
hr = IPin_EndOfStream(ppin);
|
|
|
|
IPin_Release(ppin);
|
2003-11-18 21:47:48 +01:00
|
|
|
}
|
2008-07-05 03:44:14 +02:00
|
|
|
TRACE("--> %x\n", hr);
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
/* Force the pullpin thread to stop */
|
|
|
|
return S_FALSE;
|
2003-11-18 21:47:48 +01:00
|
|
|
}
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
/* Thread worker horse */
|
|
|
|
static HRESULT AVISplitter_next_request(AVISplitterImpl *This, DWORD streamnumber)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
StreamData *stream = This->streams + streamnumber;
|
|
|
|
PullPin *pin = This->Parser.pInputPin;
|
|
|
|
IMediaSample *sample = NULL;
|
2003-11-18 21:47:48 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
TRACE("(%p, %u)->()\n", This, streamnumber);
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
hr = IMemAllocator_GetBuffer(pin->pAlloc, &sample, NULL, NULL, 0);
|
|
|
|
if (hr != S_OK)
|
|
|
|
ERR("... %08x?\n", hr);
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
LONGLONG rtSampleStart;
|
|
|
|
/* Add 4 for the next header, which should hopefully work */
|
|
|
|
LONGLONG rtSampleStop;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
stream->pos = stream->pos_next;
|
|
|
|
stream->index = stream->index_next;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
IMediaSample_SetDiscontinuity(sample, stream->seek);
|
|
|
|
stream->seek = FALSE;
|
|
|
|
if (stream->preroll)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
--stream->preroll;
|
|
|
|
IMediaSample_SetPreroll(sample, TRUE);
|
2003-11-18 21:47:48 +01:00
|
|
|
}
|
|
|
|
else
|
2008-07-05 03:44:14 +02:00
|
|
|
IMediaSample_SetPreroll(sample, FALSE);
|
|
|
|
IMediaSample_SetSyncPoint(sample, TRUE);
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
if (stream->stdindex)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
AVISTDINDEX *index = stream->stdindex[stream->index];
|
|
|
|
AVISTDINDEX_ENTRY *entry = &index->aIndex[stream->pos];
|
|
|
|
|
2008-07-22 04:50:07 +02:00
|
|
|
/* End of file */
|
|
|
|
if (stream->index >= stream->entries)
|
|
|
|
{
|
2008-07-24 22:08:09 +02:00
|
|
|
TRACE("END OF STREAM ON %u\n", streamnumber);
|
2008-07-22 04:50:07 +02:00
|
|
|
IMediaSample_Release(sample);
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
rtSampleStart = index->qwBaseOffset;
|
|
|
|
rtSampleStart += entry->dwOffset;
|
|
|
|
rtSampleStart = MEDIATIME_FROM_BYTES(rtSampleStart);
|
|
|
|
|
|
|
|
++stream->pos_next;
|
|
|
|
if (index->nEntriesInUse == stream->pos_next)
|
2004-07-23 01:44:39 +02:00
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
stream->pos_next = 0;
|
|
|
|
++stream->index_next;
|
2004-07-23 01:44:39 +02:00
|
|
|
}
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
rtSampleStop = rtSampleStart + MEDIATIME_FROM_BYTES(entry->dwSize & ~(1 << 31));
|
2008-04-12 01:40:56 +02:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
TRACE("offset(%u) size(%u)\n", (DWORD)BYTES_FROM_MEDIATIME(rtSampleStart), (DWORD)BYTES_FROM_MEDIATIME(rtSampleStop - rtSampleStart));
|
2003-11-18 21:47:48 +01:00
|
|
|
}
|
2008-07-05 03:44:14 +02:00
|
|
|
else if (This->oldindex)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
DWORD flags = This->oldindex->aIndex[stream->pos].dwFlags;
|
|
|
|
DWORD size = This->oldindex->aIndex[stream->pos].dwSize;
|
2008-07-22 04:50:07 +02:00
|
|
|
|
|
|
|
/* End of file */
|
|
|
|
if (stream->index)
|
|
|
|
{
|
2008-07-24 22:08:09 +02:00
|
|
|
TRACE("END OF STREAM ON %u\n", streamnumber);
|
2008-07-22 04:50:07 +02:00
|
|
|
IMediaSample_Release(sample);
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
rtSampleStart = MEDIATIME_FROM_BYTES(This->offset);
|
|
|
|
rtSampleStart += MEDIATIME_FROM_BYTES(This->oldindex->aIndex[stream->pos].dwOffset);
|
|
|
|
rtSampleStop = rtSampleStart + MEDIATIME_FROM_BYTES(size);
|
|
|
|
if (flags & AVIIF_MIDPART)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
FIXME("Only stand alone frames are currently handled correctly!\n");
|
|
|
|
}
|
|
|
|
if (flags & AVIIF_LIST)
|
|
|
|
{
|
|
|
|
FIXME("Not sure if this is handled correctly\n");
|
|
|
|
rtSampleStart += MEDIATIME_FROM_BYTES(sizeof(RIFFLIST));
|
|
|
|
rtSampleStop += MEDIATIME_FROM_BYTES(sizeof(RIFFLIST));
|
2003-11-18 21:47:48 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
rtSampleStart += MEDIATIME_FROM_BYTES(sizeof(RIFFCHUNK));
|
|
|
|
rtSampleStop += MEDIATIME_FROM_BYTES(sizeof(RIFFCHUNK));
|
2003-11-18 21:47:48 +01:00
|
|
|
}
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
/* Slow way of finding next index */
|
|
|
|
do {
|
|
|
|
stream->pos_next++;
|
|
|
|
} while (stream->pos_next * sizeof(This->oldindex->aIndex[0]) < This->oldindex->cb
|
|
|
|
&& StreamFromFOURCC(This->oldindex->aIndex[stream->pos_next].dwChunkId) != streamnumber);
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-22 04:50:07 +02:00
|
|
|
/* End of file soon */
|
|
|
|
if (stream->pos_next * sizeof(This->oldindex->aIndex[0]) >= This->oldindex->cb)
|
2008-07-05 03:44:14 +02:00
|
|
|
{
|
|
|
|
stream->pos_next = 0;
|
|
|
|
++stream->index_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* TODO: Generate an index automagically */
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
ERR("CAN'T PLAY WITHOUT AN INDEX! SOS! SOS! SOS!\n");
|
|
|
|
assert(0);
|
|
|
|
}
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-19 00:49:31 +02:00
|
|
|
if (rtSampleStart != rtSampleStop)
|
|
|
|
{
|
|
|
|
hr = IMediaSample_SetTime(sample, &rtSampleStart, &rtSampleStop);
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-19 00:49:31 +02:00
|
|
|
hr = IAsyncReader_Request(pin->pReader, sample, streamnumber);
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-19 00:49:31 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
assert(IMediaSample_Release(sample) == 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stream->sample = sample;
|
|
|
|
IMediaSample_SetActualDataLength(sample, 0);
|
|
|
|
SetEvent(stream->packet_queued);
|
|
|
|
}
|
2008-07-05 03:44:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (sample)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
ERR("There should be no sample!\n");
|
|
|
|
assert(IMediaSample_Release(sample) == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TRACE("--> %08x\n", hr);
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
static HRESULT AVISplitter_Receive(AVISplitterImpl *This, IMediaSample *sample, DWORD streamnumber)
|
|
|
|
{
|
|
|
|
Parser_OutputPin *pin = (Parser_OutputPin *)This->Parser.ppPins[1+streamnumber];
|
|
|
|
HRESULT hr;
|
|
|
|
LONGLONG start, stop;
|
|
|
|
StreamData *stream = &This->streams[streamnumber];
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
start = pin->dwSamplesProcessed;
|
|
|
|
start *= stream->streamheader.dwScale;
|
|
|
|
start *= 10000000;
|
|
|
|
start /= stream->streamheader.dwRate;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
if (stream->streamheader.dwSampleSize)
|
|
|
|
{
|
|
|
|
ULONG len = IMediaSample_GetActualDataLength(sample);
|
|
|
|
ULONG size = stream->streamheader.dwSampleSize;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
pin->dwSamplesProcessed += len / size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++pin->dwSamplesProcessed;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
stop = pin->dwSamplesProcessed;
|
|
|
|
stop *= stream->streamheader.dwScale;
|
|
|
|
stop *= 10000000;
|
|
|
|
stop /= stream->streamheader.dwRate;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
IMediaSample_SetTime(sample, &start, &stop);
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2010-10-05 21:37:56 +02:00
|
|
|
hr = BaseOutputPinImpl_Deliver((BaseOutputPin*)&pin->pin, sample);
|
2008-07-05 03:44:14 +02:00
|
|
|
|
|
|
|
/* Uncomment this if you want to debug the time differences between the
|
|
|
|
* different streams, it is useful for that
|
|
|
|
*
|
|
|
|
FIXME("stream %u, hr: %08x, Start: %u.%03u, Stop: %u.%03u\n", streamnumber, hr,
|
|
|
|
(DWORD)(start / 10000000), (DWORD)((start / 10000)%1000),
|
|
|
|
(DWORD)(stop / 10000000), (DWORD)((stop / 10000)%1000));
|
|
|
|
*/
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI AVISplitter_thread_reader(LPVOID data)
|
|
|
|
{
|
|
|
|
struct thread_args *args = data;
|
|
|
|
AVISplitterImpl *This = args->This;
|
|
|
|
DWORD streamnumber = args->stream;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
HRESULT nexthr = S_FALSE;
|
|
|
|
IMediaSample *sample;
|
|
|
|
|
|
|
|
WaitForSingleObject(This->streams[streamnumber].packet_queued, INFINITE);
|
|
|
|
sample = This->streams[streamnumber].sample;
|
|
|
|
This->streams[streamnumber].sample = NULL;
|
|
|
|
if (!sample)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nexthr = AVISplitter_next_request(This, streamnumber);
|
|
|
|
|
|
|
|
hr = AVISplitter_Receive(This, sample, streamnumber);
|
|
|
|
if (hr != S_OK)
|
|
|
|
FIXME("Receiving error: %08x\n", hr);
|
|
|
|
|
|
|
|
IMediaSample_Release(sample);
|
|
|
|
if (hr == S_OK)
|
|
|
|
hr = nexthr;
|
2008-07-22 04:50:07 +02:00
|
|
|
if (nexthr == S_FALSE)
|
|
|
|
AVISplitter_SendEndOfFile(This, streamnumber);
|
2008-07-05 03:44:14 +02:00
|
|
|
} while (hr == S_OK);
|
|
|
|
|
2008-12-07 12:09:43 +01:00
|
|
|
if (hr != S_FALSE)
|
|
|
|
FIXME("Thread %u terminated with hr %08x!\n", streamnumber, hr);
|
|
|
|
else
|
|
|
|
TRACE("Thread %u terminated properly\n", streamnumber);
|
2008-07-05 03:44:14 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT AVISplitter_Sample(LPVOID iface, IMediaSample * pSample, DWORD_PTR cookie)
|
|
|
|
{
|
|
|
|
AVISplitterImpl *This = iface;
|
|
|
|
StreamData *stream = This->streams + cookie;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if (!IMediaSample_GetActualDataLength(pSample))
|
2008-07-19 00:49:31 +02:00
|
|
|
{
|
|
|
|
ERR("Received empty sample\n");
|
2008-07-05 03:44:14 +02:00
|
|
|
return S_OK;
|
2008-07-19 00:49:31 +02:00
|
|
|
}
|
2008-07-05 03:44:14 +02:00
|
|
|
|
|
|
|
/* Send the sample to whatever thread is appropiate
|
|
|
|
* That thread should also not have a sample queued at the moment
|
|
|
|
*/
|
|
|
|
/* Debugging */
|
|
|
|
TRACE("(%p)->(%p size: %u, %lu)\n", This, pSample, IMediaSample_GetActualDataLength(pSample), cookie);
|
|
|
|
assert(cookie < This->Parser.cStreams);
|
|
|
|
assert(!stream->sample);
|
|
|
|
assert(WaitForSingleObject(stream->packet_queued, 0) == WAIT_TIMEOUT);
|
|
|
|
|
|
|
|
IMediaSample_AddRef(pSample);
|
|
|
|
|
|
|
|
stream->sample = pSample;
|
|
|
|
SetEvent(stream->packet_queued);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-07-11 20:20:47 +02:00
|
|
|
static HRESULT AVISplitter_done_process(LPVOID iface);
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
/* On the first request we have to be sure that (cStreams-1) samples have
|
|
|
|
* already been processed, because otherwise some pins might not ever finish
|
|
|
|
* a Pause state change
|
|
|
|
*/
|
|
|
|
static HRESULT AVISplitter_first_request(LPVOID iface)
|
|
|
|
{
|
2009-01-29 11:14:55 +01:00
|
|
|
AVISplitterImpl *This = iface;
|
2008-07-05 03:44:14 +02:00
|
|
|
HRESULT hr = S_OK;
|
2008-11-03 23:45:48 +01:00
|
|
|
DWORD x;
|
2008-07-05 03:44:14 +02:00
|
|
|
IMediaSample *sample = NULL;
|
|
|
|
BOOL have_sample = FALSE;
|
|
|
|
|
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
|
|
|
for (x = 0; x < This->Parser.cStreams; ++x)
|
|
|
|
{
|
|
|
|
StreamData *stream = This->streams + x;
|
|
|
|
|
|
|
|
/* Nothing should be running at this point */
|
|
|
|
assert(!stream->thread);
|
|
|
|
|
|
|
|
assert(!sample);
|
|
|
|
/* It could be we asked the thread to terminate, and the thread
|
|
|
|
* already terminated before receiving the deathwish */
|
|
|
|
ResetEvent(stream->packet_queued);
|
|
|
|
|
|
|
|
stream->pos_next = stream->pos;
|
|
|
|
stream->index_next = stream->index;
|
|
|
|
|
2008-07-20 23:51:31 +02:00
|
|
|
/* There should be a packet queued from AVISplitter_next_request last time
|
2008-07-05 03:44:14 +02:00
|
|
|
* It needs to be done now because this is the only way to ensure that every
|
|
|
|
* stream will have at least 1 packet processed
|
|
|
|
* If this is done after the threads start it could go all awkward and we
|
|
|
|
* would have no guarantees that it's successful at all
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (have_sample)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
DWORD_PTR dwUser = ~0;
|
|
|
|
hr = IAsyncReader_WaitForNext(This->Parser.pInputPin->pReader, 10000, &sample, &dwUser);
|
|
|
|
assert(hr == S_OK);
|
|
|
|
assert(sample);
|
|
|
|
|
|
|
|
AVISplitter_Sample(iface, sample, dwUser);
|
|
|
|
IMediaSample_Release(sample);
|
2003-11-18 21:47:48 +01:00
|
|
|
}
|
2008-07-05 03:44:14 +02:00
|
|
|
|
|
|
|
hr = AVISplitter_next_request(This, x);
|
|
|
|
TRACE("-->%08x\n", hr);
|
|
|
|
|
|
|
|
/* Could be an EOF instead */
|
|
|
|
have_sample = (hr == S_OK);
|
2008-07-22 17:04:20 +02:00
|
|
|
if (hr == S_FALSE)
|
|
|
|
AVISplitter_SendEndOfFile(This, x);
|
2008-09-15 19:48:08 +02:00
|
|
|
|
|
|
|
if (FAILED(hr) && hr != VFW_E_NOT_CONNECTED)
|
|
|
|
break;
|
|
|
|
hr = S_OK;
|
2003-11-18 21:47:48 +01:00
|
|
|
}
|
2005-03-02 11:12:12 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
/* FIXME: Don't do this for each pin that sent an EOF */
|
2008-07-11 20:20:47 +02:00
|
|
|
for (x = 0; x < This->Parser.cStreams && SUCCEEDED(hr); ++x)
|
2005-03-02 11:12:12 +01:00
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
struct thread_args *args;
|
|
|
|
DWORD tid;
|
2005-03-02 11:12:12 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
if ((This->streams[x].stdindex && This->streams[x].index_next >= This->streams[x].entries) ||
|
|
|
|
(!This->streams[x].stdindex && This->streams[x].index_next))
|
2005-03-02 11:12:12 +01:00
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
This->streams[x].thread = NULL;
|
|
|
|
continue;
|
2005-03-02 11:12:12 +01:00
|
|
|
}
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
args = CoTaskMemAlloc(sizeof(*args));
|
|
|
|
args->This = This;
|
|
|
|
args->stream = x;
|
|
|
|
This->streams[x].thread = CreateThread(NULL, 0, AVISplitter_thread_reader, args, 0, &tid);
|
2008-12-07 12:09:43 +01:00
|
|
|
TRACE("Created stream %u thread 0x%08x\n", x, tid);
|
2005-03-02 11:12:12 +01:00
|
|
|
}
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
ERR("Horsemen of the apocalypse came to bring error 0x%08x\n", hr);
|
|
|
|
|
2003-11-18 21:47:48 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
static HRESULT AVISplitter_done_process(LPVOID iface)
|
|
|
|
{
|
|
|
|
AVISplitterImpl *This = iface;
|
|
|
|
|
|
|
|
DWORD x;
|
|
|
|
|
|
|
|
for (x = 0; x < This->Parser.cStreams; ++x)
|
|
|
|
{
|
|
|
|
StreamData *stream = This->streams + x;
|
|
|
|
|
2008-12-07 12:09:43 +01:00
|
|
|
TRACE("Waiting for %u to terminate\n", x);
|
2008-07-05 03:44:14 +02:00
|
|
|
/* Make the thread return first */
|
|
|
|
SetEvent(stream->packet_queued);
|
|
|
|
assert(WaitForSingleObject(stream->thread, 100000) != WAIT_TIMEOUT);
|
|
|
|
CloseHandle(stream->thread);
|
|
|
|
stream->thread = NULL;
|
|
|
|
|
|
|
|
if (stream->sample)
|
|
|
|
assert(IMediaSample_Release(stream->sample) == 0);
|
|
|
|
stream->sample = NULL;
|
|
|
|
|
|
|
|
ResetEvent(stream->packet_queued);
|
|
|
|
}
|
2008-12-07 12:09:43 +01:00
|
|
|
TRACE("All threads are now terminated\n");
|
2008-07-05 03:44:14 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2003-11-18 21:47:48 +01:00
|
|
|
static HRESULT AVISplitter_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
|
|
|
if (IsEqualIID(&pmt->majortype, &MEDIATYPE_Stream) && IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_Avi))
|
|
|
|
return S_OK;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-04-16 23:29:09 +02:00
|
|
|
static HRESULT AVISplitter_ProcessIndex(AVISplitterImpl *This, AVISTDINDEX **index, LONGLONG qwOffset, DWORD cb)
|
2008-04-11 23:02:26 +02:00
|
|
|
{
|
|
|
|
AVISTDINDEX *pIndex;
|
2008-11-03 23:45:48 +01:00
|
|
|
DWORD x;
|
|
|
|
int rest;
|
2008-04-11 23:02:26 +02:00
|
|
|
|
2008-04-16 23:29:09 +02:00
|
|
|
*index = NULL;
|
2008-04-11 23:02:26 +02:00
|
|
|
if (cb < sizeof(AVISTDINDEX))
|
|
|
|
{
|
|
|
|
FIXME("size %u too small\n", cb);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
pIndex = CoTaskMemAlloc(cb);
|
|
|
|
if (!pIndex)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
IAsyncReader_SyncRead(((PullPin *)This->Parser.ppPins[0])->pReader, qwOffset, cb, (BYTE *)pIndex);
|
2008-07-24 22:08:09 +02:00
|
|
|
rest = cb - sizeof(AVISUPERINDEX) + sizeof(RIFFCHUNK) + sizeof(pIndex->aIndex);
|
2008-04-11 23:02:26 +02:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
TRACE("FOURCC: %s\n", debugstr_an((char *)&pIndex->fcc, 4));
|
2008-04-11 23:02:26 +02:00
|
|
|
TRACE("wLongsPerEntry: %hd\n", pIndex->wLongsPerEntry);
|
2010-09-20 10:48:49 +02:00
|
|
|
TRACE("bIndexSubType: %u\n", pIndex->bIndexSubType);
|
|
|
|
TRACE("bIndexType: %u\n", pIndex->bIndexType);
|
2008-04-11 23:02:26 +02:00
|
|
|
TRACE("nEntriesInUse: %u\n", pIndex->nEntriesInUse);
|
|
|
|
TRACE("dwChunkId: %.4s\n", (char *)&pIndex->dwChunkId);
|
|
|
|
TRACE("qwBaseOffset: %x%08x\n", (DWORD)(pIndex->qwBaseOffset >> 32), (DWORD)pIndex->qwBaseOffset);
|
|
|
|
TRACE("dwReserved_3: %u\n", pIndex->dwReserved_3);
|
|
|
|
|
|
|
|
if (pIndex->bIndexType != AVI_INDEX_OF_CHUNKS
|
|
|
|
|| pIndex->wLongsPerEntry != 2
|
|
|
|
|| rest < (pIndex->nEntriesInUse * sizeof(DWORD) * pIndex->wLongsPerEntry)
|
|
|
|
|| (pIndex->bIndexSubType != AVI_INDEX_SUB_DEFAULT))
|
|
|
|
{
|
2008-07-24 22:08:09 +02:00
|
|
|
FIXME("Invalid index chunk encountered: %u/%u, %u/%u, %u/%u, %u/%u\n",
|
|
|
|
pIndex->bIndexType, AVI_INDEX_OF_CHUNKS, pIndex->wLongsPerEntry, 2,
|
2008-08-21 16:05:15 +02:00
|
|
|
rest, (DWORD)(pIndex->nEntriesInUse * sizeof(DWORD) * pIndex->wLongsPerEntry),
|
2008-07-24 22:08:09 +02:00
|
|
|
pIndex->bIndexSubType, AVI_INDEX_SUB_DEFAULT);
|
|
|
|
*index = NULL;
|
2008-04-11 23:02:26 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (x = 0; x < pIndex->nEntriesInUse; ++x)
|
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
BOOL keyframe = !(pIndex->aIndex[x].dwSize >> 31);
|
|
|
|
DWORDLONG offset = pIndex->qwBaseOffset + pIndex->aIndex[x].dwOffset;
|
2008-04-11 23:02:26 +02:00
|
|
|
TRACE("dwOffset: %x%08x\n", (DWORD)(offset >> 32), (DWORD)offset);
|
2008-07-05 03:44:14 +02:00
|
|
|
TRACE("dwSize: %u\n", (pIndex->aIndex[x].dwSize & ~(1<<31)));
|
2008-04-11 23:02:26 +02:00
|
|
|
TRACE("Frame is a keyframe: %s\n", keyframe ? "yes" : "no");
|
|
|
|
}
|
|
|
|
|
2008-04-16 23:29:09 +02:00
|
|
|
*index = pIndex;
|
2008-04-11 23:02:26 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-16 05:39:36 +02:00
|
|
|
static HRESULT AVISplitter_ProcessOldIndex(AVISplitterImpl *This)
|
|
|
|
{
|
2008-04-17 03:23:50 +02:00
|
|
|
ULONGLONG mov_pos = BYTES_FROM_MEDIATIME(This->CurrentChunkOffset) - sizeof(DWORD);
|
2008-04-16 05:39:36 +02:00
|
|
|
AVIOLDINDEX *pAviOldIndex = This->oldindex;
|
|
|
|
int relative = -1;
|
2008-11-03 23:45:48 +01:00
|
|
|
DWORD x;
|
2008-04-16 05:39:36 +02:00
|
|
|
|
|
|
|
for (x = 0; x < pAviOldIndex->cb / sizeof(pAviOldIndex->aIndex[0]); ++x)
|
|
|
|
{
|
|
|
|
DWORD temp, temp2 = 0, offset, chunkid;
|
|
|
|
PullPin *pin = This->Parser.pInputPin;
|
|
|
|
|
|
|
|
offset = pAviOldIndex->aIndex[x].dwOffset;
|
|
|
|
chunkid = pAviOldIndex->aIndex[x].dwChunkId;
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
TRACE("dwChunkId: %.4s\n", (char *)&chunkid);
|
|
|
|
TRACE("dwFlags: %08x\n", pAviOldIndex->aIndex[x].dwFlags);
|
|
|
|
TRACE("dwOffset (%s): %08x\n", relative ? "relative" : "absolute", offset);
|
|
|
|
TRACE("dwSize: %08x\n", pAviOldIndex->aIndex[x].dwSize);
|
|
|
|
|
2008-04-16 05:39:36 +02:00
|
|
|
/* Only scan once, or else this will take too long */
|
|
|
|
if (relative == -1)
|
|
|
|
{
|
|
|
|
IAsyncReader_SyncRead(pin->pReader, offset, sizeof(DWORD), (BYTE *)&temp);
|
|
|
|
relative = (chunkid != temp);
|
|
|
|
|
|
|
|
if (chunkid == mmioFOURCC('7','F','x','x')
|
|
|
|
&& ((char *)&temp)[0] == 'i' && ((char *)&temp)[1] == 'x')
|
|
|
|
relative = FALSE;
|
|
|
|
|
|
|
|
if (relative)
|
|
|
|
{
|
|
|
|
if (offset + mov_pos < BYTES_FROM_MEDIATIME(This->EndOfFile))
|
|
|
|
IAsyncReader_SyncRead(pin->pReader, offset + mov_pos, sizeof(DWORD), (BYTE *)&temp2);
|
|
|
|
|
|
|
|
if (chunkid == mmioFOURCC('7','F','x','x')
|
|
|
|
&& ((char *)&temp2)[0] == 'i' && ((char *)&temp2)[1] == 'x')
|
|
|
|
{
|
|
|
|
/* Do nothing, all is great */
|
|
|
|
}
|
|
|
|
else if (temp2 != chunkid)
|
|
|
|
{
|
|
|
|
ERR("Faulty index or bug in handling: Wanted FCC: %s, Abs FCC: %s (@ %x), Rel FCC: %s (@ %.0x%08x)\n",
|
|
|
|
debugstr_an((char *)&chunkid, 4), debugstr_an((char *)&temp, 4), offset,
|
|
|
|
debugstr_an((char *)&temp2, 4), (DWORD)((mov_pos + offset) >> 32), (DWORD)(mov_pos + offset));
|
|
|
|
relative = -1;
|
|
|
|
}
|
2008-04-19 04:30:25 +02:00
|
|
|
else
|
|
|
|
TRACE("Scanned dwChunkId: %s\n", debugstr_an((char *)&temp2, 4));
|
2008-04-16 05:39:36 +02:00
|
|
|
}
|
2008-04-19 04:30:25 +02:00
|
|
|
else if (!relative)
|
2008-07-05 03:44:14 +02:00
|
|
|
TRACE("Scanned dwChunkId: %s\n", debugstr_an((char *)&temp, 4));
|
2008-04-16 05:39:36 +02:00
|
|
|
}
|
2008-07-05 03:44:14 +02:00
|
|
|
/* Only dump one packet */
|
2008-04-19 04:30:25 +02:00
|
|
|
else break;
|
2008-04-16 05:39:36 +02:00
|
|
|
}
|
|
|
|
|
2008-04-17 03:23:50 +02:00
|
|
|
if (relative == -1)
|
|
|
|
{
|
|
|
|
FIXME("Dropping index: no idea whether it is relative or absolute\n");
|
|
|
|
CoTaskMemFree(This->oldindex);
|
|
|
|
This->oldindex = NULL;
|
|
|
|
}
|
|
|
|
else if (!relative)
|
|
|
|
This->offset = 0;
|
|
|
|
else
|
|
|
|
This->offset = (DWORD)mov_pos;
|
|
|
|
|
2008-04-16 05:39:36 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
static HRESULT AVISplitter_ProcessStreamList(AVISplitterImpl * This, const BYTE * pData, DWORD cb, ALLOCATOR_PROPERTIES *props)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
|
|
|
PIN_INFO piOutput;
|
2004-11-30 22:38:57 +01:00
|
|
|
const RIFFCHUNK * pChunk;
|
2003-11-18 21:47:48 +01:00
|
|
|
HRESULT hr;
|
|
|
|
AM_MEDIA_TYPE amt;
|
|
|
|
float fSamplesPerSec = 0.0f;
|
|
|
|
DWORD dwSampleSize = 0;
|
|
|
|
DWORD dwLength = 0;
|
2008-07-05 03:44:14 +02:00
|
|
|
DWORD nstdindex = 0;
|
2003-11-18 21:47:48 +01:00
|
|
|
static const WCHAR wszStreamTemplate[] = {'S','t','r','e','a','m',' ','%','0','2','d',0};
|
2008-03-19 00:05:00 +01:00
|
|
|
StreamData *stream;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
|
|
|
ZeroMemory(&amt, sizeof(amt));
|
|
|
|
piOutput.dir = PINDIR_OUTPUT;
|
|
|
|
piOutput.pFilter = (IBaseFilter *)This;
|
2005-02-08 14:43:59 +01:00
|
|
|
wsprintfW(piOutput.achName, wszStreamTemplate, This->Parser.cStreams);
|
2008-04-17 03:23:50 +02:00
|
|
|
This->streams = CoTaskMemRealloc(This->streams, sizeof(StreamData) * (This->Parser.cStreams+1));
|
|
|
|
stream = This->streams + This->Parser.cStreams;
|
2008-07-05 03:44:14 +02:00
|
|
|
ZeroMemory(stream, sizeof(*stream));
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2004-11-30 22:38:57 +01:00
|
|
|
for (pChunk = (const RIFFCHUNK *)pData;
|
|
|
|
((const BYTE *)pChunk >= pData) && ((const BYTE *)pChunk + sizeof(RIFFCHUNK) < pData + cb) && (pChunk->cb > 0);
|
|
|
|
pChunk = (const RIFFCHUNK *)((const BYTE*)pChunk + sizeof(RIFFCHUNK) + pChunk->cb)
|
|
|
|
)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
|
|
|
switch (pChunk->fcc)
|
|
|
|
{
|
|
|
|
case ckidSTREAMHEADER:
|
|
|
|
{
|
|
|
|
const AVISTREAMHEADER * pStrHdr = (const AVISTREAMHEADER *)pChunk;
|
|
|
|
TRACE("processing stream header\n");
|
2008-04-17 03:23:50 +02:00
|
|
|
stream->streamheader = *pStrHdr;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
|
|
|
fSamplesPerSec = (float)pStrHdr->dwRate / (float)pStrHdr->dwScale;
|
2008-04-17 20:33:35 +02:00
|
|
|
CoTaskMemFree(amt.pbFormat);
|
|
|
|
amt.pbFormat = NULL;
|
|
|
|
amt.cbFormat = 0;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
|
|
|
switch (pStrHdr->fccType)
|
|
|
|
{
|
|
|
|
case streamtypeVIDEO:
|
2008-03-12 21:32:07 +01:00
|
|
|
amt.formattype = FORMAT_VideoInfo;
|
2003-11-18 21:47:48 +01:00
|
|
|
break;
|
|
|
|
case streamtypeAUDIO:
|
2008-03-12 21:32:07 +01:00
|
|
|
amt.formattype = FORMAT_WaveFormatEx;
|
2003-11-18 21:47:48 +01:00
|
|
|
break;
|
|
|
|
default:
|
2010-03-26 21:53:36 +01:00
|
|
|
FIXME("fccType %.4s not handled yet\n", (const char *)&pStrHdr->fccType);
|
2008-03-12 21:32:07 +01:00
|
|
|
amt.formattype = FORMAT_None;
|
2003-11-18 21:47:48 +01:00
|
|
|
}
|
2008-03-12 21:32:07 +01:00
|
|
|
amt.majortype = MEDIATYPE_Video;
|
2003-11-18 21:47:48 +01:00
|
|
|
amt.majortype.Data1 = pStrHdr->fccType;
|
2008-03-12 21:32:07 +01:00
|
|
|
amt.subtype = MEDIATYPE_Video;
|
2003-11-18 21:47:48 +01:00
|
|
|
amt.subtype.Data1 = pStrHdr->fccHandler;
|
2004-11-30 22:38:57 +01:00
|
|
|
TRACE("Subtype FCC: %.04s\n", (LPCSTR)&pStrHdr->fccHandler);
|
2003-11-18 21:47:48 +01:00
|
|
|
amt.lSampleSize = pStrHdr->dwSampleSize;
|
|
|
|
amt.bFixedSizeSamples = (amt.lSampleSize != 0);
|
|
|
|
|
|
|
|
/* FIXME: Is this right? */
|
|
|
|
if (!amt.lSampleSize)
|
|
|
|
{
|
|
|
|
amt.lSampleSize = 1;
|
|
|
|
dwSampleSize = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
amt.bTemporalCompression = IsEqualGUID(&amt.majortype, &MEDIATYPE_Video); /* FIXME? */
|
|
|
|
dwSampleSize = pStrHdr->dwSampleSize;
|
|
|
|
dwLength = pStrHdr->dwLength;
|
|
|
|
if (!dwLength)
|
|
|
|
dwLength = This->AviHeader.dwTotalFrames;
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
if (pStrHdr->dwSuggestedBufferSize && pStrHdr->dwSuggestedBufferSize > props->cbBuffer)
|
|
|
|
props->cbBuffer = pStrHdr->dwSuggestedBufferSize;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ckidSTREAMFORMAT:
|
|
|
|
TRACE("processing stream format data\n");
|
|
|
|
if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo))
|
|
|
|
{
|
|
|
|
VIDEOINFOHEADER * pvi;
|
|
|
|
/* biCompression member appears to override the value in the stream header.
|
|
|
|
* i.e. the stream header can say something completely contradictory to what
|
|
|
|
* is in the BITMAPINFOHEADER! */
|
|
|
|
if (pChunk->cb < sizeof(BITMAPINFOHEADER))
|
|
|
|
{
|
|
|
|
ERR("Not enough bytes for BITMAPINFOHEADER\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
amt.cbFormat = sizeof(VIDEOINFOHEADER) - sizeof(BITMAPINFOHEADER) + pChunk->cb;
|
|
|
|
amt.pbFormat = CoTaskMemAlloc(amt.cbFormat);
|
|
|
|
ZeroMemory(amt.pbFormat, amt.cbFormat);
|
|
|
|
pvi = (VIDEOINFOHEADER *)amt.pbFormat;
|
|
|
|
pvi->AvgTimePerFrame = (LONGLONG)(10000000.0 / fSamplesPerSec);
|
2008-07-05 03:44:14 +02:00
|
|
|
|
2009-01-29 11:14:55 +01:00
|
|
|
CopyMemory(&pvi->bmiHeader, pChunk + 1, pChunk->cb);
|
2003-11-18 21:47:48 +01:00
|
|
|
if (pvi->bmiHeader.biCompression)
|
|
|
|
amt.subtype.Data1 = pvi->bmiHeader.biCompression;
|
|
|
|
}
|
2008-07-14 23:22:09 +02:00
|
|
|
else if (IsEqualIID(&amt.formattype, &FORMAT_WaveFormatEx))
|
|
|
|
{
|
|
|
|
amt.cbFormat = pChunk->cb;
|
|
|
|
if (amt.cbFormat < sizeof(WAVEFORMATEX))
|
|
|
|
amt.cbFormat = sizeof(WAVEFORMATEX);
|
|
|
|
amt.pbFormat = CoTaskMemAlloc(amt.cbFormat);
|
|
|
|
ZeroMemory(amt.pbFormat, amt.cbFormat);
|
2009-01-29 11:14:55 +01:00
|
|
|
CopyMemory(amt.pbFormat, pChunk + 1, pChunk->cb);
|
2008-07-14 23:22:09 +02:00
|
|
|
}
|
2003-11-18 21:47:48 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
amt.cbFormat = pChunk->cb;
|
|
|
|
amt.pbFormat = CoTaskMemAlloc(amt.cbFormat);
|
2009-01-29 11:14:55 +01:00
|
|
|
CopyMemory(amt.pbFormat, pChunk + 1, amt.cbFormat);
|
2003-11-18 21:47:48 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ckidSTREAMNAME:
|
|
|
|
TRACE("processing stream name\n");
|
|
|
|
/* FIXME: this doesn't exactly match native version (we omit the "##)" prefix), but hey... */
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(pChunk + 1), pChunk->cb, piOutput.achName, sizeof(piOutput.achName) / sizeof(piOutput.achName[0]));
|
|
|
|
break;
|
|
|
|
case ckidSTREAMHANDLERDATA:
|
|
|
|
FIXME("process stream handler data\n");
|
|
|
|
break;
|
2008-04-11 00:45:32 +02:00
|
|
|
case ckidAVIPADDING:
|
2003-11-18 21:47:48 +01:00
|
|
|
TRACE("JUNK chunk ignored\n");
|
|
|
|
break;
|
2008-04-11 23:02:26 +02:00
|
|
|
case ckidAVISUPERINDEX:
|
|
|
|
{
|
|
|
|
const AVISUPERINDEX *pIndex = (const AVISUPERINDEX *)pChunk;
|
2008-11-03 23:45:48 +01:00
|
|
|
DWORD x;
|
2010-05-20 01:14:09 +02:00
|
|
|
UINT rest = pIndex->cb - sizeof(AVISUPERINDEX) + sizeof(RIFFCHUNK) + sizeof(pIndex->aIndex[0]) * ANYSIZE_ARRAY;
|
2008-04-11 23:02:26 +02:00
|
|
|
|
|
|
|
if (pIndex->cb < sizeof(AVISUPERINDEX) - sizeof(RIFFCHUNK))
|
|
|
|
{
|
2008-04-17 20:17:03 +02:00
|
|
|
FIXME("size %u\n", pIndex->cb);
|
2008-04-11 23:02:26 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
if (nstdindex++ > 0)
|
2008-04-16 23:29:09 +02:00
|
|
|
{
|
2008-05-06 15:54:52 +02:00
|
|
|
ERR("Stream %d got more than 1 superindex?\n", This->Parser.cStreams);
|
2008-04-16 23:29:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-11 23:02:26 +02:00
|
|
|
TRACE("wLongsPerEntry: %hd\n", pIndex->wLongsPerEntry);
|
2010-09-20 10:48:49 +02:00
|
|
|
TRACE("bIndexSubType: %u\n", pIndex->bIndexSubType);
|
|
|
|
TRACE("bIndexType: %u\n", pIndex->bIndexType);
|
2008-04-11 23:02:26 +02:00
|
|
|
TRACE("nEntriesInUse: %u\n", pIndex->nEntriesInUse);
|
2010-03-26 21:53:36 +01:00
|
|
|
TRACE("dwChunkId: %.4s\n", (const char *)&pIndex->dwChunkId);
|
2008-04-11 23:02:26 +02:00
|
|
|
if (pIndex->dwReserved[0])
|
|
|
|
TRACE("dwReserved[0]: %u\n", pIndex->dwReserved[0]);
|
|
|
|
if (pIndex->dwReserved[2])
|
|
|
|
TRACE("dwReserved[1]: %u\n", pIndex->dwReserved[1]);
|
|
|
|
if (pIndex->dwReserved[2])
|
|
|
|
TRACE("dwReserved[2]: %u\n", pIndex->dwReserved[2]);
|
|
|
|
|
|
|
|
if (pIndex->bIndexType != AVI_INDEX_OF_INDEXES
|
|
|
|
|| pIndex->wLongsPerEntry != 4
|
|
|
|
|| rest < (pIndex->nEntriesInUse * sizeof(DWORD) * pIndex->wLongsPerEntry)
|
|
|
|
|| (pIndex->bIndexSubType != AVI_INDEX_SUB_2FIELD && pIndex->bIndexSubType != AVI_INDEX_SUB_DEFAULT))
|
|
|
|
{
|
|
|
|
FIXME("Invalid index chunk encountered\n");
|
|
|
|
break;
|
|
|
|
}
|
2008-04-16 23:29:09 +02:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
stream->entries = pIndex->nEntriesInUse;
|
|
|
|
stream->stdindex = CoTaskMemRealloc(stream->stdindex, sizeof(*stream->stdindex) * stream->entries);
|
2008-04-11 23:02:26 +02:00
|
|
|
for (x = 0; x < pIndex->nEntriesInUse; ++x)
|
|
|
|
{
|
|
|
|
TRACE("qwOffset: %x%08x\n", (DWORD)(pIndex->aIndex[x].qwOffset >> 32), (DWORD)pIndex->aIndex[x].qwOffset);
|
|
|
|
TRACE("dwSize: %u\n", pIndex->aIndex[x].dwSize);
|
|
|
|
TRACE("dwDuration: %u (unreliable)\n", pIndex->aIndex[x].dwDuration);
|
2008-04-16 23:29:09 +02:00
|
|
|
|
2008-07-24 22:08:09 +02:00
|
|
|
AVISplitter_ProcessIndex(This, &stream->stdindex[x], pIndex->aIndex[x].qwOffset, pIndex->aIndex[x].dwSize);
|
2008-04-11 23:02:26 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-11-18 21:47:48 +01:00
|
|
|
default:
|
2004-11-30 22:38:57 +01:00
|
|
|
FIXME("unknown chunk type \"%.04s\" ignored\n", (LPCSTR)&pChunk->fcc);
|
2003-11-18 21:47:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsEqualGUID(&amt.formattype, &FORMAT_WaveFormatEx))
|
|
|
|
{
|
2008-03-12 21:32:07 +01:00
|
|
|
amt.subtype = MEDIATYPE_Video;
|
2003-11-18 21:47:48 +01:00
|
|
|
amt.subtype.Data1 = ((WAVEFORMATEX *)amt.pbFormat)->wFormatTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_AM_MEDIA_TYPE(&amt);
|
2005-01-03 21:23:14 +01:00
|
|
|
TRACE("fSamplesPerSec = %f\n", (double)fSamplesPerSec);
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("dwSampleSize = %x\n", dwSampleSize);
|
|
|
|
TRACE("dwLength = %x\n", dwLength);
|
2008-04-16 23:29:09 +02:00
|
|
|
|
2008-03-19 00:05:00 +01:00
|
|
|
stream->fSamplesPerSec = fSamplesPerSec;
|
|
|
|
stream->dwSampleSize = dwSampleSize;
|
|
|
|
stream->dwLength = dwLength; /* TODO: Use this for mediaseeking */
|
2008-07-05 03:44:14 +02:00
|
|
|
stream->packet_queued = CreateEventW(NULL, 0, 0, NULL);
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
hr = Parser_AddPin(&(This->Parser), &piOutput, props, &amt);
|
2008-04-16 05:39:36 +02:00
|
|
|
CoTaskMemFree(amt.pbFormat);
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
|
2003-11-18 21:47:48 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-04-11 23:02:26 +02:00
|
|
|
static HRESULT AVISplitter_ProcessODML(AVISplitterImpl * This, const BYTE * pData, DWORD cb)
|
|
|
|
{
|
|
|
|
const RIFFCHUNK * pChunk;
|
|
|
|
|
|
|
|
for (pChunk = (const RIFFCHUNK *)pData;
|
|
|
|
((const BYTE *)pChunk >= pData) && ((const BYTE *)pChunk + sizeof(RIFFCHUNK) < pData + cb) && (pChunk->cb > 0);
|
|
|
|
pChunk = (const RIFFCHUNK *)((const BYTE*)pChunk + sizeof(RIFFCHUNK) + pChunk->cb)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
switch (pChunk->fcc)
|
|
|
|
{
|
|
|
|
case ckidAVIEXTHEADER:
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
const AVIEXTHEADER * pExtHdr = (const AVIEXTHEADER *)pChunk;
|
|
|
|
|
|
|
|
TRACE("processing extension header\n");
|
|
|
|
if (pExtHdr->cb != sizeof(AVIEXTHEADER) - sizeof(RIFFCHUNK))
|
|
|
|
{
|
2008-04-17 20:17:03 +02:00
|
|
|
FIXME("Size: %u\n", pExtHdr->cb);
|
2008-04-11 23:02:26 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
TRACE("dwGrandFrames: %u\n", pExtHdr->dwGrandFrames);
|
|
|
|
for (x = 0; x < 61; ++x)
|
|
|
|
if (pExtHdr->dwFuture[x])
|
|
|
|
FIXME("dwFuture[%i] = %u (0x%08x)\n", x, pExtHdr->dwFuture[x], pExtHdr->dwFuture[x]);
|
2008-04-16 05:39:36 +02:00
|
|
|
This->ExtHeader = *pExtHdr;
|
2008-04-11 23:02:26 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME("unknown chunk type \"%.04s\" ignored\n", (LPCSTR)&pChunk->fcc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-17 03:23:50 +02:00
|
|
|
static HRESULT AVISplitter_InitializeStreams(AVISplitterImpl *This)
|
|
|
|
{
|
2008-11-03 23:45:48 +01:00
|
|
|
unsigned int x;
|
2008-04-17 03:23:50 +02:00
|
|
|
|
|
|
|
if (This->oldindex)
|
|
|
|
{
|
|
|
|
DWORD nMax, n;
|
|
|
|
|
|
|
|
for (x = 0; x < This->Parser.cStreams; ++x)
|
|
|
|
{
|
|
|
|
This->streams[x].frames = 0;
|
2008-07-05 03:44:14 +02:00
|
|
|
This->streams[x].pos = ~0;
|
|
|
|
This->streams[x].index = 0;
|
2008-04-17 03:23:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
nMax = This->oldindex->cb / sizeof(This->oldindex->aIndex[0]);
|
|
|
|
|
2010-07-25 03:21:26 +02:00
|
|
|
/* Ok, maybe this is more of an exercise to see if I interpret everything correctly or not, but that is useful for now. */
|
2008-04-17 03:23:50 +02:00
|
|
|
for (n = 0; n < nMax; ++n)
|
|
|
|
{
|
|
|
|
DWORD streamId = StreamFromFOURCC(This->oldindex->aIndex[n].dwChunkId);
|
|
|
|
if (streamId >= This->Parser.cStreams)
|
|
|
|
{
|
|
|
|
FIXME("Stream id %s ignored\n", debugstr_an((char*)&This->oldindex->aIndex[n].dwChunkId, 4));
|
|
|
|
continue;
|
|
|
|
}
|
2008-11-03 23:45:48 +01:00
|
|
|
if (This->streams[streamId].pos == ~0U)
|
2008-07-05 03:44:14 +02:00
|
|
|
This->streams[streamId].pos = n;
|
2008-04-17 03:23:50 +02:00
|
|
|
|
|
|
|
if (This->streams[streamId].streamheader.dwSampleSize)
|
|
|
|
This->streams[streamId].frames += This->oldindex->aIndex[n].dwSize / This->streams[streamId].streamheader.dwSampleSize;
|
|
|
|
else
|
|
|
|
++This->streams[streamId].frames;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (x = 0; x < This->Parser.cStreams; ++x)
|
|
|
|
{
|
|
|
|
if ((DWORD)This->streams[x].frames != This->streams[x].streamheader.dwLength)
|
|
|
|
{
|
|
|
|
FIXME("stream %u: frames found: %u, frames meant to be found: %u\n", x, (DWORD)This->streams[x].frames, This->streams[x].streamheader.dwLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (!This->streams[0].entries)
|
|
|
|
{
|
|
|
|
for (x = 0; x < This->Parser.cStreams; ++x)
|
|
|
|
{
|
|
|
|
This->streams[x].frames = This->streams[x].streamheader.dwLength;
|
|
|
|
}
|
2008-07-05 03:44:14 +02:00
|
|
|
/* MS Avi splitter does seek through the whole file, we should! */
|
|
|
|
ERR("We should be manually seeking through the entire file to build an index, because the index is missing!!!\n");
|
|
|
|
return E_NOTIMPL;
|
2008-04-17 03:23:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Not much here yet */
|
|
|
|
for (x = 0; x < This->Parser.cStreams; ++x)
|
|
|
|
{
|
|
|
|
StreamData *stream = This->streams + x;
|
2008-11-03 23:45:48 +01:00
|
|
|
DWORD y;
|
2008-04-17 03:23:50 +02:00
|
|
|
DWORD64 frames = 0;
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
stream->seek = 1;
|
|
|
|
|
2008-04-17 03:23:50 +02:00
|
|
|
if (stream->stdindex)
|
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
stream->index = 0;
|
|
|
|
stream->pos = 0;
|
2008-04-17 03:23:50 +02:00
|
|
|
for (y = 0; y < stream->entries; ++y)
|
|
|
|
{
|
2008-07-05 03:44:14 +02:00
|
|
|
if (stream->streamheader.dwSampleSize)
|
|
|
|
{
|
2008-11-03 23:45:48 +01:00
|
|
|
DWORD z;
|
2008-07-05 03:44:14 +02:00
|
|
|
|
|
|
|
for (z = 0; z < stream->stdindex[y]->nEntriesInUse; ++z)
|
|
|
|
{
|
|
|
|
UINT len = stream->stdindex[y]->aIndex[z].dwSize & ~(1 << 31);
|
|
|
|
frames += len / stream->streamheader.dwSampleSize + !!(len % stream->streamheader.dwSampleSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
frames += stream->stdindex[y]->nEntriesInUse;
|
2008-04-17 03:23:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else frames = stream->frames;
|
|
|
|
|
|
|
|
frames *= stream->streamheader.dwScale;
|
|
|
|
/* Keep accuracy as high as possible for duration */
|
2010-10-11 17:15:35 +02:00
|
|
|
This->Parser.sourceSeeking.llDuration = frames * 10000000;
|
|
|
|
This->Parser.sourceSeeking.llDuration /= stream->streamheader.dwRate;
|
|
|
|
This->Parser.sourceSeeking.llStop = This->Parser.sourceSeeking.llDuration;
|
|
|
|
This->Parser.sourceSeeking.llCurrent = 0;
|
2008-04-17 03:23:50 +02:00
|
|
|
|
|
|
|
frames /= stream->streamheader.dwRate;
|
|
|
|
|
2008-07-22 17:04:20 +02:00
|
|
|
TRACE("Duration: %d days, %d hours, %d minutes and %d.%03u seconds\n", (DWORD)(frames / 86400),
|
|
|
|
(DWORD)((frames % 86400) / 3600), (DWORD)((frames % 3600) / 60), (DWORD)(frames % 60),
|
2010-10-11 17:15:35 +02:00
|
|
|
(DWORD)(This->Parser.sourceSeeking.llDuration/10000) % 1000);
|
2008-04-17 03:23:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT AVISplitter_Disconnect(LPVOID iface);
|
|
|
|
|
2003-11-18 21:47:48 +01:00
|
|
|
/* FIXME: fix leaks on failure here */
|
2008-04-22 22:57:11 +02:00
|
|
|
static HRESULT AVISplitter_InputPin_PreConnect(IPin * iface, IPin * pConnectPin, ALLOCATOR_PROPERTIES *props)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
PullPin *This = (PullPin *)iface;
|
2003-11-18 21:47:48 +01:00
|
|
|
HRESULT hr;
|
|
|
|
RIFFLIST list;
|
|
|
|
LONGLONG pos = 0; /* in bytes */
|
|
|
|
BYTE * pBuffer;
|
|
|
|
RIFFCHUNK * pCurrentChunk;
|
2008-04-12 02:58:47 +02:00
|
|
|
LONGLONG total, avail;
|
2008-11-03 23:45:48 +01:00
|
|
|
ULONG x;
|
2008-04-17 03:23:50 +02:00
|
|
|
DWORD indexes;
|
2008-04-12 02:58:47 +02:00
|
|
|
|
2005-02-08 14:43:59 +01:00
|
|
|
AVISplitterImpl * pAviSplit = (AVISplitterImpl *)This->pin.pinInfo.pFilter;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
|
|
|
hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(list), (BYTE *)&list);
|
|
|
|
pos += sizeof(list);
|
|
|
|
|
2008-04-11 00:45:32 +02:00
|
|
|
if (list.fcc != FOURCC_RIFF)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
|
|
|
ERR("Input stream not a RIFF file\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2008-04-11 00:45:32 +02:00
|
|
|
if (list.fccListType != formtypeAVI)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
|
|
|
ERR("Input stream not an AVI RIFF file\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(list), (BYTE *)&list);
|
2008-04-11 00:45:32 +02:00
|
|
|
if (list.fcc != FOURCC_LIST)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
|
|
|
ERR("Expected LIST chunk, but got %.04s\n", (LPSTR)&list.fcc);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2008-04-11 00:45:32 +02:00
|
|
|
if (list.fccListType != listtypeAVIHEADER)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
|
|
|
ERR("Header list expected. Got: %.04s\n", (LPSTR)&list.fccListType);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pBuffer = HeapAlloc(GetProcessHeap(), 0, list.cb - sizeof(RIFFLIST) + sizeof(RIFFCHUNK));
|
|
|
|
hr = IAsyncReader_SyncRead(This->pReader, pos + sizeof(list), list.cb - sizeof(RIFFLIST) + sizeof(RIFFCHUNK), pBuffer);
|
|
|
|
|
|
|
|
pAviSplit->AviHeader.cb = 0;
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
/* Stream list will set the buffer size here, so set a default and allow an override */
|
|
|
|
props->cbBuffer = 0x20000;
|
|
|
|
|
2003-11-18 21:47:48 +01:00
|
|
|
for (pCurrentChunk = (RIFFCHUNK *)pBuffer; (BYTE *)pCurrentChunk + sizeof(*pCurrentChunk) < pBuffer + list.cb; pCurrentChunk = (RIFFCHUNK *)(((BYTE *)pCurrentChunk) + sizeof(*pCurrentChunk) + pCurrentChunk->cb))
|
|
|
|
{
|
|
|
|
RIFFLIST * pList;
|
|
|
|
|
|
|
|
switch (pCurrentChunk->fcc)
|
|
|
|
{
|
|
|
|
case ckidMAINAVIHEADER:
|
|
|
|
/* AVIMAINHEADER includes the structure that is pCurrentChunk at the moment */
|
|
|
|
memcpy(&pAviSplit->AviHeader, pCurrentChunk, sizeof(pAviSplit->AviHeader));
|
|
|
|
break;
|
2008-04-11 00:45:32 +02:00
|
|
|
case FOURCC_LIST:
|
2003-11-18 21:47:48 +01:00
|
|
|
pList = (RIFFLIST *)pCurrentChunk;
|
|
|
|
switch (pList->fccListType)
|
|
|
|
{
|
|
|
|
case ckidSTREAMLIST:
|
2008-07-05 03:44:14 +02:00
|
|
|
hr = AVISplitter_ProcessStreamList(pAviSplit, (BYTE *)pCurrentChunk + sizeof(RIFFLIST), pCurrentChunk->cb + sizeof(RIFFCHUNK) - sizeof(RIFFLIST), props);
|
2003-11-18 21:47:48 +01:00
|
|
|
break;
|
|
|
|
case ckidODML:
|
2008-04-11 23:02:26 +02:00
|
|
|
hr = AVISplitter_ProcessODML(pAviSplit, (BYTE *)pCurrentChunk + sizeof(RIFFLIST), pCurrentChunk->cb + sizeof(RIFFCHUNK) - sizeof(RIFFLIST));
|
2003-11-18 21:47:48 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2008-04-11 00:45:32 +02:00
|
|
|
case ckidAVIPADDING:
|
2003-11-18 21:47:48 +01:00
|
|
|
/* ignore */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unrecognised header list type: %.04s\n", (LPSTR)&pCurrentChunk->fcc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, pBuffer);
|
|
|
|
|
|
|
|
if (pAviSplit->AviHeader.cb != sizeof(pAviSplit->AviHeader) - sizeof(RIFFCHUNK))
|
|
|
|
{
|
|
|
|
ERR("Avi Header wrong size!\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos += sizeof(RIFFCHUNK) + list.cb;
|
|
|
|
hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(list), (BYTE *)&list);
|
|
|
|
|
2008-12-19 01:47:09 +01:00
|
|
|
while (list.fcc == ckidAVIPADDING || (list.fcc == FOURCC_LIST && list.fccListType != listtypeAVIMOVIE))
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
|
|
|
pos += sizeof(RIFFCHUNK) + list.cb;
|
2008-04-12 02:58:47 +02:00
|
|
|
|
2003-11-18 21:47:48 +01:00
|
|
|
hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(list), (BYTE *)&list);
|
|
|
|
}
|
|
|
|
|
2008-04-11 00:45:32 +02:00
|
|
|
if (list.fcc != FOURCC_LIST)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
|
|
|
ERR("Expected LIST, but got %.04s\n", (LPSTR)&list.fcc);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2008-04-11 00:45:32 +02:00
|
|
|
if (list.fccListType != listtypeAVIMOVIE)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
|
|
|
ERR("Expected AVI movie list, but got %.04s\n", (LPSTR)&list.fccListType);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2008-04-12 02:58:47 +02:00
|
|
|
IAsyncReader_Length(This->pReader, &total, &avail);
|
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
/* FIXME: AVIX files are extended beyond the FOURCC chunk "AVI ", and thus won't be played here,
|
|
|
|
* once I get one of the files I'll try to fix it */
|
2003-11-18 21:47:48 +01:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2008-04-12 02:58:47 +02:00
|
|
|
This->rtStart = pAviSplit->CurrentChunkOffset = MEDIATIME_FROM_BYTES(pos + sizeof(RIFFLIST));
|
|
|
|
pos += list.cb + sizeof(RIFFCHUNK);
|
|
|
|
|
|
|
|
pAviSplit->EndOfFile = This->rtStop = MEDIATIME_FROM_BYTES(pos);
|
|
|
|
if (pos > total)
|
|
|
|
{
|
|
|
|
ERR("File smaller (%x%08x) then EndOfFile (%x%08x)\n", (DWORD)(total >> 32), (DWORD)total, (DWORD)(pAviSplit->EndOfFile >> 32), (DWORD)pAviSplit->EndOfFile);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2003-11-18 21:47:48 +01:00
|
|
|
hr = IAsyncReader_SyncRead(This->pReader, BYTES_FROM_MEDIATIME(pAviSplit->CurrentChunkOffset), sizeof(pAviSplit->CurrentChunk), (BYTE *)&pAviSplit->CurrentChunk);
|
|
|
|
}
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
props->cbAlign = 1;
|
|
|
|
props->cbPrefix = 0;
|
|
|
|
/* Comrades, prevent shortage of buffers, or you will feel the consequences! DA! */
|
2008-07-11 20:20:47 +02:00
|
|
|
props->cBuffers = 2 * pAviSplit->Parser.cStreams;
|
2008-07-05 03:44:14 +02:00
|
|
|
|
2008-04-12 02:58:47 +02:00
|
|
|
/* Now peek into the idx1 index, if available */
|
|
|
|
if (hr == S_OK && (total - pos) > sizeof(RIFFCHUNK))
|
|
|
|
{
|
|
|
|
memset(&list, 0, sizeof(list));
|
|
|
|
|
|
|
|
hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(list), (BYTE *)&list);
|
|
|
|
if (list.fcc == ckidAVIOLDINDEX)
|
|
|
|
{
|
2008-04-16 05:39:36 +02:00
|
|
|
pAviSplit->oldindex = CoTaskMemRealloc(pAviSplit->oldindex, list.cb + sizeof(RIFFCHUNK));
|
2008-04-17 03:23:50 +02:00
|
|
|
if (pAviSplit->oldindex)
|
2008-04-16 05:39:36 +02:00
|
|
|
{
|
2008-04-17 03:23:50 +02:00
|
|
|
hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(RIFFCHUNK) + list.cb, (BYTE *)pAviSplit->oldindex);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = AVISplitter_ProcessOldIndex(pAviSplit);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CoTaskMemFree(pAviSplit->oldindex);
|
|
|
|
pAviSplit->oldindex = NULL;
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
2008-04-12 02:58:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-17 03:23:50 +02:00
|
|
|
indexes = 0;
|
|
|
|
for (x = 0; x < pAviSplit->Parser.cStreams; ++x)
|
|
|
|
if (pAviSplit->streams[x].entries)
|
|
|
|
++indexes;
|
|
|
|
|
|
|
|
if (indexes)
|
|
|
|
{
|
|
|
|
CoTaskMemFree(pAviSplit->oldindex);
|
|
|
|
pAviSplit->oldindex = NULL;
|
|
|
|
if (indexes < pAviSplit->Parser.cStreams)
|
|
|
|
{
|
|
|
|
/* This error could possible be survived by switching to old type index,
|
|
|
|
* but I would rather find out why it doesn't find everything here
|
|
|
|
*/
|
|
|
|
ERR("%d indexes expected, but only have %d\n", indexes, pAviSplit->Parser.cStreams);
|
|
|
|
indexes = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!indexes && pAviSplit->oldindex)
|
|
|
|
indexes = pAviSplit->Parser.cStreams;
|
|
|
|
|
|
|
|
if (!indexes && pAviSplit->AviHeader.dwFlags & AVIF_MUSTUSEINDEX)
|
|
|
|
{
|
|
|
|
FIXME("No usable index was found!\n");
|
|
|
|
hr = E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, set up the streams */
|
|
|
|
if (hr == S_OK)
|
|
|
|
hr = AVISplitter_InitializeStreams(pAviSplit);
|
|
|
|
|
2003-11-18 21:47:48 +01:00
|
|
|
if (hr != S_OK)
|
2008-04-17 03:23:50 +02:00
|
|
|
{
|
|
|
|
AVISplitter_Disconnect(pAviSplit);
|
2003-11-18 21:47:48 +01:00
|
|
|
return E_FAIL;
|
2008-04-17 03:23:50 +02:00
|
|
|
}
|
2003-11-18 21:47:48 +01:00
|
|
|
|
|
|
|
TRACE("AVI File ok\n");
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
static HRESULT AVISplitter_Flush(LPVOID iface)
|
2007-04-07 06:24:59 +02:00
|
|
|
{
|
2009-01-29 11:14:55 +01:00
|
|
|
AVISplitterImpl *This = iface;
|
2008-07-05 03:44:14 +02:00
|
|
|
DWORD x;
|
2007-04-07 06:24:59 +02:00
|
|
|
|
2008-12-07 12:09:43 +01:00
|
|
|
TRACE("(%p)->()\n", This);
|
2008-07-05 03:44:14 +02:00
|
|
|
|
|
|
|
for (x = 0; x < This->Parser.cStreams; ++x)
|
|
|
|
{
|
|
|
|
StreamData *stream = This->streams + x;
|
|
|
|
|
|
|
|
if (stream->sample)
|
|
|
|
assert(IMediaSample_Release(stream->sample) == 0);
|
|
|
|
stream->sample = NULL;
|
2007-04-07 06:24:59 +02:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
ResetEvent(stream->packet_queued);
|
|
|
|
assert(!stream->thread);
|
|
|
|
}
|
2007-04-07 06:24:59 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-16 05:39:36 +02:00
|
|
|
static HRESULT AVISplitter_Disconnect(LPVOID iface)
|
|
|
|
{
|
|
|
|
AVISplitterImpl *This = iface;
|
2008-11-03 23:45:48 +01:00
|
|
|
ULONG x;
|
2008-04-16 05:39:36 +02:00
|
|
|
|
|
|
|
/* TODO: Remove other memory that's allocated during connect */
|
|
|
|
CoTaskMemFree(This->oldindex);
|
|
|
|
This->oldindex = NULL;
|
|
|
|
|
2008-04-16 23:29:09 +02:00
|
|
|
for (x = 0; x < This->Parser.cStreams; ++x)
|
|
|
|
{
|
2008-11-03 23:45:48 +01:00
|
|
|
DWORD i;
|
2008-04-16 23:29:09 +02:00
|
|
|
|
|
|
|
StreamData *stream = &This->streams[x];
|
|
|
|
|
|
|
|
for (i = 0; i < stream->entries; ++i)
|
|
|
|
CoTaskMemFree(stream->stdindex[i]);
|
|
|
|
|
|
|
|
CoTaskMemFree(stream->stdindex);
|
2008-07-05 03:44:14 +02:00
|
|
|
CloseHandle(stream->packet_queued);
|
2008-04-16 23:29:09 +02:00
|
|
|
}
|
|
|
|
CoTaskMemFree(This->streams);
|
2008-04-17 03:23:50 +02:00
|
|
|
This->streams = NULL;
|
2008-07-05 03:44:14 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AVISplitter_Release(IBaseFilter *iface)
|
|
|
|
{
|
|
|
|
AVISplitterImpl *This = (AVISplitterImpl *)iface;
|
|
|
|
ULONG ref;
|
|
|
|
|
2010-10-07 21:47:33 +02:00
|
|
|
ref = InterlockedDecrement(&This->Parser.filter.refCount);
|
2008-07-05 03:44:14 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->() Release from %d\n", This, ref + 1);
|
|
|
|
|
|
|
|
if (!ref)
|
|
|
|
{
|
|
|
|
AVISplitter_Flush(This);
|
|
|
|
Parser_Destroy(&This->Parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2010-10-11 17:15:35 +02:00
|
|
|
static HRESULT WINAPI AVISplitter_seek(IMediaSeeking *iface)
|
2008-07-05 03:44:14 +02:00
|
|
|
{
|
2010-10-11 17:15:35 +02:00
|
|
|
AVISplitterImpl *This = impl_from_IMediaSeeking(iface);
|
2008-07-05 03:44:14 +02:00
|
|
|
PullPin *pPin = This->Parser.pInputPin;
|
|
|
|
LONGLONG newpos, endpos;
|
|
|
|
DWORD x;
|
|
|
|
|
2010-10-11 17:15:35 +02:00
|
|
|
newpos = This->Parser.sourceSeeking.llCurrent;
|
|
|
|
endpos = This->Parser.sourceSeeking.llDuration;
|
2008-07-05 03:44:14 +02:00
|
|
|
|
|
|
|
if (newpos > endpos)
|
|
|
|
{
|
|
|
|
WARN("Requesting position %x%08x beyond end of stream %x%08x\n", (DWORD)(newpos>>32), (DWORD)newpos, (DWORD)(endpos>>32), (DWORD)endpos);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("Moving position to %u.%03u s!\n", (DWORD)(newpos / 10000000), (DWORD)((newpos / 10000)%1000));
|
|
|
|
|
|
|
|
EnterCriticalSection(&pPin->thread_lock);
|
|
|
|
/* Send a flush to all output pins */
|
|
|
|
IPin_BeginFlush((IPin *)pPin);
|
|
|
|
|
|
|
|
/* Make sure this is done while stopped, BeginFlush takes care of this */
|
2010-10-07 21:47:33 +02:00
|
|
|
EnterCriticalSection(&This->Parser.filter.csFilter);
|
2008-07-05 03:44:14 +02:00
|
|
|
for (x = 0; x < This->Parser.cStreams; ++x)
|
|
|
|
{
|
|
|
|
Parser_OutputPin *pin = (Parser_OutputPin *)This->Parser.ppPins[1+x];
|
|
|
|
StreamData *stream = This->streams + x;
|
|
|
|
IPin *victim = NULL;
|
|
|
|
LONGLONG wanted_frames;
|
|
|
|
DWORD last_keyframe = 0, last_keyframeidx = 0, preroll = 0;
|
|
|
|
|
|
|
|
wanted_frames = newpos;
|
|
|
|
wanted_frames *= stream->streamheader.dwRate;
|
|
|
|
wanted_frames /= 10000000;
|
|
|
|
wanted_frames /= stream->streamheader.dwScale;
|
|
|
|
|
|
|
|
IPin_ConnectedTo((IPin *)pin, &victim);
|
|
|
|
if (victim)
|
|
|
|
{
|
|
|
|
IPin_NewSegment(victim, newpos, endpos, pPin->dRate);
|
|
|
|
IPin_Release(victim);
|
|
|
|
}
|
|
|
|
|
|
|
|
pin->dwSamplesProcessed = 0;
|
|
|
|
stream->index = 0;
|
|
|
|
stream->pos = 0;
|
|
|
|
stream->seek = 1;
|
|
|
|
if (stream->stdindex)
|
|
|
|
{
|
|
|
|
DWORD y, z = 0;
|
|
|
|
|
|
|
|
for (y = 0; y < stream->entries; ++y)
|
|
|
|
{
|
|
|
|
for (z = 0; z < stream->stdindex[y]->nEntriesInUse; ++z)
|
|
|
|
{
|
|
|
|
if (stream->streamheader.dwSampleSize)
|
|
|
|
{
|
|
|
|
ULONG len = stream->stdindex[y]->aIndex[z].dwSize & ~(1 << 31);
|
|
|
|
ULONG size = stream->streamheader.dwSampleSize;
|
|
|
|
|
|
|
|
pin->dwSamplesProcessed += len / size;
|
|
|
|
if (len % size)
|
|
|
|
++pin->dwSamplesProcessed;
|
|
|
|
}
|
|
|
|
else ++pin->dwSamplesProcessed;
|
|
|
|
|
|
|
|
if (!(stream->stdindex[y]->aIndex[z].dwSize >> 31))
|
|
|
|
{
|
|
|
|
last_keyframe = z;
|
|
|
|
last_keyframeidx = y;
|
|
|
|
preroll = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++preroll;
|
|
|
|
|
|
|
|
if (pin->dwSamplesProcessed >= wanted_frames)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (pin->dwSamplesProcessed >= wanted_frames)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
stream->index = last_keyframeidx;
|
|
|
|
stream->pos = last_keyframe;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD nMax, n;
|
|
|
|
nMax = This->oldindex->cb / sizeof(This->oldindex->aIndex[0]);
|
|
|
|
|
|
|
|
for (n = 0; n < nMax; ++n)
|
|
|
|
{
|
|
|
|
DWORD streamId = StreamFromFOURCC(This->oldindex->aIndex[n].dwChunkId);
|
|
|
|
if (streamId != x)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (stream->streamheader.dwSampleSize)
|
|
|
|
{
|
|
|
|
ULONG len = This->oldindex->aIndex[n].dwSize;
|
|
|
|
ULONG size = stream->streamheader.dwSampleSize;
|
|
|
|
|
|
|
|
pin->dwSamplesProcessed += len / size;
|
|
|
|
if (len % size)
|
|
|
|
++pin->dwSamplesProcessed;
|
|
|
|
}
|
|
|
|
else ++pin->dwSamplesProcessed;
|
|
|
|
|
|
|
|
if (This->oldindex->aIndex[n].dwFlags & AVIIF_KEYFRAME)
|
|
|
|
{
|
|
|
|
last_keyframe = n;
|
|
|
|
preroll = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++preroll;
|
|
|
|
|
|
|
|
if (pin->dwSamplesProcessed >= wanted_frames)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(n < nMax);
|
|
|
|
stream->pos = last_keyframe;
|
|
|
|
stream->index = 0;
|
|
|
|
}
|
|
|
|
stream->preroll = preroll;
|
|
|
|
stream->seek = 1;
|
|
|
|
}
|
2010-10-07 21:47:33 +02:00
|
|
|
LeaveCriticalSection(&This->Parser.filter.csFilter);
|
2008-07-05 03:44:14 +02:00
|
|
|
|
|
|
|
TRACE("Done flushing\n");
|
|
|
|
IPin_EndFlush((IPin *)pPin);
|
|
|
|
LeaveCriticalSection(&pPin->thread_lock);
|
2008-04-16 23:29:09 +02:00
|
|
|
|
2008-04-16 05:39:36 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
static const IBaseFilterVtbl AVISplitterImpl_Vtbl =
|
2008-04-23 20:23:43 +02:00
|
|
|
{
|
|
|
|
Parser_QueryInterface,
|
|
|
|
Parser_AddRef,
|
2008-07-05 03:44:14 +02:00
|
|
|
AVISplitter_Release,
|
2008-04-23 20:23:43 +02:00
|
|
|
Parser_GetClassID,
|
|
|
|
Parser_Stop,
|
|
|
|
Parser_Pause,
|
|
|
|
Parser_Run,
|
|
|
|
Parser_GetState,
|
|
|
|
Parser_SetSyncSource,
|
|
|
|
Parser_GetSyncSource,
|
|
|
|
Parser_EnumPins,
|
|
|
|
Parser_FindPin,
|
|
|
|
Parser_QueryFilterInfo,
|
|
|
|
Parser_JoinFilterGraph,
|
|
|
|
Parser_QueryVendorInfo
|
|
|
|
};
|
|
|
|
|
2005-02-08 14:43:59 +01:00
|
|
|
HRESULT AVISplitter_create(IUnknown * pUnkOuter, LPVOID * ppv)
|
2003-11-18 21:47:48 +01:00
|
|
|
{
|
2005-02-08 14:43:59 +01:00
|
|
|
HRESULT hr;
|
|
|
|
AVISplitterImpl * This;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2005-02-08 14:43:59 +01:00
|
|
|
TRACE("(%p, %p)\n", pUnkOuter, ppv);
|
2003-11-18 21:47:48 +01:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
2005-02-08 14:43:59 +01:00
|
|
|
if (pUnkOuter)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2005-02-08 14:43:59 +01:00
|
|
|
/* Note: This memory is managed by the transform filter once created */
|
|
|
|
This = CoTaskMemAlloc(sizeof(AVISplitterImpl));
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-03-19 00:05:00 +01:00
|
|
|
This->streams = NULL;
|
2008-04-16 05:39:36 +02:00
|
|
|
This->oldindex = NULL;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2008-07-05 03:44:14 +02:00
|
|
|
hr = Parser_Create(&(This->Parser), &AVISplitterImpl_Vtbl, &CLSID_AviSplitter, AVISplitter_Sample, AVISplitter_QueryAccept, AVISplitter_InputPin_PreConnect, AVISplitter_Flush, AVISplitter_Disconnect, AVISplitter_first_request, AVISplitter_done_process, NULL, AVISplitter_seek, NULL);
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2005-02-08 14:43:59 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
2009-01-29 11:14:55 +01:00
|
|
|
*ppv = This;
|
2003-11-18 21:47:48 +01:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|