Media foundation video i/o fixes.

Bug in Video for Windows capture init fixed;
Media Foundation based capture finalization fixed;
Highgui tests for video i/o updated.
This commit is contained in:
Alexander Smorkalov 2013-05-22 04:21:23 -07:00
parent 996f02a531
commit 43122939cb
5 changed files with 110 additions and 133 deletions

View File

@ -558,9 +558,11 @@ CVAPI(int) cvGetCaptureDomain( CvCapture* capture);
/* "black box" video file writer structure */ /* "black box" video file writer structure */
typedef struct CvVideoWriter CvVideoWriter; typedef struct CvVideoWriter CvVideoWriter;
#define CV_FOURCC_MACRO(c1, c2, c3, c4) ((c1 & 255) + ((c2 & 255) << 8) + ((c3 & 255) << 16) + ((c4 & 255) << 24))
CV_INLINE int CV_FOURCC(char c1, char c2, char c3, char c4) CV_INLINE int CV_FOURCC(char c1, char c2, char c3, char c4)
{ {
return (c1 & 255) + ((c2 & 255) << 8) + ((c3 & 255) << 16) + ((c4 & 255) << 24); return CV_FOURCC_MACRO(c1, c2, c3, c4);
} }
#define CV_FOURCC_PROMPT -1 /* Open Codec Selection Dialog (Windows only) */ #define CV_FOURCC_PROMPT -1 /* Open Codec Selection Dialog (Windows only) */

View File

@ -199,15 +199,6 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index)
switch (domains[i]) switch (domains[i])
{ {
#ifdef HAVE_MSMF
case CV_CAP_MSMF:
printf("Creating Media foundation capture\n");
capture = cvCreateCameraCapture_MSMF (index);
printf("Capture address %p\n", capture);
if (capture)
return capture;
break;
#endif
#ifdef HAVE_DSHOW #ifdef HAVE_DSHOW
case CV_CAP_DSHOW: case CV_CAP_DSHOW:
capture = cvCreateCameraCapture_DShow (index); capture = cvCreateCameraCapture_DShow (index);
@ -215,7 +206,13 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index)
return capture; return capture;
break; break;
#endif #endif
#ifdef HAVE_MSMF
case CV_CAP_MSMF:
capture = cvCreateCameraCapture_MSMF (index);
if (capture)
return capture;
break;
#endif
#ifdef HAVE_TYZX #ifdef HAVE_TYZX
case CV_CAP_STEREO: case CV_CAP_STEREO:
capture = cvCreateCameraCapture_TYZX (index); capture = cvCreateCameraCapture_TYZX (index);
@ -223,14 +220,12 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index)
return capture; return capture;
break; break;
#endif #endif
case CV_CAP_VFW:
#ifdef HAVE_VFW #ifdef HAVE_VFW
case CV_CAP_VFW:
capture = cvCreateCameraCapture_VFW (index); capture = cvCreateCameraCapture_VFW (index);
if (capture) if (capture)
return capture; return capture;
#endif #endif
#if defined HAVE_LIBV4L || defined HAVE_CAMV4L || defined HAVE_CAMV4L2 || defined HAVE_VIDEOIO #if defined HAVE_LIBV4L || defined HAVE_CAMV4L || defined HAVE_CAMV4L2 || defined HAVE_VIDEOIO
capture = cvCreateCameraCapture_V4L (index); capture = cvCreateCameraCapture_V4L (index);
if (capture) if (capture)
@ -363,20 +358,16 @@ CV_IMPL CvCapture * cvCreateFileCapture (const char * filename)
if (! result) if (! result)
result = cvCreateFileCapture_FFMPEG_proxy (filename); result = cvCreateFileCapture_FFMPEG_proxy (filename);
#ifdef HAVE_MSMF
if (! result)
{
printf("Creating Media foundation based reader\n");
result = cvCreateFileCapture_MSMF (filename);
printf("Construction result %p\n", result);
}
#endif
#ifdef HAVE_VFW #ifdef HAVE_VFW
if (! result) if (! result)
result = cvCreateFileCapture_VFW (filename); result = cvCreateFileCapture_VFW (filename);
#endif #endif
#ifdef HAVE_MSMF
if (! result)
result = cvCreateFileCapture_MSMF (filename);
#endif
#ifdef HAVE_XINE #ifdef HAVE_XINE
if (! result) if (! result)
result = cvCreateFileCapture_XINE (filename); result = cvCreateFileCapture_XINE (filename);
@ -422,14 +413,12 @@ CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc,
if(!fourcc || !fps) if(!fourcc || !fps)
result = cvCreateVideoWriter_Images(filename); result = cvCreateVideoWriter_Images(filename);
#ifdef HAVE_FFMPEG
if(!result) if(!result)
result = cvCreateVideoWriter_FFMPEG_proxy (filename, fourcc, fps, frameSize, is_color); result = cvCreateVideoWriter_FFMPEG_proxy (filename, fourcc, fps, frameSize, is_color);
#endif
#ifdef HAVE_VFW #ifdef HAVE_VFW
if(!result) if(!result)
return cvCreateVideoWriter_VFW(filename, fourcc, fps, frameSize, is_color); result = cvCreateVideoWriter_VFW(filename, fourcc, fps, frameSize, is_color);
#endif #endif
#ifdef HAVE_MSMF #ifdef HAVE_MSMF

