PDB: allow recursive iterator

This commit is contained in:
Martin Pulec
2013-03-26 13:11:53 +01:00
parent 8840089caa
commit f7d9fa3410
4 changed files with 31 additions and 28 deletions

View File

@@ -374,14 +374,15 @@ void audio_done(struct state_audio *s)
if(s->audio_network_device)
rtp_done(s->audio_network_device);
if(s->audio_participants) {
struct pdb_e *cp = pdb_iter_init(s->audio_participants);
pdb_iter_t it;
struct pdb_e *cp = pdb_iter_init(s->audio_participants, &it);
while (cp != NULL) {
struct pdb_e *item = NULL;
pdb_remove(s->audio_participants, cp->ssrc, &item);
cp = pdb_iter_next(s->audio_participants);
cp = pdb_iter_next(&it);
free(item);
}
pdb_iter_done(s->audio_participants);
pdb_iter_done(&it);
pdb_destroy(&s->audio_participants);
}
audio_export_destroy(s->exporter);
@@ -436,7 +437,8 @@ static void *audio_receiver_thread(void *arg)
timeout.tv_usec = 999999 / 59.94; /* audio goes almost always at the same rate
as video frames */
rtp_recv_r(s->audio_network_device, &timeout, ts);
cp = pdb_iter_init(s->audio_participants);
pdb_iter_t it;
cp = pdb_iter_init(s->audio_participants, &it);
while (cp != NULL) {
if(pbuf_data.buffer != NULL) {
@@ -460,9 +462,9 @@ static void *audio_receiver_thread(void *arg)
}
pbuf_remove(cp->playout_buffer, curr_time);
cp = pdb_iter_next(s->audio_participants);
cp = pdb_iter_next(&it);
}
pdb_iter_done(s->audio_participants);
pdb_iter_done(&it);
} else { /* NET_JACK */
#ifdef HAVE_JACK_TRANS
jack_receive(s->jack_connection, &pbuf_data);

View File

@@ -567,7 +567,8 @@ static void *receiver_thread(void *arg)
UNUSED(ret);
/* Decode and render for each participant in the conference... */
cp = pdb_iter_init(uv->participants);
pdb_iter_t it;
cp = pdb_iter_init(uv->participants, &it);
while (cp != NULL) {
if (tfrc_feedback_is_due(cp->tfrc_state, uv->curr_time)) {
debug_msg("tfrc rate %f\n",
@@ -642,9 +643,9 @@ static void *receiver_thread(void *arg)
}
pbuf_remove(cp->playout_buffer, uv->curr_time);
cp = pdb_iter_next(uv->participants);
cp = pdb_iter_next(&it);
}
pdb_iter_done(uv->participants);
pdb_iter_done(&it);
}
#ifdef SHARED_DECODER
@@ -1524,14 +1525,15 @@ cleanup:
if(uv->display_device)
display_done(uv->display_device);
if (uv->participants != NULL) {
struct pdb_e *cp = pdb_iter_init(uv->participants);
pdb_iter_t it;
struct pdb_e *cp = pdb_iter_init(uv->participants, &it);
while (cp != NULL) {
struct pdb_e *item = NULL;
pdb_remove(uv->participants, cp->ssrc, &item);
cp = pdb_iter_next(uv->participants);
cp = pdb_iter_next(&it);
free(item);
}
pdb_iter_done(uv->participants);
pdb_iter_done(&it);
pdb_destroy(&uv->participants);
}

View File

@@ -83,7 +83,6 @@ typedef struct s_pdb_node {
struct pdb {
pdb_node_t *root;
pdb_node_t *iter;
uint32_t magic;
int count;
};
@@ -248,7 +247,6 @@ struct pdb *pdb_init(void)
db->magic = PDB_MAGIC;
db->count = 0;
db->root = NULL;
db->iter = NULL;
}
return db;
}
@@ -364,27 +362,27 @@ int pdb_remove(struct pdb *db, uint32_t ssrc, struct pdb_e **item)
* Iterator functions
*/
struct pdb_e *pdb_iter_init(struct pdb *db)
struct pdb_e *pdb_iter_init(struct pdb *db, pdb_iter_t *it)
{
if (db->root == NULL) {
return NULL; /* The database is empty */
}
db->iter = pdb_min(db->root);
return db->iter->data;
*it = (pdb_node_t *) pdb_min(db->root);
return ((pdb_node_t *) *it)->data;
}
struct pdb_e *pdb_iter_next(struct pdb *db)
struct pdb_e *pdb_iter_next(pdb_iter_t *it)
{
assert(db->iter != NULL);
db->iter = pdb_successor(db->iter);
if (db->iter == NULL) {
assert(*it != NULL);
*it = (pdb_node_t *)pdb_successor((pdb_node_t *)*it);
if (*it == NULL) {
return NULL;
}
return db->iter->data;
return ((pdb_node_t *) *it)->data;
}
void pdb_iter_done(struct pdb *db)
void pdb_iter_done(pdb_iter_t *it)
{
db->iter = NULL;
*it = NULL;
}

View File

@@ -85,10 +85,11 @@ struct pdb_e *pdb_get(struct pdb *db, uint32_t ssrc);
*/
int pdb_remove(struct pdb *db, uint32_t ssrc, struct pdb_e **item);
typedef void *pdb_iter_t;
/*
* Iterator for the database. Supports only one accessor at once.
* Iterator for the database.
*/
struct pdb_e *pdb_iter_init(struct pdb *db);
struct pdb_e *pdb_iter_next(struct pdb *db);
void pdb_iter_done(struct pdb *db);
struct pdb_e *pdb_iter_init(struct pdb *db, pdb_iter_t *it);
struct pdb_e *pdb_iter_next(pdb_iter_t *it);
void pdb_iter_done(pdb_iter_t *it);