mswasapi_reader.h 2.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
mswasapi_reader.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
20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 22 23
*/


24 25 26
#pragma once


27
#include "mediastreamer2/msfilter.h"
28
#include "mediastreamer2/msticker.h"
29

30
#include "mswasapi.h"
31 32


33 34 35 36 37
class MSWASAPIReader
#ifdef MS2_WINDOWS_UNIVERSAL
	: public RuntimeClass< RuntimeClassFlags< ClassicCom >, FtmBase, IActivateAudioInterfaceCompletionHandler >
#endif
{
38
public:
39
	MSWASAPIReader(MSFilter *filter);
40 41
	virtual ~MSWASAPIReader();

42
	void init(LPCWSTR id);
43 44 45 46 47
	int activate();
	int deactivate();
	bool isStarted() { return mIsStarted; }
	void start();
	void stop();
48
	int feed(MSFilter *f);
49 50 51

	int getRate() { return mRate; }
	int getNChannels() { return mNChannels; }
52 53
	float getVolumeLevel();
	void setVolumeLevel(float volume);
54

55
#ifdef MS2_WINDOWS_UNIVERSAL
56 57
	void setAsNotInstantiated() { smInstantiated = false; }

58 59 60
	// IActivateAudioInterfaceCompletionHandler
	STDMETHOD(ActivateCompleted)(IActivateAudioInterfaceAsyncOperation *operation);
#endif
61
private:
62 63 64
	void silence(MSFilter *f);

	static bool smInstantiated;
65 66 67 68
#ifdef MS2_WINDOWS_UNIVERSAL
	Platform::String^ mCaptureId;
	HANDLE mActivationEvent;
#else
69
	LPCWSTR mCaptureId;
70 71
#endif
#if defined(MS2_WINDOWS_PHONE) || defined(MS2_WINDOWS_UNIVERSAL)
72
	IAudioClient2 *mAudioClient;
73 74 75
#else
	IAudioClient *mAudioClient;
#endif
76
	IAudioCaptureClient *mAudioCaptureClient;
77
	ISimpleAudioVolume *mVolumeControler;
78 79 80 81 82 83
	UINT32 mBufferFrameCount;
	bool mIsInitialized;
	bool mIsActivated;
	bool mIsStarted;
	int mRate;
	int mNChannels;
84 85 86
	MSFilter *mFilter;
	MSTickerSynchronizer *mTickerSynchronizer;
	uint64_t mReadFrames;
87
};
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105


#ifdef MS2_WINDOWS_UNIVERSAL
#define MSWASAPI_READER(w) ((MSWASAPIReaderType)((MSWASAPIReaderPtr)(w))->reader)
typedef ComPtr<MSWASAPIReader> MSWASAPIReaderType;

struct MSWASAPIReaderWrapper
{
	MSWASAPIReaderType reader;
};

typedef struct MSWASAPIReaderWrapper* MSWASAPIReaderPtr;
#else
#define MSWASAPI_READER(w) ((MSWASAPIReaderType)(w))
typedef MSWASAPIReader* MSWASAPIReaderPtr;
typedef MSWASAPIReader* MSWASAPIReaderType;
#endif

106
MSWASAPIReaderPtr MSWASAPIReaderNew(MSFilter *f);
107
void MSWASAPIReaderDelete(MSWASAPIReaderPtr ptr);