Ticket #6138: 132-hdhr.20081231.trunk.2.patch

File 132-hdhr.20081231.trunk.2.patch, 107.7 KB (added by cizek@…, 15 years ago)
  • mythtv/libs/libmythhdhomerun/README

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/README myth.20746.0626b/mythtv/libs/libmythhdhomerun/README
     
    11/*
    2  * libhdhomerun
     2 * README
    33 *
    44 * Copyright © 2005-2006 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033Top level include file: hdhomerun.h
  • mythtv/libs/libmythhdhomerun/README.MythTV

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/README.MythTV myth.20746.0626b/mythtv/libs/libmythhdhomerun/README.MythTV
     
     1
     2This directory contains Silicondust Engineering's hdhomerun
     3library used for communicating with the HDHomeRun hardware.
     4
     5The files in this directory are released under the GNU LESSER GENERAL PUBLIC LICENSE
     6For details see the lgpl.txt file which should be located in this directory.
     7If you can not find it, it can also be seen at http://www.gnu.org/licenses/lgpl.txt
  • mythtv/libs/libmythhdhomerun/hdhomerun.h

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun.h myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun.h
     
    11/*
    2  * hdhomerun_device.h
     2 * hdhomerun.h
    33 *
    4  * Copyright © 2006-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033#include "hdhomerun_os.h"
  • mythtv/libs/libmythhdhomerun/hdhomerun_channels.c

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_channels.c myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_channels.c
     
    11/*
    2  * hdhomerun_channelscan.c
     2 * hdhomerun_channels.c
    33 *
    4  * Copyright © 2007-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2007-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033#include "hdhomerun.h"
     
    2437struct hdhomerun_channel_entry_t {
    2538        struct hdhomerun_channel_entry_t *next;
    2639        struct hdhomerun_channel_entry_t *prev;
    27         uint32_t channel_map;
    2840        uint32_t frequency;
    2941        uint8_t channel_number;
    3042        char name[16];
    3143};
    3244
    33 struct hdhomerun_channel_map_range_t {
    34         uint32_t channel_map;
     45struct hdhomerun_channel_list_t {
     46        struct hdhomerun_channel_entry_t *head;
     47        struct hdhomerun_channel_entry_t *tail;
     48};
     49
     50struct hdhomerun_channelmap_range_t {
    3551        uint8_t channel_range_start;
    3652        uint8_t channel_range_end;
    3753        uint32_t frequency;
    3854        uint32_t spacing;
    3955};
    4056
    41 static const struct hdhomerun_channel_map_range_t hdhomerun_channels_map_ranges[] = {
    42         {CHANNEL_MAP_US_BCAST,   2,   4,  57000000, 6000000},
    43         {CHANNEL_MAP_US_BCAST,   5,   6,  79000000, 6000000},
    44         {CHANNEL_MAP_US_BCAST,   7,  13, 177000000, 6000000},
    45         {CHANNEL_MAP_US_BCAST,  14,  69, 473000000, 6000000},
    46 
    47         {CHANNEL_MAP_US_CABLE,   1,   1,  75000000, 6000000},
    48         {CHANNEL_MAP_US_CABLE,   2,   4,  57000000, 6000000},
    49         {CHANNEL_MAP_US_CABLE,   5,   6,  79000000, 6000000},
    50         {CHANNEL_MAP_US_CABLE,   7,  13, 177000000, 6000000},
    51         {CHANNEL_MAP_US_CABLE,  14,  22, 123000000, 6000000},
    52         {CHANNEL_MAP_US_CABLE,  23,  94, 219000000, 6000000},
    53         {CHANNEL_MAP_US_CABLE,  95,  99,  93000000, 6000000},
    54         {CHANNEL_MAP_US_CABLE, 100, 136, 651000000, 6000000},
    55 
    56         {CHANNEL_MAP_US_HRC,     1,   1,  73753600, 6000300},
    57         {CHANNEL_MAP_US_HRC,     2,   4,  55752700, 6000300},
    58         {CHANNEL_MAP_US_HRC,     5,   6,  79753900, 6000300},
    59         {CHANNEL_MAP_US_HRC,     7,  13, 175758700, 6000300},
    60         {CHANNEL_MAP_US_HRC,    14,  22, 121756000, 6000300},
    61         {CHANNEL_MAP_US_HRC,    23,  94, 217760800, 6000300},
    62         {CHANNEL_MAP_US_HRC,    95,  99,  91754500, 6000300},
    63         {CHANNEL_MAP_US_HRC,   100, 136, 649782400, 6000300},
    64 
    65         {CHANNEL_MAP_US_IRC,     1,   1,  75012500, 6000000},
    66         {CHANNEL_MAP_US_IRC,     2,   4,  57012500, 6000000},
    67         {CHANNEL_MAP_US_IRC,     5,   6,  81012500, 6000000},
    68         {CHANNEL_MAP_US_IRC,     7,  13, 177012500, 6000000},
    69         {CHANNEL_MAP_US_IRC,    14,  22, 123012500, 6000000},
    70         {CHANNEL_MAP_US_IRC,    23,  41, 219012500, 6000000},
    71         {CHANNEL_MAP_US_IRC,    42,  42, 333025000, 6000000},
    72         {CHANNEL_MAP_US_IRC,    43,  94, 339012500, 6000000},
    73         {CHANNEL_MAP_US_IRC,    95,  97,  93012500, 6000000},
    74         {CHANNEL_MAP_US_IRC,    98,  99, 111025000, 6000000},
    75         {CHANNEL_MAP_US_IRC,   100, 136, 651012500, 6000000},
    76 
    77         {CHANNEL_MAP_UK_BCAST,  21,  68, 474000000, 8000000},
    78         {CHANNEL_MAP_NZ_BCAST,  25,  62, 506000000, 8000000},
    79 
    80         {0,                      0,   0,         0,       0}
     57struct hdhomerun_channelmap_record_t {
     58        const char *channelmap_prefix;
     59        const char *channelmap;
     60        const struct hdhomerun_channelmap_range_t *range_list;
     61        const char *channelmap_scan_group;
     62        const char *countrycodes;
     63};
     64
     65/* AU antenna channels. Channels {0, 1, 2, 6, 7, 8, 9, 9A} are numbered {2, 3, 4, 5, 6, 7, 8, 9} by the HDHomeRun. */
     66static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_au_bcast[] = {
     67        {  2,   2,  48500000, 7000000},
     68        {  3,   4,  59500000, 7000000},
     69        {  5,  12, 177500000, 7000000},
     70        { 28,  69, 529500000, 7000000},
     71        {  0,   0,         0,       0}
     72};
     73
     74/* AU cable channels. TBD. */
     75static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_au_cable[] = {
     76        {  0,   0,         0,       0}
     77};
     78
     79/* EU antenna channels. */
     80static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_eu_bcast[] = {
     81        {  2,   4,  50500000, 7000000},
     82        {  5,  12, 177500000, 7000000},
     83        { 21,  69, 474000000, 8000000},
     84        {  0,   0,         0,       0}
     85};
     86
     87/* EU cable channels. Channels do not have simple numbers - the HDHomeRun uses its own numbering scheme (subject to change). */
     88static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_eu_cable[] = {
     89        {  6,   7, 113000000, 8000000},
     90        {  9, 100, 138000000, 8000000},
     91        {  0,   0,         0,       0}
    8192};
    8293
    83 static struct hdhomerun_channel_entry_t *hdhomerun_channel_list_head = NULL;
    84 static struct hdhomerun_channel_entry_t *hdhomerun_channel_list_tail = NULL;
     94/* US antenna channels. */
     95static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_us_bcast[] = {
     96        {  2,   4,  57000000, 6000000},
     97        {  5,   6,  79000000, 6000000},
     98        {  7,  13, 177000000, 6000000},
     99        { 14,  69, 473000000, 6000000},
     100        {  0,   0,         0,       0}
     101};
     102
     103/* US cable channels. */
     104static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_us_cable[] = {
     105        {  2,   4,  57000000, 6000000},
     106        {  5,   6,  79000000, 6000000},
     107        {  7,  13, 177000000, 6000000},
     108        { 14,  22, 123000000, 6000000},
     109        { 23,  94, 219000000, 6000000},
     110        { 95,  99,  93000000, 6000000},
     111        {100, 135, 651000000, 6000000},
     112        {  0,   0,         0,       0}
     113};
     114
     115/* US cable channels (HRC). */
     116static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_us_hrc[] = {
     117        {  2,   4,  55752700, 6000300},
     118        {  5,   6,  79753900, 6000300},
     119        {  7,  13, 175758700, 6000300},
     120        { 14,  22, 121756000, 6000300},
     121        { 23,  94, 217760800, 6000300},
     122        { 95,  99,  91754500, 6000300},
     123        {100, 135, 649782400, 6000300},
     124        {  0,   0,         0,       0}
     125};
    85126
    86 uint32_t hdhomerun_channel_entry_channel_map(struct hdhomerun_channel_entry_t *entry)
     127/* US cable channels (IRC). */
     128static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_us_irc[] = {
     129        {  2,   4,  57012500, 6000000},
     130        {  5,   6,  81012500, 6000000},
     131        {  7,  13, 177012500, 6000000},
     132        { 14,  22, 123012500, 6000000},
     133        { 23,  41, 219012500, 6000000},
     134        { 42,  42, 333025000, 6000000},
     135        { 43,  94, 339012500, 6000000},
     136        { 95,  97,  93012500, 6000000},
     137        { 98,  99, 111025000, 6000000},
     138        {100, 135, 651012500, 6000000},
     139        {  0,   0,         0,       0}
     140};
     141
     142static const struct hdhomerun_channelmap_record_t hdhomerun_channelmap_table[] = {
     143        {"au", "au-bcast", hdhomerun_channelmap_range_au_bcast, "au-bcast",               "AU"},
     144        {"au", "au-cable", hdhomerun_channelmap_range_au_cable, "au-cable",               "AU"},
     145        {"eu", "eu-bcast", hdhomerun_channelmap_range_eu_bcast, "eu-bcast",               "EU"},
     146        {"eu", "eu-cable", hdhomerun_channelmap_range_eu_cable, "eu-cable",               "EU"},
     147        {"tw", "tw-bcast", hdhomerun_channelmap_range_us_bcast, "tw-bcast",               "TW"},
     148        {"tw", "tw-cable", hdhomerun_channelmap_range_us_cable, "tw-cable",               "TW"},
     149        {"us", "us-bcast", hdhomerun_channelmap_range_us_bcast, "us-bcast",               "CA US"},
     150        {"us", "us-cable", hdhomerun_channelmap_range_us_cable, "us-cable us-hrc us-irc", "CA US"},
     151        {"us", "us-hrc",   hdhomerun_channelmap_range_us_hrc  , "us-cable us-hrc us-irc", "CA US"},
     152        {"us", "us-irc",   hdhomerun_channelmap_range_us_irc,   "us-cable us-hrc us-irc", "CA US"},
     153        {NULL, NULL,       NULL,                                NULL,                     NULL}
     154};
     155
     156const char *hdhomerun_channelmap_convert_countrycode_to_channelmap_prefix(const char *countrycode)
    87157{
    88         return entry->channel_map;
     158        const struct hdhomerun_channelmap_record_t *record = hdhomerun_channelmap_table;
     159        while (record->channelmap) {
     160                if (strstr(record->countrycodes, countrycode)) {
     161                        return record->channelmap_prefix;
     162                }
     163                record++;
     164        }
     165
     166        return "eu";
     167}
     168
     169const char *hdhomerun_channelmap_get_channelmap_scan_group(const char *channelmap)
     170{
     171        const struct hdhomerun_channelmap_record_t *record = hdhomerun_channelmap_table;
     172        while (record->channelmap) {
     173                if (strstr(channelmap, record->channelmap)) {
     174                        return record->channelmap_scan_group;
     175                }
     176                record++;
     177        }
     178
     179        return NULL;
    89180}
    90181
    91182uint8_t hdhomerun_channel_entry_channel_number(struct hdhomerun_channel_entry_t *entry)
    const char *hdhomerun_channel_entry_name 
    103194        return entry->name;
    104195}
    105196
    106 static const char *hdhomerun_channel_map_name(uint32_t channel_map)
     197struct hdhomerun_channel_entry_t *hdhomerun_channel_list_first(struct hdhomerun_channel_list_t *channel_list)
    107198{
    108         switch (channel_map) {
    109         case CHANNEL_MAP_US_BCAST:
    110                 return "us-bcast";
    111         case CHANNEL_MAP_US_CABLE:
    112                 return "us-cable";
    113         case CHANNEL_MAP_US_HRC:
    114                 return "us-hrc";
    115         case CHANNEL_MAP_US_IRC:
    116                 return "us-irc";
    117         case CHANNEL_MAP_UK_BCAST:
    118                 return "uk-bcast";
    119         case CHANNEL_MAP_NZ_BCAST:
    120                 return "nz-bcast";
    121         default:
    122                 return "unknown";
    123         }
     199        return channel_list->head;
    124200}
    125201
    126 static void hdhomerun_channel_list_build_insert(struct hdhomerun_channel_entry_t *entry)
     202struct hdhomerun_channel_entry_t *hdhomerun_channel_list_last(struct hdhomerun_channel_list_t *channel_list)
    127203{
    128         struct hdhomerun_channel_entry_t *prev = NULL;
    129         struct hdhomerun_channel_entry_t *next = hdhomerun_channel_list_head;
    130 
    131         while (next) {
    132                 if (next->frequency > entry->frequency) {
    133                         break;
    134                 }
    135 
    136                 prev = next;
    137                 next = next->next;
    138         }
    139 
    140         entry->prev = prev;
    141         entry->next = next;
    142 
    143         if (prev) {
    144                 prev->next = entry;
    145         } else {
    146                 hdhomerun_channel_list_head = entry;
    147         }
    148 
    149         if (next) {
    150                 next->prev = entry;
    151         } else {
    152                 hdhomerun_channel_list_tail = entry;
    153         }
     204        return channel_list->tail;
    154205}
    155206
    156 static void hdhomerun_channel_list_build_range(const struct hdhomerun_channel_map_range_t *range)
     207struct hdhomerun_channel_entry_t *hdhomerun_channel_list_next(struct hdhomerun_channel_list_t *channel_list, struct hdhomerun_channel_entry_t *entry)
    157208{
    158         uint8_t channel_number;
    159         for (channel_number = range->channel_range_start; channel_number <= range->channel_range_end; channel_number++) {
    160                 struct hdhomerun_channel_entry_t *entry = (struct hdhomerun_channel_entry_t *)calloc(1, sizeof(struct hdhomerun_channel_entry_t));
    161                 if (!entry) {
    162                         return;
    163                 }
    164 
    165                 entry->channel_map = range->channel_map;
    166                 entry->channel_number = channel_number;
    167                 entry->frequency = range->frequency + ((uint32_t)(channel_number - range->channel_range_start) * range->spacing);
    168                 entry->frequency = (entry->frequency / FREQUENCY_RESOLUTION) * FREQUENCY_RESOLUTION;
    169                 sprintf(entry->name, "%s:%u", hdhomerun_channel_map_name(entry->channel_map), entry->channel_number);
    170 
    171                 hdhomerun_channel_list_build_insert(entry);
    172         }
     209        return entry->next;
    173210}
    174211
    175 static void hdhomerun_channel_list_build(void)
     212struct hdhomerun_channel_entry_t *hdhomerun_channel_list_prev(struct hdhomerun_channel_list_t *channel_list, struct hdhomerun_channel_entry_t *entry)
    176213{
    177         const struct hdhomerun_channel_map_range_t *range = hdhomerun_channels_map_ranges;
    178         while (range->channel_map) {
    179                 hdhomerun_channel_list_build_range(range);
    180                 range++;
    181         }
     214        return entry->prev;
    182215}
    183216
    184 struct hdhomerun_channel_entry_t *hdhomerun_channel_list_first(uint32_t channel_map)
     217uint32_t hdhomerun_channel_list_total_count(struct hdhomerun_channel_list_t *channel_list)
    185218{
    186         if (!hdhomerun_channel_list_head) {
    187                 hdhomerun_channel_list_build();
    188         }
     219        uint32_t count = 0;
    189220
    190         struct hdhomerun_channel_entry_t *entry = hdhomerun_channel_list_head;
     221        struct hdhomerun_channel_entry_t *entry = hdhomerun_channel_list_first(channel_list);
    191222        while (entry) {
    192                 if (entry->channel_map & channel_map) {
    193                         return entry;
    194                 }
    195 
    196                 entry = entry->next;
     223                count++;
     224                entry = hdhomerun_channel_list_next(channel_list, entry);
    197225        }
    198226
    199         return NULL;
     227        return count;
    200228}
    201229
    202 struct hdhomerun_channel_entry_t *hdhomerun_channel_list_last(uint32_t channel_map)
     230uint32_t hdhomerun_channel_list_frequency_count(struct hdhomerun_channel_list_t *channel_list)
    203231{
    204         if (!hdhomerun_channel_list_head) {
    205                 hdhomerun_channel_list_build();
    206         }
     232        uint32_t count = 0;
     233        uint32_t last_frequency = 0;
    207234
    208         struct hdhomerun_channel_entry_t *entry = hdhomerun_channel_list_tail;
     235        struct hdhomerun_channel_entry_t *entry = hdhomerun_channel_list_first(channel_list);
    209236        while (entry) {
    210                 if (entry->channel_map & channel_map) {
    211                         return entry;
     237                if (entry->frequency != last_frequency) {
     238                        last_frequency = entry->frequency;
     239                        count++;
    212240                }
    213241
    214                 entry = entry->prev;
     242                entry = hdhomerun_channel_list_next(channel_list, entry);
    215243        }
    216244
    217         return NULL;
     245        return count;
     246}
     247
     248uint32_t hdhomerun_channel_frequency_truncate(uint32_t frequency)
     249{
     250        return (frequency / FREQUENCY_RESOLUTION) * FREQUENCY_RESOLUTION;
    218251}
    219252
    220 struct hdhomerun_channel_entry_t *hdhomerun_channel_list_next(uint32_t channel_map, struct hdhomerun_channel_entry_t *entry)
     253uint32_t hdhomerun_channel_number_to_frequency(struct hdhomerun_channel_list_t *channel_list, uint8_t channel_number)
    221254{
    222         entry = entry->next;
     255        struct hdhomerun_channel_entry_t *entry = hdhomerun_channel_list_first(channel_list);
    223256        while (entry) {
    224                 if (entry->channel_map & channel_map) {
    225                         return entry;
     257                if (entry->channel_number == channel_number) {
     258                        return entry->frequency;
    226259                }
    227260
    228                 entry = entry->next;
     261                entry = hdhomerun_channel_list_next(channel_list, entry);
    229262        }
    230263
    231         return NULL;
     264        return 0;
    232265}
    233266
    234 struct hdhomerun_channel_entry_t *hdhomerun_channel_list_prev(uint32_t channel_map, struct hdhomerun_channel_entry_t *entry)
     267uint8_t hdhomerun_channel_frequency_to_number(struct hdhomerun_channel_list_t *channel_list, uint32_t frequency)
    235268{
    236         entry = entry->prev;
     269        frequency = hdhomerun_channel_frequency_truncate(frequency);
     270
     271        struct hdhomerun_channel_entry_t *entry = hdhomerun_channel_list_first(channel_list);
    237272        while (entry) {
    238                 if (entry->channel_map & channel_map) {
    239                         return entry;
     273                if (entry->frequency == frequency) {
     274                        return entry->channel_number;
     275                }
     276                if (entry->frequency > frequency) {
     277                        return 0;
    240278                }
    241279
    242                 entry = entry->prev;
     280                entry = hdhomerun_channel_list_next(channel_list, entry);
    243281        }
    244282
    245         return NULL;
     283        return 0;
    246284}
    247285
    248 uint32_t hdhomerun_channel_list_total_count(uint32_t channel_map)
     286static void hdhomerun_channel_list_build_insert(struct hdhomerun_channel_list_t *channel_list, struct hdhomerun_channel_entry_t *entry)
    249287{
    250         uint32_t count = 0;
     288        struct hdhomerun_channel_entry_t *prev = NULL;
     289        struct hdhomerun_channel_entry_t *next = channel_list->head;
    251290
    252         struct hdhomerun_channel_entry_t *entry = hdhomerun_channel_list_first(channel_map);
    253         while (entry) {
    254                 count++;
    255                 entry = hdhomerun_channel_list_next(channel_map, entry);
     291        while (next) {
     292                if (next->frequency > entry->frequency) {
     293                        break;
     294                }
     295
     296                prev = next;
     297                next = next->next;
    256298        }
    257299
    258         return count;
     300        entry->prev = prev;
     301        entry->next = next;
     302
     303        if (prev) {
     304                prev->next = entry;
     305        } else {
     306                channel_list->head = entry;
     307        }
     308
     309        if (next) {
     310                next->prev = entry;
     311        } else {
     312                channel_list->tail = entry;
     313        }
    259314}
    260315
    261 uint32_t hdhomerun_channel_list_frequency_count(uint32_t channel_map)
     316static void hdhomerun_channel_list_build_range(struct hdhomerun_channel_list_t *channel_list, const char *channelmap, const struct hdhomerun_channelmap_range_t *range)
    262317{
    263         uint32_t count = 0;
    264         uint32_t last_frequency = 0;
    265 
    266         struct hdhomerun_channel_entry_t *entry = hdhomerun_channel_list_first(channel_map);
    267         while (entry) {
    268                 if (entry->frequency != last_frequency) {
    269                         last_frequency = entry->frequency;
    270                         count++;
     318        uint8_t channel_number;
     319        for (channel_number = range->channel_range_start; channel_number <= range->channel_range_end; channel_number++) {
     320                struct hdhomerun_channel_entry_t *entry = (struct hdhomerun_channel_entry_t *)calloc(1, sizeof(struct hdhomerun_channel_entry_t));
     321                if (!entry) {
     322                        return;
    271323                }
    272324
    273                 entry = hdhomerun_channel_list_next(channel_map, entry);
    274         }
     325                entry->channel_number = channel_number;
     326                entry->frequency = range->frequency + ((uint32_t)(channel_number - range->channel_range_start) * range->spacing);
     327                entry->frequency = hdhomerun_channel_frequency_truncate(entry->frequency);
     328                sprintf(entry->name, "%s:%u", channelmap, entry->channel_number);
    275329
    276         return count;
     330                hdhomerun_channel_list_build_insert(channel_list, entry);
     331        }
    277332}
    278333
    279 uint32_t hdhomerun_channel_number_to_frequency(uint32_t channel_map, uint8_t channel_number)
     334static void hdhomerun_channel_list_build_ranges(struct hdhomerun_channel_list_t *channel_list, const struct hdhomerun_channelmap_record_t *record)
    280335{
    281         struct hdhomerun_channel_entry_t *entry = hdhomerun_channel_list_first(channel_map);
    282         while (entry) {
    283                 if (entry->channel_number == channel_number) {
    284                         return entry->frequency;
    285                 }
     336        const struct hdhomerun_channelmap_range_t *range = record->range_list;
     337        while (range->frequency) {
     338                hdhomerun_channel_list_build_range(channel_list, record->channelmap, range);
     339                range++;
     340        }
     341}
    286342
    287                 entry = hdhomerun_channel_list_next(channel_map, entry);
     343void hdhomerun_channel_list_destroy(struct hdhomerun_channel_list_t *channel_list)
     344{
     345        while (channel_list->head) {
     346                struct hdhomerun_channel_entry_t *entry = channel_list->head;
     347                channel_list->head = entry->next;
     348                free(entry);
    288349        }
    289350
    290         return 0;
     351        free(channel_list);
    291352}
    292353
    293 uint8_t hdhomerun_channel_frequency_to_number(uint32_t channel_map, uint32_t frequency)
     354struct hdhomerun_channel_list_t *hdhomerun_channel_list_create(const char *channelmap)
    294355{
    295         frequency = (frequency / FREQUENCY_RESOLUTION) * FREQUENCY_RESOLUTION;
     356        struct hdhomerun_channel_list_t *channel_list = (struct hdhomerun_channel_list_t *)calloc(1, sizeof(struct hdhomerun_channel_list_t));
     357        if (!channel_list) {
     358                return NULL;
     359        }
    296360
    297         struct hdhomerun_channel_entry_t *entry = hdhomerun_channel_list_first(channel_map);
    298         while (entry) {
    299                 if (entry->frequency == frequency) {
    300                         return entry->channel_number;
    301                 }
    302                 if (entry->frequency > frequency) {
    303                         return 0;
     361        const struct hdhomerun_channelmap_record_t *record = hdhomerun_channelmap_table;
     362        while (record->channelmap) {
     363                if (!strstr(channelmap, record->channelmap)) {
     364                        record++;
     365                        continue;
    304366                }
    305367
    306                 entry = hdhomerun_channel_list_next(channel_map, entry);
     368                hdhomerun_channel_list_build_ranges(channel_list, record);
     369                record++;
    307370        }
    308371
    309         return 0;
     372        if (!channel_list->head) {
     373                free(channel_list);
     374                return NULL;
     375        }
     376
     377        return channel_list;
    310378}
  • mythtv/libs/libmythhdhomerun/hdhomerun_channels.h

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_channels.h myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_channels.h
     
    11/*
    22 * hdhomerun_channels.h
    33 *
    4  * Copyright © 2007-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2007-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    20 #define CHANNEL_MAP_US_BCAST (1 << 0)
    21 #define CHANNEL_MAP_US_CABLE (1 << 1)
    22 #define CHANNEL_MAP_US_HRC (1 << 2)
    23 #define CHANNEL_MAP_US_IRC (1 << 3)
    24 #define CHANNEL_MAP_US_ALL (CHANNEL_MAP_US_BCAST | CHANNEL_MAP_US_CABLE | CHANNEL_MAP_US_HRC | CHANNEL_MAP_US_IRC)
    25 
    26 #define CHANNEL_MAP_UK_BCAST (1 << 4)
    27 #define CHANNEL_MAP_NZ_BCAST (1 << 5)
     33#ifdef __cplusplus
     34extern "C" {
     35#endif
    2836
    2937struct hdhomerun_channel_entry_t;
     38struct hdhomerun_channel_list_t;
     39
     40extern LIBTYPE const char *hdhomerun_channelmap_convert_countrycode_to_channelmap_prefix(const char *countrycode);
     41extern LIBTYPE const char *hdhomerun_channelmap_get_channelmap_scan_group(const char *channelmap);
    3042
    31 extern LIBTYPE uint32_t hdhomerun_channel_entry_channel_map(struct hdhomerun_channel_entry_t *entry);
    3243extern LIBTYPE uint8_t hdhomerun_channel_entry_channel_number(struct hdhomerun_channel_entry_t *entry);
    3344extern LIBTYPE uint32_t hdhomerun_channel_entry_frequency(struct hdhomerun_channel_entry_t *entry);
    3445extern LIBTYPE const char *hdhomerun_channel_entry_name(struct hdhomerun_channel_entry_t *entry);
    3546
    36 extern LIBTYPE struct hdhomerun_channel_entry_t *hdhomerun_channel_list_first(uint32_t channel_map);
    37 extern LIBTYPE struct hdhomerun_channel_entry_t *hdhomerun_channel_list_last(uint32_t channel_map);
    38 extern LIBTYPE struct hdhomerun_channel_entry_t *hdhomerun_channel_list_next(uint32_t channel_map, struct hdhomerun_channel_entry_t *entry);
    39 extern LIBTYPE struct hdhomerun_channel_entry_t *hdhomerun_channel_list_prev(uint32_t channel_map, struct hdhomerun_channel_entry_t *entry);
    40 extern LIBTYPE uint32_t hdhomerun_channel_list_total_count(uint32_t channel_map);
    41 extern LIBTYPE uint32_t hdhomerun_channel_list_frequency_count(uint32_t channel_map);
     47extern LIBTYPE struct hdhomerun_channel_list_t *hdhomerun_channel_list_create(const char *channelmap);
     48extern LIBTYPE void hdhomerun_channel_list_destroy(struct hdhomerun_channel_list_t *channel_list);
    4249
    43 extern LIBTYPE uint32_t hdhomerun_channel_number_to_frequency(uint32_t channel_map, uint8_t channel_number);
    44 extern LIBTYPE uint8_t hdhomerun_channel_frequency_to_number(uint32_t channel_map, uint32_t frequency);
     50extern LIBTYPE struct hdhomerun_channel_entry_t *hdhomerun_channel_list_first(struct hdhomerun_channel_list_t *channel_list);
     51extern LIBTYPE struct hdhomerun_channel_entry_t *hdhomerun_channel_list_last(struct hdhomerun_channel_list_t *channel_list);
     52extern LIBTYPE struct hdhomerun_channel_entry_t *hdhomerun_channel_list_next(struct hdhomerun_channel_list_t *channel_list, struct hdhomerun_channel_entry_t *entry);
     53extern LIBTYPE struct hdhomerun_channel_entry_t *hdhomerun_channel_list_prev(struct hdhomerun_channel_list_t *channel_list, struct hdhomerun_channel_entry_t *entry);
     54extern LIBTYPE uint32_t hdhomerun_channel_list_total_count(struct hdhomerun_channel_list_t *channel_list);
     55extern LIBTYPE uint32_t hdhomerun_channel_list_frequency_count(struct hdhomerun_channel_list_t *channel_list);
     56
     57extern LIBTYPE uint32_t hdhomerun_channel_frequency_truncate(uint32_t frequency);
     58extern LIBTYPE uint32_t hdhomerun_channel_number_to_frequency(struct hdhomerun_channel_list_t *channel_list, uint8_t channel_number);
     59extern LIBTYPE uint8_t hdhomerun_channel_frequency_to_number(struct hdhomerun_channel_list_t *channel_list, uint32_t frequency);
     60
     61#ifdef __cplusplus
     62}
     63#endif
  • mythtv/libs/libmythhdhomerun/hdhomerun_channelscan.c

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_channelscan.c myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_channelscan.c
     
    11/*
    22 * hdhomerun_channelscan.c
    33 *
    4  * Copyright © 2007-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2007-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033#include "hdhomerun.h"
    2134
    2235struct hdhomerun_channelscan_t {
    2336        struct hdhomerun_device_t *hd;
    24         uint32_t channel_map;
    25         uint32_t options;
    2637        uint32_t scanned_channels;
     38        struct hdhomerun_channel_list_t *channel_list; 
    2739        struct hdhomerun_channel_entry_t *next_channel;
    2840};
    2941
    30 struct hdhomerun_channelscan_t *channelscan_create(struct hdhomerun_device_t *hd, uint32_t channel_map, uint32_t options)
     42struct hdhomerun_channelscan_t *channelscan_create(struct hdhomerun_device_t *hd, const char *channelmap)
    3143{
    3244        struct hdhomerun_channelscan_t *scan = (struct hdhomerun_channelscan_t *)calloc(1, sizeof(struct hdhomerun_channelscan_t));
    3345        if (!scan) {
    struct hdhomerun_channelscan_t *channels 
    3547        }
    3648
    3749        scan->hd = hd;
    38         scan->channel_map = channel_map;
    39         scan->options = options;
    4050
    41         if (scan->options & HDHOMERUN_CHANNELSCAN_OPTION_REVERSE) {
    42                 scan->next_channel = hdhomerun_channel_list_last(channel_map);
    43         } else {
    44                 scan->next_channel = hdhomerun_channel_list_first(channel_map);
     51        scan->channel_list = hdhomerun_channel_list_create(channelmap);
     52        if (!scan->channel_list) {
     53                free(scan);
     54                return NULL;
    4555        }
    4656
     57        scan->next_channel = hdhomerun_channel_list_last(scan->channel_list);
    4758        return scan;
    4859}
    4960
    void channelscan_destroy(struct hdhomeru 
    5263        free(scan);
    5364}
    5465
    55 static struct hdhomerun_channel_entry_t *channelscan_advance_channel_internal(struct hdhomerun_channelscan_t *scan, struct hdhomerun_channel_entry_t *entry)
    56 {
    57         if (scan->options & HDHOMERUN_CHANNELSCAN_OPTION_REVERSE) {
    58                 return hdhomerun_channel_list_prev(scan->channel_map, entry);
    59         } else {
    60                 return hdhomerun_channel_list_next(scan->channel_map, entry);
    61         }
    62 }
    63 
    6466static int channelscan_execute_find_lock(struct hdhomerun_channelscan_t *scan, uint32_t frequency, struct hdhomerun_channelscan_result_t *result)
    6567{
    6668        /* Set channel. */
    static int channelscan_execute_find_lock 
    100102        return 1;
    101103}
    102104
     105static void channelscan_extract_name(struct hdhomerun_channelscan_program_t *program, const char *line)
     106{
     107        /* Find start of name. */
     108        const char *start = strchr(line, ' ');
     109        if (!start) {
     110                return;
     111        }
     112        start++;
     113
     114        start = strchr(start, ' ');
     115        if (!start) {
     116                return;
     117        }
     118        start++;
     119
     120        /* Find end of name. */
     121        const char *end = strstr(start, " (");
     122        if (!end) {
     123                end = strchr(line, 0);
     124        }
     125
     126        if (end <= start) {
     127                return;
     128        }
     129
     130        /* Extract name. */
     131        size_t length = (size_t)(end - start);
     132        if (length > sizeof(program->name) - 1) {
     133                length = sizeof(program->name) - 1;
     134        }
     135
     136        strncpy(program->name, start, length);
     137        program->name[length] = 0;
     138}
     139
    103140static int channelscan_execute_detect_programs(struct hdhomerun_channelscan_t *scan, struct hdhomerun_channelscan_result_t *result, int *pchanged)
    104141{
    105142        *pchanged = FALSE;
    static int channelscan_execute_detect_pr 
    129166
    130167                unsigned int program_number;
    131168                unsigned int virtual_major, virtual_minor;
    132                 if (sscanf(line, "%u: %u.%u %7s", &program_number, &virtual_major, &virtual_minor, program.name) != 4) {
    133                         if (sscanf(line, "%u: %u.%u", &program_number, &virtual_major, &virtual_minor) != 3) {
    134                                 continue;
    135                         }
     169                if (sscanf(line, "%u: %u.%u", &program_number, &virtual_major, &virtual_minor) != 3) {
     170                        continue;
    136171                }
    137172
    138173                program.program_number = program_number;
    139174                program.virtual_major = virtual_major;
    140175                program.virtual_minor = virtual_minor;
    141176
    142                 if (program.name[0] == '(') {
    143                         memset(program.name, 0, sizeof(program.name));
    144                 }
     177                channelscan_extract_name(&program, line);
    145178
    146179                program.type = HDHOMERUN_CHANNELSCAN_PROGRAM_NORMAL;
    147180                if (strstr(line, "(no data)")) {
    int channelscan_advance(struct hdhomerun 
    186219
    187220        /* Combine channels with same frequency. */
    188221        result->frequency = hdhomerun_channel_entry_frequency(entry);
    189         result->channel_map = hdhomerun_channel_entry_channel_map(entry);
    190         strcpy(result->channel_str, hdhomerun_channel_entry_name(entry));
     222        strncpy(result->channel_str, hdhomerun_channel_entry_name(entry), sizeof(result->channel_str) - 1);
     223        result->channel_str[sizeof(result->channel_str) - 1] = 0;
    191224
    192225        while (1) {
    193                 entry = channelscan_advance_channel_internal(scan, entry);
     226                entry = hdhomerun_channel_list_prev(scan->channel_list, entry);
    194227                if (!entry) {
    195228                        scan->next_channel = NULL;
    196229                        break;
    int channelscan_advance(struct hdhomerun 
    203236
    204237                char *ptr = strchr(result->channel_str, 0);
    205238                sprintf(ptr, ", %s", hdhomerun_channel_entry_name(entry));
    206                 result->channel_map |= hdhomerun_channel_entry_channel_map(entry);
    207239        }
    208240
    209241        return 1;
    int channelscan_detect(struct hdhomerun_ 
    222254                return 1;
    223255        }
    224256
    225         /* Refine channel map. */
    226         if ((scan->options & HDHOMERUN_CHANNELSCAN_OPTION_REFINE_CHANNEL_MAP) && (result->status.symbol_error_quality == 100)) {
    227                 scan->channel_map = result->channel_map;
    228 
    229                 /* Fixup next channel. */
    230                 struct hdhomerun_channel_entry_t *entry = scan->next_channel;
    231                 if (entry && (hdhomerun_channel_entry_channel_map(entry) & scan->channel_map) == 0) {
    232                         scan->next_channel = channelscan_advance_channel_internal(scan, entry);
    233                 }
    234         }
    235 
    236257        /* Detect programs. */
    237258        result->program_count = 0;
    238259
    uint8_t channelscan_get_progress(struct  
    278299        uint32_t frequency = hdhomerun_channel_entry_frequency(entry);
    279300
    280301        while (1) {
    281                 entry = channelscan_advance_channel_internal(scan, entry);
     302                entry = hdhomerun_channel_list_prev(scan->channel_list, entry);
    282303                if (!entry) {
    283304                        break;
    284305                }
  • mythtv/libs/libmythhdhomerun/hdhomerun_channelscan.h

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_channelscan.h myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_channelscan.h
     
    11/*
    22 * hdhomerun_channelscan.h
    33 *
    4  * Copyright © 2007-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2007-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
     33#ifdef __cplusplus
     34extern "C" {
     35#endif
     36
    2037#define HDHOMERUN_CHANNELSCAN_PROGRAM_NORMAL 0
    2138#define HDHOMERUN_CHANNELSCAN_PROGRAM_NODATA 1
    2239#define HDHOMERUN_CHANNELSCAN_PROGRAM_CONTROL 2
    2340#define HDHOMERUN_CHANNELSCAN_PROGRAM_ENCRYPTED 3
    2441
    25 #define HDHOMERUN_CHANNELSCAN_OPTION_REVERSE (1 << 0)
    26 #define HDHOMERUN_CHANNELSCAN_OPTION_REFINE_CHANNEL_MAP (1 << 1)
    27 
    2842struct hdhomerun_channelscan_t;
    2943
    30 extern LIBTYPE struct hdhomerun_channelscan_t *channelscan_create(struct hdhomerun_device_t *hd, uint32_t channel_map, uint32_t options);
     44extern LIBTYPE struct hdhomerun_channelscan_t *channelscan_create(struct hdhomerun_device_t *hd, const char *channelmap);
    3145extern LIBTYPE void channelscan_destroy(struct hdhomerun_channelscan_t *scan);
    3246
    3347extern LIBTYPE int channelscan_advance(struct hdhomerun_channelscan_t *scan, struct hdhomerun_channelscan_result_t *result);
    3448extern LIBTYPE int channelscan_detect(struct hdhomerun_channelscan_t *scan, struct hdhomerun_channelscan_result_t *result);
    3549extern LIBTYPE uint8_t channelscan_get_progress(struct hdhomerun_channelscan_t *scan);
     50
     51#ifdef __cplusplus
     52}
     53#endif
  • mythtv/libs/libmythhdhomerun/hdhomerun_config.c

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_config.c myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_config.c
     
    11/*
    22 * hdhomerun_config.c
    33 *
    4  * Copyright © 2006-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033#include "hdhomerun.h"
    2134
     35/*
     36 * The console output format should be set to UTF-8, however in XP and Vista this breaks batch file processing.
     37 * Attempting to restore on exit fails to restore if the program is terminated by the user.
     38 * Solution - set the output format each printf.
     39 */
     40#if defined(__WINDOWS__)
     41#define printf console_printf
     42#define vprintf console_vprintf
     43#endif
     44
    2245static const char *appname;
    2346
    2447struct hdhomerun_device_t *hd;
    static int cmd_get(const char *item) 
    131154        return 1;
    132155}
    133156
    134 static int cmd_set(const char *item, const char *value)
     157static int cmd_set_internal(const char *item, const char *value)
    135158{
    136159        char *ret_error;
    137160        if (hdhomerun_device_set_var(hd, item, value, NULL, &ret_error) < 0) {
    static int cmd_set(const char *item, con 
    147170        return 1;
    148171}
    149172
     173static int cmd_set(const char *item, const char *value)
     174{
     175        if (strcmp(value, "-") == 0) {
     176                char *buffer = NULL;
     177                size_t pos = 0;
     178
     179                while (1) {
     180                        buffer = (char *)realloc(buffer, pos + 1024);
     181                        if (!buffer) {
     182                                fprintf(stderr, "out of memory\n");
     183                                return -1;
     184                        }
     185
     186                        int size = fread(buffer + pos, 1, 1024, stdin);
     187                        pos += size;
     188
     189                        if (size < 1024) {
     190                                break;
     191                        }
     192                }
     193
     194                buffer[pos] = 0;
     195
     196                int ret = cmd_set_internal(item, buffer);
     197
     198                free(buffer);
     199                return ret;
     200        }
     201
     202        return cmd_set_internal(item, value);
     203}
     204
    150205static void cmd_scan_printf(FILE *fp, const char *fmt, ...)
    151206{
    152207        va_list ap;
    static int cmd_scan(const char *tuner_st 
    175230                return -1;
    176231        }
    177232
    178         uint32_t channel_map = hdhomerun_device_model_channel_map_all(hd);
    179         if (channel_map == 0) {
    180                 fprintf(stderr, "failed to detect channel_map set\n");
     233        char *channelmap;
     234        if (hdhomerun_device_get_tuner_channelmap(hd, &channelmap) <= 0) {
     235                fprintf(stderr, "failed to query channelmap from device\n");
    181236                return -1;
    182237        }
    183238
    184         if (hdhomerun_device_channelscan_init(hd, channel_map, 0) <= 0) {
     239        const char *channelmap_scan_group = hdhomerun_channelmap_get_channelmap_scan_group(channelmap);
     240        if (!channelmap_scan_group) {
     241                fprintf(stderr, "unknown channelmap '%s'\n", channelmap);
     242                return -1;
     243        }
     244
     245        if (hdhomerun_device_channelscan_init(hd, channelmap_scan_group) <= 0) {
    185246                fprintf(stderr, "failed to initialize channel scan\n");
    186247                return -1;
    187248        }
    static void cmd_save_abort(int junk) 
    238299        struct hdhomerun_video_stats_t stats;
    239300        hdhomerun_device_get_video_stats(hd, &stats);
    240301        hdhomerun_device_stream_stop(hd);
     302        hdhomerun_device_destroy(hd);
    241303
    242304        fprintf(stderr, "\n");
    243305        fprintf(stderr, "-- Video statistics --\n");
    static int cmd_save(const char *tuner_st 
    257319                return -1;
    258320        }
    259321
    260         FILE *fp = NULL;
    261 
    262         if (strcmp(filename, "-") == 0) {
     322        FILE *fp;
     323        if (strcmp(filename, "null") == 0) {
     324                fp = NULL;
     325        } else if (strcmp(filename, "-") == 0) {
    263326                fp = stdout;
    264         } else if (strcmp(filename, "null") != 0) {
     327        } else {
    265328                fp = fopen(filename, "wb");
    266 
    267329                if (!fp) {
    268330                        fprintf(stderr, "unable to create file %s\n", filename);
    269331                        return -1;
    270332                }
    271333        }
    272334
    273         signal(SIGINT, cmd_save_abort);
    274         signal(SIGPIPE, cmd_save_abort);
    275 
    276335        int ret = hdhomerun_device_stream_start(hd);
    277336        if (ret <= 0) {
    278337                fprintf(stderr, "unable to start stream\n");
    279                 fclose(fp);
    280338                return ret;
    281339        }
    282340
     341        signal(SIGINT, cmd_save_abort);
     342        signal(SIGPIPE, cmd_save_abort);
     343
    283344        struct hdhomerun_video_stats_t stats_old, stats_cur;
    284345        hdhomerun_device_get_video_stats(hd, &stats_old);
    285346
    static int cmd_save(const char *tuner_st 
    294355                }
    295356
    296357                if (fp) {
    297                         fwrite(ptr, 1, actual_size, fp);
     358                        if (fwrite(ptr, 1, actual_size, fp) != actual_size) {
     359                                fprintf(stderr, "error writing output\n");
     360                                return -1;
     361                        }
    298362                }
    299363
    300364                uint64_t current_time = getcurrenttime();
    static int main_cmd(int argc, char *argv 
    413477static int main_internal(int argc, char *argv[])
    414478{
    415479#if defined(__WINDOWS__)
     480        /* Initialize network socket support. */
    416481        WORD wVersionRequested = MAKEWORD(2, 0);
    417482        WSADATA wsaData;
    418483        WSAStartup(wVersionRequested, &wsaData);
  • mythtv/libs/libmythhdhomerun/hdhomerun_control.c

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_control.c myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_control.c
     
    11/*
    22 * hdhomerun_control.c
    33 *
    4  * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033#include "hdhomerun.h"
    int hdhomerun_control_send_recv(struct h 
    276289        return hdhomerun_control_send_recv_internal(cs, tx_pkt, rx_pkt, type, HDHOMERUN_CONTROL_RECV_TIMEOUT);
    277290}
    278291
    279 static int hdhomerun_control_get_set(struct hdhomerun_control_sock_t *cs, const char *name, const char *value, char **pvalue, char **perror)
     292static int hdhomerun_control_get_set(struct hdhomerun_control_sock_t *cs, const char *name, const char *value, uint32_t lockkey, char **pvalue, char **perror)
    280293{
    281294        struct hdhomerun_pkt_t *tx_pkt = &cs->tx_pkt;
    282295        struct hdhomerun_pkt_t *rx_pkt = &cs->rx_pkt;
    static int hdhomerun_control_get_set(str 
    285298        hdhomerun_pkt_reset(tx_pkt);
    286299
    287300        int name_len = (int)strlen(name) + 1;
     301        if (tx_pkt->end + 3 + name_len > tx_pkt->limit) {
     302                return -1;
     303        }
    288304        hdhomerun_pkt_write_u8(tx_pkt, HDHOMERUN_TAG_GETSET_NAME);
    289305        hdhomerun_pkt_write_var_length(tx_pkt, name_len);
    290306        hdhomerun_pkt_write_mem(tx_pkt, (const void *)name, name_len);
    291307
    292308        if (value) {
    293309                int value_len = (int)strlen(value) + 1;
     310                if (tx_pkt->end + 3 + value_len > tx_pkt->limit) {
     311                        return -1;
     312                }
    294313                hdhomerun_pkt_write_u8(tx_pkt, HDHOMERUN_TAG_GETSET_VALUE);
    295314                hdhomerun_pkt_write_var_length(tx_pkt, value_len);
    296315                hdhomerun_pkt_write_mem(tx_pkt, (const void *)value, value_len);
    297316        }
    298317
     318        if (lockkey != 0) {
     319                if (tx_pkt->end + 6 > tx_pkt->limit) {
     320                        return -1;
     321                }
     322                hdhomerun_pkt_write_u8(tx_pkt, HDHOMERUN_TAG_GETSET_LOCKKEY);
     323                hdhomerun_pkt_write_var_length(tx_pkt, 4);
     324                hdhomerun_pkt_write_u32(tx_pkt, lockkey);
     325        }
     326
    299327        /* Send/Recv. */
    300328        if (hdhomerun_control_send_recv_internal(cs, tx_pkt, rx_pkt, HDHOMERUN_TYPE_GETSET_REQ, HDHOMERUN_CONTROL_RECV_TIMEOUT) < 0) {
    301329                return -1;
    static int hdhomerun_control_get_set(str 
    341369
    342370int hdhomerun_control_get(struct hdhomerun_control_sock_t *cs, const char *name, char **pvalue, char **perror)
    343371{
    344         return hdhomerun_control_get_set(cs, name, NULL, pvalue, perror);
     372        return hdhomerun_control_get_set(cs, name, NULL, 0, pvalue, perror);
    345373}
    346374
    347375int hdhomerun_control_set(struct hdhomerun_control_sock_t *cs, const char *name, const char *value, char **pvalue, char **perror)
    348376{
    349         return hdhomerun_control_get_set(cs, name, value, pvalue, perror);
     377        return hdhomerun_control_get_set(cs, name, value, 0, pvalue, perror);
     378}
     379
     380int hdhomerun_control_set_with_lockkey(struct hdhomerun_control_sock_t *cs, const char *name, const char *value, uint32_t lockkey, char **pvalue, char **perror)
     381{
     382        return hdhomerun_control_get_set(cs, name, value, lockkey, pvalue, perror);
    350383}
    351384
    352385int hdhomerun_control_upgrade(struct hdhomerun_control_sock_t *cs, FILE *upgrade_file)
  • mythtv/libs/libmythhdhomerun/hdhomerun_control.h

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_control.h myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_control.h
     
    11/*
    22 * hdhomerun_control.h
    33 *
    4  * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932#ifdef __cplusplus
    2033extern "C" {
    extern LIBTYPE int hdhomerun_control_sen 
    8396 */
    8497extern LIBTYPE int hdhomerun_control_get(struct hdhomerun_control_sock_t *cs, const char *name, char **pvalue, char **perror);
    8598extern LIBTYPE int hdhomerun_control_set(struct hdhomerun_control_sock_t *cs, const char *name, const char *value, char **pvalue, char **perror);
     99extern LIBTYPE int hdhomerun_control_set_with_lockkey(struct hdhomerun_control_sock_t *cs, const char *name, const char *value, uint32_t lockkey, char **pvalue, char **perror);
    86100
    87101/*
    88102 * Upload new firmware to the device.
  • mythtv/libs/libmythhdhomerun/hdhomerun_debug.c

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_debug.c myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_debug.c
     
    11/*
    22 * hdhomerun_debug.c
    33 *
    4  * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033/*
    void hdhomerun_debug_vprintf(struct hdho 
    240253        char *end = message->buffer + sizeof(message->buffer) - 2;
    241254        *end = 0;
    242255
    243         time_t t = time(NULL);
    244         strftime(ptr, end - ptr, "%Y%m%d-%H:%M:%S ", localtime(&t));
    245         ptr = strchr(ptr, 0);
     256        /*
     257         * Timestamp.
     258         */
     259        time_t current_time = time(NULL);
     260        ptr += strftime(ptr, end - ptr, "%Y%m%d-%H:%M:%S ", localtime(&current_time));
     261        if (ptr > end) {
     262                ptr = end;
     263        }
    246264
     265        /*
     266         * Debug prefix.
     267         */
    247268        pthread_mutex_lock(&dbg->print_lock);
    248269
    249270        if (dbg->prefix) {
    250                 snprintf(ptr, end - ptr, "%s ", dbg->prefix);
    251                 ptr = strchr(ptr, 0);
     271                int len = snprintf(ptr, end - ptr, "%s ", dbg->prefix);
     272                len = (len <= 0) ? 0 : len;
     273                ptr += len;
     274                if (ptr > end) {
     275                        ptr = end;
     276                }
    252277        }
    253278
    254279        pthread_mutex_unlock(&dbg->print_lock);
    255280
    256         vsnprintf(ptr, end - ptr, fmt, args);
    257 
    258         ptr = strchr(ptr, 0) - 1;
    259         if (*ptr++ != '\n') {
    260                 strcpy(ptr, "\n");
    261         }
    262 
     281        /*
     282         * Message text.
     283         */
     284        int len = vsnprintf(ptr, end - ptr, fmt, args);
     285        len = (len < 0) ? 0 : len; /* len does not include null */
     286        ptr += len;
     287        if (ptr > end) {
     288                ptr = end;
     289        }
     290
     291        /*
     292         * Force newline.
     293         */
     294        if ((ptr[-1] != '\n') && (ptr + 1 <= end)) {
     295                *ptr++ = '\n';
     296        }
     297
     298        /*
     299         * Force NULL.
     300         */
     301        if (ptr + 1 > end) {
     302                ptr = end - 1;
     303        }
     304        *ptr++ = 0;
     305
     306        /*
     307         * Enqueue.
     308         */
    263309        pthread_mutex_lock(&dbg->queue_lock);
    264310
    265311        message->prev = NULL;
  • mythtv/libs/libmythhdhomerun/hdhomerun_debug.h

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_debug.h myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_debug.h
     
    11/*
    22 * hdhomerun_debug.h
    33 *
    4  * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033/*
  • mythtv/libs/libmythhdhomerun/hdhomerun_device.c

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_device.c myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_device.c
     
    11/*
    22 * hdhomerun_device.c
    33 *
    4  * Copyright © 2006-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033#include "hdhomerun.h"
    struct hdhomerun_device_t { 
    2538        struct hdhomerun_debug_t *dbg;
    2639        struct hdhomerun_channelscan_t *scan;
    2740        unsigned int tuner;
     41        uint32_t lockkey;
    2842        char name[32];
    2943        char model[32];
    3044};
    static uint32_t hdhomerun_device_get_sta 
    275289        return (uint32_t)value;
    276290}
    277291
     292static bool_t hdhomerun_device_get_tuner_status_lock_is_bcast(struct hdhomerun_tuner_status_t *status)
     293{
     294        if (strcmp(status->lock_str, "8vsb") == 0) {
     295                return TRUE;
     296        }
     297        if (strncmp(status->lock_str, "t8", 2) == 0) {
     298                return TRUE;
     299        }
     300        if (strncmp(status->lock_str, "t7", 2) == 0) {
     301                return TRUE;
     302        }
     303        if (strncmp(status->lock_str, "t6", 2) == 0) {
     304                return TRUE;
     305        }
     306
     307        return FALSE;
     308}
     309
    278310uint32_t hdhomerun_device_get_tuner_status_ss_color(struct hdhomerun_tuner_status_t *status)
    279311{
    280312        unsigned int ss_yellow_min;
    281313        unsigned int ss_green_min;
    282314
    283         if (strstr(status->lock_str, "8vsb")) {
     315        if (!status->lock_supported) {
     316                return HDHOMERUN_STATUS_COLOR_NEUTRAL;
     317        }
     318
     319        if (hdhomerun_device_get_tuner_status_lock_is_bcast(status)) {
    284320                ss_yellow_min = 50;     /* -30dBmV */
    285321                ss_green_min = 75;      /* -15dBmV */
    286         } else if (strstr(status->lock_str, "qam64")) {
    287                 ss_yellow_min = 80;     /* -12dBmV */
    288                 ss_green_min = 90;      /* -6dBmV */
    289         } else if (strstr(status->lock_str, "qam256")) {
     322        } else {
    290323                ss_yellow_min = 80;     /* -12dBmV */
    291324                ss_green_min = 90;      /* -6dBmV */
    292         } else {
    293                 return HDHOMERUN_STATUS_COLOR_NEUTRAL;
    294325        }
    295326
    296327        if (status->signal_strength >= ss_green_min) {
    uint32_t hdhomerun_device_get_tuner_stat 
    305336
    306337uint32_t hdhomerun_device_get_tuner_status_snq_color(struct hdhomerun_tuner_status_t *status)
    307338{
    308         if (status->signal_to_noise_quality >= 60) {
     339        if (status->signal_to_noise_quality >= 70) {
    309340                return HDHOMERUN_STATUS_COLOR_GREEN;
    310341        }
    311         if (status->signal_to_noise_quality >= 40) {
     342        if (status->signal_to_noise_quality >= 50) {
    312343                return HDHOMERUN_STATUS_COLOR_YELLOW;
    313344        }
    314345
    int hdhomerun_device_get_tuner_plotsampl 
    461492        return 1;
    462493}
    463494
     495int hdhomerun_device_get_tuner_lockkey_owner(struct hdhomerun_device_t *hd, char **powner)
     496{
     497        char name[32];
     498        sprintf(name, "/tuner%u/lockkey", hd->tuner);
     499        return hdhomerun_control_get(hd->cs, name, powner, NULL);
     500}
     501
    464502int hdhomerun_device_get_ir_target(struct hdhomerun_device_t *hd, char **ptarget)
    465503{
    466504        return hdhomerun_control_get(hd->cs, "/ir/target", ptarget, NULL);
    int hdhomerun_device_set_tuner_channel(s 
    499537{
    500538        char name[32];
    501539        sprintf(name, "/tuner%u/channel", hd->tuner);
    502         return hdhomerun_control_set(hd->cs, name, channel, NULL, NULL);
     540        return hdhomerun_control_set_with_lockkey(hd->cs, name, channel, hd->lockkey, NULL, NULL);
    503541}
    504542
    505543int hdhomerun_device_set_tuner_channelmap(struct hdhomerun_device_t *hd, const char *channelmap)
    506544{
    507545        char name[32];
    508546        sprintf(name, "/tuner%u/channelmap", hd->tuner);
    509         return hdhomerun_control_set(hd->cs, name, channelmap, NULL, NULL);
     547        return hdhomerun_control_set_with_lockkey(hd->cs, name, channelmap, hd->lockkey, NULL, NULL);
    510548}
    511549
    512550int hdhomerun_device_set_tuner_filter(struct hdhomerun_device_t *hd, const char *filter)
    513551{
    514552        char name[32];
    515553        sprintf(name, "/tuner%u/filter", hd->tuner);
    516         return hdhomerun_control_set(hd->cs, name, filter, NULL, NULL);
     554        return hdhomerun_control_set_with_lockkey(hd->cs, name, filter, hd->lockkey, NULL, NULL);
    517555}
    518556
    519557static int hdhomerun_device_set_tuner_filter_by_array_append(char **pptr, char *end, uint16_t range_begin, uint16_t range_end)
    int hdhomerun_device_set_tuner_filter_by 
    578616        /* Remove trailing space. */
    579617        if (ptr > filter) {
    580618                ptr--;
    581                 *ptr = 0;
    582619        }
     620        *ptr = 0;
    583621
    584622        return hdhomerun_device_set_tuner_filter(hd, filter);
    585623}
    int hdhomerun_device_set_tuner_program(s 
    588626{
    589627        char name[32];
    590628        sprintf(name, "/tuner%u/program", hd->tuner);
    591         return hdhomerun_control_set(hd->cs, name, program, NULL, NULL);
     629        return hdhomerun_control_set_with_lockkey(hd->cs, name, program, hd->lockkey, NULL, NULL);
    592630}
    593631
    594632int hdhomerun_device_set_tuner_target(struct hdhomerun_device_t *hd, const char *target)
    595633{
    596634        char name[32];
    597635        sprintf(name, "/tuner%u/target", hd->tuner);
    598         return hdhomerun_control_set(hd->cs, name, target, NULL, NULL);
     636        return hdhomerun_control_set_with_lockkey(hd->cs, name, target, hd->lockkey, NULL, NULL);
    599637}
    600638
    601639int hdhomerun_device_set_tuner_target_to_local_protocol(struct hdhomerun_device_t *hd, const char *protocol)
    int hdhomerun_device_set_var(struct hdho 
    645683        return hdhomerun_control_set(hd->cs, name, value, pvalue, perror);
    646684}
    647685
     686int hdhomerun_device_tuner_lockkey_request(struct hdhomerun_device_t *hd)
     687{
     688        uint32_t new_lockkey = (uint32_t)getcurrenttime();
     689
     690        char name[32];
     691        sprintf(name, "/tuner%u/lockkey", hd->tuner);
     692
     693        char new_lockkey_str[64];
     694        sprintf(new_lockkey_str, "%u", (unsigned int)new_lockkey);
     695
     696        int ret = hdhomerun_control_set_with_lockkey(hd->cs, name, new_lockkey_str, hd->lockkey, NULL, NULL);
     697        if (ret <= 0) {
     698                hd->lockkey = 0;
     699                return ret;
     700        }
     701
     702        hd->lockkey = new_lockkey;
     703        return ret;
     704}
     705
     706int hdhomerun_device_tuner_lockkey_release(struct hdhomerun_device_t *hd)
     707{
     708        if (hd->lockkey == 0) {
     709                return 1;
     710        }
     711
     712        char name[32];
     713        sprintf(name, "/tuner%u/lockkey", hd->tuner);
     714        int ret = hdhomerun_control_set_with_lockkey(hd->cs, name, "none", hd->lockkey, NULL, NULL);
     715
     716        hd->lockkey = 0;
     717        return ret;
     718}
     719
    648720int hdhomerun_device_wait_for_lock(struct hdhomerun_device_t *hd, struct hdhomerun_tuner_status_t *status)
    649721{
    650722        /* Wait for up to 2.5 seconds for lock. */
    void hdhomerun_device_stream_stop(struct 
    708780        hdhomerun_device_set_tuner_target(hd, "none");
    709781}
    710782
    711 int hdhomerun_device_channelscan_init(struct hdhomerun_device_t *hd, uint32_t channel_map, uint32_t options)
     783int hdhomerun_device_channelscan_init(struct hdhomerun_device_t *hd, const char *channelmap)
    712784{
    713785        if (hd->scan) {
    714786                channelscan_destroy(hd->scan);
    715787        }
    716788
    717         hd->scan = channelscan_create(hd, channel_map, options);
     789        hd->scan = channelscan_create(hd, channelmap);
    718790        if (!hd->scan) {
    719791                return -1;
    720792        }
    const char *hdhomerun_device_get_model_s 
    787859                return NULL;
    788860        }
    789861        if (ret == 0) {
    790                 strcpy(hd->model, "hdhomerun_atsc");
    791                 return hd->model;
     862                model_str = "hdhomerun_atsc";
    792863        }
    793864
    794         strcpy(hd->model, model_str);
    795         return hd->model;
    796 }
     865        strncpy(hd->model, model_str, sizeof(hd->model) - 1);
     866        hd->model[sizeof(hd->model) - 1] = 0;
    797867
    798 uint32_t hdhomerun_device_model_channel_map_all(struct hdhomerun_device_t *hd)
    799 {
    800         return hdhomerun_device_model_channel_map_antenna(hd) | hdhomerun_device_model_channel_map_cable(hd);
    801 }
    802 
    803 uint32_t hdhomerun_device_model_channel_map_antenna(struct hdhomerun_device_t *hd)
    804 {
    805         const char *model = hdhomerun_device_get_model_str(hd);
    806         if (!model) {
    807                 return 0;
    808         }
    809 
    810         if (strstr(model, "atsc")) {
    811                 return CHANNEL_MAP_US_BCAST;
    812         }
    813 
    814         if (strstr(model, "dvbt")) {
    815                 return CHANNEL_MAP_UK_BCAST | CHANNEL_MAP_NZ_BCAST;
    816         }
    817 
    818         return 0;
    819 }
    820 
    821 uint32_t hdhomerun_device_model_channel_map_cable(struct hdhomerun_device_t *hd)
    822 {
    823         const char *model = hdhomerun_device_get_model_str(hd);
    824         if (!model) {
    825                 return 0;
    826         }
    827 
    828         if (strstr(model, "atsc")) {
    829                 return CHANNEL_MAP_US_CABLE | CHANNEL_MAP_US_HRC | CHANNEL_MAP_US_IRC;
    830         }
    831 
    832         return 0;
     868        return hd->model;
    833869}
    834870
    835871int hdhomerun_device_upgrade(struct hdhomerun_device_t *hd, FILE *upgrade_file)
    836872{
     873        hdhomerun_control_set(hd->cs, "/tuner0/lockkey", "force", NULL, NULL);
    837874        hdhomerun_control_set(hd->cs, "/tuner0/channel", "none", NULL, NULL);
     875
     876        hdhomerun_control_set(hd->cs, "/tuner1/lockkey", "force", NULL, NULL);
    838877        hdhomerun_control_set(hd->cs, "/tuner1/channel", "none", NULL, NULL);
     878
    839879        return hdhomerun_control_upgrade(hd->cs, upgrade_file);
    840880}
    841881
  • mythtv/libs/libmythhdhomerun/hdhomerun_device.h

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_device.h myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_device.h
     
    11/*
    22 * hdhomerun_device.h
    33 *
    4  * Copyright © 2006-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033#ifdef __cplusplus
    extern "C" { 
    2841#define HDHOMERUN_STATUS_COLOR_NEUTRAL  0xFFFFFFFF
    2942#define HDHOMERUN_STATUS_COLOR_RED              0xFFFF0000
    3043#define HDHOMERUN_STATUS_COLOR_YELLOW   0xFFFFFF00
    31 #define HDHOMERUN_STATUS_COLOR_GREEN    0xFF008000
     44#define HDHOMERUN_STATUS_COLOR_GREEN    0xFF00C000
    3245
    3346#define HDHOMERUN_TARGET_PROTOCOL_UDP "udp"
    3447#define HDHOMERUN_TARGET_PROTOCOL_RTP "rtp"
    extern LIBTYPE int hdhomerun_device_get_ 
    112125extern LIBTYPE int hdhomerun_device_get_tuner_program(struct hdhomerun_device_t *hd, char **pprogram);
    113126extern LIBTYPE int hdhomerun_device_get_tuner_target(struct hdhomerun_device_t *hd, char **ptarget);
    114127extern LIBTYPE int hdhomerun_device_get_tuner_plotsample(struct hdhomerun_device_t *hd, struct hdhomerun_plotsample_t **psamples, size_t *pcount);
     128extern LIBTYPE int hdhomerun_device_get_tuner_lockkey_owner(struct hdhomerun_device_t *hd, char **powner);
    115129extern LIBTYPE int hdhomerun_device_get_ir_target(struct hdhomerun_device_t *hd, char **ptarget);
    116130extern LIBTYPE int hdhomerun_device_get_lineup_location(struct hdhomerun_device_t *hd, char **plocation);
    117131extern LIBTYPE int hdhomerun_device_get_version(struct hdhomerun_device_t *hd, char **pversion_str, uint32_t *pversion_num);
    extern LIBTYPE uint32_t hdhomerun_device 
    121135extern LIBTYPE uint32_t hdhomerun_device_get_tuner_status_seq_color(struct hdhomerun_tuner_status_t *status);
    122136
    123137extern LIBTYPE const char *hdhomerun_device_get_model_str(struct hdhomerun_device_t *hd);
    124 extern LIBTYPE uint32_t hdhomerun_device_model_channel_map_all(struct hdhomerun_device_t *hd);
    125 extern LIBTYPE uint32_t hdhomerun_device_model_channel_map_antenna(struct hdhomerun_device_t *hd);
    126 extern LIBTYPE uint32_t hdhomerun_device_model_channel_map_cable(struct hdhomerun_device_t *hd);
    127138
    128139/*
    129140 * Set operations.
    extern LIBTYPE int hdhomerun_device_get_ 
    166177extern LIBTYPE int hdhomerun_device_set_var(struct hdhomerun_device_t *hd, const char *name, const char *value, char **pvalue, char **perror);
    167178
    168179/*
     180 * Tuner locking.
     181 *
     182 * The hdhomerun_device_tuner_lockkey_request function is used to obtain a lock
     183 * or to verify that the hdhomerun_device object still holds the lock.
     184 * Returns 1 if the lock request was successful and the lock was obtained.
     185 * Returns 0 if the lock request was rejected.
     186 * Returns -1 if a communication error occurs.
     187 *
     188 * The hdhomerun_device_tuner_lockkey_release function is used to release a
     189 * previously held lock. If locking is used then this function must be called
     190 * before destroying the hdhomerun_device object.
     191 */
     192extern LIBTYPE int hdhomerun_device_tuner_lockkey_request(struct hdhomerun_device_t *hd);
     193extern LIBTYPE int hdhomerun_device_tuner_lockkey_release(struct hdhomerun_device_t *hd);
     194
     195/*
    169196 * Wait for tuner lock after channel change.
    170197 *
    171198 * The hdhomerun_device_wait_for_lock function is used to detect/wait for a lock vs no lock indication
    extern LIBTYPE void hdhomerun_device_str 
    202229/*
    203230 * Channel scan API.
    204231 */
    205 extern LIBTYPE int hdhomerun_device_channelscan_init(struct hdhomerun_device_t *hd, uint32_t channel_map, uint32_t options);
     232extern LIBTYPE int hdhomerun_device_channelscan_init(struct hdhomerun_device_t *hd, const char *channelmap);
    206233extern LIBTYPE int hdhomerun_device_channelscan_advance(struct hdhomerun_device_t *hd, struct hdhomerun_channelscan_result_t *result);
    207234extern LIBTYPE int hdhomerun_device_channelscan_detect(struct hdhomerun_device_t *hd, struct hdhomerun_channelscan_result_t *result);
    208235extern LIBTYPE uint8_t hdhomerun_device_channelscan_get_progress(struct hdhomerun_device_t *hd);
  • mythtv/libs/libmythhdhomerun/hdhomerun_dhcp.c

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_dhcp.c myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_dhcp.c
     
    11/*
    22 * hdhomerun_dhcp.c
    33 *
    4  * Copyright © 2006-2007 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006-2007 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033#include "hdhomerun.h"
  • mythtv/libs/libmythhdhomerun/hdhomerun_dhcp.h

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_dhcp.h myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_dhcp.h
     
    11/*
    22 * hdhomerun_dhcp.h
    33 *
    4  * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033#ifdef __cplusplus
  • mythtv/libs/libmythhdhomerun/hdhomerun_discover.c

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_discover.c myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_discover.c
     
    11/*
    22 * hdhomerun_discover.c
    33 *
    4  * Copyright © 2006-2007 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006-2007 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033#include "hdhomerun.h"
     
    2336#include <windows.h>
    2437#include <iphlpapi.h>
    2538#define USE_IPHLPAPI 1
     39#else
     40#include <net/if.h>
     41#include <sys/ioctl.h>
     42#ifndef _SIZEOF_ADDR_IFREQ
     43#define _SIZEOF_ADDR_IFREQ(x) sizeof(x)
    2644#endif
    27 
    28 #include <sys/param.h>  // Defines BSD on FreeBSD and Mac OS X
    29 
    30 #if defined(__linux__) || defined(__APPLE__) || defined(BSD)
    31 #include <ifaddrs.h>
    32 #define USE_IFADDRS 1
    33 #include <sys/select.h>
    3445#endif
    3546
    3647#define HDHOMERUN_DISOCVER_MAX_SOCK_COUNT 16
    3748
    3849struct hdhomerun_discover_sock_t {
    3950        int sock;
    40         uint32_t broadcast_ip;
     51        uint32_t local_ip;
     52        uint32_t subnet_mask;
    4153};
    4254
    4355struct hdhomerun_discover_t {
    struct hdhomerun_discover_t { 
    4759        struct hdhomerun_pkt_t rx_pkt;
    4860};
    4961
    50 static void hdhomerun_discover_sock_create(struct hdhomerun_discover_t *ds, uint32_t local_ip, uint32_t mask)
     62static bool_t hdhomerun_discover_sock_create(struct hdhomerun_discover_t *ds, uint32_t local_ip, uint32_t subnet_mask)
    5163{
    5264        if (ds->sock_count >= HDHOMERUN_DISOCVER_MAX_SOCK_COUNT) {
    53                 return;
     65                return FALSE;
    5466        }
    5567
    5668        /* Create socket. */
    5769        int sock = (int)socket(AF_INET, SOCK_DGRAM, 0);
    5870        if (sock == -1) {
    59                 return;
     71                return FALSE;
    6072        }
    6173
    6274        /* Set timeouts. */
    static void hdhomerun_discover_sock_crea 
    7587        sock_addr.sin_port = htons(0);
    7688        if (bind(sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) != 0) {
    7789                close(sock);
    78                 return;
     90                return FALSE;
    7991        }
    8092
    8193        /* Write sock entry. */
    8294        struct hdhomerun_discover_sock_t *dss = &ds->socks[ds->sock_count++];
    8395        dss->sock = sock;
    84         dss->broadcast_ip = local_ip | ~mask;
     96        dss->local_ip = local_ip;
     97        dss->subnet_mask = subnet_mask;
     98
     99        return TRUE;
    85100}
    86101
    87102#if defined(USE_IPHLPAPI)
    static void hdhomerun_discover_sock_dete 
    125140
    126141        free(pAdapterInfo);
    127142}
    128 #endif
    129143
    130 #if defined(USE_IFADDRS)
     144#else
     145
    131146static void hdhomerun_discover_sock_detect(struct hdhomerun_discover_t *ds)
    132147{
    133         struct ifaddrs *ifap;
    134         if (getifaddrs(&ifap) < 0) {
     148        int fd = socket(AF_INET, SOCK_DGRAM, 0);
     149        if (fd == -1) {
     150                return;
     151        }
     152
     153        struct ifconf ifc;
     154        uint8_t buf[8192];
     155        ifc.ifc_len = sizeof(buf);
     156        ifc.ifc_buf = (char *)buf;
     157
     158        memset(buf, 0, sizeof(buf));
     159
     160        if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) {
     161                close(fd);
    135162                return;
    136163        }
    137164
    138         struct ifaddrs *p = ifap;
    139         while (p) {
    140                 struct sockaddr_in *addr_in = (struct sockaddr_in *)p->ifa_addr;
    141                 struct sockaddr_in *mask_in = (struct sockaddr_in *)p->ifa_netmask;
    142                 if (!addr_in || !mask_in) {
    143                         p = p->ifa_next;
     165        uint8_t *ptr = (uint8_t *)ifc.ifc_req;
     166        uint8_t *end = (uint8_t *)&ifc.ifc_buf[ifc.ifc_len];
     167
     168        while (ptr <= end) {
     169                struct ifreq *ifr = (struct ifreq *)ptr;
     170                ptr += _SIZEOF_ADDR_IFREQ(*ifr);
     171
     172                if (ioctl(fd, SIOCGIFADDR, ifr) != 0) {
    144173                        continue;
    145174                }
    146 
     175                struct sockaddr_in *addr_in = (struct sockaddr_in *)&(ifr->ifr_addr);
    147176                uint32_t local_ip = ntohl(addr_in->sin_addr.s_addr);
    148                 uint32_t mask = ntohl(mask_in->sin_addr.s_addr);
    149177                if (local_ip == 0) {
    150                         p = p->ifa_next;
    151178                        continue;
    152179                }
    153180
     181                if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) {
     182                        continue;
     183                }
     184                struct sockaddr_in *mask_in = (struct sockaddr_in *)&(ifr->ifr_addr);
     185                uint32_t mask = ntohl(mask_in->sin_addr.s_addr);
     186
    154187                hdhomerun_discover_sock_create(ds, local_ip, mask);
    155                 p = p->ifa_next;
    156188        }
    157 
    158         freeifaddrs(ifap);
    159 }
    160 #endif
    161 
    162 
    163 #if !defined(USE_IPHLPAPI) && !defined(USE_IFADDRS)
    164 static void hdhomerun_discover_sock_detect(struct hdhomerun_discover_t *ds)
    165 {
    166         /* do nothing */
    167189}
    168190#endif
    169191
    static struct hdhomerun_discover_t *hdho 
    174196                return NULL;
    175197        }
    176198
    177         /* Detect & create sockets. */
    178         hdhomerun_discover_sock_detect(ds);
    179         if (ds->sock_count == 0) {
    180                 hdhomerun_discover_sock_create(ds, 0, 0);
    181                 if (ds->sock_count == 0) {
    182                         free(ds);
    183                         return NULL;
    184                 }
     199        /* Create a routable socket. */
     200        if (!hdhomerun_discover_sock_create(ds, 0, 0)) {
     201                free(ds);
     202                return NULL;
    185203        }
    186204
     205        /* Detect & create local sockets. */
     206        hdhomerun_discover_sock_detect(ds);
     207
    187208        /* Success. */
    188209        return ds;
    189210}
    static void hdhomerun_discover_destroy(s 
    201222
    202223static bool_t hdhomerun_discover_send_internal(struct hdhomerun_discover_t *ds, struct hdhomerun_discover_sock_t *dss, uint32_t target_ip, uint32_t device_type, uint32_t device_id)
    203224{
    204         if (target_ip == 0) {
    205                 target_ip = dss->broadcast_ip;
    206         }
    207 
    208225        struct hdhomerun_pkt_t *tx_pkt = &ds->tx_pkt;
    209226        hdhomerun_pkt_reset(tx_pkt);
    210227
    static bool_t hdhomerun_discover_send_in 
    230247        return TRUE;
    231248}
    232249
    233 static bool_t hdhomerun_discover_send(struct hdhomerun_discover_t *ds, uint32_t target_ip, uint32_t device_type, uint32_t device_id)
     250static bool_t hdhomerun_discover_send_wildcard_ip(struct hdhomerun_discover_t *ds, uint32_t device_type, uint32_t device_id)
    234251{
    235252        bool_t result = FALSE;
    236253
     254        /*
     255         * Send subnet broadcast using each local ip socket.
     256         * This will work with multiple separate 169.254.x.x interfaces.
     257         */
    237258        unsigned int i;
    238         for (i = 0; i < ds->sock_count; i++) {
     259        for (i = 1; i < ds->sock_count; i++) {
     260                struct hdhomerun_discover_sock_t *dss = &ds->socks[i];
     261                uint32_t target_ip = dss->local_ip | ~dss->subnet_mask;
     262                result |= hdhomerun_discover_send_internal(ds, dss, target_ip, device_type, device_id);
     263        }
     264
     265        /*
     266         * If no local ip sockets then fall back to sending a global broadcast letting the OS choose the interface.
     267         */
     268        if (!result) {
     269                struct hdhomerun_discover_sock_t *dss = &ds->socks[0];
     270                result = hdhomerun_discover_send_internal(ds, dss, 0xFFFFFFFF, device_type, device_id);
     271        }
     272
     273        return result;
     274}
     275
     276static bool_t hdhomerun_discover_send_target_ip(struct hdhomerun_discover_t *ds, uint32_t target_ip, uint32_t device_type, uint32_t device_id)
     277{
     278        bool_t result = FALSE;
     279
     280        /*
     281         * Send targeted packet from any local ip that is in the same subnet.
     282         * This will work with multiple separate 169.254.x.x interfaces.
     283         */
     284        unsigned int i;
     285        for (i = 1; i < ds->sock_count; i++) {
    239286                struct hdhomerun_discover_sock_t *dss = &ds->socks[i];
     287                if ((target_ip & dss->subnet_mask) != (dss->local_ip & dss->subnet_mask)) {
     288                        continue;
     289                }
     290
    240291                result |= hdhomerun_discover_send_internal(ds, dss, target_ip, device_type, device_id);
    241292        }
    242293
     294        /*
     295         * If target IP does not match a local subnet then fall back to letting the OS choose the gateway interface.
     296         */
     297        if (!result) {
     298                struct hdhomerun_discover_sock_t *dss = &ds->socks[0];
     299                result = hdhomerun_discover_send_internal(ds, dss, target_ip, device_type, device_id);
     300        }
     301
    243302        return result;
    244303}
    245304
     305static bool_t hdhomerun_discover_send(struct hdhomerun_discover_t *ds, uint32_t target_ip, uint32_t device_type, uint32_t device_id)
     306{
     307        if (target_ip != 0) {
     308                return hdhomerun_discover_send_target_ip(ds, target_ip, device_type, device_id);
     309        }
     310
     311        return hdhomerun_discover_send_wildcard_ip(ds, device_type, device_id);
     312}
     313
    246314static int hdhomerun_discover_recv_internal(struct hdhomerun_discover_t *ds, struct hdhomerun_discover_sock_t *dss, struct hdhomerun_discover_device_t *result)
    247315{
    248316        struct hdhomerun_pkt_t *rx_pkt = &ds->rx_pkt;
  • mythtv/libs/libmythhdhomerun/hdhomerun_discover.h

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_discover.h myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_discover.h
     
    11/*
    22 * hdhomerun_discover.h
    33 *
    4  * Copyright © 2006-2007 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006-2007 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932#ifdef __cplusplus
    2033extern "C" {
  • mythtv/libs/libmythhdhomerun/hdhomerun_os.h

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_os.h myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_os.h
     
    11/*
    22 * hdhomerun_os.h
    33 *
    4  * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033#if defined(_WIN32) || defined(_WIN64)
     
    2235#endif
    2336
    2437#if defined(__WINDOWS__)
    25 #define _WINSOCKAPI_
    26 #include <windows.h>
    27 #include <winsock2.h>
    28 #include <ws2tcpip.h>
    29 #include <wspiapi.h>
    30 #include <stdlib.h>
    31 #include <stdio.h>
    32 #include <stdarg.h>
    33 #include <string.h>
    34 #include <signal.h>
    35 #include <time.h>
    36 #include <sys/types.h>
    37 #include <sys/timeb.h>
    38 
    39 #else /* !defined(__WINDOWS__) */
    40 #define _FILE_OFFSET_BITS 64
    41 #include <stdlib.h>
    42 #include <stdio.h>
    43 #include <stdarg.h>
    44 #include <string.h>
    45 #include <unistd.h>
    46 #include <errno.h>
    47 #include <fcntl.h>
    48 #include <sys/types.h>
    49 #include <sys/socket.h>
    50 #include <sys/time.h>
    51 #include <sys/timeb.h>
    52 #include <sys/wait.h>
    53 #include <sys/signal.h>
    54 #include <netinet/in.h>
    55 #include <arpa/inet.h>
    56 #include <netdb.h>
    57 #include <pthread.h>
     38#include "hdhomerun_os_windows.h"
     39#else
     40#include "hdhomerun_os_posix.h"
    5841#endif
    5942
    6043#if !defined(TRUE)
     
    6447#if !defined(FALSE)
    6548#define FALSE 0
    6649#endif
    67 
    68 #if defined(__WINDOWS__)
    69 
    70 #define LIBTYPE
    71 
    72 #if defined(DLL_IMPORT)
    73 #define LIBTYPE __declspec( dllexport )
    74 #endif
    75 
    76 #if defined(DLL_EXPORT)
    77 #define LIBTYPE __declspec( dllimport )
    78 #endif
    79 
    80 typedef int bool_t;
    81 typedef signed __int8 int8_t;
    82 typedef signed __int16 int16_t;
    83 typedef signed __int32 int32_t;
    84 typedef signed __int64 int64_t;
    85 typedef unsigned __int8 uint8_t;
    86 typedef unsigned __int16 uint16_t;
    87 typedef unsigned __int32 uint32_t;
    88 typedef unsigned __int64 uint64_t;
    89 typedef HANDLE pthread_t;
    90 typedef HANDLE pthread_mutex_t;
    91 
    92 #define socklen_t int
    93 #define close closesocket
    94 #define sock_getlasterror WSAGetLastError()
    95 #define sock_getlasterror_socktimeout (WSAGetLastError() == WSAETIMEDOUT)
    96 #define va_copy(x, y) x = y
    97 #define atoll _atoi64
    98 #define strdup _strdup
    99 #define strcasecmp _stricmp
    100 #define snprintf _snprintf
    101 #define fseeko _fseeki64
    102 #define ftello _ftelli64
    103 #define usleep(us) Sleep((us)/1000)
    104 #define sleep(sec) Sleep((sec)*1000)
    105 #define THREAD_FUNC_PREFIX DWORD WINAPI
    106 #define SIGPIPE SIGABRT
    107 
    108 static inline uint64_t getcurrenttime(void)
    109 {
    110         struct timeb tb;
    111         ftime(&tb);
    112         return ((uint64_t)tb.time * 1000) + tb.millitm;
    113 }
    114 
    115 static inline int setsocktimeout(int s, int level, int optname, uint64_t timeout)
    116 {
    117         int t = (int)timeout;
    118         return setsockopt(s, level, optname, (char *)&t, sizeof(t));
    119 }
    120 
    121 static inline int pthread_create(pthread_t *tid, void *attr, LPTHREAD_START_ROUTINE start, void *arg)
    122 {
    123         *tid = CreateThread(NULL, 0, start, arg, 0, NULL);
    124         if (!*tid) {
    125                 return (int)GetLastError();
    126         }
    127         return 0;
    128 }
    129 
    130 static inline int pthread_join(pthread_t tid, void **value_ptr)
    131 {
    132         while (1) {
    133                 DWORD ExitCode = 0;
    134                 if (!GetExitCodeThread(tid, &ExitCode)) {
    135                         return (int)GetLastError();
    136                 }
    137                 if (ExitCode != STILL_ACTIVE) {
    138                         return 0;
    139                 }
    140         }
    141 }
    142 
    143 extern inline void pthread_mutex_init(pthread_mutex_t *mutex, void *attr)
    144 {
    145         *mutex = CreateMutex(NULL, FALSE, NULL);
    146 }
    147 
    148 extern inline void pthread_mutex_lock(pthread_mutex_t *mutex)
    149 {
    150         WaitForSingleObject(*mutex, INFINITE);
    151 }
    152 
    153 extern inline void pthread_mutex_unlock(pthread_mutex_t *mutex)
    154 {
    155         ReleaseMutex(*mutex);
    156 }
    157 
    158 #else /* !defined(__WINDOWS__) */
    159 
    160 typedef int bool_t;
    161 
    162 #define LIBTYPE
    163 #define sock_getlasterror errno
    164 #define sock_getlasterror_socktimeout (errno == EAGAIN)
    165 #define THREAD_FUNC_PREFIX void *
    166 
    167 static inline uint64_t getcurrenttime(void)
    168 {
    169         struct timeval t;
    170         gettimeofday(&t, NULL);
    171         return ((uint64_t)t.tv_sec * 1000) + (t.tv_usec / 1000);
    172 }
    173 
    174 static inline int setsocktimeout(int s, int level, int optname, uint64_t timeout)
    175 {
    176         struct timeval t;
    177         t.tv_sec = timeout / 1000;
    178         t.tv_usec = (timeout % 1000) * 1000;
    179         return setsockopt(s, level, optname, (char *)&t, sizeof(t));
    180 }
    181 
    182 #endif
  • mythtv/libs/libmythhdhomerun/hdhomerun_os_posix.h

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_os_posix.h myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_os_posix.h
     
     1/*
     2 * hdhomerun_os_posix.h
     3 *
     4 * Copyright © 2006-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
     5 *
     6 * This library is free software; you can redistribute it and/or
     7 * modify it under the terms of the GNU Lesser General Public
     8 * License as published by the Free Software Foundation; either
     9 * version 3 of the License, or (at your option) any later version.
     10 *
     11 * This library is distributed in the hope that it will be useful,
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14 * Lesser General Public License for more details.
     15 *
     16 * You should have received a copy of the GNU Lesser General Public
     17 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
     31 */
     32
     33#define _FILE_OFFSET_BITS 64
     34#include <stdlib.h>
     35#include <stdio.h>
     36#include <stdarg.h>
     37#include <string.h>
     38#include <unistd.h>
     39#include <errno.h>
     40#include <fcntl.h>
     41#include <sys/types.h>
     42#include <sys/socket.h>
     43#include <sys/time.h>
     44#include <sys/timeb.h>
     45#include <sys/wait.h>
     46#include <sys/signal.h>
     47#include <netinet/in.h>
     48#include <arpa/inet.h>
     49#include <netdb.h>
     50#include <pthread.h>
     51
     52typedef int bool_t;
     53
     54#define LIBTYPE
     55#define sock_getlasterror errno
     56#define sock_getlasterror_socktimeout (errno == EAGAIN)
     57#define console_vprintf vprintf
     58#define console_printf printf
     59#define THREAD_FUNC_PREFIX void *
     60
     61static inline uint64_t getcurrenttime(void)
     62{
     63        struct timeval t;
     64        gettimeofday(&t, NULL);
     65        return ((uint64_t)t.tv_sec * 1000) + (t.tv_usec / 1000);
     66}
     67
     68static inline int setsocktimeout(int s, int level, int optname, uint64_t timeout)
     69{
     70        struct timeval t;
     71        t.tv_sec = timeout / 1000;
     72        t.tv_usec = (timeout % 1000) * 1000;
     73        return setsockopt(s, level, optname, (char *)&t, sizeof(t));
     74}
  • mythtv/libs/libmythhdhomerun/hdhomerun_os_windows.h

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_os_windows.h myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_os_windows.h
     
     1/*
     2 * hdhomerun_os_windows.h
     3 *
     4 * Copyright © 2006-2008 Silicondust Engineering Ltd. <www.silicondust.com>.
     5 *
     6 * This library is free software; you can redistribute it and/or
     7 * modify it under the terms of the GNU Lesser General Public
     8 * License as published by the Free Software Foundation; either
     9 * version 3 of the License, or (at your option) any later version.
     10 *
     11 * This library is distributed in the hope that it will be useful,
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14 * Lesser General Public License for more details.
     15 *
     16 * You should have received a copy of the GNU Lesser General Public
     17 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
     31 */
     32
     33#define _WINSOCKAPI_
     34#include <windows.h>
     35#include <winsock2.h>
     36#include <ws2tcpip.h>
     37#include <wspiapi.h>
     38#include <stdlib.h>
     39#include <stdio.h>
     40#include <stdarg.h>
     41#include <string.h>
     42#include <signal.h>
     43#include <time.h>
     44#include <sys/types.h>
     45#include <sys/timeb.h>
     46
     47#if defined(DLL_IMPORT)
     48#define LIBTYPE __declspec( dllexport )
     49#elif  defined(DLL_EXPORT)
     50#define LIBTYPE __declspec( dllimport )
     51#else
     52#define LIBTYPE
     53#endif
     54
     55typedef int bool_t;
     56typedef signed __int8 int8_t;
     57typedef signed __int16 int16_t;
     58typedef signed __int32 int32_t;
     59typedef signed __int64 int64_t;
     60typedef unsigned __int8 uint8_t;
     61typedef unsigned __int16 uint16_t;
     62typedef unsigned __int32 uint32_t;
     63typedef unsigned __int64 uint64_t;
     64typedef HANDLE pthread_t;
     65typedef HANDLE pthread_mutex_t;
     66
     67#define socklen_t int
     68#define close closesocket
     69#define sock_getlasterror WSAGetLastError()
     70#define sock_getlasterror_socktimeout (WSAGetLastError() == WSAETIMEDOUT)
     71#define va_copy(x, y) x = y
     72#define atoll _atoi64
     73#define strdup _strdup
     74#define strcasecmp _stricmp
     75#define snprintf _snprintf
     76#define fseeko _fseeki64
     77#define ftello _ftelli64
     78#define THREAD_FUNC_PREFIX DWORD WINAPI
     79#define SIGPIPE SIGABRT
     80
     81static inline int usleep(unsigned int us)
     82{
     83        Sleep((us)/1000);
     84        return 0;
     85}
     86
     87static inline int sleep(unsigned int sec)
     88{
     89        Sleep((sec)*1000);
     90        return 0;
     91}
     92
     93static inline uint64_t getcurrenttime(void)
     94{
     95        struct timeb tb;
     96        ftime(&tb);
     97        return ((uint64_t)tb.time * 1000) + tb.millitm;
     98}
     99
     100static inline int setsocktimeout(int s, int level, int optname, uint64_t timeout)
     101{
     102        int t = (int)timeout;
     103        return setsockopt(s, level, optname, (char *)&t, sizeof(t));
     104}
     105
     106static inline int pthread_create(pthread_t *tid, void *attr, LPTHREAD_START_ROUTINE start, void *arg)
     107{
     108        *tid = CreateThread(NULL, 0, start, arg, 0, NULL);
     109        if (!*tid) {
     110                return (int)GetLastError();
     111        }
     112        return 0;
     113}
     114
     115static inline int pthread_join(pthread_t tid, void **value_ptr)
     116{
     117        while (1) {
     118                DWORD ExitCode = 0;
     119                if (!GetExitCodeThread(tid, &ExitCode)) {
     120                        return (int)GetLastError();
     121                }
     122                if (ExitCode != STILL_ACTIVE) {
     123                        return 0;
     124                }
     125        }
     126}
     127
     128static inline void pthread_mutex_init(pthread_mutex_t *mutex, void *attr)
     129{
     130        *mutex = CreateMutex(NULL, FALSE, NULL);
     131}
     132
     133static inline void pthread_mutex_lock(pthread_mutex_t *mutex)
     134{
     135        WaitForSingleObject(*mutex, INFINITE);
     136}
     137
     138static inline void pthread_mutex_unlock(pthread_mutex_t *mutex)
     139{
     140        ReleaseMutex(*mutex);
     141}
     142
     143/*
     144 * The console output format should be set to UTF-8, however in XP and Vista this breaks batch file processing.
     145 * Attempting to restore on exit fails to restore if the program is terminated by the user.
     146 * Solution - set the output format each printf.
     147 */
     148static inline void console_vprintf(const char *fmt, va_list ap)
     149{
     150        UINT cp = GetConsoleOutputCP();
     151        SetConsoleOutputCP(CP_UTF8);
     152        vprintf(fmt, ap);
     153        SetConsoleOutputCP(cp);
     154}
     155
     156static inline void console_printf(const char *fmt, ...)
     157{
     158        va_list ap;
     159        va_start(ap, fmt);
     160        console_vprintf(fmt, ap);
     161        va_end(ap);
     162}
  • mythtv/libs/libmythhdhomerun/hdhomerun_pkt.c

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_pkt.c myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_pkt.c
     
    11/*
    22 * hdhomerun_pkt.c
    33 *
    4  * Copyright © 2005-2006 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2005-2006 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033#include "hdhomerun.h"
    void hdhomerun_pkt_destroy(struct hdhome 
    3851
    3952void hdhomerun_pkt_reset(struct hdhomerun_pkt_t *pkt)
    4053{
    41         pkt->limit = pkt->buffer + sizeof(pkt->buffer);
     54        pkt->limit = pkt->buffer + sizeof(pkt->buffer) - 4;
    4255        pkt->start = pkt->buffer + 1024;
    4356        pkt->end = pkt->start;
    4457        pkt->pos = pkt->start;
  • mythtv/libs/libmythhdhomerun/hdhomerun_pkt.h

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_pkt.h myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_pkt.h
     
    11/*
    22 * hdhomerun_pkt.h
    33 *
    4  * Copyright © 2005-2006 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2005-2006 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932#ifdef __cplusplus
    2033extern "C" {
    extern "C" { 
    109122#define HDHOMERUN_DISCOVER_UDP_PORT 65001
    110123#define HDHOMERUN_CONTROL_TCP_PORT 65001
    111124
     125#define HDHOMERUN_MAX_PACKET_SIZE 1460
     126#define HDHOMERUN_MAX_PAYLOAD_SIZE 1452
     127
    112128#define HDHOMERUN_TYPE_DISCOVER_REQ 0x0002
    113129#define HDHOMERUN_TYPE_DISCOVER_RPY 0x0003
    114130#define HDHOMERUN_TYPE_GETSET_REQ 0x0004
    extern "C" { 
    120136#define HDHOMERUN_TAG_DEVICE_ID 0x02
    121137#define HDHOMERUN_TAG_GETSET_NAME 0x03
    122138#define HDHOMERUN_TAG_GETSET_VALUE 0x04
     139#define HDHOMERUN_TAG_GETSET_LOCKKEY 0x15
    123140#define HDHOMERUN_TAG_ERROR_MESSAGE 0x05
    124141
    125142#define HDHOMERUN_DEVICE_TYPE_WILDCARD 0xFFFFFFFF
  • mythtv/libs/libmythhdhomerun/hdhomerun_types.h

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_types.h myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_types.h
     
    11/*
    22 * hdhomerun_types.h
    33 *
    4  * Copyright © 2008 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2008 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033struct hdhomerun_device_t;
    struct hdhomerun_channelscan_program_t { 
    3851        uint16_t virtual_major;
    3952        uint16_t virtual_minor;
    4053        uint16_t type;
    41         char name[8];
     54        char name[32];
    4255};
    4356
    4457#define HDHOMERUN_CHANNELSCAN_MAX_PROGRAM_COUNT 64
    4558
    4659struct hdhomerun_channelscan_result_t {
    4760        char channel_str[64];
    48         uint32_t channel_map;
     61        uint32_t channelmap;
    4962        uint32_t frequency;
    5063        struct hdhomerun_tuner_status_t status;
    5164        int program_count;
  • mythtv/libs/libmythhdhomerun/hdhomerun_video.c

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_video.c myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_video.c
     
    11/*
    22 * hdhomerun_video.c
    33 *
    4  * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932
    2033#include "hdhomerun.h"
    2134
    2235struct hdhomerun_video_sock_t {
     36        pthread_mutex_t lock;
    2337        uint8_t *buffer;
    2438        size_t buffer_size;
    2539        volatile size_t head;
    struct hdhomerun_video_sock_t { 
    2842        volatile bool_t terminate;
    2943        pthread_t thread;
    3044        int sock;
     45        uint32_t rtp_sequence;
    3146        struct hdhomerun_debug_t *dbg;
    3247        volatile uint32_t packet_count;
    3348        volatile uint32_t transport_error_count;
    struct hdhomerun_video_sock_t { 
    3550        volatile uint32_t sequence_error_count;
    3651        volatile uint32_t overflow_error_count;
    3752        volatile uint8_t sequence[0x2000];
    38         uint32_t rtp_sequence;
    3953};
    4054
    4155static THREAD_FUNC_PREFIX hdhomerun_video_thread_execute(void *arg);
    struct hdhomerun_video_sock_t *hdhomerun 
    8498                return NULL;
    8599        }
    86100
     101        pthread_mutex_init(&vs->lock, NULL);
     102
    87103        /* Reset sequence tracking. */
    88104        hdhomerun_video_flush(vs);
    89105
    static void hdhomerun_video_parse_rtp(st 
    210226
    211227                        /* restart pid sequence check */
    212228                        /* can't use memset bcs sequence is volatile */
    213                         int i;
     229                        int i;
    214230                        for (i = 0; i < sizeof(vs->sequence) / sizeof(uint8_t) ; i++)
    215231                                vs->sequence[i] = 0xFF;
    216232                }
    static THREAD_FUNC_PREFIX hdhomerun_vide 
    250266                        return NULL;
    251267                }
    252268
     269                pthread_mutex_lock(&vs->lock);
     270
    253271                /* Store in ring buffer. */
    254272                size_t head = vs->head;
    255273                uint8_t *ptr = vs->buffer + head;
    static THREAD_FUNC_PREFIX hdhomerun_vide 
    274292                /* Check for buffer overflow. */
    275293                if (head == vs->tail) {
    276294                        vs->overflow_error_count++;
     295                        pthread_mutex_unlock(&vs->lock);
    277296                        continue;
    278297                }
    279298
    280299                /* Atomic update. */
    281300                vs->head = head;
     301
     302                pthread_mutex_unlock(&vs->lock);
    282303        }
    283304
    284305        return NULL;
    static THREAD_FUNC_PREFIX hdhomerun_vide 
    286307
    287308uint8_t *hdhomerun_video_recv(struct hdhomerun_video_sock_t *vs, size_t max_size, size_t *pactual_size)
    288309{
     310        pthread_mutex_lock(&vs->lock);
     311
    289312        size_t head = vs->head;
    290313        size_t tail = vs->tail;
    291314
    uint8_t *hdhomerun_video_recv(struct hdh 
    302325        if (head == tail) {
    303326                vs->advance = 0;
    304327                *pactual_size = 0;
     328                pthread_mutex_unlock(&vs->lock);
    305329                return NULL;
    306330        }
    307331
    uint8_t *hdhomerun_video_recv(struct hdh 
    309333        if (size == 0) {
    310334                vs->advance = 0;
    311335                *pactual_size = 0;
     336                pthread_mutex_unlock(&vs->lock);
    312337                return NULL;
    313338        }
    314339
    uint8_t *hdhomerun_video_recv(struct hdh 
    323348        }
    324349        vs->advance = size;
    325350        *pactual_size = size;
    326         return vs->buffer + tail;
     351        uint8_t *result = vs->buffer + tail;
     352
     353        pthread_mutex_unlock(&vs->lock);
     354        return result;
    327355}
    328356
    329357void hdhomerun_video_flush(struct hdhomerun_video_sock_t *vs)
    330358{
    331         /* Atomic update of tail. */
     359        pthread_mutex_lock(&vs->lock);
     360
    332361        vs->tail = vs->head;
    333362        vs->advance = 0;
    334363
    335364        /* can't use memset bcs sequence is volatile */
    336         int i;
     365        int i;
    337366        for (i = 0; i < sizeof(vs->sequence) / sizeof(uint8_t) ; i++)
    338367                vs->sequence[i] = 0xFF;
    339368
    void hdhomerun_video_flush(struct hdhome 
    344373        vs->network_error_count = 0;
    345374        vs->sequence_error_count = 0;
    346375        vs->overflow_error_count = 0;
     376
     377        pthread_mutex_unlock(&vs->lock);
    347378}
    348379
    349380void hdhomerun_video_debug_print_stats(struct hdhomerun_video_sock_t *vs)
    350381{
    351         hdhomerun_debug_printf(vs->dbg, "video sock: pkt=%ld net=%ld te=%ld miss=%ld drop=%ld\n", vs->packet_count, vs->network_error_count, vs->transport_error_count, vs->sequence_error_count, vs->overflow_error_count);
     382        struct hdhomerun_video_stats_t stats;
     383        hdhomerun_video_get_stats(vs, &stats);
     384
     385        hdhomerun_debug_printf(vs->dbg, "video sock: pkt=%ld net=%ld te=%ld miss=%ld drop=%ld\n",
     386                stats.packet_count, stats.network_error_count,
     387                stats.transport_error_count, stats.sequence_error_count,
     388                stats.overflow_error_count
     389        );
    352390}
    353391
    354392void hdhomerun_video_get_stats(struct hdhomerun_video_sock_t *vs, struct hdhomerun_video_stats_t *stats)
    355393{
    356394        memset(stats, 0, sizeof(struct hdhomerun_video_stats_t));
    357395
     396        pthread_mutex_lock(&vs->lock);
     397
    358398        stats->packet_count = vs->packet_count;
    359399        stats->network_error_count = vs->network_error_count;
    360400        stats->transport_error_count = vs->transport_error_count;
    361401        stats->sequence_error_count = vs->sequence_error_count;
     402        stats->overflow_error_count = vs->overflow_error_count;
     403
     404        pthread_mutex_unlock(&vs->lock);
    362405}
  • mythtv/libs/libmythhdhomerun/hdhomerun_video.h

    diff -p -r -u -N -X /tmp/diff.exclude.2286 -x myth.20746.0626a -x myth.20746.0626b myth.20746.0626a/mythtv/libs/libmythhdhomerun/hdhomerun_video.h myth.20746.0626b/mythtv/libs/libmythhdhomerun/hdhomerun_video.h
     
    11/*
    22 * hdhomerun_video.h
    33 *
    4  * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
     4 * Copyright © 2006 Silicondust Engineering Ltd. <www.silicondust.com>.
    55 *
    66 * This library is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU Lesser General Public
     
    1515 *
    1616 * You should have received a copy of the GNU Lesser General Public
    1717 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     18 *
     19 * As a special exception to the GNU Lesser General Public License,
     20 * you may link, statically or dynamically, an application with a
     21 * publicly distributed version of the Library to produce an
     22 * executable file containing portions of the Library, and
     23 * distribute that executable file under terms of your choice,
     24 * without any of the additional requirements listed in clause 4 of
     25 * the GNU Lesser General Public License.
     26 *
     27 * By "a publicly distributed version of the Library", we mean
     28 * either the unmodified Library as distributed by Silicondust, or a
     29 * modified version of the Library that is distributed under the
     30 * conditions defined in the GNU Lesser General Public License.
    1831 */
    1932#ifdef __cplusplus
    2033extern "C" {
    struct hdhomerun_video_stats_t { 
    2740        uint32_t network_error_count;
    2841        uint32_t transport_error_count;
    2942        uint32_t sequence_error_count;
     43        uint32_t overflow_error_count;
    3044};
    3145
    3246#define TS_PACKET_SIZE 188