View File

@ -840,9 +840,11 @@ LPCWSTR GetGUIDNameConstNew(const GUID& guid)
IF_EQUAL_RETURN(guid, MFAudioFormat_ADTS); // WAVE_FORMAT_MPEG_ADTS_AAC IF_EQUAL_RETURN(guid, MFAudioFormat_ADTS); // WAVE_FORMAT_MPEG_ADTS_AAC
return NULL; return NULL;
} }
FormatReader::FormatReader(void) FormatReader::FormatReader(void)
{ {
} }
MediaType FormatReader::Read(IMFMediaType *pType) MediaType FormatReader::Read(IMFMediaType *pType)
{ {
UINT32 count = 0; UINT32 count = 0;
@ -888,9 +890,9 @@ ImageGrabber::ImageGrabber(unsigned int deviceID, bool synchronous):
ig_RIE(true), ig_RIE(true),
ig_Close(false), ig_Close(false),
ig_Synchronous(synchronous), ig_Synchronous(synchronous),
ig_hFrameReady(synchronous ? CreateEvent(NULL, FALSE, FALSE, "ig_hFrameReady"): 0), ig_hFrameReady(synchronous ? CreateEvent(NULL, FALSE, FALSE, NULL): 0),
ig_hFrameGrabbed(synchronous ? CreateEvent(NULL, FALSE, TRUE, "ig_hFrameGrabbed"): 0), ig_hFrameGrabbed(synchronous ? CreateEvent(NULL, FALSE, TRUE, NULL): 0),
ig_hFinish(synchronous ? CreateEvent(NULL, FALSE, FALSE, "ig_hFinish") : 0) ig_hFinish(CreateEvent(NULL, TRUE, FALSE, NULL))
{} {}
ImageGrabber::~ImageGrabber(void) ImageGrabber::~ImageGrabber(void)
@ -898,15 +900,16 @@ ImageGrabber::~ImageGrabber(void)
printf("ImageGrabber::~ImageGrabber()\n"); printf("ImageGrabber::~ImageGrabber()\n");
if (ig_pSession) if (ig_pSession)
{ {
printf("ig_pSession->Shutdown()"); printf("ig_pSession->Shutdown()\n");
ig_pSession->Shutdown(); ig_pSession->Shutdown();
} }
CloseHandle(ig_hFinish);
if (ig_Synchronous) if (ig_Synchronous)
{ {
CloseHandle(ig_hFrameReady); CloseHandle(ig_hFrameReady);
CloseHandle(ig_hFrameGrabbed); CloseHandle(ig_hFrameGrabbed);
CloseHandle(ig_hFinish);
} }
SafeRelease(&ig_pSession); SafeRelease(&ig_pSession);
@ -1061,7 +1064,6 @@ HRESULT ImageGrabber::startGrabbing(void)
hr = S_OK; hr = S_OK;
goto done; goto done;
} }
printf("media foundation event: %d\n", met);
if (met == MESessionEnded) if (met == MESessionEnded)
{ {
DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: MESessionEnded \n", ig_DeviceID); DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: MESessionEnded \n", ig_DeviceID);
@ -1088,13 +1090,7 @@ HRESULT ImageGrabber::startGrabbing(void)
DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: Finish startGrabbing \n", ig_DeviceID); DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: Finish startGrabbing \n", ig_DeviceID);
done: done:
if (ig_Synchronous) SetEvent(ig_hFinish);
{
SetEvent(ig_hFinish);
}
SafeRelease(&ig_pSession);
SafeRelease(&ig_pTopology);
return hr; return hr;
} }
@ -1109,7 +1105,7 @@ void ImageGrabber::resumeGrabbing()
HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSinkActivate, IMFTopology **ppTopo) HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSinkActivate, IMFTopology **ppTopo)
{ {
ComPtr<IMFTopology> pTopology = NULL; IMFTopology* pTopology = NULL;
ComPtr<IMFPresentationDescriptor> pPD = NULL; ComPtr<IMFPresentationDescriptor> pPD = NULL;
ComPtr<IMFStreamDescriptor> pSD = NULL; ComPtr<IMFStreamDescriptor> pSD = NULL;
ComPtr<IMFMediaTypeHandler> pHandler = NULL; ComPtr<IMFMediaTypeHandler> pHandler = NULL;
@ -1117,7 +1113,7 @@ HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSink
ComPtr<IMFTopologyNode> pNode2 = NULL; ComPtr<IMFTopologyNode> pNode2 = NULL;
HRESULT hr = S_OK; HRESULT hr = S_OK;
DWORD cStreams = 0; DWORD cStreams = 0;
CHECK_HR(hr = MFCreateTopology(pTopology.GetAddressOf())); CHECK_HR(hr = MFCreateTopology(&pTopology));
CHECK_HR(hr = pSource->CreatePresentationDescriptor(pPD.GetAddressOf())); CHECK_HR(hr = pSource->CreatePresentationDescriptor(pPD.GetAddressOf()));
CHECK_HR(hr = pPD->GetStreamDescriptorCount(&cStreams)); CHECK_HR(hr = pPD->GetStreamDescriptorCount(&cStreams));
for (DWORD i = 0; i < cStreams; i++) for (DWORD i = 0; i < cStreams; i++)
@ -1130,8 +1126,8 @@ HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSink
CHECK_HR(hr = pHandler->GetMajorType(&majorType)); CHECK_HR(hr = pHandler->GetMajorType(&majorType));
if (majorType == MFMediaType_Video && fSelected) if (majorType == MFMediaType_Video && fSelected)
{ {
CHECK_HR(hr = AddSourceNode(pTopology.Get(), pSource, pPD.Get(), pSD.Get(), pNode1.GetAddressOf())); CHECK_HR(hr = AddSourceNode(pTopology, pSource, pPD.Get(), pSD.Get(), pNode1.GetAddressOf()));
CHECK_HR(hr = AddOutputNode(pTopology.Get(), pSinkActivate, 0, pNode2.GetAddressOf())); CHECK_HR(hr = AddOutputNode(pTopology, pSinkActivate, 0, pNode2.GetAddressOf()));
CHECK_HR(hr = pNode1->ConnectOutput(0, pNode2.Get(), 0)); CHECK_HR(hr = pNode1->ConnectOutput(0, pNode2.Get(), 0));
break; break;
} }
@ -1140,7 +1136,7 @@ HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSink
CHECK_HR(hr = pPD->DeselectStream(i)); CHECK_HR(hr = pPD->DeselectStream(i));
} }
} }
*ppTopo = pTopology.Get(); *ppTopo = pTopology;
(*ppTopo)->AddRef(); (*ppTopo)->AddRef();
done: done:
@ -1286,9 +1282,15 @@ STDMETHODIMP ImageGrabber::OnProcessSample(REFGUID guidMajorMediaType, DWORD dwS
(void)llSampleDuration; (void)llSampleDuration;
(void)dwSampleSize; (void)dwSampleSize;
WaitForSingleObject(ig_hFrameGrabbed, INFINITE); //printf("ImageGrabber::OnProcessSample() -- begin\n");
HANDLE tmp[] = {ig_hFinish, ig_hFrameGrabbed, NULL};
printf("ImageGrabber::OnProcessSample() -- begin\n"); DWORD status = WaitForMultipleObjects(2, tmp, FALSE, INFINITE);
if (status == WAIT_OBJECT_0)
{
printf("OnProcessFrame called after ig_hFinish event\n");
return S_OK;
}
if(ig_RIE) if(ig_RIE)
{ {
@ -1300,25 +1302,24 @@ STDMETHODIMP ImageGrabber::OnProcessSample(REFGUID guidMajorMediaType, DWORD dwS
ig_RISecond->fastCopy(pSampleBuffer); ig_RISecond->fastCopy(pSampleBuffer);
ig_RIOut = ig_RISecond; ig_RIOut = ig_RISecond;
} }
ig_RIE = !ig_RIE;
printf("ImageGrabber::OnProcessSample() -- end\n"); //printf("ImageGrabber::OnProcessSample() -- end\n");
if (ig_Synchronous) if (ig_Synchronous)
{ {
SetEvent(ig_hFrameReady); SetEvent(ig_hFrameReady);
} }
else
{
ig_RIE = !ig_RIE;
}
return S_OK; return S_OK;
} }
STDMETHODIMP ImageGrabber::OnShutdown() STDMETHODIMP ImageGrabber::OnShutdown()
{ {
if (ig_Synchronous) SetEvent(ig_hFinish);
{
SetEvent(ig_hFrameGrabbed);
}
return S_OK; return S_OK;
} }
@ -1387,6 +1388,8 @@ ImageGrabberThread::~ImageGrabberThread(void)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Destroing ImageGrabberThread\n", igt_DeviceID); DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Destroing ImageGrabberThread\n", igt_DeviceID);
if (igt_Handle)
WaitForSingleObject(igt_Handle, INFINITE);
delete igt_pImageGrabber; delete igt_pImageGrabber;
} }
@ -1431,7 +1434,6 @@ void ImageGrabberThread::run()
DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Emergency Stop thread\n", igt_DeviceID); DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Emergency Stop thread\n", igt_DeviceID);
if(igt_func) if(igt_func)
{ {
printf("Calling Emergency stop even handler\n");
igt_func(igt_DeviceID, igt_userData); igt_func(igt_DeviceID, igt_userData);
} }
} }
@ -3045,6 +3047,7 @@ CvCaptureFile_MSMF::CvCaptureFile_MSMF():
CvCaptureFile_MSMF::~CvCaptureFile_MSMF() CvCaptureFile_MSMF::~CvCaptureFile_MSMF()
{ {
close();
MFShutdown(); MFShutdown();
} }
@ -3109,7 +3112,7 @@ void CvCaptureFile_MSMF::close()
if (grabberThread) if (grabberThread)
{ {
isOpened = false; isOpened = false;
SetEvent(grabberThread->getImageGrabber()->ig_hFrameReady); SetEvent(grabberThread->getImageGrabber()->ig_hFinish);
grabberThread->stop(); grabberThread->stop();
delete grabberThread; delete grabberThread;
} }
@ -3289,12 +3292,12 @@ bool CvCaptureFile_MSMF::grabFrame()
DWORD waitResult; DWORD waitResult;
if (isOpened) if (isOpened)
{ {
SetEvent(grabberThread->getImageGrabber()->ig_hFrameGrabbed);
HANDLE tmp[] = {grabberThread->getImageGrabber()->ig_hFrameReady, grabberThread->getImageGrabber()->ig_hFinish, 0}; HANDLE tmp[] = {grabberThread->getImageGrabber()->ig_hFrameReady, grabberThread->getImageGrabber()->ig_hFinish, 0};
waitResult = WaitForMultipleObjects(2, tmp, FALSE, INFINITE); waitResult = WaitForMultipleObjects(2, tmp, FALSE, INFINITE);
SetEvent(grabberThread->getImageGrabber()->ig_hFrameGrabbed);
} }
return isOpened && (waitResult == WAIT_OBJECT_0); return isOpened && grabberThread->getImageGrabber()->getRawImage()->isNew() && (waitResult == WAIT_OBJECT_0);
} }
IplImage* CvCaptureFile_MSMF::retrieveFrame(int) IplImage* CvCaptureFile_MSMF::retrieveFrame(int)
@ -3443,7 +3446,8 @@ private:
HRESULT WriteFrame(DWORD *videoFrameBuffer, const LONGLONG& rtStart, const LONGLONG& rtDuration); HRESULT WriteFrame(DWORD *videoFrameBuffer, const LONGLONG& rtStart, const LONGLONG& rtDuration);
}; };
CvVideoWriter_MSMF::CvVideoWriter_MSMF() CvVideoWriter_MSMF::CvVideoWriter_MSMF():
initiated(false)
{ {
} }
@ -3456,47 +3460,47 @@ const GUID CvVideoWriter_MSMF::FourCC2GUID(int fourcc)
{ {
switch(fourcc) switch(fourcc)
{ {
case 'dv25': case CV_FOURCC_MACRO('d', 'v', '2', '5'):
return MFVideoFormat_DV25; break; return MFVideoFormat_DV25; break;
case 'dv50': case CV_FOURCC_MACRO('d', 'v', '5', '0'):
return MFVideoFormat_DV50; break; return MFVideoFormat_DV50; break;
case 'dvc ': case CV_FOURCC_MACRO('d', 'v', 'c', ' '):
return MFVideoFormat_DVC; break; return MFVideoFormat_DVC; break;
case 'dvh1': case CV_FOURCC_MACRO('d', 'v', 'h', '1'):
return MFVideoFormat_DVH1; break; return MFVideoFormat_DVH1; break;
case 'dvhd': case CV_FOURCC_MACRO('d', 'v', 'h', 'd'):
return MFVideoFormat_DVHD; break; return MFVideoFormat_DVHD; break;
case 'dvsd': case CV_FOURCC_MACRO('d', 'v', 's', 'd'):
return MFVideoFormat_DVSD; break; return MFVideoFormat_DVSD; break;
case 'dvsl': case CV_FOURCC_MACRO('d', 'v', 's', 'l'):
return MFVideoFormat_DVSL; break; return MFVideoFormat_DVSL; break;
case 'H263': case CV_FOURCC_MACRO('H', '2', '6', '3'):
return MFVideoFormat_H263; break; return MFVideoFormat_H263; break;
case 'H264': case CV_FOURCC_MACRO('H', '2', '6', '4'):
return MFVideoFormat_H264; break; return MFVideoFormat_H264; break;
case 'M4S2': case CV_FOURCC_MACRO('M', '4', 'S', '2'):
return MFVideoFormat_M4S2; break; return MFVideoFormat_M4S2; break;
case 'MJPG': case CV_FOURCC_MACRO('M', 'J', 'P', 'G'):
return MFVideoFormat_MJPG; break; return MFVideoFormat_MJPG; break;
case 'MP43': case CV_FOURCC_MACRO('M', 'P', '4', '3'):
return MFVideoFormat_MP43; break; return MFVideoFormat_MP43; break;
case 'MP4S': case CV_FOURCC_MACRO('M', 'P', '4', 'S'):
return MFVideoFormat_MP4S; break; return MFVideoFormat_MP4S; break;
case 'MP4V': case CV_FOURCC_MACRO('M', 'P', '4', 'V'):
return MFVideoFormat_MP4V; break; return MFVideoFormat_MP4V; break;
case 'MPG1': case CV_FOURCC_MACRO('M', 'P', 'G', '1'):
return MFVideoFormat_MPG1; break; return MFVideoFormat_MPG1; break;
case 'MSS1': case CV_FOURCC_MACRO('M', 'S', 'S', '1'):
return MFVideoFormat_MSS1; break; return MFVideoFormat_MSS1; break;
case 'MSS2': case CV_FOURCC_MACRO('M', 'S', 'S', '2'):
return MFVideoFormat_MSS2; break; return MFVideoFormat_MSS2; break;
case 'WMV1': case CV_FOURCC_MACRO('W', 'M', 'V', '1'):
return MFVideoFormat_WMV1; break; return MFVideoFormat_WMV1; break;
case 'WMV2': case CV_FOURCC_MACRO('W', 'M', 'V', '2'):
return MFVideoFormat_WMV2; break; return MFVideoFormat_WMV2; break;
case 'WMV3': case CV_FOURCC_MACRO('W', 'M', 'V', '3'):
return MFVideoFormat_WMV3; break; return MFVideoFormat_WMV3; break;
case 'WVC1': case CV_FOURCC_MACRO('W', 'V', 'C', '1'):
return MFVideoFormat_WVC1; break; return MFVideoFormat_WVC1; break;
default: default:
return MFVideoFormat_H264; return MFVideoFormat_H264;
@ -3516,19 +3520,15 @@ bool CvVideoWriter_MSMF::open( const char* filename, int fourcc,
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
printf("CoInitializeEx is successfull\n");
hr = MFStartup(MF_VERSION); hr = MFStartup(MF_VERSION);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
printf("MFStartup is successfull\n");
hr = InitializeSinkWriter(filename); hr = InitializeSinkWriter(filename);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
printf("InitializeSinkWriter is successfull\n");
initiated = true; initiated = true;
rtStart = 0; rtStart = 0;
MFFrameRateToAverageTimePerFrame((UINT32)fps, 1, &rtDuration); MFFrameRateToAverageTimePerFrame((UINT32)fps, 1, &rtDuration);
printf("duration: %d\n", rtDuration);
} }
} }
} }
@ -3556,13 +3556,9 @@ bool CvVideoWriter_MSMF::writeFrame(const IplImage* img)
if (!img) if (!img)
return false; return false;
printf("Writing not empty IplImage\n");
int length = img->width * img->height * 4; int length = img->width * img->height * 4;
printf("Image: %dx%d, %d\n", img->width, img->height, length);
DWORD* target = new DWORD[length]; DWORD* target = new DWORD[length];
printf("Before for loop\n");
for (int rowIdx = 0; rowIdx < img->height; rowIdx++) for (int rowIdx = 0; rowIdx < img->height; rowIdx++)
{ {
char* rowStart = img->imageData + rowIdx*img->widthStep; char* rowStart = img->imageData + rowIdx*img->widthStep;
@ -3577,9 +3573,7 @@ bool CvVideoWriter_MSMF::writeFrame(const IplImage* img)
} }
// Send frame to the sink writer. // Send frame to the sink writer.
printf("Before private WriteFrame call\n");
HRESULT hr = WriteFrame(target, rtStart, rtDuration); HRESULT hr = WriteFrame(target, rtStart, rtDuration);
printf("After private WriteFrame call\n");
if (FAILED(hr)) if (FAILED(hr))
{ {
printf("Private WriteFrame failed\n"); printf("Private WriteFrame failed\n");
@ -3588,8 +3582,6 @@ bool CvVideoWriter_MSMF::writeFrame(const IplImage* img)
} }
rtStart += rtDuration; rtStart += rtDuration;
printf("End of writing IplImage\n");
delete[] target; delete[] target;
return true; return true;
@ -3681,7 +3673,8 @@ HRESULT CvVideoWriter_MSMF::InitializeSinkWriter(const char* filename)
{ {
hr = MFSetAttributeRatio(mediaTypeIn.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1); hr = MFSetAttributeRatio(mediaTypeIn.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
} }
if (SUCCEEDED(hr))
if (SUCCEEDED(hr))
{ {
hr = sinkWriter->SetInputMediaType(streamIndex, mediaTypeIn.Get(), NULL); hr = sinkWriter->SetInputMediaType(streamIndex, mediaTypeIn.Get(), NULL);
} }
@ -3697,7 +3690,6 @@ HRESULT CvVideoWriter_MSMF::InitializeSinkWriter(const char* filename)
HRESULT CvVideoWriter_MSMF::WriteFrame(DWORD *videoFrameBuffer, const LONGLONG& Start, const LONGLONG& Duration) HRESULT CvVideoWriter_MSMF::WriteFrame(DWORD *videoFrameBuffer, const LONGLONG& Start, const LONGLONG& Duration)
{ {
printf("Private WriteFrame(%p, %llu, %llu)\n", videoFrameBuffer, Start, Duration);
ComPtr<IMFSample> sample; ComPtr<IMFSample> sample;
ComPtr<IMFMediaBuffer> buffer; ComPtr<IMFMediaBuffer> buffer;
@ -3712,13 +3704,11 @@ HRESULT CvVideoWriter_MSMF::WriteFrame(DWORD *videoFrameBuffer, const LONGLONG&
// Lock the buffer and copy the video frame to the buffer. // Lock the buffer and copy the video frame to the buffer.
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
printf("MFCreateMemoryBuffer successfull\n");
hr = buffer->Lock(&pData, NULL, NULL); hr = buffer->Lock(&pData, NULL, NULL);
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
printf("Before MFCopyImage(%p, %d, %p, %d, %d %d)\n", pData, cbWidth, videoFrameBuffer, cbWidth, cbWidth, videoHeight);
hr = MFCopyImage( hr = MFCopyImage(
pData, // Destination buffer. pData, // Destination buffer.
cbWidth, // Destination stride. cbWidth, // Destination stride.
@ -3727,21 +3717,16 @@ HRESULT CvVideoWriter_MSMF::WriteFrame(DWORD *videoFrameBuffer, const LONGLONG&
cbWidth, // Image width in bytes. cbWidth, // Image width in bytes.
videoHeight // Image height in pixels. videoHeight // Image height in pixels.
); );
printf("After MFCopyImage()\n");
} }
printf("Before buffer.Get()\n");
if (buffer) if (buffer)
{ {
printf("Before buffer->Unlock\n");
buffer->Unlock(); buffer->Unlock();
printf("After buffer->Unlock\n");
} }
// Set the data length of the buffer. // Set the data length of the buffer.
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
printf("MFCopyImage successfull\n");
hr = buffer->SetCurrentLength(cbBuffer); hr = buffer->SetCurrentLength(cbBuffer);
} }
@ -3758,24 +3743,19 @@ HRESULT CvVideoWriter_MSMF::WriteFrame(DWORD *videoFrameBuffer, const LONGLONG&
// Set the time stamp and the duration. // Set the time stamp and the duration.
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
printf("Sample time: %d\n", Start);
hr = sample->SetSampleTime(Start); hr = sample->SetSampleTime(Start);
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
printf("Duration: %d\n", Duration);
hr = sample->SetSampleDuration(Duration); hr = sample->SetSampleDuration(Duration);
} }
// Send the sample to the Sink Writer. // Send the sample to the Sink Writer.
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
printf("Setting writer params successfull\n");
hr = sinkWriter->WriteSample(streamIndex, sample.Get()); hr = sinkWriter->WriteSample(streamIndex, sample.Get());
} }
printf("Private WriteFrame(%d, %p) end with status %u\n", streamIndex, sample.Get(), hr);
return hr; return hr;
} }

