Commit 4c465b2c authored by Ghislain MARY's avatar Ghislain MARY

Initial import that handles starting and stopping capture.

parents
Copyright Belledonne Communications SARL.
This diff is collapsed.
mswp8cap - Windows Phone 8 Video Capture plugin for mediastreamer2.
Compile on Windows using Visual Studio 2012.
/*
mswp8cap.cpp
mediastreamer2 library - modular sound and video processing and streaming
Windows Audio Session API sound card plugin for mediastreamer2
Copyright (C) 2010-2013 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "mediastreamer2/msfilter.h"
#include "mediastreamer2/msvideo.h"
#include "mediastreamer2/mswebcam.h"
#include "mswp8cap_reader.h"
using namespace mediastreamer2;
/******************************************************************************
* Methods to (de)initialize and run the WP8 Video capture filter *
*****************************************************************************/
static void ms_wp8cap_read_init(MSFilter *f) {
MSWP8CapReader *r = new MSWP8CapReader();
f->data = r;
}
static void ms_wp8cap_read_preprocess(MSFilter *f) {
MSWP8CapReader *r = static_cast<MSWP8CapReader *>(f->data);
r->activate();
}
static void ms_wp8cap_read_process(MSFilter *f) {
MSWP8CapReader *r = static_cast<MSWP8CapReader *>(f->data);
if (!r->isStarted()) {
r->start();
}
// TODO
}
static void ms_wp8cap_read_postprocess(MSFilter *f) {
MSWP8CapReader *r = static_cast<MSWP8CapReader *>(f->data);
r->stop();
r->deactivate();
}
static void ms_wp8cap_read_uninit(MSFilter *f) {
MSWP8CapReader *r = static_cast<MSWP8CapReader *>(f->data);
delete r;
}
/******************************************************************************
* Methods to configure the Windows Phone 8 Video capture filter *
*****************************************************************************/
static int ms_wp8cap_set_fps(MSFilter *f, void *arg) {
// TODO
return 0;
}
static int ms_wp8cap_get_pix_fmt(MSFilter *f, void *arg) {
// TODO
return 0;
}
static int ms_wp8cap_set_vsize(MSFilter *f, void *arg) {
// TODO
return 0;
}
static int ms_wp8cap_get_vsize(MSFilter *f, void *arg) {
// TODO
return 0;
}
static MSFilterMethod ms_wp8cap_read_methods[] = {
{ MS_FILTER_SET_FPS, ms_wp8cap_set_fps },
{ MS_FILTER_GET_PIX_FMT, ms_wp8cap_get_pix_fmt },
{ MS_FILTER_SET_VIDEO_SIZE, ms_wp8cap_set_vsize },
{ MS_FILTER_GET_VIDEO_SIZE, ms_wp8cap_get_vsize },
{ 0, NULL }
};
/******************************************************************************
* Definition of the Windows Phone 8 Video Capture filter *
*****************************************************************************/
#define MS_WP8CAP_READ_ID MS_FILTER_PLUGIN_ID
#define MS_WP8CAP_READ_NAME "MSWP8CapRead"
#define MS_WP8CAP_READ_DESCRIPTION "Windows Phone 8 Video capture"
#define MS_WP8CAP_READ_CATEGORY MS_FILTER_OTHER
#define MS_WP8CAP_READ_ENC_FMT NULL
#define MS_WP8CAP_READ_NINPUTS 0
#define MS_WP8CAP_READ_NOUTPUTS 1
#define MS_WP8CAP_READ_FLAGS 0
#ifndef _MSC_VER
MSFilterDesc ms_wp8cap_read_desc = {
.id = MS_WP8CAP_READ_ID,
.name = MS_WP8CAP_READ_NAME,
.text = MS_WP8CAP_READ_DESCRIPTION,
.category = MS_WP8CAP_READ_CATEGORY,
.enc_fmt = MS_WP8CAP_READ_ENC_FMT,
.ninputs = MS_WP8CAP_READ_NINPUTS,
.noutputs = MS_WP8CAP_READ_NOUTPUTS,
.init = ms_wp8cap_read_init,
.preprocess = ms_wp8cap_read_preprocess,
.process = ms_wp8cap_read_process,
.postprocess = ms_wp8cap_read_postprocess,
.uninit = ms_wp8cap_read_uninit,
.methods = ms_wp8cap_read_methods,
.flags = MS_WP8CAP_READ_FLAGS
};
#else
MSFilterDesc ms_wp8cap_read_desc = {
MS_WP8CAP_READ_ID,
MS_WP8CAP_READ_NAME,
MS_WP8CAP_READ_DESCRIPTION,
MS_WP8CAP_READ_CATEGORY,
MS_WP8CAP_READ_ENC_FMT,
MS_WP8CAP_READ_NINPUTS,
MS_WP8CAP_READ_NOUTPUTS,
ms_wp8cap_read_init,
ms_wp8cap_read_preprocess,
ms_wp8cap_read_process,
ms_wp8cap_read_postprocess,
ms_wp8cap_read_uninit,
ms_wp8cap_read_methods,
MS_WP8CAP_READ_FLAGS
};
#endif
MS_FILTER_DESC_EXPORT(ms_wp8cap_read_desc)
static void ms_wp8cap_detect(MSWebCamManager *m);
static MSFilter *ms_wp8cap_create_reader(MSWebCam *cam);
static MSWebCamDesc ms_wp8cap_desc = {
"MSWP8Cap",
ms_wp8cap_detect,
NULL,
ms_wp8cap_create_reader,
NULL
};
static MSWebCam *ms_wp8cap_new(void) {
MSWebCam *cam = ms_web_cam_new(&ms_wp8cap_desc);
cam->name = ms_strdup("WP8 Camera");
return cam;
}
static void ms_wp8cap_detect(MSWebCamManager *m) {
MSWebCam *cam = ms_wp8cap_new();
ms_web_cam_manager_prepend_cam(m, cam);
}
static MSFilter *ms_wp8cap_create_reader(MSWebCam *cam) {
MS_UNUSED(cam);
return ms_filter_new_from_desc(&ms_wp8cap_read_desc);
}
#ifdef _MSC_VER
#define MS_PLUGIN_DECLARE(type) extern "C" __declspec(dllexport) type
#else
#define MS_PLUGIN_DECLARE(type) extern "C" type
#endif
MS_PLUGIN_DECLARE(void) libmswp8cap_init(void) {
MSWebCamManager *manager = ms_web_cam_manager_get();
ms_web_cam_manager_register_desc(manager, &ms_wp8cap_desc);
ms_message("libmswp8cap plugin loaded");
}

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2012 for Windows Phone
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mswp8cap", "mswp8cap\mswp8cap.vcxproj", "{0565952A-EA62-46A2-8261-F5B4B490DA42}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mediastreamer2", "..\..\mediastreamer2\build\vsx\mediastreamer2\mediastreamer2\mediastreamer2.vcxproj", "{027BAD0E-9179-48C1-9733-7AA7E2C2EC70}"
ProjectSection(ProjectDependencies) = postProject
{D5EC8C11-C1D9-47E3-BB82-A93C300FD902} = {D5EC8C11-C1D9-47E3-BB82-A93C300FD902}
{FFC7B532-0502-4D88-AC98-9E89071CBC97} = {FFC7B532-0502-4D88-AC98-9E89071CBC97}
{6BD78980-9C71-4341-8775-AD19E9EC7305} = {6BD78980-9C71-4341-8775-AD19E9EC7305}
{746EA080-5BA9-42C5-9E52-EA421C3F3AFD} = {746EA080-5BA9-42C5-9E52-EA421C3F3AFD}
{1C4E6DA0-B8C7-4A05-A58E-54A6ED07C8DF} = {1C4E6DA0-B8C7-4A05-A58E-54A6ED07C8DF}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "oRTP", "..\..\ortp\build\vsx\oRTP\oRTP\oRTP.vcxproj", "{FFC7B532-0502-4D88-AC98-9E89071CBC97}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gsm", "..\..\gsm\build\windows\gsm\gsm\gsm.vcxproj", "{746EA080-5BA9-42C5-9E52-EA421C3F3AFD}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "speex", "..\..\speex\build\windows\speex\speex\speex.vcxproj", "{D5EC8C11-C1D9-47E3-BB82-A93C300FD902}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "speexdsp", "..\..\speex\build\windows\speex\speexdsp\speexdsp.vcxproj", "{6BD78980-9C71-4341-8775-AD19E9EC7305}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "webrtcaecm", "..\..\webrtc\build\windows\webrtcaecm\webrtcaecm\webrtcaecm.vcxproj", "{1C4E6DA0-B8C7-4A05-A58E-54A6ED07C8DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Debug|Win32 = Debug|Win32
Release|ARM = Release|ARM
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0565952A-EA62-46A2-8261-F5B4B490DA42}.Debug|ARM.ActiveCfg = Debug|ARM
{0565952A-EA62-46A2-8261-F5B4B490DA42}.Debug|ARM.Build.0 = Debug|ARM
{0565952A-EA62-46A2-8261-F5B4B490DA42}.Debug|Win32.ActiveCfg = Debug|Win32
{0565952A-EA62-46A2-8261-F5B4B490DA42}.Debug|Win32.Build.0 = Debug|Win32
{0565952A-EA62-46A2-8261-F5B4B490DA42}.Release|ARM.ActiveCfg = Release|ARM
{0565952A-EA62-46A2-8261-F5B4B490DA42}.Release|ARM.Build.0 = Release|ARM
{0565952A-EA62-46A2-8261-F5B4B490DA42}.Release|Win32.ActiveCfg = Release|Win32
{0565952A-EA62-46A2-8261-F5B4B490DA42}.Release|Win32.Build.0 = Release|Win32
{027BAD0E-9179-48C1-9733-7AA7E2C2EC70}.Debug|ARM.ActiveCfg = Debug|ARM
{027BAD0E-9179-48C1-9733-7AA7E2C2EC70}.Debug|ARM.Build.0 = Debug|ARM
{027BAD0E-9179-48C1-9733-7AA7E2C2EC70}.Debug|Win32.ActiveCfg = Debug|Win32
{027BAD0E-9179-48C1-9733-7AA7E2C2EC70}.Debug|Win32.Build.0 = Debug|Win32
{027BAD0E-9179-48C1-9733-7AA7E2C2EC70}.Release|ARM.ActiveCfg = Release|ARM
{027BAD0E-9179-48C1-9733-7AA7E2C2EC70}.Release|ARM.Build.0 = Release|ARM
{027BAD0E-9179-48C1-9733-7AA7E2C2EC70}.Release|Win32.ActiveCfg = Release|Win32
{027BAD0E-9179-48C1-9733-7AA7E2C2EC70}.Release|Win32.Build.0 = Release|Win32
{FFC7B532-0502-4D88-AC98-9E89071CBC97}.Debug|ARM.ActiveCfg = Debug|ARM
{FFC7B532-0502-4D88-AC98-9E89071CBC97}.Debug|ARM.Build.0 = Debug|ARM
{FFC7B532-0502-4D88-AC98-9E89071CBC97}.Debug|Win32.ActiveCfg = Debug|Win32
{FFC7B532-0502-4D88-AC98-9E89071CBC97}.Debug|Win32.Build.0 = Debug|Win32
{FFC7B532-0502-4D88-AC98-9E89071CBC97}.Release|ARM.ActiveCfg = Release|ARM
{FFC7B532-0502-4D88-AC98-9E89071CBC97}.Release|ARM.Build.0 = Release|ARM
{FFC7B532-0502-4D88-AC98-9E89071CBC97}.Release|Win32.ActiveCfg = Release|Win32
{FFC7B532-0502-4D88-AC98-9E89071CBC97}.Release|Win32.Build.0 = Release|Win32
{746EA080-5BA9-42C5-9E52-EA421C3F3AFD}.Debug|ARM.ActiveCfg = Debug|ARM
{746EA080-5BA9-42C5-9E52-EA421C3F3AFD}.Debug|ARM.Build.0 = Debug|ARM
{746EA080-5BA9-42C5-9E52-EA421C3F3AFD}.Debug|Win32.ActiveCfg = Debug|Win32
{746EA080-5BA9-42C5-9E52-EA421C3F3AFD}.Debug|Win32.Build.0 = Debug|Win32
{746EA080-5BA9-42C5-9E52-EA421C3F3AFD}.Release|ARM.ActiveCfg = Release|ARM
{746EA080-5BA9-42C5-9E52-EA421C3F3AFD}.Release|ARM.Build.0 = Release|ARM
{746EA080-5BA9-42C5-9E52-EA421C3F3AFD}.Release|Win32.ActiveCfg = Release|Win32
{746EA080-5BA9-42C5-9E52-EA421C3F3AFD}.Release|Win32.Build.0 = Release|Win32
{D5EC8C11-C1D9-47E3-BB82-A93C300FD902}.Debug|ARM.ActiveCfg = Debug|ARM
{D5EC8C11-C1D9-47E3-BB82-A93C300FD902}.Debug|ARM.Build.0 = Debug|ARM
{D5EC8C11-C1D9-47E3-BB82-A93C300FD902}.Debug|Win32.ActiveCfg = Debug|Win32
{D5EC8C11-C1D9-47E3-BB82-A93C300FD902}.Debug|Win32.Build.0 = Debug|Win32
{D5EC8C11-C1D9-47E3-BB82-A93C300FD902}.Release|ARM.ActiveCfg = Release|ARM
{D5EC8C11-C1D9-47E3-BB82-A93C300FD902}.Release|ARM.Build.0 = Release|ARM
{D5EC8C11-C1D9-47E3-BB82-A93C300FD902}.Release|Win32.ActiveCfg = Release|Win32
{D5EC8C11-C1D9-47E3-BB82-A93C300FD902}.Release|Win32.Build.0 = Release|Win32
{6BD78980-9C71-4341-8775-AD19E9EC7305}.Debug|ARM.ActiveCfg = Debug|ARM
{6BD78980-9C71-4341-8775-AD19E9EC7305}.Debug|ARM.Build.0 = Debug|ARM
{6BD78980-9C71-4341-8775-AD19E9EC7305}.Debug|Win32.ActiveCfg = Debug|Win32
{6BD78980-9C71-4341-8775-AD19E9EC7305}.Debug|Win32.Build.0 = Debug|Win32
{6BD78980-9C71-4341-8775-AD19E9EC7305}.Release|ARM.ActiveCfg = Release|ARM
{6BD78980-9C71-4341-8775-AD19E9EC7305}.Release|ARM.Build.0 = Release|ARM
{6BD78980-9C71-4341-8775-AD19E9EC7305}.Release|Win32.ActiveCfg = Release|Win32
{6BD78980-9C71-4341-8775-AD19E9EC7305}.Release|Win32.Build.0 = Release|Win32
{1C4E6DA0-B8C7-4A05-A58E-54A6ED07C8DF}.Debug|ARM.ActiveCfg = Debug|ARM
{1C4E6DA0-B8C7-4A05-A58E-54A6ED07C8DF}.Debug|ARM.Build.0 = Debug|ARM
{1C4E6DA0-B8C7-4A05-A58E-54A6ED07C8DF}.Debug|Win32.ActiveCfg = Debug|Win32
{1C4E6DA0-B8C7-4A05-A58E-54A6ED07C8DF}.Debug|Win32.Build.0 = Debug|Win32
{1C4E6DA0-B8C7-4A05-A58E-54A6ED07C8DF}.Release|ARM.ActiveCfg = Release|ARM
{1C4E6DA0-B8C7-4A05-A58E-54A6ED07C8DF}.Release|ARM.Build.0 = Release|ARM
{1C4E6DA0-B8C7-4A05-A58E-54A6ED07C8DF}.Release|Win32.ActiveCfg = Release|Win32
{1C4E6DA0-B8C7-4A05-A58E-54A6ED07C8DF}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
This diff is collapsed.
/*
mswp8cap_reader.cpp
mediastreamer2 library - modular sound and video processing and streaming
Windows Audio Session API sound card plugin for mediastreamer2
Copyright (C) 2010-2013 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "mediastreamer2/mscommon.h"
#include "mediastreamer2/msticker.h"
#include "mediastreamer2/msvideo.h"
#include "mswp8cap_reader.h"
using namespace Microsoft::WRL;
using namespace Windows::Foundation;
using namespace Windows::Phone::Media::Capture;
using namespace mediastreamer2;
bool MSWP8CapReader::smInstantiated = false;
MSWP8CapReader::MSWP8CapReader()
: mIsInitialized(false), mIsActivated(false), mIsStarted(false),
mCameraLocation(CameraSensorLocation::Front),
mDimensions(MS_VIDEO_SIZE_CIF_W, MS_VIDEO_SIZE_CIF_H),
mVideoDevice(nullptr)
{
if (smInstantiated) {
ms_error("[MSWP8Cap] An video capture filter is already instantiated. A second one can not be created.");
return;
}
mStartCompleted = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS);
if (!mStartCompleted) {
ms_error("[MSWP8Cap] Could not create start event [%i]", GetLastError());
return;
}
mStopCompleted = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS);
if (!mStopCompleted) {
ms_error("[MSWP8Cap] Could not create shutdown event [%i]", GetLastError());
return;
}
if (!selectBestSensorLocation()) {
ms_error("[MSWP8Cap] It looks like this device does not have a camera");
return;
}
mIsInitialized = true;
smInstantiated = true;
}
MSWP8CapReader::~MSWP8CapReader()
{
smInstantiated = false;
}
int MSWP8CapReader::activate()
{
IAsyncOperation<AudioVideoCaptureDevice^> ^openOperation = nullptr;
if (!mIsInitialized) return -1;
if (!selectBestFormat()) return -1;
openOperation = AudioVideoCaptureDevice::OpenForVideoOnlyAsync(mCameraLocation, mDimensions);
openOperation->Completed = ref new AsyncOperationCompletedHandler<AudioVideoCaptureDevice^>([this] (IAsyncOperation<AudioVideoCaptureDevice^> ^operation, Windows::Foundation::AsyncStatus status) {
if (status == Windows::Foundation::AsyncStatus::Completed) {
IAudioVideoCaptureDeviceNative *pNativeDevice = nullptr;
ms_debug("[MSWP8Cap] OpenAsyncOperation completed");
mVideoDevice = operation->GetResults();
HRESULT hr = reinterpret_cast<IUnknown*>(mVideoDevice)->QueryInterface(__uuidof(IAudioVideoCaptureDeviceNative), (void**) &pNativeDevice);
if ((pNativeDevice == nullptr) || FAILED(hr)) {
ms_error("[MSWP8Cap] Unable to query interface IAudioVideoCaptureDeviceNative");
} else {
mNativeVideoDevice = pNativeDevice;
mVideoDevice->VideoEncodingFormat = CameraCaptureVideoFormat::H264;
// Create the sink and notify the start completion
MakeAndInitialize<MSWP8CapSampleSink>(&(this->mVideoSink), this);
mNativeVideoDevice->SetVideoSampleSink(mVideoSink);
mIsActivated = true;
SetEvent(mStartCompleted);
}
}
else if (status == Windows::Foundation::AsyncStatus::Canceled) {
ms_warning("[MSWP8Cap] OpenAsyncOperation has been canceled");
}
else if (status == Windows::Foundation::AsyncStatus::Error) {
ms_error("[MSWP8Cap] OpenAsyncOperation failed");
}
});
return 0;
}
int MSWP8CapReader::deactivate()
{
mIsActivated = false;
return 0;
}
void MSWP8CapReader::start()
{
DWORD waitResult;
if (!mIsStarted && mIsActivated) {
waitResult = WaitForSingleObjectEx(mStartCompleted, 0, FALSE);
if (waitResult == WAIT_OBJECT_0) {
mIsStarted = true;
mVideoCaptureAction = mVideoDevice->StartRecordingToSinkAsync();
mVideoCaptureAction->Completed = ref new AsyncActionCompletedHandler([this] (IAsyncAction ^asyncInfo, Windows::Foundation::AsyncStatus status) {
if (status == Windows::Foundation::AsyncStatus::Completed) {
ms_message("[MSWP8Cap] StartRecordingToSinkAsync completed");
}
else if ((status == Windows::Foundation::AsyncStatus::Error) || (status == Windows::Foundation::AsyncStatus::Canceled)) {
ms_error("[MSWP8Cap] StartRecordingToSinkAsync did not complete");
}
});
}
}
}
void MSWP8CapReader::stop()
{
if (!mIsStarted) return;
if (mVideoDevice) {
try {
mVideoDevice->StopRecordingAsync()->Completed = ref new AsyncActionCompletedHandler([this] (IAsyncAction ^action, Windows::Foundation::AsyncStatus status) {
if (status == Windows::Foundation::AsyncStatus::Completed) {
ms_message("[MSWP8Cap] Video successfully stopped");
} else {
ms_error("[MSWP8Cap] Error while stopping recording");
}
mVideoCaptureAction = nullptr;
mVideoDevice = nullptr;
mIsStarted = false;
SetEvent(mStopCompleted);
});
} catch(...) {
// A Platform::ObjectDisposedException can be raised if the app has had its access
// to video revoked (most commonly when the app is going out of the foreground)
ms_warning("[MSWP8Cap] Exception caught while destroying video capture");
mVideoCaptureAction = nullptr;
mVideoDevice = nullptr;
mIsStarted = false;
SetEvent(mStopCompleted);
}
if (mNativeVideoDevice) {
mNativeVideoDevice->Release();
mNativeVideoDevice = nullptr;
}
if (mVideoSink) {
mVideoSink->Release();
mVideoSink = nullptr;
}
}
}
void MSWP8CapReader::OnSampleAvailable(ULONGLONG hnsPresentationTime, ULONGLONG hnsSampleDuration, DWORD cbSample, BYTE* pSample)
{
// TODO
}
bool MSWP8CapReader::selectBestSensorLocation()
{
Collections::IVectorView<CameraSensorLocation> ^availableSensorLocations;
Collections::IIterator<CameraSensorLocation> ^availableSensorLocationsIterator;
CameraSensorLocation requestedLocation = mCameraLocation;
CameraSensorLocation bestLocation = CameraSensorLocation::Front;
bool locationAvailable = false;
availableSensorLocations = AudioVideoCaptureDevice::AvailableSensorLocations;
availableSensorLocationsIterator = availableSensorLocations->First();
while (availableSensorLocationsIterator->HasCurrent) {
CameraSensorLocation currentLocation = availableSensorLocationsIterator->Current;
locationAvailable = true;
bestLocation = currentLocation;
if (currentLocation == requestedLocation) break;
availableSensorLocationsIterator->MoveNext();
}
if (locationAvailable) {
mCameraLocation = bestLocation;
}
return locationAvailable;
}
bool MSWP8CapReader::selectBestFormat()
{
Collections::IVectorView<Size> ^availableSizes;
Collections::IIterator<Size> ^availableSizesIterator;
MSVideoSize requestedSize;
MSVideoSize bestFoundSize;
bestFoundSize.width = bestFoundSize.height = 0;
requestedSize.width = mDimensions.Width;
requestedSize.height = mDimensions.Height;
availableSizes = AudioVideoCaptureDevice::GetAvailableCaptureResolutions(mCameraLocation);
availableSizesIterator = availableSizes->First();
while (availableSizesIterator->HasCurrent) {
MSVideoSize currentSize;
currentSize.width = availableSizesIterator->Current.Width;
currentSize.height = availableSizesIterator->Current.Height;
ms_message("Seeing format %ix%i", currentSize.width, currentSize.height);
if (ms_video_size_greater_than(requestedSize, currentSize)) {
if (ms_video_size_greater_than(currentSize, bestFoundSize)) {
bestFoundSize = currentSize;
}
}
availableSizesIterator->MoveNext();
}
if ((bestFoundSize.width == 0) && bestFoundSize.height == 0) {
ms_error("This camera does not support our format");
return false;
}
mDimensions.Width = bestFoundSize.width;
mDimensions.Height = bestFoundSize.height;
ms_message("Best camera format is %ix%i", bestFoundSize.width, bestFoundSize.height);
return true;
}
\ No newline at end of file
/*
mswp8cap_reader.h
mediastreamer2 library - modular sound and video processing and streaming
Windows Audio Session API sound card plugin for mediastreamer2
Copyright (C) 2010-2013 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#pragma once
#include "windows.h"
#include "implements.h"
#include <Windows.Phone.Media.Capture.h>
#include <Windows.Phone.Media.Capture.Native.h>
#include "mediastreamer2/msfilter.h"
namespace mediastreamer2
{
class MSWP8CapSampleSink;
class MSWP8CapReader {
public:
MSWP8CapReader();
virtual ~MSWP8CapReader();
int activate();
int deactivate();
bool isStarted() { return mIsStarted; }
void start();
void stop();
void OnSampleAvailable(ULONGLONG hnsPresentationTime, ULONGLONG hnsSampleDuration, DWORD cbSample, BYTE* pSample);
private:
bool selectBestSensorLocation();
bool selectBestFormat();
static bool smInstantiated;
bool mIsInitialized;
bool mIsActivated;
bool mIsStarted;
HANDLE mStartCompleted;
HANDLE mStopCompleted;
Windows::Phone::Media::Capture::CameraSensorLocation mCameraLocation;
Windows::Foundation::Size mDimensions;
Windows::Phone::Media::Capture::AudioVideoCaptureDevice^ mVideoDevice;
MSWP8CapSampleSink *mVideoSink;
IAudioVideoCaptureDeviceNative* mNativeVideoDevice;
Windows::Foundation::IAsyncAction^ mVideoCaptureAction;
};
class MSWP8CapSampleSink
: public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>, ICameraCaptureSampleSink>
{
public:
STDMETHODIMP RuntimeClassInitialize(MSWP8CapReader *reader) {
m_dwSampleCount = 0;
m_reader = reader;
return S_OK;
}
DWORD GetSampleCount() {
return m_dwSampleCount;
}
IFACEMETHODIMP_(void) OnSampleAvailable(ULONGLONG hnsPresentationTime, ULONGLONG hnsSampleDuration, DWORD cbSample, BYTE* pSample) {
m_dwSampleCount++;
if (m_reader) {
m_reader->OnSampleAvailable(hnsPresentationTime, hnsSampleDuration, cbSample, pSample);
}
}
private:
DWORD m_dwSampleCount;
MSWP8CapReader *m_reader;
};
}
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