Commit 2cdd4b72 authored by Ghislain MARY's avatar Ghislain MARY

Handle capture orientation + Select best video size according to camera capabilities.

parent f459870b
This diff is collapsed.
......@@ -46,6 +46,7 @@ namespace libmswinrtvid
MSWinRTCap();
virtual ~MSWinRTCap();
void initialize();
int activate();
int deactivate();
bool isStarted() { return mIsStarted; }
......@@ -55,15 +56,17 @@ 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 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; }
MSPixFmt getPixFmt() { return MS_YUV420P; }
float getFps() { return mFps; }
float getAverageFps();
void setFps(float fps);
MSVideoSize getVideoSize();
void setVideoSize(MSVideoSize vs);
int getCameraSensorRotation() { return mCameraSensorRotation; }
int getDeviceOrientation() { return mDeviceOrientation; }
void setDeviceOrientation(int degrees);
static void detectCameras(MSWebCamManager *manager, MSWebCamDesc *desc);
......@@ -71,7 +74,7 @@ namespace libmswinrtvid
private:
void applyFps();
void applyVideoSize();
bool selectBestVideoSize();
void selectBestVideoSize(MSVideoSize vs);
void configure();
static void addCamera(MSWebCamManager *manager, MSWebCamDesc *desc, Windows::Devices::Enumeration::DeviceInformation^ DeviceInfo);
static void registerCameras(MSWebCamManager *manager);
......@@ -92,15 +95,18 @@ namespace libmswinrtvid
int mCameraSensorRotation;
int mDeviceOrientation;
MSVideoStarter mStarter;
HANDLE mActivationCompleted;
HANDLE mInitializationCompleted;
HANDLE mStartCompleted;
HANDLE mStopCompleted;
HANDLE mPreviewStartCompleted;
HANDLE mPreviewStopCompleted;
Windows::UI::Xaml::Controls::CaptureElement^ mCaptureElement;
Platform::String^ mDeviceId;
bool mFront;
bool mExternal;
Platform::Agile<MediaCapture^> mCapture;
MediaEncodingProfile^ mEncodingProfile;
ComPtr<IMFMediaSink> mMediaSink;
const GUID mRotationKey;
};
}
......@@ -232,16 +232,21 @@ int MSWinRTDis::feed(MSFilter *f)
if (mIsStarted) {
mblk_t *im;
while ((im = ms_queue_get(f->inputs[0])) != NULL) {
if ((f->inputs[0] != NULL) && ((im = ms_queue_peek_last(f->inputs[0])) != NULL)) {
int size = 0;
MSPicture buf;
ms_yuv_buf_init_from_mblk(&buf, im);
if ((buf.w != mSampleHandler->Width) || (buf.h != mSampleHandler->Height)) {
//ms_error("GMA: MSWinRTDis size change: %dx%d", buf.w, buf.h);
mSampleHandler->Width = buf.w;
mSampleHandler->Height = buf.h;
mSampleHandler->RequestMediaElementRestart();
if (mBuffer) ms_free(mBuffer);
if (mBuffer) {
ms_free(mBuffer);
mBuffer = NULL;
}
}
//ms_error("GMA: buf=%dx%d", buf.w, buf.h);
size = (buf.w * buf.h * 3) / 2;
if (!mBuffer) mBuffer = (uint8_t *)ms_malloc(size);
int ysize = buf.w * buf.h;
......@@ -249,19 +254,17 @@ int MSWinRTDis::feed(MSFilter *f)
memcpy(mBuffer, buf.planes[0], ysize);
memcpy(mBuffer + ysize, buf.planes[2], usize);
memcpy(mBuffer + ysize + usize, buf.planes[1], usize);
freemsg(im);
if (size > 0) {
ComPtr<VideoBuffer> spVideoBuffer = NULL;
MakeAndInitialize<VideoBuffer>(&spVideoBuffer, mBuffer, size);
mSampleHandler->Feed(VideoBuffer::GetIBuffer(spVideoBuffer), f->ticker->time);
}
}
} else {
if (f->inputs[0] != NULL) {
ms_queue_flush(f->inputs[0]);
}
}
if (f->inputs[0] != NULL) {
ms_queue_flush(f->inputs[0]);
}
if (f->inputs[1] != NULL) {
ms_queue_flush(f->inputs[1]);
}
......
......@@ -113,15 +113,12 @@ static int ms_winrtcap_set_vsize(MSFilter *f, void *arg) {
return 0;
}
static int ms_winrtcap_get_camera_sensor_rotation(MSFilter *f, void *arg) {
MSWinRTCap *r = static_cast<MSWinRTCap *>(f->data);
*((int *)arg) = r->getCameraSensorRotation();
return 0;
}
static int ms_winrtcap_set_device_orientation(MSFilter *f, void *arg) {
MSWinRTCap *r = static_cast<MSWinRTCap *>(f->data);
r->setDeviceOrientation(*((int *)arg));
int orientation = *((int *)arg);
if (r->getDeviceOrientation() != orientation) {
r->setDeviceOrientation(orientation);
}
return 0;
}
......@@ -141,7 +138,6 @@ static MSFilterMethod ms_winrtcap_read_methods[] = {
{ MS_FILTER_GET_PIX_FMT, ms_winrtcap_get_pix_fmt },
{ MS_FILTER_GET_VIDEO_SIZE, ms_winrtcap_get_vsize },
{ MS_FILTER_SET_VIDEO_SIZE, ms_winrtcap_set_vsize },
{ MS_VIDEO_CAPTURE_GET_CAMERA_SENSOR_ROTATION, ms_winrtcap_get_camera_sensor_rotation },
{ 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 }
......@@ -193,6 +189,9 @@ static MSFilter *ms_winrtcap_create_reader(MSWebCam *cam) {
MSWinRTCap *r = static_cast<MSWinRTCap *>(f->data);
WinRTWebcam* winrtcam = static_cast<WinRTWebcam *>(cam->data);
r->setDeviceId(ref new Platform::String(winrtcam->id));
r->setFront(winrtcam->front == TRUE);
r->setExternal(winrtcam->external == TRUE);
r->initialize();
return f;
}
......
......@@ -38,6 +38,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
typedef struct WinRTWebcam {
std::vector<wchar_t> *id_vector;
LPWSTR id;
bool_t external;
bool_t front;
} WinRTWebcam;
#endif
......
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