MediaStreamSource.h 3.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
MediaStreamSource.h

mediastreamer2 library - modular sound and video processing and streaming
Windows Audio Session API sound card plugin for mediastreamer2
Copyright (C) 2010-2015 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
20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
*/

#pragma once

#include <Mfidl.h>
#include <mutex>
#include <collection.h>


namespace libmswinrtvid
{
	private ref class SampleRequestDeferral sealed
	{
	public:
		SampleRequestDeferral(Windows::Media::Core::MediaStreamSourceSampleRequest^ request, Windows::Media::Core::MediaStreamSourceSampleRequestDeferral^ deferral)
		{
			this->Request = request;
			this->Deferral = deferral;
		}

		property Windows::Media::Core::MediaStreamSourceSampleRequest^ Request
		{
			Windows::Media::Core::MediaStreamSourceSampleRequest^ get() { return mRequest; }
			void set(Windows::Media::Core::MediaStreamSourceSampleRequest^ value) { mRequest = value; }
		}

		property Windows::Media::Core::MediaStreamSourceSampleRequestDeferral^ Deferral
		{
			Windows::Media::Core::MediaStreamSourceSampleRequestDeferral^ get() { return mDeferral; }
			void set(Windows::Media::Core::MediaStreamSourceSampleRequestDeferral^ value) { mDeferral = value; }
		}

	private:
		~SampleRequestDeferral() {};

		Windows::Media::Core::MediaStreamSourceSampleRequest^ mRequest;
		Windows::Media::Core::MediaStreamSourceSampleRequestDeferral^ mDeferral;
	};

	private ref class Sample sealed
	{
	public:
		Sample(Windows::Storage::Streams::IBuffer^ buffer, int width, int height)
		{
			mBuffer = buffer;
			mWidth = width;
			mHeight = height;
		}

		property Windows::Storage::Streams::IBuffer^ Buffer
		{
			Windows::Storage::Streams::IBuffer^ get() { return mBuffer; }
		}

		property int Width
		{
			int get() { return mWidth; }
		}

		property int Height
		{
			int get() { return mHeight; }
		}

	private:
		~Sample() {};

		Windows::Storage::Streams::IBuffer^ mBuffer;
		int mWidth;
		int mHeight;
	};

	ref class MediaStreamSource sealed
	{
	public:
		static MediaStreamSource^ CreateMediaSource();

		void Feed(Windows::Storage::Streams::IBuffer^ pBuffer, int width, int height);
Ghislain MARY's avatar
Ghislain MARY committed
99
		void Stop();
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

		property Windows::Media::Core::MediaStreamSource^ Source
		{
			Windows::Media::Core::MediaStreamSource^ get() { return mMediaStreamSource; }
		}

	private:
		MediaStreamSource();
		~MediaStreamSource();

		void OnSampleRequested(Windows::Media::Core::MediaStreamSource ^sender, Windows::Media::Core::MediaStreamSourceSampleRequestedEventArgs ^args);
		void AnswerSampleRequest(Windows::Media::Core::MediaStreamSourceSampleRequest^ sampleRequest);
		void RenderFrame(IMFMediaBuffer* mediaBuffer);

		Windows::Media::Core::MediaStreamSource^ mMediaStreamSource;
		Windows::Media::Core::VideoStreamDescriptor^ mVideoDesc;
		Platform::Collections::Vector<SampleRequestDeferral^>^ mDeferralQueue;
		Sample^ mSample;
		uint64 mTimeStamp;
		uint64 mInitialTimeStamp;
		std::mutex mMutex;
	};
}