View File

@ -613,8 +613,10 @@ bool CvVideoWriter_VFW::open( const char* filename, int _fourcc, double _fps, Cv
close(); close();
return false; return false;
} }
return true;
} }
return true; else
return false;
} }

View File

@ -57,27 +57,27 @@ string fourccToString(int fourcc)
#ifdef HAVE_MSMF #ifdef HAVE_MSMF
const VideoFormat g_specific_fmt_list[] = const VideoFormat g_specific_fmt_list[] =
{ {
/* VideoFormat("avi", 'dv25'), /*VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', '2', '5')),
VideoFormat("avi", 'dv50'), VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', '5', '0')),
VideoFormat("avi", 'dvc '), VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 'c', ' ')),
VideoFormat("avi", 'dvh1'), VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 'h', '1')),
VideoFormat("avi", 'dvhd'), VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 'h', 'd')),
VideoFormat("avi", 'dvsd'), VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 's', 'd')),
VideoFormat("avi", 'dvsl'), VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 's', 'l')),
VideoFormat("avi", 'M4S2'), */ VideoFormat("wmv", CV_FOURCC_MACRO('H', '2', '6', '3')),
VideoFormat("wmv", 'WMV3'), VideoFormat("wmv", CV_FOURCC_MACRO('M', '4', 'S', '2')),
// VideoFormat("avi", 'H264'), VideoFormat("avi", CV_FOURCC_MACRO('M', 'J', 'P', 'G')),
// VideoFormat("avi", 'MJPG'), VideoFormat("mp4", CV_FOURCC_MACRO('M', 'P', '4', 'S')),
// VideoFormat("avi", 'MP43'), VideoFormat("mp4", CV_FOURCC_MACRO('M', 'P', '4', 'V')),
// VideoFormat("avi", 'MP4S'), VideoFormat("wmv", CV_FOURCC_MACRO('M', 'P', '4', '3')),
// VideoFormat("avi", 'MP4V'), VideoFormat("wmv", CV_FOURCC_MACRO('M', 'P', 'G', '1')),
/* VideoFormat("avi", 'MPG1'), VideoFormat("wmv", CV_FOURCC_MACRO('M', 'S', 'S', '1')),
VideoFormat("avi", 'MSS1'), VideoFormat("wmv", CV_FOURCC_MACRO('M', 'S', 'S', '2')),*/
VideoFormat("avi", 'MSS2'), //VideoFormat("avi", CV_FOURCC_MACRO('H', '2', '6', '4')),
VideoFormat("avi", 'WMV1'), VideoFormat("wmv", CV_FOURCC_MACRO('W', 'M', 'V', '1')),
VideoFormat("avi", 'WMV2'), VideoFormat("wmv", CV_FOURCC_MACRO('W', 'M', 'V', '2')),
VideoFormat("avi", 'WMV3'), VideoFormat("wmv", CV_FOURCC_MACRO('W', 'M', 'V', '3')),
VideoFormat("avi", 'WVC1'), */ //VideoFormat("wmv", CV_FOURCC_MACRO('W', 'V', 'C', '1')),
VideoFormat() VideoFormat()
}; };
#else #else
@ -269,19 +269,19 @@ void CV_HighGuiTest::VideoTest(const string& dir, const cvtest::VideoFormat& fmt
for(;;) for(;;)
{ {
IplImage * img = cvQueryFrame( cap ); IplImage* img = cvQueryFrame( cap );
if (!img) if (!img)
break; break;
frames.push_back(Mat(img).clone()); frames.push_back(Mat(img).clone());
if (writer == 0) if (writer == NULL)
{ {
writer = cvCreateVideoWriter(tmp_name.c_str(), fmt.fourcc, 24, cvGetSize(img)); writer = cvCreateVideoWriter(tmp_name.c_str(), fmt.fourcc, 24, cvGetSize(img));
if (writer == 0) if (writer == NULL)
{ {
ts->printf(ts->LOG, "can't create writer (with fourcc : %d)\n", ts->printf(ts->LOG, "can't create writer (with fourcc : %s)\n",
cvtest::fourccToString(fmt.fourcc).c_str()); cvtest::fourccToString(fmt.fourcc).c_str());
cvReleaseCapture( &cap ); cvReleaseCapture( &cap );
ts->set_failed_test_info(ts->FAIL_MISMATCH); ts->set_failed_test_info(ts->FAIL_MISMATCH);
@ -317,18 +317,22 @@ void CV_HighGuiTest::VideoTest(const string& dir, const cvtest::VideoFormat& fmt
double psnr = PSNR(img1, img); double psnr = PSNR(img1, img);
if (psnr < thresDbell) if (psnr < thresDbell)
{ {
printf("Too low psnr = %gdb\n", psnr); ts->printf(ts->LOG, "Too low frame %d psnr = %gdb\n", i, psnr);
ts->set_failed_test_info(ts->FAIL_MISMATCH);
//imwrite("original.png", img); //imwrite("original.png", img);
//imwrite("after_test.png", img1); //imwrite("after_test.png", img1);
//Mat diff; //Mat diff;
//absdiff(img, img1, diff); //absdiff(img, img1, diff);
//imwrite("diff.png", diff); //imwrite("diff.png", diff);
ts->set_failed_test_info(ts->FAIL_MISMATCH);
break; break;
} }
} }
printf("Before saved release for %s\n", tmp_name.c_str());
cvReleaseCapture( &saved ); cvReleaseCapture( &saved );
printf("After release\n");
ts->printf(ts->LOG, "end test function : ImagesVideo \n"); ts->printf(ts->LOG, "end test function : ImagesVideo \n");
} }