mswinrtcap.h 4.07 KB
Newer Older
1
/*
2
mswinrtcap.h
3 4 5

mediastreamer2 library - modular sound and video processing and streaming
Windows Audio Session API sound card plugin for mediastreamer2
6
Copyright (C) 2010-2015 Belledonne Communications, Grenoble, France
7 8 9 10 11 12 13 14 15 16 17 18 19

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
20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 22 23 24 25 26
*/


#pragma once


27 28
#include <mediastreamer2/mswebcam.h>
#include <mediastreamer2/rfc3984.h>
29
#include <mediastreamer2/mscodecutils.h>
30

Ghislain MARY's avatar
Ghislain MARY committed
31
#include "mswinrtvid.h"
32
#include "mswinrtmediasink.h"
Ghislain MARY's avatar
Ghislain MARY committed
33

34
#include <wrl\implements.h>
Ghislain MARY's avatar
Ghislain MARY committed
35 36 37 38 39
#include <ppltasks.h>

using namespace Windows::Media::Capture;
using namespace Windows::Media::Devices;
using namespace Windows::Media::MediaProperties;
40 41 42


namespace libmswinrtvid
Ghislain MARY's avatar
Ghislain MARY committed
43
{
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
	ref class MSWinRTCapHelper sealed {
	internal:
		MSWinRTCapHelper();
		bool Initialize(Platform::String^ DeviceId);
		bool StartCapture(Windows::Media::MediaProperties::MediaEncodingProfile^ EncodingProfile);
		void StopCapture();
		void MSWinRTCapHelper::OnSampleAvailable(BYTE *buf, DWORD bufLen, LONGLONG presentationTime);
		MSVideoSize SelectBestVideoSize(MSVideoSize vs);
		mblk_t * GetSample();
		
		property Platform::Agile<MediaCapture^> CaptureDevice
		{
			Platform::Agile<MediaCapture^> get() { return mCapture; }
		}

Ghislain MARY's avatar
Ghislain MARY committed
59 60 61 62 63 64
		property int DeviceOrientation
		{
			int get() { return mDeviceOrientation; }
			void set(int value) { mDeviceOrientation = value; }
		}

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
	private:
		~MSWinRTCapHelper();
		void OnCaptureFailed(Windows::Media::Capture::MediaCapture^ sender, Windows::Media::Capture::MediaCaptureFailedEventArgs^ errorEventArgs);

		HANDLE mInitializationCompleted;
		HANDLE mStartCompleted;
		HANDLE mStopCompleted;
		const GUID mRotationKey;
		Platform::Agile<MediaCapture^> mCapture;
		Windows::Foundation::EventRegistrationToken mMediaCaptureFailedEventRegistrationToken;
		ComPtr<IMFMediaSink> mMediaSink;
		MediaEncodingProfile^ mEncodingProfile;
		int mDeviceOrientation;
		ms_mutex_t mMutex;
		MSYuvBufAllocator *mAllocator;
		MSQueue mSamplesQueue;
	};

83 84 85 86 87
	class MSWinRTCap {
	public:
		MSWinRTCap();
		virtual ~MSWinRTCap();

88
		void initialize();
89 90 91 92 93 94 95
		int activate();
		int deactivate();
		bool isStarted() { return mIsStarted; }
		void start();
		void stop();
		int feed(MSFilter *f);

96
		void OnSampleAvailable(BYTE *buf, DWORD bufLen, LONGLONG presentationTime);
97

98 99 100
		void setDeviceId(Platform::String^ id) { mDeviceId = id; }
		void setFront(bool front) { mFront = front; }
		void setExternal(bool external) { mExternal = external; }
101 102
		MSPixFmt getPixFmt() { return MS_YUV420P; }
		float getFps() { return mFps; }
103
		float getAverageFps();
104 105 106
		void setFps(float fps);
		MSVideoSize getVideoSize();
		void setVideoSize(MSVideoSize vs);
Ghislain MARY's avatar
Ghislain MARY committed
107
		int getDeviceOrientation() { return mHelper->DeviceOrientation; }
108 109 110 111 112 113 114
		void setDeviceOrientation(int degrees);

		static void detectCameras(MSWebCamManager *manager, MSWebCamDesc *desc);

	private:
		void applyFps();
		void applyVideoSize();
115
		void selectBestVideoSize(MSVideoSize vs);
116
		void configure();
117 118
		static void addCamera(MSWebCamManager *manager, MSWebCamDesc *desc, Windows::Devices::Enumeration::DeviceInformation^ DeviceInfo);
		static void registerCameras(MSWebCamManager *manager);
119 120

		static bool smInstantiated;
121
		static MSList *smCameras;
122 123 124
		bool mIsInitialized;
		bool mIsActivated;
		bool mIsStarted;
125
		float mFps;
126
		MSAverageFPS mAvgFps;
127
		MSVideoSize mVideoSize;
128 129 130
		uint64_t mStartTime;
		MSVideoStarter mStarter;
		Platform::String^ mDeviceId;
131 132
		bool mFront;
		bool mExternal;
133
		MSWinRTCapHelper^ mHelper;
134
		MediaEncodingProfile^ mEncodingProfile;
135
		MSFrameRateController mFpsControl;
136 137
	};
}