mirror of https://github.com/neutrinolabs/xrdp
Change chansrv to use common fifo code
This commit is contained in:
parent
3d87d40d0a
commit
05d1733950
|
@ -61,8 +61,6 @@ xrdp_chansrv_SOURCES = \
|
|||
clipboard_file.h \
|
||||
devredir.c \
|
||||
devredir.h \
|
||||
fifo.c \
|
||||
fifo.h \
|
||||
irp.c \
|
||||
irp.h \
|
||||
rail.c \
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
#define AUDIN_NAME "AUDIO_INPUT"
|
||||
#define AUDIN_FLAGS 1 /* WTS_CHANNEL_OPTION_DYNAMIC */
|
||||
|
||||
extern FIFO g_in_fifo; /* in sound.c */
|
||||
extern struct fifo *g_in_fifo; /* in sound.c */
|
||||
extern int g_bytes_in_fifo; /* in sound.c */
|
||||
|
||||
struct xr_wave_format_ex
|
||||
|
@ -346,7 +346,7 @@ audin_process_data(int chan_id, struct stream *s)
|
|||
g_memcpy(ls->data, s->p, data_bytes);
|
||||
ls->p += data_bytes;
|
||||
s_mark_end(ls);
|
||||
fifo_insert(&g_in_fifo, (void *) ls);
|
||||
fifo_add_item(g_in_fifo, (void *) ls);
|
||||
g_bytes_in_fifo += data_bytes;
|
||||
|
||||
return 0;
|
||||
|
@ -514,19 +514,15 @@ int
|
|||
audin_start(void)
|
||||
{
|
||||
int error;
|
||||
struct stream *s;
|
||||
|
||||
LOG_DEVEL(LOG_LEVEL_INFO, "audin_start:");
|
||||
if (g_audin_chanid != 0)
|
||||
if (g_audin_chanid != 0 || g_in_fifo == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* if there is any data in FIFO, discard it */
|
||||
while ((s = (struct stream *) fifo_remove(&g_in_fifo)) != NULL)
|
||||
{
|
||||
xstream_free(s);
|
||||
}
|
||||
fifo_clear(g_in_fifo, NULL);
|
||||
g_bytes_in_fifo = 0;
|
||||
|
||||
error = chansrv_drdynvc_open(AUDIN_NAME, AUDIN_FLAGS,
|
||||
|
|
|
@ -1,265 +0,0 @@
|
|||
/**
|
||||
* xrdp: A Remote Desktop Protocol server.
|
||||
*
|
||||
* Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* FIFO implementation to store a pointer to a user struct */
|
||||
|
||||
/* module based logging */
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include <config_ac.h>
|
||||
#endif
|
||||
|
||||
#define MODULE_NAME "FIFO "
|
||||
#define LOCAL_DEBUG
|
||||
|
||||
#include "chansrv.h"
|
||||
#include "fifo.h"
|
||||
#include "os_calls.h"
|
||||
|
||||
/**
|
||||
* Initialize a FIFO that grows as required
|
||||
*
|
||||
* @param fp pointer to a FIFO
|
||||
* @param num_entries initial size
|
||||
*
|
||||
* @return 0 on success, -1 on failure
|
||||
*****************************************************************************/
|
||||
int
|
||||
fifo_init(FIFO *fp, int num_entries)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "entered");
|
||||
|
||||
/* validate params */
|
||||
if (!fp)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "invalid parameters");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (num_entries < 1)
|
||||
{
|
||||
num_entries = 10;
|
||||
}
|
||||
|
||||
fp->rd_ptr = 0;
|
||||
fp->wr_ptr = 0;
|
||||
fp->user_data = (long *) g_malloc(sizeof(long) * num_entries, 1);
|
||||
|
||||
if (fp->user_data)
|
||||
{
|
||||
fp->entries = num_entries;
|
||||
LOG_DEVEL(LOG_LEVEL_DEBUG, "FIFO created; rd_ptr=%d wr_ptr=%d entries=%d",
|
||||
fp->rd_ptr, fp->wr_ptr, fp->entries);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_ERROR, "FIFO create error; system out of memory");
|
||||
fp->entries = 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deinit FIFO and release resources
|
||||
*
|
||||
* @param fp FIFO to deinit
|
||||
*
|
||||
* @return 0 on success, -1 on error
|
||||
*****************************************************************************/
|
||||
int
|
||||
fifo_deinit(FIFO *fp)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "entered");
|
||||
|
||||
if (!fp)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "FIFO is null");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fp->user_data)
|
||||
{
|
||||
g_free(fp->user_data);
|
||||
fp->user_data = 0;
|
||||
}
|
||||
|
||||
fp->rd_ptr = 0;
|
||||
fp->wr_ptr = 0;
|
||||
fp->entries = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if FIFO is empty
|
||||
*
|
||||
* @param fp FIFO
|
||||
*
|
||||
* @return 1 if FIFO is empty, 0 otherwise
|
||||
*****************************************************************************/
|
||||
int
|
||||
fifo_is_empty(FIFO *fp)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "entered");
|
||||
|
||||
if (!fp)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "FIFO is null");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (fp->rd_ptr == fp->wr_ptr) ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert an item at the end
|
||||
*
|
||||
* @param fp FIFO
|
||||
* @param data data to insert into FIFO
|
||||
*
|
||||
* @param 0 on success, -1 on error
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
fifo_insert(FIFO *fp, void *data)
|
||||
{
|
||||
long *lp;
|
||||
int next_val; /* next value for wr_ptr */
|
||||
int i;
|
||||
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "entered");
|
||||
|
||||
if (!fp)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "FIFO is null");
|
||||
return -1;
|
||||
}
|
||||
|
||||
next_val = fp->wr_ptr + 1;
|
||||
if (next_val >= fp->entries)
|
||||
{
|
||||
next_val = 0;
|
||||
}
|
||||
|
||||
if (next_val == fp->rd_ptr)
|
||||
{
|
||||
/* FIFO is full, expand it by 10 entries */
|
||||
lp = (long *) g_malloc(sizeof(long) * (fp->entries + 10), 1);
|
||||
if (!lp)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_DEBUG, "FIFO full; cannot expand, no memory");
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG_DEVEL(LOG_LEVEL_DEBUG, "FIFO full, expanding by 10 entries");
|
||||
|
||||
/* copy old data new location */
|
||||
for (i = 0; i < (fp->entries - 1); i++)
|
||||
{
|
||||
lp[i] = fp->user_data[fp->rd_ptr++];
|
||||
if (fp->rd_ptr >= fp->entries)
|
||||
{
|
||||
fp->rd_ptr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* update pointers */
|
||||
fp->rd_ptr = 0;
|
||||
fp->wr_ptr = fp->entries - 1;
|
||||
next_val = fp->entries;
|
||||
fp->entries += 10;
|
||||
|
||||
/* free old data */
|
||||
g_free(fp->user_data);
|
||||
fp->user_data = lp;
|
||||
}
|
||||
|
||||
LOG_DEVEL(LOG_LEVEL_DEBUG, "inserting data at index %d", fp->wr_ptr);
|
||||
|
||||
fp->user_data[fp->wr_ptr] = (long) data;
|
||||
fp->wr_ptr = next_val;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the head
|
||||
*
|
||||
* @param fp FIFO
|
||||
*
|
||||
* @param data on success, NULL on error
|
||||
*****************************************************************************/
|
||||
void *
|
||||
fifo_remove(FIFO *fp)
|
||||
{
|
||||
long data;
|
||||
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "entered");
|
||||
|
||||
if (!fp)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "FIFO is null");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fp->rd_ptr == fp->wr_ptr)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "FIFO is empty");
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOG_DEVEL(LOG_LEVEL_DEBUG, "removing data at index %d", fp->rd_ptr);
|
||||
|
||||
data = fp->user_data[fp->rd_ptr++];
|
||||
|
||||
if (fp->rd_ptr >= fp->entries)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "FIFO rd_ptr wrapped around");
|
||||
fp->rd_ptr = 0;
|
||||
}
|
||||
|
||||
return (void *) data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return item from head, but do not remove it
|
||||
*
|
||||
* @param fp FIFO
|
||||
*
|
||||
* @param data on success, NULL on error
|
||||
*****************************************************************************/
|
||||
void *
|
||||
fifo_peek(FIFO *fp)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "entered");
|
||||
|
||||
if (!fp)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "FIFO is null");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fp->rd_ptr == fp->wr_ptr)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "FIFO is empty");
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOG_DEVEL(LOG_LEVEL_DEBUG, "peeking data at index %d", fp->rd_ptr);
|
||||
|
||||
return (void *) fp->user_data[fp->rd_ptr];
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/**
|
||||
* xrdp: A Remote Desktop Protocol server.
|
||||
*
|
||||
* Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FIFO_H
|
||||
#define FIFO_H
|
||||
|
||||
/* FIFO implementation to store a pointer to a user struct */
|
||||
|
||||
typedef struct fifo
|
||||
{
|
||||
long *user_data;
|
||||
int rd_ptr;
|
||||
int wr_ptr;
|
||||
int entries;
|
||||
} FIFO;
|
||||
|
||||
int fifo_init(FIFO *fp, int num_entries);
|
||||
int fifo_deinit(FIFO *fp);
|
||||
int fifo_is_empty(FIFO *fp);
|
||||
int fifo_insert(FIFO *fp, void *data);
|
||||
void *fifo_remove(FIFO *fp);
|
||||
void *fifo_peek(FIFO *fp);
|
||||
|
||||
#endif // FIFO_H
|
|
@ -74,7 +74,7 @@ static struct trans *g_audio_c_trans_in = 0; /* connection */
|
|||
static int g_training_sent_time = 0;
|
||||
static int g_cBlockNo = 0;
|
||||
static int g_bytes_in_stream = 0;
|
||||
FIFO g_in_fifo;
|
||||
struct fifo *g_in_fifo;
|
||||
int g_bytes_in_fifo = 0;
|
||||
static int g_time_diff = 0;
|
||||
static int g_best_time_diff = 0;
|
||||
|
@ -1259,6 +1259,15 @@ sound_sndsrvr_source_conn_in(struct trans *trans, struct trans *new_trans)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Item destructor for g_in_fifo
|
||||
*/
|
||||
static void
|
||||
in_fifo_item_destructor(void *item, void *closure)
|
||||
{
|
||||
xstream_free((struct stream *)item);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int
|
||||
sound_init(void)
|
||||
|
@ -1276,7 +1285,7 @@ sound_init(void)
|
|||
sound_start_source_listener();
|
||||
|
||||
/* save data from sound_server_source */
|
||||
fifo_init(&g_in_fifo, 100);
|
||||
g_in_fifo = fifo_create(in_fifo_item_destructor);
|
||||
|
||||
g_client_does_fdk_aac = 0;
|
||||
g_client_fdk_aac_index = 0;
|
||||
|
@ -1340,7 +1349,7 @@ sound_deinit(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
fifo_deinit(&g_in_fifo);
|
||||
fifo_delete(g_in_fifo, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1660,7 +1669,6 @@ sound_process_input_formats(struct stream *s, int size)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -1673,10 +1681,7 @@ sound_input_start_recording(void)
|
|||
LOG_DEVEL(LOG_LEVEL_DEBUG, "sound_input_start_recording:");
|
||||
|
||||
/* if there is any data in FIFO, discard it */
|
||||
while ((s = (struct stream *) fifo_remove(&g_in_fifo)) != NULL)
|
||||
{
|
||||
xstream_free(s);
|
||||
}
|
||||
fifo_clear(g_in_fifo, NULL);
|
||||
g_bytes_in_fifo = 0;
|
||||
|
||||
xstream_new(s, 1024);
|
||||
|
@ -1752,7 +1757,7 @@ sound_process_input_data(struct stream *s, int bytes)
|
|||
g_memcpy(ls->data, s->p, bytes);
|
||||
ls->p += bytes;
|
||||
s_mark_end(ls);
|
||||
fifo_insert(&g_in_fifo, (void *) ls);
|
||||
fifo_add_item(g_in_fifo, (void *) ls);
|
||||
g_bytes_in_fifo += bytes;
|
||||
|
||||
return 0;
|
||||
|
@ -1805,7 +1810,7 @@ sound_sndsrvr_source_data_in(struct trans *trans)
|
|||
{
|
||||
if (g_stream_inp == NULL)
|
||||
{
|
||||
g_stream_inp = (struct stream *) fifo_remove(&g_in_fifo);
|
||||
g_stream_inp = (struct stream *) fifo_remove_item(g_in_fifo);
|
||||
if (g_stream_inp != NULL)
|
||||
{
|
||||
g_bytes_in_fifo -= g_stream_inp->size;
|
||||
|
|
Loading…
Reference in New Issue