chansrv: change to 44100 recording, disconnect / reconnect fixes

This commit is contained in:
Jay Sorg 2014-11-26 16:48:37 -08:00
parent 2d514e666a
commit bff2009147
2 changed files with 52 additions and 16 deletions

View File

@ -174,6 +174,7 @@ static int data_get(struct userdata *u, pa_memchunk *chunk) {
int fd;
int bytes;
int read_bytes;
struct sockaddr_un s;
char *data;
char buf[11];
@ -216,7 +217,12 @@ static int data_get(struct userdata *u, pa_memchunk *chunk) {
buf[9] = 0;
buf[10] = 0;
lsend(u->fd, buf, 11);
if (lsend(u->fd, buf, 11) != 11) {
close(u->fd);
u->fd = 0;
pa_memblock_release(chunk->memblock);
return -1;
}
u->want_src_data = 1;
pa_log_debug("###### started recording");
}
@ -234,10 +240,22 @@ static int data_get(struct userdata *u, pa_memchunk *chunk) {
buf[9] = (unsigned char) chunk->length;
buf[10] = (unsigned char) ((chunk->length >> 8) & 0xff);
lsend(u->fd, buf, 11);
if (lsend(u->fd, buf, 11) != 11) {
close(u->fd);
u->fd = 0;
pa_memblock_release(chunk->memblock);
u->want_src_data = 0;
return -1;
}
/* read length of data available */
lrecv(u->fd, (char *) ubuf, 2);
if (lrecv(u->fd, (char *) ubuf, 2) != 2) {
close(u->fd);
u->fd = 0;
pa_memblock_release(chunk->memblock);
u->want_src_data = 0;
return -1;
}
bytes = ((ubuf[1] << 8) & 0xff00) | (ubuf[0] & 0xff);
if (bytes == 0) {
@ -246,15 +264,22 @@ static int data_get(struct userdata *u, pa_memchunk *chunk) {
}
/* get data */
bytes = lrecv(u->fd, data, bytes);
read_bytes = lrecv(u->fd, data, bytes);
if (read_bytes != bytes) {
close(u->fd);
u->fd = 0;
pa_memblock_release(chunk->memblock);
u->want_src_data = 0;
return -1;
}
pa_memblock_release(chunk->memblock);
return bytes;
return read_bytes;
}
static void thread_func(void *userdata) {
struct userdata *u = userdata;
int bytes;
pa_assert(u);
pa_thread_mq_install(&u->thread_mq);
@ -271,10 +296,15 @@ static void thread_func(void *userdata) {
now = pa_rtclock_now();
if ((chunk.length = pa_usec_to_bytes(now - u->timestamp, &u->source->sample_spec)) > 0) {
chunk.memblock = pa_memblock_new(u->core->mempool, (size_t) -1); /* or chunk.length? */
chunk.length *= 4;
chunk.memblock = pa_memblock_new(u->core->mempool, chunk.length);
chunk.index = 0;
data_get(u, &chunk);
pa_source_post(u->source, &chunk);
bytes = data_get(u, &chunk);
if (bytes > 0)
{
chunk.length = bytes;
pa_source_post(u->source, &chunk);
}
pa_memblock_unref(chunk.memblock);
u->timestamp = now;
}
@ -298,7 +328,10 @@ static void thread_func(void *userdata) {
buf[9] = 0;
buf[10] = 0;
lsend(u->fd, buf, 11);
if (lsend(u->fd, buf, 11) != 11) {
close(u->fd);
u->fd = 0;
}
u->want_src_data = 0;
pa_log_debug("###### stopped recording");
}
@ -338,7 +371,7 @@ int pa__init(pa_module *m) {
goto fail;
}
#if 0
#if 1
ss = m->core->default_sample_spec;
#else
ss.format = PA_SAMPLE_S16LE;

View File

@ -140,8 +140,8 @@ static struct xr_wave_format_ex g_pcm_inp_44100 =
#define SND_NUM_INP_FORMATS 2
static struct xr_wave_format_ex *g_wave_inp_formats[SND_NUM_INP_FORMATS] =
{
&g_pcm_inp_22050,
&g_pcm_inp_44100
&g_pcm_inp_44100,
&g_pcm_inp_22050
};
static int g_client_input_format_index = 0;
@ -960,7 +960,7 @@ sound_process_input_format(int aindex, int wFormatTag, int nChannels,
LOG(10, (" wBitsPerSample %d", wBitsPerSample));
LOG(10, (" cbSize %d", cbSize));
#if 0
#if 1
/* select CD quality audio */
if (wFormatTag == g_pcm_inp_44100.wFormatTag &&
nChannels == g_pcm_inp_44100.nChannels &&
@ -1047,7 +1047,9 @@ sound_input_start_recording(void)
/* if there is any data in FIFO, discard it */
while ((s = (struct stream *) fifo_remove(&g_in_fifo)) != NULL)
{
xstream_free(s);
}
g_bytes_in_fifo = 0;
xstream_new(s, 1024);
@ -1110,14 +1112,15 @@ sound_process_input_data(struct stream *s, int bytes)
{
struct stream *ls;
LOG(0, ("sound_process_input_data: bytes %d g_bytes_in_fifo %d",
LOG(10, ("sound_process_input_data: bytes %d g_bytes_in_fifo %d",
bytes, g_bytes_in_fifo));
#if 0 /* no need to cap anymore */
/* cap data in fifo */
if (g_bytes_in_fifo > 8 * 1024)
{
return 0;
}
#endif
xstream_new(ls, bytes);
g_memcpy(ls->data, s->p, bytes);
ls->p += bytes;