tvhdhomerun: lock tuners when in use

This commit is contained in:
Ben Fennema 2015-03-24 20:13:45 -07:00 committed by Jaroslav Kysela
parent 266b28cfd1
commit 1ccdcd33a2
3 changed files with 37 additions and 28 deletions

View file

@ -48,7 +48,7 @@ tvhdhomerun_device_class_get_childs ( idnode_t *in )
}
typedef struct tvhdhomerun_discovery {
TAILQ_ENTRY(tvhdhomerun_discovery) disc_link;
TAILQ_ENTRY(tvhdhomerun_discovery) disc_link;
} tvhdhomerun_discovery_t;
TAILQ_HEAD(tvhdhomerun_discovery_queue, tvhdhomerun_discovery);
@ -175,7 +175,7 @@ const idclass_t tvhdhomerun_device_class =
.notify = tvhdhomerun_device_class_override_notify,
.list = tvhdhomerun_device_class_override_enum,
.off = offsetof(tvhdhomerun_device_t, hd_type),
},
},
{}
}
};
@ -315,7 +315,7 @@ static void tvhdhomerun_device_create(struct hdhomerun_discover_device_t *dInfo)
hd->hd_info.ip_address = strdup(inet_ntoa(ip_addr));
hd->hd_info.uuid = strdup(uuid.hex);
hd->hd_info.friendlyname = strdup(fName);
if (conf)
feconf = htsmsg_get_map(conf, "frontends");
save = !conf || !feconf;
@ -327,7 +327,7 @@ static void tvhdhomerun_device_create(struct hdhomerun_discover_device_t *dInfo)
tvhlog(LOG_ERR, "tvhdhomerun", "Unable to create frontend-device. ( %08x-%d )", dInfo->device_id,j);
}
}
if (save)
tvhdhomerun_device_save(hd);
@ -360,7 +360,7 @@ tvhdhomerun_device_discovery( void )
tvhdhomerun_device_create(cDev);
}
}
}
}
}
}
@ -403,7 +403,7 @@ tvhdhomerun_device_destroy( tvhdhomerun_device_t *hd )
gtimer_disarm(&hd->hd_destroy_timer);
tvhlog(LOG_INFO, "tvhdhomerun", "Releaseing locks for devices");
tvhlog(LOG_INFO, "tvhdhomerun", "Releasing locks for devices");
while ((lfe = TAILQ_FIRST(&hd->hd_frontends)) != NULL) {
tvhdhomerun_frontend_delete(lfe);
}

View file

