~ubuntu-branches/ubuntu/karmic/mumble/karmic-updates

« back to all changes in this revision

Viewing changes to src/mumble/PAAudio.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Matthäi, Patrick Matthäi, Thorvald Natvig
  • Date: 2009-02-04 10:32:16 UTC
  • mfrom: (1.2.1 upstream) (4.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090204103216-vqx5fmlruwzn3uh2
[ Patrick Matthäi ]
* Add a mumble-dbg package, which contains the debugging symbols of mumble
  and mumble-server.
* Move swedish translation debian/sv.po to debian/po/sv.po.
  This was a bad error of mine.
* Remove debian/patches and dpatch, everything has been merged by upstream.

[ Thorvald Natvig ]
* New upstream release.
  Closes: #513119
* Added Spanish translation from Álvaro M. Recio
* Synchronized copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2005-2008, Thorvald Natvig <thorvald@natvig.com>
 
1
/* Copyright (C) 2005-2009, Thorvald Natvig <thorvald@natvig.com>
2
2
   Copyright (C) 2007, Stefan Gehn <mETz AT gehn DOT net>
3
3
 
4
4
   All rights reserved.
40
40
                virtual AudioInput *create();
41
41
                virtual const QList<audioDevice> getDeviceChoices();
42
42
                virtual void setDeviceChoice(const QVariant &, Settings &);
43
 
                virtual bool canEcho(const QString &);
 
43
                virtual bool canEcho(const QString &) const;
44
44
};
45
45
 
46
46
class PortAudioOutputRegistrar : public AudioOutputRegistrar {
106
106
        s.iPortAudioInput = choice.toInt();
107
107
}
108
108
 
109
 
bool PortAudioInputRegistrar::canEcho(const QString &) {
 
109
bool PortAudioInputRegistrar::canEcho(const QString &) const {
110
110
        return false;
111
111
}
112
112
 
335
335
                err = Pa_ReadStream(inputStream, psMic, iFrameSize);
336
336
                if (err == paNoError) {
337
337
                        encodeAudioFrame();
338
 
                } else if (err == paInputOverflow) {
 
338
                } else if (err == paInputOverflowed) {
339
339
                        qWarning("PortAudioInput: Overflow on PortAudio input-stream, we lost incoming data!");
340
340
                } else { // other error, aborg
341
341
                        qWarning("PortAudioInput: Could not read from PortAudio stream, error %s", Pa_GetErrorText(err));
368
368
//TODO: redo this without busy waiting if possible
369
369
void PortAudioOutput::run() {
370
370
        PaStream            *outputStream   = 0;
371
 
        bool                hasMoreToMix    = true;
372
371
        PaError             err             = paNoError;
373
372
        int                 chans           = 0;
 
373
        bool                zero            = true;
374
374
 
375
375
        if (!PortAudioSystem::initStream(&outputStream, g.s.iPortAudioOutput, iFrameSize, &chans, false))
376
376
                return; // PA initialization or stream opening failed, we will give up
386
386
        initializeMixer(cmask);
387
387
 
388
388
        short outBuffer[iFrameSize * iChannels];
389
 
        memset(outBuffer, 0, sizeof(short) * iFrameSize * iChannels);
390
 
 
391
 
        // Get rid of crackling noise when starting the stream.
392
 
        if (PortAudioSystem::startStream(outputStream)) {
393
 
                err = Pa_WriteStream(outputStream, outBuffer, iFrameSize);
394
 
                if (err != paNoError) {
395
 
                        qWarning("PortAudioOutput: Could not write to PortAudio stream, error: %s", Pa_GetErrorText(err));
396
 
                        bRunning = false;
397
 
                }
398
 
        } else
399
 
                bRunning = false;
400
389
 
401
390
        while (bRunning) {
402
 
                bool nextHasMoreToMix = mix(outBuffer, iFrameSize);
403
 
                if (hasMoreToMix) {
404
 
                        if (PortAudioSystem::startStream(outputStream)) {
405
 
                                err = Pa_WriteStream(outputStream, outBuffer, iFrameSize);
406
 
                                if (err != paNoError) {
407
 
                                        qWarning("PortAudioOutput: Could not write to PortAudio stream, error %s", Pa_GetErrorText(err));
408
 
                                        bRunning = false;
409
 
                                }
410
 
                        } else
411
 
                                bRunning = false;
 
391
                bool avail = true;
 
392
 
 
393
                if (zero)
 
394
                        memset(outBuffer, 0, sizeof(short) * iFrameSize * iChannels);
 
395
                else
 
396
                        avail = mix(outBuffer, iFrameSize);
 
397
 
 
398
                if (avail) {
 
399
                        if (! PortAudioSystem::startStream(outputStream)) {
 
400
                                bRunning = false;
 
401
                                break;
 
402
                        }
 
403
                        err = Pa_WriteStream(outputStream, outBuffer, iFrameSize);
 
404
                        if (err == paOutputUnderflowed) {
 
405
                                qWarning("PortAudioOutput: Output underflowed. Attempting graceful recovery.");
 
406
                                zero = true;
 
407
                                continue;
 
408
                        } else if (err != paNoError) {
 
409
                                qWarning("PortAudioOutput: Could not write to PortAudio stream, error %s", Pa_GetErrorText(err));
 
410
                                bRunning = false;
 
411
                        }
412
412
                } else {
413
 
                        if (!PortAudioSystem::stopStream(outputStream))
 
413
                        if (! PortAudioSystem::stopStream(outputStream))
414
414
                                bRunning = false;
415
 
                        this->msleep(20); // 20ms wait to avoid hogging the cpu too much
 
415
                        this->msleep(20);
416
416
                }
417
 
                hasMoreToMix = nextHasMoreToMix;
 
417
 
 
418
                zero = false;
418
419
        }
419
420
 
420
 
        // ignoring return value of terminateStream, we cannot do anything about it anyway
421
421
        PortAudioSystem::terminateStream(outputStream);
422
 
        outputStream = 0; // just for gdb sessions
 
422
        outputStream = NULL; // just for gdb sessions
423
423
}