Add support for cloning of DVB adapter configuration

This commit is contained in:
Andreas Öman 2008-05-02 06:58:00 +00:00
parent a1ade3232a
commit 4afc4092a7
3 changed files with 134 additions and 2 deletions

View file

@ -165,7 +165,7 @@ ajax_adaptereditor(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
tcp_queue_t *tq = &hr->hr_tq;
th_dvb_adapter_t *tda;
th_dvb_adapter_t *tda, *tda2;
const char *s;
if(remain == NULL || (tda = dvb_adapter_find_by_identifier(remain)) == NULL)
@ -217,10 +217,40 @@ ajax_adaptereditor(http_connection_t *hc, http_reply_t *hr,
tcp_qprintf(tq, "</div>");
tcp_qprintf(tq, "<div style=\"float: left; width:55%%\">");
tcp_qprintf(tq, "<div style=\"overflow: auto; width:100%%\">");
ajax_a_jsfuncf(tq, "Rename adapter...",
"dvb_adapter_rename('%s', '%s');",
tda->tda_identifier, tda->tda_displayname);
tcp_qprintf(tq, "</div>");
/* Clone adapter */
tcp_qprintf(tq, "<div style=\"overflow: auto; width:100%%\">");
tcp_qprintf(tq,
"<select class=\"textinput\" "
"onChange=\"new Ajax.Request('/ajax/dvbadapterclone/%s', "
"{parameters: { source: this.value }})\">",
tda->tda_identifier);
tcp_qprintf(tq, "<option value=\"n\">Clone settings from adapter:</option>");
TAILQ_FOREACH(tda2, &dvb_adapters, tda_global_link) {
if(tda2 == tda || tda2->tda_type != tda->tda_type)
continue;
tcp_qprintf(tq, "<option value=\"%s\">%s (%s)</option>",
tda2->tda_identifier, tda2->tda_displayname,
tda2->tda_rootpath ?: "not present");
}
tcp_qprintf(tq, "</select></div>");
tcp_qprintf(tq, "</div>");
tcp_qprintf(tq, "</div>");
tcp_qprintf(tq, "</div>");
/* Muxes and transports */
@ -872,6 +902,39 @@ ajax_dvbadapteraddnetwork(http_connection_t *hc, http_reply_t *hr,
return 0;
}
/**
* Clone adapter
*/
static int
ajax_dvbadapterclone(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
tcp_queue_t *tq = &hr->hr_tq;
th_dvb_adapter_t *src, *dst;
const char *s;
if(remain == NULL || (dst = dvb_adapter_find_by_identifier(remain)) == NULL)
return HTTP_STATUS_NOT_FOUND;
if((s = http_arg_get(&hc->hc_req_args, "source")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if((src = dvb_adapter_find_by_identifier(s)) == NULL)
return HTTP_STATUS_BAD_REQUEST;
printf("Clone from %s to %s\n", src->tda_displayname, dst->tda_displayname);
dvb_tda_clone(dst, src);
tcp_qprintf(tq, "new Ajax.Updater('dvbadaptereditor', "
"'/ajax/dvbadaptereditor/%s', "
"{method: 'get', evalScripts: true});\r\n",
dst->tda_identifier);
http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0);
return 0;
}
/**
*
@ -899,5 +962,7 @@ ajax_config_dvb_init(void)
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/dvbadapteraddnetwork", NULL, ajax_dvbadapteraddnetwork,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/dvbadapterclone", NULL, ajax_dvbadapterclone,
AJAX_ACCESS_CONFIG);
}

65
dvb.c
View file

@ -692,3 +692,68 @@ dvb_source_name(th_transport_t *t)
return buf;
}
/**
*
*/
void
dvb_tda_clone(th_dvb_adapter_t *dst, th_dvb_adapter_t *src)
{
th_dvb_mux_instance_t *tdmi_src, *tdmi_dst;
th_transport_t *t_src, *t_dst;
th_stream_t *st_src, *st_dst;
while((tdmi_dst = LIST_FIRST(&dst->tda_muxes)) != NULL)
dvb_mux_destroy(tdmi_dst);
LIST_FOREACH(tdmi_src, &src->tda_muxes, tdmi_adapter_link) {
tdmi_dst = dvb_mux_create(dst,
tdmi_src->tdmi_fe_params,
tdmi_src->tdmi_polarisation,
tdmi_src->tdmi_switchport,
0,
tdmi_src->tdmi_transport_stream_id,
tdmi_src->tdmi_network);
LIST_FOREACH(t_src, &tdmi_src->tdmi_transports, tht_mux_link) {
t_dst = dvb_find_transport(tdmi_dst,
t_src->tht_dvb_service_id,
t_src->tht_pmt,
NULL);
t_dst->tht_pcr_pid = t_src->tht_pcr_pid;
t_dst->tht_disabled = t_src->tht_disabled;
t_dst->tht_servicetype = t_src->tht_servicetype;
t_dst->tht_scrambled = t_src->tht_scrambled;
if(t_src->tht_provider != NULL)
t_dst->tht_provider = strdup(t_src->tht_provider);
if(t_src->tht_servicename != NULL)
t_dst->tht_servicename = strdup(t_src->tht_servicename);
if(t_src->tht_channelname != NULL)
t_dst->tht_channelname = strdup(t_src->tht_channelname);
if(t_src->tht_channel != NULL)
transport_set_channel(t_dst, t_src->tht_channel->ch_name);
LIST_FOREACH(st_src, &t_src->tht_streams, st_link) {
st_dst = transport_add_stream(t_dst,
st_src->st_pid,
st_src->st_type);
st_dst->st_tb = (AVRational){1, 90000};
memcpy(st_dst->st_lang, st_src->st_lang, 4);
st_dst->st_frame_duration = st_src->st_frame_duration;
st_dst->st_caid = st_src->st_caid;
}
}
dvb_tdmi_save(tdmi_dst);
}
dvb_tda_save(dst);
}

2
dvb.h
View file

@ -68,4 +68,6 @@ void dvb_mux_destroy(th_dvb_mux_instance_t *tdmi);
void tdmi_stop(th_dvb_mux_instance_t *tdmi);
void dvb_tda_clone(th_dvb_adapter_t *dst, th_dvb_adapter_t *src);
#endif /* DVB_H_ */