@ -75,7 +75,7 @@ tvhdhomerun_frontend_input_thread ( void *aux )
tvhpoll_event_t ev[2];
tvhpoll_t *efd;
tvhdebug("tvhdhomerun", "starting input thread");
tvhdebug("tvhdhomerun", "starting input thread");
/* Get MMI */
pthread_mutex_lock(&hfe->hf_input_thread_mutex);
@ -85,7 +85,7 @@ tvhdhomerun_frontend_input_thread ( void *aux )
pthread_mutex_unlock(&hfe->hf_input_thread_mutex);
if (mmi == NULL) return NULL;
tvhdebug("tvhdhomerun", "opening client socket");
tvhdebug("tvhdhomerun", "opening client socket");
/* One would like to use libhdhomerun for the streaming details,
* but that library uses threads on its own and the socket is put
@ -157,7 +157,7 @@ tvhdhomerun_frontend_input_thread ( void *aux )
(unsigned int)(local_ip >> 8) & 0xFF,
(unsigned int)(local_ip >> 0) & 0xFF,
ntohs(sock_addr.sin_port));
tvhdebug("tvhdhomerun", "setting target to: %s", target);
tvhdebug("tvhdhomerun", "setting target to: %s", target);
pthread_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
r = hdhomerun_device_set_tuner_target(hfe->hf_hdhomerun_tuner, target);
pthread_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
@ -269,7 +269,7 @@ tvhdhomerun_frontend_monitor_cb( void *aux )
hfe->hf_status = SIGNAL_GOOD;
else
hfe->hf_status = SIGNAL_NONE;
/* Get current mux */
mm = mmi->mmi_mux;
@ -372,6 +372,7 @@ static int tvhdhomerun_frontend_tune(tvhdhomerun_frontend_t *hfe, mpegts_mux_ins
char channel_buf[64];
uint32_t symbol_rate = 0;
int res;
char *perror;
/* resolve the modulation type */
switch (dmc->dmc_fe_type) {
@ -396,15 +397,21 @@ static int tvhdhomerun_frontend_tune(tvhdhomerun_frontend_t *hfe, mpegts_mux_ins
}
tvhlog(LOG_INFO, "tvhdhomerun", "tuning to %s", channel_buf);
pthread_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
res = hdhomerun_device_tuner_lockkey_request(hfe->hf_hdhomerun_tuner, &perror);
if(res < 1) {
pthread_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
tvhlog(LOG_ERR, "tvhdhomerun", "failed to acquire lockkey: %s", perror);
return SM_CODE_TUNING_FAILED;
}
res = hdhomerun_device_set_tuner_channel(hfe->hf_hdhomerun_tuner, channel_buf);
pthread_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
if(res < 1) {
tvhlog(LOG_ERR, "tvhdhomerun", "failed to tune to %s", channel_buf);
return SM_CODE_TUNING_FAILED;
tvhlog(LOG_ERR, "tvhdhomerun", "failed to tune to %s", channel_buf);
return SM_CODE_TUNING_FAILED;
}
hfe->hf_status = SIGNAL_NONE;
/* start the monitoring */
@ -421,7 +428,7 @@ tvhdhomerun_frontend_start_mux
tvhdhomerun_frontend_t *hfe = (tvhdhomerun_frontend_t*)mi;
int res, r;
char buf1[256], buf2[256];
mi->mi_display_name(mi, buf1, sizeof(buf1));
mpegts_mux_nice_name(mmi->mmi_mux, buf2, sizeof(buf2));
tvhdebug("tvhdhomerun", "%s - starting %s", buf1, buf2);
@ -445,7 +452,7 @@ tvhdhomerun_frontend_stop_mux
{
tvhdhomerun_frontend_t *hfe = (tvhdhomerun_frontend_t*)mi;
char buf1[256], buf2[256];
mi->mi_display_name(mi, buf1, sizeof(buf1));
mpegts_mux_nice_name(mmi->mmi_mux, buf2, sizeof(buf2));
tvhdebug("tvhdhomerun", "%s - stopping %s", buf1, buf2);
@ -459,6 +466,8 @@ tvhdhomerun_frontend_stop_mux
tvhtrace("tvhdhomerun", "%s - input thread stopped", buf1);
}
hdhomerun_device_tuner_lockkey_release(hfe->hf_hdhomerun_tuner);
hfe->hf_locked = 0;
hfe->hf_status = 0;
hfe->hf_ready = 0;
@ -505,7 +514,7 @@ tvhdhomerun_frontend_network_list ( mpegts_input_t *mi )
else if (hfe->hf_type == DVB_TYPE_C)
idc = &dvb_network_dvbc_class;
else if (hfe->hf_type == DVB_TYPE_ATSC)
idc = &dvb_network_atsc_class;
idc = &dvb_network_atsc_class;
else
return NULL;
@ -591,7 +600,7 @@ tvhdhomerun_frontend_delete ( tvhdhomerun_frontend_t *hfe )
gtimer_disarm(&hfe->hf_monitor_timer);
// hdhomerun_device_tuner_lockkey_release(hfe->hf_hdhomerun_tuner);
hdhomerun_device_tuner_lockkey_release(hfe->hf_hdhomerun_tuner);
hdhomerun_device_destroy(hfe->hf_hdhomerun_tuner);
/* Ensure we're stopped */
@ -602,12 +611,12 @@ tvhdhomerun_frontend_delete ( tvhdhomerun_frontend_t *hfe )
pthread_mutex_destroy(&hfe->hf_input_thread_mutex);
pthread_mutex_destroy(&hfe->hf_hdhomerun_device_mutex);
/* Finish */
mpegts_input_delete((mpegts_input_t*)hfe, 0);
}
tvhdhomerun_frontend_t *
tvhdhomerun_frontend_t *
tvhdhomerun_frontend_create(tvhdhomerun_device_t *hd, struct hdhomerun_discover_device_t *discover_info, htsmsg_t *conf, dvb_fe_type_t type, unsigned int frontend_number )
{
const idclass_t *idc;
@ -658,7 +667,7 @@ tvhdhomerun_frontend_create(tvhdhomerun_device_t *hd, struct hdhomerun_discover_
if (!hfe->mi_name ||
(strncmp(hfe->mi_name, "HDHomeRun ", 7) == 0 &&
strstr(hfe->mi_name, " Tuner ") &&
strstr(hfe->mi_name, " #"))) {
strstr(hfe->mi_name, " #"))) {
char lname[256];
snprintf(lname, sizeof(lname), "HDHomeRun %s Tuner #%i (%s)",
dvb_type2str(type), hfe->hf_tunerNumber, hd->hd_info.ip_address);

View file

@ -51,7 +51,7 @@ struct tvhdhomerun_device
* Adapter info
*/
tvhdhomerun_device_info_t hd_info;
/*
* Frontends
*/
@ -61,14 +61,14 @@ struct tvhdhomerun_device
Flags...
*/
int hd_fullmux_ok;
int hd_pids_max;
int hd_pids_len;
int hd_pids_deladd;
dvb_fe_type_t hd_type;
char *hd_override_type;
};
#define HDHOMERUN_MAX_PIDS 32
@ -88,7 +88,7 @@ struct tvhdhomerun_frontend
* Frontend info
*/
int hf_tunerNumber;
dvb_fe_type_t hf_type;
dvb_fe_type_t hf_type;
// libhdhomerun objects.
struct hdhomerun_device_t *hf_hdhomerun_tuner;
@ -117,19 +117,19 @@ struct tvhdhomerun_frontend
gtimer_t hf_monitor_timer;
mpegts_mux_instance_t *hf_mmi;
};
/*
* Methods
*/
void tvhdhomerun_device_init ( void );
void tvhdhomerun_device_done ( void );
void tvhdhomerun_device_destroy ( tvhdhomerun_device_t *sd );
void tvhdhomerun_device_destroy_later( tvhdhomerun_device_t *sd, int after_ms );
tvhdhomerun_frontend_t *
tvhdhomerun_frontend_t *
tvhdhomerun_frontend_create( tvhdhomerun_device_t *hd, struct hdhomerun_discover_device_t *discover_info, htsmsg_t *conf, dvb_fe_type_t type, unsigned int frontend_number );
void tvhdhomerun_frontend_delete ( tvhdhomerun_frontend_t *lfe );