void LoaderSourceFileWindowsMedia::loadData( BufferList *ioData )
{	
	HRESULT hr;
	INSSBuffer * outBuffer;
	QWORD pcnsSampleTime;
	QWORD pcnsDuration;
	DWORD pdwFlags;
	DWORD pdwOutputNum;
	WORD pwStreamNum;

	hr = mReader->GetNextSample( 0, &outBuffer, &pcnsSampleTime, &pcnsDuration, &pdwFlags, &pdwOutputNum, &pwStreamNum );
	if( hr == NS_E_NO_MORE_SAMPLES ) {
		ioData->mBuffers[0].mSampleCount = 0;
		return;
	}

	DWORD bufferLen;
	BYTE * rawBuffer = 0;
	hr = outBuffer->GetBufferAndLength( &rawBuffer, &bufferLen );
	if( hr != S_OK ) {
		//TODO
	}

	uint32_t bufferSize = bufferLen;
	if( bufferSize > ioData->mBuffers[0].mDataByteSize ) {
		bufferSize = ioData->mBuffers[0].mDataByteSize;
	}

	memcpy( ioData->mBuffers[0].mData, rawBuffer, bufferSize );
	ioData->mBuffers[0].mDataByteSize = bufferSize;
	ioData->mBuffers[0].mSampleCount = bufferSize / mSrcBlockAlign;
	mSampleOffset += ioData->mBuffers[0].mSampleCount;
}
Exemple #2
0
unsigned long decoder_read(unsigned long id, void* adata, unsigned long dsize)
{
	HRESULT      hres = 0;
	DWORD        i = 0;
	INSSBuffer*  ppSample;
	QWORD        pcnsSampleTime;
	QWORD        pcnsDuration;
	DWORD        pdwFlags;
	DWORD        pdwOutputNum;
	WORD         pwStreamNum;
	DWORD        lenret = 0;
	unsigned char* ptbuff;

	if(pstreams[id].buffersize && (pstreams[id].bufferpt < pstreams[id].buffersize))
	{
		memmove((char*)adata, pstreams[id].buffer + pstreams[id].bufferpt, min(dsize, pstreams[id].buffersize - pstreams[id].bufferpt));
		i += min(dsize, pstreams[id].buffersize - pstreams[id].bufferpt);
		pstreams[id].bufferpt += min(dsize, pstreams[id].buffersize - pstreams[id].bufferpt);

		if(i >= dsize)return dsize;
	}

	while(1)
	{
		hres = pstreams[id].wmreader->GetNextSample((WORD)pstreams[id].wmaudioout, &ppSample, &pcnsSampleTime, &pcnsDuration, &pdwFlags, &pdwOutputNum, &pwStreamNum);
		if(hres == NS_E_NO_MORE_SAMPLES || FAILED(hres))return 0;

		ppSample->GetBufferAndLength(&ptbuff, &lenret);
		
		if(!lenret)break;

		memmove((char*)adata + i, ptbuff, min(dsize - i, lenret));
		i += lenret;

		if(i > dsize)
		{
			if(!pstreams[id].buffer)
			{
				pstreams[id].buffer = (char*)malloc(lenret);
				pstreams[id].bufferallocsize = lenret;
				pstreams[id].buffersize = lenret;
			}else{
				if(lenret > pstreams[id].bufferallocsize)
				{
					pstreams[id].buffer = (char*) realloc(pstreams[id].buffer, lenret);
					pstreams[id].bufferallocsize = lenret;
				}
				pstreams[id].buffersize = lenret;
			}
			memcpy(pstreams[id].buffer, ptbuff, lenret);

			pstreams[id].bufferpt = lenret - (i - dsize);
		}

		ppSample->Release();

		if(i >= dsize)return dsize;
	}
    return i;
}
// THREADED, NO TOUCH
int CVideoInstance::NextFrame()
{
    HRESULT hr = S_OK;
    QWORD cnsSampleTime = 0;
    QWORD cnsSampleDuration = 0;
    DWORD dwFlags = 0;
    if (!mySyncReader)
    {
        return 0;
    }

    INSSBuffer* iNSSBuffer;
    hr = mySyncReader->GetNextSample(myVideoStreamNumber,
                                     &iNSSBuffer,
                                     &cnsSampleTime,
                                     &cnsSampleDuration,
                                     &dwFlags,
                                     NULL,//&dwOutputNumber,
                                     NULL);
    if (hr == NS_E_NO_MORE_SAMPLES)
    {
        //no more samples to read in file
        myIsStreamDone = true;
        return 0;
    }


    if (SUCCEEDED(hr))
    {
        // TODO: Process the sample in whatever way is appropriate
        // to your application. When finished, clean up.
        if (dwFlags == WM_SF_CLEANPOINT) //this a clean point frame, a picture to take read sdk for explantion
        {
            //					AfxMessageBox("found new sample");
            //1. Get the Bitmap from the frame
            //BYTE* meir;
            unsigned char *buffer;
            iNSSBuffer->GetBufferAndLength(&buffer, &myDwrdBitmapBufferLength);
            if (myBitmapBuffer == NULL)
            {
                myBitmapBuffer = new unsigned char[myDwrdBitmapBufferLength];
            }
            memcpy(myBitmapBuffer, buffer, myDwrdBitmapBufferLength);
            //calc the current postion in seconds
            m_qwCurrrentPostionInSeconds = (cnsSampleTime * 100) / 1000000000;
            myFramesRead++;


        }
        iNSSBuffer->Release();
        iNSSBuffer = NULL;
    }

    return 1;
}