Commit 3899e91f authored by Ghislain MARY's avatar Ghislain MARY

Remove preview handling in capture filter (the preview will be done with a...

Remove preview handling in capture filter (the preview will be done with a display filter instanciated by mediastreamer2).
parent 597bbbcf
......@@ -43,11 +43,6 @@ MSWinRTCapHelper::MSWinRTCapHelper() :
ms_error("[MSWinRTCap] Could not create initialization event [%i]", GetLastError());
return;
}
mPreviewStartCompleted = CreateEventEx(NULL, L"Local\\MSWinRTCapPreviewStart", 0, EVENT_ALL_ACCESS);
if (!mPreviewStartCompleted) {
ms_error("[MSWinRTCap] Could not create preview start event [%i]", GetLastError());
return;
}
mStartCompleted = CreateEventEx(NULL, L"Local\\MSWinRTCapStart", 0, EVENT_ALL_ACCESS);
if (!mStartCompleted) {
ms_error("[MSWinRTCap] Could not create start event [%i]", GetLastError());
......@@ -58,11 +53,6 @@ MSWinRTCapHelper::MSWinRTCapHelper() :
ms_error("[MSWinRTCap] Could not create stop event [%i]", GetLastError());
return;
}
mPreviewStopCompleted = CreateEventEx(NULL, L"Local\\MSWinRTCapPreviewStop", 0, EVENT_ALL_ACCESS);
if (!mPreviewStopCompleted) {
ms_error("[MSWinRTCap] Could not create preview stop event [%i]", GetLastError());
return;
}
ms_mutex_init(&mMutex, NULL);
mAllocator = ms_yuv_buf_allocator_new();
......@@ -74,18 +64,10 @@ MSWinRTCapHelper::~MSWinRTCapHelper()
if (mCapture.Get() != nullptr) {
mCapture->Failed -= mMediaCaptureFailedEventRegistrationToken;
}
if (mPreviewStopCompleted) {
CloseHandle(mPreviewStopCompleted);
mPreviewStopCompleted = NULL;
}
if (mStopCompleted) {
CloseHandle(mStopCompleted);
mStopCompleted = NULL;
}
if (mPreviewStartCompleted) {
CloseHandle(mPreviewStartCompleted);
mPreviewStartCompleted = NULL;
}
if (mStartCompleted) {
CloseHandle(mStartCompleted);
mStartCompleted = NULL;
......@@ -138,90 +120,6 @@ bool MSWinRTCapHelper::Initialize(Platform::String^ DeviceId)
return isInitialized;
}
bool MSWinRTCapHelper::StartPreview(int DeviceOrientation)
{
bool isStarted = false;
mDeviceOrientation = DeviceOrientation;
try {
IAsyncAction^ previewAction = mCapture->StartPreviewAsync();
previewAction->Completed = ref new AsyncActionCompletedHandler([this, &isStarted](IAsyncAction^ asyncAction, Windows::Foundation::AsyncStatus asyncStatus) {
IAsyncAction^ previewPropertiesAction = nullptr;
IMediaEncodingProperties^ props = nullptr;
switch (asyncStatus) {
case Windows::Foundation::AsyncStatus::Completed:
ms_message("[MSWinRTCap] StartPreviewAsync completed");
props = mCapture->VideoDeviceController->GetMediaStreamProperties(Capture::MediaStreamType::VideoPreview);
props->Properties->Insert(mRotationKey, mDeviceOrientation);
try {
previewPropertiesAction = mCapture->SetEncodingPropertiesAsync(Capture::MediaStreamType::VideoPreview, props, nullptr);
previewPropertiesAction->Completed = ref new AsyncActionCompletedHandler([this, &isStarted](IAsyncAction^ asyncAction, Windows::Foundation::AsyncStatus asyncStatus) {
isStarted = true;
switch (asyncStatus) {
case Windows::Foundation::AsyncStatus::Completed:
ms_message("[MSWinRTCap] SetEncodingPropertiesAsync completed");
break;
case Windows::Foundation::AsyncStatus::Canceled:
ms_error("[MSWinRTCap] SetEncodingPropertiesAsync has been cancelled");
break;
case Windows::Foundation::AsyncStatus::Error:
{
int res = asyncAction->ErrorCode.Value;
ms_error("[MSWinRTCap] SetEncodingPropertiesAsync failed [0x%x]", res);
}
break;
default:
break;
}
SetEvent(mPreviewStartCompleted);
});
} catch (Exception^ e) {
ms_error("[MSWinRTCap] StartPreviewAsync exception 0x%x", e->HResult);
// Apparently, sometimes the preview is not correctly stopped, try again...
StopPreview();
SetEvent(mPreviewStartCompleted);
}
break;
case Windows::Foundation::AsyncStatus::Canceled:
ms_error("[MSWinRTCap] StartPreviewAsync has been cancelled");
SetEvent(mPreviewStartCompleted);
break;
case Windows::Foundation::AsyncStatus::Error:
{
int res = asyncAction->ErrorCode.Value;
ms_error("[MSWinRTCap] StartPreviewAsync failed [0x%x]", res);
SetEvent(mPreviewStartCompleted);
}
break;
default:
SetEvent(mPreviewStartCompleted);
break;
}
});
WaitForSingleObjectEx(mPreviewStartCompleted, INFINITE, FALSE);
}
catch (Exception^ e) {
ms_error("[MSWinRTCap] SetEncodingPropertiesAsync exception 0x%x", e->HResult);
// Apparently, sometimes the preview is not correctly stopped, try again...
StopPreview();
}
return isStarted;
}
void MSWinRTCapHelper::StopPreview()
{
IAsyncAction^ action = mCapture->StopPreviewAsync();
action->Completed = ref new AsyncActionCompletedHandler([this](IAsyncAction^ asyncAction, Windows::Foundation::AsyncStatus asyncStatus) {
if (asyncStatus == Windows::Foundation::AsyncStatus::Completed) {
ms_message("[MSWinRTCap] StopPreviewAsync completed");
}
else {
ms_message("[MSWinRTCap] StopPreviewAsync failed");
}
SetEvent(mPreviewStopCompleted);
});
WaitForSingleObjectEx(mPreviewStopCompleted, INFINITE, FALSE);
}
bool MSWinRTCapHelper::StartCapture(MediaEncodingProfile^ EncodingProfile)
{
bool isStarted = false;
......@@ -377,21 +275,11 @@ int MSWinRTCap::activate()
applyVideoSize();
applyFps();
mIsActivated = true;
if (mIsActivated && (mCaptureElement != nullptr)) {
if (mCaptureElement->Dispatcher->HasThreadAccess) {
mCaptureElement->Source = mHelper->CaptureDevice.Get();
} else {
mCaptureElement->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([this]() {
mCaptureElement->Source = mHelper->CaptureDevice.Get();
}));
}
}
return 0;
}
int MSWinRTCap::deactivate()
{
//mHelper->StopPreview();
mIsActivated = false;
mIsInitialized = false;
return 0;
......@@ -400,8 +288,7 @@ int MSWinRTCap::deactivate()
void MSWinRTCap::start()
{
if (!mIsStarted && mIsActivated) {
/*mIsStarted = mHelper->StartPreview(mDeviceOrientation);
if (mIsStarted)*/ mIsStarted = mHelper->StartCapture(mEncodingProfile);
mIsStarted = mHelper->StartCapture(mEncodingProfile);
}
}
......
......@@ -45,8 +45,6 @@ namespace libmswinrtvid
internal:
MSWinRTCapHelper();
bool Initialize(Platform::String^ DeviceId);
bool StartPreview(int DeviceOrientation);
void StopPreview();
bool StartCapture(Windows::Media::MediaProperties::MediaEncodingProfile^ EncodingProfile);
void StopCapture();
void MSWinRTCapHelper::OnSampleAvailable(BYTE *buf, DWORD bufLen, LONGLONG presentationTime);
......@@ -65,8 +63,6 @@ namespace libmswinrtvid
HANDLE mInitializationCompleted;
HANDLE mStartCompleted;
HANDLE mStopCompleted;
HANDLE mPreviewStartCompleted;
HANDLE mPreviewStopCompleted;
const GUID mRotationKey;
Platform::Agile<MediaCapture^> mCapture;
Windows::Foundation::EventRegistrationToken mMediaCaptureFailedEventRegistrationToken;
......@@ -93,7 +89,6 @@ namespace libmswinrtvid
void OnSampleAvailable(BYTE *buf, DWORD bufLen, LONGLONG presentationTime);
void setCaptureElement(Windows::UI::Xaml::Controls::CaptureElement^ captureElement) { mCaptureElement = captureElement; }
void setDeviceId(Platform::String^ id) { mDeviceId = id; }
void setFront(bool front) { mFront = front; }
void setExternal(bool external) { mExternal = external; }
......@@ -127,7 +122,6 @@ namespace libmswinrtvid
uint64_t mStartTime;
int mDeviceOrientation;
MSVideoStarter mStarter;
Windows::UI::Xaml::Controls::CaptureElement^ mCaptureElement;
Platform::String^ mDeviceId;
bool mFront;
bool mExternal;
......
......@@ -121,16 +121,6 @@ static int ms_winrtcap_set_device_orientation(MSFilter *f, void *arg) {
return 0;
}
static int ms_winrtcap_set_native_window_id(MSFilter *f, void *arg) {
#ifdef MS2_WINDOWS_UNIVERSAL
/*MSWinRTCap *r = static_cast<MSWinRTCap *>(f->data);
RefToPtrProxy<Platform::Object^> *proxy = static_cast<RefToPtrProxy<Platform::Object^>*>((void *)(*((PULONG_PTR)arg)));
Windows::UI::Xaml::Controls::CaptureElement^ captureElement = dynamic_cast<Windows::UI::Xaml::Controls::CaptureElement^>(proxy->Ref());
r->setCaptureElement(captureElement);*/
#endif
return 0;
}
static MSFilterMethod ms_winrtcap_read_methods[] = {
{ MS_FILTER_GET_FPS, ms_winrtcap_get_fps },
{ MS_FILTER_SET_FPS, ms_winrtcap_set_fps },
......@@ -138,7 +128,6 @@ static MSFilterMethod ms_winrtcap_read_methods[] = {
{ MS_FILTER_GET_VIDEO_SIZE, ms_winrtcap_get_vsize },
{ MS_FILTER_SET_VIDEO_SIZE, ms_winrtcap_set_vsize },
{ MS_VIDEO_CAPTURE_SET_DEVICE_ORIENTATION, ms_winrtcap_set_device_orientation },
{ MS_VIDEO_DISPLAY_SET_NATIVE_WINDOW_ID, ms_winrtcap_set_native_window_id },
{ 0, NULL }
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment