Ignore:
Timestamp:
Jul 12, 2010, 12:57:31 AM (15 years ago)
Author:
David Azarewicz
Message:

AddBuffers reentry fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OCO/branches/DAZ/drv16/wavestrm.cpp

    r512 r513  
    4242extern "C" ULONG  __cdecl __saveregs OSSIDC_EntryPoint(ULONG cmd, ULONG param1, ULONG param2);
    4343
     44#define SNDRV_PCM_STATE_XRUN 4 /* stream reached an xrun */
    4445
    4546//******************************************************************************
     
    148149{
    149150        if (ulStreamState == STREAM_STOPPED) return;
    150         rprintf(("%s: Buffer Underrun-stop", pchStr));
    151         pahw->SetVolume(StreamId, getMixerStreamId(), 0);
     151        rprintf(("%s: Underrun-stop", pchStr));
     152        //pahw->SetVolume(StreamId, getMixerStreamId(), 0);
    152153        pahw->Stop(StreamId);
    153154        ulStreamState = STREAM_STOPPED;
     
    160161{
    161162        if (ulStreamState == STREAM_STREAMING) return 0;
     163        rprintf(("Underrun-start"));
    162164        PSTREAMBUFFER pTemp = (PSTREAMBUFFER)qhInProcess.Head();
    163         if(pahw->ConfigDev(StreamId, &_configinfo, (pTemp) ? pTemp->ulBuffsz : 0) == FALSE) {
    164                 rprintf(("WS::Write: ConfigDev failed"));
    165                 return ERROR_INSUFF_BUFFER;
    166         }
     165//      if(pahw->ConfigDev(StreamId, &_configinfo, (pTemp) ? pTemp->ulBuffsz : 0) == FALSE) {
     166//              rprintf(("WS::Write: ConfigDev failed"));
     167//              return ERROR_INSUFF_BUFFER;
     168//      }
     169        _configinfo.ulSRatePosition = 0;
    167170        // prepare wave device for playback/recording
    168171        if(pahw->Prepare(StreamId) == FALSE) {
    169                 rprintf(("WS::Write: Prepare failed"));
     172                rprintf(("WS::UR Start: Prepare failed"));
    170173                return ERROR_START_STREAM;
    171174        }
     
    175178        ulStreamState = STREAM_STREAMING;
    176179        fUnderrun = FALSE;
    177         if (ulStreamType == STREAM_WAVE_PLAY) pahw->SetVolume(StreamId, getMixerStreamId(), volume);
     180        //if (ulStreamType == STREAM_WAVE_PLAY) pahw->SetVolume(StreamId, getMixerStreamId(), volume);
    178181        return 0;
    179182}
     
    185188// if this is a write stream call _vFillAudioBuf
    186189//******************************************************************************
     190short sDbgInProcess = 0;
     191short sDbgSave;
    187192#pragma off (unreferenced)
    188 void WAVESTREAM::AddBuffers(BOOL fFirst)
     193void WAVESTREAM::AddBuffers(SHORT sFirst)
    189194#pragma on (unreferenced)
    190195{
     
    193198        ULONG ulStatus;
    194199
    195         //dprintf(("WS:AddBuffers First=%d, SampleSize=%lx", fFirst, _configinfo.ulSampleSize));
     200        //dprintf(("WS:AddBuffers First=%d, SampleSize=%lx", sFirst, _configinfo.ulSampleSize));
     201
     202        if (sDbgInProcess) {
     203                rprintf(("WS::ABS InProcess Now=%x Save=%x", sFirst, sDbgSave));
     204                return;
     205        }
     206        sDbgInProcess++;
     207        sDbgSave = sFirst;
    196208
    197209        ulBytesWritten = 0;
     
    204216                // In extream cases we will stay stuck in this loop long enough to casue a trap rjj
    205217                if (pahw->GetSpace(StreamId, &_configinfo, &ulSpace) == FALSE) {
    206                         rprintf(("WAVESTREAM::AddBuffers GetSpace failed"));
     218                        rprintf(("WS::ABS GetSpace failed"));
    207219                        return;
    208220                }
    209221                ulSpace &= (~(_configinfo.ulSampleSize - 1));
    210222#if 1
     223                /* DAZ testing -- underrun detection */
    211224                if (ulSpace == 0) {
    212225                        OSS16_WaveGetStatus(StreamId, &ulStatus);
    213                         rprintf(("WAVESTREAM::AddBuffers ulSpace=0, u32status=%lx", ulStatus));
    214 
    215                         _vUnderrunStop("WS:AB");
     226                        rprintf(("WS::ABS ulSpace=0 state=%lx u32status=%lx", ulStreamState, ulStatus));
     227
     228                        _vUnderrunStop("WS:ABS");
    216229                        _vUnderrunStart();
    217230
    218231                        if (pahw->GetSpace(StreamId, &_configinfo, &ulSpace) == FALSE) {
    219                                 rprintf(("WS::AB GetSpace failed"));
     232                                rprintf(("WS::ABS GetSpace failed"));
    220233                                return;
    221234                        }
    222235                        ulSpace &= (~(_configinfo.ulSampleSize - 1));
     236                        if (ulSpace ==0) rprintf(("WS::ABS still no space"));
    223237                }
    224238#endif
     
    227241                {
    228242                        if (ulDAZ++ > 20) {
    229                                 rprintf(("WAVESTREAM::AddBuffers DAZ break")); // Temporary hack to prevent lockups when uniaud32 stops (underrun)
     243                                rprintf(("WS::ABS DAZ break")); // Temporary hack to prevent lockups when uniaud32 stops (underrun)
    230244                                int3(); /* should never happen */
    231245                                break;
    232246                        }
    233 #if 0
    234 //DAZ move the ProcBlock to the start stream code, if really needed
    235                         // First time is in task time. For I7 need to give time for interrupt time
    236                         if (fFirst == TRUE)  //PS+++
    237                         {
    238                                 //cli();
    239                                 DevHelp_ProcBlock (0x5541, 20, 0); // ok since the first call is at task time
    240                                 ulBytesWritten = AddBuffer(ulSpace);
    241                                 return;
    242                         }
    243 #endif
    244247                        ulBytesWritten = AddBuffer(ulSpace);
    245248                        if (ulBytesWritten == (ULONG)-1) {
    246249                                OSS16_WaveGetStatus(StreamId, &ulStatus);
    247                                 rprintf(("WAVESTREAM::AddBuffers AddBuffer returns -1 u32Status=%lx", ulStatus));
     250                                rprintf(("WS::ABS AddBuffer returns -1 u32Status=%lx", ulStatus));
    248251                                break;
    249252                        }
     
    255258//              }
    256259        }
     260        sDbgInProcess--;
    257261}
    258262
     
    296300        if (pahw->Transfer(StreamId, &_configinfo, pDataBuf, ulBuffLeft, &ulBytesWritten) == FALSE) {
    297301                // This could mean that the hardware has underrun TODO: implement underrun logic
    298                 rprintf(("WS::AddBuffer: pahw->Transfer failed"));
     302                rprintf(("WS::AB: pahw->Transfer failed"));
    299303                return (ULONG)-1;
    300304        }
     305        //dprintf(("WS::AB: %lx of %lx bytes written", ulBytesWritten, ulBuffLeft));
    301306        if (ulBytesWritten == 0) {
    302307                // This could mean that the hardware has underrun TODO: implement underrun logic
    303                 rprintf(("WS::AddBuffer: 0 of %lx bytes written by transfer", ulBuffLeft));
     308                //rprintf(("WS::AddBuffer: 0 of %lx bytes written by transfer", ulBuffLeft));
    304309                return (ULONG)-1;
    305310        }
     
    396401                                break;
    397402                        }
    398                         if (qhInProcess.IsElements()) AddBuffers(FALSE);
     403                        if (qhInProcess.IsElements()) AddBuffers(1);
    399404                        // Return any buffers that have been completely written to uniaud32
    400405                        //dprintf(("WS::Process usBufferMode=%x", usBufferMode));
     
    418423                        while(_vReadAudioBuf()) {
    419424                                if (ulDAZ++ > 20) { /* temporary hack to prevent hangs when uniaud32 stops (overruns) */
    420                                         rprintf(("WAVESTREAM::Process Read DAZ Break"));
     425                                        rprintf(("WS::Process Read DAZ Break"));
    421426                                        break;
    422427                                }
     
    442447//******************************************************************************
    443448//******************************************************************************
    444 #define SNDRV_PCM_STATE_XRUN 4 /* stream reached an xrun */
    445449ULONG WAVESTREAM::Write(PSTREAMBUFFER pStreamBuf)
    446450{
     
    457461                fUnderrun = TRUE;
    458462        }
    459 #else
    460         if (!fUnderrun && !qhInProcess.IsElements()) {
    461                 rprintf(("WS::Write: Buffer Underrun detect"));
    462                 fUnderrun = TRUE;
    463         }
    464463#endif
    465464        qhInProcess.PushOnTail((PQUEUEELEMENT)pStreamBuf);
    466         //dprintf(("WS::Write: sz=%lx IRQ=%lx", pStreamBuf->ulBuffsz, _configinfo.ulBytesPerIRQ));
    467 //        if (pStreamBuf->ulBuffsz < (_configinfo.ulBytesPerIRQ*2)) {
    468 //              dprintf(("WS::Write: BufferMode=1"));
    469 //              usBufferMode = 1;
    470 //      }
    471465        if (fUnderrun) {
    472466                _vUnderrunStart();
    473                 AddBuffers(FALSE);
     467                AddBuffers(2);
    474468        }
    475469        return 0;
     
    614608        if (ulStreamType == STREAM_WAVE_PLAY)
    615609        {
     610                //DAZ moved from AddBuffers, for I7, might not be needed
     611                //DevHelp_ProcBlock (0x5541, 20, 0);
    616612                pahw->SetVolume(StreamId, getMixerStreamId(), volume);    //PS
    617                 AddBuffers(TRUE);
     613                AddBuffers(3);
    618614        }
    619615        else
     
    641637{
    642638        if(ulStreamState == STREAM_STOPPED) {
    643                 dprintf(("WAVESTREAM::StopStream %lx (already stopped)", StreamId));
     639                //dprintf(("WS::StopStream %lx (already stopped)", StreamId));
    644640                fUnderrun = FALSE;
    645641                pControl->ulTime = GetCurrentTime();
     
    676672
    677673        if(ulStreamState == STREAM_PAUSED) {
    678                 dprintf(("WAVESTREAM::PauseStream %lx (already paused)", StreamId));
     674                dprintf(("WS::PauseStream %lx (already paused)", StreamId));
    679675                fUnderrun = FALSE;
    680676                pControl->ulTime = GetCurrentTime();
     
    691687        if (pahw->GetPosition(StreamId, &_configinfo, &ulEndPos2) == FALSE) ulEndPos2 = 0;
    692688        if (ulEndPos2 != ulEndPos) {
    693                 dprintf(("WAVESTREAM::PauseStream %lx!=%lx", ulEndPos, ulEndPos2));
     689                dprintf(("WS::PauseStream %lx!=%lx", ulEndPos, ulEndPos2));
    694690                if (ulEndPos2) ulEndPos = ulEndPos2;
    695691        }
     
    699695        ulStreamState = STREAM_PAUSED;
    700696
    701         dprintf(("WAVESTREAM::PauseStream %lx", StreamId));
     697        dprintf(("WS::PauseStream %lx", StreamId));
    702698
    703699        _ulBytesProcessed = ulEndPos;
     
    717713ULONG  WAVESTREAM::ResumeStream(void)
    718714{
    719 #ifdef DEBUG
    720715        //dprintf(("WAVESTREAM::ResumeStream %lx", StreamId));
    721 #endif
    722716        return StartStream();
    723717}
     
    729723        case PROPERTY_VOLUME:
    730724                volume = value;
    731                 dprintf(("WAVESTREAM::SetProperty() Vol: %0lx",value));
     725                dprintf(("WS::SetProperty() Vol: %0lx",value));
    732726                if(ulStreamState == STREAM_STREAMING && ulStreamType == STREAM_WAVE_PLAY) {
    733727                        MixerSetWaveVolume(getMixerStreamId(), StreamId, volume);
Note: See TracChangeset for help on using the changeset viewer.