Skip to content
Browse files

Resync to SiliconDust libhdhomerun 20121107beta1

Fixes #11281.

Conflicts:

	mythtv/external/libhdhomerun/Makefile

Signed-off-by: Daniel Thor Kristjansson <danielk@cuymedia.net>
  • Loading branch information...
1 parent 84de78c commit 14772544081f0186ae8681acb73d5cdb2bf4df1b @garybuhrmaster garybuhrmaster committed with daniel-kristjansson Dec 8, 2012
View
2 mythtv/external/libhdhomerun/.gitignore
@@ -1,4 +1,4 @@
-Makefile
+!Makefile
Makefile.app
Makefile.lib
mythhdhomerun_config
View
14 mythtv/external/libhdhomerun/hdhomerun_channels.c
@@ -79,6 +79,16 @@ static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_eu_c
{ 0, 0, 0, 0}
};
+/* KR cable channels. */
+static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_kr_cable[] = {
+ { 2, 4, 57000000, 6000000},
+ { 5, 6, 79000000, 6000000},
+ { 7, 13, 177000000, 6000000},
+ { 14, 22, 123000000, 6000000},
+ { 23, 153, 219000000, 6000000},
+ { 0, 0, 0, 0}
+};
+
/* US antenna channels. */
static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_us_bcast[] = {
{ 2, 4, 57000000, 6000000},
@@ -135,6 +145,8 @@ static const struct hdhomerun_channelmap_record_t hdhomerun_channelmap_table[] =
{"tw-bcast", hdhomerun_channelmap_range_us_bcast, "tw-bcast", "TW"},
{"tw-cable", hdhomerun_channelmap_range_us_cable, "tw-cable", "TW"},
+ {"kr-bcast", hdhomerun_channelmap_range_us_bcast, "kr-bcast", "KR"},
+ {"kr-cable", hdhomerun_channelmap_range_kr_cable, "kr-cable", "KR"},
{"us-bcast", hdhomerun_channelmap_range_us_bcast, "us-bcast", "CA US"},
{"us-cable", hdhomerun_channelmap_range_us_cable, "us-cable us-hrc us-irc", "CA PA US"},
{"us-hrc", hdhomerun_channelmap_range_us_hrc , "us-cable us-hrc us-irc", "CA PA US"},
@@ -334,7 +346,7 @@ static void hdhomerun_channel_list_build_range(struct hdhomerun_channel_list_t *
entry->channel_number = channel_number;
entry->frequency = range->frequency + ((uint32_t)(channel_number - range->channel_range_start) * range->spacing);
entry->frequency = hdhomerun_channel_frequency_round_normal(entry->frequency);
- sprintf(entry->name, "%s:%u", channelmap, entry->channel_number);
+ hdhomerun_sprintf(entry->name, entry->name + sizeof(entry->name), "%s:%u", channelmap, entry->channel_number);
hdhomerun_channel_list_build_insert(channel_list, entry);
}
View
15 mythtv/external/libhdhomerun/hdhomerun_channelscan.c
@@ -67,7 +67,7 @@ static int channelscan_find_lock(struct hdhomerun_channelscan_t *scan, uint32_t
{
/* Set channel. */
char channel_str[64];
- sprintf(channel_str, "auto:%ld", (unsigned long)frequency);
+ hdhomerun_sprintf(channel_str, channel_str + sizeof(channel_str), "auto:%u", (unsigned int)frequency);
int ret = hdhomerun_device_set_tuner_channel(scan->hd, channel_str);
if (ret <= 0) {
@@ -175,8 +175,7 @@ static int channelscan_detect_programs(struct hdhomerun_channelscan_t *scan, str
struct hdhomerun_channelscan_program_t program;
memset(&program, 0, sizeof(program));
- strncpy(program.program_str, line, sizeof(program.program_str));
- program.program_str[sizeof(program.program_str) - 1] = 0;
+ hdhomerun_sprintf(program.program_str, program.program_str + sizeof(program.program_str), "%s", line);
unsigned int program_number;
unsigned int virtual_major, virtual_minor;
@@ -237,8 +236,10 @@ int channelscan_advance(struct hdhomerun_channelscan_t *scan, struct hdhomerun_c
/* Combine channels with same frequency. */
result->frequency = hdhomerun_channel_entry_frequency(entry);
- strncpy(result->channel_str, hdhomerun_channel_entry_name(entry), sizeof(result->channel_str) - 1);
- result->channel_str[sizeof(result->channel_str) - 1] = 0;
+
+ char *ptr = result->channel_str;
+ char *end = result->channel_str + sizeof(result->channel_str);
+ hdhomerun_sprintf(ptr, end, hdhomerun_channel_entry_name(entry));
while (1) {
entry = hdhomerun_channel_list_prev(scan->channel_list, entry);
@@ -252,8 +253,8 @@ int channelscan_advance(struct hdhomerun_channelscan_t *scan, struct hdhomerun_c
break;
}
- char *ptr = strchr(result->channel_str, 0);
- sprintf(ptr, ", %s", hdhomerun_channel_entry_name(entry));
+ ptr = strchr(ptr, 0);
+ hdhomerun_sprintf(ptr, end, ", %s", hdhomerun_channel_entry_name(entry));
}
return 1;
View
14 mythtv/external/libhdhomerun/hdhomerun_config.c
@@ -93,8 +93,8 @@ static bool_t contains(const char *arg, const char *cmpstr)
static uint32_t parse_ip_addr(const char *str)
{
- unsigned long a[4];
- if (sscanf(str, "%lu.%lu.%lu.%lu", &a[0], &a[1], &a[2], &a[3]) != 4) {
+ unsigned int a[4];
+ if (sscanf(str, "%u.%u.%u.%u", &a[0], &a[1], &a[2], &a[3]) != 4) {
return 0;
}
@@ -126,8 +126,8 @@ static int discover_print(char *target_ip_str)
int index;
for (index = 0; index < count; index++) {
struct hdhomerun_discover_device_t *result = &result_list[index];
- printf("hdhomerun device %08lX found at %u.%u.%u.%u\n",
- (unsigned long)result->device_id,
+ printf("hdhomerun device %08X found at %u.%u.%u.%u\n",
+ (unsigned int)result->device_id,
(unsigned int)(result->ip_addr >> 24) & 0x0FF, (unsigned int)(result->ip_addr >> 16) & 0x0FF,
(unsigned int)(result->ip_addr >> 8) & 0x0FF, (unsigned int)(result->ip_addr >> 0) & 0x0FF
);
@@ -303,8 +303,8 @@ static int cmd_scan(const char *tuner_str, const char *filename)
break;
}
- cmd_scan_printf(fp, "SCANNING: %lu (%s)\n",
- (unsigned long)result.frequency, result.channel_str
+ cmd_scan_printf(fp, "SCANNING: %u (%s)\n",
+ (unsigned int)result.frequency, result.channel_str
);
ret = hdhomerun_device_channelscan_detect(hd, &result);
@@ -671,7 +671,7 @@ static int main_internal(int argc, char *argv[])
/* 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);
+ fprintf(stderr, "invalid device id: %08X\n", (unsigned int)device_id_requested);
}
/* Connect to device and check model. */
View
12 mythtv/external/libhdhomerun/hdhomerun_control.c
@@ -368,8 +368,16 @@ int hdhomerun_control_upgrade(struct hdhomerun_control_sock_t *cs, FILE *upgrade
{
struct hdhomerun_pkt_t *tx_pkt = &cs->tx_pkt;
struct hdhomerun_pkt_t *rx_pkt = &cs->rx_pkt;
+ bool_t upload_delay = FALSE;
uint32_t sequence = 0;
+ /* Special case detection. */
+ char *version_str;
+ int ret = hdhomerun_control_get(cs, "/sys/version", &version_str, NULL);
+ if (ret > 0) {
+ upload_delay = strcmp(version_str, "20120704beta1") == 0;
+ }
+
/* Upload. */
while (1) {
uint8_t data[256];
@@ -388,6 +396,10 @@ int hdhomerun_control_upgrade(struct hdhomerun_control_sock_t *cs, FILE *upgrade
}
sequence += (uint32_t)length;
+
+ if (upload_delay) {
+ msleep_approx(25);
+ }
}
if (sequence == 0) {
View
28 mythtv/external/libhdhomerun/hdhomerun_debug.c
@@ -300,40 +300,24 @@ void hdhomerun_debug_vprintf(struct hdhomerun_debug_t *dbg, const char *fmt, va_
pthread_mutex_lock(&dbg->print_lock);
if (dbg->prefix) {
- int len = snprintf(ptr, end - ptr, "%s ", dbg->prefix);
- len = (len <= 0) ? 0 : len;
- ptr += len;
- if (ptr > end) {
- ptr = end;
- }
+ hdhomerun_sprintf(ptr, end, "%s ", dbg->prefix);
+ ptr = strchr(ptr, 0);
}
pthread_mutex_unlock(&dbg->print_lock);
/*
* Message text.
*/
- int len = vsnprintf(ptr, end - ptr, fmt, args);
- len = (len < 0) ? 0 : len; /* len does not include null */
- ptr += len;
- if (ptr > end) {
- ptr = end;
- }
+ hdhomerun_vsprintf(ptr, end, fmt, args);
+ ptr = strchr(ptr, 0);
/*
* Force newline.
*/
- if ((ptr[-1] != '\n') && (ptr + 1 <= end)) {
- *ptr++ = '\n';
- }
-
- /*
- * Force NULL.
- */
- if (ptr + 1 > end) {
- ptr = end - 1;
+ if (ptr[-1] != '\n') {
+ hdhomerun_sprintf(ptr, end, "\n");
}
- *ptr++ = 0;
/*
* Enqueue.
View
126 mythtv/external/libhdhomerun/hdhomerun_device.c
@@ -68,8 +68,8 @@ static int hdhomerun_device_set_device_normal(struct hdhomerun_device_t *hd, uin
hd->tuner = 0;
hd->lockkey = 0;
- sprintf(hd->name, "%08lX-%u", (unsigned long)hd->device_id, hd->tuner);
- hd->model[0] = 0; /* clear cached model string */
+ hdhomerun_sprintf(hd->name, hd->name + sizeof(hd->name), "%08X-%u", (unsigned int)hd->device_id, hd->tuner);
+ hdhomerun_sprintf(hd->model, hd->model + sizeof(hd->model), ""); /* clear cached model string */
return 1;
}
@@ -87,9 +87,9 @@ static int hdhomerun_device_set_device_multicast(struct hdhomerun_device_t *hd,
hd->tuner = 0;
hd->lockkey = 0;
- unsigned long ip = multicast_ip;
- sprintf(hd->name, "%lu.%lu.%lu.%lu", (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, (ip >> 0) & 0xFF);
- sprintf(hd->model, "multicast");
+ unsigned int ip = multicast_ip;
+ hdhomerun_sprintf(hd->name, hd->name + sizeof(hd->name), "%u.%u.%u.%u", (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, (ip >> 0) & 0xFF);
+ hdhomerun_sprintf(hd->model, hd->model + sizeof(hd->model), "multicast");
return 1;
}
@@ -120,7 +120,7 @@ int hdhomerun_device_set_tuner(struct hdhomerun_device_t *hd, unsigned int tuner
}
hd->tuner = tuner;
- sprintf(hd->name, "%08lX-%u", (unsigned long)hd->device_id, hd->tuner);
+ hdhomerun_sprintf(hd->name, hd->name + sizeof(hd->name), "%08X-%u", (unsigned int)hd->device_id, hd->tuner);
return 1;
}
@@ -193,17 +193,17 @@ static struct hdhomerun_device_t *hdhomerun_device_create_from_str_device_id(con
}
if (*ptr == 0) {
- unsigned long device_id;
- if (sscanf(device_str, "%lx", &device_id) != 1) {
+ unsigned int device_id;
+ if (sscanf(device_str, "%x", &device_id) != 1) {
return NULL;
}
return hdhomerun_device_create((uint32_t)device_id, 0, 0, dbg);
}
if (*ptr == '-') {
- unsigned long device_id;
+ unsigned int device_id;
unsigned int tuner;
- if (sscanf(device_str, "%lx-%u", &device_id, &tuner) != 2) {
+ if (sscanf(device_str, "%x-%u", &device_id, &tuner) != 2) {
return NULL;
}
return hdhomerun_device_create((uint32_t)device_id, 0, tuner, dbg);
@@ -212,10 +212,10 @@ static struct hdhomerun_device_t *hdhomerun_device_create_from_str_device_id(con
return NULL;
}
-static struct hdhomerun_device_t *hdhomerun_device_create_from_str_ip_result(unsigned long a[4], unsigned int port, unsigned int tuner, struct hdhomerun_debug_t *dbg)
+static struct hdhomerun_device_t *hdhomerun_device_create_from_str_ip_result(unsigned int a[4], unsigned int port, unsigned int tuner, struct hdhomerun_debug_t *dbg)
{
- unsigned long device_ip = (a[0] << 24) | (a[1] << 16) | (a[2] << 8) | (a[3] << 0);
- struct hdhomerun_device_t *hd = hdhomerun_device_create(HDHOMERUN_DEVICE_ID_WILDCARD, (uint32_t)device_ip, tuner, dbg);
+ uint32_t device_ip = (uint32_t)((a[0] << 24) | (a[1] << 16) | (a[2] << 8) | (a[3] << 0));
+ struct hdhomerun_device_t *hd = hdhomerun_device_create(HDHOMERUN_DEVICE_ID_WILDCARD, device_ip, tuner, dbg);
if (!hd) {
return NULL;
}
@@ -229,17 +229,17 @@ static struct hdhomerun_device_t *hdhomerun_device_create_from_str_ip_result(uns
static struct hdhomerun_device_t *hdhomerun_device_create_from_str_ip(const char *device_str, struct hdhomerun_debug_t *dbg)
{
- unsigned long a[4];
+ unsigned int a[4];
unsigned int port = 0;
unsigned int tuner = 0;
- if (sscanf(device_str, "%lu.%lu.%lu.%lu:%u", &a[0], &a[1], &a[2], &a[3], &port) == 5) {
+ if (sscanf(device_str, "%u.%u.%u.%u:%u", &a[0], &a[1], &a[2], &a[3], &port) == 5) {
return hdhomerun_device_create_from_str_ip_result(a, port, tuner, dbg);
}
- if (sscanf(device_str, "%lu.%lu.%lu.%lu-%u", &a[0], &a[1], &a[2], &a[3], &tuner) == 5) {
+ if (sscanf(device_str, "%u.%u.%u.%u-%u", &a[0], &a[1], &a[2], &a[3], &tuner) == 5) {
return hdhomerun_device_create_from_str_ip_result(a, port, tuner, dbg);
}
- if (sscanf(device_str, "%lu.%lu.%lu.%lu", &a[0], &a[1], &a[2], &a[3]) == 4) {
+ if (sscanf(device_str, "%u.%u.%u.%u", &a[0], &a[1], &a[2], &a[3]) == 4) {
return hdhomerun_device_create_from_str_ip_result(a, port, tuner, dbg);
}
@@ -398,8 +398,8 @@ static uint32_t hdhomerun_device_get_status_parse(const char *status_str, const
return 0;
}
- unsigned long value = 0;
- sscanf(ptr + strlen(tag), "%lu", &value);
+ unsigned int value = 0;
+ sscanf(ptr + strlen(tag), "%u", &value);
return (uint32_t)value;
}
@@ -480,7 +480,7 @@ int hdhomerun_device_get_tuner_status(struct hdhomerun_device_t *hd, char **psta
memset(status, 0, sizeof(struct hdhomerun_tuner_status_t));
char name[32];
- sprintf(name, "/tuner%u/status", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/status", hd->tuner);
char *status_str;
int ret = hdhomerun_control_get(hd->cs, name, &status_str, NULL);
@@ -572,7 +572,7 @@ int hdhomerun_device_get_tuner_vstatus(struct hdhomerun_device_t *hd, char **pvs
memset(vstatus, 0, sizeof(struct hdhomerun_tuner_vstatus_t));
char var_name[32];
- sprintf(var_name, "/tuner%u/vstatus", hd->tuner);
+ hdhomerun_sprintf(var_name, var_name + sizeof(var_name), "/tuner%u/vstatus", hd->tuner);
char *vstatus_str;
int ret = hdhomerun_control_get(hd->cs, var_name, &vstatus_str, NULL);
@@ -640,7 +640,7 @@ int hdhomerun_device_get_tuner_streaminfo(struct hdhomerun_device_t *hd, char **
}
char name[32];
- sprintf(name, "/tuner%u/streaminfo", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/streaminfo", hd->tuner);
return hdhomerun_control_get(hd->cs, name, pstreaminfo, NULL);
}
@@ -652,7 +652,7 @@ int hdhomerun_device_get_tuner_channel(struct hdhomerun_device_t *hd, char **pch
}
char name[32];
- sprintf(name, "/tuner%u/channel", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/channel", hd->tuner);
return hdhomerun_control_get(hd->cs, name, pchannel, NULL);
}
@@ -664,7 +664,7 @@ int hdhomerun_device_get_tuner_vchannel(struct hdhomerun_device_t *hd, char **pv
}
char name[32];
- sprintf(name, "/tuner%u/vchannel", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/vchannel", hd->tuner);
return hdhomerun_control_get(hd->cs, name, pvchannel, NULL);
}
@@ -676,7 +676,7 @@ int hdhomerun_device_get_tuner_channelmap(struct hdhomerun_device_t *hd, char **
}
char name[32];
- sprintf(name, "/tuner%u/channelmap", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/channelmap", hd->tuner);
return hdhomerun_control_get(hd->cs, name, pchannelmap, NULL);
}
@@ -688,7 +688,7 @@ int hdhomerun_device_get_tuner_filter(struct hdhomerun_device_t *hd, char **pfil
}
char name[32];
- sprintf(name, "/tuner%u/filter", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/filter", hd->tuner);
return hdhomerun_control_get(hd->cs, name, pfilter, NULL);
}
@@ -700,7 +700,7 @@ int hdhomerun_device_get_tuner_program(struct hdhomerun_device_t *hd, char **ppr
}
char name[32];
- sprintf(name, "/tuner%u/program", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/program", hd->tuner);
return hdhomerun_control_get(hd->cs, name, pprogram, NULL);
}
@@ -712,7 +712,7 @@ int hdhomerun_device_get_tuner_target(struct hdhomerun_device_t *hd, char **ptar
}
char name[32];
- sprintf(name, "/tuner%u/target", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/target", hd->tuner);
return hdhomerun_control_get(hd->cs, name, ptarget, NULL);
}
@@ -735,8 +735,8 @@ static int hdhomerun_device_get_tuner_plotsample_internal(struct hdhomerun_devic
}
*ptr++ = 0;
- unsigned long raw;
- if (sscanf(result, "%lx", &raw) != 1) {
+ unsigned int raw;
+ if (sscanf(result, "%x", &raw) != 1) {
break;
}
@@ -770,7 +770,7 @@ int hdhomerun_device_get_tuner_plotsample(struct hdhomerun_device_t *hd, struct
}
char name[32];
- sprintf(name, "/tuner%u/plotsample", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/plotsample", hd->tuner);
return hdhomerun_device_get_tuner_plotsample_internal(hd, name, psamples, pcount);
}
@@ -792,7 +792,7 @@ int hdhomerun_device_get_tuner_lockkey_owner(struct hdhomerun_device_t *hd, char
}
char name[32];
- sprintf(name, "/tuner%u/lockkey", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/lockkey", hd->tuner);
return hdhomerun_control_get(hd->cs, name, powner, NULL);
}
@@ -834,8 +834,8 @@ int hdhomerun_device_get_version(struct hdhomerun_device_t *hd, char **pversion_
}
if (pversion_num) {
- unsigned long version_num;
- if (sscanf(version_str, "%lu", &version_num) != 1) {
+ unsigned int version_num;
+ if (sscanf(version_str, "%u", &version_num) != 1) {
*pversion_num = 0;
} else {
*pversion_num = (uint32_t)version_num;
@@ -887,7 +887,7 @@ int hdhomerun_device_set_tuner_channel(struct hdhomerun_device_t *hd, const char
}
char name[32];
- sprintf(name, "/tuner%u/channel", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/channel", hd->tuner);
return hdhomerun_control_set_with_lockkey(hd->cs, name, channel, hd->lockkey, NULL, NULL);
}
@@ -899,7 +899,7 @@ int hdhomerun_device_set_tuner_vchannel(struct hdhomerun_device_t *hd, const cha
}
char name[32];
- sprintf(name, "/tuner%u/vchannel", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/vchannel", hd->tuner);
return hdhomerun_control_set_with_lockkey(hd->cs, name, vchannel, hd->lockkey, NULL, NULL);
}
@@ -911,7 +911,7 @@ int hdhomerun_device_set_tuner_channelmap(struct hdhomerun_device_t *hd, const c
}
char name[32];
- sprintf(name, "/tuner%u/channelmap", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/channelmap", hd->tuner);
return hdhomerun_control_set_with_lockkey(hd->cs, name, channelmap, hd->lockkey, NULL, NULL);
}
@@ -923,29 +923,17 @@ int hdhomerun_device_set_tuner_filter(struct hdhomerun_device_t *hd, const char
}
char name[32];
- sprintf(name, "/tuner%u/filter", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/filter", hd->tuner);
return hdhomerun_control_set_with_lockkey(hd->cs, name, filter, hd->lockkey, NULL, NULL);
}
-static int hdhomerun_device_set_tuner_filter_by_array_append(char **pptr, char *end, uint16_t range_begin, uint16_t range_end)
+static bool_t hdhomerun_device_set_tuner_filter_by_array_append(char *ptr, char *end, uint16_t range_begin, uint16_t range_end)
{
- char *ptr = *pptr;
-
- size_t available = end - ptr;
- size_t required;
-
if (range_begin == range_end) {
- required = snprintf(ptr, available, "0x%04x ", range_begin) + 1;
+ return hdhomerun_sprintf(ptr, end, "0x%04x ", (unsigned int)range_begin);
} else {
- required = snprintf(ptr, available, "0x%04x-0x%04x ", range_begin, range_end) + 1;
- }
-
- if (required > available) {
- return FALSE;
+ return hdhomerun_sprintf(ptr, end, "0x%04x-0x%04x ", (unsigned int)range_begin, (unsigned int)range_end);
}
-
- *pptr = strchr(ptr, 0);
- return TRUE;
}
int hdhomerun_device_set_tuner_filter_by_array(struct hdhomerun_device_t *hd, unsigned char filter_array[0x2000])
@@ -963,9 +951,10 @@ int hdhomerun_device_set_tuner_filter_by_array(struct hdhomerun_device_t *hd, un
if (range_begin == 0xFFFF) {
continue;
}
- if (!hdhomerun_device_set_tuner_filter_by_array_append(&ptr, end, range_begin, range_end)) {
+ if (!hdhomerun_device_set_tuner_filter_by_array_append(ptr, end, range_begin, range_end)) {
return 0;
}
+ ptr = strchr(ptr, 0);
range_begin = 0xFFFF;
range_end = 0xFFFF;
continue;
@@ -981,16 +970,17 @@ int hdhomerun_device_set_tuner_filter_by_array(struct hdhomerun_device_t *hd, un
}
if (range_begin != 0xFFFF) {
- if (!hdhomerun_device_set_tuner_filter_by_array_append(&ptr, end, range_begin, range_end)) {
+ if (!hdhomerun_device_set_tuner_filter_by_array_append(ptr, end, range_begin, range_end)) {
return 0;
}
+ ptr = strchr(ptr, 0);
}
/* Remove trailing space. */
if (ptr > filter) {
ptr--;
+ *ptr = 0;
}
- *ptr = 0;
return hdhomerun_device_set_tuner_filter(hd, filter);
}
@@ -1003,7 +993,7 @@ int hdhomerun_device_set_tuner_program(struct hdhomerun_device_t *hd, const char
}
char name[32];
- sprintf(name, "/tuner%u/program", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/program", hd->tuner);
return hdhomerun_control_set_with_lockkey(hd->cs, name, program, hd->lockkey, NULL, NULL);
}
@@ -1015,7 +1005,7 @@ int hdhomerun_device_set_tuner_target(struct hdhomerun_device_t *hd, const char
}
char name[32];
- sprintf(name, "/tuner%u/target", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/target", hd->tuner);
return hdhomerun_control_set_with_lockkey(hd->cs, name, target, hd->lockkey, NULL, NULL);
}
@@ -1034,7 +1024,7 @@ static int hdhomerun_device_set_tuner_target_to_local(struct hdhomerun_device_t
char target[64];
uint32_t local_ip = hdhomerun_control_get_local_addr(hd->cs);
uint16_t local_port = hdhomerun_video_get_local_port(hd->vs);
- sprintf(target, "%s://%u.%u.%u.%u:%u",
+ hdhomerun_sprintf(target, target + sizeof(target), "%s://%u.%u.%u.%u:%u",
protocol,
(unsigned int)(local_ip >> 24) & 0xFF, (unsigned int)(local_ip >> 16) & 0xFF,
(unsigned int)(local_ip >> 8) & 0xFF, (unsigned int)(local_ip >> 0) & 0xFF,
@@ -1107,10 +1097,10 @@ int hdhomerun_device_tuner_lockkey_request(struct hdhomerun_device_t *hd, char *
uint32_t new_lockkey = random_get32();
char name[32];
- sprintf(name, "/tuner%u/lockkey", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/lockkey", hd->tuner);
char new_lockkey_str[64];
- sprintf(new_lockkey_str, "%u", (unsigned int)new_lockkey);
+ hdhomerun_sprintf(new_lockkey_str, new_lockkey_str + sizeof(new_lockkey_str), "%u", (unsigned int)new_lockkey);
int ret = hdhomerun_control_set_with_lockkey(hd->cs, name, new_lockkey_str, hd->lockkey, NULL, perror);
if (ret <= 0) {
@@ -1137,7 +1127,7 @@ int hdhomerun_device_tuner_lockkey_release(struct hdhomerun_device_t *hd)
}
char name[32];
- sprintf(name, "/tuner%u/lockkey", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/lockkey", hd->tuner);
int ret = hdhomerun_control_set_with_lockkey(hd->cs, name, "none", hd->lockkey, NULL, NULL);
hd->lockkey = 0;
@@ -1155,7 +1145,7 @@ int hdhomerun_device_tuner_lockkey_force(struct hdhomerun_device_t *hd)
}
char name[32];
- sprintf(name, "/tuner%u/lockkey", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/lockkey", hd->tuner);
int ret = hdhomerun_control_set(hd->cs, name, "force", NULL, NULL);
hd->lockkey = 0;
@@ -1259,7 +1249,7 @@ void hdhomerun_device_stream_stop(struct hdhomerun_device_t *hd)
}
if (hd->multicast_ip != 0) {
- hdhomerun_video_leave_multicast_group(hd->vs);
+ hdhomerun_video_leave_multicast_group(hd->vs, hd->multicast_ip, 0);
} else {
hdhomerun_device_set_tuner_target(hd, "none");
}
@@ -1339,13 +1329,11 @@ const char *hdhomerun_device_get_model_str(struct hdhomerun_device_t *hd)
return NULL;
}
if (ret == 0) {
- strncpy(hd->model, "hdhomerun_atsc", sizeof(hd->model) - 1);
- hd->model[sizeof(hd->model) - 1] = 0;
+ hdhomerun_sprintf(hd->model, hd->model + sizeof(hd->model), "hdhomerun_atsc");
return hd->model;
}
- strncpy(hd->model, model_str, sizeof(hd->model) - 1);
- hd->model[sizeof(hd->model) - 1] = 0;
+ hdhomerun_sprintf(hd->model, hd->model + sizeof(hd->model), "%s", model_str);
return hd->model;
}
@@ -1373,7 +1361,7 @@ void hdhomerun_device_debug_print_video_stats(struct hdhomerun_device_t *hd)
if (hd->cs) {
char name[32];
- sprintf(name, "/tuner%u/debug", hd->tuner);
+ hdhomerun_sprintf(name, name + sizeof(name), "/tuner%u/debug", hd->tuner);
char *debug_str;
char *error_str;
View
8 mythtv/external/libhdhomerun/hdhomerun_device_selector.c
@@ -201,7 +201,7 @@ int hdhomerun_device_selector_load_from_windows_registry(struct hdhomerun_device
/* Create and add device. */
char device_name[32];
- sprintf(device_name, "%S", wdevice_name);
+ hdhomerun_sprintf(device_name, device_name + sizeof(device_name), "%S", wdevice_name);
struct hdhomerun_device_t *hd = hdhomerun_device_create_from_str(device_name, hds->dbg);
if (!hd) {
@@ -258,9 +258,9 @@ static bool_t hdhomerun_device_selector_choose_test(struct hdhomerun_device_sele
*ptr = 0;
}
- unsigned long a[4];
- unsigned long target_port;
- if (sscanf(target, "%lu.%lu.%lu.%lu:%lu", &a[0], &a[1], &a[2], &a[3], &target_port) != 5) {
+ unsigned int a[4];
+ unsigned int target_port;
+ if (sscanf(target, "%u.%u.%u.%u:%u", &a[0], &a[1], &a[2], &a[3], &target_port) != 5) {
hdhomerun_debug_printf(hds->dbg, "hdhomerun_device_selector_choose_test: device %s in use, no target set (%s)\n", name, target);
return FALSE;
}
View
13 mythtv/external/libhdhomerun/hdhomerun_discover.c
@@ -46,6 +46,7 @@ struct hdhomerun_discover_t {
unsigned int sock_count;
struct hdhomerun_pkt_t tx_pkt;
struct hdhomerun_pkt_t rx_pkt;
+ struct hdhomerun_debug_t *dbg;
};
static bool_t hdhomerun_discover_sock_add(struct hdhomerun_discover_t *ds, uint32_t local_ip, uint32_t subnet_mask)
@@ -72,6 +73,7 @@ static bool_t hdhomerun_discover_sock_add(struct hdhomerun_discover_t *ds, uint3
/* Bind socket. */
if (!hdhomerun_sock_bind(sock, local_ip, 0, FALSE)) {
+ hdhomerun_debug_printf(ds->dbg, "discover: failed to bind to %u.%u.%u.%u:0\n", (unsigned int)(local_ip >> 24) & 0xFF, (unsigned int)(local_ip >> 16) & 0xFF, (unsigned int)(local_ip >> 8) & 0xFF, (unsigned int)(local_ip >> 0) & 0xFF);
hdhomerun_sock_destroy(sock);
return FALSE;
}
@@ -86,13 +88,15 @@ static bool_t hdhomerun_discover_sock_add(struct hdhomerun_discover_t *ds, uint3
return TRUE;
}
-struct hdhomerun_discover_t *hdhomerun_discover_create(void)
+struct hdhomerun_discover_t *hdhomerun_discover_create(struct hdhomerun_debug_t *dbg)
{
struct hdhomerun_discover_t *ds = (struct hdhomerun_discover_t *)calloc(1, sizeof(struct hdhomerun_discover_t));
if (!ds) {
return NULL;
}
+ ds->dbg = dbg;
+
/* Create a routable socket (always first entry). */
if (!hdhomerun_discover_sock_add(ds, 0, 0)) {
free(ds);
@@ -125,8 +129,13 @@ static void hdhomerun_discover_sock_detect(struct hdhomerun_discover_t *ds)
struct hdhomerun_local_ip_info_t ip_info_list[HDHOMERUN_DISOCVER_MAX_SOCK_COUNT];
int count = hdhomerun_local_ip_info(ip_info_list, HDHOMERUN_DISOCVER_MAX_SOCK_COUNT);
if (count < 0) {
+ hdhomerun_debug_printf(ds->dbg, "discover: hdhomerun_local_ip_info returned error\n");
count = 0;
}
+ if (count > HDHOMERUN_DISOCVER_MAX_SOCK_COUNT) {
+ hdhomerun_debug_printf(ds->dbg, "discover: too many local IP addresses\n");
+ count = HDHOMERUN_DISOCVER_MAX_SOCK_COUNT;
+ }
int index;
for (index = 0; index < count; index++) {
@@ -404,7 +413,7 @@ int hdhomerun_discover_find_devices_custom(uint32_t target_ip, uint32_t device_t
return 0;
}
- struct hdhomerun_discover_t *ds = hdhomerun_discover_create();
+ struct hdhomerun_discover_t *ds = hdhomerun_discover_create(NULL);
if (!ds) {
return -1;
}
View
2 mythtv/external/libhdhomerun/hdhomerun_discover.h
@@ -59,7 +59,7 @@ extern LIBTYPE int hdhomerun_discover_find_devices_custom(uint32_t target_ip, ui
/*
* Optional: persistent discover instance available for discover polling use.
*/
-extern LIBTYPE struct hdhomerun_discover_t *hdhomerun_discover_create(void);
+extern LIBTYPE struct hdhomerun_discover_t *hdhomerun_discover_create(struct hdhomerun_debug_t *dbg);
extern LIBTYPE void hdhomerun_discover_destroy(struct hdhomerun_discover_t *ds);
extern LIBTYPE int hdhomerun_discover_find_devices(struct hdhomerun_discover_t *ds, uint32_t target_ip, uint32_t device_type, uint32_t device_id, struct hdhomerun_discover_device_t result_list[], int max_count);
View
34 mythtv/external/libhdhomerun/hdhomerun_os_posix.c
@@ -36,12 +36,12 @@ uint32_t random_get32(void)
{
FILE *fp = fopen("/dev/urandom", "rb");
if (!fp) {
- return (uint32_t)rand();
+ return (uint32_t)getcurrenttime();
}
uint32_t Result;
if (fread(&Result, 4, 1, fp) != 1) {
- Result = (uint32_t)rand();
+ Result = (uint32_t)getcurrenttime();
}
fclose(fp);
@@ -103,3 +103,33 @@ void msleep_minimum(uint64_t ms)
msleep_approx(stop_time - current_time);
}
}
+
+bool_t hdhomerun_vsprintf(char *buffer, char *end, const char *fmt, va_list ap)
+{
+ if (buffer >= end) {
+ return FALSE;
+ }
+
+ int length = vsnprintf(buffer, end - buffer - 1, fmt, ap);
+ if (length < 0) {
+ *buffer = 0;
+ return FALSE;
+ }
+
+ if (buffer + length + 1 > end) {
+ *(end - 1) = 0;
+ return FALSE;
+
+ }
+
+ return TRUE;
+}
+
+bool_t hdhomerun_sprintf(char *buffer, char *end, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ bool_t result = hdhomerun_vsprintf(buffer, end, fmt, ap);
+ va_end(ap);
+ return result;
+}
View
3 mythtv/external/libhdhomerun/hdhomerun_os_posix.h
@@ -69,6 +69,9 @@ extern LIBTYPE uint64_t getcurrenttime(void);
extern LIBTYPE void msleep_approx(uint64_t ms);
extern LIBTYPE void msleep_minimum(uint64_t ms);
+extern LIBTYPE bool_t hdhomerun_vsprintf(char *buffer, char *end, const char *fmt, va_list ap);
+extern LIBTYPE bool_t hdhomerun_sprintf(char *buffer, char *end, const char *fmt, ...);
+
#ifdef __cplusplus
}
#endif
View
32 mythtv/external/libhdhomerun/hdhomerun_os_windows.c
@@ -36,7 +36,7 @@ uint32_t random_get32(void)
{
HCRYPTPROV hProv;
if (!CryptAcquireContext(&hProv, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
- return (uint32_t)rand();
+ return (uint32_t)getcurrenttime();
}
uint32_t Result;
@@ -129,6 +129,36 @@ void pthread_mutex_unlock(pthread_mutex_t *mutex)
}
#endif
+bool_t hdhomerun_vsprintf(char *buffer, char *end, const char *fmt, va_list ap)
+{
+ if (buffer >= end) {
+ return FALSE;
+ }
+
+ int length = _vsnprintf(buffer, end - buffer - 1, fmt, ap);
+ if (length < 0) {
+ *buffer = 0;
+ return FALSE;
+ }
+
+ if (buffer + length + 1 > end) {
+ *(end - 1) = 0;
+ return FALSE;
+
+ }
+
+ return TRUE;
+}
+
+bool_t hdhomerun_sprintf(char *buffer, char *end, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ bool_t result = hdhomerun_vsprintf(buffer, end, fmt, ap);
+ va_end(ap);
+ return result;
+}
+
/*
* The console output format should be set to UTF-8, however in XP and Vista this breaks batch file processing.
* Attempting to restore on exit fails to restore if the program is terminated by the user.
View
4 mythtv/external/libhdhomerun/hdhomerun_os_windows.h
@@ -81,7 +81,6 @@ typedef HANDLE pthread_mutex_t;
#define atoll _atoi64
#define strdup _strdup
#define strcasecmp _stricmp
-#define snprintf _snprintf
#define fseeko _fseeki64
#define ftello _ftelli64
#define THREAD_FUNC_PREFIX DWORD WINAPI
@@ -103,6 +102,9 @@ extern LIBTYPE void pthread_mutex_lock(pthread_mutex_t *mutex);
extern LIBTYPE void pthread_mutex_unlock(pthread_mutex_t *mutex);
#endif
+extern LIBTYPE bool_t hdhomerun_vsprintf(char *buffer, char *end, const char *fmt, va_list ap);
+extern LIBTYPE bool_t hdhomerun_sprintf(char *buffer, char *end, const char *fmt, ...);
+
/*
* The console output format should be set to UTF-8, however in XP and Vista this breaks batch file processing.
* Attempting to restore on exit fails to restore if the program is terminated by the user.
View
3 mythtv/external/libhdhomerun/hdhomerun_sock.h
@@ -54,6 +54,9 @@ extern LIBTYPE uint16_t hdhomerun_sock_getsockname_port(hdhomerun_sock_t sock);
extern LIBTYPE uint32_t hdhomerun_sock_getpeername_addr(hdhomerun_sock_t sock);
extern LIBTYPE uint32_t hdhomerun_sock_getaddrinfo_addr(hdhomerun_sock_t sock, const char *name);
+extern LIBTYPE bool_t hdhomerun_sock_join_multicast_group(hdhomerun_sock_t sock, uint32_t multicast_ip, uint32_t local_ip);
+extern LIBTYPE bool_t hdhomerun_sock_leave_multicast_group(hdhomerun_sock_t sock, uint32_t multicast_ip, uint32_t local_ip);
+
extern LIBTYPE bool_t hdhomerun_sock_bind(hdhomerun_sock_t sock, uint32_t local_addr, uint16_t local_port, bool_t allow_reuse);
extern LIBTYPE bool_t hdhomerun_sock_connect(hdhomerun_sock_t sock, uint32_t remote_addr, uint16_t remote_port, uint64_t timeout);
View
179 mythtv/external/libhdhomerun/hdhomerun_sock_posix.c
@@ -50,13 +50,19 @@
#include <net/if.h>
#include <sys/ioctl.h>
+
#ifndef SIOCGIFCONF
#include <sys/sockio.h>
#endif
+
#ifndef _SIZEOF_ADDR_IFREQ
#define _SIZEOF_ADDR_IFREQ(x) sizeof(x)
#endif
+#ifndef MSG_NOSIGNAL
+#define MSG_NOSIGNAL 0
+#endif
+
int hdhomerun_local_ip_info(struct hdhomerun_local_ip_info_t ip_info_list[], int max_count)
{
int sock = socket(AF_INET, SOCK_DGRAM, 0);
@@ -99,6 +105,19 @@ int hdhomerun_local_ip_info(struct hdhomerun_local_ip_info_t ip_info_list[], int
struct ifreq *ifr = (struct ifreq *)ptr;
ptr += _SIZEOF_ADDR_IFREQ(*ifr);
+ /* Flags. */
+ if (ioctl(sock, SIOCGIFFLAGS, ifr) != 0) {
+ continue;
+ }
+
+ if ((ifr->ifr_flags & IFF_UP) == 0) {
+ continue;
+ }
+ if ((ifr->ifr_flags & IFF_RUNNING) == 0) {
+ continue;
+ }
+
+ /* Local IP address. */
if (ioctl(sock, SIOCGIFADDR, ifr) != 0) {
continue;
}
@@ -109,20 +128,22 @@ int hdhomerun_local_ip_info(struct hdhomerun_local_ip_info_t ip_info_list[], int
continue;
}
+ /* Subnet mask. */
if (ioctl(sock, SIOCGIFNETMASK, ifr) != 0) {
continue;
}
struct sockaddr_in *subnet_mask_in = (struct sockaddr_in *)&(ifr->ifr_addr);
uint32_t subnet_mask = ntohl(subnet_mask_in->sin_addr.s_addr);
- struct hdhomerun_local_ip_info_t *ip_info = &ip_info_list[count++];
- ip_info->ip_addr = ip_addr;
- ip_info->subnet_mask = subnet_mask;
-
- if (count >= max_count) {
- break;
+ /* Report. */
+ if (count < max_count) {
+ struct hdhomerun_local_ip_info_t *ip_info = &ip_info_list[count];
+ ip_info->ip_addr = ip_addr;
+ ip_info->subnet_mask = subnet_mask;
}
+
+ count++;
}
free(ifc.ifc_buf);
@@ -236,6 +257,34 @@ uint32_t hdhomerun_sock_getaddrinfo_addr(hdhomerun_sock_t sock, const char *name
return addr;
}
+bool_t hdhomerun_sock_join_multicast_group(hdhomerun_sock_t sock, uint32_t multicast_ip, uint32_t local_ip)
+{
+ struct ip_mreq imr;
+ memset(&imr, 0, sizeof(imr));
+ imr.imr_multiaddr.s_addr = htonl(multicast_ip);
+ imr.imr_interface.s_addr = htonl(local_ip);
+
+ if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char *)&imr, sizeof(imr)) != 0) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+bool_t hdhomerun_sock_leave_multicast_group(hdhomerun_sock_t sock, uint32_t multicast_ip, uint32_t local_ip)
+{
+ struct ip_mreq imr;
+ memset(&imr, 0, sizeof(imr));
+ imr.imr_multiaddr.s_addr = htonl(multicast_ip);
+ imr.imr_interface.s_addr = htonl(local_ip);
+
+ if (setsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, (const char *)&imr, sizeof(imr)) != 0) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
bool_t hdhomerun_sock_bind(hdhomerun_sock_t sock, uint32_t local_addr, uint16_t local_port, bool_t allow_reuse)
{
int sock_opt = allow_reuse;
@@ -340,30 +389,20 @@ bool_t hdhomerun_sock_connect(hdhomerun_sock_t sock, uint32_t remote_addr, uint1
sock_addr.sin_addr.s_addr = htonl(remote_addr);
sock_addr.sin_port = htons(remote_port);
- if (connect(sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) == 0) {
- return TRUE;
+ if (connect(sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) != 0) {
+ if ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (errno != EINPROGRESS)) {
+ return FALSE;
+ }
}
uint64_t stop_time = getcurrenttime() + timeout;
- /*
- * getpeername() is used to detect if connect succeeded. Bug - cygwin
- * will return getpeername success even if the connect process hasn't
- * completed. This first call to select is used to work around the
- * problem (at least for low numbered sockets where select is used).
- */
- if (!hdhomerun_sock_wait_for_write_event(sock, stop_time)) {
- return FALSE;
- }
-
while (1) {
- struct sockaddr_in sock_addr;
- socklen_t sockaddr_size = sizeof(sock_addr);
- if (getpeername(sock, (struct sockaddr *)&sock_addr, &sockaddr_size) == 0) {
+ if (send(sock, NULL, 0, MSG_NOSIGNAL) == 0) {
return TRUE;
}
- if (errno != ENOTCONN) {
+ if ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (errno != EINPROGRESS) && (errno != ENOTCONN)) {
return FALSE;
}
@@ -379,26 +418,24 @@ bool_t hdhomerun_sock_send(hdhomerun_sock_t sock, const void *data, size_t lengt
const uint8_t *ptr = (const uint8_t *)data;
while (1) {
- int ret = send(sock, ptr, length, 0);
- if (ret >= (int)length) {
- return TRUE;
+ int ret = send(sock, ptr, length, MSG_NOSIGNAL);
+ if (ret <= 0) {
+ if ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (errno != EINPROGRESS)) {
+ return FALSE;
+ }
+ if (!hdhomerun_sock_wait_for_write_event(sock, stop_time)) {
+ return FALSE;
+ }
+ continue;
}
- if (ret > 0) {
+ if (ret < (int)length) {
ptr += ret;
length -= ret;
+ continue;
}
- if (errno == EINPROGRESS) {
- errno = EWOULDBLOCK;
- }
- if (errno != EWOULDBLOCK) {
- return FALSE;
- }
-
- if (!hdhomerun_sock_wait_for_write_event(sock, stop_time)) {
- return FALSE;
- }
+ return TRUE;
}
}
@@ -415,25 +452,23 @@ bool_t hdhomerun_sock_sendto(hdhomerun_sock_t sock, uint32_t remote_addr, uint16
sock_addr.sin_port = htons(remote_port);
int ret = sendto(sock, ptr, length, 0, (struct sockaddr *)&sock_addr, sizeof(sock_addr));
- if (ret >= (int)length) {
- return TRUE;
+ if (ret <= 0) {
+ if ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (errno != EINPROGRESS)) {
+ return FALSE;
+ }
+ if (!hdhomerun_sock_wait_for_write_event(sock, stop_time)) {
+ return FALSE;
+ }
+ continue;
}
- if (ret > 0) {
+ if (ret < (int)length) {
ptr += ret;
length -= ret;
+ continue;
}
- if (errno == EINPROGRESS) {
- errno = EWOULDBLOCK;
- }
- if (errno != EWOULDBLOCK) {
- return FALSE;
- }
-
- if (!hdhomerun_sock_wait_for_write_event(sock, stop_time)) {
- return FALSE;
- }
+ return TRUE;
}
}
@@ -443,21 +478,22 @@ bool_t hdhomerun_sock_recv(hdhomerun_sock_t sock, void *data, size_t *length, ui
while (1) {
int ret = recv(sock, data, *length, 0);
- if (ret > 0) {
- *length = ret;
- return TRUE;
+ if (ret < 0) {
+ if ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (errno != EINPROGRESS)) {
+ return FALSE;
+ }
+ if (!hdhomerun_sock_wait_for_read_event(sock, stop_time)) {
+ return FALSE;
+ }
+ continue;
}
- if (errno == EINPROGRESS) {
- errno = EWOULDBLOCK;
- }
- if (errno != EWOULDBLOCK) {
+ if (ret == 0) {
return FALSE;
}
- if (!hdhomerun_sock_wait_for_read_event(sock, stop_time)) {
- return FALSE;
- }
+ *length = ret;
+ return TRUE;
}
}
@@ -471,22 +507,23 @@ bool_t hdhomerun_sock_recvfrom(hdhomerun_sock_t sock, uint32_t *remote_addr, uin
socklen_t sockaddr_size = sizeof(sock_addr);
int ret = recvfrom(sock, data, *length, 0, (struct sockaddr *)&sock_addr, &sockaddr_size);
- if (ret > 0) {
- *remote_addr = ntohl(sock_addr.sin_addr.s_addr);
- *remote_port = ntohs(sock_addr.sin_port);
- *length = ret;
- return TRUE;
+ if (ret < 0) {
+ if ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (errno != EINPROGRESS)) {
+ return FALSE;
+ }
+ if (!hdhomerun_sock_wait_for_read_event(sock, stop_time)) {
+ return FALSE;
+ }
+ continue;
}
- if (errno == EINPROGRESS) {
- errno = EWOULDBLOCK;
- }
- if (errno != EWOULDBLOCK) {
+ if (ret == 0) {
return FALSE;
}
- if (!hdhomerun_sock_wait_for_read_event(sock, stop_time)) {
- return FALSE;
- }
+ *remote_addr = ntohl(sock_addr.sin_addr.s_addr);
+ *remote_port = ntohs(sock_addr.sin_port);
+ *length = ret;
+ return TRUE;
}
}
View
158 mythtv/external/libhdhomerun/hdhomerun_sock_windows.c
@@ -91,14 +91,13 @@ int hdhomerun_local_ip_info(struct hdhomerun_local_ip_info_t ip_info_list[], int
continue;
}
- struct hdhomerun_local_ip_info_t *ip_info = &ip_info_list[count++];
- ip_info->ip_addr = ip_addr;
- ip_info->subnet_mask = subnet_mask;
-
- if (count >= max_count) {
- break;
+ if (count < max_count) {
+ struct hdhomerun_local_ip_info_t *ip_info = &ip_info_list[count];
+ ip_info->ip_addr = ip_addr;
+ ip_info->subnet_mask = subnet_mask;
}
+ count++;
IPAddr = IPAddr->Next;
}
@@ -221,6 +220,34 @@ uint32_t hdhomerun_sock_getaddrinfo_addr(hdhomerun_sock_t sock, const char *name
return addr;
}
+bool_t hdhomerun_sock_join_multicast_group(hdhomerun_sock_t sock, uint32_t multicast_ip, uint32_t local_ip)
+{
+ struct ip_mreq imr;
+ memset(&imr, 0, sizeof(imr));
+ imr.imr_multiaddr.s_addr = htonl(multicast_ip);
+ imr.imr_interface.s_addr = htonl(local_ip);
+
+ if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char *)&imr, sizeof(imr)) != 0) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+bool_t hdhomerun_sock_leave_multicast_group(hdhomerun_sock_t sock, uint32_t multicast_ip, uint32_t local_ip)
+{
+ struct ip_mreq imr;
+ memset(&imr, 0, sizeof(imr));
+ imr.imr_multiaddr.s_addr = htonl(multicast_ip);
+ imr.imr_interface.s_addr = htonl(local_ip);
+
+ if (setsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, (const char *)&imr, sizeof(imr)) != 0) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
bool_t hdhomerun_sock_bind(hdhomerun_sock_t sock, uint32_t local_addr, uint16_t local_port, bool_t allow_reuse)
{
int sock_opt = allow_reuse;
@@ -241,16 +268,6 @@ bool_t hdhomerun_sock_bind(hdhomerun_sock_t sock, uint32_t local_addr, uint16_t
bool_t hdhomerun_sock_connect(hdhomerun_sock_t sock, uint32_t remote_addr, uint16_t remote_port, uint64_t timeout)
{
- WSAEVENT wsa_event = WSACreateEvent();
- if (wsa_event == WSA_INVALID_EVENT) {
- return FALSE;
- }
-
- if (WSAEventSelect(sock, wsa_event, FD_CONNECT) == SOCKET_ERROR) {
- WSACloseEvent(wsa_event);
- return FALSE;
- }
-
/* Connect (non-blocking). */
struct sockaddr_in sock_addr;
memset(&sock_addr, 0, sizeof(sock_addr));
@@ -260,22 +277,41 @@ bool_t hdhomerun_sock_connect(hdhomerun_sock_t sock, uint32_t remote_addr, uint1
if (connect(sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) != 0) {
if (WSAGetLastError() != WSAEWOULDBLOCK) {
- WSACloseEvent(wsa_event);
return FALSE;
}
}
/* Wait for connect to complete (both success and failure will signal). */
+ WSAEVENT wsa_event = WSACreateEvent();
+ if (wsa_event == WSA_INVALID_EVENT) {
+ return FALSE;
+ }
+
+ if (WSAEventSelect(sock, wsa_event, FD_WRITE | FD_CLOSE) == SOCKET_ERROR) {
+ WSACloseEvent(wsa_event);
+ return FALSE;
+ }
+
DWORD ret = WaitForSingleObjectEx(wsa_event, (DWORD)timeout, FALSE);
WSACloseEvent(wsa_event);
-
if (ret != WAIT_OBJECT_0) {
return FALSE;
}
/* Detect success/failure. */
- int sockaddr_size = sizeof(sock_addr);
- if (getpeername(sock, (struct sockaddr *)&sock_addr, &sockaddr_size) != 0) {
+ wsa_event = WSACreateEvent();
+ if (wsa_event == WSA_INVALID_EVENT) {
+ return FALSE;
+ }
+
+ if (WSAEventSelect(sock, wsa_event, FD_CLOSE) == SOCKET_ERROR) {
+ WSACloseEvent(wsa_event);
+ return FALSE;
+ }
+
+ ret = WaitForSingleObjectEx(wsa_event, 0, FALSE);
+ WSACloseEvent(wsa_event);
+ if (ret == WAIT_OBJECT_0) {
return FALSE;
}
@@ -316,22 +352,23 @@ bool_t hdhomerun_sock_send(hdhomerun_sock_t sock, const void *data, size_t lengt
while (1) {
int ret = send(sock, (char *)ptr, (int)length, 0);
- if (ret >= (int)length) {
- return TRUE;
+ if (ret <= 0) {
+ if (WSAGetLastError() != WSAEWOULDBLOCK) {
+ return FALSE;
+ }
+ if (!hdhomerun_sock_wait_for_event(sock, FD_WRITE | FD_CLOSE, stop_time)) {
+ return FALSE;
+ }
+ continue;
}
- if (ret > 0) {
+ if (ret < (int)length) {
ptr += ret;
length -= ret;
+ continue;
}
- if (WSAGetLastError() != WSAEWOULDBLOCK) {
- return FALSE;
- }
-
- if (!hdhomerun_sock_wait_for_event(sock, FD_WRITE | FD_CLOSE, stop_time)) {
- return FALSE;
- }
+ return TRUE;
}
}
@@ -348,22 +385,23 @@ bool_t hdhomerun_sock_sendto(hdhomerun_sock_t sock, uint32_t remote_addr, uint16
sock_addr.sin_port = htons(remote_port);
int ret = sendto(sock, (char *)ptr, (int)length, 0, (struct sockaddr *)&sock_addr, sizeof(sock_addr));
- if (ret >= (int)length) {
- return TRUE;
+ if (ret <= 0) {
+ if (WSAGetLastError() != WSAEWOULDBLOCK) {
+ return FALSE;
+ }
+ if (!hdhomerun_sock_wait_for_event(sock, FD_WRITE | FD_CLOSE, stop_time)) {
+ return FALSE;
+ }
+ continue;
}
- if (ret > 0) {
+ if (ret < (int)length) {
ptr += ret;
length -= ret;
+ continue;
}
- if (WSAGetLastError() != WSAEWOULDBLOCK) {
- return FALSE;
- }
-
- if (!hdhomerun_sock_wait_for_event(sock, FD_WRITE | FD_CLOSE, stop_time)) {
- return FALSE;
- }
+ return TRUE;
}
}
@@ -373,18 +411,22 @@ bool_t hdhomerun_sock_recv(hdhomerun_sock_t sock, void *data, size_t *length, ui
while (1) {
int ret = recv(sock, (char *)data, (int)(*length), 0);
- if (ret > 0) {
- *length = ret;
- return TRUE;
+ if (ret < 0) {
+ if (WSAGetLastError() != WSAEWOULDBLOCK) {
+ return FALSE;
+ }
+ if (!hdhomerun_sock_wait_for_event(sock, FD_READ | FD_CLOSE, stop_time)) {
+ return FALSE;
+ }
+ continue;
}
- if (WSAGetLastError() != WSAEWOULDBLOCK) {
+ if (ret == 0) {
return FALSE;
}
- if (!hdhomerun_sock_wait_for_event(sock, FD_READ | FD_CLOSE, stop_time)) {
- return FALSE;
- }
+ *length = ret;
+ return TRUE;
}
}
@@ -398,19 +440,23 @@ bool_t hdhomerun_sock_recvfrom(hdhomerun_sock_t sock, uint32_t *remote_addr, uin
int sockaddr_size = sizeof(sock_addr);
int ret = recvfrom(sock, (char *)data, (int)(*length), 0, (struct sockaddr *)&sock_addr, &sockaddr_size);
- if (ret > 0) {
- *remote_addr = ntohl(sock_addr.sin_addr.s_addr);
- *remote_port = ntohs(sock_addr.sin_port);
- *length = ret;
- return TRUE;
+ if (ret < 0) {
+ if (WSAGetLastError() != WSAEWOULDBLOCK) {
+ return FALSE;
+ }
+ if (!hdhomerun_sock_wait_for_event(sock, FD_READ | FD_CLOSE, stop_time)) {
+ return FALSE;
+ }
+ continue;
}
- if (WSAGetLastError() != WSAEWOULDBLOCK) {
+ if (ret == 0) {
return FALSE;
}
- if (!hdhomerun_sock_wait_for_event(sock, FD_READ | FD_CLOSE, stop_time)) {
- return FALSE;
- }
+ *remote_addr = ntohl(sock_addr.sin_addr.s_addr);
+ *remote_port = ntohs(sock_addr.sin_port);
+ *length = ret;
+ return TRUE;
}
}
View
38 mythtv/external/libhdhomerun/hdhomerun_video.c
@@ -35,9 +35,7 @@
struct hdhomerun_video_sock_t {
pthread_mutex_t lock;
struct hdhomerun_debug_t *dbg;
-
hdhomerun_sock_t sock;
- uint32_t multicast_ip;
volatile size_t head;
volatile size_t tail;
@@ -157,41 +155,19 @@ uint16_t hdhomerun_video_get_local_port(struct hdhomerun_video_sock_t *vs)
int hdhomerun_video_join_multicast_group(struct hdhomerun_video_sock_t *vs, uint32_t multicast_ip, uint32_t local_ip)
{
- if (vs->multicast_ip != 0) {
- hdhomerun_video_leave_multicast_group(vs);
- }
-
- struct ip_mreq imr;
- memset(&imr, 0, sizeof(imr));
- imr.imr_multiaddr.s_addr = htonl(multicast_ip);
- imr.imr_interface.s_addr = htonl(local_ip);
-
- if (setsockopt(vs->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char *)&imr, sizeof(imr)) != 0) {
+ if (!hdhomerun_sock_join_multicast_group(vs->sock, multicast_ip, local_ip)) {
hdhomerun_debug_printf(vs->dbg, "hdhomerun_video_join_multicast_group: setsockopt failed (%d)\n", hdhomerun_sock_getlasterror());
return -1;
}
- vs->multicast_ip = multicast_ip;
return 1;
}
-int hdhomerun_video_leave_multicast_group(struct hdhomerun_video_sock_t *vs)
+void hdhomerun_video_leave_multicast_group(struct hdhomerun_video_sock_t *vs, uint32_t multicast_ip, uint32_t local_ip)
{
- if (vs->multicast_ip == 0) {
- return 1;
- }
-
- struct ip_mreq imr;
- memset(&imr, 0, sizeof(imr));
- imr.imr_multiaddr.s_addr = htonl(vs->multicast_ip);
- imr.imr_interface.s_addr = htonl(INADDR_ANY);
-
- if (setsockopt(vs->sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, (const char *)&imr, sizeof(imr)) != 0) {
+ if (!hdhomerun_sock_leave_multicast_group(vs->sock, multicast_ip, local_ip)) {
hdhomerun_debug_printf(vs->dbg, "hdhomerun_video_leave_multicast_group: setsockopt failed (%d)\n", hdhomerun_sock_getlasterror());
}
-
- vs->multicast_ip = 0;
- return 1;
}
static void hdhomerun_video_stats_ts_pkt(struct hdhomerun_video_sock_t *vs, uint8_t *ptr)
@@ -396,10 +372,10 @@ void hdhomerun_video_debug_print_stats(struct hdhomerun_video_sock_t *vs)
struct hdhomerun_video_stats_t stats;
hdhomerun_video_get_stats(vs, &stats);
- hdhomerun_debug_printf(vs->dbg, "video sock: pkt=%lu net=%lu te=%lu miss=%lu drop=%lu\n",
- (unsigned long)stats.packet_count, (unsigned long)stats.network_error_count,
- (unsigned long)stats.transport_error_count, (unsigned long)stats.sequence_error_count,
- (unsigned long)stats.overflow_error_count
+ hdhomerun_debug_printf(vs->dbg, "video sock: pkt=%u net=%u te=%u miss=%u drop=%u\n",
+ (unsigned int)stats.packet_count, (unsigned int)stats.network_error_count,
+ (unsigned int)stats.transport_error_count, (unsigned int)stats.sequence_error_count,
+ (unsigned int)stats.overflow_error_count
);
}
View
2 mythtv/external/libhdhomerun/hdhomerun_video.h
@@ -74,7 +74,7 @@ extern LIBTYPE uint16_t hdhomerun_video_get_local_port(struct hdhomerun_video_so
* Join/leave multicast group.
*/
extern LIBTYPE int hdhomerun_video_join_multicast_group(struct hdhomerun_video_sock_t *vs, uint32_t multicast_ip, uint32_t local_ip);
-extern LIBTYPE int hdhomerun_video_leave_multicast_group(struct hdhomerun_video_sock_t *vs);
+extern LIBTYPE void hdhomerun_video_leave_multicast_group(struct hdhomerun_video_sock_t *vs, uint32_t multicast_ip, uint32_t local_ip);
/*
* Read data from buffer.

0 comments on commit 1477254

Please sign in to comment.
Something went wrong with that request. Please try again.