Commit 32b6326b authored by Ghislain MARY's avatar Ghislain MARY

Enable video preview.

parent 7ccb03b3
This diff is collapsed.
......@@ -24,16 +24,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#pragma once
#include <mediastreamer2/mscommon.h>
#include <mediastreamer2/msfilter.h>
#include <mediastreamer2/msticker.h>
#include <mediastreamer2/msvideo.h>
#include <mediastreamer2/mswebcam.h>
#include <mediastreamer2/rfc3984.h>
#include <mediastreamer2/videostarter.h>
#include "mswinrtvid.h"
#ifdef MS2_WINDOWS_UNIVERSAL
#include <wrl\implements.h>
#include <ppltasks.h>
using namespace Windows::Media::Capture;
using namespace Windows::Media::Devices;
using namespace Windows::Media::MediaProperties;
#endif
#ifdef MS2_WINDOWS_PHONE
#include "implements.h"
......@@ -42,105 +45,119 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif
namespace mswinrtvid
{
class SampleSink;
class MSWinRTCap {
public:
MSWinRTCap();
virtual ~MSWinRTCap();
int activate();
int deactivate();
bool isStarted() { return mIsStarted; }
void start();
void stop();
int feed(MSFilter *f);
void OnSampleAvailable(ULONGLONG hnsPresentationTime, ULONGLONG hnsSampleDuration, DWORD cbSample, BYTE* pSample);
void setCameraLocation(uint32 location);
MSPixFmt getPixFmt() { return mPixFmt; }
void setPixFmt(MSPixFmt pixFmt) { mPixFmt = pixFmt; }
float getFps() { return mVConf.fps; }
void setFps(float fps);
int getBitrate() { return mBitrate; }
void setBitrate(int bitrate);
MSVideoSize getVideoSize();
void setVideoSize(MSVideoSize vs);
const MSVideoConfiguration * getConfigurationList();
void setConfiguration(const MSVideoConfiguration *vconf);
int getCameraSensorRotation() { return mCameraSensorRotation; }
void setDeviceOrientation(int degrees);
void requestIdrFrame();
static void detectCameras(MSWebCamManager *manager, MSWebCamDesc *desc);
private:
void applyFps();
void applyVideoSize();
void bitstreamToMsgb(uint8_t *encoded_buf, size_t size, MSQueue *nalus);
bool selectBestVideoSize();
void configure();
void printProperties();
static bool smInstantiated;
bool mIsInitialized;
bool mIsActivated;
bool mIsStarted;
MSQueue mSampleToSendQueue;
MSQueue mSampleToFreeQueue;
ms_mutex_t mMutex;
Rfc3984Context *mRfc3984Packer;
MSYuvBufAllocator *mAllocator;
int mPackerMode;
uint64_t mStartTime;
int mSamplesCount;
int mBitrate;
int mCameraSensorRotation;
int mDeviceOrientation;
MSVideoStarter mStarter;
MSVideoConfiguration mVConf;
MSPixFmt mPixFmt;
HANDLE mActivationCompleted;
HANDLE mStartCompleted;
HANDLE mStopCompleted;
#ifdef MS2_WINDOWS_PHONE
Windows::Phone::Media::Capture::CameraSensorLocation mCameraLocation;
Windows::Phone::Media::Capture::AudioVideoCaptureDevice^ mVideoDevice;
class SampleSink;
#endif
class MSWinRTCap {
public:
MSWinRTCap();
virtual ~MSWinRTCap();
int activate();
int deactivate();
bool isStarted() { return mIsStarted; }
void start();
void stop();
int feed(MSFilter *f);
void OnSampleAvailable(ULONGLONG hnsPresentationTime, ULONGLONG hnsSampleDuration, DWORD cbSample, BYTE* pSample);
#ifdef MS2_WINDOWS_UNIVERSAL
void setCaptureElement(Windows::UI::Xaml::Controls::CaptureElement^ captureElement) { mCaptureElement = captureElement; };
void setDeviceId(Platform::String^ id) { mDeviceId = id; };
#endif
SampleSink *mVideoSink;
#ifdef MS2_WINDOWS_PHONE
IAudioVideoCaptureDeviceNative* mNativeVideoDevice;
void setCameraLocation(uint32 location);
#endif
};
MSPixFmt getPixFmt() { return mPixFmt; }
void setPixFmt(MSPixFmt pixFmt) { mPixFmt = pixFmt; }
float getFps() { return mVConf.fps; }
void setFps(float fps);
int getBitrate() { return mBitrate; }
void setBitrate(int bitrate);
MSVideoSize getVideoSize();
void setVideoSize(MSVideoSize vs);
const MSVideoConfiguration * getConfigurationList();
void setConfiguration(const MSVideoConfiguration *vconf);
int getCameraSensorRotation() { return mCameraSensorRotation; }
void setDeviceOrientation(int degrees);
void requestIdrFrame();
static void detectCameras(MSWebCamManager *manager, MSWebCamDesc *desc);
private:
void applyFps();
void applyVideoSize();
void bitstreamToMsgb(uint8_t *encoded_buf, size_t size, MSQueue *nalus);
bool selectBestVideoSize();
void configure();
void printProperties();
#ifdef MS2_WINDOWS_UNIVERSAL
static void addCamera(MSWebCamManager *manager, MSWebCamDesc *desc, Platform::String^ DeviceId, Platform::String^ DeviceName);
#endif
static bool smInstantiated;
bool mIsInitialized;
bool mIsActivated;
bool mIsStarted;
MSQueue mSampleToSendQueue;
MSQueue mSampleToFreeQueue;
ms_mutex_t mMutex;
Rfc3984Context *mRfc3984Packer;
MSYuvBufAllocator *mAllocator;
int mPackerMode;
uint64_t mStartTime;
int mSamplesCount;
int mBitrate;
int mCameraSensorRotation;
int mDeviceOrientation;
MSVideoStarter mStarter;
MSVideoConfiguration mVConf;
MSPixFmt mPixFmt;
HANDLE mActivationCompleted;
HANDLE mStartCompleted;
HANDLE mStopCompleted;
#ifdef MS2_WINDOWS_UNIVERSAL
HANDLE mPreviewStartCompleted;
Windows::UI::Xaml::Controls::CaptureElement^ mCaptureElement;
Platform::String^ mDeviceId;
Platform::Agile<MediaCapture^> mCapture;
MediaEncodingProfile^ mEncodingProfile;
Windows::Storage::Streams::InMemoryRandomAccessStream^ mStream;
#endif
#ifdef MS2_WINDOWS_PHONE
Windows::Phone::Media::Capture::CameraSensorLocation mCameraLocation;
Windows::Phone::Media::Capture::AudioVideoCaptureDevice^ mVideoDevice;
SampleSink *mVideoSink;
IAudioVideoCaptureDeviceNative* mNativeVideoDevice;
#endif
};
#ifdef MS2_WINDOWS_PHONE
class SampleSink
: public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>, ICameraCaptureSampleSink>
{
public:
STDMETHODIMP RuntimeClassInitialize(MSWinRTCap *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;
MSWinRTCap *m_reader;
};
class SampleSink
: public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>, ICameraCaptureSampleSink>
{
public:
STDMETHODIMP RuntimeClassInitialize(MSWinRTCap *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;
MSWinRTCap *m_reader;
};
#endif
}
......@@ -25,7 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "VideoBuffer.h"
using namespace Microsoft::WRL;
using namespace mswinrtvid;
//using namespace Mediastreamer2::WinRTVideo;
......
......@@ -24,10 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#pragma once
#include <mediastreamer2/mscommon.h>
#include <mediastreamer2/msfilter.h>
#include <mediastreamer2/msticker.h>
#include <mediastreamer2/msvideo.h>
#include "mswinrtvid.h"
#include <mediastreamer2/rfc3984.h>
#ifdef MS2_WINDOWS_PHONE
......@@ -41,51 +39,48 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif
namespace mswinrtvid
{
class MSWinRTDis {
public:
MSWinRTDis();
virtual ~MSWinRTDis();
int activate();
int deactivate();
bool isStarted() { return mIsStarted; }
void start();
void stop();
int feed(MSFilter *f);
MSVideoSize getVideoSize();
void setVideoSize(MSVideoSize vs);
void setPixFmt(MSPixFmt pix_fmt) { mPixFmt = pix_fmt; }
class MSWinRTDis {
public:
MSWinRTDis();
virtual ~MSWinRTDis();
int activate();
int deactivate();
bool isStarted() { return mIsStarted; }
void start();
void stop();
int feed(MSFilter *f);
MSVideoSize getVideoSize();
void setVideoSize(MSVideoSize vs);
void setPixFmt(MSPixFmt pix_fmt) { mPixFmt = pix_fmt; }
#ifdef MS2_WINDOWS_PHONE
Mediastreamer2::WinRTVideo::IVideoRenderer^ getVideoRenderer();
void setVideoRenderer(Mediastreamer2::WinRTVideo::IVideoRenderer^ renderer);
Mediastreamer2::WinRTVideo::IVideoRenderer^ getVideoRenderer();
void setVideoRenderer(Mediastreamer2::WinRTVideo::IVideoRenderer^ renderer);
#endif
private:
int nalusToFrame(MSQueue *nalus, bool *new_sps_pps);
void enlargeBitstream(int newSize);
bool checkSPSChange(mblk_t *sps);
bool checkPPSChange(mblk_t *pps);
void updateSPS(mblk_t *sps);
void updatePPS(mblk_t *pps);
void updateVideoSizeFromSPS();
static bool smInstantiated;
bool mIsInitialized;
bool mIsActivated;
bool mIsStarted;
int mWidth;
int mHeight;
Rfc3984Context *mRfc3984Unpacker;
MSPixFmt mPixFmt;
int mBitstreamSize;
uint8_t *mBitstream;
mblk_t *mSPS;
mblk_t *mPPS;
private:
int nalusToFrame(MSQueue *nalus, bool *new_sps_pps);
void enlargeBitstream(int newSize);
bool checkSPSChange(mblk_t *sps);
bool checkPPSChange(mblk_t *pps);
void updateSPS(mblk_t *sps);
void updatePPS(mblk_t *pps);
void updateVideoSizeFromSPS();
static bool smInstantiated;
bool mIsInitialized;
bool mIsActivated;
bool mIsStarted;
int mWidth;
int mHeight;
Rfc3984Context *mRfc3984Unpacker;
MSPixFmt mPixFmt;
int mBitstreamSize;
uint8_t *mBitstream;
mblk_t *mSPS;
mblk_t *mPPS;
#ifdef MS2_WINDOWS_PHONE
Mediastreamer2::WinRTVideo::IVideoRenderer^ mRenderer;
Mediastreamer2::WinRTVideo::IVideoRenderer^ mRenderer;
#endif
bool mFirstFrameReceived;
};
}
bool mFirstFrameReceived;
};
......@@ -27,15 +27,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mswinrtcap.h"
#include "mswinrtdis.h"
#ifdef MS2_WINDOWS_PHONE
#include "IVideoRenderer.h"
#endif
using namespace mswinrtvid;
//using namespace Mediastreamer2::WinRTVideo;
/******************************************************************************
* Methods to (de)initialize and run the WP8 video capture filter *
* Methods to (de)initialize and run the WinRT video capture filter *
*****************************************************************************/
static void ms_winrtcap_read_init(MSFilter *f) {
......@@ -69,7 +70,7 @@ static void ms_winrtcap_read_uninit(MSFilter *f) {
/******************************************************************************
* Methods to configure the Windows Phone 8 video capture filter *
* Methods to configure the WinRT video capture filter *
*****************************************************************************/
static int ms_winrtcap_get_fps(MSFilter *f, void *arg) {
......@@ -157,27 +158,38 @@ 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 },
{ MS_FILTER_GET_PIX_FMT, ms_winrtcap_get_pix_fmt },
{ MS_FILTER_SET_PIX_FMT, ms_winrtcap_set_pix_fmt },
{ MS_FILTER_GET_VIDEO_SIZE, ms_winrtcap_get_vsize },
{ MS_FILTER_SET_VIDEO_SIZE, ms_winrtcap_set_vsize },
{ MS_FILTER_GET_BITRATE, ms_winrtcap_get_bitrate },
{ MS_FILTER_SET_BITRATE, ms_winrtcap_set_bitrate },
{ MS_FILTER_REQ_VFU, ms_winrtcap_req_vfu },
{ MS_VIDEO_ENCODER_REQ_VFU, ms_winrtcap_req_vfu },
{ MS_VIDEO_ENCODER_GET_CONFIGURATION_LIST, ms_winrtcap_get_configuration_list },
{ MS_VIDEO_ENCODER_SET_CONFIGURATION, ms_winrtcap_set_configuration },
{ MS_VIDEO_CAPTURE_GET_CAMERA_SENSOR_ROTATION, ms_winrtcap_get_camera_sensor_rotation },
{ MS_VIDEO_CAPTURE_SET_DEVICE_ORIENTATION, ms_winrtcap_set_device_orientation },
{ 0, NULL }
{ MS_FILTER_GET_FPS, ms_winrtcap_get_fps },
{ MS_FILTER_SET_FPS, ms_winrtcap_set_fps },
{ MS_FILTER_GET_PIX_FMT, ms_winrtcap_get_pix_fmt },
{ MS_FILTER_SET_PIX_FMT, ms_winrtcap_set_pix_fmt },
{ MS_FILTER_GET_VIDEO_SIZE, ms_winrtcap_get_vsize },
{ MS_FILTER_SET_VIDEO_SIZE, ms_winrtcap_set_vsize },
{ MS_FILTER_GET_BITRATE, ms_winrtcap_get_bitrate },
{ MS_FILTER_SET_BITRATE, ms_winrtcap_set_bitrate },
{ MS_FILTER_REQ_VFU, ms_winrtcap_req_vfu },
{ MS_VIDEO_ENCODER_REQ_VFU, ms_winrtcap_req_vfu },
{ MS_VIDEO_ENCODER_GET_CONFIGURATION_LIST, ms_winrtcap_get_configuration_list },
{ MS_VIDEO_ENCODER_SET_CONFIGURATION, ms_winrtcap_set_configuration },
{ 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 }
};
/******************************************************************************
* Definition of the Windows Phone 8 video capture filter *
* Definition of the WinRT video capture filter *
*****************************************************************************/
#define MS_WINRTCAP_READ_ID MS_FILTER_PLUGIN_ID
......@@ -211,7 +223,7 @@ MS_FILTER_DESC_EXPORT(ms_winrtcap_read_desc)
/******************************************************************************
* Definition of the Windows Phone 8 video camera detection *
* Definition of the WinRT video camera detection *
*****************************************************************************/
static void ms_winrtcap_detect(MSWebCamManager *m);
......@@ -219,7 +231,12 @@ static void ms_winrtcap_detect(MSWebCamManager *m);
static MSFilter *ms_winrtcap_create_reader(MSWebCam *cam) {
MSFilter *f = ms_filter_new_from_desc(&ms_winrtcap_read_desc);
MSWinRTCap *r = static_cast<MSWinRTCap *>(f->data);
#if defined(MS2_WINDOWS_UNIVERSAL)
WinRTWebcam* winrtcam = static_cast<WinRTWebcam *>(cam->data);
r->setDeviceId(ref new Platform::String(winrtcam->id));
#elif defined(MS2_WINDOWS_PHONE)
r->setCameraLocation((uint32)cam->data);
#endif
return f;
}
......@@ -245,7 +262,7 @@ static void ms_winrtcap_detect(MSWebCamManager *m) {
/******************************************************************************
* Methods to (de)initialize and run the WP8 video display filter *
* Methods to (de)initialize and run the WinRT video display filter *
*****************************************************************************/
static void ms_winrtdis_init(MSFilter *f) {
......@@ -281,7 +298,7 @@ static void ms_winrtdis_uninit(MSFilter *f) {
/******************************************************************************
* Methods to configure the Windows Phone 8 video display filter *
* Methods to configure the WinRT video display filter *
*****************************************************************************/
static int ms_winrtdis_get_vsize(MSFilter *f, void *arg) {
......@@ -312,16 +329,6 @@ static int ms_winrtdis_support_rendering(MSFilter *f, void *arg) {
return 0;
}
template <class T> class RefToPtrProxy
{
public:
RefToPtrProxy(T obj) : mObj(obj) {}
~RefToPtrProxy() { mObj = nullptr; }
T Ref() { return mObj; }
private:
T mObj;
};
static int ms_winrtdis_set_native_window_id(MSFilter *f, void *arg) {
MSWinRTDis *w = static_cast<MSWinRTDis *>(f->data);
unsigned long *ptr = (unsigned long *)arg;
......@@ -334,22 +341,22 @@ static int ms_winrtdis_set_native_window_id(MSFilter *f, void *arg) {
}
static MSFilterMethod ms_winrtdis_methods[] = {
{ MS_FILTER_GET_VIDEO_SIZE, ms_winrtdis_get_vsize },
{ MS_FILTER_SET_VIDEO_SIZE, ms_winrtdis_set_vsize },
{ MS_FILTER_SET_PIX_FMT, ms_winrtdis_set_pix_fmt },
{ MS_VIDEO_DECODER_SUPPORT_RENDERING, ms_winrtdis_support_rendering },
{ MS_VIDEO_DISPLAY_SET_NATIVE_WINDOW_ID, ms_winrtdis_set_native_window_id },
{ 0, NULL }
{ MS_FILTER_GET_VIDEO_SIZE, ms_winrtdis_get_vsize },
{ MS_FILTER_SET_VIDEO_SIZE, ms_winrtdis_set_vsize },
{ MS_FILTER_SET_PIX_FMT, ms_winrtdis_set_pix_fmt },
{ MS_VIDEO_DECODER_SUPPORT_RENDERING, ms_winrtdis_support_rendering },
{ MS_VIDEO_DISPLAY_SET_NATIVE_WINDOW_ID, ms_winrtdis_set_native_window_id },
{ 0, NULL }
};
/******************************************************************************
* Definition of the Windows Phone 8 video display filter *
* Definition of the WinRT video display filter *
*****************************************************************************/
#define MS_WINRTDIS_ID MS_FILTER_PLUGIN_ID
#define MS_WINRTDIS_NAME "MSWinRTDis"
#define MS_WINRTDIS_DESCRIPTION "Windows Phone 8 video display"
#define MS_WINRTDIS_DESCRIPTION "WinRT video display"
#define MS_WINRTDIS_CATEGORY MS_FILTER_DECODER_RENDERER
#define MS_WINRTDIS_ENC_FMT "H264"
#define MS_WINRTDIS_NINPUTS 2
......
/*
mswinrtvid.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 <mediastreamer2/mscommon.h>
#include <mediastreamer2/msfilter.h>
#include <mediastreamer2/msticker.h>
#include <mediastreamer2/msvideo.h>
#include <vector>
#ifdef MS2_WINDOWS_UNIVERSAL
#include <agile.h>
typedef struct WinRTWebcam {
std::vector<wchar_t> *id_vector;
LPWSTR id;
} WinRTWebcam;
#endif
template <class T> class RefToPtrProxy
{
public:
RefToPtrProxy(T obj) : mObj(obj) {}
~RefToPtrProxy() { mObj = nullptr; }
T Ref() { return mObj; }
private:
T mObj;
};
......@@ -42,6 +42,7 @@
<ItemGroup>
<ClInclude Include="..\..\mswinrtcap.h" />
<ClInclude Include="..\..\mswinrtdis.h" />
<ClInclude Include="..\..\mswinrtvid.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{2d0e44c4-e51d-4911-b876-345d1e5e5209}</ProjectGuid>
......
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