JunkBox_Win_Lib 1.5.3
Loading...
Searching...
No Matches
WinAudioStream.h
Go to the documentation of this file.
1#pragma once
2
14#include "WinMediaBuffer.h"
15
16#include <mmreg.h> // WAVEFORMATEX
17#include <avrt.h> // MMCSS(AvSetMmThreadCharacteristics)
18#include <MMSystem.h> // outout of Wave
19
20
21// Lib
22#pragma comment(lib, "avrt.lib")
23#pragma comment(lib, "winmm.lib")
24
25
26//
27namespace jbxwl {
28
29
30class CWinAudioStream : public IStream
31{
32public:
33
34 CWinAudioStream(IMediaObject *pObj);
35 virtual ~CWinAudioStream(void);
36
37 BOOL startCapture(WAVEFORMATEX* format=NULL);
38 void stopCapture (void);
39 Buffer input(void); // not free
40
41 //
42 BOOL openOutput(ULONG bufcount=100, WAVEFORMATEX* format=NULL);
43 void closeOutput(void);
44 void output(Buffer buf);
45
46private:
47 //
48 void freeOutputHeaders(void);
49
50public:
52 // IUnknown methods
53 //
54 STDMETHODIMP_(ULONG) AddRef(void) { return InterlockedIncrement(&m_cRef);}
55
56 STDMETHODIMP_(ULONG) Release(void)
57 {
58 UINT ref = InterlockedDecrement(&m_cRef);
59 if (ref==0) delete this;
60 return ref;
61 }
62
63 STDMETHODIMP QueryInterface(REFIID riid, void** ppv)
64 {
65 if (riid==IID_IUnknown) {
66 AddRef();
67 *ppv = (IUnknown*)this;
68 return S_OK;
69 }
70 else if (riid==IID_IStream) {
71 AddRef();
72 *ppv = (IStream*)this;
73 return S_OK;
74 }
75 else return E_NOINTERFACE;
76 }
77
78public:
80 // IStream methods
81 //
82 STDMETHODIMP Read(void*, ULONG, ULONG*);
83 STDMETHODIMP Seek(LARGE_INTEGER, DWORD, ULARGE_INTEGER*);
84 STDMETHODIMP Write(const void*, ULONG, ULONG*);
85
86 // Not Implement
87 STDMETHODIMP SetSize(ULARGE_INTEGER) { return E_NOTIMPL;}
88 STDMETHODIMP CopyTo(IStream*, ULARGE_INTEGER, ULARGE_INTEGER*, ULARGE_INTEGER*) { return E_NOTIMPL;}
89 STDMETHODIMP Commit(DWORD) { return E_NOTIMPL;}
90 STDMETHODIMP Revert(void) { return E_NOTIMPL;}
91 STDMETHODIMP LockRegion (ULARGE_INTEGER, ULARGE_INTEGER, DWORD) { return E_NOTIMPL;}
92 STDMETHODIMP UnlockRegion(ULARGE_INTEGER, ULARGE_INTEGER, DWORD) { return E_NOTIMPL;}
93 STDMETHODIMP Stat(STATSTG*, DWORD) { return E_NOTIMPL;}
94 STDMETHODIMP Clone(IStream**) { return E_NOTIMPL;}
95
96private:
97 CRITICAL_SECTION m_lock;
98
99 UINT m_cRef; // Number of references
100 IMediaObject* m_pMediaObj;
101
102private: // Input
103 static const UINT MaxReadBuffers = 20;
104
107
108 CWinThread* m_captureThread;
109
112
115
119
120private: // Output
121 static const UINT MaxOutputBuffers = 2*1024*1024;
122
123 HWAVEOUT m_hWave;
125
128
130
131private:
133 void Back2BufferStack(CWinMediaBuffer* pMediaBuf);
134 void Back2BufferStackAll(void);
135
136 void QueueCapturedData(BYTE* pData, UINT cbData);
137 void QueueCapturedBuffer(CWinMediaBuffer* pMediaBuf);
138
139 void ReadOneBuffer(BYTE** ppbData, ULONG* pcbData);
140
141 static UINT CaptureThread(LPVOID pParam);
142 UINT CaptureThread(void);
143
144 //
145 BOOL IsCapturing(void)
146 {
147 return (m_hStopEvent!=NULL) && (WaitForSingleObject(m_hStopEvent,0)!=WAIT_OBJECT_0);
148 }
149};
150
151
152} // namespace
153
154
メディアバッファ ヘッダ
STDMETHODIMP Read(void *, ULONG, ULONG *)
CWinMediaBuffer * m_readBuffer
void QueueCapturedBuffer(CWinMediaBuffer *pMediaBuf)
CRITICAL_SECTION m_lock
void Back2BufferStack(CWinMediaBuffer *pMediaBuf)
STDMETHODIMP CopyTo(IStream *, ULARGE_INTEGER, ULARGE_INTEGER *, ULARGE_INTEGER *)
STDMETHODIMP Revert(void)
STDMETHODIMP SetSize(ULARGE_INTEGER)
CWinAudioStream(IMediaObject *pObj)
MediaBufferStack m_bufferStack
STDMETHODIMP_(ULONG) Release(void)
CWinMediaBuffer * GetWriteBuffer(void)
CWinMediaBuffer * m_writeBuffer
STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
STDMETHODIMP Clone(IStream **)
STDMETHODIMP Seek(LARGE_INTEGER, DWORD, ULARGE_INTEGER *)
virtual ~CWinAudioStream(void)
STDMETHODIMP Stat(STATSTG *, DWORD)
BOOL startCapture(WAVEFORMATEX *format=NULL)
IMediaObject * m_pMediaObj
STDMETHODIMP Write(const void *, ULONG, ULONG *)
STDMETHODIMP Commit(DWORD)
STDMETHODIMP_(ULONG) AddRef(void)
void QueueCapturedData(BYTE *pData, UINT cbData)
static const UINT MaxOutputBuffers
STDMETHODIMP UnlockRegion(ULARGE_INTEGER, ULARGE_INTEGER, DWORD)
void ReadOneBuffer(BYTE **ppbData, ULONG *pcbData)
STDMETHODIMP LockRegion(ULARGE_INTEGER, ULARGE_INTEGER, DWORD)
BOOL openOutput(ULONG bufcount=100, WAVEFORMATEX *format=NULL)
static const UINT MaxReadBuffers
MediaBufferQueue m_bufferQueue
std::stack< CWinMediaBuffer * > MediaBufferStack
std::queue< CWinMediaBuffer * > MediaBufferQueue