Commit 58b954f2 authored by Mikhail Karpenko's avatar Mikhail Karpenko

Update debug macro in audio, fix debug macro in other modules

parent 7e9dba1a
...@@ -27,133 +27,140 @@ ...@@ -27,133 +27,140 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#undef AUDIO_DEBUG //#undef AUDIO_DEBUG
//#define AUDIO_DEBUG #define AUDIO_DEBUG
#undef AUDIO_DEBUG_2 //#undef AUDIO_DEBUG_2
//#define AUDIO_DEBUG_2 #define AUDIO_DEBUG_2
#ifdef AUDIO_DEBUG #ifdef AUDIO_DEBUG
#define D(a) a #define D(s_port, a) \
do { \
cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << ": sensor port: " << s_port << " "; \
a; \
} while (0)
#else #else
#define D(a) #define D(s_port, a)
#endif #endif
#ifdef AUDIO_DEBUG_2 #ifdef AUDIO_DEBUG_2
#define D2(a) a #define D2(s_port, a) \
do { \
cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << ": sensor port: " << s_port << " "; \
a; \
} while (0)
#else #else
#define D2(a) #define D2(s_port, a)
#endif #endif
//#define SAMPLE_TIME 50 // in milliseconds #define SAMPLE_TIME 20 // in milliseconds
#define SAMPLE_TIME 20 // in milliseconds #define BUFFER_TIME 1000 // in milliseconds
#define BUFFER_TIME 1000 // in milliseconds
using namespace std; using namespace std;
Audio::Audio(bool enable, Parameters *pars, int sample_rate, int channels) { Audio::Audio(int port, bool enable, Parameters *pars, int sample_rate, int channels) {
//cerr << "Audio::Audio()" << endl;
snd_pcm_hw_params_t *hw_params; snd_pcm_hw_params_t *hw_params;
snd_pcm_sw_params_t *sw_params; snd_pcm_sw_params_t *sw_params;
_present = false; _present = false;
stream_name = "audio"; stream_name = "audio";
params = pars; params = pars;
sensor_port = port;
// normalize audio settings // normalize audio settings
if(sample_rate == 0) sample_rate = SAMPLE_RATE; if (sample_rate == 0)
if(sample_rate > 48000) sample_rate = 48000; sample_rate = SAMPLE_RATE;
if(sample_rate < 11025) sample_rate = 11025; if (sample_rate > 48000)
sample_rate = 48000;
if (sample_rate < 11025)
sample_rate = 11025;
_sample_rate = sample_rate; _sample_rate = sample_rate;
if(channels == 0) channels = SAMPLE_CHANNELS; if (channels == 0)
if(channels < 1) channels = 1; channels = SAMPLE_CHANNELS;
if(channels > 2) channels = 2; if (channels < 1)
channels = 1;
if (channels > 2)
channels = 2;
_channels = channels; _channels = channels;
_volume = 65535; _volume = 65535;
_volume *= 90; _volume *= 90;
_volume /= 100; _volume /= 100;
SSRC = 10; SSRC = 10;
// here sbuffer_len in samples, not bytes // here sbuffer_len in samples, not bytes
sbuffer_len = _sample_rate * SAMPLE_TIME; sbuffer_len = _sample_rate * SAMPLE_TIME;
sbuffer_len /= 1000; sbuffer_len /= 1000;
sbuffer_len -= sbuffer_len % 2; sbuffer_len -= sbuffer_len % 2;
D( cerr << "sbuffer_len == " << sbuffer_len << endl;) D(sensor_port, cerr << "sbuffer_len == " << sbuffer_len << endl);
_ptype = 97; _ptype = 97;
sbuffer = NULL; sbuffer = NULL;
if(enable) { if (enable) {
// open ALSA for capturing // open ALSA for capturing
int err; int err;
sbuffer = new short[sbuffer_len * 2 * _channels]; sbuffer = new short[sbuffer_len * 2 * _channels];
bool init_ok = false; bool init_ok = false;
while(true) { while (true) {
if((err = snd_pcm_open(&capture_handle, "default", SND_PCM_STREAM_CAPTURE, 0)) < 0) if ((err = snd_pcm_open(&capture_handle, "default", SND_PCM_STREAM_CAPTURE, 0)) < 0)
break; break;
snd_pcm_hw_params_alloca(&hw_params); snd_pcm_hw_params_alloca(&hw_params);
if((err = snd_pcm_hw_params_any(capture_handle, hw_params)) < 0) if ((err = snd_pcm_hw_params_any(capture_handle, hw_params)) < 0)
break; break;
if((err = snd_pcm_hw_params_set_access(capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) if ((err = snd_pcm_hw_params_set_access(capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
break; break;
if((err = snd_pcm_hw_params_set_format(capture_handle, hw_params, SND_PCM_FORMAT_S16_BE)) < 0) if ((err = snd_pcm_hw_params_set_format(capture_handle, hw_params, SND_PCM_FORMAT_S16_BE)) < 0)
break; break;
unsigned int t = _sample_rate; unsigned int t = _sample_rate;
if((err = snd_pcm_hw_params_set_rate_near(capture_handle, hw_params, &t, 0)) < 0) if ((err = snd_pcm_hw_params_set_rate_near(capture_handle, hw_params, &t, 0)) < 0)
break; break;
unsigned int period_time = SAMPLE_TIME * 1000; unsigned int period_time = SAMPLE_TIME * 1000;
if((err = snd_pcm_hw_params_set_period_time_near(capture_handle, hw_params, &period_time, 0)) < 0) if ((err = snd_pcm_hw_params_set_period_time_near(capture_handle, hw_params, &period_time, 0)) < 0)
break; break;
D( cerr << "period_time == " << period_time << endl;) D(sensor_port, cerr << "period_time == " << period_time << endl);
unsigned int buffer_time = BUFFER_TIME * 1000; unsigned int buffer_time = BUFFER_TIME * 1000;
if((err = snd_pcm_hw_params_set_buffer_time_near(capture_handle, hw_params, &buffer_time, 0)) < 0) if ((err = snd_pcm_hw_params_set_buffer_time_near(capture_handle, hw_params, &buffer_time, 0)) < 0)
break; break;
D( cerr << "buffer_time == " << buffer_time << endl;) D(sensor_port, cerr << "buffer_time == " << buffer_time << endl);
_sample_rate = t; _sample_rate = t;
if((err = snd_pcm_hw_params_set_channels(capture_handle, hw_params, _channels)) < 0) if ((err = snd_pcm_hw_params_set_channels(capture_handle, hw_params, _channels)) < 0)
break; break;
if((err = snd_pcm_hw_params(capture_handle, hw_params)) < 0) if ((err = snd_pcm_hw_params(capture_handle, hw_params)) < 0)
break; break;
snd_pcm_sw_params_alloca(&sw_params); snd_pcm_sw_params_alloca(&sw_params);
if((err = snd_pcm_sw_params_current(capture_handle, sw_params)) < 0) if ((err = snd_pcm_sw_params_current(capture_handle, sw_params)) < 0)
break; break;
if((err = snd_pcm_sw_params_set_tstamp_mode(capture_handle, sw_params, SND_PCM_TSTAMP_ENABLE)) < 0) if ((err = snd_pcm_sw_params_set_tstamp_mode(capture_handle, sw_params, SND_PCM_TSTAMP_ENABLE)) < 0)
break; break;
if((err = snd_pcm_sw_params(capture_handle, sw_params)) < 0) if ((err = snd_pcm_sw_params(capture_handle, sw_params)) < 0)
break; break;
// if((err = snd_pcm_prepare(capture_handle)) < 0)
// break;
init_ok = true; init_ok = true;
break; break;
} }
if(init_ok) { if (init_ok) {
D( cerr << endl << "Audio init: ok; with sample rate: " << _sample_rate << "; and channels: " << _channels << endl;) D(sensor_port, cerr << "Audio init: ok; with sample rate: " << _sample_rate << "; and channels: " << _channels << endl);
// cerr << endl << "Audio init: ok; with sample rate: " << _sample_rate << "; and channels: " << _channels << endl;
_present = true; _present = true;
_play = false; _play = false;
set_volume(_volume); set_volume(_volume);
// create thread... // create thread...
init_pthread((void *)this); init_pthread((void *) this);
} else { } else {
D( cerr << "Audio: init FAIL!" << endl;) D(sensor_port, cerr << "Audio: init FAIL!" << endl);
// cerr << "Audio: init FAIL!" << endl;
_present = false; _present = false;
} }
} }
} }
Audio::~Audio(void) { Audio::~Audio(void) {
//cerr << "Audio::~Audio()" << endl; if (_present) {
if(_present) {
snd_pcm_drop(capture_handle); snd_pcm_drop(capture_handle);
snd_pcm_close(capture_handle); snd_pcm_close(capture_handle);
snd_config_update_free_global(); snd_config_update_free_global();
//cerr << "--------------->> close audio" << endl;
} }
if(sbuffer != NULL) if (sbuffer != NULL)
delete[] sbuffer; delete[] sbuffer;
} }
void Audio::set_capture_volume(int nvolume) { void Audio::set_capture_volume(int nvolume) {
if(_present == false) if (_present == false)
return; return;
// int err; // int err;
snd_mixer_t *mixer; snd_mixer_t *mixer;
...@@ -166,23 +173,23 @@ void Audio::set_capture_volume(int nvolume) { ...@@ -166,23 +173,23 @@ void Audio::set_capture_volume(int nvolume) {
snd_mixer_attach(mixer, "default"); snd_mixer_attach(mixer, "default");
snd_mixer_selem_register(mixer, NULL, NULL); snd_mixer_selem_register(mixer, NULL, NULL);
snd_mixer_load(mixer); snd_mixer_load(mixer);
for(elem = snd_mixer_first_elem(mixer); elem; elem = snd_mixer_elem_next(elem)) { for (elem = snd_mixer_first_elem(mixer); elem; elem = snd_mixer_elem_next(elem)) {
snd_mixer_selem_get_id(elem, sid); snd_mixer_selem_get_id(elem, sid);
if(!snd_mixer_selem_is_active(elem)) if (!snd_mixer_selem_is_active(elem))
continue; continue;
// set volume at percents for capture elements // set volume at percents for capture elements
snd_mixer_elem_t *selem = snd_mixer_find_selem(mixer, sid); snd_mixer_elem_t *selem = snd_mixer_find_selem(mixer, sid);
if(selem == NULL) { if (selem == NULL) {
break; break;
} }
long volume_min = 0; long volume_min = 0;
long volume_max = 0; long volume_max = 0;
if(snd_mixer_selem_get_capture_volume_range(selem, &volume_min, &volume_max) == 0) { if (snd_mixer_selem_get_capture_volume_range(selem, &volume_min, &volume_max) == 0) {
// set volume only for capture // set volume only for capture
if(nvolume > 65535) if (nvolume > 65535)
nvolume = 65535; nvolume = 65535;
if(nvolume < 0) if (nvolume < 0)
nvolume = 0; nvolume = 0;
long long vol_new = volume_max; long long vol_new = volume_max;
vol_new *= nvolume; vol_new *= nvolume;
...@@ -190,9 +197,13 @@ void Audio::set_capture_volume(int nvolume) { ...@@ -190,9 +197,13 @@ void Audio::set_capture_volume(int nvolume) {
long vol = 0; long vol = 0;
snd_mixer_selem_get_capture_volume(selem, SND_MIXER_SCHN_FRONT_LEFT, &vol); snd_mixer_selem_get_capture_volume(selem, SND_MIXER_SCHN_FRONT_LEFT, &vol);
snd_mixer_selem_set_capture_volume_all(selem, vol_new); snd_mixer_selem_set_capture_volume_all(selem, vol_new);
D( cerr << "element " << snd_mixer_selem_id_get_name(sid) << " - OLD min vol == " << volume_min << "; max vol == " << volume_max << "; volume == " << vol << endl;) D(sensor_port, cerr << "element " << snd_mixer_selem_id_get_name(sid) << " - OLD min vol == "
D( snd_mixer_selem_get_capture_volume(selem, SND_MIXER_SCHN_FRONT_LEFT, &vol);) << volume_min << "; max vol == " << volume_max << "; volume == " << vol
D( cerr << "element " << snd_mixer_selem_id_get_name(sid) << " - NEW min vol == " << volume_min << "; max vol == " << volume_max << "; volume == " << vol << endl;) << endl);
D(sensor_port, snd_mixer_selem_get_capture_volume(selem, SND_MIXER_SCHN_FRONT_LEFT, &vol));
D(sensor_port, cerr << "element " << snd_mixer_selem_id_get_name(sid) << " - NEW min vol == "
<< volume_min << "; max vol == " << volume_max << "; volume == " << vol
<< endl);
} }
} }
_volume = nvolume; _volume = nvolume;
...@@ -200,17 +211,14 @@ D( cerr << "element " << snd_mixer_selem_id_get_name(sid) << " - NEW min vol = ...@@ -200,17 +211,14 @@ D( cerr << "element " << snd_mixer_selem_id_get_name(sid) << " - NEW min vol =
} }
void Audio::Start(string ip, long port, int ttl) { void Audio::Start(string ip, long port, int ttl) {
if(!_present) if (!_present)
return; return;
D( cerr << "Audio ---> Start !!!" << endl;) D(sensor_port, cerr << "Audio ---> Start !!!" << endl);
//cerr << "Audio ---> Start !!!" << endl;
//is_first = true;
timestamp_rtcp = 0; timestamp_rtcp = 0;
f_tv.tv_sec = 0; f_tv.tv_sec = 0;
f_tv.tv_usec = 0; f_tv.tv_usec = 0;
snd_pcm_prepare(capture_handle); snd_pcm_prepare(capture_handle);
snd_pcm_reset(capture_handle); snd_pcm_reset(capture_handle);
//cerr << "Audio ---> Start !!! - done" << endl;
// get FPGA/sys time delta // get FPGA/sys time delta
// Parameters *params = Parameters::instance(); // Parameters *params = Parameters::instance();
...@@ -242,14 +250,14 @@ D( cerr << "Audio ---> Start !!!" << endl;) ...@@ -242,14 +250,14 @@ D( cerr << "Audio ---> Start !!!" << endl;)
tv_fpga.tv_usec = tv_fpga.tv_usec % 1000000; tv_fpga.tv_usec = tv_fpga.tv_usec % 1000000;
bool fpga_gt = false; bool fpga_gt = false;
if(tv_fpga.tv_sec > tv_sys.tv_sec) if (tv_fpga.tv_sec > tv_sys.tv_sec)
fpga_gt = true; fpga_gt = true;
if (tv_fpga.tv_sec == tv_sys.tv_sec) if (tv_fpga.tv_sec == tv_sys.tv_sec)
if(tv_fpga.tv_usec > tv_sys.tv_usec) if (tv_fpga.tv_usec > tv_sys.tv_usec)
fpga_gt = true; fpga_gt = true;
struct timeval *tv_b = &tv_sys; struct timeval *tv_b = &tv_sys;
struct timeval *tv_s = &tv_fpga; struct timeval *tv_s = &tv_fpga;
if(fpga_gt) { if (fpga_gt) {
tv_b = &tv_fpga; tv_b = &tv_fpga;
tv_s = &tv_sys; tv_s = &tv_sys;
} }
...@@ -258,9 +266,14 @@ D( cerr << "Audio ---> Start !!!" << endl;) ...@@ -258,9 +266,14 @@ D( cerr << "Audio ---> Start !!!" << endl;)
delta_fpga_sys *= 1000000; delta_fpga_sys *= 1000000;
delta_fpga_sys += tv_b->tv_usec; delta_fpga_sys += tv_b->tv_usec;
delta_fpga_sys -= tv_s->tv_usec; delta_fpga_sys -= tv_s->tv_usec;
if(fpga_gt) if (fpga_gt)
delta_fpga_sys = -delta_fpga_sys; delta_fpga_sys = -delta_fpga_sys;
D2(sensor_port, cerr << "first time = " << tv_1.tv_sec << ":" << tv_1.tv_usec
<< ", second time = " << tv_2.tv_sec << ":" << tv_2.tv_usec << endl);
D2(sensor_port, cerr << "FPGA time = " << tv_fpga.tv_sec << ":" << tv_fpga.tv_usec
<< ", system time = " << tv_sys.tv_sec << ":" << tv_sys.tv_usec << endl);
D2(sensor_port, cerr << "time delta = " << delta_fpga_sys << endl << endl);
//fprintf(stderr, "first time == %d:%06d; second time == %d:%06d\n", tv_1.tv_sec, tv_1.tv_usec, tv_2.tv_sec, tv_2.tv_usec); //fprintf(stderr, "first time == %d:%06d; second time == %d:%06d\n", tv_1.tv_sec, tv_1.tv_usec, tv_2.tv_sec, tv_2.tv_usec);
//fprintf(stderr, "FPGA time == %d:%06d; system time == %d:%06d\n", tv_fpga.tv_sec, tv_fpga.tv_usec, tv_sys.tv_sec, tv_sys.tv_usec); //fprintf(stderr, "FPGA time == %d:%06d; system time == %d:%06d\n", tv_fpga.tv_sec, tv_fpga.tv_usec, tv_sys.tv_sec, tv_sys.tv_usec);
//fprintf(stderr, "times delta == %06d\n\n", delta_fpga_sys); //fprintf(stderr, "times delta == %06d\n\n", delta_fpga_sys);
...@@ -269,23 +282,20 @@ D( cerr << "Audio ---> Start !!!" << endl;) ...@@ -269,23 +282,20 @@ D( cerr << "Audio ---> Start !!!" << endl;)
} }
void Audio::Stop(void) { void Audio::Stop(void) {
if(!_present) if (!_present)
return; return;
// cerr << "Audio ---> Stop !!!" << endl; D(sensor_port, cerr << "Audio ---> Stop !!!" << endl);
D( cerr << "Audio ---> Stop !!!" << endl;)
RTP_Stream::Stop(); RTP_Stream::Stop();
f_tv.tv_sec = 0; f_tv.tv_sec = 0;
f_tv.tv_usec = 0; f_tv.tv_usec = 0;
} }
long Audio::process(void) { long Audio::process(void) {
// static timeval ts_old = {0, 0};
long ret = 0; long ret = 0;
snd_pcm_status_t *status; snd_pcm_status_t *status;
snd_pcm_status_alloca(&status); snd_pcm_status_alloca(&status);
snd_timestamp_t ts; snd_timestamp_t ts;
unsigned long avail; unsigned long avail;
//bool first = true;
for(int i = 0; i < 4; i++) { for(int i = 0; i < 4; i++) {
snd_pcm_status(capture_handle, status); snd_pcm_status(capture_handle, status);
...@@ -344,16 +354,13 @@ fprintf(stderr, "status timestamp == %d:%06d at %d:%06d; delta == %d:%06d, slen ...@@ -344,16 +354,13 @@ fprintf(stderr, "status timestamp == %d:%06d at %d:%06d; delta == %d:%06d, slen
// --==-- // --==--
ret += slen; ret += slen;
process_send(slen); process_send(slen);
// check again what buffer is not empty // check again that buffer is not empty
snd_pcm_status(capture_handle, status); snd_pcm_status(capture_handle, status);
avail = (unsigned long)snd_pcm_status_get_avail(status); avail = (unsigned long)snd_pcm_status_get_avail(status);
//c++;
if(avail >= (unsigned long)sbuffer_len) { if(avail >= (unsigned long)sbuffer_len) {
//cerr << "process() again - available " << avail << " samples" << endl; D2(sensor_port, cerr << "process() again - available " << avail << " samples" << endl);
continue; continue;
} }
//if(c != 0)
//cerr << "process " << c << " times" << endl;
return ret; return ret;
} }
if(slen < 0) { if(slen < 0) {
...@@ -372,24 +379,24 @@ long Audio::process_send(long sample_len) { ...@@ -372,24 +379,24 @@ long Audio::process_send(long sample_len) {
static unsigned short packet_num = 0; static unsigned short packet_num = 0;
unsigned short pnum; unsigned short pnum;
void *m = (void *)sbuffer; void *m = (void *) sbuffer;
int i; int i;
long offset = 0; long offset = 0;
#define LEN 1200 #define LEN 1200
static unsigned char *d = NULL; static unsigned char *d = NULL;
if(d == NULL) { if (d == NULL) {
d = (unsigned char *)malloc(LEN + 20); d = (unsigned char *) malloc(LEN + 20);
} }
int to_send = sample_len * 2 * _channels; int to_send = sample_len * 2 * _channels;
int size = to_send; int size = to_send;
long count = 0; long count = 0;
uint32_t ts; uint32_t ts;
for(;;) { for (;;) {
if(to_send == 0) if (to_send == 0)
break; break;
if(to_send > LEN) { if (to_send > LEN) {
i = LEN; i = LEN;
to_send -= i; to_send -= i;
} else { } else {
...@@ -400,7 +407,7 @@ long Audio::process_send(long sample_len) { ...@@ -400,7 +407,7 @@ long Audio::process_send(long sample_len) {
uint32_t ts_delta = i / 2; uint32_t ts_delta = i / 2;
ts_delta /= _channels; ts_delta /= _channels;
timestamp_rtcp += ts_delta; timestamp_rtcp += ts_delta;
if(timestamp_rtcp > 0xFFFFFFFF) if (timestamp_rtcp > 0xFFFFFFFF)
timestamp_rtcp &= 0xFFFFFFFF; timestamp_rtcp &= 0xFFFFFFFF;
// //
packet_num++; packet_num++;
...@@ -408,21 +415,21 @@ long Audio::process_send(long sample_len) { ...@@ -408,21 +415,21 @@ long Audio::process_send(long sample_len) {
count += i; count += i;
// fill RTP header // fill RTP header
d[0] = 0x80; d[0] = 0x80;
if(count >= size) if (count >= size)
d[1] = _ptype + 0x80; d[1] = _ptype + 0x80;
else else
d[1] = _ptype; d[1] = _ptype;
memcpy((void *)&d[2], (void *)&pnum, 2); memcpy((void *) &d[2], (void *) &pnum, 2);
memcpy((void *)&d[4], (void *)&ts, 4); memcpy((void *) &d[4], (void *) &ts, 4);
memcpy((void *)&d[8], (void *)&SSRC, 4); memcpy((void *) &d[8], (void *) &SSRC, 4);
// fill data // fill data
memcpy((void *)&d[12], (void *)((char *)m + offset), i); memcpy((void *) &d[12], (void *) ((char *) m + offset), i);
offset += i; offset += i;
// send packet // send packet
rtp_packets++; rtp_packets++;
rtp_octets += i; // data + MJPEG header rtp_octets += i; // data + MJPEG header
rtp_socket->send((void *)d, i + 12); rtp_socket->send((void *) d, i + 12);
} }
return sample_len; return sample_len;
} }
...@@ -40,7 +40,7 @@ using namespace std; ...@@ -40,7 +40,7 @@ using namespace std;
class Audio : public RTP_Stream { class Audio : public RTP_Stream {
public: public:
Audio(bool enable, Parameters *pars, int sample_rate = SAMPLE_RATE, int channels = SAMPLE_CHANNELS); Audio(int port, bool enable, Parameters *pars, int sample_rate = SAMPLE_RATE, int channels = SAMPLE_CHANNELS);
virtual ~Audio(void); virtual ~Audio(void);
long sample_rate(void) { return _sample_rate; }; long sample_rate(void) { return _sample_rate; };
long channels(void) { return _channels; }; long channels(void) { return _channels; };
...@@ -51,11 +51,11 @@ public: ...@@ -51,11 +51,11 @@ public:
void Start(string ip, long port, int ttl = -1); void Start(string ip, long port, int ttl = -1);
void Stop(void); void Stop(void);
protected: protected:
int fd; // int fd;
snd_pcm_t *capture_handle; snd_pcm_t *capture_handle; // PCM handle, returned from snd_pcm_open
short *sbuffer; short *sbuffer;
long sbuffer_len; long sbuffer_len;
bool _present; bool _present; // flag indicating that audio interface has been initialized
long _sample_rate; long _sample_rate;
long _channels; long _channels;
long _volume; long _volume;
...@@ -66,9 +66,9 @@ protected: ...@@ -66,9 +66,9 @@ protected:
void set_capture_volume(int volume); void set_capture_volume(int volume);
uint64_t timestamp_rtcp; uint64_t timestamp_rtcp;
long delta_fpga_sys; // A/V clocks delta for RTCP long delta_fpga_sys; // A/V clocks delta for RTCP
bool is_first; // bool is_first;
bool is_first2; // bool is_first2;
}; };
#endif // _AUDIO__H_ #endif // _AUDIO__H_
...@@ -73,7 +73,8 @@ int main(int argc, char *argv[]) { ...@@ -73,7 +73,8 @@ int main(int argc, char *argv[]) {
cerr << "|" << (*it).first << "| == |" << (*it).second << "|" << endl; cerr << "|" << (*it).first << "| == |" << (*it).second << "|" << endl;
} }
for (int i = 0; i < SENSOR_PORTS; i++) { for (int i = 0; i < 1; i++) {
// for (int i = 0; i < SENSOR_PORTS; i++) {
pthread_attr_t attr; pthread_attr_t attr;
cout << "Start thread " << i << endl; cout << "Start thread " << i << endl;
streamers[i] = new Streamer(args, i); streamers[i] = new Streamer(args, i);
......
...@@ -39,7 +39,7 @@ using namespace std; ...@@ -39,7 +39,7 @@ using namespace std;
a; \ a; \
} while (0) } while (0)
#else #else
#define D(a) #define D(s_port, a)
#endif #endif
RTP_Stream::RTP_Stream(void) { RTP_Stream::RTP_Stream(void) {
...@@ -200,6 +200,8 @@ void RTP_Stream::rtcp_send_sr(void) { ...@@ -200,6 +200,8 @@ void RTP_Stream::rtcp_send_sr(void) {
ul = htonl(rtp_octets); ul = htonl(rtp_octets);
memcpy((void *) &packet[24], (void *) &ul, 4); memcpy((void *) &packet[24], (void *) &ul, 4);
rtcp_socket->send(packet, packet_len); rtcp_socket->send(packet, packet_len);
D(sensor_port, cerr << "stream name: " << stream_name << ", f_tv: " << f_tv.tv_sec << ":" << f_tv.tv_usec
<< ", timestamp: " << timestamp << endl);
} }
void RTP_Stream::rtcp_send_sdes(void) { void RTP_Stream::rtcp_send_sdes(void) {
......
...@@ -65,7 +65,7 @@ Streamer::Streamer(const map<string, string> &_args, int port_num) { ...@@ -65,7 +65,7 @@ Streamer::Streamer(const map<string, string> &_args, int port_num) {
params = new Parameters(sensor_port); params = new Parameters(sensor_port);
args = _args; args = _args;
audio = NULL; audio = NULL;
session->process_audio = false; session->process_audio = true;
session->audio.sample_rate = 0; session->audio.sample_rate = 0;
session->audio.channels = 0; session->audio.channels = 0;
session->rtp_out.ip_custom = false; session->rtp_out.ip_custom = false;
...@@ -83,6 +83,13 @@ Streamer::Streamer(const map<string, string> &_args, int port_num) { ...@@ -83,6 +83,13 @@ Streamer::Streamer(const map<string, string> &_args, int port_num) {
} }
rtsp_server = NULL; rtsp_server = NULL;
connected_count = 0; connected_count = 0;
// DEBUG FEATURE: self-enable audio processing, this should be done elsewhere, probably from camvc
unsigned long snd_en = 0;
if (session->process_audio)
snd_en = 1;
unsigned long params_array[2] = {P_STROP_AUDIO_EN, snd_en};
params->setPValue(params_array, 2);
} }
void Streamer::audio_init(void) { void Streamer::audio_init(void) {
...@@ -91,7 +98,7 @@ void Streamer::audio_init(void) { ...@@ -91,7 +98,7 @@ void Streamer::audio_init(void) {
delete audio; delete audio;
} }
D(sensor_port, cout << "audio_enabled == " << session->process_audio << endl); D(sensor_port, cout << "audio_enabled == " << session->process_audio << endl);
audio = new Audio(session->process_audio, params, session->audio.sample_rate, session->audio.channels); audio = new Audio(sensor_port, session->process_audio, params, session->audio.sample_rate, session->audio.channels);
if (audio->present() && session->process_audio) { if (audio->present() && session->process_audio) {
session->process_audio = true; session->process_audio = true;
session->audio.type = audio->ptype(); session->audio.type = audio->ptype();
...@@ -271,6 +278,7 @@ int Streamer::update_settings(bool apply) { ...@@ -271,6 +278,7 @@ int Streamer::update_settings(bool apply) {
f_audio_channels = true; f_audio_channels = true;
if ((audio_proc || session->process_audio) && (f_audio_rate || f_audio_channels)) if ((audio_proc || session->process_audio) && (f_audio_rate || f_audio_channels))
audio_was_changed = true; audio_was_changed = true;
D(sensor_port, cerr << "audio_proc = " << audio_proc << ", process_audio = " << session->process_audio << ", f_audio_rate = " << f_audio_rate << "f_audio_channels = " << f_audio_channels << endl);
if (apply) { if (apply) {
bool audio_restarted = false; bool audio_restarted = false;
if (audio_was_changed) { if (audio_was_changed) {
......
...@@ -40,10 +40,10 @@ using namespace std; ...@@ -40,10 +40,10 @@ using namespace std;
//#undef VIDEO_DEBUG //#undef VIDEO_DEBUG
//#undef VIDEO_DEBUG_2 // for timestamp monitoring //#undef VIDEO_DEBUG_2 // for timestamp monitoring
//#undef VIDEO_DEBUG_3 // for FPS monitoring #undef VIDEO_DEBUG_3 // for FPS monitoring
#define VIDEO_DEBUG #define VIDEO_DEBUG
#define VIDEO_DEBUG_2 // for timestamp monitoring #define VIDEO_DEBUG_2 // for timestamp monitoring
#define VIDEO_DEBUG_3 // for FPS monitoring //#define VIDEO_DEBUG_3 // for FPS monitoring
#ifdef VIDEO_DEBUG #ifdef VIDEO_DEBUG
#define D(s_port, a) \ #define D(s_port, a) \
...@@ -52,7 +52,7 @@ using namespace std; ...@@ -52,7 +52,7 @@ using namespace std;
a; \ a; \
} while (0) } while (0)
#else #else
#define D(a) #define D(s_port, a)
#endif #endif
#ifdef VIDEO_DEBUG_2 #ifdef VIDEO_DEBUG_2
...@@ -62,7 +62,7 @@ using namespace std; ...@@ -62,7 +62,7 @@ using namespace std;
a; \ a; \
} while (0) } while (0)
#else #else
#define D2(a) #define D2(s_port, a)
#endif #endif
#ifdef VIDEO_DEBUG_3 #ifdef VIDEO_DEBUG_3
...@@ -72,7 +72,7 @@ using namespace std; ...@@ -72,7 +72,7 @@ using namespace std;
a; \ a; \
} while (0) } while (0)
#else #else
#define D3(a) #define D3(s_port, a)
#endif #endif
/** The length of interframe parameters in bytes */ /** The length of interframe parameters in bytes */
...@@ -459,7 +459,6 @@ long Video::capture(void) { ...@@ -459,7 +459,6 @@ long Video::capture(void) {
// read Q value // read Q value
get_frame_pars(fp, latestAvailableFrame_ptr); get_frame_pars(fp, latestAvailableFrame_ptr);
D3(sensor_port, cerr << "fp->signffff " << fp->signffff << endl);
// See if the frame parameters are the same as were used when starting the stream, // See if the frame parameters are the same as were used when starting the stream,
// otherwise check for up to G_SKIP_DIFF_FRAME older frames and return them instead. // otherwise check for up to G_SKIP_DIFF_FRAME older frames and return them instead.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment