audio.h 1.87 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/**
 * @file FILENAME
 * @brief BRIEF DESCRIPTION
 * @copyright Copyright (C) YEAR Elphel Inc.
 * @author AUTHOR <EMAIL>
 *
 * @par License:
 *  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, see <http://www.gnu.org/licenses/>.
*/

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#ifndef _AUDIO__H_
#define _AUDIO__H_

#include <string>
#define __cplusplus 1
#include <alsa/asoundlib.h>
#include <pthread.h>
#include "rtp_stream.h"

using namespace std;

#define SAMPLE_RATE	44100
#define SAMPLE_CHANNELS 2

class Audio : public RTP_Stream {
public:
	Audio(bool enable, int sample_rate = SAMPLE_RATE, int channels = SAMPLE_CHANNELS);
	virtual ~Audio(void);
	long sample_rate(void) { return _sample_rate; };
	long channels(void) { return _channels; };
	bool present(void) { return _present; };
	long volume(void) { return _volume; };
	void set_volume(long volume) { set_capture_volume(volume); }

	void Start(string ip, long port, int ttl = -1);
	void Stop(void);
protected:
	int fd;
	snd_pcm_t *capture_handle;
	short *sbuffer;
	long sbuffer_len;
	bool _present;
	long _sample_rate;
	long _channels;
	long _volume;

	long capture(void);
	long process(void);
	long process_send(long sample_len);
	void set_capture_volume(int volume);

	uint64_t timestamp_rtcp;
	long delta_fpga_sys;	// A/V clocks delta for RTCP
bool is_first;
bool is_first2;
};

//extern Audio *audio;

#endif // _AUDIO__H_