]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tvhdhomerun: lock tuners when in use
authorBen Fennema <fennema@google.com>
Wed, 25 Mar 2015 03:13:45 +0000 (20:13 -0700)
committerJaroslav Kysela <perex@perex.cz>
Wed, 25 Mar 2015 14:16:36 +0000 (15:16 +0100)
src/input/mpegts/tvhdhomerun/tvhdhomerun.c
src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c
src/input/mpegts/tvhdhomerun/tvhdhomerun_private.h

index 9eb24181575d4b055755dd25e927663bb3887709..6fae629bcc39ea178a68cde43d23c10882b310fe 100644 (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);
   }
index 795aa34cb7ca1f99c47c71e7d0c00784244d0498..b8bd705aeac0ae06a3669824a381cf5bb2e32e93 100644 (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);
index 35a99c0e1c8d9d6a75b59d34d61a53f1781979e6..962627ae2cae0244f5bd5569c9b94dae1d94962d 100644 (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 );