Commit 3c604c4a authored by Ghislain MARY's avatar Ghislain MARY

Capture performed (need to output the samples now) + cleanup of display.

parent 2da506c1
This diff is collapsed.
......@@ -53,53 +53,41 @@ namespace libmswinrtvid
void stop();
int feed(MSFilter *f);
void OnSampleAvailable(ULONGLONG hnsPresentationTime, ULONGLONG hnsSampleDuration, DWORD cbSample, BYTE* pSample);
//void OnSampleAvailable(ULONGLONG hnsPresentationTime, ULONGLONG hnsSampleDuration, DWORD cbSample, BYTE* pSample);
void setCaptureElement(Windows::UI::Xaml::Controls::CaptureElement^ captureElement) { mCaptureElement = captureElement; };
void setDeviceId(Platform::String^ id) { mDeviceId = id; };
MSPixFmt getPixFmt() { return mPixFmt; }
void setPixFmt(MSPixFmt pixFmt) { mPixFmt = pixFmt; }
float getFps() { return mVConf.fps; }
MSPixFmt getPixFmt() { return MS_YUV420P; }
float getFps() { return mFps; }
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 void addCamera(MSWebCamManager *manager, MSWebCamDesc *desc, Platform::String^ DeviceId, Platform::String^ DeviceName);
static bool smInstantiated;
bool mIsInitialized;
bool mIsActivated;
bool mIsStarted;
float mFps;
MSVideoSize mVideoSize;
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;
......
This diff is collapsed.
......@@ -131,35 +131,15 @@ namespace libmswinrtvid
int feed(MSFilter *f);
MSVideoSize getVideoSize();
void setVideoSize(MSVideoSize vs);
void setPixFmt(MSPixFmt pix_fmt) { mSampleHandler->PixFmt = pix_fmt; }
void enableAVPF(bool enable) { mAVPFEnabled = enable; }
void setMediaElement(Windows::UI::Xaml::Controls::MediaElement^ mediaElement) { mSampleHandler->MediaElement = mediaElement; }
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();
#if 0
void startMediaElement();
void stopMediaElement();
#endif
static bool smInstantiated;
bool mIsInitialized;
bool mIsActivated;
bool mIsStarted;
Rfc3984Context *mRfc3984Unpacker;
int mBitstreamSize;
uint8_t *mBitstream;
mblk_t *mSPS;
mblk_t *mPPS;
bool mAVPFEnabled;
uint8_t *mBuffer;
MSWinRTDisSampleHandler^ mSampleHandler;
Windows::Media::Core::MediaStreamSource^ mMediaStreamSource;
bool mFirstFrameReceived;
};
}
This diff is collapsed.
......@@ -35,6 +35,66 @@ namespace libmswinrtvid {
class MSWinRTMediaSink;
template<class T>
class AsyncCallback : public IMFAsyncCallback
{
public:
typedef HRESULT(T::*InvokeFn)(IMFAsyncResult *pAsyncResult);
AsyncCallback(T *pParent, InvokeFn fn) : m_pParent(pParent), m_pInvokeFn(fn)
{
}
// IUnknown
STDMETHODIMP_(ULONG) AddRef() {
// Delegate to parent class.
return m_pParent->AddRef();
}
STDMETHODIMP_(ULONG) Release() {
// Delegate to parent class.
return m_pParent->Release();
}
STDMETHODIMP QueryInterface(REFIID iid, void** ppv)
{
if (!ppv)
{
return E_POINTER;
}
if (iid == __uuidof(IUnknown))
{
*ppv = static_cast<IUnknown*>(static_cast<IMFAsyncCallback*>(this));
}
else if (iid == __uuidof(IMFAsyncCallback))
{
*ppv = static_cast<IMFAsyncCallback*>(this);
}
else
{
*ppv = NULL;
return E_NOINTERFACE;
}
AddRef();
return S_OK;
}
// IMFAsyncCallback methods
STDMETHODIMP GetParameters(DWORD*, DWORD*)
{
// Implementation of this method is optional.
return E_NOTIMPL;
}
STDMETHODIMP Invoke(IMFAsyncResult* pAsyncResult)
{
return (m_pParent->*m_pInvokeFn)(pAsyncResult);
}
T *m_pParent;
InvokeFn m_pInvokeFn;
};
class MSWinRTStreamSink : public IMFStreamSink, public IMFMediaTypeHandler
{
public:
......@@ -63,15 +123,15 @@ namespace libmswinrtvid {
Op_Count // Number of operations
};
// CAsyncOperation:
// MSWinRTAsyncOperation:
// Used to queue asynchronous operations. When we call MFPutWorkItem, we use this
// object for the callback state (pState). Then, when the callback is invoked,
// we can use the object to determine which asynchronous operation to perform.
class CAsyncOperation : public IUnknown
class MSWinRTAsyncOperation : public IUnknown
{
public:
CAsyncOperation(StreamOperation op);
MSWinRTAsyncOperation(StreamOperation op);
StreamOperation m_op; // The operation to perform.
......@@ -82,7 +142,7 @@ namespace libmswinrtvid {
private:
long _cRef;
virtual ~CAsyncOperation();
virtual ~MSWinRTAsyncOperation();
};
public:
......@@ -139,23 +199,22 @@ namespace libmswinrtvid {
HRESULT ValidateOperation(StreamOperation op);
HRESULT QueueAsyncOperation(StreamOperation op);
HRESULT OnDispatchWorkItem(IMFAsyncResult *pAsyncResult);
void DispatchProcessSample(CAsyncOperation *pOp);
void DispatchProcessSample(MSWinRTAsyncOperation *pOp);
bool DropSamplesFromQueue();
bool SendSampleFromQueue();
bool ProcessSamplesFromQueue(bool fFlush);
void ProcessFormatChange(IMFMediaType *pMediaType);
HRESULT PrepareSample(IMFSample *pSample);
void HandleError(HRESULT hr);
private:
std::recursive_mutex _mutex;
long _cRef; // reference count
//CritSec _critSec; // critical section for thread safety
DWORD _dwIdentifier;
State _state;
bool _IsShutdown; // Flag to indicate if Shutdown() method was called.
bool _Connected;
bool _fGetStartTimeFromSample;
bool _fWaitingForFirstSample;
bool _fFirstSampleAfterConnect;
......@@ -175,9 +234,7 @@ namespace libmswinrtvid {
ComPtrList<IUnknown> _SampleQueue; // Queue to hold samples and markers.
// Applies to: ProcessSample, PlaceMarker
//Network::INetworkChannel^ _networkSender;
//AsyncCallback<CStreamSink> _WorkQueueCB; // Callback for the work queue.
AsyncCallback<MSWinRTStreamSink> _WorkQueueCB; // Callback for the work queue.
ComPtr<IUnknown> _spFTM;
};
......@@ -197,14 +254,14 @@ namespace libmswinrtvid {
MSWinRTMediaSink();
~MSWinRTMediaSink();
HRESULT RuntimeClassInitialize(/*ISinkCallback ^callback,*/ Windows::Media::MediaProperties::IMediaEncodingProperties ^videoEncodingProperties);
HRESULT RuntimeClassInitialize(Windows::Media::MediaProperties::IMediaEncodingProperties ^videoEncodingProperties);
// IMediaExtension
IFACEMETHOD(SetProperties) (ABI::Windows::Foundation::Collections::IPropertySet *pConfiguration) { return S_OK; }
// IMFMediaSink methods
IFACEMETHOD(GetCharacteristics) (DWORD *pdwCharacteristics);
IFACEMETHOD(AddStreamSink)(/* [in] */ DWORD dwStreamSinkIdentifier, /* [in] */ IMFMediaType *pMediaType, /* [out] */ IMFStreamSink **ppStreamSink);
IFACEMETHOD(AddStreamSink) (/* [in] */ DWORD dwStreamSinkIdentifier, /* [in] */ IMFMediaType *pMediaType, /* [out] */ IMFStreamSink **ppStreamSink);
IFACEMETHOD(RemoveStreamSink) (DWORD dwStreamSinkIdentifier);
IFACEMETHOD(GetStreamSinkCount) (_Out_ DWORD *pcStreamSinkCount);
IFACEMETHOD(GetStreamSinkByIndex) (DWORD dwIndex, _Outptr_ IMFStreamSink **ppStreamSink);
......@@ -225,17 +282,6 @@ namespace libmswinrtvid {
void ReportEndOfStream();
private:
//typedef ComPtrList<IMFStreamSink> StreamContainer;
private:
//void StartListening();
//void StartReceiving(Network::IMediaBufferWrapper *pReceiveBuffer);
//concurrency::task<void> SendPacket(Network::IBufferPacket *pPacket);
//String ^PrepareRemoteUrl(StreamSocketInformation ^info);
//void SendDescription();
//ComPtr<Network::IMediaBufferWrapper> FillStreamDescription(CStreamSink *pStream, StspStreamDescription *pStreamDescription);
void HandleError(HRESULT hr);
void SetVideoStreamProperties(_In_opt_ Windows::Media::MediaProperties::IMediaEncodingProperties ^mediaEncodingProperties);
......@@ -249,20 +295,15 @@ namespace libmswinrtvid {
private:
std::recursive_mutex _mutex;
ComPtrList<IMFStreamSink> _streams;
ComPtr<IMFStreamSink> _stream;
long _cRef; // reference count
//CritSec _critSec; // critical section for thread safety
bool _IsShutdown; // Flag to indicate if Shutdown() method was called.
bool _IsConnected;
LONGLONG _llStartTime;
ComPtr<IMFPresentationClock> _spClock; // Presentation clock.
//Network::INetworkChannel^ _networkSender;
//ISinkCallback^ _callback;
//ComPtr<Network::IMediaBufferWrapper> _spReceiveBuffer;
//StreamContainer _streams;
long _cStreamsEnded;
String^ _remoteUrl;
......
......@@ -95,13 +95,6 @@ static int ms_winrtcap_get_pix_fmt(MSFilter *f, void *arg) {
return 0;
}
static int ms_winrtcap_set_pix_fmt(MSFilter *f, void *arg) {
MSWinRTCap *r = static_cast<MSWinRTCap *>(f->data);
MSPixFmt *fmt = static_cast<MSPixFmt *>(arg);
r->setPixFmt(*fmt);
return 0;
}
static int ms_winrtcap_get_vsize(MSFilter *f, void *arg) {
MSWinRTCap *r = static_cast<MSWinRTCap *>(f->data);
MSVideoSize *vs = static_cast<MSVideoSize *>(arg);
......@@ -116,39 +109,6 @@ static int ms_winrtcap_set_vsize(MSFilter *f, void *arg) {
return 0;
}
static int ms_winrtcap_get_bitrate(MSFilter *f, void *arg) {
MSWinRTCap *r = static_cast<MSWinRTCap *>(f->data);
*((int *)arg) = r->getBitrate();
return 0;
}
static int ms_winrtcap_set_bitrate(MSFilter *f, void *arg) {
MSWinRTCap *r = static_cast<MSWinRTCap *>(f->data);
r->setBitrate(*((int *)arg));
return 0;
}
static int ms_winrtcap_req_vfu(MSFilter *f, void *arg) {
MS_UNUSED(arg);
MSWinRTCap *r = static_cast<MSWinRTCap *>(f->data);
r->requestIdrFrame();
return 0;
}
static int ms_winrtcap_get_configuration_list(MSFilter *f, void *arg) {
MSWinRTCap *r = static_cast<MSWinRTCap *>(f->data);
const MSVideoConfiguration **vconf_list = (const MSVideoConfiguration **)arg;
*vconf_list = r->getConfigurationList();
return 0;
}
static int ms_winrtcap_set_configuration(MSFilter *f, void *arg) {
MSWinRTCap *r = static_cast<MSWinRTCap *>(f->data);
const MSVideoConfiguration *vconf = (const MSVideoConfiguration *)arg;
r->setConfiguration(vconf);
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();
......@@ -175,15 +135,8 @@ 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 },
{ MS_VIDEO_DISPLAY_SET_NATIVE_WINDOW_ID, ms_winrtcap_set_native_window_id },
......@@ -198,8 +151,8 @@ static MSFilterMethod ms_winrtcap_read_methods[] = {
#define MS_WINRTCAP_READ_ID MS_FILTER_PLUGIN_ID
#define MS_WINRTCAP_READ_NAME "MSWinRTCap"
#define MS_WINRTCAP_READ_DESCRIPTION "WinRT video capture"
#define MS_WINRTCAP_READ_CATEGORY MS_FILTER_ENCODING_CAPTURER
#define MS_WINRTCAP_READ_ENC_FMT "H264"
#define MS_WINRTCAP_READ_CATEGORY MS_FILTER_OTHER
#define MS_WINRTCAP_READ_ENC_FMT NULL
#define MS_WINRTCAP_READ_NINPUTS 0
#define MS_WINRTCAP_READ_NOUTPUTS 1
#define MS_WINRTCAP_READ_FLAGS 0
......@@ -234,28 +187,18 @@ 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;
}
static bool_t ms_winrtcap_encode_to_mime_type(MSWebCam *cam, const char *mime_type) {
MS_UNUSED(cam);
if (strcmp(mime_type, "H264") == 0) return TRUE;
return FALSE;
}
static MSWebCamDesc ms_winrtcap_desc = {
"MSWinRTCap",
ms_winrtcap_detect,
NULL,
ms_winrtcap_create_reader,
NULL,
ms_winrtcap_encode_to_mime_type
NULL
};
static void ms_winrtcap_detect(MSWebCamManager *m) {
......@@ -276,18 +219,11 @@ static void ms_winrtdis_init(MSFilter *f) {
static void ms_winrtdis_preprocess(MSFilter *f) {
MSWinRTDis *w = static_cast<MSWinRTDis *>(f->data);
w->activate();
#ifdef MS2_WINDOWS_UNIVERSAL
w->start();
#endif
}
static void ms_winrtdis_process(MSFilter *f) {
MSWinRTDis *w = static_cast<MSWinRTDis *>(f->data);
#ifdef MS2_WINDOWS_PHONE
if (!w->isStarted()) {
w->start();
}
#endif
if (w->isStarted()) {
w->feed(f);
}
......@@ -322,48 +258,17 @@ static int ms_winrtdis_set_vsize(MSFilter *f, void *arg) {
return 0;
}
static int ms_winrtdis_set_pix_fmt(MSFilter *f, void *arg) {
MSWinRTDis *w = static_cast<MSWinRTDis *>(f->data);
MSPixFmt *fmt = static_cast<MSPixFmt *>(arg);
w->setPixFmt(*fmt);
return 0;
}
static int ms_winrtdis_support_rendering(MSFilter *f, void *arg) {
MS_UNUSED(f);
MSVideoDisplayDecodingSupport *decoding_support = static_cast<MSVideoDisplayDecodingSupport *>(arg);
if (strcmp(decoding_support->mime_type, "H264") == 0) decoding_support->supported = TRUE;
else decoding_support->supported = FALSE;
return 0;
}
static int ms_winrtdis_enable_avpf(MSFilter *f, void *arg) {
MSWinRTDis *w = static_cast<MSWinRTDis *>(f->data);
w->enableAVPF(*((bool_t *)arg) ? true : false);
return 0;
}
static int ms_winrtdis_set_native_window_id(MSFilter *f, void *arg) {
MSWinRTDis *w = static_cast<MSWinRTDis *>(f->data);
#if defined(MS2_WINDOWS_UNIVERSAL)
RefToPtrProxy<Platform::Object^> *proxy = static_cast<RefToPtrProxy<Platform::Object^>*>((void *)(*((PULONG_PTR)arg)));
Windows::UI::Xaml::Controls::MediaElement^ mediaElement = dynamic_cast<Windows::UI::Xaml::Controls::MediaElement^>(proxy->Ref());
w->setMediaElement(mediaElement);
#elif defined(MS2_WINDOWS_PHONE)
unsigned long *ptr = (unsigned long *)arg;
RefToPtrProxy<IVideoRenderer^> *proxy = reinterpret_cast< RefToPtrProxy<IVideoRenderer^> *>(*ptr);
IVideoRenderer^ renderer = (proxy) ? proxy->Ref() : nullptr;
w->setVideoRenderer(renderer);
#endif
return 0;
}
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_DECODER_ENABLE_AVPF, ms_winrtdis_enable_avpf },
{ MS_VIDEO_DISPLAY_SET_NATIVE_WINDOW_ID, ms_winrtdis_set_native_window_id },
{ 0, NULL }
};
......@@ -376,8 +281,8 @@ static MSFilterMethod ms_winrtdis_methods[] = {
#define MS_WINRTDIS_ID MS_FILTER_PLUGIN_ID
#define MS_WINRTDIS_NAME "MSWinRTDis"
#define MS_WINRTDIS_DESCRIPTION "WinRT video display"
#define MS_WINRTDIS_CATEGORY MS_FILTER_DECODER_RENDERER
#define MS_WINRTDIS_ENC_FMT "H264"
#define MS_WINRTDIS_CATEGORY MS_FILTER_OTHER
#define MS_WINRTDIS_ENC_FMT NULL
#define MS_WINRTDIS_NINPUTS 2
#define MS_WINRTDIS_NOUTPUTS 0
#define MS_WINRTDIS_FLAGS 0
......
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