mpegts: further updates starting to get shape back

Now added a LIST of active muxes, for IPTV this will be a list but
generally speaking will not be too important for others this will
almost certainly only ever contain one entry.

However I may still rework this as I work my way back through the code.
This commit is contained in:
Adam Sutton 2013-04-27 21:07:56 +01:00
parent 024d68416e
commit 9cd7a53b9f
4 changed files with 47 additions and 17 deletions

View file

@ -350,7 +350,8 @@ struct mpegts_input
mpegts_network_t *mi_network; // TODO: this may need altering for DVB-S
//mpegts_mux_instance_t *mi_mux_current;
LIST_HEAD(,mpegts_mux_instance) mi_mux_active;
/*
* Input processing
@ -363,8 +364,6 @@ struct mpegts_input
int mi_bytes;
struct mpegts_table_feed_queue mi_table_feed;
pthread_cond_t mi_table_feed_cond; // Bound to mi_delivery_mutex
@ -376,10 +375,12 @@ struct mpegts_input
* Functions
*/
int (*mi_start_mux) (mpegts_input_t*,mpegts_mux_instance_t*);
void (*mi_stop_mux) (mpegts_input_t*);
void (*mi_open_service) (mpegts_input_t*,mpegts_service_t*);
void (*mi_close_service) (mpegts_input_t*,mpegts_service_t*);
int (*mi_start_mux) (mpegts_input_t*,mpegts_mux_instance_t*);
void (*mi_stop_mux) (mpegts_input_t*);
void (*mi_open_service) (mpegts_input_t*,mpegts_service_t*);
void (*mi_close_service) (mpegts_input_t*,mpegts_service_t*);
int (*mi_is_free) (mpegts_input_t*);
int (*mi_current_weight) (mpegts_input_t*);
};
#endif /* __TVH_MPEGTS_H__ */
@ -411,6 +412,10 @@ size_t mpegts_input_recv_packets
void *mpegts_input_table_thread ( void *aux );
int mpegts_input_is_free ( mpegts_input_t *mi );
int mpegts_input_current_weight ( mpegts_input_t *mi );
void mpegts_table_dispatch
(mpegts_table_t *mt, const uint8_t *sec, int r);
void mpegts_table_release

View file

@ -20,6 +20,7 @@
#include "tsdemux.h"
#include "packet.h"
#include "streaming.h"
#include "subscriptions.h"
#include "atomic.h"
#include <pthread.h>
@ -177,6 +178,28 @@ mpegts_input_table_thread ( void *aux )
return NULL;
}
int
mpegts_input_is_free ( mpegts_input_t *mi )
{
return LIST_FIRST(&mi->mi_mux_active) == NULL;
}
int
mpegts_input_current_weight ( mpegts_input_t *mi )
{
const service_t *s;
const th_subscription_t *ths;
int w = 0;
pthread_mutex_lock(&mi->mi_delivery_mutex);
LIST_FOREACH(s, &mi->mi_transports, s_active_link) {
LIST_FOREACH(ths, &s->s_subscriptions, ths_service_link)
w = MAX(w, ths->ths_weight);
}
pthread_mutex_unlock(&mi->mi_delivery_mutex);
return w;
}
mpegts_input_t*
mpegts_input_create0 ( const char *uuid )
{

View file

@ -120,24 +120,24 @@ mpegts_mux_start ( mpegts_mux_t *mm, const char *reason, int weight )
// TODO: don't like this is unbounded, if for some reason mi_start_mux()
// constantly fails this will lock
while (1) {
/* Find free input */
LIST_FOREACH(mmi, &mm->mm_instances, mmi_mux_link)
if (!mmi->mmi_tune_failed /*TODO&&
!mmi->mmi_input->mi_mux_current*/)
if (!mmi->mmi_tune_failed &&
!mmi->mmi_input->mi_is_free(mmi->mmi_input));
break;
printf("free input = %p\n", mmi);
printf("free input ?= %p\n", mmi);
/* Try and remove a lesser instance */
if (!mmi) {
LIST_FOREACH(mmi, &mm->mm_instances, mmi_mux_link) {
/* Bad */
/* Bad - skip */
if (mmi->mmi_tune_failed)
continue;
/* Found */
if (100 < weight)//TODO:mpegts_mux_instance_weight(mmi->mmi_input->mi_mux_current) < weight)
if (weight > mmi->mmi_input->mi_current_weight(mmi->mmi_input))
break;
}

View file

@ -224,10 +224,12 @@ tsfile_input_create ( void )
/* Create object */
mi = mpegts_input_create0(NULL);
mi->mi_start_mux = tsfile_input_start_mux;
mi->mi_stop_mux = tsfile_input_stop_mux;
mi->mi_open_service = tsfile_input_open_service;
mi->mi_close_service = tsfile_input_close_service;
mi->mi_start_mux = tsfile_input_start_mux;
mi->mi_stop_mux = tsfile_input_stop_mux;
mi->mi_open_service = tsfile_input_open_service;
mi->mi_close_service = tsfile_input_close_service;
mi->mi_is_free = mpegts_input_is_free;
mi->mi_current_weight = mpegts_input_current_weight;
/* Start table thread */
pthread_create(&tid, NULL, mpegts_input_table_thread, mi);