|
|
@@ -40,7 +40,7 @@ static pa_usec_t play_latency = 0; //real latency in usec (for timestamping)
|
|
|
//pa_context* pa_ctx; /* pulse context*/
|
|
|
|
|
|
//pa_stream* playstream; /* pulse audio stream*/
|
|
|
-pa_context* play_pa_ctx; /* pulse context*/
|
|
|
+//pa_context* play_pa_ctx; /* pulse context*/
|
|
|
|
|
|
static apr_status_t read_frame(void* self, audioframe_t* frame)
|
|
|
{
|
|
|
@@ -433,7 +433,6 @@ static void get_play_latency(pa_stream* s)
|
|
|
|
|
|
pa_stream_get_timing_info(s);
|
|
|
if (pa_stream_get_latency(s, &l, &negative) != 0) {
|
|
|
- audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pa_stream_get_latency failed for %s.", __FUNCTION__, __LINE__, pa_strerror(pa_context_errno(play_pa_ctx)));
|
|
|
return;
|
|
|
}
|
|
|
play_latency = l;
|
|
|
@@ -466,19 +465,23 @@ static void stream_write_request_cb(pa_stream* s, size_t length, void* data)
|
|
|
while (audio_ctx->uaudio_len < nbytes)
|
|
|
{
|
|
|
char delaybuffer[RVC_DELAY_AUDIO_LEN] = { 0 };
|
|
|
- if (audio_ctx->bstart_get_flag && audio_ctx->micspkpulse_parent) {
|
|
|
- if (0 == ((audiomicspkpulse_t*)(audio_ctx->micspkpulse_parent))->ply_buf_cnt) {
|
|
|
- int iget = delay_buf_get((delay_buf*)((audiomicspkpulse_t*)(audio_ctx->micspkpulse_parent))->ply_dbuf, (short*)delaybuffer);
|
|
|
+ if (audio_ctx->bstart_get_flag && audio_ctx->micspkpulse_parent && audio_ctx->play_stream_flag) {
|
|
|
+ audiomicspkpulse_t* audio_micspk = (audiomicspkpulse_t*)audio_ctx->micspkpulse_parent;
|
|
|
+ if (0 == audio_micspk->ply_buf_cnt) {
|
|
|
+ int iget = delay_buf_get((delay_buf*)audio_micspk->ply_dbuf, (short*)delaybuffer);
|
|
|
if (0 == iget){
|
|
|
- if (audio_ctx->uaudio_len + RVC_DELAY_AUDIO_LEN < RVC_MAX_AUDIO_BUFFER_LEN){
|
|
|
- memcpy(audio_ctx->paudio_buffer + audio_ctx->uaudio_len, delaybuffer, RVC_DELAY_AUDIO_LEN);
|
|
|
- audio_ctx->uaudio_len += RVC_DELAY_AUDIO_LEN;
|
|
|
- }
|
|
|
- else{
|
|
|
- memcpy(audio_ctx->paudio_buffer + audio_ctx->uaudio_len, delaybuffer, RVC_MAX_AUDIO_BUFFER_LEN - audio_ctx->uaudio_len);
|
|
|
- audio_ctx->uaudio_len = nbytes = RVC_MAX_AUDIO_BUFFER_LEN;
|
|
|
- break;
|
|
|
- }
|
|
|
+ //char audionsbuffer[RVC_DELAY_AUDIO_LEN] = { 0 };
|
|
|
+ //if (0 == audio_micspk->on_audio_play_ns(audionsbuffer, RVC_DELAY_AUDIO_LEN, delaybuffer, RVC_DELAY_AUDIO_LEN, audio_micspk->user_data)) {
|
|
|
+ if (audio_ctx->uaudio_len + RVC_DELAY_AUDIO_LEN < RVC_MAX_AUDIO_BUFFER_LEN) {
|
|
|
+ memcpy(audio_ctx->paudio_buffer + audio_ctx->uaudio_len, delaybuffer, RVC_DELAY_AUDIO_LEN);
|
|
|
+ audio_ctx->uaudio_len += RVC_DELAY_AUDIO_LEN;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ memcpy(audio_ctx->paudio_buffer + audio_ctx->uaudio_len, delaybuffer, RVC_MAX_AUDIO_BUFFER_LEN - audio_ctx->uaudio_len);
|
|
|
+ audio_ctx->uaudio_len = nbytes = RVC_MAX_AUDIO_BUFFER_LEN;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -499,9 +502,9 @@ static void stream_write_request_cb(pa_stream* s, size_t length, void* data)
|
|
|
// audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pa_stream_write success.", __FUNCTION__, __LINE__);
|
|
|
//}
|
|
|
}
|
|
|
- else {
|
|
|
- audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pa_stream_begin_write failed for %s.", __FUNCTION__, __LINE__, pa_strerror(pa_context_errno(play_pa_ctx)));
|
|
|
- }
|
|
|
+ //else {
|
|
|
+ // audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pa_stream_begin_write failed for %s.", __FUNCTION__, __LINE__, pa_strerror(pa_context_errno(play_pa_ctx)));
|
|
|
+ //}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -512,10 +515,7 @@ static void stream_request_cb(pa_stream* s, size_t length, void* data)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- int64_t ts = 0;/*
|
|
|
- int64_t buff_ts = 0;
|
|
|
- uint32_t i = 0;*/
|
|
|
-
|
|
|
+ int64_t ts = 0;
|
|
|
|
|
|
while (pa_stream_readable_size(s) > 0)
|
|
|
{
|
|
|
@@ -554,10 +554,11 @@ static void stream_request_cb(pa_stream* s, size_t length, void* data)
|
|
|
|
|
|
icount = 0;
|
|
|
while (audio_ctx->uaudio_inlen > RVC_DELAY_AUDIO_LEN) {
|
|
|
- if (audio_ctx->bstart_put_flag && audio_ctx->micspkpulse_parent) {
|
|
|
+ if (audio_ctx->bstart_put_flag && audio_ctx->micspkpulse_parent && audio_ctx->stream_flag) {
|
|
|
+ audiomicspkpulse_t* audio_micspk = audio_ctx->micspkpulse_parent;
|
|
|
char paudions[RVC_DELAY_AUDIO_LEN] = { 0 };
|
|
|
- if (0 == ((audiomicspkpulse_t*)(audio_ctx->micspkpulse_parent))->on_audio_ns(paudions, RVC_DELAY_AUDIO_LEN, (short*)audio_ctx->paudio_in + icount * RVC_DELAY_AUDIO_LEN / sizeof(short), RVC_DELAY_AUDIO_LEN, ((audiomicspkpulse_t*)(audio_ctx->micspkpulse_parent))->user_data)){
|
|
|
- delay_buf_put((delay_buf*)((audiomicspkpulse_t*)(audio_ctx->micspkpulse_parent))->rec_dbuf, paudions);
|
|
|
+ if (0 == audio_micspk->on_audio_ns(paudions, RVC_DELAY_AUDIO_LEN, (short*)audio_ctx->paudio_in + icount * RVC_DELAY_AUDIO_LEN / sizeof(short), RVC_DELAY_AUDIO_LEN, audio_micspk->user_data)){
|
|
|
+ delay_buf_put((delay_buf*)audio_micspk->rec_dbuf, paudions);
|
|
|
}
|
|
|
icount++;
|
|
|
audio_ctx->uaudio_inlen -= RVC_DELAY_AUDIO_LEN;
|
|
|
@@ -632,7 +633,7 @@ void* pulse_read_audio(void* data)
|
|
|
/* set the sample spec (frame rate, channels and format) */
|
|
|
ss.rate = audio_ctx->samprate;
|
|
|
ss.channels = audio_ctx->channels;
|
|
|
- ss.format = audio_ctx->eformat/*PA_SAMPLE_FLOAT32LE*/; /*for PCM -> PA_SAMPLE_S16LE*/
|
|
|
+ ss.format = audio_ctx->eformat;/*PA_SAMPLE_FLOAT32LE*/ /*for PCM -> PA_SAMPLE_S16LE*/
|
|
|
|
|
|
pa_stream* recordstream = pa_stream_new(pa_ctx, "Record", &ss, NULL);
|
|
|
if (!recordstream){
|
|
|
@@ -694,7 +695,7 @@ void* pulse_read_audio(void* data)
|
|
|
while (audio_ctx->stream_flag == AUDIO_STRM_ON){
|
|
|
pa_mainloop_iterate(pa_ml, 1, NULL);
|
|
|
}
|
|
|
-
|
|
|
+ pa_stream_set_read_callback(recordstream, NULL, NULL);
|
|
|
audio_log_v(AUDIO_LOG_LEVEL_INFO, "AUDIO: pulse audio stream terminated(%i)", audio_ctx->stream_flag);
|
|
|
|
|
|
pa_stream_disconnect(recordstream);
|
|
|
@@ -750,12 +751,10 @@ void* pulse_write_audio(void* data)
|
|
|
int pa_ready = 0;
|
|
|
char* dev = NULL;
|
|
|
|
|
|
- pa_cvolume* ptr_cvolume = NULL;
|
|
|
-
|
|
|
/* Create a mainloop API and connection to the default server */
|
|
|
pa_ml = pa_mainloop_new();
|
|
|
pa_mlapi = pa_mainloop_get_api(pa_ml);
|
|
|
- play_pa_ctx = pa_context_new(pa_mlapi, "rvc play api");
|
|
|
+ pa_context* play_pa_ctx = pa_context_new(pa_mlapi, "rvc play api");
|
|
|
|
|
|
if (PA_OK != pa_context_connect(play_pa_ctx, NULL, PA_CONTEXT_NOFLAGS, NULL)) {
|
|
|
audio_log_v(AUDIO_LOG_LEVEL_INFO, "AUDIO: PULSE - unable to connect to server: pa_context_connect failed for %d.", pa_context_errno(play_pa_ctx));
|
|
|
@@ -798,7 +797,7 @@ void* pulse_write_audio(void* data)
|
|
|
/* define the callbacks */
|
|
|
pa_stream_set_write_callback(playstream, stream_write_request_cb, (void*)audio_ctx);
|
|
|
|
|
|
- pa_stream_set_latency_update_callback(playstream, stream_latency_cb, NULL);
|
|
|
+ //pa_stream_set_latency_update_callback(playstream, stream_latency_cb, NULL);
|
|
|
|
|
|
// Set properties of the record buffer
|
|
|
pa_zero(bufattr);
|
|
|
@@ -820,10 +819,10 @@ void* pulse_write_audio(void* data)
|
|
|
|
|
|
dev = audio_ctx->list_output_devices[audio_ctx->play_device].name;
|
|
|
|
|
|
- audio_log_v(AUDIO_LOG_LEVEL_INFO, "play audio connecting to device %s (channels %d rate %d buf fragsize %d buf tlength %d)", dev, ss.channels, ss.rate, bufattr.fragsize, bufattr.tlength);
|
|
|
+ audio_log_v(AUDIO_LOG_LEVEL_INFO, "play audio connecting to device %s (channels %d rate %d buf frag size %d buf length %d)", dev, ss.channels, ss.rate, bufattr.fragsize, bufattr.tlength);
|
|
|
|
|
|
// Connect the stream to a sink
|
|
|
- r = pa_stream_connect_playback(playstream, dev, &bufattr, (pa_stream_flags_t)pastream_flag, ptr_cvolume, NULL);
|
|
|
+ r = pa_stream_connect_playback(playstream, dev, &bufattr, (pa_stream_flags_t)pastream_flag, NULL, NULL);
|
|
|
if (PA_OK != r)
|
|
|
{
|
|
|
audio_log_v(AUDIO_LOG_LEVEL_INFO, "play stream connected failed for %d.", pa_context_errno(play_pa_ctx));
|
|
|
@@ -848,6 +847,7 @@ void* pulse_write_audio(void* data)
|
|
|
pa_mainloop_iterate(pa_ml, 1, NULL);
|
|
|
}
|
|
|
|
|
|
+ pa_stream_set_write_callback(playstream, NULL, NULL);
|
|
|
audio_log_v(AUDIO_LOG_LEVEL_INFO, "AUDIO: play audio stream terminated(%i)", audio_ctx->play_stream_flag);
|
|
|
|
|
|
pa_stream_disconnect(playstream);
|
|
|
@@ -892,7 +892,6 @@ int audio_stop_playaudio(audio_context_t* audio_ctx)
|
|
|
audio_log_v(AUDIO_LOG_LEVEL_INFO, "AUDIO: (pulse audio) write thread joined failed.");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
return 0;
|
|
|
}
|
|
|
|