Permalink
Browse files

add some debugs, better logging, go back to the old style of marking …

…TS's LOL
  • Loading branch information...
1 parent 07c3f9e commit 709fa91bd9ab88fb456c8a27e17f7dfb37815348 @rdp committed May 2, 2012
View
@@ -1,3 +1,8 @@
+0.2.9 5/2/12
+
+ move an assertion, also we use a more "directshowy" fillbuffer now, which...is probably wrong LOL.
+ more debug logs
+
0.2.8 2-21-12
64 bit release kind of
View
@@ -1,15 +1,18 @@
-#define AppVer "0.2.8"
+#define AppVer "0.2.9"
#define AppName "virtual audio capture grabber device"
-[UninstallRun]
-Filename: regsvr32; WorkingDir: {app}; Parameters: /s /u audio_sniffer.ax
[Run]
Filename: regsvr32; WorkingDir: {app}; Parameters: /s audio_sniffer.ax
+Filename: {app}\vendor\vcredist_x86.exe; Parameters: "/passive /Q:a /c:""msiexec /qb /i vcredist.msi"" "; StatusMsg: Installing 2010 RunTime...
+
+[UninstallRun]
+Filename: regsvr32; WorkingDir: {app}; Parameters: /s /u audio_sniffer.ax
[Files]
Source: source_code\Release\audio_sniffer.ax; DestDir: {app}
Source: README.TXT; DestDir: {app}; Flags: isreadme
Source: script_it\*.*; DestDir: {app}\script_it; Flags: recursesubdirs
+Source: vendor\vcredist_x86.exe; DestDir: {app}\vendor
[Setup]
MinVersion=,6.0.6000
Binary file not shown.
View
@@ -122,7 +122,7 @@ class CVCamStream : public CSourceStream, public IAMStreamConfig, public IKsProp
CVCamStream(HRESULT *phr, CVCam *pParent, LPCWSTR pPinName);
~CVCamStream();
- CRefTime m_rtSampleEndTime; // The time to be stamped on each sample
+ CRefTime m_rtPreviousSampleEndTime;
private:
CVCam *m_pParent;
@@ -24,7 +24,7 @@ HRESULT CVCamStream::FillBuffer(IMediaSample *pms)
}
LONG totalWrote = -1;
- // the real meat -- get all the incoming data
+ // the real meat -- get all the incoming data
hr = LoopbackCaptureTakeFromBuffer(pData, pms->GetSize(), NULL, &totalWrote);
if(FAILED(hr)) {
// this one can return false during shutdown, so it's actually ok to just return from here...
@@ -47,27 +47,26 @@ HRESULT CVCamStream::FillBuffer(IMediaSample *pms)
(REFERENCE_TIME)pwfexCurrent->nAvgBytesPerSec;
CRefTime rtStart;
- if(true) { // bFirstPacket
+ if(bFirstPacket) { // bFirstPacket or true here...
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 a first packet");
+ if(bFirstPacket)
+ ShowOutput("retrieving a first packet");
} 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
// since that's theoretically accurate...
- // exept that it ends up being bad
+ // exept that it ends up being bad [?]
// I don't "think" this will hurt graphs that have no reference clock...hopefully...
- CRefTime cur_time;
- m_pParent->StreamTime(cur_time);
- REFERENCE_TIME previousEnd = m_rtSampleEndTime;
- rtStart = previousEnd;
+
+ // rtStart = cur_time;
+ rtStart = m_rtPreviousSampleEndTime;
}
// I once tried to change it to always have monotonicity of timestamps at this point, but it didn't fix any problems, and seems to do all right without it so maybe ok [?]
- m_rtSampleEndTime = rtStart + sampleTimeUsed;
+ m_rtPreviousSampleEndTime = rtStart + sampleTimeUsed;
// NB that this *can* set it to a negative start time...hmm...which apparently is "ok" when a graph is just starting up it's expected...
- hr = pms->SetTime((REFERENCE_TIME*)&rtStart, (REFERENCE_TIME*)&m_rtSampleEndTime);
+ hr = pms->SetTime((REFERENCE_TIME*) &rtStart, (REFERENCE_TIME*) &m_rtPreviousSampleEndTime);
if (FAILED(hr)) {
assert(false);
return hr;
@@ -77,7 +76,7 @@ HRESULT CVCamStream::FillBuffer(IMediaSample *pms)
// [a possible VLC bug?] http://forum.videolan.org/viewtopic.php?f=14&t=92659&hilit=+50ms
// whatever SetMediaTime even does...
- hr = pms->SetMediaTime((REFERENCE_TIME*)&rtStart, (REFERENCE_TIME*)&m_rtSampleEndTime);
+ // hr = pms->SetMediaTime((REFERENCE_TIME*)&rtStart, (REFERENCE_TIME*)&m_rtPreviousSampleEndTime);
//m_llSampleMediaTimeStart = m_rtSampleEndTime;
if (FAILED(hr)) {
@@ -41,7 +41,7 @@ CVCam::CVCam(LPUNKNOWN lpunk, HRESULT *phr) :
}
STDMETHODIMP CVCam::Run(REFERENCE_TIME tStart) {
- ((CVCamStream*) m_paStreams[0])->m_rtSampleEndTime = 0;
+ ((CVCamStream*) m_paStreams[0])->m_rtPreviousSampleEndTime = 0;
return CSource::Run(tStart);
}
@@ -179,10 +179,8 @@ HRESULT CVCamStream::setAsNormal(CMediaType *pmt) {
return E_OUTOFMEMORY;
}
return setupPwfex(pwfex, pmt);
-
}
-
// GetMediaType
// I believe "they" call this...
// we only have one type at a time...
@@ -233,7 +231,7 @@ HRESULT CVCamStream::CheckMediaType(const CMediaType *pMediaType)
// Size of each allocated buffer
// seems arbitrary
-// maybe downstream needed a certain size?
+// maybe downstream needs a certain size?
const int WaveBufferChunkSize = 16*1024;
void setExpectedMaxBufferSize(long toThis);
@@ -346,12 +346,11 @@ extern CCritSec m_cSharedState;
int totalSuccessFullyread = 0;
int totalBlips = 0;
+int totalOverflows = 0;
HRESULT propagateBufferOnce() {
HRESULT hr = S_OK;
- // this should also...umm...detect the timeout stuff and fake fill?
-
// grab next audio chunk...
int gotAnyAtAll = FALSE;
DWORD start_time = timeGetTime();
@@ -417,29 +416,29 @@ HRESULT propagateBufferOnce() {
if( dwFlags == 0 ) {
// the good case
- // we'll let fillbuffer set bFirstPacket = false; since it repackages the audio
+ // 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");
- bFirstPacket = true; // won't hurt
+ bFirstPacket = true; // won't hurt, even if it is a real first packet :)
// LODO it should probably clear the buffers if it ever gets discontinuity
// or "let" it clear the buffers then send the new data on
// as we have any left-over data that will be assigned a wrong timestamp
// but it won't be too far wrong, compared to what it would otherwise be with always
// assigning it the current graph timestamp, like we used to...
} else if (AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY == dwFlags) {
ShowOutput("IAudioCaptureClient::discontinuity GetBuffer set flags to 0x%08x after %u frames\n", dwFlags, pnFrames);
- // expected if audio turns on then off...
- // or if your CPU gets behind or what not.
+ // expected your CPU gets behind or what not. I guess.
/*pAudioClient->Stop();
AvRevertMmThreadCharacteristics(hTask);
- pAudioCaptureClient->Release(); // WE GET HERE
+ pAudioCaptureClient->Release();
pAudioClient->Release();
return E_UNEXPECTED;*/
bFirstPacket = true;
} else if (AUDCLNT_BUFFERFLAGS_SILENT == dwFlags) {
- ShowOutput("IAudioCaptureClient::silence (just) from GetBuffer after %u frames\n", pnFrames);
- // expected if there's silence, esp. since we have the "silence generation" work-around...
+ // ShowOutput("IAudioCaptureClient::silence (just) from GetBuffer after %u frames\n", pnFrames);
+ // expected if there's silence (i.e. nothing playing), since we now include the "silence generator" work-around...
} else {
+ // probably silence + discontinuity
ShowOutput("IAudioCaptureClient::unknown discontinuity GetBuffer set flags to 0x%08x after %u frames\n", dwFlags, pnFrames);
bFirstPacket = true; // probably is some type of discontinuity :P
}
@@ -448,7 +447,7 @@ HRESULT propagateBufferOnce() {
totalBlips++;
if (0 == nNumFramesToRead) {
- ShowOutput("death: IAudioCaptureClient::GetBuffer said to read 0 frames after %u frames\n", pnFrames);
+ ShowOutput("death failure: IAudioCaptureClient::GetBuffer said to read 0 frames after %u frames\n", pnFrames);
pAudioClient->Stop();
AvRevertMmThreadCharacteristics(hTask);
pAudioCaptureClient->Release();
@@ -472,6 +471,8 @@ HRESULT propagateBufferOnce() {
// so basically we don't accomodate realtime at all currently...hmmm...
ShowOutput("overfilled buffer, cancelling/flushing."); //over flow overflow appears VLC just keeps reading though, when paused [?] but not graphedit...or does it?
pBufLocalCurrentEndLocation = 0;
+ totalOverflows++;
+ bFirstPacket = true;
}
for(INT i = 0; i < lBytesToWrite && pBufLocalCurrentEndLocation < expectedMaxBufferSize; i++) {
@@ -500,15 +501,15 @@ HRESULT propagateBufferOnce() {
// iSize is max size of the BYTE buffer...so maybe...we should just drop it if we have past that size? hmm...we're probably
HRESULT LoopbackCaptureTakeFromBuffer(BYTE pBuf[], int iSize, WAVEFORMATEX* ifNotNullThenJustSetTypeOnly, LONG* totalBytesWrote)
{
- while(!shouldStop) { // allow this to exit, at shutdown.
+ while(!shouldStop) { // allow this to exit, too, at shutdown.
{
CAutoLock cObjectLock(&csMyLock); // Lock the critical section, releases scope after block is done...
if(pBufLocalCurrentEndLocation > 0) {
// fails lodo is that ok?
// assert(pBufLocalCurrentEndLocation <= expectedMaxBufferSize);
int totalToWrite = MIN(pBufLocalCurrentEndLocation, expectedMaxBufferSize);
+ ASSERT(totalToWrite <= iSize); // just in case...just in case almost...
memcpy(pBuf, pBufLocal, totalToWrite);
- ASSERT(totalToWrite <= iSize); // just in case
*totalBytesWrote = totalToWrite;
pBufLocalCurrentEndLocation = 0;
return S_OK;
@@ -517,13 +518,11 @@ HRESULT LoopbackCaptureTakeFromBuffer(BYTE pBuf[], int iSize, WAVEFORMATEX* ifNo
// sleep outside the lock ...
// using sleep doesn't seem to hurt the cpu
// and it seems to not get many "discontinuity" messages currently...
- Sleep(1);
+ Sleep(1);
}
- pBufLocalCurrentEndLocation = 0; // not sure who should set this...producer or consumer :)
- return E_FAIL; // we didn't fill anything...
+ return E_FAIL; // we didn't fill anything...and are shutting down...
}
-
// clean up
void loopBackRelease() {
// tell running collector thread to end...
@@ -536,13 +535,13 @@ void loopBackRelease() {
pAudioCaptureClient->Release();
pAudioClient->Release();
m_pMMDevice->Release();
- #ifdef _DEBUG
- outputStats();
- #endif
+ // thread is done, we are exiting...
+ pBufLocalCurrentEndLocation = 0;
+ outputStats();
}
void outputStats() {
wchar_t output[250];
- wsprintf(output, L"total reads %d total blips %d", totalSuccessFullyread , totalBlips);
+ wsprintf(output, L"total reads %d total blips %d total overflows %d", totalSuccessFullyread , totalBlips, totalOverflows);
set_config_string_setting(L"last_output", output);
}
@@ -24,7 +24,7 @@ void ShowOutput(const char *str, ...)
HRESULT set_config_string_setting(LPCTSTR szValueName, wchar_t *szToThis ) {
- HKEY hKey;
+ HKEY hKey = NULL;
LONG i;
DWORD dwDisp = 0;
@@ -39,9 +39,11 @@ HRESULT set_config_string_setting(LPCTSTR szValueName, wchar_t *szToThis ) {
i = RegSetValueEx(hKey, szValueName, 0, REG_SZ, (LPBYTE) szToThis, wcslen(szToThis)*2+1);
} else {
- // failed to set...
+ // failed to create key...
}
- RegCloseKey(hKey);
+
+ if(hKey)
+ RegCloseKey(hKey);
return i;
}
@@ -11,8 +11,8 @@ Global
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {B6830EAD-C98E-490D-8999-CAA246788BF7}.Debug|Win32.ActiveCfg = Debug|x64
- {B6830EAD-C98E-490D-8999-CAA246788BF7}.Debug|Win32.Build.0 = Debug|x64
+ {B6830EAD-C98E-490D-8999-CAA246788BF7}.Debug|Win32.ActiveCfg = Debug|Win32
+ {B6830EAD-C98E-490D-8999-CAA246788BF7}.Debug|Win32.Build.0 = Debug|Win32
{B6830EAD-C98E-490D-8999-CAA246788BF7}.Debug|x64.ActiveCfg = Debug|x64
{B6830EAD-C98E-490D-8999-CAA246788BF7}.Debug|x64.Build.0 = Debug|x64
{B6830EAD-C98E-490D-8999-CAA246788BF7}.Release|Win32.ActiveCfg = Release|Win32
View
Binary file not shown.

0 comments on commit 709fa91

Please sign in to comment.