Permalink
Browse files

actually use the buffer parameter settings

  • Loading branch information...
1 parent ee83760 commit 0149e9de42f5058b017611bd69948dba33abf449 @rdp committed Aug 22, 2012
View
2 TODO
@@ -10,6 +10,8 @@
== meh ==
+figure out pauses in FME when clicking "stop"...huh?
+
faster script start speed?
One feature I had thought of would be a "strip trailing silence" option or the like. I know if I were recording things I might like it :)
View
18 source_code/acam/ReadMe.txt
@@ -10,4 +10,20 @@ maybe a straight verbatim copy instead of my 16-bit hack? Except did things like
WAVE_FORMAT_EXTENSIBLE
maybe try these, see if they work:
-http://betterlogic.com/roger/2010/07/directsound-audio-input-filter-exampledemo/
+http://betterlogic.com/roger/2010/07/directsound-audio-input-filter-exampledemo/
+
+
+
+
+big buffer: blips 2, 3
+a little "fast forward snip" at the beginning when it's catching up (and has tons of blips)...
+
+with threads 1, full size:
+ a few fast forwards...
+
+
+with threads 2:
+lots of fast forward blips at the beginning, blips through, "stumbles forward"
+
+with threads 2, actually using it, still just 2 blips
+I think it's ok to use.
View
2 source_code/acam/acam.h
@@ -49,7 +49,7 @@ class CVCam : public CSource // not needed -> public IMediaFilter
// IMediaFilter [added]
//////////////////////////////////////////////////////////////////////////
STDMETHODIMP Run(REFERENCE_TIME tStart);
- STDMETHODIMP GetState(DWORD dw, FILTER_STATE *pState);
+ STDMETHODIMP GetState(DWORD dw, FILTER_STATE *pState);
//protected:
View
17 source_code/acam/directshow_fillbuffer.cpp
@@ -1,8 +1,9 @@
#include "stdafx.h"
#include "acam.h"
-CCritSec m_cSharedState;
+CCritSec gSharedState;
+extern int totalBlips;
//
// FillBuffer
//
@@ -34,7 +35,7 @@ HRESULT CVCamStream::FillBuffer(IMediaSample *pms)
return hr;
}
- CAutoLock cAutoLockShared(&m_cSharedState); // for the bFirstPacket boolean control, except there's probably still some odd race conditions er other...
+ CAutoLock cAutoLockShared(&gSharedState); // for the bFirstPacket boolean control, except there's probably still some odd race conditions er other...
hr = pms->SetActualDataLength(totalWrote);
if(FAILED(hr)) {
@@ -51,7 +52,7 @@ HRESULT CVCamStream::FillBuffer(IMediaSample *pms)
if(bFirstPacket) { // either have bFirstPacket or true here...true seemed to help that one guy...
m_pParent->StreamTime(rtStart); // gets current graph ref time [now] as its "start", as normal "capture" devices would, just in case that's better...
if(bFirstPacket)
- ShowOutput("got an audio first packet");
+ ShowOutput("got an audio first packet or discontinuity detected");
} else {
// since there hasn't been discontinuity, I think we should be safe to tell it
// that this packet starts where the previous packet ended off
@@ -112,14 +113,16 @@ HRESULT CVCamStream::FillBuffer(IMediaSample *pms)
}
// Set TRUE on every sample for PCM audio http://msdn.microsoft.com/en-us/library/windows/desktop/dd407021%28v=vs.85%29.aspx
- pms->SetSyncPoint(TRUE);
+ hr = pms->SetSyncPoint(TRUE);
if (FAILED(hr)) {
assert(false);
return hr;
}
- ShowOutput("sent audio frame");
- bFirstPacket = false;
+ FILTER_STATE State;
+ m_pParent->GetState(0, &State);
+ ShowOutput("sent audio frame, %d blips, state %d", totalBlips, State);
- return NOERROR;
+ bFirstPacket = false;
+ return S_OK;
} // end FillBuffer
View
33 source_code/acam/directshow_stuff.cpp
@@ -18,6 +18,9 @@
#define DECLARE_PTR(type, ptr, expr) type* ptr = (type*)(expr);
+extern long expectedMaxBufferSize;
+extern long pBufOriginalSize;
+
//////////////////////////////////////////////////////////////////////////
// CVCam is the source filter which masquerades as a capture device
//////////////////////////////////////////////////////////////////////////
@@ -41,6 +44,7 @@ CVCam::CVCam(LPUNKNOWN lpunk, HRESULT *phr) :
}
STDMETHODIMP CVCam::Run(REFERENCE_TIME tStart) {
+ ShowOutput("run called");
((CVCamStream*) m_paStreams[0])->m_rtPreviousSampleEndTime = 0;
return CSource::Run(tStart);
}
@@ -217,8 +221,6 @@ HRESULT CVCamStream::CheckMediaType(const CMediaType *pMediaType)
// maybe downstream needs a certain size?
const int WaveBufferChunkSize = 16*1024;
-void setExpectedMaxBufferSize(long toThis);
-
// DecideBufferSize
//
// This will always be called after the format has been sucessfully
@@ -232,7 +234,8 @@ HRESULT CVCamStream::DecideBufferSize(IMemAllocator *pAlloc,
WAVEFORMATEX *pwfexCurrent = (WAVEFORMATEX*)m_mt.Format();
- int nBitsPerSample = pwfexCurrent->wBitsPerSample;
+
+ /*int nBitsPerSample = pwfexCurrent->wBitsPerSample;
int nSamplesPerSec = pwfexCurrent->nSamplesPerSec;
int nChannels = pwfexCurrent->nChannels;
@@ -249,17 +252,18 @@ HRESULT CVCamStream::DecideBufferSize(IMemAllocator *pAlloc,
if(pProperties->cBuffers < 1)
pProperties->cBuffers = 1;
-
- // try with 1024B of buffer, just for fun.
- //pProperties->cbBuffer = 1024;
- //pProperties->cBuffers = 1;
long maxBufferSize = pProperties->cbBuffer * pProperties->cBuffers;
- setExpectedMaxBufferSize(maxBufferSize);
+ expectedMaxBufferSize = maxBufferSize;
+ */
- // Ask the allocator to reserve us the memory...
+ // just use our max size (or whatever they specified for us)
+ pProperties->cBuffers = 1;
+ pProperties->cbBuffer = expectedMaxBufferSize;
+ // Ask the allocator to reserve us this much memory...
+
ALLOCATOR_PROPERTIES Actual;
- HRESULT hr = pAlloc->SetProperties(pProperties,&Actual);
+ HRESULT hr = pAlloc->SetProperties(pProperties, &Actual);
if(FAILED(hr))
{
return hr;
@@ -450,25 +454,22 @@ HRESULT CVCamStream::QuerySupported(REFGUID guidPropSet, DWORD dwPropID, DWORD *
return S_OK;
}
-extern long pBufLocalSize;
-extern long pBufOriginalSize;
HRESULT STDMETHODCALLTYPE CVCamStream::SuggestAllocatorProperties( /* [in] */ const ALLOCATOR_PROPERTIES *pprop) {
// maybe we shouldn't even care though...I mean like seriously...why let them make it smaller <sigh>
// LODO test it both ways with FME, fast computer/slow computer does it make a difference?
-
int requested = pprop->cbBuffer;
if(pprop->cBuffers > 0)
requested *= pprop->cBuffers;
if(pprop->cbPrefix > 0)
requested += pprop->cbPrefix;
if(requested <= pBufOriginalSize) {
- pBufLocalSize = requested;
- return S_OK;
+ expectedMaxBufferSize = requested;
+ return S_OK; // they requested it? ok you got it! You're requesting possible problems! oh well! you requested it!
} else {
return E_FAIL;
}
}
-HRESULT STDMETHODCALLTYPE CVCamStream::GetAllocatorProperties( ALLOCATOR_PROPERTIES *pprop) {return NULL;}
+HRESULT STDMETHODCALLTYPE CVCamStream::GetAllocatorProperties( ALLOCATOR_PROPERTIES *pprop) {return NULL;} // they never call this...
View
18 source_code/acam/loopback-capture.cpp
@@ -30,14 +30,10 @@ int shouldStop = true;
BYTE pBufLocal[1024*1024]; // 1MB is quite awhile I think...
long pBufOriginalSize = 1024*1024;
-long pBufLocalSize = 1024*1024; // used for buffer size negotiation method.
+//long pBufLocalSize = 1024*1024; // used for buffer size negotiation method, use expectedmaxbuffersize instead
long pBufLocalCurrentEndLocation = 0;
-long expectedMaxBufferSize = 0;
-
-void setExpectedMaxBufferSize(long toThis) {
- expectedMaxBufferSize = toThis;
-}
+long expectedMaxBufferSize = 1024*1024; // TODO make non-global
HANDLE m_hThread;
@@ -106,7 +102,7 @@ HRESULT LoopbackCaptureSetup()
// tell it to not overflow one buffer's worth <sigh> not sure if this is right or not, and thus we don't "cache" or "buffer" more than that much currently...
// but a buffer size is a buffer size...hmm...as long as we keep it small though...
- assert(expectedMaxBufferSize <= pBufLocalSize);
+ assert(expectedMaxBufferSize <= pBufOriginalSize);
// activate an (the default, for us, since we want loopback) IAudioClient
hr = m_pMMDevice->Activate(
__uuidof(IAudioClient),
@@ -372,8 +368,7 @@ BYTE *captureData;
HRESULT propagateBufferOnce();
-
-extern CCritSec m_cSharedState;
+extern CCritSec gSharedState;
int totalSuccessFullyread = 0;
int totalBlips = 0;
@@ -443,10 +438,10 @@ HRESULT propagateBufferOnce() {
}
{
- CAutoLock cAutoLockShared(&m_cSharedState);
+ CAutoLock cAutoLockShared(&gSharedState);
if( dwFlags == 0 ) {
- // the good case
+ // the good case, got audio packet
// we'll let fillbuffer set bFirstPacket = false; since it uses it to know if the next packet should restart, etc.
} else if (bFirstPacket && AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY == dwFlags) {
ShowOutput("Probably spurious glitch reported on first packet, or two discontinuity errors occurred before it read from the cached buffer\n");
@@ -579,7 +574,6 @@ void outputStats() {
// called via reflection :)
static DWORD WINAPI propagateBufferForever(LPVOID pv) {
- int a = 3;
while(!shouldStop) {
HRESULT hr = propagateBufferOnce();
if(FAILED(hr)) {

0 comments on commit 0149e9d

Please sign in to comment.