Ticket #5313: 5313-v1.patch

File 5313-v1.patch, 4.6 KB (added by danielk, 16 years ago)

untested backport of the referenced trunk patches.

  • libs/libmyth/audiooutputbase.h

     
    7474    virtual void Drain(void);
    7575 
    7676    virtual int GetAudiotime(void);
     77    virtual int GetAudioBufferedTime(void) const;
    7778
    7879    // Send output events showing current progress
    7980    virtual void Status(void);
  • libs/libmyth/audiooutputalsa.cpp

     
    8989    }
    9090    else
    9191    {
    92         fragment_size = 6144; // nicely divisible by 2,4,6,8 channels @ 16-bits
    93         buffer_time = 500000; // 500 ms
    94         period_time = buffer_time / 4;  // 4 interrupts per buffer
     92        fragment_size = 1536 * audio_channels * audio_bits / 8;
     93        period_time = 25000;  // in usec, interrupt period time
     94        // in usec, for driver buffer alloc (64k max)
     95        buffer_time = period_time * 16;
    9596    }
    9697
    9798    if (audio_bits == 8)
  • libs/libmyth/audiooutputbase.cpp

     
    110110void AudioOutputBase::SetStretchFactorLocked(float laudio_stretchfactor)
    111111{
    112112    effdspstretched = (int)((float)effdsp / laudio_stretchfactor);
    113     if (audio_stretchfactor != laudio_stretchfactor)
     113    if ((audio_stretchfactor != laudio_stretchfactor) ||  !pSoundStretch)
    114114    {
    115115        audio_stretchfactor = laudio_stretchfactor;
    116116        if (pSoundStretch)
     
    363363
    364364    if (redo_stretch)
    365365    {
    366         float laudio_stretchfactor = audio_stretchfactor;
    367366        delete pSoundStretch;
    368367        pSoundStretch = NULL;
    369         audio_stretchfactor = 0.0f;
    370         SetStretchFactorLocked(laudio_stretchfactor);
     368        SetStretchFactorLocked(audio_stretchfactor);
    371369    }
    372370    else
    373371    {
     
    678676    pthread_mutex_unlock(&audio_buflock);
    679677}
    680678
     679int AudioOutputBase::GetAudioBufferedTime(void) const
     680{
     681     return audbuf_timecode - GetAudiotime();
     682}
     683
    681684bool AudioOutputBase::AddSamples(char *buffers[], int samples,
    682685                                 long long timecode)
    683686{
     
    699702        len += (pSoundStretch->numUnprocessedSamples() +
    700703                (int)(pSoundStretch->numSamples()/audio_stretchfactor))*abps;
    701704
    702     if (((len > afree) || ((audbuf_timecode - GetAudiotime()) > 2000)) && !blocking)
     705    if (((len > afree) && !blocking)
    703706    {
    704707        VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC + QString(
    705708                "AddSamples FAILED bytes=%1, used=%2, free=%3, timecode=%4")
     
    768771                (int)(pSoundStretch->numSamples()/audio_stretchfactor))*abps;
    769772    }
    770773
    771     if (((len > afree) || (audiotime && ((audbuf_timecode - GetAudiotime()) > 2000))) && !blocking)
     774    if (((len > afree) && !blocking)
    772775    {
    773776        VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC + QString(
    774777                "AddSamples FAILED bytes=%1, used=%2, free=%3, timecode=%4")
     
    958961                    if (audio_bits == 16)
    959962                        audiobuffer[org_waud++] = mybuf[chan][itemp+1];
    960963
    961                     if (org_waud >= AUDBUFSIZE)
    962                         org_waud -= AUDBUFSIZE;
     964                    org_waud %= AUDBUFSIZE;
    963965                }
    964966            }
    965967        }
     
    10341036                        memcpy(audiobuffer + org_waud, ob, amount);
    10351037
    10361038                    bdiff = AUDBUFSIZE - amount;
    1037                     org_waud += amount;
     1039                    org_waud += (org_waud + amount) % AUDBUFSIZE;
    10381040                }
    10391041            }
    10401042            else
     
    10611063                    }
    10621064                    else
    10631065                    {
    1064                         org_waud += nSamples * audio_bytes_per_sample;
     1066                        int bufsz = nSamples * audio_bytes_per_sample;
     1067                        org_waud = (org_waud + bufsz) % AUDBUFSIZE;
    10651068                        nSamplesToEnd -= nSamples;
    10661069                    }
    10671070
  • libs/libmyth/audiooutput.h

     
    6262
    6363    virtual int GetAudiotime(void) = 0;
    6464
     65    /// report amount of audio buffered in milliseconds.
     66    virtual int GetAudioBufferedTime(void) const { return 0; }
     67
    6568    virtual void SetSourceBitrate(int ) { }
    6669
    6770    QString GetError(void)   const { return lastError; }