2008-05-16 17:04:21 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Savoir-Faire Linux inc.
|
|
|
|
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _AUDIO_STREAM_H
|
|
|
|
#define _AUDIO_STREAM_H
|
|
|
|
|
|
|
|
#include <pulse/pulseaudio.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "../global.h"
|
|
|
|
#include "ringbuffer.h"
|
|
|
|
#include "audioloop.h"
|
|
|
|
|
2009-05-07 13:30:59 -04:00
|
|
|
#include <cc++/thread.h>
|
|
|
|
|
2008-05-30 10:37:15 -04:00
|
|
|
/**
|
|
|
|
* This data structure contains the different king of audio streams available
|
|
|
|
*/
|
2008-05-16 17:04:21 -04:00
|
|
|
enum STREAM_TYPE {
|
|
|
|
PLAYBACK_STREAM,
|
|
|
|
CAPTURE_STREAM,
|
|
|
|
UPLOAD_STREAM
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class AudioStream {
|
|
|
|
public:
|
2008-05-30 10:37:15 -04:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* @param context The pulseaudio context
|
|
|
|
* @param type The type of audio stream
|
|
|
|
* @param desc The stream name
|
|
|
|
*/
|
2008-05-30 17:29:01 -04:00
|
|
|
AudioStream(pa_context* context , int type, std::string desc, double vol);
|
2008-05-30 10:37:15 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
2008-05-16 17:04:21 -04:00
|
|
|
~AudioStream();
|
|
|
|
|
2008-05-30 10:37:15 -04:00
|
|
|
/**
|
|
|
|
* Write data to the main abstraction ring buffer.
|
|
|
|
* @param buffer The buffer containing the data to be played
|
|
|
|
* @param toCopy The number of samples, in bytes
|
|
|
|
* @return int The number of bytes played
|
|
|
|
*/
|
2008-05-16 17:04:21 -04:00
|
|
|
int putMain( void* buffer , int toCopy );
|
2008-05-30 10:37:15 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write data to the urgent abstraction ring buffer. ( dtmf , double calls )
|
|
|
|
* @param buffer The buffer containing the data to be played
|
|
|
|
* @param toCopy The number of samples, in bytes
|
|
|
|
* @return int The number of bytes played
|
|
|
|
*/
|
2008-05-16 17:04:21 -04:00
|
|
|
int putUrgent( void* buffer , int toCopy );
|
|
|
|
|
2009-05-07 11:39:15 -04:00
|
|
|
/**
|
|
|
|
* Connect the pulse audio stream
|
|
|
|
*/
|
2009-05-07 19:42:47 -04:00
|
|
|
bool connectStream();
|
2009-05-07 11:39:15 -04:00
|
|
|
|
2008-05-30 10:37:15 -04:00
|
|
|
/**
|
|
|
|
* Disconnect the pulseaudio stream
|
|
|
|
*/
|
2009-05-07 19:42:47 -04:00
|
|
|
bool disconnectStream();
|
2008-05-30 10:37:15 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Accessor: Get the pulseaudio stream object
|
|
|
|
* @return pa_stream* The stream
|
|
|
|
*/
|
2008-05-16 17:04:21 -04:00
|
|
|
pa_stream* pulseStream(){ return _audiostream; }
|
|
|
|
|
2008-05-30 10:37:15 -04:00
|
|
|
/**
|
|
|
|
* Accessor
|
|
|
|
* @return std::string The stream name
|
|
|
|
*/
|
|
|
|
std::string getStreamName( void ) { return _streamDescription; }
|
|
|
|
|
2008-06-05 17:40:58 -04:00
|
|
|
/**
|
|
|
|
* Accessor
|
|
|
|
* @param name The stream name
|
|
|
|
*/
|
|
|
|
void setStreamName( std::string name ) { _streamDescription = name; }
|
|
|
|
|
2008-06-02 14:08:33 -04:00
|
|
|
void setVolume( double pc ) { _volume.values[0] *= pc/100; }
|
|
|
|
pa_cvolume getVolume( void ) { return _volume; }
|
2008-05-30 17:29:01 -04:00
|
|
|
|
2009-05-07 11:39:15 -04:00
|
|
|
/**
|
|
|
|
* Accessor
|
|
|
|
* @return stream state
|
|
|
|
*/
|
|
|
|
pa_stream_state_t getStreamState(void);
|
|
|
|
|
2009-05-07 13:30:59 -04:00
|
|
|
|
|
|
|
|
2008-05-16 17:04:21 -04:00
|
|
|
private:
|
2008-10-02 09:34:16 -04:00
|
|
|
|
|
|
|
// Copy Constructor
|
|
|
|
AudioStream(const AudioStream& rh);
|
|
|
|
|
|
|
|
// Assignment Operator
|
|
|
|
AudioStream& operator=( const AudioStream& rh);
|
|
|
|
|
2008-05-30 10:37:15 -04:00
|
|
|
/**
|
|
|
|
* Create the audio stream into the given context
|
|
|
|
* @param c The pulseaudio context
|
|
|
|
* @return pa_stream* The newly created audio stream
|
|
|
|
*/
|
2008-05-16 17:04:21 -04:00
|
|
|
pa_stream* createStream( pa_context* c );
|
|
|
|
|
2008-05-30 10:37:15 -04:00
|
|
|
/**
|
|
|
|
* Mandatory asynchronous callback on the audio stream state
|
|
|
|
*/
|
2008-05-16 17:04:21 -04:00
|
|
|
static void stream_state_callback( pa_stream* s, void* user_data );
|
2008-05-30 10:37:15 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronous callback on data processing ( write and read )
|
|
|
|
*/
|
2008-05-16 17:04:21 -04:00
|
|
|
static void audioCallback ( pa_stream* s, size_t bytes, void* userdata );
|
2008-05-30 10:37:15 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write data to the sound device
|
|
|
|
*/
|
2008-05-16 17:04:21 -04:00
|
|
|
void write( void );
|
|
|
|
|
2009-05-07 11:39:15 -04:00
|
|
|
/**
|
|
|
|
* The pulse audio context
|
|
|
|
*/
|
|
|
|
pa_context* _context;
|
|
|
|
|
2008-05-30 10:37:15 -04:00
|
|
|
/**
|
|
|
|
* The pulse audio object
|
|
|
|
*/
|
|
|
|
pa_stream* _audiostream;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the stream
|
|
|
|
*/
|
2008-05-16 17:04:21 -04:00
|
|
|
int _streamType;
|
2008-05-30 10:37:15 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The name of the stream
|
|
|
|
*/
|
2008-05-16 17:04:21 -04:00
|
|
|
std::string _streamDescription;
|
2008-05-30 10:37:15 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Streams parameters
|
|
|
|
*/
|
2008-05-16 17:04:21 -04:00
|
|
|
pa_stream_flags_t flag;
|
|
|
|
pa_sample_spec sample_spec ;
|
2008-06-02 14:08:33 -04:00
|
|
|
pa_cvolume _volume;
|
2008-05-16 17:04:21 -04:00
|
|
|
|
2009-05-07 13:30:59 -04:00
|
|
|
ost::Mutex _mutex;
|
|
|
|
|
2008-05-16 17:04:21 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _AUDIO_STREAM_H
|