static int main_internal(int argc, char *argv[]) { #if defined(__WINDOWS__) /* Initialize network socket support. */ WORD wVersionRequested = MAKEWORD(2, 0); WSADATA wsaData; WSAStartup(wVersionRequested, &wsaData); #endif extract_appname(argv[0]); argv++; argc--; if (argc == 0) { return help(); } char *id_str = *argv++; argc--; if (contains(id_str, "help")) { return help(); } if (contains(id_str, "discover")) { if (argc < 1) { return discover_print(NULL); } else { return discover_print(argv[0]); } } /* Device object. */ hd = hdhomerun_device_create_from_str(id_str, NULL); if (!hd) { fprintf(stderr, "invalid device id: %s\n", id_str); return -1; } /* Device ID check. */ uint32_t device_id_requested = hdhomerun_device_get_device_id_requested(hd); if (!hdhomerun_discover_validate_device_id(device_id_requested)) { fprintf(stderr, "invalid device id: %08lX\n", (unsigned long)device_id_requested); } /* Connect to device and check model. */ const char *model = hdhomerun_device_get_model_str(hd); if (!model) { fprintf(stderr, "unable to connect to device\n"); hdhomerun_device_destroy(hd); return -1; } /* Command. */ int ret = main_cmd(argc, argv); /* Cleanup. */ hdhomerun_device_destroy(hd); /* Complete. */ return ret; }
bool HDHRStreamHandler::Open(void) { if (Connect()) { const char *model = hdhomerun_device_get_model_str(_hdhomerun_device); _tuner_types.clear(); if (QString(model).toLower().contains("cablecard")) { QString status_channel = "none"; hdhomerun_tuner_status_t t_status; if (hdhomerun_device_get_oob_status( _hdhomerun_device, NULL, &t_status) < 0) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to query Cable card OOB channel"); } else { status_channel = QString(t_status.channel); LOG(VB_RECORD, LOG_INFO, LOC + QString("Cable card OOB channel is '%1'") .arg(status_channel)); } if (status_channel == "none") { LOG(VB_RECORD, LOG_INFO, LOC + "Cable card is not present"); _tuner_types.push_back(DTVTunerType::kTunerTypeATSC); } else { LOG(VB_RECORD, LOG_INFO, LOC + "Cable card is present"); _tuner_types.push_back(DTVTunerType::kTunerTypeOCUR); } } else if (QString(model).toLower().contains("dvb")) { _tuner_types.push_back(DTVTunerType::kTunerTypeDVBT); _tuner_types.push_back(DTVTunerType::kTunerTypeDVBC); } else { _tuner_types.push_back(DTVTunerType::kTunerTypeATSC); } return true; } return false; }
bool HDHRDevice::openDevice() { mDeviceConnection = hdhomerun_device_create(mDeviceInfo.device_id, mDeviceInfo.ip_addr, mTunerIndex, NULL); if(!mDeviceConnection) return false; if(!mChannel) mChannel = new DTVChannel(dynamic_cast <SageTuner*> (this), mChannelName, NULL, 0); if(!mChannel) { hdhomerun_device_destroy(mDeviceConnection); mDeviceConnection = NULL; return false; } mDeviceModel = hdhomerun_device_get_model_str(mDeviceConnection); flog( "Native.log", "HDHomeRun Device(Tuner:\"%s\" Model:%s) is open\r\n", mChannelName, mDeviceModel ); return true; }
bool HDHRStreamHandler::Open(void) { if (Connect()) { const char *model = hdhomerun_device_get_model_str(_hdhomerun_device); _tuner_types.clear(); if (QString(model).toLower().contains("dvb")) { _tuner_types.push_back(DTVTunerType::kTunerTypeDVBT); _tuner_types.push_back(DTVTunerType::kTunerTypeDVBC); } else { _tuner_types.push_back(DTVTunerType::kTunerTypeATSC); } return true; } return false; }
static void tvhdhomerun_device_create(struct hdhomerun_discover_device_t *dInfo) { tvhdhomerun_device_t *hd = calloc(1, sizeof(tvhdhomerun_device_t)); htsmsg_t *conf = NULL, *feconf = NULL; char uhex[UUID_HEX_SIZE]; int j, save = 0; struct hdhomerun_device_t *hdhomerun_tuner; dvb_fe_type_t type = DVB_TYPE_C; tvhdhomerun_device_calc_uuid(uhex, dInfo->device_id); hdhomerun_tuner = hdhomerun_device_create(dInfo->device_id, dInfo->ip_addr, 0, NULL); { const char *deviceModel = hdhomerun_device_get_model_str(hdhomerun_tuner); if(deviceModel != NULL) { hd->hd_info.deviceModel = strdup(deviceModel); } hdhomerun_device_destroy(hdhomerun_tuner); } conf = hts_settings_load("input/tvhdhomerun/adapters/%s", uhex); if ( conf != NULL ) { const char *override_type = htsmsg_get_str(conf, "fe_override"); if ( override_type != NULL) { if ( !strcmp(override_type, "ATSC" ) ) override_type = "ATSC-T"; type = dvb_str2type(override_type); if ( ! ( type == DVB_TYPE_C || type == DVB_TYPE_T || type == DVB_TYPE_ATSC_T || type == DVB_TYPE_ATSC_C ) ) { type = DVB_TYPE_C; } } } else { if (strstr(hd->hd_info.deviceModel, "_atsc")) type = DVB_TYPE_ATSC_T; } hd->hd_override_type = strdup(dvb_type2str(type)); tvhinfo(LS_TVHDHOMERUN, "Using Network type : %s", hd->hd_override_type); /* some sane defaults */ hd->hd_fullmux_ok = 1; hd->hd_pids_len = 127; hd->hd_pids_max = 32; hd->hd_pids_deladd = 1; if (!tvh_hardware_create0((tvh_hardware_t*)hd, &tvhdhomerun_device_class, uhex, conf)) return; TAILQ_INIT(&hd->hd_frontends); /* we may check if uuid matches, but the SHA hash should be enough */ if (hd->hd_info.uuid) free(hd->hd_info.uuid); char fName[128]; snprintf(fName, 128, "HDHomeRun(%08X)",dInfo->device_id); memset(&hd->hd_info.ip_address, 0, sizeof(hd->hd_info.ip_address)); hd->hd_info.ip_address.ss_family = AF_INET; ((struct sockaddr_in *)&hd->hd_info.ip_address)->sin_addr.s_addr = htonl(dInfo->ip_addr); hd->hd_info.uuid = strdup(uhex); hd->hd_info.friendlyname = strdup(fName); if (conf) feconf = htsmsg_get_map(conf, "frontends"); save = !conf || !feconf; for (j = 0; j < dInfo->tuner_count; ++j) { if (tvhdhomerun_frontend_create(hd, dInfo, feconf, type, j)) { tvhinfo(LS_TVHDHOMERUN, "Created frontend %08X tuner %d", dInfo->device_id, j); } else { tvherror(LS_TVHDHOMERUN, "Unable to create frontend-device. ( %08x-%d )", dInfo->device_id,j); } } if (save) tvhdhomerun_device_changed(hd); htsmsg_destroy(conf); }
int channelscan_detect(struct hdhomerun_channelscan_t *scan, struct hdhomerun_channelscan_result_t *result) { scan->scanned_channels++; /* Find lock. */ int ret = channelscan_find_lock(scan, result->frequency, result); if (ret <= 0) { return ret; } if (!result->status.lock_supported) { return 1; } /* Detect programs. */ result->program_count = 0; uint64_t timeout; if (strstr(hdhomerun_device_get_model_str(scan->hd), "atsc")) { timeout = getcurrenttime() + 4000; } else { timeout = getcurrenttime() + 10000; } uint64_t complete_time = getcurrenttime() + 1000; while (1) { bool_t changed, incomplete; ret = channelscan_detect_programs(scan, result, &changed, &incomplete); if (ret <= 0) { return ret; } if (changed) { complete_time = getcurrenttime() + 1000; } if (!incomplete && (getcurrenttime() >= complete_time)) { break; } if (getcurrenttime() >= timeout) { break; } msleep_approx(250); } /* Lock => skip overlapping channels. */ uint32_t max_next_frequency = result->frequency - 5500000; while (1) { if (!scan->next_channel) { break; } if (hdhomerun_channel_entry_frequency(scan->next_channel) <= max_next_frequency) { break; } scan->next_channel = hdhomerun_channel_list_prev(scan->channel_list, scan->next_channel); } /* Success. */ return 1; }
static void tvhdhomerun_device_create(struct hdhomerun_discover_device_t *dInfo) { tvhdhomerun_device_t *hd = calloc(1, sizeof(tvhdhomerun_device_t)); htsmsg_t *conf = NULL, *feconf = NULL; tvh_uuid_t uuid; int j, save = 0; struct hdhomerun_device_t *hdhomerun_tuner; dvb_fe_type_t type = DVB_TYPE_C; struct in_addr ip_addr; tvhdhomerun_device_calc_uuid(&uuid, dInfo->device_id); hdhomerun_tuner = hdhomerun_device_create(dInfo->device_id, dInfo->ip_addr, 0, NULL); { const char *deviceModel = hdhomerun_device_get_model_str(hdhomerun_tuner); if(deviceModel != NULL) { hd->hd_info.deviceModel = strdup(deviceModel); } hdhomerun_device_destroy(hdhomerun_tuner); } conf = hts_settings_load("input/tvhdhomerun/adapters/%s", uuid.hex); if ( conf != NULL ) { const char *override_type = htsmsg_get_str(conf, "fe_override"); if ( override_type != NULL) { type = dvb_str2type(override_type); if ( ! ( type == DVB_TYPE_C || type == DVB_TYPE_T || type == DVB_TYPE_ATSC ) ) { type = DVB_TYPE_C; } } } else { if (strstr(hd->hd_info.deviceModel, "_atsc")) type = DVB_TYPE_ATSC; } hd->hd_override_type = strdup(dvb_type2str(type)); tvhlog(LOG_INFO, "tvheadend","Using Network type : %s", hd->hd_override_type); /* some sane defaults */ hd->hd_fullmux_ok = 1; hd->hd_pids_len = 127; hd->hd_pids_max = 32; hd->hd_pids_deladd = 1; if (!tvh_hardware_create0((tvh_hardware_t*)hd, &tvhdhomerun_device_class, uuid.hex, conf)) { free(hd); return; } TAILQ_INIT(&hd->hd_frontends); /* we may check if uuid matches, but the SHA hash should be enough */ if (hd->hd_info.uuid) free(hd->hd_info.uuid); char fName[128]; snprintf(fName, 128, "HDHomeRun(%08X)",dInfo->device_id); ip_addr.s_addr = htonl(dInfo->ip_addr); 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; for (j = 0; j < dInfo->tuner_count; ++j) { if (tvhdhomerun_frontend_create(hd, dInfo, feconf, type, j)) { tvhlog(LOG_INFO, "tvhdhomerun", "Created frontend %08X tuner %d", dInfo->device_id, j); } else { tvhlog(LOG_ERR, "tvhdhomerun", "Unable to create frontend-device. ( %08x-%d )", dInfo->device_id,j); } } if (save) tvhdhomerun_device_save(hd); htsmsg_destroy(conf); }