Advertisement
Guest User

R5000Patch

a guest
Feb 16th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 335.01 KB | None | 0 0
  1. diff -crBN ../../mythtv/mythtv/configure ./configure
  2. *** ../../mythtv/mythtv/configure 2013-02-16 10:36:54.416158056 -0800
  3. --- ./configure 2013-02-16 10:52:50.018567158 -0800
  4. ***************
  5. *** 119,124 ****
  6. --- 119,125 ----
  7. --disable-ivtv disable ivtv support (PVR-x50) req. v4l2 support
  8. --disable-hdpvr disable HD-PVR support
  9. --disable-dvb disable DVB support
  10. + --disable-r5000 disable support for R5000 USB STBs
  11. --dvb-path=HDRLOC location of directory containing
  12. 'linux/dvb/frontend.h', not the
  13. directory with frontend.h [$dvb_path_default]
  14. ***************
  15. *** 1676,1681 ****
  16. --- 1677,1683 ----
  17. ceton
  18. hdpvr
  19. ivtv
  20. + r5000
  21. asi
  22. joystick_menu
  23. libcec
  24. ***************
  25. *** 2284,2289 ****
  26. --- 2286,2292 ----
  27. audio_oss_deps_any="soundcard_h sys_soundcard_h"
  28. dvb_deps="backend"
  29. firewire_deps="backend"
  30. + r5000_deps="backend"
  31. ivtv_deps="backend v4l2"
  32. hdpvr_deps="backend v4l2"
  33. hdhomerun_deps="backend"
  34. ***************
  35. *** 2501,2506 ****
  36. --- 2504,2510 ----
  37. enable ceton
  38. enable hdpvr
  39. enable ivtv
  40. + enable r5000
  41. enable asi
  42. enable lamemp3
  43. enable libass
  44. ***************
  45. *** 5702,5707 ****
  46. --- 5706,5712 ----
  47. echo "DVB-S2 support ${fe_can_2g_modulation-no}"
  48. echo "HDHomeRun support ${hdhomerun-no}"
  49. echo "Ceton support ${ceton-no}"
  50. + echo "R5000 support ${r5000-no}"
  51. echo "ASI support ${asi-no}"
  52. fi
  53.  
  54. diff -crBN ../../mythtv/mythtv/libs/libmythtv/cardutil.h ./libs/libmythtv/cardutil.h
  55. *** ../../mythtv/mythtv/libs/libmythtv/cardutil.h 2013-02-16 10:36:55.152162905 -0800
  56. --- ./libs/libmythtv/cardutil.h 2013-02-16 10:52:50.014567132 -0800
  57. ***************
  58. *** 66,71 ****
  59. --- 66,72 ----
  60. DEMO = 15,
  61. ASI = 16,
  62. CETON = 17,
  63. + R5000 = 18,
  64. };
  65.  
  66. static enum CARD_TYPES toCardType(const QString &name)
  67. ***************
  68. *** 106,111 ****
  69. --- 107,114 ----
  70. return ASI;
  71. if ("CETON" == name)
  72. return CETON;
  73. + if ("R5000" == name)
  74. + return R5000;
  75. return ERROR_UNKNOWN;
  76. }
  77.  
  78. ***************
  79. *** 115,121 ****
  80. (rawtype != "DVB") && (rawtype != "FIREWIRE") &&
  81. (rawtype != "HDHOMERUN") && (rawtype != "FREEBOX") &&
  82. (rawtype != "IMPORT") && (rawtype != "DEMO") &&
  83. ! (rawtype != "ASI") && (rawtype != "CETON");
  84. }
  85.  
  86. static bool IsV4L(const QString &rawtype)
  87. --- 118,125 ----
  88. (rawtype != "DVB") && (rawtype != "FIREWIRE") &&
  89. (rawtype != "HDHOMERUN") && (rawtype != "FREEBOX") &&
  90. (rawtype != "IMPORT") && (rawtype != "DEMO") &&
  91. ! (rawtype != "ASI") && (rawtype != "CETON") &&
  92. ! (rawtype != "R5000") ;
  93. }
  94.  
  95. static bool IsV4L(const QString &rawtype)
  96. ***************
  97. *** 135,141 ****
  98. return
  99. (rawtype == "FIREWIRE") || (rawtype == "HDPVR") ||
  100. (rawtype == "IMPORT") || (rawtype == "DEMO") ||
  101. ! (rawtype == "GO7007") || (rawtype == "MJPEG");
  102. }
  103. static QString GetScanableCardTypes(void);
  104.  
  105. --- 139,146 ----
  106. return
  107. (rawtype == "FIREWIRE") || (rawtype == "HDPVR") ||
  108. (rawtype == "IMPORT") || (rawtype == "DEMO") ||
  109. ! (rawtype == "GO7007") || (rawtype == "MJPEG") ||
  110. ! (rawtype == "R5000");
  111. }
  112. static QString GetScanableCardTypes(void);
  113.  
  114. ***************
  115. *** 182,188 ****
  116. (rawtype == "FIREWIRE") || (rawtype == "HDHOMERUN") ||
  117. (rawtype == "FREEBOX") || (rawtype == "ASI") ||
  118. (rawtype == "IMPORT") || (rawtype == "DEMO") ||
  119. ! (rawtype == "CETON");
  120. }
  121.  
  122. // Card creation and deletion
  123. --- 187,193 ----
  124. (rawtype == "FIREWIRE") || (rawtype == "HDHOMERUN") ||
  125. (rawtype == "FREEBOX") || (rawtype == "ASI") ||
  126. (rawtype == "IMPORT") || (rawtype == "DEMO") ||
  127. ! (rawtype == "CETON") || (rawtype == "R5000");
  128. }
  129.  
  130. // Card creation and deletion
  131. diff -crBN ../../mythtv/mythtv/libs/libmythtv/libmythtv.pro ./libs/libmythtv/libmythtv.pro
  132. *** ../../mythtv/mythtv/libs/libmythtv/libmythtv.pro 2013-02-16 10:36:55.164162984 -0800
  133. --- ./libs/libmythtv/libmythtv.pro 2013-02-16 10:52:50.014567132 -0800
  134. ***************
  135. *** 733,738 ****
  136. --- 733,757 ----
  137. DEFINES += USING_ASI
  138. }
  139.  
  140. + #Support for R5000 usb device
  141. + using_r5000 {
  142. + HEADERS += r5000channel.h r5000recorder.h
  143. + HEADERS += r5000signalmonitor.h r5000device.h
  144. + HEADERS += r5000/r5000.h r5000/libusb_augment.h
  145. + HEADERS += r5000/r5000_internal.h r5000/r5000init.h
  146. +
  147. + SOURCES += r5000channel.cpp r5000recorder.cpp
  148. + SOURCES += r5000signalmonitor.cpp r5000device.cpp
  149. + SOURCES += r5000/r5000.c r5000/libusb_augment.c
  150. + SOURCES += r5000/r5k_vip.c r5000/r5k_pes.c
  151. + SOURCES += r5000/r5k_sat.c r5000/r5k_misc.c
  152. + SOURCES += r5000/r5k_vip_buttons.c r5000/r5k_directv_buttons.c
  153. + SOURCES += r5000/r5k_dish6000_buttons.c
  154. +
  155. + LIBS += -lusb
  156. + DEFINES += USING_R5000
  157. + }
  158. +
  159. DEFINES += USING_BACKEND
  160. }
  161.  
  162. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/libusb_augment.c ./libs/libmythtv/r5000/libusb_augment.c
  163. *** ../../mythtv/mythtv/libs/libmythtv/r5000/libusb_augment.c 1969-12-31 16:00:00.000000000 -0800
  164. --- ./libs/libmythtv/r5000/libusb_augment.c 2011-04-08 19:29:47.000000000 -0700
  165. ***************
  166. *** 0 ****
  167. --- 1,311 ----
  168. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  169. + * 2005-10-19/lindi: downloaded from http://www.gaesi.org/~nmct/cvista/cvista/
  170. + *
  171. + * This library is free software; you can redistribute it and/or
  172. + * modify it under the terms of the GNU Lesser General Public
  173. + * License as published by the Free Software Foundation; either
  174. + * version 2.1 of the License, or (at your option) any later version.
  175. + *
  176. + * This library is distributed in the hope that it will be useful,
  177. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  178. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  179. + * Lesser General Public License for more details.
  180. + *
  181. + * You should have received a copy of the GNU Lesser General Public
  182. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  183. + */
  184. +
  185. + // libusb_augment.c
  186. + // $Revision$
  187. + // $Date$
  188. +
  189. + // Hopefully, the functions in this file will become part of libusb.
  190. +
  191. + #include <stdio.h>
  192. + #include <sys/ioctl.h>
  193. + #include <errno.h>
  194. + #include <sys/time.h>
  195. + #include <sys/poll.h>
  196. + #include <usb.h>
  197. + #include <linux/usbdevice_fs.h>
  198. + #include <string.h>
  199. + #include <signal.h>
  200. + #define LIBUSB_AUGMENT
  201. + #include "libusb_augment.h"
  202. +
  203. + // Taken from libusb file usbi.h because usb.h
  204. + // hides the definition of usb_dev_handle.
  205. + extern int usb_debug;
  206. +
  207. + struct usb_dev_handle {
  208. + int fd;
  209. +
  210. + struct usb_bus *bus;
  211. + struct usb_device *device;
  212. +
  213. + int config;
  214. + int interface;
  215. + int altsetting;
  216. +
  217. + /* Added by RMT so implementations can store other per-open-device data */
  218. + void *impl_info;
  219. + };
  220. +
  221. + // Taken from libusb file error.h to supply error handling macro definition.
  222. + typedef enum {
  223. + USB_ERROR_TYPE_NONE = 0,
  224. + USB_ERROR_TYPE_STRING,
  225. + USB_ERROR_TYPE_ERRNO,
  226. + } usb_error_type_t;
  227. +
  228. + extern char usb_error_str[1024];
  229. + extern usb_error_type_t usb_error_type;
  230. +
  231. + #define USB_ERROR_STR(format, args...) \
  232. + do { \
  233. + usb_error_type = USB_ERROR_TYPE_STRING; \
  234. + snprintf(usb_error_str, sizeof(usb_error_str) - 1, format, ## args); \
  235. + if (usb_debug >= 2) \
  236. + fprintf(stderr, "USB error: %s\n", usb_error_str); \
  237. + } while (0)
  238. +
  239. + static int urb_signr = 0;
  240. + void (*urb_completion_callback)(struct usbdevfs_urb *) = NULL;
  241. + #define USB_ASYNC_COMPLETION_SIGNAL (SIGRTMIN + 5)
  242. +
  243. + void urb_completion_handler(int signum, siginfo_t *info, void *context)
  244. + {
  245. + struct usbdevfs_urb *urb = (struct usbdevfs_urb *)info->si_addr;
  246. + struct usbdevfs_urb *context1;
  247. + usb_dev_handle *dev = (usb_dev_handle *)urb->usercontext;
  248. + int ret;
  249. + if (info->si_code != SI_ASYNCIO ||
  250. + info->si_signo != USB_ASYNC_COMPLETION_SIGNAL) {
  251. + return;
  252. + }
  253. + if(info->si_errno != 0) {
  254. + USB_ERROR_STR("Async URB Completion failed: %s", strerror(info->si_errno));
  255. + return;
  256. + }
  257. + ret = ioctl(dev->fd, USBDEVFS_REAPURB, &context1);
  258. + if(ret < 0) {
  259. + USB_ERROR_STR("Failed to read URB: %s", strerror(-ret));
  260. + return;
  261. + }
  262. + if(context1 != urb) {
  263. + USB_ERROR_STR("Reaped unexpected urb");
  264. + return;
  265. + }
  266. + if(urb_completion_callback)
  267. + urb_completion_callback(urb);
  268. + }
  269. +
  270. + int usbdevfs_urb_signal_completion(void (*cb)( struct usbdevfs_urb *))
  271. + {
  272. + urb_completion_callback = cb;
  273. + urb_signr = USB_ASYNC_COMPLETION_SIGNAL;
  274. + struct sigaction usb_linux_sa;
  275. + usb_linux_sa.sa_sigaction = urb_completion_handler;
  276. + sigfillset(&usb_linux_sa.sa_mask);
  277. + usb_linux_sa.sa_flags = SA_SIGINFO;
  278. + usb_linux_sa.sa_flags |= SA_ONSTACK;
  279. + sigaction(USB_ASYNC_COMPLETION_SIGNAL, &usb_linux_sa, NULL);
  280. + return 0;
  281. + }
  282. +
  283. + struct usbdevfs_urb *usb_bulk_setup(
  284. + struct usbdevfs_urb *iso_urb, // URB pointer-pointer.
  285. + unsigned char ep, // Device endpoint.
  286. + char *bytes, // Data buffer pointer.
  287. + int size) { // Size of the buffer.
  288. + struct usbdevfs_urb *local_urb;
  289. +
  290. + // No more than 16384 bytes can be transferred at a time.
  291. + if (size > 16384) {
  292. + USB_ERROR_STR("error on transfer size: %s", strerror(EINVAL));
  293. + return NULL;
  294. + }
  295. + local_urb = iso_urb;
  296. + if (!local_urb) {
  297. + local_urb = (struct usbdevfs_urb *) calloc(1, sizeof(struct usbdevfs_urb));
  298. + if (!local_urb) {
  299. + USB_ERROR_STR("error on packet size: %s", strerror(EINVAL));
  300. + return NULL;
  301. + }
  302. + }
  303. + local_urb->type = USBDEVFS_URB_TYPE_BULK;
  304. + local_urb->endpoint = ep;
  305. + local_urb->status = 0;
  306. + local_urb->flags = 0;
  307. + local_urb->buffer = bytes;
  308. + local_urb->buffer_length = size;
  309. + local_urb->actual_length = 0;
  310. + local_urb->start_frame = 0;
  311. + local_urb->number_of_packets = 0;
  312. + local_urb->error_count = 0;
  313. + local_urb->signr = urb_signr;
  314. + local_urb->usercontext = (void *) 0;
  315. + return local_urb;
  316. + }
  317. + // Reading and writing are the same except for the endpoint
  318. + struct usbdevfs_urb *usb_isochronous_setup(
  319. + struct usbdevfs_urb *iso_urb, // URB pointer-pointer.
  320. + unsigned char ep, // Device endpoint.
  321. + int pktsize, // Endpoint packet size.
  322. + char *bytes, // Data buffer pointer.
  323. + int size) { // Size of the buffer.
  324. + struct usbdevfs_urb *local_urb;
  325. + // int ret
  326. + // was unused /lindi
  327. + int pktcount, fullpkts, partpktsize, packets, urb_size;
  328. +
  329. + // No more than 32768 bytes can be transferred at a time.
  330. + if (size > 32768) {
  331. + USB_ERROR_STR("error on transfer size: %s", strerror(EINVAL));
  332. + return NULL;
  333. + }
  334. +
  335. + // Determine the number of packets that need to be created based upon the
  336. + // amount of data to be transferred, and the maximum packet size of the
  337. + // endpoint.
  338. +
  339. + // Find integral number of full packets.
  340. + //fprintf(stderr, "buf size: %d\n", size);
  341. + //fprintf(stderr, "iso size: %d\n", pktsize);
  342. + fullpkts = size / pktsize;
  343. + //fprintf(stderr, "Number of full packets: %d\n", fullpkts);
  344. + // Find length of partial packet.
  345. + partpktsize = size % pktsize;
  346. + //fprintf(stderr, "Size of partial packet: %d\n", partpktsize);
  347. + // Find total number of packets to be transfered.
  348. + packets = fullpkts + ((partpktsize > 0) ? 1 : 0);
  349. + //fprintf(stderr, "Total number of packets: %d\n", packets);
  350. + // Limit the number of packets transfered according to
  351. + // the Linux usbdevfs maximum read/write buffer size.
  352. + if ((packets < 1) || (packets > 128)) {
  353. + USB_ERROR_STR("error on packet size: %s", strerror(EINVAL));
  354. + return NULL;
  355. + }
  356. +
  357. + // If necessary, allocate the urb and packet
  358. + // descriptor structures from the heap.
  359. + local_urb = iso_urb;
  360. + if (!local_urb) {
  361. + urb_size = sizeof(struct usbdevfs_urb) +
  362. + packets * sizeof(struct usb_iso_packet_desc);
  363. + local_urb = (struct usbdevfs_urb *) calloc(1, urb_size);
  364. + if (!local_urb) {
  365. + USB_ERROR_STR("error on packet size: %s", strerror(EINVAL));
  366. + return NULL;
  367. + }
  368. + }
  369. +
  370. + // Set up each packet for the data to be transferred.
  371. + for (pktcount = 0; pktcount < fullpkts; pktcount++) {
  372. + local_urb->iso_frame_desc[pktcount].length = pktsize;
  373. + local_urb->iso_frame_desc[pktcount].actual_length = 0;
  374. + local_urb->iso_frame_desc[pktcount].status = 0;
  375. + }
  376. +
  377. + // Set up the last packet for the partial data to be transferred.
  378. + if (partpktsize > 0) {
  379. + local_urb->iso_frame_desc[pktcount].length = partpktsize;
  380. + local_urb->iso_frame_desc[pktcount].actual_length = 0;
  381. + local_urb->iso_frame_desc[pktcount++].status = 0;
  382. + }
  383. +
  384. + // Set up the URB structure.
  385. + local_urb->type = USBDEVFS_URB_TYPE_ISO;
  386. + //fprintf(stderr, "type: %d\n", local_urb->type);
  387. + local_urb->endpoint = ep;
  388. + //fprintf(stderr, "endpoint: 0x%x\n", local_urb->endpoint);
  389. + local_urb->status = 0;
  390. + local_urb->flags = USBDEVFS_URB_ISO_ASAP; // Additional flags here?
  391. + //fprintf(stderr, "flags: %d\n", local_urb->flags);
  392. + local_urb->buffer = bytes;
  393. + //fprintf(stderr, "buffer: 0x%x\n", local_urb->buffer);
  394. + local_urb->buffer_length = size;
  395. + //fprintf(stderr, "buffer_length: %d\n", local_urb->buffer_length);
  396. + local_urb->actual_length = 0;
  397. + local_urb->start_frame = 0;
  398. + //fprintf(stderr, "start_frame: %d\n", local_urb->start_frame);
  399. + local_urb->number_of_packets = pktcount;
  400. + //fprintf(stderr, "number_of_packets: %d\n", local_urb->number_of_packets);
  401. + local_urb->error_count = 0;
  402. + local_urb->signr = 0;
  403. + //fprintf(stderr, "signr: %d\n", local_urb->signr);
  404. + local_urb->usercontext = (void *) 0;
  405. + return local_urb;
  406. + }
  407. +
  408. +
  409. + int usb_urb_submit(usb_dev_handle *dev, // Open usb device handle.
  410. + struct usbdevfs_urb *iso_urb, // Pointer to URB.
  411. + struct timeval *tv_submit) { // Time structure pointer.
  412. + int ret;
  413. +
  414. + iso_urb->usercontext = dev;
  415. + // Get actual time, of the URB submission.
  416. + if(tv_submit)
  417. + gettimeofday(tv_submit, NULL);
  418. + // Submit the URB through an IOCTL call.
  419. + ret = ioctl(dev->fd, USBDEVFS_SUBMITURB, iso_urb);
  420. + //fprintf(stderr, "start_frame now: %d\n", iso_urb->start_frame);
  421. + //fprintf(stderr, "submit ioctl return value: %d\n", ret);
  422. + if (ret < 0) {
  423. + //fprintf(stderr, "error submitting URB: %s\n", strerror(errno));
  424. + USB_ERROR_STR("error submitting URB: %s", strerror(errno));
  425. + return -errno;
  426. + }
  427. + return ret;
  428. + }
  429. +
  430. +
  431. + int usb_urb_reap(usb_dev_handle *dev, // Open usb device handle.
  432. + struct usbdevfs_urb *iso_urb, // Pointer to URB.
  433. + int timeout) { // Attempt timeout (usec).
  434. + void *context = NULL;
  435. + int ret;
  436. + struct pollfd ufd[1];
  437. +
  438. + // Get actual time, and add the timeout value. The result is the absolute
  439. + // time where we have to quit waiting for an isochronous message.
  440. + ufd[0].fd = dev->fd;
  441. + ufd[0].events = POLLIN | POLLOUT;
  442. + ufd[0].revents = 0;
  443. + ret = poll(ufd, 1, timeout);
  444. + if(ret <= 0)
  445. + return -ETIMEDOUT;
  446. +
  447. + //fprintf(stderr, "preparing to reap\n");
  448. + ret = ioctl(dev->fd, USBDEVFS_REAPURB, &context);
  449. +
  450. + /*
  451. + * If there was an error, that wasn"t EAGAIN (no completion), then
  452. + * something happened during the reaping and we should return that
  453. + * error now
  454. + */
  455. + //fprintf(stderr, "reap ioctl return value: %d\n", ret);
  456. + if (ret < 0) {
  457. + USB_ERROR_STR("error reaping interrupt URB: %s",
  458. + strerror(errno));
  459. + return -errno;
  460. + }
  461. +
  462. + //fprintf(stderr, "actual_length: %d\n", iso_urb->actual_length);
  463. + //fprintf(stderr, "URB status: %d\n", iso_urb->status);
  464. + //fprintf(stderr, "error count: %d\n", iso_urb->error_count);
  465. +
  466. + //fprintf(stderr, "waiting done\n");
  467. + if(context != NULL && iso_urb != context) {
  468. + fprintf(stderr, "Expected urb: %p but got %p\n", iso_urb, context);
  469. + return -1;
  470. + }
  471. + //fprintf(stderr, "Total bytes: %d\n", bytesdone);
  472. + return iso_urb->actual_length;
  473. + }
  474. +
  475. + int usb_urb_cancel(usb_dev_handle *dev, struct usbdevfs_urb *iso_urb)
  476. + {
  477. + return ioctl(dev->fd, USBDEVFS_DISCARDURB, iso_urb);
  478. + }
  479. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/libusb_augment.h ./libs/libmythtv/r5000/libusb_augment.h
  480. *** ../../mythtv/mythtv/libs/libmythtv/r5000/libusb_augment.h 1969-12-31 16:00:00.000000000 -0800
  481. --- ./libs/libmythtv/r5000/libusb_augment.h 2011-04-08 19:29:47.000000000 -0700
  482. ***************
  483. *** 0 ****
  484. --- 1,36 ----
  485. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  486. + * 2005-10-19/lindi: downloaded from http://www.gaesi.org/~nmct/cvista/cvista/
  487. + *
  488. + * This library is free software; you can redistribute it and/or
  489. + * modify it under the terms of the GNU Lesser General Public
  490. + * License as published by the Free Software Foundation; either
  491. + * version 2.1 of the License, or (at your option) any later version.
  492. + *
  493. + * This library is distributed in the hope that it will be useful,
  494. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  495. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  496. + * Lesser General Public License for more details.
  497. + *
  498. + * You should have received a copy of the GNU Lesser General Public
  499. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  500. + */
  501. +
  502. + #ifdef LIBUSB_AUGMENT
  503. + // Taken from libusb file linux.h to provide the URB structure definitions.
  504. + struct usb_iso_packet_desc {
  505. + unsigned int length;
  506. + unsigned int actual_length;
  507. + unsigned int status;
  508. + };
  509. + #endif
  510. +
  511. + int usbdevfs_urb_signal_completion(void (*cb)( struct usbdevfs_urb *));
  512. + struct usbdevfs_urb *usb_bulk_setup(struct usbdevfs_urb *iso_urb, unsigned char ep,
  513. + char *bytes, int size);
  514. + struct usbdevfs_urb *usb_isochronous_setup(struct usbdevfs_urb *iso_urb,
  515. + unsigned char ep, int pktsize, char *bytes, int size);
  516. + int usb_urb_submit(usb_dev_handle *dev, struct usbdevfs_urb *iso_urb,
  517. + struct timeval *tv_rsubmit);
  518. + int usb_urb_reap(usb_dev_handle *dev, struct usbdevfs_urb *iso_urb,
  519. + int timeout_usec);
  520. + int usb_urb_cancel(usb_dev_handle *dev, struct usbdevfs_urb *iso_urb);
  521. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/r5000.c ./libs/libmythtv/r5000/r5000.c
  522. *** ../../mythtv/mythtv/libs/libmythtv/r5000/r5000.c 1969-12-31 16:00:00.000000000 -0800
  523. --- ./libs/libmythtv/r5000/r5000.c 2011-04-08 19:29:47.000000000 -0700
  524. ***************
  525. *** 0 ****
  526. --- 1,767 ----
  527. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  528. + *
  529. + * This library is free software; you can redistribute it and/or
  530. + * modify it under the terms of the GNU Lesser General Public
  531. + * License as published by the Free Software Foundation; either
  532. + * version 2.1 of the License, or (at your option) any later version.
  533. + *
  534. + * This library is distributed in the hope that it will be useful,
  535. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  536. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  537. + * Lesser General Public License for more details.
  538. + *
  539. + * You should have received a copy of the GNU Lesser General Public
  540. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  541. + */
  542. +
  543. + #include <stdio.h>
  544. + #include <sys/types.h>
  545. + #include <sys/time.h>
  546. + #include <sys/stat.h>
  547. + #include <fcntl.h>
  548. + #include <string.h>
  549. + #include <errno.h>
  550. + #include <stdarg.h>
  551. + #include <time.h>
  552. +
  553. + #ifdef R5K_DEBUG
  554. + char strmfile[256] = "/tmp/strm";
  555. + int fd = -1;
  556. + #endif
  557. +
  558. + #ifdef R5K_RAWUSB
  559. + int usbfd = -1;
  560. + #endif
  561. + #include "r5000_internal.h"
  562. + #include "r5000init.h"
  563. +
  564. + #define R5K_WARM_VID 0x0547
  565. + #define R5K_WARM_PID 0x1002
  566. +
  567. + #define MAX_URBS_IN_FLIGHT 128
  568. +
  569. + static struct {
  570. + char serial[8];
  571. + time_t time;
  572. + } last_cmd_time[10] = {
  573. + {{0}, 0}, {{0}, 0}, {{0}, 0}, {{0}, 0}, {{0}, 0},
  574. + {{0}, 0}, {{0}, 0}, {{0}, 0}, {{0}, 0}, {{0}, 0},
  575. + };
  576. +
  577. +
  578. + #define R5K_UNRELIABLE_TIMEOUT (5 * 60)
  579. + #define R5K_BUTTON_LEN(_r, _b) \
  580. + ((_r)->button->len ? (_r)->button->len \
  581. + : ((unsigned char)(_b)[1]) + 6 )
  582. + #ifndef USE_ISOCHRONOUS
  583. + //BULK
  584. + #define R5K_URB_BUFFER_SIZE (1 << 14)
  585. + #else
  586. + //ISOCHRONOUS
  587. + #define LIBUSB_AUGMENT
  588. + #define R5K_URB_BUFFER_SIZE (1 << 15)
  589. + #endif
  590. + #include "libusb_augment.h"
  591. +
  592. + static int r5000_usb_init = 0;
  593. + static struct {
  594. + unsigned char serial[R5K_MAX_DEVS][8];
  595. + struct usb_device *dev[R5K_MAX_DEVS];
  596. + int count;
  597. + } r5000_dev_map;
  598. +
  599. + static void (*msgcb)(char *msg);
  600. +
  601. + enum {
  602. + R5K_PMT_START = 0x01,
  603. + R5K_PMT_READY = 0x02
  604. + };
  605. +
  606. + long r5klog_count = 0;
  607. + FILE *r5klog_fh = NULL;
  608. + struct timeval r5klog_tv;
  609. + char r5klog_msg[2048];
  610. +
  611. + #ifdef R5000_TRACE
  612. + void r5000_log(int flush, const char *fmt, ...)
  613. + {
  614. + struct timeval tv, tv1;
  615. + va_list args;
  616. + char logmsg[2048];
  617. +
  618. + if(! r5klog_fh) {
  619. + int oldmask = umask(0);
  620. + r5klog_fh = fopen("/tmp/r5000_trace.log", "w+");
  621. + umask(oldmask);
  622. + }
  623. +
  624. + va_start(args,fmt);
  625. + vsnprintf(logmsg,sizeof(logmsg),fmt,args);
  626. + va_end(args);
  627. +
  628. + if (strncmp(logmsg, r5klog_msg, sizeof(logmsg)) == 0) {
  629. + r5klog_count++;
  630. + return;
  631. + }
  632. + gettimeofday(&tv, NULL);
  633. + timersub(&tv, &r5klog_tv, &tv1);
  634. + r5klog_tv = tv;
  635. + if(r5klog_count > 1) {
  636. + fprintf(r5klog_fh, "%ld.%06ld: Repeated %ld times\n", (long)tv1.tv_sec, (long)tv1.tv_usec, r5klog_count);
  637. + printf("%ld.%06ld: Repeated %ld times\n", (long)tv1.tv_sec, (long)tv1.tv_usec, r5klog_count);
  638. + }
  639. + fprintf(r5klog_fh, "%ld.%ld: %s\n", (long)tv1.tv_sec, (long)tv1.tv_usec, logmsg);
  640. + printf("%ld.%ld: %s\n", (long)tv1.tv_sec, (long)tv1.tv_usec, logmsg);
  641. + memcpy(r5klog_msg, logmsg, sizeof(logmsg));
  642. + r5klog_count = 1;
  643. + if(flush) {
  644. + fflush(r5klog_fh);
  645. + }
  646. + }
  647. + #else
  648. + void r5000_log(int flush, const char *fmt, ...)
  649. + {
  650. + }
  651. + #endif
  652. +
  653. + void r5000_print(const char *fmt, ...)
  654. + {
  655. + va_list args;
  656. + char logmsg[1024];
  657. + va_start(args,fmt);
  658. + vsnprintf(logmsg,sizeof(logmsg),fmt,args);
  659. + va_end(args);
  660. + if(msgcb) {
  661. + //msgcb routine must ensure thread safeness
  662. + msgcb(logmsg);
  663. + } else {
  664. + fprintf(stderr, "%s", logmsg);
  665. + }
  666. + }
  667. +
  668. + int r5000_create_urbs(r5kdev_t *r5kdev)
  669. + {
  670. + int i, urbsize;
  671. + #ifndef USE_ISOCHRONOUS
  672. + urbsize = sizeof(struct usbdevfs_urb);
  673. + #else
  674. + urbsize = sizeof(struct usbdevfs_urb) + sizeof(struct usb_iso_packet_desc) * R5K_URB_BUFFER_SIZE / 1024;
  675. + #endif
  676. +
  677. + r5kdev->buffer = (char *)malloc(R5K_URB_BUFFER_SIZE * MAX_URBS_IN_FLIGHT);
  678. + r5kdev->urbs = (struct usbdevfs_urb **)malloc(sizeof(struct usbdevfs_urb *) * MAX_URBS_IN_FLIGHT);
  679. + r5kdev->urbblk = (void *)malloc(urbsize * MAX_URBS_IN_FLIGHT);
  680. + for(i = 0; i < MAX_URBS_IN_FLIGHT; i++) {
  681. + r5kdev->urbs[i] = (struct usbdevfs_urb *)((unsigned long)r5kdev->urbblk + (urbsize * i));
  682. + #ifndef USE_ISOCHRONOUS
  683. + usb_bulk_setup(r5kdev->urbs[i], 0x82, r5kdev->buffer + (R5K_URB_BUFFER_SIZE*i), R5K_URB_BUFFER_SIZE);
  684. + #else
  685. + usb_isochronous_setup(r5kdev->urbs[i], 0x82, 1024, r5kdev->buffer + (R5K_URB_BUFFER_SIZE*i), R5K_URB_BUFFER_SIZE);
  686. + #endif
  687. + }
  688. + r5kdev->nexturb = 0;
  689. + return 1;
  690. + }
  691. +
  692. + int r5000_free_urbs(r5kdev_t *r5kdev)
  693. + {
  694. + free(r5kdev->urbblk);
  695. + free(r5kdev->urbs);
  696. + free(r5kdev->buffer);
  697. + return 0;
  698. + }
  699. +
  700. + usb_dev_handle *r5000_locate_device(
  701. + unsigned short vendor_id, unsigned short product_id, int skip)
  702. + {
  703. + struct usb_bus *bus;
  704. + struct usb_device *dev;
  705. + usb_dev_handle *device_handle = 0;
  706. + usb_find_busses();
  707. + usb_find_devices();
  708. +
  709. + for (bus = usb_get_busses(); bus && !device_handle; bus = bus->next)
  710. + {
  711. + for (dev = bus->devices; dev && !device_handle; dev = dev->next)
  712. + {
  713. + if (dev->descriptor.idVendor == vendor_id &&
  714. + dev->descriptor.idProduct == product_id)
  715. + {
  716. + device_handle = usb_open(dev);
  717. + if(device_handle && skip) {
  718. + usb_close(device_handle);
  719. + device_handle = NULL;
  720. + skip--;
  721. + }
  722. + }
  723. + }
  724. + }
  725. +
  726. + if (device_handle) {
  727. + int open_status = usb_set_configuration(device_handle,1);
  728. +
  729. + open_status = usb_claim_interface(device_handle,0);
  730. +
  731. + open_status = usb_set_altinterface(device_handle,0);
  732. + }
  733. + return (device_handle);
  734. + }
  735. +
  736. + int r5000_dev_init(r5kdev_t *r5kdev) {
  737. + int i, bytes;
  738. + char *ptr;
  739. + unsigned char *serial = r5kdev->serial;
  740. + char datain[0x80];
  741. + bytes = usb_bulk_read(r5kdev->handle, 129, datain, sizeof(datain), 5000);
  742. + for(i = 0; i < R5K_INIT_SERIAL; i++) {
  743. + //PRINTHEX("Write:\n", r5kinit[i].data, r5kinit[i].wlen);
  744. + if(r5kinit[i].wsleep) usleep(r5kinit[i].wsleep);
  745. + usb_bulk_write(r5kdev->handle, 1, r5kinit[i].data, r5kinit[i].wlen, 5000);
  746. + if(r5kinit[i].rsleep) usleep(r5kinit[i].rsleep);
  747. + bytes = usb_bulk_read(r5kdev->handle, 129, datain, sizeof(datain), 5000);
  748. + //PRINTHEX("Read:\n", datain, bytes);
  749. + if(r5kinit[i].rlen > 0 && bytes != r5kinit[i].rlen) {
  750. + r5000_print("R5000 initialization failed at stage %d:\n\tExpected %d bytes, but got %d bytes\n", i, r5kinit[i].rlen, bytes);
  751. + return 0;
  752. + }
  753. + }
  754. +
  755. + //last read is serial #
  756. + if (datain[0] != 0x08) {
  757. + r5000_print("R5000 initialization failed reading serial #\n");
  758. + return 0;
  759. + }
  760. + for(ptr = datain + 6; ptr < datain + 13; ptr++) {
  761. + *serial++ = ( *ptr >= '0' && *ptr <= 'z' ) ? *ptr : '*';
  762. + }
  763. + *serial = 0;
  764. +
  765. + //complete initialization now
  766. + for(; i < R5K_INIT_MAX; i++) {
  767. + //PRINTHEX("Write:\n", r5kinit[i].data, r5kinit[i].wlen);
  768. + if(r5kinit[i].wsleep) usleep(r5kinit[i].wsleep);
  769. + usb_bulk_write(r5kdev->handle, 1, r5kinit[i].data, r5kinit[i].wlen, 5000);
  770. + if(r5kinit[i].rsleep) usleep(r5kinit[i].rsleep);
  771. + bytes = usb_bulk_read(r5kdev->handle, 129, datain, sizeof(datain), 5000);
  772. + //PRINTHEX("Read:\n", datain, bytes);
  773. + if(r5kinit[i].rlen > 0 && bytes != r5kinit[i].rlen) {
  774. + r5000_print("R5000 initialization failed at stage %d:\n\tExpected %d bytes, but got %d bytes\n", i, r5kinit[i].rlen, bytes);
  775. + return 0;
  776. + }
  777. + }
  778. + return 1;
  779. + }
  780. +
  781. + int r5000_start_stream(r5kdev_t *r5kdev)
  782. + {
  783. + char data[0x80];
  784. + int bytes;
  785. + int i;
  786. + struct usb_dev_handle *handle = (struct usb_dev_handle *)r5kdev->handle;
  787. +
  788. + //*r5kdev->last_command_time = time(NULL);
  789. + r5000_log(0, "r5000_start_stream(%p)", r5kdev);
  790. + if(! r5kdev->urbs)
  791. + r5000_create_urbs(r5kdev);
  792. +
  793. + data[0] = 0x30;
  794. + usb_bulk_write(handle, 1, data, 1, 5000);
  795. + bytes = usb_bulk_read(handle, 129, data, 2, 5000);
  796. +
  797. + //0x50 sets byte mode. Use '0x60' to set word mode
  798. + data[0] = r5kdev->read_words ? 0x60: 0x50;
  799. + usb_bulk_write(handle, 1, data, 1, 5000);
  800. +
  801. + for(i=0; i < MAX_URBS_IN_FLIGHT; i++) {
  802. + usb_urb_submit(handle, r5kdev->urbs[i], NULL);
  803. + }
  804. + r5kdev->nexturb = 0;
  805. + r5kdev->streaming = 1;
  806. + if(r5kdev->start_stream)
  807. + r5kdev->start_stream(r5kdev);
  808. + return 1;
  809. + }
  810. +
  811. + int r5000_stop_stream(r5kdev_t *r5kdev)
  812. + {
  813. + struct usb_dev_handle *handle = (struct usb_dev_handle *)r5kdev->handle;
  814. + struct usbdevfs_urb **urbs = r5kdev->urbs;
  815. + int i;
  816. +
  817. + //*r5kdev->last_command_time = time(NULL);
  818. + r5000_log(0, "r5000_stop_stream(%p)", r5kdev);
  819. + if(r5kdev->streaming) {
  820. + for(i=0; i < MAX_URBS_IN_FLIGHT; i++)
  821. + usb_urb_cancel(handle, urbs[i]);
  822. + r5kdev->streaming = 0;
  823. + }
  824. + return 1;
  825. + }
  826. +
  827. + /* r5000_init must be called from a thread-safe context */
  828. + int r5000_init(void (*_msgcb)(char *str))
  829. + {
  830. + int bus_count, dev_count;
  831. + r5kdev_t r5kd;
  832. + int count = 0;
  833. +
  834. + r5000_log(0, "r5000_init()");
  835. +
  836. + msgcb = _msgcb;
  837. +
  838. + if(r5000_usb_init)
  839. + return 1;
  840. + usb_init();
  841. + bus_count = usb_find_busses();
  842. + dev_count = usb_find_devices();
  843. + if(bus_count == 0 || dev_count ==0) {
  844. + r5000_print("R5000 failed to locate any USB devices. Are you sure you have permissions set properly?\n");
  845. + return 0;
  846. + }
  847. + while(r5000_dev_map.count < R5K_MAX_DEVS) {
  848. + r5kd.handle = r5000_locate_device(R5K_WARM_VID, R5K_WARM_PID, count);
  849. + if(! r5kd.handle)
  850. + break;
  851. + if (r5000_dev_init(&r5kd)) {
  852. + memcpy(r5000_dev_map.serial[r5000_dev_map.count], r5kd.serial, 8);
  853. + r5000_dev_map.dev[r5000_dev_map.count] = usb_device(r5kd.handle);
  854. + r5000_dev_map.count++;
  855. + }
  856. + count++;
  857. + usb_close(r5kd.handle);
  858. + }
  859. + if(! r5000_dev_map.count) {
  860. + r5000_print("R5000 failed to locate any R5000 devices. Are you sure you have permissions set properly?\n");
  861. + return 0;
  862. + }
  863. + r5000_usb_init = 1;
  864. + return 1;
  865. + }
  866. +
  867. + r5kdev_t *r5000_open(r5ktype_t type,
  868. + unsigned int (*cb)(unsigned char *buffer, int len, void *callback_data),
  869. + void *cb_data,
  870. + const char *serial)
  871. + {
  872. + r5kdev_t *r5kdev, r5kd;
  873. + int count = 0;
  874. +
  875. + r5000_log(0, "r5000_open(%d, NULL, %p, %s)", type, cb_data, serial);
  876. + memset(&r5kd, 0, sizeof(r5kdev_t));
  877. +
  878. + if(! r5000_usb_init) {
  879. + r5000_print("R5000 was not initialized before r5000_open(). Please call r5000_init() first\n");
  880. + return NULL;
  881. + }
  882. + for(count = 0; count < r5000_dev_map.count; count++) {
  883. + if(! serial || memcmp(r5000_dev_map.serial[count], serial, 8) == 0) {
  884. + r5kd.handle = usb_open(r5000_dev_map.dev[count]);
  885. + if(! r5kd.handle)
  886. + return NULL;
  887. + usb_set_configuration(r5kd.handle,1);
  888. + usb_claim_interface(r5kd.handle,0);
  889. + usb_set_altinterface(r5kd.handle,0);
  890. + if(! r5000_dev_init(&r5kd)) {
  891. + usb_close(r5kd.handle);
  892. + return NULL;
  893. + }
  894. + break;
  895. + }
  896. + }
  897. + if(count == r5000_dev_map.count) {
  898. + //We can't get here unless a serial was specified
  899. + r5000_print("Could not locate R5000 device with serial '%s'\n", serial);
  900. + return NULL;
  901. + }
  902. + #ifdef R5K_DEBUG
  903. + printf("Reading stream file: %s\n", strmfile);
  904. + fd = open(strmfile, O_RDONLY);
  905. + #endif
  906. + #ifdef R5K_RAWUSB
  907. + usbfd = open("raw.av", O_WRONLY | O_CREAT | O_TRUNC, 0666);
  908. + #endif
  909. + r5kdev = (r5kdev_t *)malloc(sizeof(r5kdev_t));
  910. + *r5kdev = r5kd;
  911. + r5kdev->urbs = NULL;
  912. + r5kdev->cb = cb;
  913. + r5kdev->cb_data = cb_data;
  914. + r5kdev->stb_type = type;
  915. +
  916. + r5kdev->last_command_time = &last_cmd_time[0].time;
  917. + for(count = 0; count < 10; count++) {
  918. + if (last_cmd_time[count].serial[0] == 0) {
  919. + memcpy(last_cmd_time[count].serial, r5kdev->serial, 8);
  920. + r5kdev->last_command_time = &last_cmd_time[count].time;
  921. + break;
  922. + } else if(memcmp(last_cmd_time[count].serial, r5kdev->serial, 8) == 0) {
  923. + r5kdev->last_command_time = &last_cmd_time[count].time;
  924. + break;
  925. + }
  926. + }
  927. +
  928. + switch(type) {
  929. + case R5K_STB_VIP211:
  930. + case R5K_STB_VIP622:
  931. + vip_init(r5kdev);
  932. + break;
  933. + case R5K_STB_DIRECTV:
  934. + case R5K_STB_DISH6000:
  935. + pes_init(r5kdev);
  936. + break;
  937. + case R5K_STB_DSR:
  938. + case R5K_STB_HDD:
  939. + sat_init(r5kdev);
  940. + break;
  941. + default:
  942. + r5000_print("Unknown STB type %d specified.\n", type);
  943. + r5kdev->stb_type = R5K_STB_VIP211;
  944. + vip_init(r5kdev);
  945. + break;
  946. + }
  947. + {
  948. + char fw[4];
  949. + r5000_get_fw_version(r5kdev, fw);
  950. + r5000_print("R5000 firmware version for %s: %s\n", r5kdev->serial, fw);
  951. + }
  952. + return r5kdev;
  953. + }
  954. +
  955. + int r5000_close(r5kdev_t *r5kdev)
  956. + {
  957. + r5000_log(1, "r5000_close(%p)", r5kdev);
  958. + if(! r5kdev)
  959. + return 1;
  960. + if(r5kdev->urbs) {
  961. + if(r5kdev->streaming)
  962. + r5000_stop_stream(r5kdev);
  963. + r5000_free_urbs(r5kdev);
  964. + }
  965. + usb_close(r5kdev->handle);
  966. + #ifdef R5K_RAWUSB
  967. + if(usbfd >= 0) close(usbfd);
  968. + #endif
  969. + switch(r5kdev->stb_type) {
  970. + case R5K_STB_VIP211:
  971. + case R5K_STB_VIP622:
  972. + vip_free(r5kdev);
  973. + break;
  974. + case R5K_STB_DIRECTV:
  975. + case R5K_STB_DISH6000:
  976. + pes_free(r5kdev);
  977. + break;
  978. + case R5K_STB_DSR:
  979. + case R5K_STB_HDD:
  980. + sat_free(r5kdev);
  981. + break;
  982. + }
  983. + free(r5kdev);
  984. + return 1;
  985. + }
  986. +
  987. + int r5000_loop_iterate(r5kdev_t *r5kdev, int timeout_usec)
  988. + {
  989. + struct usb_dev_handle *handle = (struct usb_dev_handle *)r5kdev->handle;
  990. + struct usbdevfs_urb **urbs = r5kdev->urbs;
  991. + int len;
  992. + char *buf;
  993. +
  994. + r5000_log(0, "r5000_loop_iterate(%p, %d)", r5kdev, timeout_usec);
  995. + if(! r5kdev->streaming)
  996. + return -1;
  997. + len = usb_urb_reap(handle, urbs[r5kdev->nexturb], timeout_usec);
  998. + if(len <= 0) {
  999. + if(len != -ETIMEDOUT)
  1000. + r5000_print("(%d) Reap failed at %08x: %s\n", r5kdev->nexturb, r5kdev->bytes_read, strerror(errno));
  1001. + return len;
  1002. + }
  1003. + buf = r5kdev->buffer + (R5K_URB_BUFFER_SIZE*r5kdev->nexturb);
  1004. + #ifdef R5K_RAWUSB
  1005. + if(usbfd >= 0) write(usbfd, buf, len);
  1006. + #endif
  1007. + #ifdef R5K_DEBUG
  1008. + if(fd >= 0) {
  1009. + int newlen = read(fd, buf, len);
  1010. + if(newlen < len) {
  1011. + r5000_print("hit end of debug file\n");
  1012. + lseek(fd, 0, SEEK_SET);
  1013. + read(fd, buf + newlen, len - newlen);
  1014. + }
  1015. + }
  1016. + #endif
  1017. + r5kdev->process_block(r5kdev, (unsigned char *)buf, len);
  1018. + r5kdev->bytes_read += len;
  1019. + usb_urb_submit(handle, urbs[r5kdev->nexturb], NULL);
  1020. + r5kdev->nexturb = (r5kdev->nexturb + 1) % MAX_URBS_IN_FLIGHT;
  1021. + if(r5kdev->nexturb == 0) {
  1022. + *r5kdev->last_command_time = time(NULL);
  1023. + }
  1024. + return 0;
  1025. + }
  1026. +
  1027. + //use this to read a status frame. It doesn't do anything special
  1028. + //but makes it obvious what data is expected
  1029. + int r5000_clear_status(r5kdev_t *r5kdev, char *buf)
  1030. + {
  1031. + int i = 5;
  1032. + int ret;
  1033. +
  1034. + while (i--) {
  1035. + ret = usb_bulk_read(r5kdev->handle, 129, buf, 128, 5000);
  1036. + if (ret > 2 && (unsigned char)buf[0] == 0xcc && buf[1] == 0x00)
  1037. + return ret;
  1038. + buf[0] = 0xcc;
  1039. + buf[1] = 0x00;
  1040. + r5000_log(0, "r5000_clear_status overflow detected: %d %02x, %02x", ret, (unsigned int)buf[0], (unsigned int)buf[1]);
  1041. + usb_bulk_write(r5kdev->handle, 1, buf, 2, 5000);
  1042. + usleep(100000);
  1043. + }
  1044. + return ret;
  1045. + }
  1046. +
  1047. + #ifdef USE_OLD_POWER_CHECK
  1048. + int r5000_get_power_state(r5kdev_t *r5kdev)
  1049. + {
  1050. + unsigned char data1[1] = { 0x30 };
  1051. + unsigned char data2[0x80];
  1052. + int count = 10;
  1053. + while(count--) {
  1054. + usb_bulk_read(r5kdev->handle, 129, (char *)data2, 128, 5000);
  1055. + usb_bulk_write(r5kdev->handle, 1, (char *)data1, 1, 5000);
  1056. + usleep(100000);
  1057. + if(usb_bulk_read(r5kdev->handle, 1, (char *)data2, 2, 5000) == 2 &&
  1058. + data2[0] == 0x0a && (data2[1] & 0x4e) == 0x4c) {
  1059. + // The following boxes are known to be power active low:
  1060. + // 4DTV 922, Dish 622/722, Bell 9242, D*
  1061. + if(r5kdev->power_active_low)
  1062. + return (!(data2[1] == 0x4d));
  1063. + else
  1064. + return (!!(data2[1] == 0x4d));
  1065. + }
  1066. + usleep(100000);
  1067. + }
  1068. + r5000_print("R5000 failed to read power state. Assuming ON state\n");
  1069. + return 1;
  1070. + }
  1071. +
  1072. + #else
  1073. + int r5000_get_power_state(r5kdev_t *r5kdev)
  1074. + {
  1075. + unsigned char data2[0x80];
  1076. + int count = 10;
  1077. + int len;
  1078. +
  1079. + r5000_log(0, "r5000_get_power_state(%p)", r5kdev);
  1080. +
  1081. + while(count--) {
  1082. + data2[0] = 0x00;
  1083. + len = usb_bulk_read(r5kdev->handle, 129, (char *)data2, 128, 5000);
  1084. + //r5000_print("%d: %02x %02x %02x\n", len, data2[0], data2[1], data2[2]);
  1085. + usleep(100000);
  1086. + if (data2[0] == 0xcc) {
  1087. + // The following boxes are known to be power active low:
  1088. + // 4DTV 922, Dish 622/722, Bell 9242, D*
  1089. + if(r5kdev->power_active_low)
  1090. + return (!(data2[2] & 0x01));
  1091. + else
  1092. + return (!!(data2[2] & 0x01));
  1093. + }
  1094. + }
  1095. + r5000_print("R5000 failed to read power state. Assuming ON state\n");
  1096. + return 1;
  1097. + }
  1098. + #endif
  1099. +
  1100. + int r5000_send_pwr_cmd(r5kdev_t *r5kdev, char *data, int send_clear)
  1101. + {
  1102. + r5000_get_power_state(r5kdev);
  1103. + if (send_clear) {
  1104. + usb_bulk_write(r5kdev->handle, 1, r5kdev->button->clear,
  1105. + R5K_BUTTON_LEN(r5kdev, r5kdev->button->clear),
  1106. + 5000);
  1107. + usleep(r5kdev->button->delay);
  1108. + usleep(r5kdev->button->delay);
  1109. + }
  1110. + usb_bulk_write(r5kdev->handle, 1, data,
  1111. + R5K_BUTTON_LEN(r5kdev, data),
  1112. + 5000);
  1113. + usleep(r5kdev->button->delay);
  1114. + return 1;
  1115. + }
  1116. +
  1117. + int r5000_wait_pwr(r5kdev_t *r5kdev, int on_off)
  1118. + {
  1119. + int new_state, count = 20;
  1120. + while(count-- && (new_state = r5000_get_power_state(r5kdev)) != on_off)
  1121. + ;
  1122. + //r5000_print("End state: %s\n", !on_off ? "On" : "Off");
  1123. + return new_state;
  1124. + }
  1125. +
  1126. + int r5000_toggle_on_off(r5kdev_t *r5kdev)
  1127. + {
  1128. + unsigned on_off;
  1129. +
  1130. + r5000_log(0, "r5000_toggle_on_off(%p)", r5kdev);
  1131. +
  1132. + on_off = r5000_get_power_state(r5kdev);
  1133. + if(! r5kdev->button) {
  1134. + r5000_print("No button IR commands defined for this device!\n");
  1135. + return on_off;
  1136. + }
  1137. + //r5000_print("Start state: %s\n", on_off ? "On" : "Off");
  1138. + r5000_send_pwr_cmd(r5kdev, r5kdev->button->power, 1);
  1139. + on_off = r5000_wait_pwr(r5kdev, ! on_off);
  1140. + //r5000_print("End state: %s\n", on_off ? "On" : "Off");
  1141. + return on_off;
  1142. + }
  1143. +
  1144. + int r5000_power_on_off(r5kdev_t *r5kdev, int turn_on)
  1145. + {
  1146. + char *pwr_command;
  1147. + int on_off;
  1148. + int wait_time = 0;
  1149. +
  1150. + r5000_log(0, "r5000_power_on_off(%p, %d)", r5kdev, turn_on);
  1151. +
  1152. + on_off = r5000_get_power_state(r5kdev);
  1153. +
  1154. + if(! r5kdev->button) {
  1155. + r5000_print("No button IR commands defined for this device!\n");
  1156. + return on_off;
  1157. + }
  1158. +
  1159. + if(r5kdev->discrete_power) {
  1160. + //r5000_print("Using discrete power commands\n");
  1161. + if(turn_on) {
  1162. + pwr_command = r5kdev->button->power_on;
  1163. + } else {
  1164. + pwr_command = r5kdev->button->power_off;
  1165. + }
  1166. + } else {
  1167. + pwr_command = r5kdev->button->power;
  1168. + }
  1169. +
  1170. + if(r5kdev->unreliable_power_detect && on_off &&
  1171. + (time(NULL) - *r5kdev->last_command_time > R5K_UNRELIABLE_TIMEOUT)) {
  1172. + //The VIP211 can not be relied upon to be on when it says it is
  1173. + // But 'off' is trustworthy
  1174. + // We assume that if we've recorded or changed channel in the past 5 mins, that we can trust the state
  1175. + printf("Potential unreliable power state detected. Trying to ensure power state!\n");
  1176. + if(r5kdev->discrete_power) {
  1177. + wait_time = 2500000;
  1178. + } else {
  1179. + //We can't trustthe 'on' state, so toggle it off then back on to be sure
  1180. + r5000_send_pwr_cmd(r5kdev, pwr_command, turn_on != 2);
  1181. + r5000_wait_pwr(r5kdev, 0);
  1182. + }
  1183. + } else if(on_off == !!turn_on) {
  1184. + return on_off;
  1185. + }
  1186. +
  1187. + r5000_send_pwr_cmd(r5kdev, pwr_command, turn_on != 2);
  1188. + if(wait_time)
  1189. + usleep(wait_time);
  1190. + return r5000_wait_pwr(r5kdev, !!turn_on);
  1191. + }
  1192. +
  1193. + int r5000_change_channel(r5kdev_t *r5kdev, const char *chan, int mpeg_prog)
  1194. + {
  1195. + char data2[0x80];
  1196. + const char *ptr = NULL;
  1197. + const char *p;
  1198. + const char ignore[1] = {0xfe};
  1199. +
  1200. + r5000_log(0, "r5000_change_channel(%p, %s, %d)", r5kdev, chan, mpeg_prog);
  1201. + printf("Got channel change command: %s (%d)\n", chan, mpeg_prog);
  1202. +
  1203. + if(! r5kdev)
  1204. + return 0;
  1205. + if (chan) {
  1206. + if(! r5kdev->button) {
  1207. + r5000_print("No button IR commands defined for this device!\n");
  1208. + } else {
  1209. + r5000_clear_status(r5kdev, data2);
  1210. + if(r5kdev->button->clear[0] == 0x00) {
  1211. + usb_bulk_write(r5kdev->handle, 1, r5kdev->button->clear,
  1212. + R5K_BUTTON_LEN(r5kdev, r5kdev->button->clear),
  1213. + 5000);
  1214. + usleep(900000);
  1215. + }
  1216. + //usleep(r5kdev->button->delay);
  1217. + //usleep(r5kdev->button->delay);
  1218. + for(p = chan; *p; p++) {
  1219. + printf("Sending button '%c'\n", *p);
  1220. + ptr = NULL;
  1221. + switch(*p) {
  1222. + case '0' : ptr = r5kdev->button->b0; break;
  1223. + case '1' : ptr = r5kdev->button->b1; break;
  1224. + case '2' : ptr = r5kdev->button->b2; break;
  1225. + case '3' : ptr = r5kdev->button->b3; break;
  1226. + case '4' : ptr = r5kdev->button->b4; break;
  1227. + case '5' : ptr = r5kdev->button->b5; break;
  1228. + case '6' : ptr = r5kdev->button->b6; break;
  1229. + case '7' : ptr = r5kdev->button->b7; break;
  1230. + case '8' : ptr = r5kdev->button->b8; break;
  1231. + case '9' : ptr = r5kdev->button->b9; break;
  1232. + case 'P' : ptr = ignore; r5000_power_on_off(r5kdev, 2); break;
  1233. + }
  1234. + if(ptr && ptr[0] == 0x00) {
  1235. + //r5000_clear_status(r5kdev, data2);
  1236. + usb_bulk_write(r5kdev->handle, 1, ptr,
  1237. + R5K_BUTTON_LEN(r5kdev, ptr),
  1238. + 5000);
  1239. + } else if(ptr != ignore) {
  1240. + r5000_print("No button information found for %c\n", *p);
  1241. + }
  1242. + usleep(r5kdev->button->delay);
  1243. + }
  1244. + //r5000_clear_status(r5kdev, data2);
  1245. + if(r5kdev->button->enter[0] == 0x00) {
  1246. + usb_bulk_write(r5kdev->handle, 1, r5kdev->button->enter,
  1247. + R5K_BUTTON_LEN(r5kdev,r5kdev->button->enter),
  1248. + 5000);
  1249. + }
  1250. + }
  1251. + }
  1252. + r5kdev->channel = (mpeg_prog > 0xffff) ? -(mpeg_prog & 0xffff) : mpeg_prog;
  1253. + if(r5kdev->change_channel)
  1254. + r5kdev->change_channel(r5kdev);
  1255. + *r5kdev->last_command_time = time(NULL);
  1256. + return 1;
  1257. + }
  1258. +
  1259. + int r5000_find_stbs(r5kenum_t *devs)
  1260. + {
  1261. + r5000_log(0, "r5000_find_stbs(%p)", devs);
  1262. + devs->count = 0;
  1263. + if(! r5000_usb_init) {
  1264. + r5000_print("R5000 was not initialized before r5000_find_stbs(). Please call r5000_init() first\n");
  1265. + return 0;
  1266. + }
  1267. + devs->count = r5000_dev_map.count;
  1268. + memcpy(devs->serial, r5000_dev_map.serial, 8 * r5000_dev_map.count);
  1269. + return 1;
  1270. + }
  1271. +
  1272. + void r5000_get_fw_version(r5kdev_t *r5kdev, char *fwver)
  1273. + {
  1274. + char buf[128];
  1275. +
  1276. + r5000_clear_status(r5kdev, buf);
  1277. +
  1278. + buf[0]=0x20;
  1279. + buf[1]=0x00;
  1280. + usb_bulk_write(r5kdev->handle, 1, buf, 2, 5000);
  1281. + usleep(100000);
  1282. + usb_bulk_read(r5kdev->handle, 129, buf, 4, 5000);
  1283. + if ((unsigned char)buf[0] == 0xdd) {
  1284. + fwver[0] = buf[1];
  1285. + fwver[1] = buf[2];
  1286. + fwver[2] = buf[3];
  1287. + } else {
  1288. + fwver[0] = 'x';
  1289. + fwver[1] = '.';
  1290. + fwver[2] = 'x';
  1291. + }
  1292. + fwver[3] = 0;
  1293. + }
  1294. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/r5000.h ./libs/libmythtv/r5000/r5000.h
  1295. *** ../../mythtv/mythtv/libs/libmythtv/r5000/r5000.h 1969-12-31 16:00:00.000000000 -0800
  1296. --- ./libs/libmythtv/r5000/r5000.h 2011-04-08 19:29:47.000000000 -0700
  1297. ***************
  1298. *** 0 ****
  1299. --- 1,52 ----
  1300. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  1301. + *
  1302. + * This library is free software; you can redistribute it and/or
  1303. + * modify it under the terms of the GNU Lesser General Public
  1304. + * License as published by the Free Software Foundation; either
  1305. + * version 2.1 of the License, or (at your option) any later version.
  1306. + *
  1307. + * This library is distributed in the hope that it will be useful,
  1308. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1309. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1310. + * Lesser General Public License for more details.
  1311. + *
  1312. + * You should have received a copy of the GNU Lesser General Public
  1313. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  1314. + */
  1315. +
  1316. + #ifndef R5000_H
  1317. + #define R5000_H
  1318. +
  1319. + #ifndef r5kdev_t
  1320. + #define r5kdev_t void
  1321. + #endif
  1322. +
  1323. + #define R5K_MAX_DEVS 10
  1324. + typedef struct {
  1325. + unsigned char serial[R5K_MAX_DEVS][8];
  1326. + int count;
  1327. + } r5kenum_t;
  1328. +
  1329. + typedef enum {
  1330. + R5K_STB_VIP211 = 0,
  1331. + R5K_STB_DIRECTV,
  1332. + R5K_STB_HDD,
  1333. + R5K_STB_DSR,
  1334. + R5K_STB_VIP622,
  1335. + R5K_STB_DISH6000,
  1336. + R5K_STB_MAX,
  1337. + } r5ktype_t;
  1338. +
  1339. + extern int r5000_init(void (*_msgcb)(char *str));
  1340. + extern r5kdev_t *r5000_open(r5ktype_t type, unsigned int (*cb)(unsigned char *buffer, int len, void *callback_data), void *cb_data, const char *serial);
  1341. + extern int r5000_close(r5kdev_t *r5kdev);
  1342. + extern int r5000_start_stream(r5kdev_t *r5kdev);
  1343. + extern int r5000_stop_stream(r5kdev_t *r5kdev);
  1344. + extern int r5000_loop_iterate(r5kdev_t *r5kdev, int timeout_usec);
  1345. + extern int r5000_get_power_state(r5kdev_t *r5kdev);
  1346. + extern int r5000_toggle_on_off(r5kdev_t *r5kdev);
  1347. + extern int r5000_power_on_off(r5kdev_t *r5kdev, int turn_on);
  1348. + extern int r5000_change_channel(r5kdev_t *r5kdev, const char *chan, int mpeg_prog);
  1349. + extern int r5000_find_stbs(r5kenum_t *devs);
  1350. + extern void r5000_get_fw_version(r5kdev_t *r5kdev, char *fwver);
  1351. + #endif //R5000_H
  1352. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/r5000init.h ./libs/libmythtv/r5000/r5000init.h
  1353. *** ../../mythtv/mythtv/libs/libmythtv/r5000/r5000init.h 1969-12-31 16:00:00.000000000 -0800
  1354. --- ./libs/libmythtv/r5000/r5000init.h 2011-04-08 19:29:47.000000000 -0700
  1355. ***************
  1356. *** 0 ****
  1357. --- 1,79 ----
  1358. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  1359. + *
  1360. + * This library is free software; you can redistribute it and/or
  1361. + * modify it under the terms of the GNU Lesser General Public
  1362. + * License as published by the Free Software Foundation; either
  1363. + * version 2.1 of the License, or (at your option) any later version.
  1364. + *
  1365. + * This library is distributed in the hope that it will be useful,
  1366. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1367. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1368. + * Lesser General Public License for more details.
  1369. + *
  1370. + * You should have received a copy of the GNU Lesser General Public
  1371. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  1372. + */
  1373. +
  1374. + #ifndef R5000_INIT_H
  1375. + #define R5000_INIT_H
  1376. +
  1377. + #define R5K_INIT_MAX 9
  1378. + #define R5K_INIT_SERIAL 8
  1379. + #define R5K_DEFAULT_SLEEP 100000
  1380. + typedef struct {
  1381. + int rsleep;
  1382. + int rlen;
  1383. + int wsleep;
  1384. + int wlen;
  1385. + char data[0x40];
  1386. + } r5kinit_t;
  1387. +
  1388. + r5kinit_t r5kinit[R5K_INIT_MAX] = {
  1389. + // 0
  1390. + {R5K_DEFAULT_SLEEP, -1, 0, 64,
  1391. + {0x30}},
  1392. + // 1
  1393. + {R5K_DEFAULT_SLEEP, 1, 0, 64,
  1394. + {0x08, 0x00, 0x20, 0x00, 0x00, 0x3a, 0xd4, 0x29, 0x7c, 0x56, 0x31, 0x44, 0x86, 0x6d, 0x0d, 0x0d,
  1395. + 0x1b, 0x0a, 0xad, 0x0f, 0xd0, 0x2e, 0x94, 0x3f, 0xd4, 0x08, 0xa2, 0x4b, 0x68, 0x14, 0x1f, 0x13,
  1396. + 0x04, 0x62, 0x1b, 0x14, 0xb9, 0x69, 0xcc, 0x25, 0x91, 0x06, 0xc9, 0x26, 0xf9, 0x41, 0x64, 0x46,
  1397. + 0x7d, 0x17, 0x61, 0x09, 0x5c, 0x5b, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
  1398. + // 2
  1399. + {R5K_DEFAULT_SLEEP, 1, 0, 64,
  1400. + {0x08, 0x00, 0x5a, 0x00, 0x00, 0x06, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1401. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1402. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1403. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
  1404. + // 3
  1405. + {R5K_DEFAULT_SLEEP, 1, 0, 64,
  1406. + {0x08, 0x00, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1407. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1408. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1409. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
  1410. + // 4
  1411. + {R5K_DEFAULT_SLEEP, 1, R5K_DEFAULT_SLEEP, 64,
  1412. + {0x08, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1413. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1414. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1415. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
  1416. + // 5
  1417. + {R5K_DEFAULT_SLEEP, 26, 0, 6,
  1418. + {0x08, 0x01, 0x00, 0x00, 0x01, 0x14}},
  1419. + // 6
  1420. + {R5K_DEFAULT_SLEEP, 1, 0, 64,
  1421. + {0x08, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1422. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1423. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1424. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
  1425. + // 7
  1426. + {R5K_DEFAULT_SLEEP, 22, 0, 64,
  1427. + {0x08, 0x01, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1428. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1429. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1430. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
  1431. + // 8
  1432. + {R5K_DEFAULT_SLEEP, 4, 0, 1,
  1433. + {0x20}}
  1434. + };
  1435. +
  1436. + #endif
  1437. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/r5000_internal.h ./libs/libmythtv/r5000/r5000_internal.h
  1438. *** ../../mythtv/mythtv/libs/libmythtv/r5000/r5000_internal.h 1969-12-31 16:00:00.000000000 -0800
  1439. --- ./libs/libmythtv/r5000/r5000_internal.h 2011-04-08 19:29:47.000000000 -0700
  1440. ***************
  1441. *** 0 ****
  1442. --- 1,127 ----
  1443. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  1444. + *
  1445. + * This library is free software; you can redistribute it and/or
  1446. + * modify it under the terms of the GNU Lesser General Public
  1447. + * License as published by the Free Software Foundation; either
  1448. + * version 2.1 of the License, or (at your option) any later version.
  1449. + *
  1450. + * This library is distributed in the hope that it will be useful,
  1451. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1452. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1453. + * Lesser General Public License for more details.
  1454. + *
  1455. + * You should have received a copy of the GNU Lesser General Public
  1456. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  1457. + */
  1458. +
  1459. + #ifndef R5000_INT_H
  1460. + #define R5000_INT_H
  1461. +
  1462. + #include <usb.h>
  1463. + #include <linux/usbdevice_fs.h>
  1464. +
  1465. + #define PRINTHEX(str, data, len) if(1) do { \
  1466. + int _i; \
  1467. + fprintf(stderr, str); \
  1468. + for(_i = 0; _i < (len); _i++) { \
  1469. + fprintf(stderr, "%02x ", (unsigned char)(data)[_i]); \
  1470. + if((_i % 16) == 15) fprintf(stderr, "\n"); \
  1471. + } \
  1472. + if(_i % 16) fprintf(stderr, "\n"); \
  1473. + } while(0)
  1474. +
  1475. + #define R5K_MAX_BUTTON_SIZE 0xF8
  1476. + #define R5K_MAX_PIDS 10
  1477. + #define IS_VIDEO(x) ((x) == 0x02 || (x) == 0x1b || (x) == 0x80)
  1478. +
  1479. + struct r5k_descriptor {
  1480. + unsigned char d[10];
  1481. + };
  1482. +
  1483. + struct r5k_epid {
  1484. + int pid;
  1485. + unsigned char id;
  1486. + struct r5k_descriptor desc;
  1487. + };
  1488. +
  1489. + struct r5000_buttons {
  1490. + int len;
  1491. + int delay;
  1492. + char b0[R5K_MAX_BUTTON_SIZE];
  1493. + char b1[R5K_MAX_BUTTON_SIZE];
  1494. + char b2[R5K_MAX_BUTTON_SIZE];
  1495. + char b3[R5K_MAX_BUTTON_SIZE];
  1496. + char b4[R5K_MAX_BUTTON_SIZE];
  1497. + char b5[R5K_MAX_BUTTON_SIZE];
  1498. + char b6[R5K_MAX_BUTTON_SIZE];
  1499. + char b7[R5K_MAX_BUTTON_SIZE];
  1500. + char b8[R5K_MAX_BUTTON_SIZE];
  1501. + char b9[R5K_MAX_BUTTON_SIZE];
  1502. + char clear[R5K_MAX_BUTTON_SIZE];
  1503. + char enter[R5K_MAX_BUTTON_SIZE];
  1504. + char power[R5K_MAX_BUTTON_SIZE];
  1505. + char power_on[R5K_MAX_BUTTON_SIZE];
  1506. + char power_off[R5K_MAX_BUTTON_SIZE];
  1507. + char guide[R5K_MAX_BUTTON_SIZE];
  1508. + };
  1509. +
  1510. + struct r5kdev {
  1511. + usb_dev_handle *handle;
  1512. + unsigned char serial[8];
  1513. + void *urbblk;
  1514. + struct usbdevfs_urb **urbs;
  1515. + char *buffer;
  1516. + int stb_type;
  1517. + int read_words;
  1518. + void (*process_block)(struct r5kdev *r5kdev, unsigned char *buf, int len);
  1519. + void (*start_stream)(struct r5kdev *r5kdev);
  1520. + void (*change_channel)(struct r5kdev *r5kdev);
  1521. + void *stbdata;
  1522. + unsigned int (*cb)(unsigned char *buffer, int len, void *callback_data);
  1523. + void *cb_data;
  1524. + int nexturb;
  1525. + int streaming;
  1526. + int bytes_read;
  1527. + struct r5000_buttons *button;
  1528. + int power_active_low;
  1529. + int discrete_power;
  1530. + int unreliable_power_detect;
  1531. + int channel;
  1532. + time_t *last_command_time;
  1533. + unsigned char pmt_pkt[188];
  1534. + unsigned char num_pmt_entries;
  1535. + unsigned char pmt_state;
  1536. + unsigned char pmt_next_cc;
  1537. + unsigned char pmt_version;
  1538. + struct r5k_epid pmt[R5K_MAX_PIDS];
  1539. + } r5kdev_t;
  1540. + #define r5kdev_t struct r5kdev
  1541. +
  1542. + #include "r5000.h"
  1543. +
  1544. + extern void r5000_print(const char *fmt, ...);
  1545. + extern unsigned char r5000_pat_pkt[188];
  1546. + extern struct r5k_descriptor r5000_pmt_audio_desc;
  1547. + extern struct r5k_descriptor r5000_pmt_video_desc;
  1548. + extern struct r5k_descriptor r5000_pmt_nowplaying_desc;
  1549. + extern void r5000_reset_pmt(r5kdev_t *r5kdev);
  1550. + extern void r5000_send_pmt(r5kdev_t *r5kdev);
  1551. +
  1552. + //Support for DirecTV and Dish/BEV 6000 boxes
  1553. + extern void pes_init(r5kdev_t *r5kdev);
  1554. + extern void pes_free(r5kdev_t *r5kdev);
  1555. +
  1556. + //Support for ViP series Dish Network boxes
  1557. + extern void vip_init(r5kdev_t *r5kdev);
  1558. + extern void vip_free(r5kdev_t *r5kdev);
  1559. +
  1560. + //Support for HDD and DSR series satellite/cable boxes
  1561. + extern void sat_init(r5kdev_t *r5kdev);
  1562. + extern void sat_free(r5kdev_t *r5kdev);
  1563. +
  1564. + //Buttons
  1565. + extern struct r5000_buttons vip_button_cmd;
  1566. + extern struct r5000_buttons directv_button_cmd;
  1567. + extern struct r5000_buttons dish6000_button_cmd;
  1568. + extern struct r5000_buttons dsr_button_cmd;
  1569. + #endif
  1570. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_directv_buttons.c ./libs/libmythtv/r5000/r5k_directv_buttons.c
  1571. *** ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_directv_buttons.c 1969-12-31 16:00:00.000000000 -0800
  1572. --- ./libs/libmythtv/r5000/r5k_directv_buttons.c 2011-04-08 19:29:47.000000000 -0700
  1573. ***************
  1574. *** 0 ****
  1575. --- 1,129 ----
  1576. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  1577. + *
  1578. + * This library is free software; you can redistribute it and/or
  1579. + * modify it under the terms of the GNU Lesser General Public
  1580. + * License as published by the Free Software Foundation; either
  1581. + * version 2.1 of the License, or (at your option) any later version.
  1582. + *
  1583. + * This library is distributed in the hope that it will be useful,
  1584. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1585. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1586. + * Lesser General Public License for more details.
  1587. + *
  1588. + * You should have received a copy of the GNU Lesser General Public
  1589. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  1590. + */
  1591. +
  1592. + //Support for DirectTV remotes
  1593. +
  1594. + #include "r5000_internal.h"
  1595. +
  1596. + struct r5000_buttons directv_button_cmd =
  1597. + {
  1598. + 0x49, //len
  1599. + 400000, //delay
  1600. + //button 0:
  1601. + {
  1602. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1603. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1604. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05,
  1605. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1606. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  1607. + },
  1608. + //button 1:
  1609. + {
  1610. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1611. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1612. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05,
  1613. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1614. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  1615. + },
  1616. + //button 2:
  1617. + {
  1618. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1619. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1620. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05,
  1621. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f,
  1622. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  1623. + },
  1624. + //button 3:
  1625. + {
  1626. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1627. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1628. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05,
  1629. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f,
  1630. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  1631. + },
  1632. + //button 4:
  1633. + {
  1634. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1635. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1636. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f,
  1637. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05,
  1638. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  1639. + },
  1640. + //button 5:
  1641. + {
  1642. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1643. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1644. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f,
  1645. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05,
  1646. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  1647. + },
  1648. + //button 6:
  1649. + {
  1650. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1651. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1652. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1653. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05,
  1654. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  1655. + },
  1656. + //button 7:
  1657. + {
  1658. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1659. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1660. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1661. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05,
  1662. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  1663. + },
  1664. + //button 8:
  1665. + {
  1666. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1667. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1668. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1669. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05,
  1670. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  1671. + },
  1672. + //button 9:
  1673. + {
  1674. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1675. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1676. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1677. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05,
  1678. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  1679. + },
  1680. + //Clear:
  1681. + {
  1682. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1683. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1684. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f,
  1685. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
  1686. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  1687. + },
  1688. + //Enter:
  1689. + {
  1690. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1691. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1692. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f,
  1693. + 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05,
  1694. + 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  1695. + },
  1696. + //Power
  1697. + {
  1698. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  1699. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1700. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05,
  1701. + 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  1702. + 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  1703. + },
  1704. + };
  1705. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_dish6000_buttons.c ./libs/libmythtv/r5000/r5k_dish6000_buttons.c
  1706. *** ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_dish6000_buttons.c 1969-12-31 16:00:00.000000000 -0800
  1707. --- ./libs/libmythtv/r5000/r5k_dish6000_buttons.c 2011-04-08 19:29:47.000000000 -0700
  1708. ***************
  1709. *** 0 ****
  1710. --- 1,190 ----
  1711. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  1712. + *
  1713. + * This library is free software; you can redistribute it and/or
  1714. + * modify it under the terms of the GNU Lesser General Public
  1715. + * License as published by the Free Software Foundation; either
  1716. + * version 2.1 of the License, or (at your option) any later version.
  1717. + *
  1718. + * This library is distributed in the hope that it will be useful,
  1719. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1720. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1721. + * Lesser General Public License for more details.
  1722. + *
  1723. + * You should have received a copy of the GNU Lesser General Public
  1724. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  1725. + */
  1726. +
  1727. + //Support for Dish/BEV 6000 remotes
  1728. +
  1729. + #include "r5000_internal.h"
  1730. +
  1731. + struct r5000_buttons dish6000_button_cmd =
  1732. + {
  1733. + 0x79, //len
  1734. + 800000, //delay
  1735. + //button 0:
  1736. + {
  1737. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  1738. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1739. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  1740. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1741. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  1742. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1743. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  1744. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04,
  1745. + },
  1746. + //button 1:
  1747. + {
  1748. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1749. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1750. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1751. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1752. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1753. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1754. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1755. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  1756. + },
  1757. + //button 2:
  1758. + {
  1759. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1760. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1761. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1762. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1763. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1764. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1765. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1766. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04,
  1767. + },
  1768. + //button 3:
  1769. + {
  1770. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1771. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1772. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1773. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1774. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1775. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1776. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1777. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  1778. + },
  1779. + //button 4:
  1780. + {
  1781. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  1782. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1783. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1784. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1785. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  1786. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1787. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1788. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  1789. + },
  1790. + //button 5:
  1791. + {
  1792. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  1793. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1794. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1795. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1796. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  1797. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1798. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1799. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04,
  1800. + },
  1801. + //button 6:
  1802. + {
  1803. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  1804. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1805. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1806. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1807. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  1808. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1809. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1810. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  1811. + },
  1812. + //button 7:
  1813. + {
  1814. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  1815. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1816. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1817. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1818. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  1819. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1820. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1821. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  1822. + },
  1823. + //button 8:
  1824. + {
  1825. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  1826. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1827. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1828. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1829. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  1830. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1831. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1832. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04,
  1833. + },
  1834. + //button 9:
  1835. + {
  1836. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  1837. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1838. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1839. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1840. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  1841. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1842. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1843. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  1844. + },
  1845. + //Clear:
  1846. + {
  1847. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  1848. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1849. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  1850. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1851. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  1852. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1853. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  1854. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  1855. + },
  1856. + //Enter:
  1857. + {
  1858. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  1859. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1860. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  1861. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1862. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  1863. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1864. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  1865. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  1866. + },
  1867. + //Power
  1868. + {
  1869. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1870. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1871. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1872. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1873. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1874. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1875. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1876. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  1877. + },
  1878. + //Power-On
  1879. + {
  1880. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1881. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1882. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1883. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1884. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1885. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1886. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1887. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04,
  1888. + },
  1889. + //Power-Off
  1890. + {
  1891. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1892. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1893. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  1894. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1895. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  1896. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  1897. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  1898. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04,
  1899. + },
  1900. + };
  1901. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_dsr_buttons.c ./libs/libmythtv/r5000/r5k_dsr_buttons.c
  1902. *** ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_dsr_buttons.c 1969-12-31 16:00:00.000000000 -0800
  1903. --- ./libs/libmythtv/r5000/r5k_dsr_buttons.c 2011-04-08 19:29:47.000000000 -0700
  1904. ***************
  1905. *** 0 ****
  1906. --- 1,105 ----
  1907. + /* Copyright 2010 Alan Nisota <alannisota@gmail.com>
  1908. + *
  1909. + * This library is free software; you can redistribute it and/or
  1910. + * modify it under the terms of the GNU Lesser General Public
  1911. + * License as published by the Free Software Foundation; either
  1912. + * version 2.1 of the License, or (at your option) any later version.
  1913. + *
  1914. + * This library is distributed in the hope that it will be useful,
  1915. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1916. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1917. + * Lesser General Public License for more details.
  1918. + *
  1919. + * You should have received a copy of the GNU Lesser General Public
  1920. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  1921. + */
  1922. + //Support for DSR remotes
  1923. +
  1924. + #include "r5000_internal.h"
  1925. +
  1926. + struct r5000_buttons dsr_button_cmd =
  1927. + {
  1928. + 0x00, //len
  1929. + 400000, //delay
  1930. +
  1931. + //button 0:
  1932. + {
  1933. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09,
  1934. + 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x09,
  1935. + 0x09
  1936. + },
  1937. + //button 1:
  1938. + {
  1939. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x1b,
  1940. + 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09,
  1941. + 0x09
  1942. + },
  1943. + //button 2:
  1944. + {
  1945. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
  1946. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x09,
  1947. + 0x09
  1948. + },
  1949. + //button 3:
  1950. + {
  1951. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09,
  1952. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09,
  1953. + 0x09
  1954. + },
  1955. + //button 4:
  1956. + {
  1957. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x09,
  1958. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b,
  1959. + 0x09
  1960. + },
  1961. + //button 5:
  1962. + {
  1963. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b,
  1964. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b,
  1965. + 0x09
  1966. + },
  1967. + //button 6:
  1968. + {
  1969. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x1b,
  1970. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x1b,
  1971. + 0x09
  1972. + },
  1973. + //button 7:
  1974. + {
  1975. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x1b,
  1976. + 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b,
  1977. + 0x09
  1978. + },
  1979. + //button 8:
  1980. + {
  1981. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b,
  1982. + 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b,
  1983. + 0x09
  1984. + },
  1985. + //button 9:
  1986. + {
  1987. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x1b,
  1988. + 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
  1989. + 0x09
  1990. + },
  1991. + //Clear:
  1992. + {
  1993. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b,
  1994. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09,
  1995. + 0x09
  1996. + },
  1997. + //Enter:
  1998. + {
  1999. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b,
  2000. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09,
  2001. + 0x09
  2002. + },
  2003. + //Power
  2004. + {
  2005. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b,
  2006. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09,
  2007. + 0x09
  2008. + }
  2009. + };
  2010. +
  2011. +
  2012. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_misc.c ./libs/libmythtv/r5000/r5k_misc.c
  2013. *** ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_misc.c 1969-12-31 16:00:00.000000000 -0800
  2014. --- ./libs/libmythtv/r5000/r5k_misc.c 2011-04-08 19:29:47.000000000 -0700
  2015. ***************
  2016. *** 0 ****
  2017. --- 1,158 ----
  2018. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  2019. + *
  2020. + * This library is free software; you can redistribute it and/or
  2021. + * modify it under the terms of the GNU Lesser General Public
  2022. + * License as published by the Free Software Foundation; either
  2023. + * version 2.1 of the License, or (at your option) any later version.
  2024. + *
  2025. + * This library is distributed in the hope that it will be useful,
  2026. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2027. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2028. + * Lesser General Public License for more details.
  2029. + *
  2030. + * You should have received a copy of the GNU Lesser General Public
  2031. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  2032. + */
  2033. +
  2034. + #include <stdio.h>
  2035. + #include <string.h>
  2036. + #include "r5000_internal.h"
  2037. +
  2038. + unsigned char r5000_pat_pkt[188] = {
  2039. + 0x47, 0x40, 0x00, 0x13, 0x00, 0x00, 0xb0, 0x0d, 0x00, 0x06, 0xc5, 0x00, 0x00, 0x00, 0x01, 0xe0,
  2040. + 0x21, 0x19, 0x3a, 0x82, 0xc4, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  2041. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  2042. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  2043. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  2044. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  2045. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  2046. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  2047. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  2048. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  2049. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  2050. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  2051. +
  2052. +
  2053. + struct r5k_descriptor r5000_pmt_audio_desc = {{0x06, 0x0a, 0x04, 0x65, 0x6e, 0x67, 0x00}};
  2054. + struct r5k_descriptor r5000_pmt_video_desc = {{0x00}};
  2055. + struct r5k_descriptor r5000_pmt_nowplaying_desc = {{0x00}};
  2056. +
  2057. + //taken and adapted from libdtv, (c) Rolf Hakenes
  2058. + // CRC32 lookup table for polynomial 0x04c11db7
  2059. + static unsigned int crc_table[256] = {
  2060. + 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
  2061. + 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
  2062. + 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,
  2063. + 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
  2064. + 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3,
  2065. + 0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
  2066. + 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef,
  2067. + 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
  2068. + 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb,
  2069. + 0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
  2070. + 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
  2071. + 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
  2072. + 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4,
  2073. + 0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
  2074. + 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08,
  2075. + 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
  2076. + 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc,
  2077. + 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
  2078. + 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050,
  2079. + 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
  2080. + 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
  2081. + 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
  2082. + 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1,
  2083. + 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
  2084. + 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5,
  2085. + 0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
  2086. + 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9,
  2087. + 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
  2088. + 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd,
  2089. + 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
  2090. + 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
  2091. + 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
  2092. + 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2,
  2093. + 0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
  2094. + 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e,
  2095. + 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
  2096. + 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a,
  2097. + 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
  2098. + 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676,
  2099. + 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
  2100. + 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
  2101. + 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
  2102. + 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4};
  2103. +
  2104. + static void r5000_calc_crc(unsigned char *out, const unsigned char *d, int len)
  2105. + {
  2106. + register int i;
  2107. + unsigned int crc = 0xFFFFFFFF;
  2108. + const unsigned char *u=(const unsigned char*)d; // Saves '& 0xff'
  2109. +
  2110. + for (i=0; i<len; i++)
  2111. + crc = (crc << 8) ^ crc_table[((crc >> 24) ^ *u++)];
  2112. +
  2113. + *out++ = (crc >> 24) & 0xff;
  2114. + *out++ = (crc >> 16) & 0xff;
  2115. + *out++ = (crc >> 8) & 0xff;
  2116. + *out++ = (crc >> 0) & 0xff;
  2117. + }
  2118. +
  2119. + static void r5000_build_pmt(r5kdev_t *r5kdev)
  2120. + {
  2121. + int i;
  2122. + unsigned char *ptr;
  2123. + unsigned char ts[188] = {
  2124. + 0x47, 0x40, 0x21, 0x10,
  2125. + 0x00, 0x02,
  2126. + 0xb0, 0x00, //length
  2127. + 0x00, 0x01,
  2128. + 0xc1, //version<<1 (5 bits) | current_next
  2129. + 0x00, 0x00, //section/last_section
  2130. + 0xf0, 0x00, //PCR_PID
  2131. + 0xf0, 0x00}; //Program Info Length
  2132. +
  2133. + ts[3] = 0x10 | r5kdev->pmt_next_cc;
  2134. +
  2135. + //Change the PMT version every time we rebuild the PMT
  2136. + ts[10] |= r5kdev->pmt_version << 1;
  2137. + r5kdev->pmt_version = (r5kdev->pmt_version + 1) % 32;
  2138. +
  2139. + r5000_print("Building PMT\n");
  2140. + ptr = ts + 17;
  2141. + for(i = 0; i < r5kdev->num_pmt_entries; i++) {
  2142. + *ptr++ = r5kdev->pmt[i].id;
  2143. + *ptr++ = 0xe0 | (r5kdev->pmt[i].pid>>8);
  2144. + *ptr++ = r5kdev->pmt[i].pid & 0xff;
  2145. + *ptr++ = 0xf0;
  2146. + memcpy(ptr, r5kdev->pmt[i].desc.d, r5kdev->pmt[i].desc.d[0]+1);
  2147. + ptr += r5kdev->pmt[i].desc.d[0]+1;
  2148. + if(IS_VIDEO(r5kdev->pmt[i].id)) {
  2149. + ts[13] = 0xe0 | (r5kdev->pmt[i].pid >> 8);
  2150. + ts[14] = r5kdev->pmt[i].pid & 0xff;
  2151. + }
  2152. + }
  2153. + ts[7] = (ptr - ts) - 8/*header*/ + 4/*CRC*/;
  2154. + r5000_calc_crc(ptr, ts + 5, (ptr - ts) - 5);
  2155. + memset(ptr+4, 0xff, 188 - (ptr + 4 - ts));
  2156. + memcpy(r5kdev->pmt_pkt, ts, 188);
  2157. + //PRINTHEX("PMT", r5kdev->pmt_pkt, 188);
  2158. + }
  2159. +
  2160. + void r5000_reset_pmt(r5kdev_t *r5kdev)
  2161. + {
  2162. + r5kdev->num_pmt_entries = 0;
  2163. + r5kdev->pmt_state = 0;
  2164. + r5kdev->pmt_pkt[0] = 0;
  2165. + }
  2166. +
  2167. + void r5000_send_pmt(r5kdev_t *r5kdev)
  2168. + {
  2169. + if(r5kdev->pmt_pkt[0] != 0x47) {
  2170. + r5000_build_pmt(r5kdev);
  2171. + }
  2172. + r5kdev->pmt_pkt[3] = 0x10 | r5kdev->pmt_next_cc;
  2173. + r5kdev->pmt_next_cc = (r5kdev->pmt_next_cc + 1) & 0x0f;
  2174. + r5kdev->cb(r5kdev->pmt_pkt, 188, r5kdev->cb_data);
  2175. + }
  2176. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_pes.c ./libs/libmythtv/r5000/r5k_pes.c
  2177. *** ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_pes.c 1969-12-31 16:00:00.000000000 -0800
  2178. --- ./libs/libmythtv/r5000/r5k_pes.c 2011-04-08 19:29:47.000000000 -0700
  2179. ***************
  2180. *** 0 ****
  2181. --- 1,316 ----
  2182. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  2183. + *
  2184. + * This library is free software; you can redistribute it and/or
  2185. + * modify it under the terms of the GNU Lesser General Public
  2186. + * License as published by the Free Software Foundation; either
  2187. + * version 2.1 of the License, or (at your option) any later version.
  2188. + *
  2189. + * This library is distributed in the hope that it will be useful,
  2190. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2191. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2192. + * Lesser General Public License for more details.
  2193. + *
  2194. + * You should have received a copy of the GNU Lesser General Public
  2195. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  2196. + */
  2197. +
  2198. + //Support for DirecTV boxes
  2199. + #include <netinet/in.h>
  2200. + #include <string.h>
  2201. +
  2202. + #include "r5000_internal.h"
  2203. +
  2204. + #define DTV_VPID 0x1322
  2205. + #define DTV_APID 0x1333
  2206. + #define DTV_PAT_PMT_COUNT 5000
  2207. +
  2208. + struct r5000_dtv {
  2209. + unsigned char vbuf[188*2+4];
  2210. + unsigned char abuf[188*2+6];
  2211. + unsigned char *video;
  2212. + unsigned char *audio;
  2213. + unsigned int vpos;
  2214. + unsigned int apos;
  2215. + unsigned int vstart;
  2216. + unsigned int astart;
  2217. + unsigned int video_cc;
  2218. + unsigned int audio_cc;
  2219. + unsigned int vstate;
  2220. + unsigned int pic_pos;
  2221. + int alen;
  2222. + unsigned int pat_pmt_count;
  2223. + };
  2224. +
  2225. + //The following are used to convert DirectTV into TS format
  2226. + static int directv_make_empty_pes(unsigned char *ptr, unsigned char type)
  2227. + {
  2228. + ptr[0] = 0x00;
  2229. + ptr[1] = 0x00;
  2230. + ptr[2] = 0x01;
  2231. + ptr[3] = type;
  2232. + ptr[4] = 0x00;
  2233. + ptr[5] = 0x00;
  2234. + ptr[6] = 0x80;
  2235. + ptr[7] = 0x00; //2 MSB represent PTS/DTS flag
  2236. + ptr[8] = 0x0a;
  2237. + ptr[9] = 0xff;
  2238. + ptr[10] = 0xff;
  2239. + ptr[11] = 0xff;
  2240. + ptr[12] = 0xff;
  2241. + ptr[13] = 0xff;
  2242. + ptr[14] = 0xff;
  2243. + ptr[15] = 0xff;
  2244. + ptr[16] = 0xff;
  2245. + ptr[17] = 0xff;
  2246. + ptr[18] = 0xff;
  2247. + return 19;
  2248. + }
  2249. +
  2250. + static void directv_make_pespts(unsigned char *outptr, unsigned int pts)
  2251. + {
  2252. + pts = htonl(pts);
  2253. + unsigned char *inpts = (unsigned char *)&pts;
  2254. + outptr[0] = 0x01 |
  2255. + ((inpts[0] & 0xC0) >>5);
  2256. + outptr[1] = ((inpts[0] & 0x3F) << 2) |
  2257. + ((inpts[1] & 0xC0) >> 6);
  2258. + outptr[2] = 0x01 | ((inpts[1] & 0x3F) << 2) |
  2259. + ((inpts[2] & 0x80) >> 6);
  2260. + outptr[3] = ((inpts[2] & 0x7F) << 1) |
  2261. + ((inpts[3] & 0x80) >> 7);
  2262. + outptr[4] = 0x01 | ((inpts[3] & 0x7F) << 1);
  2263. + }
  2264. +
  2265. + static void directv_update_video_pes(unsigned char *ptr, int pos)
  2266. + {
  2267. + //pos points at the 1st char after a pic start code
  2268. + int picture_coding_type;
  2269. + int hdr_len;
  2270. + unsigned int pts1, dts1;
  2271. + unsigned char *buf = ptr + pos;
  2272. + picture_coding_type = (buf[1] >> 3) & 0x07;
  2273. + hdr_len = (picture_coding_type > 1) ? 5 : 4;
  2274. + if(buf[hdr_len + 3] == 0xb5)
  2275. + hdr_len += 9;
  2276. + if(buf[hdr_len + 3] == 0xb2) {
  2277. + pts1 = ((buf[hdr_len+6] & 0x03) << 30) +
  2278. + ((buf[hdr_len+7] & 0x7f) << 23) +
  2279. + ((buf[hdr_len+8]) << 15) +
  2280. + ((buf[hdr_len+9] & 0x7f) << 8) +
  2281. + buf[hdr_len+10];
  2282. + dts1 = ((buf[hdr_len+13] & 0x03) << 30) +
  2283. + ((buf[hdr_len+14] & 0x7f) << 23) +
  2284. + ((buf[hdr_len+15]) << 15) +
  2285. + ((buf[hdr_len+16] & 0x7f) << 8) +
  2286. + buf[hdr_len+17];
  2287. + //NOTE: This is wrong. DSS timestamps only have a resolution of 2^32/300
  2288. + //r5000_print("pts: %08x/%f dts: %08x/%f\n", pts1, pts1 / 27000000.0, dts1, dts1 / 27000000.0);
  2289. + ptr[7] |= 0xc0;
  2290. + directv_make_pespts(ptr+9, pts1/300);
  2291. + ptr[9] |= 0x30;
  2292. + directv_make_pespts(ptr+14, dts1/300);
  2293. + ptr[14] |= 0x10;
  2294. + }
  2295. + }
  2296. +
  2297. + static void directv_fix_audio_pts(unsigned char *ptr)
  2298. + {
  2299. + unsigned int pts = ((ptr[0] & 0x06) << 29) +
  2300. + (ptr[1] << 22) +
  2301. + ((ptr[2] & 0xfe) << 14) +
  2302. + (ptr[3] << 7) +
  2303. + (ptr[4] >> 1);
  2304. + directv_make_pespts(ptr, pts/300);
  2305. + ptr[0] |= 0x20;
  2306. + }
  2307. +
  2308. +
  2309. + static void pes_write_ts(r5kdev_t *r5kdev, unsigned char *ptr, int len, int pid, int start, unsigned int *cc)
  2310. + {
  2311. + int stuff = 184 - len;
  2312. + //Note: we know that there are 188 bytes allocated before 'ptr'
  2313. + // that we can use for the header
  2314. + if(stuff > 0) {
  2315. + int stuff1 = stuff;
  2316. + while(stuff1 > 2) {
  2317. + *--ptr = 0xff;
  2318. + stuff1--;
  2319. + }
  2320. + if(stuff1 == 2) {
  2321. + *--ptr = 0x00;
  2322. + }
  2323. + *--ptr = stuff - 1;
  2324. + *--ptr = 0x30 | *cc;
  2325. + } else {
  2326. + *--ptr = 0x10 | *cc;
  2327. + }
  2328. + *--ptr = pid & 0xff;
  2329. + *--ptr = (start << 6) | (pid >> 8);
  2330. + *--ptr = 0x47;
  2331. + r5kdev->cb(ptr, 188, r5kdev->cb_data);
  2332. + *cc = (*cc+1) & 0x0f;
  2333. + }
  2334. +
  2335. + static void pes_process_block(r5kdev_t *r5kdev, unsigned char *buf, int len)
  2336. + {
  2337. + int i;
  2338. + struct r5000_dtv *dtv = (struct r5000_dtv *)r5kdev->stbdata;
  2339. + for(i = 0; i < len; i+=2) {
  2340. + unsigned char data = buf[i];
  2341. + unsigned char type = buf[i+1];
  2342. + if(0xff == type) {
  2343. + //video
  2344. + dtv->video[dtv->vpos++] = data;
  2345. + if(dtv->vpos > 4 && dtv->video[dtv->vpos-2] == 0x01 &&
  2346. + dtv->video[dtv->vpos-3] == 0x00 && dtv->video[dtv->vpos-4] == 0x00) {
  2347. + if (data == 0xe0) {
  2348. + //HD video header (PES)
  2349. + pes_write_ts(r5kdev, dtv->video, dtv->vpos - 4, DTV_VPID, dtv->vstart, &dtv->video_cc);
  2350. + dtv->pat_pmt_count++;
  2351. + dtv->video[0] = 0x00;
  2352. + dtv->video[1] = 0x00;
  2353. + dtv->video[2] = 0x01;
  2354. + dtv->video[3] = 0xe0;
  2355. + dtv->vpos = 4;
  2356. + dtv->vstart = 1;
  2357. + dtv->vstate = data;
  2358. + } else if (r5kdev->stb_type == R5K_STB_DIRECTV &&
  2359. + (data == 0xb3 || data == 0x00)) {
  2360. + if (dtv->vstate == 0xff) {
  2361. + dtv->vstate = data;
  2362. + pes_write_ts(r5kdev, dtv->video, dtv->vpos - 4, DTV_VPID, dtv->vstart, &dtv->video_cc);
  2363. + dtv->pat_pmt_count++;
  2364. + //Create a PES header, but no PTS/DTS info yet so just use stuffing bytes
  2365. + dtv->vpos = directv_make_empty_pes(dtv->video, 0xe0);
  2366. + dtv->video[dtv->vpos++] = 0x00;
  2367. + dtv->video[dtv->vpos++] = 0x00;
  2368. + dtv->video[dtv->vpos++] = 0x01;
  2369. + dtv->video[dtv->vpos++] = data;
  2370. + dtv->vstart = 1;
  2371. + dtv->pic_pos = dtv->vpos;
  2372. + }
  2373. + }
  2374. + }
  2375. + if(dtv->vpos == 188) {
  2376. + if (dtv->vstate == 0x00)
  2377. + //We found pic frame without a PES header (SD)
  2378. + directv_update_video_pes(dtv->video, dtv->pic_pos);
  2379. + pes_write_ts(r5kdev, dtv->video, 184, DTV_VPID, dtv->vstart, &dtv->video_cc);
  2380. + dtv->pat_pmt_count++;
  2381. + dtv->video[0] = dtv->video[184];
  2382. + dtv->video[1] = dtv->video[185];
  2383. + dtv->video[2] = dtv->video[186];
  2384. + dtv->video[3] = dtv->video[187];
  2385. + dtv->vpos = 4;
  2386. + dtv->vstart = 0;
  2387. + dtv->vstate = 0xff;
  2388. + }
  2389. + } else if(0xfe == type) {
  2390. + //audio
  2391. + dtv->audio[dtv->apos++] = data;
  2392. + dtv->alen--;
  2393. + if(dtv->alen <= 0 && dtv->apos > 6 && dtv->audio[dtv->apos-3] == 0xbd && dtv->audio[dtv->apos-4] == 0x01 &&
  2394. + dtv->audio[dtv->apos-5] == 0x00 && dtv->audio[dtv->apos-6] == 0x00) {
  2395. + dtv->alen = (dtv->audio[dtv->apos-2] << 8) + data;
  2396. + pes_write_ts(r5kdev, dtv->audio, dtv->apos - 6, DTV_APID, dtv->astart, &dtv->audio_cc);
  2397. + dtv->pat_pmt_count++;
  2398. + dtv->audio[0] = 0x00;
  2399. + dtv->audio[1] = 0x00;
  2400. + dtv->audio[2] = 0x01;
  2401. + dtv->audio[3] = 0xbd;
  2402. + dtv->audio[4] = dtv->audio[dtv->apos-2];
  2403. + dtv->audio[5] = data;
  2404. + dtv->apos = 6;
  2405. + dtv->astart = 1;
  2406. + r5kdev->pmt[1].id = 0x81; //AC3
  2407. + } else if(dtv->alen <= 0 && dtv->apos > 6 && dtv->audio[dtv->apos-3] == 0xc0 && dtv->audio[dtv->apos-4] == 0x01 &&
  2408. + dtv->audio[dtv->apos-5] == 0x00 && dtv->audio[dtv->apos-6] == 0x00) {
  2409. + dtv->alen = (dtv->audio[dtv->apos-2] << 8) + data;
  2410. + pes_write_ts(r5kdev, dtv->audio, dtv->apos - 6, DTV_APID, dtv->astart, &dtv->audio_cc);
  2411. + dtv->pat_pmt_count++;
  2412. + dtv->audio[0] = 0x00;
  2413. + dtv->audio[1] = 0x00;
  2414. + dtv->audio[2] = 0x01;
  2415. + dtv->audio[3] = 0xc0;
  2416. + if (r5kdev->stb_type == R5K_STB_DIRECTV) {
  2417. + dtv->audio[4] = (dtv->alen + 3) >> 8;
  2418. + dtv->audio[5] = (dtv->alen + 3) & 0xff;
  2419. + dtv->audio[6] = 0x80;
  2420. + dtv->audio[7] = 0x80;
  2421. + dtv->audio[8] = 0x05;
  2422. + dtv->apos = 9;
  2423. + } else {
  2424. + dtv->audio[4] = dtv->audio[dtv->apos-2];
  2425. + dtv->audio[5] = data;
  2426. + dtv->apos = 6;
  2427. + }
  2428. + dtv->astart = 1;
  2429. + r5kdev->pmt[1].id = 0x04; //MP2
  2430. + } else if(dtv->apos == 190) {
  2431. + if(dtv->astart && dtv->audio[3] == 0xc0 && r5kdev->stb_type == R5K_STB_DIRECTV)
  2432. + directv_fix_audio_pts(dtv->audio+9);
  2433. + pes_write_ts(r5kdev, dtv->audio, 184, DTV_APID, dtv->astart, &dtv->audio_cc);
  2434. + dtv->pat_pmt_count++;
  2435. + dtv->audio[0] = dtv->audio[184];
  2436. + dtv->audio[1] = dtv->audio[185];
  2437. + dtv->audio[2] = dtv->audio[186];
  2438. + dtv->audio[3] = dtv->audio[187];
  2439. + dtv->audio[4] = dtv->audio[188];
  2440. + dtv->audio[5] = dtv->audio[189];
  2441. + dtv->apos = 6;
  2442. + dtv->astart = 0;
  2443. + }
  2444. + }
  2445. + }
  2446. + if(r5kdev->pmt[1].id && dtv->pat_pmt_count > DTV_PAT_PMT_COUNT) {
  2447. + r5kdev->cb(r5000_pat_pkt, 188, r5kdev->cb_data);
  2448. + r5000_send_pmt(r5kdev);
  2449. + dtv->pat_pmt_count = 0;
  2450. + }
  2451. + }
  2452. +
  2453. + static void pes_start_stream(r5kdev_t *r5kdev)
  2454. + {
  2455. + struct r5000_dtv *dtv = (struct r5000_dtv *)r5kdev->stbdata;
  2456. + dtv->vstart = 0;
  2457. + dtv->astart = 0;
  2458. + dtv->vpos = 0;
  2459. + dtv->apos = 0;
  2460. + dtv->video_cc = 0;
  2461. + dtv->audio_cc = 0;
  2462. + dtv->vstate = 0xff;
  2463. + dtv->pat_pmt_count = DTV_PAT_PMT_COUNT;
  2464. + }
  2465. +
  2466. + void pes_init(r5kdev_t *r5kdev)
  2467. + {
  2468. + struct r5000_dtv *dtv = (struct r5000_dtv *)calloc(1, sizeof(struct r5000_dtv));
  2469. + dtv->video = dtv->vbuf + 188;
  2470. + dtv->audio = dtv->abuf + 188;
  2471. + dtv->pat_pmt_count = DTV_PAT_PMT_COUNT;
  2472. + dtv->vstate = 0xff;
  2473. + r5kdev->stbdata = dtv;
  2474. + r5kdev->pmt[0].id = 0x02; //MPEG2
  2475. + r5kdev->pmt[0].pid = DTV_VPID;
  2476. + r5kdev->pmt[0].desc = r5000_pmt_video_desc;
  2477. + r5kdev->pmt[1].id = 0x00;
  2478. + r5kdev->pmt[1].pid = DTV_APID;
  2479. + r5kdev->pmt[1].desc = r5000_pmt_audio_desc;
  2480. + r5kdev->num_pmt_entries = 2;
  2481. + r5kdev->process_block = pes_process_block;
  2482. + r5kdev->start_stream = pes_start_stream;
  2483. + if(r5kdev->stb_type == R5K_STB_DIRECTV) {
  2484. + r5kdev->button = &directv_button_cmd;
  2485. + r5kdev->power_active_low = 1;
  2486. + } else {
  2487. + r5kdev->button = &dish6000_button_cmd;
  2488. + r5kdev->power_active_low = 0;
  2489. + r5kdev->discrete_power = 1;
  2490. + }
  2491. + r5kdev->read_words = 1;
  2492. + }
  2493. +
  2494. + void pes_free(r5kdev_t *r5kdev)
  2495. + {
  2496. + free(r5kdev->stbdata);
  2497. + }
  2498. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_sat.c ./libs/libmythtv/r5000/r5k_sat.c
  2499. *** ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_sat.c 1969-12-31 16:00:00.000000000 -0800
  2500. --- ./libs/libmythtv/r5000/r5k_sat.c 2011-04-08 19:29:47.000000000 -0700
  2501. ***************
  2502. *** 0 ****
  2503. --- 1,475 ----
  2504. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  2505. + *
  2506. + * This library is free software; you can redistribute it and/or
  2507. + * modify it under the terms of the GNU Lesser General Public
  2508. + * License as published by the Free Software Foundation; either
  2509. + * version 2.1 of the License, or (at your option) any later version.
  2510. + *
  2511. + * This library is distributed in the hope that it will be useful,
  2512. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2513. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2514. + * Lesser General Public License for more details.
  2515. + *
  2516. + * You should have received a copy of the GNU Lesser General Public
  2517. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  2518. + */
  2519. +
  2520. + //Support for Dish Network ViP211/ViP422 boxes
  2521. + #include <stdio.h>
  2522. + #include <string.h>
  2523. + #include "r5000_internal.h"
  2524. +
  2525. + #define DTV_PAT_PMT_COUNT 5000
  2526. + #define MAX_PKT_SIZE 272
  2527. + #define MAX_PAT_SECTIONS 1
  2528. + #define MAX_SIDS 200
  2529. + #define MAX_EPIDS 5
  2530. +
  2531. + struct pat {
  2532. + int version;
  2533. + unsigned char last_section;
  2534. + unsigned char section_seen[MAX_PAT_SECTIONS];
  2535. + unsigned int crc[MAX_PAT_SECTIONS];
  2536. + unsigned int pmts[MAX_SIDS];
  2537. + int pmt_count;
  2538. + };
  2539. +
  2540. + struct sids {
  2541. + unsigned short sid;
  2542. + unsigned int crc;
  2543. + unsigned char seen_name;
  2544. + struct r5k_epid epid[MAX_EPIDS];
  2545. + unsigned char epid_count;
  2546. + };
  2547. +
  2548. + struct r5000_sat {
  2549. + unsigned char buf[MAX_PKT_SIZE];
  2550. + unsigned int pos;
  2551. + int offset;
  2552. + unsigned char sync;
  2553. + unsigned char bytesize;
  2554. + unsigned char sync_byte;
  2555. + unsigned int has_sync_byte;
  2556. + unsigned int pat_pmt_count;
  2557. + unsigned int packet_size;
  2558. + unsigned int allowed_packet_size[8];
  2559. +
  2560. + unsigned int current_sid;
  2561. + struct pat pats;
  2562. + struct sids *sids;
  2563. + };
  2564. +
  2565. + static int sat_read_pat_pkt(unsigned char *pes, struct pat *pat, unsigned int size) {
  2566. + unsigned int sec, end, crc, current_next;
  2567. + int version;
  2568. + unsigned char *ptr, last_sec;
  2569. +
  2570. + if (pes[0] != 0x00) {
  2571. + r5000_print("read_pat: expected PAT table 0x00 but got 0x%02x\n", pes[0]);
  2572. + return -1;
  2573. + }
  2574. + end = (((pes[1] & 0x03) << 8 | pes[2]) + 3 - 4);
  2575. + if(end > size-4) {
  2576. + r5000_print("read_pat: invalid PAT table size (%d > %d)\n", end, size-4);
  2577. + return -1;
  2578. + }
  2579. + crc = (pes[end]<<24) | (pes[end+1]<<16) | (pes[end+2]<<8) | pes[end+3];
  2580. + version = (pes[5] >> 1) & 0x1f;
  2581. + current_next = pes[5] & 0x01;
  2582. + sec = pes[6];
  2583. + last_sec = pes[7];
  2584. + if(! current_next)
  2585. + //ignore inactive PAT
  2586. + return 0;
  2587. + if(last_sec >= MAX_PAT_SECTIONS) {
  2588. + r5000_print("read_pat: illegal section count %d > %d\n",
  2589. + last_sec, MAX_PAT_SECTIONS);
  2590. + return -1;
  2591. + }
  2592. + if (pat->version != version || last_sec != pat->last_section ||
  2593. + pat->crc[sec] != crc) {
  2594. + pat->version = version;
  2595. + pat->last_section = last_sec;
  2596. + pat->pmt_count = 0;
  2597. + memset(pat->section_seen, 0, sizeof(pat->section_seen));
  2598. + }
  2599. + if(pat->section_seen[sec])
  2600. + return 0;
  2601. + pat->crc[sec] = crc;
  2602. + pat->section_seen[sec] = 1;
  2603. + for(ptr = pes + 8; ptr < pes + end; ptr += 4) {
  2604. + int sid, pid;
  2605. + sid = (ptr[0] << 8) | ptr[1];
  2606. + pid = ((ptr[2] & 0x1F) << 8) | ptr[3];
  2607. + r5000_print("found PID: %04x for sid: %d\n", pid, sid);
  2608. + if(sid != 0) {
  2609. + pat->pmts[pat->pmt_count++] = (sid << 16) | pid;
  2610. + }
  2611. + }
  2612. + return 1;
  2613. + }
  2614. +
  2615. + static struct sids *sat_read_pmt_pkt(unsigned char *buf, struct sids *sids,
  2616. + unsigned int size) {
  2617. + //
  2618. + // NOTE we aren't using last_sec here yet!
  2619. + //
  2620. +
  2621. + struct sids *sidptr = sids;
  2622. + unsigned int count, skip, pos, crc, current_next;
  2623. + int sid, sec, last_sec, pcrpid, epid, type;
  2624. + if (buf[0] != 0x02) {
  2625. + r5000_print("read_pmt expected table 0x02 but got 0x%02x\n", buf[0]);
  2626. + return NULL;
  2627. + }
  2628. + count = (((buf[1] & 0x03) << 8) | buf[2]) + 3 - 4;
  2629. + sid = (buf[3] << 8) | buf[4];
  2630. + current_next = buf[5] & 0x01;
  2631. + crc = (buf[count]<<24) | (buf[count+1]<<16) | (buf[count+2]<<8) | buf[count+3];
  2632. + sec = buf[6];
  2633. + last_sec = buf[7];
  2634. + pcrpid = ((buf[8] & 0x1F) << 8) | buf[9];
  2635. + skip = ((buf[10] & 0x03) << 8) | buf[11];
  2636. + if(skip > count - 12 || count > size) {
  2637. + r5000_print("skip: %d > count: %d - 12 || count > size: %d\n",
  2638. + skip, count, size);
  2639. + return NULL;
  2640. + }
  2641. + if(! current_next) {
  2642. + r5000_print("read_pmt ignoring future PMT\n");
  2643. + return NULL;
  2644. + }
  2645. + while(sidptr->sid != 0) {
  2646. + if(sidptr->sid == sid)
  2647. + break;
  2648. + sidptr++;
  2649. + }
  2650. + if(sidptr->sid == 0) {
  2651. + // We weren't expecting this sid
  2652. + r5000_print("read_pmt found unexpected sid: %d\n", sidptr->sid);
  2653. + return sidptr;
  2654. + }
  2655. + if(sidptr->crc == crc) {
  2656. + //sid is unchanged
  2657. + //r5000_print("read_pmt found identical crc (%08x) for %d\n", crc, sidptr->sid);
  2658. + return NULL;
  2659. + }
  2660. + memset(sidptr, 0, sizeof(struct sids));
  2661. +
  2662. + r5000_print("read_pmt: sid: %d pcrpid: %d skip: %d count: %d\n", sid, pcrpid, skip, count);
  2663. + sidptr->sid = sid;
  2664. + sidptr->crc = crc;
  2665. + sidptr->epid_count = 0;
  2666. + for(pos = 12 + skip; pos < count;) {
  2667. + struct r5k_epid *pidptr = &sidptr->epid[sidptr->epid_count];
  2668. + type = buf[pos];
  2669. + epid = ((buf[pos+1] & 0x1F) << 8) | buf[pos+2];
  2670. + skip = ((buf[pos+3] & 0x03) << 8) | buf[pos+4];
  2671. + pidptr->pid = epid;
  2672. + pidptr->id = type == 0x80 ? 0x02 : type;
  2673. + memcpy(pidptr->desc.d, buf + pos + 4, skip + 1);
  2674. + sidptr->epid_count++;
  2675. + r5000_print("read_pmt: epid %04x (type %02x, skip=%d) mapped to sid %d\n", epid, type, skip, sid);
  2676. + pos += 5 + skip;
  2677. + }
  2678. + return sidptr;
  2679. + }
  2680. +
  2681. + void sat_find_chname(unsigned char *buf, struct sids *sids, unsigned int size) {
  2682. + struct sids *sidptr = sids;
  2683. + unsigned int count;
  2684. + int sid;
  2685. + unsigned char str[20], *strptr = str;
  2686. + while(size) {
  2687. + count = (((buf[1] & 0x03) << 8) | buf[2]) + 3;
  2688. + if(buf[0] == 0x41) {
  2689. + buf += count;
  2690. + size -= count;
  2691. + continue;
  2692. + }
  2693. + if(buf[0] == 0xc1) {
  2694. + unsigned char *ptr = buf+16;
  2695. + sid = (buf[7]<<8) | buf[8];
  2696. + while(sidptr->sid != 0) {
  2697. + if(sidptr->sid == sid)
  2698. + break;
  2699. + sidptr++;
  2700. + }
  2701. + if(sidptr->sid == 0) {
  2702. + // We weren't expecting this sid
  2703. + return;
  2704. + }
  2705. + if(sidptr->seen_name)
  2706. + return;
  2707. + sidptr->seen_name = 1;
  2708. + while(*ptr >= 0x20 && *ptr < 0x7b && (strptr-str) < (int)(sizeof(str)-1)) {
  2709. + *strptr++ = *ptr++;
  2710. + }
  2711. + *strptr = 0;
  2712. + r5000_print("sid: %d is channel %s\n", sid, str);
  2713. + return;
  2714. + }
  2715. + return;
  2716. + }
  2717. + }
  2718. +
  2719. + int sat_add_pmt(r5kdev_t *r5kdev, struct r5k_epid *epid)
  2720. + {
  2721. + int i;
  2722. + int is_video = IS_VIDEO(epid->id);
  2723. +
  2724. + for(i = 0; i < r5kdev->num_pmt_entries; i++) {
  2725. + if(r5kdev->pmt[i].pid == epid->pid) {
  2726. + if(r5kdev->pmt[i].id == epid->id)
  2727. + return 0;
  2728. + //different table_id for existing pid. Reset
  2729. + r5000_reset_pmt(r5kdev);
  2730. + break;
  2731. + }
  2732. + if(is_video) {
  2733. + if(IS_VIDEO(r5kdev->pmt[i].id)) {
  2734. + //a video entry already exists. Reset
  2735. + r5000_reset_pmt(r5kdev);
  2736. + break;
  2737. + }
  2738. + }
  2739. + }
  2740. + //Didn't find this PID, add it
  2741. + if(i == R5K_MAX_PIDS)
  2742. + return 0;
  2743. + r5000_print("Adding %04x: %02x (desc_len=%d) @ %08x\n", epid->pid, epid->id, epid->desc.d[0], r5kdev->bytes_read);
  2744. + r5kdev->pmt[r5kdev->num_pmt_entries++] = *epid;
  2745. + r5kdev->pmt_state |= is_video ? 0x01 : 0x02;
  2746. + return 1;
  2747. + }
  2748. +
  2749. + void sat_process_ts(r5kdev_t *r5kdev, unsigned char *buf)
  2750. + {
  2751. + struct r5000_sat *sat = (struct r5000_sat *)r5kdev->stbdata;
  2752. + int pid;
  2753. + int i, j, k;
  2754. + pid = ((buf[1] << 8) | buf[2]) & 0x1fff;
  2755. + if(pid == 0x1fff)
  2756. + return;
  2757. + if(pid == 0 && (buf[1] & 0x40)) {
  2758. + //Always read PAT in case we changed transponders
  2759. + if(sat_read_pat_pkt(buf+buf[4]+5, &sat->pats, 188-buf[4]-5) > 0) {
  2760. + r5000_print("Found new PAT\n");
  2761. + if(sat->pats.pmt_count) {
  2762. + sat->sids = (struct sids *)realloc(sat->sids, sizeof(struct sids)*(sat->pats.pmt_count+1));
  2763. + memset(sat->sids, 0, sizeof(struct sids)*(sat->pats.pmt_count+1));
  2764. + //Pre load sids so we don't overrun if the PMT changes before the PAT
  2765. + for(i = 0; i < sat->pats.pmt_count; i++) {
  2766. + sat->sids[i].sid = sat->pats.pmts[i]>>16;
  2767. + }
  2768. + sat->sids[i].sid = 0;
  2769. + r5000_reset_pmt(r5kdev);
  2770. + }
  2771. + } else if(r5kdev->pmt_state == 0x03) {
  2772. + r5kdev->cb(r5000_pat_pkt, 188, r5kdev->cb_data);
  2773. + r5000_send_pmt(r5kdev);
  2774. + sat->pat_pmt_count = 0;
  2775. + }
  2776. + return;
  2777. + }
  2778. + //Always reread PMT in case the pids have changed
  2779. + for(i = 0; i < sat->pats.pmt_count; i++) {
  2780. + if(pid == (unsigned short)(sat->pats.pmts[i])) {
  2781. + #if 0
  2782. + {
  2783. + char s[80];
  2784. + FILE *fh;
  2785. + sprintf(s, "0x%04x.ts", pid);
  2786. + fh= fopen(s, "a");
  2787. + fwrite(buf, 188, 1, fh);
  2788. + fclose(fh);
  2789. + }
  2790. + #endif
  2791. + //r5000_print("PID: %04x - %04x (%d) %02x %02x %02x %02x %02x\n", pid, (unsigned short)(sat->pats.pmts[i]), i, buf[1], buf[2], buf[3], buf[4], buf[5]);
  2792. + if(buf[1] & 0x40 && buf[4]+5 < 188) {
  2793. + if(buf[buf[4]+5] == 0x02) {
  2794. + struct sids *sidptr;
  2795. + if((sidptr = sat_read_pmt_pkt(buf+buf[4]+5, sat->sids, 188-buf[4]-5))) {
  2796. + if(sidptr->sid == 0) {
  2797. + //Unexpected sid, reset PAT;
  2798. + memset(&sat->pats, 0, sizeof(struct pat));
  2799. + } else if(sat->current_sid == sidptr->sid) {
  2800. + r5000_reset_pmt(r5kdev);
  2801. + sat->current_sid = 0;
  2802. + }
  2803. + }
  2804. + //} else if(buf[buf[4]+5] == 0xc1 || buf[buf[4]+5] == 0x41) {
  2805. + // sat_find_chname(buf+buf[4]+5, sat->sids, 188-buf[4]-5);
  2806. + }
  2807. + }
  2808. + return;
  2809. + }
  2810. + if(! sat->current_sid) {
  2811. + for(j = 0; j < sat->sids[i].epid_count; j++) {
  2812. + if(pid == sat->sids[i].epid[j].pid &&
  2813. + IS_VIDEO(sat->sids[i].epid[j].id) &&
  2814. + (!r5kdev->channel || r5kdev->channel == sat->sids[i].sid)) {
  2815. + //Found unencrypted video. Choose this one
  2816. + // Assume this is MPEG2. Don't know what MPEG4 looks like yet
  2817. + sat->current_sid = sat->sids[i].sid;
  2818. + r5000_print("Found decrypted sid %d\n", sat->current_sid);
  2819. + if (sat_add_pmt(r5kdev, &sat->sids[i].epid[j])) {
  2820. + //This is a new Video PID
  2821. + for(k = 0; k < sat->sids[i].epid_count; k++) {
  2822. + if(sat->sids[i].epid[k].id == 0x81 ||
  2823. + sat->sids[i].epid[k].id == 0xbd) {
  2824. + sat_add_pmt(r5kdev, &sat->sids[i].epid[k]);
  2825. + }
  2826. + }
  2827. + r5kdev->cb(r5000_pat_pkt, 188, r5kdev->cb_data);
  2828. + r5000_send_pmt(r5kdev);
  2829. + sat->pat_pmt_count = 0;
  2830. + }
  2831. + r5kdev->cb(sat->buf, 188, r5kdev->cb_data);
  2832. + return;
  2833. + }
  2834. + }
  2835. + }
  2836. + }
  2837. + for(i = 0; i < r5kdev->num_pmt_entries; i++) {
  2838. + if(pid == r5kdev->pmt[i].pid) {
  2839. + r5kdev->cb(sat->buf, 188, r5kdev->cb_data);
  2840. + sat->pat_pmt_count++;
  2841. + return;
  2842. + }
  2843. + }
  2844. + #if 0
  2845. + //r5000_print("Ignoring PID: %04x\n", pid);
  2846. + {
  2847. + char s[80];
  2848. + FILE *fh;
  2849. + sprintf(s, "0x%04x.ts", pid);
  2850. + fh= fopen(s, "a");
  2851. + fwrite(buf, 188, 1, fh);
  2852. + fclose(fh);
  2853. + }
  2854. + #endif
  2855. + }
  2856. +
  2857. + static void sat_process_block(r5kdev_t *r5kdev, unsigned char *buf, int len)
  2858. + {
  2859. + struct r5000_sat *sat = (struct r5000_sat *)r5kdev->stbdata;
  2860. +
  2861. + int pos;
  2862. + if(! r5kdev->streaming)
  2863. + return;
  2864. + if(len <= 0)
  2865. + return;
  2866. +
  2867. + for(pos = sat->offset; pos < len; pos += sat->bytesize) {
  2868. + if(! sat->sync) {
  2869. + if(buf[pos] == 0x47) {
  2870. + int i;
  2871. + if ((int)(pos + (sat->allowed_packet_size[0]<<1)) < len) {
  2872. + if((buf[pos+1] & 0xfc) == 0xfc && (buf[pos+3] & 0xfc) == 0xfc &&
  2873. + (buf[pos+5] & 0xfc) == 0xfc && (buf[pos+7] & 0xfc) == 0xfc) {
  2874. + sat->bytesize = 2;
  2875. + }
  2876. + for(i=0; sat->allowed_packet_size[i] != 0; i++) {
  2877. + if(buf[pos+(sat->allowed_packet_size[i] * sat->bytesize)] == 0x47) {
  2878. + r5000_print("(%d) Found %d byte sync at %08x: bytesize = %d\n",
  2879. + r5kdev->nexturb, sat->allowed_packet_size[i],
  2880. + r5kdev->bytes_read+pos, sat->bytesize);
  2881. + sat->packet_size = sat->allowed_packet_size[i];
  2882. + sat->sync = 1;
  2883. + sat->buf[0] = 0x47;
  2884. + sat->pos = 1;
  2885. + break;
  2886. + }
  2887. + }
  2888. + }
  2889. + }
  2890. + continue;
  2891. + }
  2892. + if (sat->pos == 0 && buf[pos] != 0x47) {
  2893. + sat->sync = 0;
  2894. + sat->bytesize = 1;
  2895. + r5000_print("(%d)Lost sync at %08x\n", r5kdev->nexturb,
  2896. + r5kdev->bytes_read+pos);
  2897. + continue;
  2898. + }
  2899. + if(sat->pos == 3 && (buf[pos] & 0xc0) != 0x00) {
  2900. + // Encrypted channel, skip this packet
  2901. + sat->pos = 0;
  2902. + pos += sat->bytesize * (sat->packet_size - 4); //Loop adds additional 2
  2903. + continue;
  2904. + }
  2905. + sat->buf[sat->pos++] = buf[pos];
  2906. + if (sat->pos == sat->packet_size) {
  2907. + sat_process_ts(r5kdev, sat->buf);
  2908. + //if packet size > 188, assume remaining bytes are parity and ignore
  2909. + sat->pos = 0;
  2910. + }
  2911. + }
  2912. + sat->offset = pos - len;
  2913. + if(r5kdev->pmt_state == 0x03 && sat->pat_pmt_count > DTV_PAT_PMT_COUNT) {
  2914. + r5kdev->cb(r5000_pat_pkt, 188, r5kdev->cb_data);
  2915. + r5000_send_pmt(r5kdev);
  2916. + sat->pat_pmt_count = 0;
  2917. + }
  2918. + }
  2919. +
  2920. + static void sat_start_stream(r5kdev_t *r5kdev)
  2921. + {
  2922. + struct r5000_sat *sat = (struct r5000_sat *)r5kdev->stbdata;
  2923. + sat->offset = 0;
  2924. + sat->sync = 0;
  2925. + sat->pos = 0;
  2926. + sat->bytesize = 1;
  2927. +
  2928. + //Clear any defined PAT or PMT data
  2929. + if(sat->sids) {
  2930. + free(sat->sids);
  2931. + sat->sids = 0;
  2932. + }
  2933. + memset(&sat->pats, 0, sizeof(struct pat));
  2934. + sat->pat_pmt_count = DTV_PAT_PMT_COUNT;
  2935. + }
  2936. +
  2937. + static void sat_change_channel(r5kdev_t *r5kdev)
  2938. + {
  2939. + r5000_reset_pmt(r5kdev);
  2940. + }
  2941. +
  2942. + void sat_init(r5kdev_t *r5kdev)
  2943. + {
  2944. + struct r5000_sat *sat =
  2945. + (struct r5000_sat *)calloc(1, sizeof(struct r5000_sat));
  2946. + r5kdev->stbdata = sat;
  2947. + sat->pat_pmt_count = DTV_PAT_PMT_COUNT;
  2948. + if(r5kdev->stb_type == R5K_STB_HDD) {
  2949. + sat->sync_byte = 0xff;
  2950. + sat->has_sync_byte = 1;
  2951. + sat->allowed_packet_size[0] = 272;
  2952. + sat->allowed_packet_size[1] = 233;
  2953. + sat->allowed_packet_size[2] = 204;
  2954. + sat->allowed_packet_size[3] = 188;
  2955. + sat->allowed_packet_size[4] = 0;
  2956. + } else {
  2957. + sat->allowed_packet_size[0] = 188;
  2958. + sat->allowed_packet_size[1] = 0;
  2959. + }
  2960. + r5kdev->process_block = sat_process_block;
  2961. + r5kdev->start_stream = sat_start_stream;
  2962. + r5kdev->change_channel = &sat_change_channel;
  2963. + if(r5kdev->stb_type == R5K_STB_DSR) {
  2964. + r5kdev->power_active_low = 1;
  2965. + }
  2966. + #ifdef R5K_DSR_BUTTONS
  2967. + r5kdev->button = &dsr_button_cmd;
  2968. + #endif
  2969. + }
  2970. +
  2971. + void sat_free(r5kdev_t *r5kdev)
  2972. + {
  2973. + struct r5000_sat *sat = (struct r5000_sat *)r5kdev->stbdata;
  2974. + if(sat->sids)
  2975. + free(sat->sids);
  2976. + free(r5kdev->stbdata);
  2977. + }
  2978. +
  2979. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_vip_buttons.c ./libs/libmythtv/r5000/r5k_vip_buttons.c
  2980. *** ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_vip_buttons.c 1969-12-31 16:00:00.000000000 -0800
  2981. --- ./libs/libmythtv/r5000/r5k_vip_buttons.c 2011-04-08 19:29:47.000000000 -0700
  2982. ***************
  2983. *** 0 ****
  2984. --- 1,215 ----
  2985. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  2986. + *
  2987. + * This library is free software; you can redistribute it and/or
  2988. + * modify it under the terms of the GNU Lesser General Public
  2989. + * License as published by the Free Software Foundation; either
  2990. + * version 2.1 of the License, or (at your option) any later version.
  2991. + *
  2992. + * This library is distributed in the hope that it will be useful,
  2993. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2994. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2995. + * Lesser General Public License for more details.
  2996. + *
  2997. + * You should have received a copy of the GNU Lesser General Public
  2998. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  2999. + */
  3000. +
  3001. +
  3002. + #include "r5000_internal.h"
  3003. + struct r5000_buttons vip_button_cmd =
  3004. + {
  3005. + 0x00, //len
  3006. + 400000, //delay
  3007. + //button 0
  3008. + {
  3009. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  3010. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3011. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  3012. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3013. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e,
  3014. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3015. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3016. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3017. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3018. + },
  3019. + //button 1
  3020. + {
  3021. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  3022. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3023. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3024. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3025. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  3026. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3027. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3028. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3029. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3030. + },
  3031. + //button 2
  3032. + {
  3033. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  3034. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3035. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3036. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3037. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  3038. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3039. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3040. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3041. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3042. + },
  3043. + //button 3
  3044. + {
  3045. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  3046. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3047. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3048. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3049. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  3050. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3051. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3052. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3053. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3054. + },
  3055. + //button 4
  3056. + {
  3057. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  3058. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3059. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  3060. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3061. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  3062. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3063. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3064. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3065. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3066. + },
  3067. + //button 5
  3068. + {
  3069. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  3070. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3071. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  3072. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3073. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  3074. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3075. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3076. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3077. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3078. + },
  3079. + //button 6
  3080. + {
  3081. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  3082. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3083. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  3084. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3085. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  3086. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3087. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3088. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3089. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3090. + },
  3091. + //button 7
  3092. + {
  3093. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  3094. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3095. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  3096. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3097. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  3098. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3099. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3100. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3101. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3102. + },
  3103. + //button 8
  3104. + {
  3105. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  3106. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3107. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  3108. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3109. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  3110. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3111. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3112. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3113. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3114. + },
  3115. + //button 9
  3116. + {
  3117. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  3118. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3119. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  3120. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3121. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  3122. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3123. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3124. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3125. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3126. + },
  3127. + //button Clear
  3128. + {
  3129. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  3130. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3131. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  3132. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3133. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e,
  3134. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3135. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3136. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3137. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3138. + },
  3139. + //button Enter
  3140. + {
  3141. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  3142. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3143. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  3144. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3145. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e,
  3146. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3147. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3148. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3149. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3150. + },
  3151. + //button Power
  3152. + {
  3153. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3154. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3155. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3156. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3157. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  3158. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3159. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3160. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3161. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3162. + },
  3163. + //button Power-On
  3164. + {
  3165. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3166. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3167. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3168. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3169. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  3170. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3171. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3172. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3173. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3174. + },
  3175. + //button Power-Off
  3176. + {
  3177. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  3178. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3179. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  3180. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3181. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x0e, 0x04, 0x1a,
  3182. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3183. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x0e,
  3184. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3185. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3186. + },
  3187. + //button Guide
  3188. + {
  3189. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e,
  3190. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3191. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  3192. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3193. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e,
  3194. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3195. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  3196. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  3197. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  3198. + },
  3199. + };
  3200. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_vip.c ./libs/libmythtv/r5000/r5k_vip.c
  3201. *** ../../mythtv/mythtv/libs/libmythtv/r5000/r5k_vip.c 1969-12-31 16:00:00.000000000 -0800
  3202. --- ./libs/libmythtv/r5000/r5k_vip.c 2011-04-08 19:29:47.000000000 -0700
  3203. ***************
  3204. *** 0 ****
  3205. --- 1,246 ----
  3206. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  3207. + *
  3208. + * This library is free software; you can redistribute it and/or
  3209. + * modify it under the terms of the GNU Lesser General Public
  3210. + * License as published by the Free Software Foundation; either
  3211. + * version 2.1 of the License, or (at your option) any later version.
  3212. + *
  3213. + * This library is distributed in the hope that it will be useful,
  3214. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3215. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3216. + * Lesser General Public License for more details.
  3217. + *
  3218. + * You should have received a copy of the GNU Lesser General Public
  3219. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  3220. + */
  3221. +
  3222. + //Support for Dish Network ViP211/ViP422 boxes
  3223. + #include <stdio.h>
  3224. + #include <string.h>
  3225. + #include <sys/time.h>
  3226. + #include "r5000_internal.h"
  3227. +
  3228. + struct r5000_vip {
  3229. + unsigned char leftover[188];
  3230. + int offset;
  3231. + int pos;
  3232. + };
  3233. + #define CHECK_CONTINUITY 1
  3234. + #ifdef CHECK_CONTINUITY
  3235. + static unsigned char continuity[0x2000];
  3236. + #endif
  3237. +
  3238. + #define PMT_READY(_r5kdev) (((_r5kdev)->pmt_state == 0x03) || ((_r5kdev)->channel < 0 && (_r5kdev)->pmt_state == 0x02))
  3239. +
  3240. + #define IS_PRIVATE_SECTION(x) (x == 0x05)
  3241. +
  3242. + enum {
  3243. + R5K_STREAMTYPE_VIDEO,
  3244. + R5K_STREAMTYPE_AUDIO,
  3245. + R5K_STREAMTYPE_PRIVATE,
  3246. + };
  3247. +
  3248. + static struct timeval last_tv;
  3249. + void vip_add_pmt(r5kdev_t *r5kdev, int pid, int table_id)
  3250. + {
  3251. + int i;
  3252. + struct r5000_vip *vip = (struct r5000_vip *)r5kdev->stbdata;
  3253. +
  3254. + int streamtype = IS_VIDEO(table_id) ? R5K_STREAMTYPE_VIDEO : (IS_PRIVATE_SECTION(table_id) ? R5K_STREAMTYPE_PRIVATE : R5K_STREAMTYPE_AUDIO);
  3255. +
  3256. + for(i = 0; i < r5kdev->num_pmt_entries; i++) {
  3257. + if(r5kdev->pmt[i].pid == pid) {
  3258. + if(r5kdev->pmt[i].id == table_id) {
  3259. + if (streamtype == R5K_STREAMTYPE_VIDEO && r5kdev->pmt_state == 0x03) {
  3260. + //If we haven't seen a PAT or PMT in 500ms, send one
  3261. + struct timeval tv, tv_test;
  3262. + gettimeofday(&tv, NULL);
  3263. + timersub(&tv, &last_tv, &tv_test);
  3264. + if(tv.tv_sec > 0 || tv.tv_usec > 500 * 1000) {
  3265. + r5kdev->cb(r5000_pat_pkt, 188, r5kdev->cb_data);
  3266. + r5000_send_pmt(r5kdev);
  3267. + last_tv = tv;
  3268. + }
  3269. + }
  3270. + return;
  3271. + }
  3272. + //different table_id for existing pid. Reset
  3273. + r5000_reset_pmt(r5kdev);
  3274. + break;
  3275. + }
  3276. + if(streamtype == R5K_STREAMTYPE_VIDEO) {
  3277. + if(IS_VIDEO(r5kdev->pmt[i].id)) {
  3278. + //a video entry already exists. Reset
  3279. + r5000_reset_pmt(r5kdev);
  3280. + break;
  3281. + }
  3282. + }
  3283. + }
  3284. + //Didn't find this PID, add it
  3285. + if(i == R5K_MAX_PIDS)
  3286. + return;
  3287. + gettimeofday(&last_tv, NULL);
  3288. + r5000_print("Adding %04x: %02x @ %08x\n", pid, table_id, r5kdev->bytes_read + vip->pos);
  3289. + r5kdev->pmt[r5kdev->num_pmt_entries].pid = pid;
  3290. + r5kdev->pmt[r5kdev->num_pmt_entries].id = table_id;
  3291. + switch(streamtype) {
  3292. + case R5K_STREAMTYPE_VIDEO:
  3293. + r5kdev->pmt[r5kdev->num_pmt_entries].desc = r5000_pmt_video_desc;
  3294. + r5kdev->pmt_state |= 0x01;
  3295. + break;
  3296. + case R5K_STREAMTYPE_AUDIO:
  3297. + r5kdev->pmt[r5kdev->num_pmt_entries].desc = r5000_pmt_audio_desc;
  3298. + r5kdev->pmt_state |= 0x02;
  3299. + break;
  3300. + case R5K_STREAMTYPE_PRIVATE:
  3301. + r5kdev->pmt[r5kdev->num_pmt_entries].desc = r5000_pmt_nowplaying_desc;
  3302. + break;
  3303. + }
  3304. + r5kdev->num_pmt_entries++;
  3305. + //Force rebuild of PMT
  3306. + r5kdev->pmt_pkt[0] = 0;
  3307. + }
  3308. +
  3309. + void vip_force_pmt(r5kdev_t *r5kdev, unsigned char *buf)
  3310. + {
  3311. + int stream_id, pid, afc, af_size = 0;
  3312. +
  3313. + pid = ((buf[1] << 8) | buf[2]) & 0x1fff;
  3314. + if(pid == 0x1fff)
  3315. + return;
  3316. + #ifdef CHECK_CONTINUITY
  3317. + if(pid >= 0x1000) {
  3318. + struct r5000_vip *vip = (struct r5000_vip *)r5kdev->stbdata;
  3319. + unsigned char cont = buf[3] & 0x0f;
  3320. + if(continuity[pid] != cont && (buf[3] & 0x30) != 0x20) {
  3321. + r5000_print("Continuity (0x%04x) %d != %d @%08x\n",
  3322. + pid, cont, continuity[pid], r5kdev->bytes_read + vip->pos);
  3323. + }
  3324. + continuity[pid] = (cont + 1) & 0x0f;
  3325. + }
  3326. + #endif
  3327. + if(pid == 0) {
  3328. + gettimeofday(&last_tv, NULL);
  3329. + r5kdev->cb(r5000_pat_pkt, 188, r5kdev->cb_data);
  3330. + if(PMT_READY(r5kdev))
  3331. + r5000_send_pmt(r5kdev);
  3332. + } else {
  3333. + if(pid != 0x21)
  3334. + r5kdev->cb(buf, 188, r5kdev->cb_data);
  3335. + //Only interested in PES packets starting in this TS packet
  3336. + if (!(buf[1] & 0x40))
  3337. + return;
  3338. + afc = (buf[3]>>4) & 0x03;
  3339. + if(afc == 0x2)
  3340. + return;
  3341. + if(afc == 0x3)
  3342. + af_size = buf[4]+1;
  3343. + if(buf[4+af_size] != 0x00 || buf[5+af_size] != 0x00 || buf[6+af_size] != 0x01)
  3344. + return;
  3345. + //We have a PES packet
  3346. + stream_id = buf[7+af_size];
  3347. + if((stream_id & 0xf0) == 0xe0) {
  3348. + //Video stream (we need the adaptation field)
  3349. + if(0) {
  3350. + PRINTHEX("data", buf, af_size+8);
  3351. + }
  3352. + if(afc == 0x03) {
  3353. + if(buf[5] & 0x02) {
  3354. + // Has private data, this is MPEG4
  3355. + vip_add_pmt(r5kdev, pid, 0x1b);
  3356. + } else { //if(buf[5] & 0x10) {
  3357. + // Has PCR and no private data, this is MPEG2
  3358. + vip_add_pmt(r5kdev, pid, 0x02);
  3359. + }
  3360. + } else {
  3361. + // No PCR, maybe this is ATSC?
  3362. + vip_add_pmt(r5kdev, pid, 0x02);
  3363. + }
  3364. + } else if((stream_id & 0xf0) == 0xc0) {
  3365. + //Audio stream
  3366. + vip_add_pmt(r5kdev, pid, 0x04);
  3367. + } else if(stream_id == 0xbd) {
  3368. + //Audio stream
  3369. + vip_add_pmt(r5kdev, pid, 0x81);
  3370. + }
  3371. + }
  3372. + }
  3373. +
  3374. + static void vip_process_block(r5kdev_t *r5kdev, unsigned char *buf, int len)
  3375. + {
  3376. + struct r5000_vip *vip = (struct r5000_vip *)r5kdev->stbdata;
  3377. +
  3378. + int sync = 1;
  3379. + if(! r5kdev->streaming)
  3380. + return;
  3381. + if(len <= 0)
  3382. + return;
  3383. +
  3384. + vip->pos = vip->offset;
  3385. + while(vip->pos < len) {
  3386. + if(buf[vip->pos] != 0x47 || (vip->pos <len-1 && buf[vip->pos+1] == 0xff))
  3387. + goto nosync;
  3388. + // If we get here, buf[vip->pos] == 0x47
  3389. + if(vip->offset) {
  3390. + //previous data exists and is part of a good packet
  3391. + memcpy(vip->leftover+188-vip->offset, buf, vip->offset);
  3392. + vip_force_pmt(r5kdev, vip->leftover);
  3393. + vip->offset = 0;
  3394. + }
  3395. + if(vip->pos+188 <= len) {
  3396. + //at least one full packet is available
  3397. + if(vip->pos+188 < len && buf[vip->pos+188] != 0x47)
  3398. + goto nosync;
  3399. + } else {
  3400. + //Out of data, but the partial packet may be ok.
  3401. + memcpy(vip->leftover, buf+vip->pos, len-vip->pos);
  3402. + vip->offset = 188-(len-vip->pos);
  3403. + break;
  3404. + }
  3405. + //If we get here, we have a good packet
  3406. + vip_force_pmt(r5kdev, buf+vip->pos);
  3407. + if(! sync)
  3408. + r5000_print("(%d) Found sync @ %08x\n", r5kdev->nexturb, r5kdev->bytes_read+vip->pos);
  3409. + sync = 1;
  3410. + vip->pos+=188;
  3411. + continue;
  3412. + nosync:
  3413. + vip->offset=0;
  3414. + if(sync)
  3415. + r5000_print("(%d)Lost sync @ %08x\n", r5kdev->nexturb, r5kdev->bytes_read+vip->pos);
  3416. + sync = 0;
  3417. + vip->pos++;
  3418. + }
  3419. + }
  3420. +
  3421. + static void vip_start_stream(r5kdev_t *r5kdev)
  3422. + {
  3423. + struct r5000_vip *vip = (struct r5000_vip *)r5kdev->stbdata;
  3424. + vip->offset = 0;
  3425. + }
  3426. +
  3427. + static void vip_change_channel(r5kdev_t *r5kdev)
  3428. + {
  3429. + r5000_reset_pmt(r5kdev);
  3430. + }
  3431. +
  3432. + void vip_init(r5kdev_t *r5kdev)
  3433. + {
  3434. + struct r5000_vip *vip = (struct r5000_vip *)malloc(sizeof(struct r5000_vip));
  3435. + r5kdev->stbdata = vip;
  3436. + r5kdev->process_block = vip_process_block;
  3437. + r5kdev->start_stream = vip_start_stream;
  3438. + r5kdev->button = &vip_button_cmd;
  3439. + r5kdev->change_channel = &vip_change_channel;
  3440. + r5kdev->discrete_power = 1;
  3441. + if(r5kdev->stb_type == R5K_STB_VIP211)
  3442. + r5kdev->unreliable_power_detect = 1;
  3443. + if(r5kdev->stb_type == R5K_STB_VIP622)
  3444. + r5kdev->power_active_low = 1;
  3445. + }
  3446. +
  3447. + void vip_free(r5kdev_t *r5kdev)
  3448. + {
  3449. + free(r5kdev->stbdata);
  3450. + }
  3451. +
  3452. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/all-wcprops ./libs/libmythtv/r5000/.svn/all-wcprops
  3453. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/all-wcprops 1969-12-31 16:00:00.000000000 -0800
  3454. --- ./libs/libmythtv/r5000/.svn/all-wcprops 2011-04-08 19:29:47.000000000 -0700
  3455. ***************
  3456. *** 0 ****
  3457. --- 1,89 ----
  3458. + K 25
  3459. + svn:wc:ra_dav:version-url
  3460. + V 32
  3461. + /svn/!svn/ver/17/trunk/src/r5000
  3462. + END
  3463. + r5000init.h
  3464. + K 25
  3465. + svn:wc:ra_dav:version-url
  3466. + V 43
  3467. + /svn/!svn/ver/4/trunk/src/r5000/r5000init.h
  3468. + END
  3469. + r5k_vip.c
  3470. + K 25
  3471. + svn:wc:ra_dav:version-url
  3472. + V 42
  3473. + /svn/!svn/ver/17/trunk/src/r5000/r5k_vip.c
  3474. + END
  3475. + r5k_directv_buttons.c
  3476. + K 25
  3477. + svn:wc:ra_dav:version-url
  3478. + V 53
  3479. + /svn/!svn/ver/3/trunk/src/r5000/r5k_directv_buttons.c
  3480. + END
  3481. + libusb_augment.c
  3482. + K 25
  3483. + svn:wc:ra_dav:version-url
  3484. + V 48
  3485. + /svn/!svn/ver/4/trunk/src/r5000/libusb_augment.c
  3486. + END
  3487. + libusb_augment.h
  3488. + K 25
  3489. + svn:wc:ra_dav:version-url
  3490. + V 48
  3491. + /svn/!svn/ver/4/trunk/src/r5000/libusb_augment.h
  3492. + END
  3493. + r5000.c
  3494. + K 25
  3495. + svn:wc:ra_dav:version-url
  3496. + V 40
  3497. + /svn/!svn/ver/13/trunk/src/r5000/r5000.c
  3498. + END
  3499. + r5k_dsr_buttons.c
  3500. + K 25
  3501. + svn:wc:ra_dav:version-url
  3502. + V 50
  3503. + /svn/!svn/ver/17/trunk/src/r5000/r5k_dsr_buttons.c
  3504. + END
  3505. + r5000_internal.h
  3506. + K 25
  3507. + svn:wc:ra_dav:version-url
  3508. + V 49
  3509. + /svn/!svn/ver/17/trunk/src/r5000/r5000_internal.h
  3510. + END
  3511. + r5k_pes.c
  3512. + K 25
  3513. + svn:wc:ra_dav:version-url
  3514. + V 41
  3515. + /svn/!svn/ver/4/trunk/src/r5000/r5k_pes.c
  3516. + END
  3517. + r5k_sat.c
  3518. + K 25
  3519. + svn:wc:ra_dav:version-url
  3520. + V 42
  3521. + /svn/!svn/ver/17/trunk/src/r5000/r5k_sat.c
  3522. + END
  3523. + r5000.h
  3524. + K 25
  3525. + svn:wc:ra_dav:version-url
  3526. + V 40
  3527. + /svn/!svn/ver/11/trunk/src/r5000/r5000.h
  3528. + END
  3529. + r5k_misc.c
  3530. + K 25
  3531. + svn:wc:ra_dav:version-url
  3532. + V 43
  3533. + /svn/!svn/ver/17/trunk/src/r5000/r5k_misc.c
  3534. + END
  3535. + r5k_dish6000_buttons.c
  3536. + K 25
  3537. + svn:wc:ra_dav:version-url
  3538. + V 54
  3539. + /svn/!svn/ver/3/trunk/src/r5000/r5k_dish6000_buttons.c
  3540. + END
  3541. + r5k_vip_buttons.c
  3542. + K 25
  3543. + svn:wc:ra_dav:version-url
  3544. + V 50
  3545. + /svn/!svn/ver/12/trunk/src/r5000/r5k_vip_buttons.c
  3546. + END
  3547. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/entries ./libs/libmythtv/r5000/.svn/entries
  3548. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/entries 1969-12-31 16:00:00.000000000 -0800
  3549. --- ./libs/libmythtv/r5000/.svn/entries 2011-04-08 19:29:47.000000000 -0700
  3550. ***************
  3551. *** 0 ****
  3552. --- 1,504 ----
  3553. + 10
  3554. +
  3555. + dir
  3556. + 18
  3557. + http://r5000-for-linux.googlecode.com/svn/trunk/src/r5000
  3558. + http://r5000-for-linux.googlecode.com/svn
  3559. +
  3560. +
  3561. +
  3562. + 2010-11-04T00:57:00.778364Z
  3563. + 17
  3564. + alannisota
  3565. +
  3566. +
  3567. +
  3568. +
  3569. +
  3570. +
  3571. +
  3572. +
  3573. +
  3574. +
  3575. +
  3576. +
  3577. +
  3578. +
  3579. + 9285ed98-ce7b-11de-ad5a-8fd976f75259
  3580. +
  3581. + r5000init.h
  3582. + file
  3583. +
  3584. +
  3585. +
  3586. +
  3587. + 2011-04-09T02:29:47.556136Z
  3588. + 14541c3661aed075d0cee406a8b01b16
  3589. + 2009-11-20T22:54:57.232504Z
  3590. + 4
  3591. + alannisota
  3592. +
  3593. +
  3594. +
  3595. +
  3596. +
  3597. +
  3598. +
  3599. +
  3600. +
  3601. +
  3602. +
  3603. +
  3604. +
  3605. +
  3606. +
  3607. +
  3608. +
  3609. +
  3610. +
  3611. +
  3612. +
  3613. + 3840
  3614. +
  3615. + r5k_vip.c
  3616. + file
  3617. +
  3618. +
  3619. +
  3620. +
  3621. + 2011-04-09T02:29:47.557136Z
  3622. + 6294c96c03e2b274f58ec20cfeabb557
  3623. + 2010-11-04T00:57:00.778364Z
  3624. + 17
  3625. + alannisota
  3626. +
  3627. +
  3628. +
  3629. +
  3630. +
  3631. +
  3632. +
  3633. +
  3634. +
  3635. +
  3636. +
  3637. +
  3638. +
  3639. +
  3640. +
  3641. +
  3642. +
  3643. +
  3644. +
  3645. +
  3646. +
  3647. + 7509
  3648. +
  3649. + r5k_directv_buttons.c
  3650. + file
  3651. +
  3652. +
  3653. +
  3654. +
  3655. + 2011-04-09T02:29:47.558136Z
  3656. + 3f582e1df98aef283f15fb96c3f1339f
  3657. + 2009-11-17T16:32:06.245666Z
  3658. + 3
  3659. + alannisota
  3660. +
  3661. +
  3662. +
  3663. +
  3664. +
  3665. +
  3666. +
  3667. +
  3668. +
  3669. +
  3670. +
  3671. +
  3672. +
  3673. +
  3674. +
  3675. +
  3676. +
  3677. +
  3678. +
  3679. +
  3680. +
  3681. + 7031
  3682. +
  3683. + libusb_augment.c
  3684. + file
  3685. +
  3686. +
  3687. +
  3688. +
  3689. + 2011-04-09T02:29:47.559136Z
  3690. + 6c16aed4347ce34061bbc43b09ed7f3c
  3691. + 2009-11-20T22:54:57.232504Z
  3692. + 4
  3693. + alannisota
  3694. +
  3695. +
  3696. +
  3697. +
  3698. +
  3699. +
  3700. +
  3701. +
  3702. +
  3703. +
  3704. +
  3705. +
  3706. +
  3707. +
  3708. +
  3709. +
  3710. +
  3711. +
  3712. +
  3713. +
  3714. +
  3715. + 10605
  3716. +
  3717. + libusb_augment.h
  3718. + file
  3719. +
  3720. +
  3721. +
  3722. +
  3723. + 2011-04-09T02:29:47.560136Z
  3724. + c78f28f02bf3924dbe68a7b6a6c1ecf6
  3725. + 2009-11-20T22:54:57.232504Z
  3726. + 4
  3727. + alannisota
  3728. +
  3729. +
  3730. +
  3731. +
  3732. +
  3733. +
  3734. +
  3735. +
  3736. +
  3737. +
  3738. +
  3739. +
  3740. +
  3741. +
  3742. +
  3743. +
  3744. +
  3745. +
  3746. +
  3747. +
  3748. +
  3749. + 1663
  3750. +
  3751. + r5000.c
  3752. + file
  3753. +
  3754. +
  3755. +
  3756. +
  3757. + 2011-04-09T02:29:47.561136Z
  3758. + de4a381cb0c8f050d6abe8d40156d7ad
  3759. + 2010-05-01T16:24:30.997577Z
  3760. + 13
  3761. + alannisota
  3762. +
  3763. +
  3764. +
  3765. +
  3766. +
  3767. +
  3768. +
  3769. +
  3770. +
  3771. +
  3772. +
  3773. +
  3774. +
  3775. +
  3776. +
  3777. +
  3778. +
  3779. +
  3780. +
  3781. +
  3782. +
  3783. + 22120
  3784. +
  3785. + r5k_dsr_buttons.c
  3786. + file
  3787. +
  3788. +
  3789. +
  3790. +
  3791. + 2011-04-09T02:29:47.562136Z
  3792. + 6cf22ea89a6b19303e99c65569bd0caf
  3793. + 2010-11-04T00:57:00.778364Z
  3794. + 17
  3795. + alannisota
  3796. +
  3797. +
  3798. +
  3799. +
  3800. +
  3801. +
  3802. +
  3803. +
  3804. +
  3805. +
  3806. +
  3807. +
  3808. +
  3809. +
  3810. +
  3811. +
  3812. +
  3813. +
  3814. +
  3815. +
  3816. +
  3817. + 3825
  3818. +
  3819. + r5000_internal.h
  3820. + file
  3821. +
  3822. +
  3823. +
  3824. +
  3825. + 2011-04-09T02:29:47.563136Z
  3826. + b5098b35494c2d810fd8834343e5871a
  3827. + 2010-11-04T00:57:00.778364Z
  3828. + 17
  3829. + alannisota
  3830. +
  3831. +
  3832. +
  3833. +
  3834. +
  3835. +
  3836. +
  3837. +
  3838. +
  3839. +
  3840. +
  3841. +
  3842. +
  3843. +
  3844. +
  3845. +
  3846. +
  3847. +
  3848. +
  3849. +
  3850. +
  3851. + 3779
  3852. +
  3853. + r5k_pes.c
  3854. + file
  3855. +
  3856. +
  3857. +
  3858. +
  3859. + 2011-04-09T02:29:47.564136Z
  3860. + b7cb637fcd3be09197fc41dad4d1f9ba
  3861. + 2009-11-20T22:54:57.232504Z
  3862. + 4
  3863. + alannisota
  3864. +
  3865. +
  3866. +
  3867. +
  3868. +
  3869. +
  3870. +
  3871. +
  3872. +
  3873. +
  3874. +
  3875. +
  3876. +
  3877. +
  3878. +
  3879. +
  3880. +
  3881. +
  3882. +
  3883. +
  3884. +
  3885. + 10389
  3886. +
  3887. + r5k_sat.c
  3888. + file
  3889. +
  3890. +
  3891. +
  3892. +
  3893. + 2011-04-09T02:29:47.565136Z
  3894. + 1e7fddc53577f3a7fbbf89f0906c6355
  3895. + 2010-11-04T00:57:00.778364Z
  3896. + 17
  3897. + alannisota
  3898. +
  3899. +
  3900. +
  3901. +
  3902. +
  3903. +
  3904. +
  3905. +
  3906. +
  3907. +
  3908. +
  3909. +
  3910. +
  3911. +
  3912. +
  3913. +
  3914. +
  3915. +
  3916. +
  3917. +
  3918. +
  3919. + 14340
  3920. +
  3921. + r5000.h
  3922. + file
  3923. +
  3924. +
  3925. +
  3926. +
  3927. + 2011-04-09T02:29:47.566136Z
  3928. + 893190b2b4c22b4c851bdd906068f292
  3929. + 2009-12-17T16:13:51.909319Z
  3930. + 11
  3931. + alannisota
  3932. +
  3933. +
  3934. +
  3935. +
  3936. +
  3937. +
  3938. +
  3939. +
  3940. +
  3941. +
  3942. +
  3943. +
  3944. +
  3945. +
  3946. +
  3947. +
  3948. +
  3949. +
  3950. +
  3951. +
  3952. +
  3953. + 1856
  3954. +
  3955. + r5k_misc.c
  3956. + file
  3957. +
  3958. +
  3959. +
  3960. +
  3961. + 2011-04-09T02:29:47.567136Z
  3962. + c64c3490880278f1767c56a3622b33e7
  3963. + 2010-11-04T00:57:00.778364Z
  3964. + 17
  3965. + alannisota
  3966. +
  3967. +
  3968. +
  3969. +
  3970. +
  3971. +
  3972. +
  3973. +
  3974. +
  3975. +
  3976. +
  3977. +
  3978. +
  3979. +
  3980. +
  3981. +
  3982. +
  3983. +
  3984. +
  3985. +
  3986. +
  3987. + 7560
  3988. +
  3989. + r5k_dish6000_buttons.c
  3990. + file
  3991. +
  3992. +
  3993. +
  3994. +
  3995. + 2011-04-09T02:29:47.568136Z
  3996. + dba930e1177815fd10a12fb035e9a7ae
  3997. + 2009-11-17T16:32:06.245666Z
  3998. + 3
  3999. + alannisota
  4000. +
  4001. +
  4002. +
  4003. +
  4004. +
  4005. +
  4006. +
  4007. +
  4008. +
  4009. +
  4010. +
  4011. +
  4012. +
  4013. +
  4014. +
  4015. +
  4016. +
  4017. +
  4018. +
  4019. +
  4020. +
  4021. + 12126
  4022. +
  4023. + r5k_vip_buttons.c
  4024. + file
  4025. +
  4026. +
  4027. +
  4028. +
  4029. + 2011-04-09T02:29:47.569136Z
  4030. + 6742808bbe96392ea1d4c6b3689f7ad0
  4031. + 2010-02-24T04:59:22.991373Z
  4032. + 12
  4033. + alannisota
  4034. +
  4035. +
  4036. +
  4037. +
  4038. +
  4039. +
  4040. +
  4041. +
  4042. +
  4043. +
  4044. +
  4045. +
  4046. +
  4047. +
  4048. +
  4049. +
  4050. +
  4051. +
  4052. +
  4053. +
  4054. +
  4055. + 14989
  4056. +
  4057. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/libusb_augment.c.svn-base ./libs/libmythtv/r5000/.svn/text-base/libusb_augment.c.svn-base
  4058. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/libusb_augment.c.svn-base 1969-12-31 16:00:00.000000000 -0800
  4059. --- ./libs/libmythtv/r5000/.svn/text-base/libusb_augment.c.svn-base 2011-04-08 19:29:47.000000000 -0700
  4060. ***************
  4061. *** 0 ****
  4062. --- 1,311 ----
  4063. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  4064. + * 2005-10-19/lindi: downloaded from http://www.gaesi.org/~nmct/cvista/cvista/
  4065. + *
  4066. + * This library is free software; you can redistribute it and/or
  4067. + * modify it under the terms of the GNU Lesser General Public
  4068. + * License as published by the Free Software Foundation; either
  4069. + * version 2.1 of the License, or (at your option) any later version.
  4070. + *
  4071. + * This library is distributed in the hope that it will be useful,
  4072. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4073. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  4074. + * Lesser General Public License for more details.
  4075. + *
  4076. + * You should have received a copy of the GNU Lesser General Public
  4077. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  4078. + */
  4079. +
  4080. + // libusb_augment.c
  4081. + // $Revision$
  4082. + // $Date$
  4083. +
  4084. + // Hopefully, the functions in this file will become part of libusb.
  4085. +
  4086. + #include <stdio.h>
  4087. + #include <sys/ioctl.h>
  4088. + #include <errno.h>
  4089. + #include <sys/time.h>
  4090. + #include <sys/poll.h>
  4091. + #include <usb.h>
  4092. + #include <linux/usbdevice_fs.h>
  4093. + #include <string.h>
  4094. + #include <signal.h>
  4095. + #define LIBUSB_AUGMENT
  4096. + #include "libusb_augment.h"
  4097. +
  4098. + // Taken from libusb file usbi.h because usb.h
  4099. + // hides the definition of usb_dev_handle.
  4100. + extern int usb_debug;
  4101. +
  4102. + struct usb_dev_handle {
  4103. + int fd;
  4104. +
  4105. + struct usb_bus *bus;
  4106. + struct usb_device *device;
  4107. +
  4108. + int config;
  4109. + int interface;
  4110. + int altsetting;
  4111. +
  4112. + /* Added by RMT so implementations can store other per-open-device data */
  4113. + void *impl_info;
  4114. + };
  4115. +
  4116. + // Taken from libusb file error.h to supply error handling macro definition.
  4117. + typedef enum {
  4118. + USB_ERROR_TYPE_NONE = 0,
  4119. + USB_ERROR_TYPE_STRING,
  4120. + USB_ERROR_TYPE_ERRNO,
  4121. + } usb_error_type_t;
  4122. +
  4123. + extern char usb_error_str[1024];
  4124. + extern usb_error_type_t usb_error_type;
  4125. +
  4126. + #define USB_ERROR_STR(format, args...) \
  4127. + do { \
  4128. + usb_error_type = USB_ERROR_TYPE_STRING; \
  4129. + snprintf(usb_error_str, sizeof(usb_error_str) - 1, format, ## args); \
  4130. + if (usb_debug >= 2) \
  4131. + fprintf(stderr, "USB error: %s\n", usb_error_str); \
  4132. + } while (0)
  4133. +
  4134. + static int urb_signr = 0;
  4135. + void (*urb_completion_callback)(struct usbdevfs_urb *) = NULL;
  4136. + #define USB_ASYNC_COMPLETION_SIGNAL (SIGRTMIN + 5)
  4137. +
  4138. + void urb_completion_handler(int signum, siginfo_t *info, void *context)
  4139. + {
  4140. + struct usbdevfs_urb *urb = (struct usbdevfs_urb *)info->si_addr;
  4141. + struct usbdevfs_urb *context1;
  4142. + usb_dev_handle *dev = (usb_dev_handle *)urb->usercontext;
  4143. + int ret;
  4144. + if (info->si_code != SI_ASYNCIO ||
  4145. + info->si_signo != USB_ASYNC_COMPLETION_SIGNAL) {
  4146. + return;
  4147. + }
  4148. + if(info->si_errno != 0) {
  4149. + USB_ERROR_STR("Async URB Completion failed: %s", strerror(info->si_errno));
  4150. + return;
  4151. + }
  4152. + ret = ioctl(dev->fd, USBDEVFS_REAPURB, &context1);
  4153. + if(ret < 0) {
  4154. + USB_ERROR_STR("Failed to read URB: %s", strerror(-ret));
  4155. + return;
  4156. + }
  4157. + if(context1 != urb) {
  4158. + USB_ERROR_STR("Reaped unexpected urb");
  4159. + return;
  4160. + }
  4161. + if(urb_completion_callback)
  4162. + urb_completion_callback(urb);
  4163. + }
  4164. +
  4165. + int usbdevfs_urb_signal_completion(void (*cb)( struct usbdevfs_urb *))
  4166. + {
  4167. + urb_completion_callback = cb;
  4168. + urb_signr = USB_ASYNC_COMPLETION_SIGNAL;
  4169. + struct sigaction usb_linux_sa;
  4170. + usb_linux_sa.sa_sigaction = urb_completion_handler;
  4171. + sigfillset(&usb_linux_sa.sa_mask);
  4172. + usb_linux_sa.sa_flags = SA_SIGINFO;
  4173. + usb_linux_sa.sa_flags |= SA_ONSTACK;
  4174. + sigaction(USB_ASYNC_COMPLETION_SIGNAL, &usb_linux_sa, NULL);
  4175. + return 0;
  4176. + }
  4177. +
  4178. + struct usbdevfs_urb *usb_bulk_setup(
  4179. + struct usbdevfs_urb *iso_urb, // URB pointer-pointer.
  4180. + unsigned char ep, // Device endpoint.
  4181. + char *bytes, // Data buffer pointer.
  4182. + int size) { // Size of the buffer.
  4183. + struct usbdevfs_urb *local_urb;
  4184. +
  4185. + // No more than 16384 bytes can be transferred at a time.
  4186. + if (size > 16384) {
  4187. + USB_ERROR_STR("error on transfer size: %s", strerror(EINVAL));
  4188. + return NULL;
  4189. + }
  4190. + local_urb = iso_urb;
  4191. + if (!local_urb) {
  4192. + local_urb = (struct usbdevfs_urb *) calloc(1, sizeof(struct usbdevfs_urb));
  4193. + if (!local_urb) {
  4194. + USB_ERROR_STR("error on packet size: %s", strerror(EINVAL));
  4195. + return NULL;
  4196. + }
  4197. + }
  4198. + local_urb->type = USBDEVFS_URB_TYPE_BULK;
  4199. + local_urb->endpoint = ep;
  4200. + local_urb->status = 0;
  4201. + local_urb->flags = 0;
  4202. + local_urb->buffer = bytes;
  4203. + local_urb->buffer_length = size;
  4204. + local_urb->actual_length = 0;
  4205. + local_urb->start_frame = 0;
  4206. + local_urb->number_of_packets = 0;
  4207. + local_urb->error_count = 0;
  4208. + local_urb->signr = urb_signr;
  4209. + local_urb->usercontext = (void *) 0;
  4210. + return local_urb;
  4211. + }
  4212. + // Reading and writing are the same except for the endpoint
  4213. + struct usbdevfs_urb *usb_isochronous_setup(
  4214. + struct usbdevfs_urb *iso_urb, // URB pointer-pointer.
  4215. + unsigned char ep, // Device endpoint.
  4216. + int pktsize, // Endpoint packet size.
  4217. + char *bytes, // Data buffer pointer.
  4218. + int size) { // Size of the buffer.
  4219. + struct usbdevfs_urb *local_urb;
  4220. + // int ret
  4221. + // was unused /lindi
  4222. + int pktcount, fullpkts, partpktsize, packets, urb_size;
  4223. +
  4224. + // No more than 32768 bytes can be transferred at a time.
  4225. + if (size > 32768) {
  4226. + USB_ERROR_STR("error on transfer size: %s", strerror(EINVAL));
  4227. + return NULL;
  4228. + }
  4229. +
  4230. + // Determine the number of packets that need to be created based upon the
  4231. + // amount of data to be transferred, and the maximum packet size of the
  4232. + // endpoint.
  4233. +
  4234. + // Find integral number of full packets.
  4235. + //fprintf(stderr, "buf size: %d\n", size);
  4236. + //fprintf(stderr, "iso size: %d\n", pktsize);
  4237. + fullpkts = size / pktsize;
  4238. + //fprintf(stderr, "Number of full packets: %d\n", fullpkts);
  4239. + // Find length of partial packet.
  4240. + partpktsize = size % pktsize;
  4241. + //fprintf(stderr, "Size of partial packet: %d\n", partpktsize);
  4242. + // Find total number of packets to be transfered.
  4243. + packets = fullpkts + ((partpktsize > 0) ? 1 : 0);
  4244. + //fprintf(stderr, "Total number of packets: %d\n", packets);
  4245. + // Limit the number of packets transfered according to
  4246. + // the Linux usbdevfs maximum read/write buffer size.
  4247. + if ((packets < 1) || (packets > 128)) {
  4248. + USB_ERROR_STR("error on packet size: %s", strerror(EINVAL));
  4249. + return NULL;
  4250. + }
  4251. +
  4252. + // If necessary, allocate the urb and packet
  4253. + // descriptor structures from the heap.
  4254. + local_urb = iso_urb;
  4255. + if (!local_urb) {
  4256. + urb_size = sizeof(struct usbdevfs_urb) +
  4257. + packets * sizeof(struct usb_iso_packet_desc);
  4258. + local_urb = (struct usbdevfs_urb *) calloc(1, urb_size);
  4259. + if (!local_urb) {
  4260. + USB_ERROR_STR("error on packet size: %s", strerror(EINVAL));
  4261. + return NULL;
  4262. + }
  4263. + }
  4264. +
  4265. + // Set up each packet for the data to be transferred.
  4266. + for (pktcount = 0; pktcount < fullpkts; pktcount++) {
  4267. + local_urb->iso_frame_desc[pktcount].length = pktsize;
  4268. + local_urb->iso_frame_desc[pktcount].actual_length = 0;
  4269. + local_urb->iso_frame_desc[pktcount].status = 0;
  4270. + }
  4271. +
  4272. + // Set up the last packet for the partial data to be transferred.
  4273. + if (partpktsize > 0) {
  4274. + local_urb->iso_frame_desc[pktcount].length = partpktsize;
  4275. + local_urb->iso_frame_desc[pktcount].actual_length = 0;
  4276. + local_urb->iso_frame_desc[pktcount++].status = 0;
  4277. + }
  4278. +
  4279. + // Set up the URB structure.
  4280. + local_urb->type = USBDEVFS_URB_TYPE_ISO;
  4281. + //fprintf(stderr, "type: %d\n", local_urb->type);
  4282. + local_urb->endpoint = ep;
  4283. + //fprintf(stderr, "endpoint: 0x%x\n", local_urb->endpoint);
  4284. + local_urb->status = 0;
  4285. + local_urb->flags = USBDEVFS_URB_ISO_ASAP; // Additional flags here?
  4286. + //fprintf(stderr, "flags: %d\n", local_urb->flags);
  4287. + local_urb->buffer = bytes;
  4288. + //fprintf(stderr, "buffer: 0x%x\n", local_urb->buffer);
  4289. + local_urb->buffer_length = size;
  4290. + //fprintf(stderr, "buffer_length: %d\n", local_urb->buffer_length);
  4291. + local_urb->actual_length = 0;
  4292. + local_urb->start_frame = 0;
  4293. + //fprintf(stderr, "start_frame: %d\n", local_urb->start_frame);
  4294. + local_urb->number_of_packets = pktcount;
  4295. + //fprintf(stderr, "number_of_packets: %d\n", local_urb->number_of_packets);
  4296. + local_urb->error_count = 0;
  4297. + local_urb->signr = 0;
  4298. + //fprintf(stderr, "signr: %d\n", local_urb->signr);
  4299. + local_urb->usercontext = (void *) 0;
  4300. + return local_urb;
  4301. + }
  4302. +
  4303. +
  4304. + int usb_urb_submit(usb_dev_handle *dev, // Open usb device handle.
  4305. + struct usbdevfs_urb *iso_urb, // Pointer to URB.
  4306. + struct timeval *tv_submit) { // Time structure pointer.
  4307. + int ret;
  4308. +
  4309. + iso_urb->usercontext = dev;
  4310. + // Get actual time, of the URB submission.
  4311. + if(tv_submit)
  4312. + gettimeofday(tv_submit, NULL);
  4313. + // Submit the URB through an IOCTL call.
  4314. + ret = ioctl(dev->fd, USBDEVFS_SUBMITURB, iso_urb);
  4315. + //fprintf(stderr, "start_frame now: %d\n", iso_urb->start_frame);
  4316. + //fprintf(stderr, "submit ioctl return value: %d\n", ret);
  4317. + if (ret < 0) {
  4318. + //fprintf(stderr, "error submitting URB: %s\n", strerror(errno));
  4319. + USB_ERROR_STR("error submitting URB: %s", strerror(errno));
  4320. + return -errno;
  4321. + }
  4322. + return ret;
  4323. + }
  4324. +
  4325. +
  4326. + int usb_urb_reap(usb_dev_handle *dev, // Open usb device handle.
  4327. + struct usbdevfs_urb *iso_urb, // Pointer to URB.
  4328. + int timeout) { // Attempt timeout (usec).
  4329. + void *context = NULL;
  4330. + int ret;
  4331. + struct pollfd ufd[1];
  4332. +
  4333. + // Get actual time, and add the timeout value. The result is the absolute
  4334. + // time where we have to quit waiting for an isochronous message.
  4335. + ufd[0].fd = dev->fd;
  4336. + ufd[0].events = POLLIN | POLLOUT;
  4337. + ufd[0].revents = 0;
  4338. + ret = poll(ufd, 1, timeout);
  4339. + if(ret <= 0)
  4340. + return -ETIMEDOUT;
  4341. +
  4342. + //fprintf(stderr, "preparing to reap\n");
  4343. + ret = ioctl(dev->fd, USBDEVFS_REAPURB, &context);
  4344. +
  4345. + /*
  4346. + * If there was an error, that wasn"t EAGAIN (no completion), then
  4347. + * something happened during the reaping and we should return that
  4348. + * error now
  4349. + */
  4350. + //fprintf(stderr, "reap ioctl return value: %d\n", ret);
  4351. + if (ret < 0) {
  4352. + USB_ERROR_STR("error reaping interrupt URB: %s",
  4353. + strerror(errno));
  4354. + return -errno;
  4355. + }
  4356. +
  4357. + //fprintf(stderr, "actual_length: %d\n", iso_urb->actual_length);
  4358. + //fprintf(stderr, "URB status: %d\n", iso_urb->status);
  4359. + //fprintf(stderr, "error count: %d\n", iso_urb->error_count);
  4360. +
  4361. + //fprintf(stderr, "waiting done\n");
  4362. + if(context != NULL && iso_urb != context) {
  4363. + fprintf(stderr, "Expected urb: %p but got %p\n", iso_urb, context);
  4364. + return -1;
  4365. + }
  4366. + //fprintf(stderr, "Total bytes: %d\n", bytesdone);
  4367. + return iso_urb->actual_length;
  4368. + }
  4369. +
  4370. + int usb_urb_cancel(usb_dev_handle *dev, struct usbdevfs_urb *iso_urb)
  4371. + {
  4372. + return ioctl(dev->fd, USBDEVFS_DISCARDURB, iso_urb);
  4373. + }
  4374. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/libusb_augment.h.svn-base ./libs/libmythtv/r5000/.svn/text-base/libusb_augment.h.svn-base
  4375. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/libusb_augment.h.svn-base 1969-12-31 16:00:00.000000000 -0800
  4376. --- ./libs/libmythtv/r5000/.svn/text-base/libusb_augment.h.svn-base 2011-04-08 19:29:47.000000000 -0700
  4377. ***************
  4378. *** 0 ****
  4379. --- 1,36 ----
  4380. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  4381. + * 2005-10-19/lindi: downloaded from http://www.gaesi.org/~nmct/cvista/cvista/
  4382. + *
  4383. + * This library is free software; you can redistribute it and/or
  4384. + * modify it under the terms of the GNU Lesser General Public
  4385. + * License as published by the Free Software Foundation; either
  4386. + * version 2.1 of the License, or (at your option) any later version.
  4387. + *
  4388. + * This library is distributed in the hope that it will be useful,
  4389. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4390. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  4391. + * Lesser General Public License for more details.
  4392. + *
  4393. + * You should have received a copy of the GNU Lesser General Public
  4394. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  4395. + */
  4396. +
  4397. + #ifdef LIBUSB_AUGMENT
  4398. + // Taken from libusb file linux.h to provide the URB structure definitions.
  4399. + struct usb_iso_packet_desc {
  4400. + unsigned int length;
  4401. + unsigned int actual_length;
  4402. + unsigned int status;
  4403. + };
  4404. + #endif
  4405. +
  4406. + int usbdevfs_urb_signal_completion(void (*cb)( struct usbdevfs_urb *));
  4407. + struct usbdevfs_urb *usb_bulk_setup(struct usbdevfs_urb *iso_urb, unsigned char ep,
  4408. + char *bytes, int size);
  4409. + struct usbdevfs_urb *usb_isochronous_setup(struct usbdevfs_urb *iso_urb,
  4410. + unsigned char ep, int pktsize, char *bytes, int size);
  4411. + int usb_urb_submit(usb_dev_handle *dev, struct usbdevfs_urb *iso_urb,
  4412. + struct timeval *tv_rsubmit);
  4413. + int usb_urb_reap(usb_dev_handle *dev, struct usbdevfs_urb *iso_urb,
  4414. + int timeout_usec);
  4415. + int usb_urb_cancel(usb_dev_handle *dev, struct usbdevfs_urb *iso_urb);
  4416. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5000.c.svn-base ./libs/libmythtv/r5000/.svn/text-base/r5000.c.svn-base
  4417. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5000.c.svn-base 1969-12-31 16:00:00.000000000 -0800
  4418. --- ./libs/libmythtv/r5000/.svn/text-base/r5000.c.svn-base 2011-04-08 19:29:47.000000000 -0700
  4419. ***************
  4420. *** 0 ****
  4421. --- 1,767 ----
  4422. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  4423. + *
  4424. + * This library is free software; you can redistribute it and/or
  4425. + * modify it under the terms of the GNU Lesser General Public
  4426. + * License as published by the Free Software Foundation; either
  4427. + * version 2.1 of the License, or (at your option) any later version.
  4428. + *
  4429. + * This library is distributed in the hope that it will be useful,
  4430. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4431. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  4432. + * Lesser General Public License for more details.
  4433. + *
  4434. + * You should have received a copy of the GNU Lesser General Public
  4435. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  4436. + */
  4437. +
  4438. + #include <stdio.h>
  4439. + #include <sys/types.h>
  4440. + #include <sys/time.h>
  4441. + #include <sys/stat.h>
  4442. + #include <fcntl.h>
  4443. + #include <string.h>
  4444. + #include <errno.h>
  4445. + #include <stdarg.h>
  4446. + #include <time.h>
  4447. +
  4448. + #ifdef R5K_DEBUG
  4449. + char strmfile[256] = "/tmp/strm";
  4450. + int fd = -1;
  4451. + #endif
  4452. +
  4453. + #ifdef R5K_RAWUSB
  4454. + int usbfd = -1;
  4455. + #endif
  4456. + #include "r5000_internal.h"
  4457. + #include "r5000init.h"
  4458. +
  4459. + #define R5K_WARM_VID 0x0547
  4460. + #define R5K_WARM_PID 0x1002
  4461. +
  4462. + #define MAX_URBS_IN_FLIGHT 128
  4463. +
  4464. + static struct {
  4465. + char serial[8];
  4466. + time_t time;
  4467. + } last_cmd_time[10] = {
  4468. + {{0}, 0}, {{0}, 0}, {{0}, 0}, {{0}, 0}, {{0}, 0},
  4469. + {{0}, 0}, {{0}, 0}, {{0}, 0}, {{0}, 0}, {{0}, 0},
  4470. + };
  4471. +
  4472. +
  4473. + #define R5K_UNRELIABLE_TIMEOUT (5 * 60)
  4474. + #define R5K_BUTTON_LEN(_r, _b) \
  4475. + ((_r)->button->len ? (_r)->button->len \
  4476. + : ((unsigned char)(_b)[1]) + 6 )
  4477. + #ifndef USE_ISOCHRONOUS
  4478. + //BULK
  4479. + #define R5K_URB_BUFFER_SIZE (1 << 14)
  4480. + #else
  4481. + //ISOCHRONOUS
  4482. + #define LIBUSB_AUGMENT
  4483. + #define R5K_URB_BUFFER_SIZE (1 << 15)
  4484. + #endif
  4485. + #include "libusb_augment.h"
  4486. +
  4487. + static int r5000_usb_init = 0;
  4488. + static struct {
  4489. + unsigned char serial[R5K_MAX_DEVS][8];
  4490. + struct usb_device *dev[R5K_MAX_DEVS];
  4491. + int count;
  4492. + } r5000_dev_map;
  4493. +
  4494. + static void (*msgcb)(char *msg);
  4495. +
  4496. + enum {
  4497. + R5K_PMT_START = 0x01,
  4498. + R5K_PMT_READY = 0x02
  4499. + };
  4500. +
  4501. + long r5klog_count = 0;
  4502. + FILE *r5klog_fh = NULL;
  4503. + struct timeval r5klog_tv;
  4504. + char r5klog_msg[2048];
  4505. +
  4506. + #ifdef R5000_TRACE
  4507. + void r5000_log(int flush, const char *fmt, ...)
  4508. + {
  4509. + struct timeval tv, tv1;
  4510. + va_list args;
  4511. + char logmsg[2048];
  4512. +
  4513. + if(! r5klog_fh) {
  4514. + int oldmask = umask(0);
  4515. + r5klog_fh = fopen("/tmp/r5000_trace.log", "w+");
  4516. + umask(oldmask);
  4517. + }
  4518. +
  4519. + va_start(args,fmt);
  4520. + vsnprintf(logmsg,sizeof(logmsg),fmt,args);
  4521. + va_end(args);
  4522. +
  4523. + if (strncmp(logmsg, r5klog_msg, sizeof(logmsg)) == 0) {
  4524. + r5klog_count++;
  4525. + return;
  4526. + }
  4527. + gettimeofday(&tv, NULL);
  4528. + timersub(&tv, &r5klog_tv, &tv1);
  4529. + r5klog_tv = tv;
  4530. + if(r5klog_count > 1) {
  4531. + fprintf(r5klog_fh, "%ld.%06ld: Repeated %ld times\n", (long)tv1.tv_sec, (long)tv1.tv_usec, r5klog_count);
  4532. + printf("%ld.%06ld: Repeated %ld times\n", (long)tv1.tv_sec, (long)tv1.tv_usec, r5klog_count);
  4533. + }
  4534. + fprintf(r5klog_fh, "%ld.%ld: %s\n", (long)tv1.tv_sec, (long)tv1.tv_usec, logmsg);
  4535. + printf("%ld.%ld: %s\n", (long)tv1.tv_sec, (long)tv1.tv_usec, logmsg);
  4536. + memcpy(r5klog_msg, logmsg, sizeof(logmsg));
  4537. + r5klog_count = 1;
  4538. + if(flush) {
  4539. + fflush(r5klog_fh);
  4540. + }
  4541. + }
  4542. + #else
  4543. + void r5000_log(int flush, const char *fmt, ...)
  4544. + {
  4545. + }
  4546. + #endif
  4547. +
  4548. + void r5000_print(const char *fmt, ...)
  4549. + {
  4550. + va_list args;
  4551. + char logmsg[1024];
  4552. + va_start(args,fmt);
  4553. + vsnprintf(logmsg,sizeof(logmsg),fmt,args);
  4554. + va_end(args);
  4555. + if(msgcb) {
  4556. + //msgcb routine must ensure thread safeness
  4557. + msgcb(logmsg);
  4558. + } else {
  4559. + fprintf(stderr, "%s", logmsg);
  4560. + }
  4561. + }
  4562. +
  4563. + int r5000_create_urbs(r5kdev_t *r5kdev)
  4564. + {
  4565. + int i, urbsize;
  4566. + #ifndef USE_ISOCHRONOUS
  4567. + urbsize = sizeof(struct usbdevfs_urb);
  4568. + #else
  4569. + urbsize = sizeof(struct usbdevfs_urb) + sizeof(struct usb_iso_packet_desc) * R5K_URB_BUFFER_SIZE / 1024;
  4570. + #endif
  4571. +
  4572. + r5kdev->buffer = (char *)malloc(R5K_URB_BUFFER_SIZE * MAX_URBS_IN_FLIGHT);
  4573. + r5kdev->urbs = (struct usbdevfs_urb **)malloc(sizeof(struct usbdevfs_urb *) * MAX_URBS_IN_FLIGHT);
  4574. + r5kdev->urbblk = (void *)malloc(urbsize * MAX_URBS_IN_FLIGHT);
  4575. + for(i = 0; i < MAX_URBS_IN_FLIGHT; i++) {
  4576. + r5kdev->urbs[i] = (struct usbdevfs_urb *)((unsigned long)r5kdev->urbblk + (urbsize * i));
  4577. + #ifndef USE_ISOCHRONOUS
  4578. + usb_bulk_setup(r5kdev->urbs[i], 0x82, r5kdev->buffer + (R5K_URB_BUFFER_SIZE*i), R5K_URB_BUFFER_SIZE);
  4579. + #else
  4580. + usb_isochronous_setup(r5kdev->urbs[i], 0x82, 1024, r5kdev->buffer + (R5K_URB_BUFFER_SIZE*i), R5K_URB_BUFFER_SIZE);
  4581. + #endif
  4582. + }
  4583. + r5kdev->nexturb = 0;
  4584. + return 1;
  4585. + }
  4586. +
  4587. + int r5000_free_urbs(r5kdev_t *r5kdev)
  4588. + {
  4589. + free(r5kdev->urbblk);
  4590. + free(r5kdev->urbs);
  4591. + free(r5kdev->buffer);
  4592. + return 0;
  4593. + }
  4594. +
  4595. + usb_dev_handle *r5000_locate_device(
  4596. + unsigned short vendor_id, unsigned short product_id, int skip)
  4597. + {
  4598. + struct usb_bus *bus;
  4599. + struct usb_device *dev;
  4600. + usb_dev_handle *device_handle = 0;
  4601. + usb_find_busses();
  4602. + usb_find_devices();
  4603. +
  4604. + for (bus = usb_get_busses(); bus && !device_handle; bus = bus->next)
  4605. + {
  4606. + for (dev = bus->devices; dev && !device_handle; dev = dev->next)
  4607. + {
  4608. + if (dev->descriptor.idVendor == vendor_id &&
  4609. + dev->descriptor.idProduct == product_id)
  4610. + {
  4611. + device_handle = usb_open(dev);
  4612. + if(device_handle && skip) {
  4613. + usb_close(device_handle);
  4614. + device_handle = NULL;
  4615. + skip--;
  4616. + }
  4617. + }
  4618. + }
  4619. + }
  4620. +
  4621. + if (device_handle) {
  4622. + int open_status = usb_set_configuration(device_handle,1);
  4623. +
  4624. + open_status = usb_claim_interface(device_handle,0);
  4625. +
  4626. + open_status = usb_set_altinterface(device_handle,0);
  4627. + }
  4628. + return (device_handle);
  4629. + }
  4630. +
  4631. + int r5000_dev_init(r5kdev_t *r5kdev) {
  4632. + int i, bytes;
  4633. + char *ptr;
  4634. + unsigned char *serial = r5kdev->serial;
  4635. + char datain[0x80];
  4636. + bytes = usb_bulk_read(r5kdev->handle, 129, datain, sizeof(datain), 5000);
  4637. + for(i = 0; i < R5K_INIT_SERIAL; i++) {
  4638. + //PRINTHEX("Write:\n", r5kinit[i].data, r5kinit[i].wlen);
  4639. + if(r5kinit[i].wsleep) usleep(r5kinit[i].wsleep);
  4640. + usb_bulk_write(r5kdev->handle, 1, r5kinit[i].data, r5kinit[i].wlen, 5000);
  4641. + if(r5kinit[i].rsleep) usleep(r5kinit[i].rsleep);
  4642. + bytes = usb_bulk_read(r5kdev->handle, 129, datain, sizeof(datain), 5000);
  4643. + //PRINTHEX("Read:\n", datain, bytes);
  4644. + if(r5kinit[i].rlen > 0 && bytes != r5kinit[i].rlen) {
  4645. + r5000_print("R5000 initialization failed at stage %d:\n\tExpected %d bytes, but got %d bytes\n", i, r5kinit[i].rlen, bytes);
  4646. + return 0;
  4647. + }
  4648. + }
  4649. +
  4650. + //last read is serial #
  4651. + if (datain[0] != 0x08) {
  4652. + r5000_print("R5000 initialization failed reading serial #\n");
  4653. + return 0;
  4654. + }
  4655. + for(ptr = datain + 6; ptr < datain + 13; ptr++) {
  4656. + *serial++ = ( *ptr >= '0' && *ptr <= 'z' ) ? *ptr : '*';
  4657. + }
  4658. + *serial = 0;
  4659. +
  4660. + //complete initialization now
  4661. + for(; i < R5K_INIT_MAX; i++) {
  4662. + //PRINTHEX("Write:\n", r5kinit[i].data, r5kinit[i].wlen);
  4663. + if(r5kinit[i].wsleep) usleep(r5kinit[i].wsleep);
  4664. + usb_bulk_write(r5kdev->handle, 1, r5kinit[i].data, r5kinit[i].wlen, 5000);
  4665. + if(r5kinit[i].rsleep) usleep(r5kinit[i].rsleep);
  4666. + bytes = usb_bulk_read(r5kdev->handle, 129, datain, sizeof(datain), 5000);
  4667. + //PRINTHEX("Read:\n", datain, bytes);
  4668. + if(r5kinit[i].rlen > 0 && bytes != r5kinit[i].rlen) {
  4669. + r5000_print("R5000 initialization failed at stage %d:\n\tExpected %d bytes, but got %d bytes\n", i, r5kinit[i].rlen, bytes);
  4670. + return 0;
  4671. + }
  4672. + }
  4673. + return 1;
  4674. + }
  4675. +
  4676. + int r5000_start_stream(r5kdev_t *r5kdev)
  4677. + {
  4678. + char data[0x80];
  4679. + int bytes;
  4680. + int i;
  4681. + struct usb_dev_handle *handle = (struct usb_dev_handle *)r5kdev->handle;
  4682. +
  4683. + //*r5kdev->last_command_time = time(NULL);
  4684. + r5000_log(0, "r5000_start_stream(%p)", r5kdev);
  4685. + if(! r5kdev->urbs)
  4686. + r5000_create_urbs(r5kdev);
  4687. +
  4688. + data[0] = 0x30;
  4689. + usb_bulk_write(handle, 1, data, 1, 5000);
  4690. + bytes = usb_bulk_read(handle, 129, data, 2, 5000);
  4691. +
  4692. + //0x50 sets byte mode. Use '0x60' to set word mode
  4693. + data[0] = r5kdev->read_words ? 0x60: 0x50;
  4694. + usb_bulk_write(handle, 1, data, 1, 5000);
  4695. +
  4696. + for(i=0; i < MAX_URBS_IN_FLIGHT; i++) {
  4697. + usb_urb_submit(handle, r5kdev->urbs[i], NULL);
  4698. + }
  4699. + r5kdev->nexturb = 0;
  4700. + r5kdev->streaming = 1;
  4701. + if(r5kdev->start_stream)
  4702. + r5kdev->start_stream(r5kdev);
  4703. + return 1;
  4704. + }
  4705. +
  4706. + int r5000_stop_stream(r5kdev_t *r5kdev)
  4707. + {
  4708. + struct usb_dev_handle *handle = (struct usb_dev_handle *)r5kdev->handle;
  4709. + struct usbdevfs_urb **urbs = r5kdev->urbs;
  4710. + int i;
  4711. +
  4712. + //*r5kdev->last_command_time = time(NULL);
  4713. + r5000_log(0, "r5000_stop_stream(%p)", r5kdev);
  4714. + if(r5kdev->streaming) {
  4715. + for(i=0; i < MAX_URBS_IN_FLIGHT; i++)
  4716. + usb_urb_cancel(handle, urbs[i]);
  4717. + r5kdev->streaming = 0;
  4718. + }
  4719. + return 1;
  4720. + }
  4721. +
  4722. + /* r5000_init must be called from a thread-safe context */
  4723. + int r5000_init(void (*_msgcb)(char *str))
  4724. + {
  4725. + int bus_count, dev_count;
  4726. + r5kdev_t r5kd;
  4727. + int count = 0;
  4728. +
  4729. + r5000_log(0, "r5000_init()");
  4730. +
  4731. + msgcb = _msgcb;
  4732. +
  4733. + if(r5000_usb_init)
  4734. + return 1;
  4735. + usb_init();
  4736. + bus_count = usb_find_busses();
  4737. + dev_count = usb_find_devices();
  4738. + if(bus_count == 0 || dev_count ==0) {
  4739. + r5000_print("R5000 failed to locate any USB devices. Are you sure you have permissions set properly?\n");
  4740. + return 0;
  4741. + }
  4742. + while(r5000_dev_map.count < R5K_MAX_DEVS) {
  4743. + r5kd.handle = r5000_locate_device(R5K_WARM_VID, R5K_WARM_PID, count);
  4744. + if(! r5kd.handle)
  4745. + break;
  4746. + if (r5000_dev_init(&r5kd)) {
  4747. + memcpy(r5000_dev_map.serial[r5000_dev_map.count], r5kd.serial, 8);
  4748. + r5000_dev_map.dev[r5000_dev_map.count] = usb_device(r5kd.handle);
  4749. + r5000_dev_map.count++;
  4750. + }
  4751. + count++;
  4752. + usb_close(r5kd.handle);
  4753. + }
  4754. + if(! r5000_dev_map.count) {
  4755. + r5000_print("R5000 failed to locate any R5000 devices. Are you sure you have permissions set properly?\n");
  4756. + return 0;
  4757. + }
  4758. + r5000_usb_init = 1;
  4759. + return 1;
  4760. + }
  4761. +
  4762. + r5kdev_t *r5000_open(r5ktype_t type,
  4763. + unsigned int (*cb)(unsigned char *buffer, int len, void *callback_data),
  4764. + void *cb_data,
  4765. + const char *serial)
  4766. + {
  4767. + r5kdev_t *r5kdev, r5kd;
  4768. + int count = 0;
  4769. +
  4770. + r5000_log(0, "r5000_open(%d, NULL, %p, %s)", type, cb_data, serial);
  4771. + memset(&r5kd, 0, sizeof(r5kdev_t));
  4772. +
  4773. + if(! r5000_usb_init) {
  4774. + r5000_print("R5000 was not initialized before r5000_open(). Please call r5000_init() first\n");
  4775. + return NULL;
  4776. + }
  4777. + for(count = 0; count < r5000_dev_map.count; count++) {
  4778. + if(! serial || memcmp(r5000_dev_map.serial[count], serial, 8) == 0) {
  4779. + r5kd.handle = usb_open(r5000_dev_map.dev[count]);
  4780. + if(! r5kd.handle)
  4781. + return NULL;
  4782. + usb_set_configuration(r5kd.handle,1);
  4783. + usb_claim_interface(r5kd.handle,0);
  4784. + usb_set_altinterface(r5kd.handle,0);
  4785. + if(! r5000_dev_init(&r5kd)) {
  4786. + usb_close(r5kd.handle);
  4787. + return NULL;
  4788. + }
  4789. + break;
  4790. + }
  4791. + }
  4792. + if(count == r5000_dev_map.count) {
  4793. + //We can't get here unless a serial was specified
  4794. + r5000_print("Could not locate R5000 device with serial '%s'\n", serial);
  4795. + return NULL;
  4796. + }
  4797. + #ifdef R5K_DEBUG
  4798. + printf("Reading stream file: %s\n", strmfile);
  4799. + fd = open(strmfile, O_RDONLY);
  4800. + #endif
  4801. + #ifdef R5K_RAWUSB
  4802. + usbfd = open("raw.av", O_WRONLY | O_CREAT | O_TRUNC, 0666);
  4803. + #endif
  4804. + r5kdev = (r5kdev_t *)malloc(sizeof(r5kdev_t));
  4805. + *r5kdev = r5kd;
  4806. + r5kdev->urbs = NULL;
  4807. + r5kdev->cb = cb;
  4808. + r5kdev->cb_data = cb_data;
  4809. + r5kdev->stb_type = type;
  4810. +
  4811. + r5kdev->last_command_time = &last_cmd_time[0].time;
  4812. + for(count = 0; count < 10; count++) {
  4813. + if (last_cmd_time[count].serial[0] == 0) {
  4814. + memcpy(last_cmd_time[count].serial, r5kdev->serial, 8);
  4815. + r5kdev->last_command_time = &last_cmd_time[count].time;
  4816. + break;
  4817. + } else if(memcmp(last_cmd_time[count].serial, r5kdev->serial, 8) == 0) {
  4818. + r5kdev->last_command_time = &last_cmd_time[count].time;
  4819. + break;
  4820. + }
  4821. + }
  4822. +
  4823. + switch(type) {
  4824. + case R5K_STB_VIP211:
  4825. + case R5K_STB_VIP622:
  4826. + vip_init(r5kdev);
  4827. + break;
  4828. + case R5K_STB_DIRECTV:
  4829. + case R5K_STB_DISH6000:
  4830. + pes_init(r5kdev);
  4831. + break;
  4832. + case R5K_STB_DSR:
  4833. + case R5K_STB_HDD:
  4834. + sat_init(r5kdev);
  4835. + break;
  4836. + default:
  4837. + r5000_print("Unknown STB type %d specified.\n", type);
  4838. + r5kdev->stb_type = R5K_STB_VIP211;
  4839. + vip_init(r5kdev);
  4840. + break;
  4841. + }
  4842. + {
  4843. + char fw[4];
  4844. + r5000_get_fw_version(r5kdev, fw);
  4845. + r5000_print("R5000 firmware version for %s: %s\n", r5kdev->serial, fw);
  4846. + }
  4847. + return r5kdev;
  4848. + }
  4849. +
  4850. + int r5000_close(r5kdev_t *r5kdev)
  4851. + {
  4852. + r5000_log(1, "r5000_close(%p)", r5kdev);
  4853. + if(! r5kdev)
  4854. + return 1;
  4855. + if(r5kdev->urbs) {
  4856. + if(r5kdev->streaming)
  4857. + r5000_stop_stream(r5kdev);
  4858. + r5000_free_urbs(r5kdev);
  4859. + }
  4860. + usb_close(r5kdev->handle);
  4861. + #ifdef R5K_RAWUSB
  4862. + if(usbfd >= 0) close(usbfd);
  4863. + #endif
  4864. + switch(r5kdev->stb_type) {
  4865. + case R5K_STB_VIP211:
  4866. + case R5K_STB_VIP622:
  4867. + vip_free(r5kdev);
  4868. + break;
  4869. + case R5K_STB_DIRECTV:
  4870. + case R5K_STB_DISH6000:
  4871. + pes_free(r5kdev);
  4872. + break;
  4873. + case R5K_STB_DSR:
  4874. + case R5K_STB_HDD:
  4875. + sat_free(r5kdev);
  4876. + break;
  4877. + }
  4878. + free(r5kdev);
  4879. + return 1;
  4880. + }
  4881. +
  4882. + int r5000_loop_iterate(r5kdev_t *r5kdev, int timeout_usec)
  4883. + {
  4884. + struct usb_dev_handle *handle = (struct usb_dev_handle *)r5kdev->handle;
  4885. + struct usbdevfs_urb **urbs = r5kdev->urbs;
  4886. + int len;
  4887. + char *buf;
  4888. +
  4889. + r5000_log(0, "r5000_loop_iterate(%p, %d)", r5kdev, timeout_usec);
  4890. + if(! r5kdev->streaming)
  4891. + return -1;
  4892. + len = usb_urb_reap(handle, urbs[r5kdev->nexturb], timeout_usec);
  4893. + if(len <= 0) {
  4894. + if(len != -ETIMEDOUT)
  4895. + r5000_print("(%d) Reap failed at %08x: %s\n", r5kdev->nexturb, r5kdev->bytes_read, strerror(errno));
  4896. + return len;
  4897. + }
  4898. + buf = r5kdev->buffer + (R5K_URB_BUFFER_SIZE*r5kdev->nexturb);
  4899. + #ifdef R5K_RAWUSB
  4900. + if(usbfd >= 0) write(usbfd, buf, len);
  4901. + #endif
  4902. + #ifdef R5K_DEBUG
  4903. + if(fd >= 0) {
  4904. + int newlen = read(fd, buf, len);
  4905. + if(newlen < len) {
  4906. + r5000_print("hit end of debug file\n");
  4907. + lseek(fd, 0, SEEK_SET);
  4908. + read(fd, buf + newlen, len - newlen);
  4909. + }
  4910. + }
  4911. + #endif
  4912. + r5kdev->process_block(r5kdev, (unsigned char *)buf, len);
  4913. + r5kdev->bytes_read += len;
  4914. + usb_urb_submit(handle, urbs[r5kdev->nexturb], NULL);
  4915. + r5kdev->nexturb = (r5kdev->nexturb + 1) % MAX_URBS_IN_FLIGHT;
  4916. + if(r5kdev->nexturb == 0) {
  4917. + *r5kdev->last_command_time = time(NULL);
  4918. + }
  4919. + return 0;
  4920. + }
  4921. +
  4922. + //use this to read a status frame. It doesn't do anything special
  4923. + //but makes it obvious what data is expected
  4924. + int r5000_clear_status(r5kdev_t *r5kdev, char *buf)
  4925. + {
  4926. + int i = 5;
  4927. + int ret;
  4928. +
  4929. + while (i--) {
  4930. + ret = usb_bulk_read(r5kdev->handle, 129, buf, 128, 5000);
  4931. + if (ret > 2 && (unsigned char)buf[0] == 0xcc && buf[1] == 0x00)
  4932. + return ret;
  4933. + buf[0] = 0xcc;
  4934. + buf[1] = 0x00;
  4935. + r5000_log(0, "r5000_clear_status overflow detected: %d %02x, %02x", ret, (unsigned int)buf[0], (unsigned int)buf[1]);
  4936. + usb_bulk_write(r5kdev->handle, 1, buf, 2, 5000);
  4937. + usleep(100000);
  4938. + }
  4939. + return ret;
  4940. + }
  4941. +
  4942. + #ifdef USE_OLD_POWER_CHECK
  4943. + int r5000_get_power_state(r5kdev_t *r5kdev)
  4944. + {
  4945. + unsigned char data1[1] = { 0x30 };
  4946. + unsigned char data2[0x80];
  4947. + int count = 10;
  4948. + while(count--) {
  4949. + usb_bulk_read(r5kdev->handle, 129, (char *)data2, 128, 5000);
  4950. + usb_bulk_write(r5kdev->handle, 1, (char *)data1, 1, 5000);
  4951. + usleep(100000);
  4952. + if(usb_bulk_read(r5kdev->handle, 1, (char *)data2, 2, 5000) == 2 &&
  4953. + data2[0] == 0x0a && (data2[1] & 0x4e) == 0x4c) {
  4954. + // The following boxes are known to be power active low:
  4955. + // 4DTV 922, Dish 622/722, Bell 9242, D*
  4956. + if(r5kdev->power_active_low)
  4957. + return (!(data2[1] == 0x4d));
  4958. + else
  4959. + return (!!(data2[1] == 0x4d));
  4960. + }
  4961. + usleep(100000);
  4962. + }
  4963. + r5000_print("R5000 failed to read power state. Assuming ON state\n");
  4964. + return 1;
  4965. + }
  4966. +
  4967. + #else
  4968. + int r5000_get_power_state(r5kdev_t *r5kdev)
  4969. + {
  4970. + unsigned char data2[0x80];
  4971. + int count = 10;
  4972. + int len;
  4973. +
  4974. + r5000_log(0, "r5000_get_power_state(%p)", r5kdev);
  4975. +
  4976. + while(count--) {
  4977. + data2[0] = 0x00;
  4978. + len = usb_bulk_read(r5kdev->handle, 129, (char *)data2, 128, 5000);
  4979. + //r5000_print("%d: %02x %02x %02x\n", len, data2[0], data2[1], data2[2]);
  4980. + usleep(100000);
  4981. + if (data2[0] == 0xcc) {
  4982. + // The following boxes are known to be power active low:
  4983. + // 4DTV 922, Dish 622/722, Bell 9242, D*
  4984. + if(r5kdev->power_active_low)
  4985. + return (!(data2[2] & 0x01));
  4986. + else
  4987. + return (!!(data2[2] & 0x01));
  4988. + }
  4989. + }
  4990. + r5000_print("R5000 failed to read power state. Assuming ON state\n");
  4991. + return 1;
  4992. + }
  4993. + #endif
  4994. +
  4995. + int r5000_send_pwr_cmd(r5kdev_t *r5kdev, char *data, int send_clear)
  4996. + {
  4997. + r5000_get_power_state(r5kdev);
  4998. + if (send_clear) {
  4999. + usb_bulk_write(r5kdev->handle, 1, r5kdev->button->clear,
  5000. + R5K_BUTTON_LEN(r5kdev, r5kdev->button->clear),
  5001. + 5000);
  5002. + usleep(r5kdev->button->delay);
  5003. + usleep(r5kdev->button->delay);
  5004. + }
  5005. + usb_bulk_write(r5kdev->handle, 1, data,
  5006. + R5K_BUTTON_LEN(r5kdev, data),
  5007. + 5000);
  5008. + usleep(r5kdev->button->delay);
  5009. + return 1;
  5010. + }
  5011. +
  5012. + int r5000_wait_pwr(r5kdev_t *r5kdev, int on_off)
  5013. + {
  5014. + int new_state, count = 20;
  5015. + while(count-- && (new_state = r5000_get_power_state(r5kdev)) != on_off)
  5016. + ;
  5017. + //r5000_print("End state: %s\n", !on_off ? "On" : "Off");
  5018. + return new_state;
  5019. + }
  5020. +
  5021. + int r5000_toggle_on_off(r5kdev_t *r5kdev)
  5022. + {
  5023. + unsigned on_off;
  5024. +
  5025. + r5000_log(0, "r5000_toggle_on_off(%p)", r5kdev);
  5026. +
  5027. + on_off = r5000_get_power_state(r5kdev);
  5028. + if(! r5kdev->button) {
  5029. + r5000_print("No button IR commands defined for this device!\n");
  5030. + return on_off;
  5031. + }
  5032. + //r5000_print("Start state: %s\n", on_off ? "On" : "Off");
  5033. + r5000_send_pwr_cmd(r5kdev, r5kdev->button->power, 1);
  5034. + on_off = r5000_wait_pwr(r5kdev, ! on_off);
  5035. + //r5000_print("End state: %s\n", on_off ? "On" : "Off");
  5036. + return on_off;
  5037. + }
  5038. +
  5039. + int r5000_power_on_off(r5kdev_t *r5kdev, int turn_on)
  5040. + {
  5041. + char *pwr_command;
  5042. + int on_off;
  5043. + int wait_time = 0;
  5044. +
  5045. + r5000_log(0, "r5000_power_on_off(%p, %d)", r5kdev, turn_on);
  5046. +
  5047. + on_off = r5000_get_power_state(r5kdev);
  5048. +
  5049. + if(! r5kdev->button) {
  5050. + r5000_print("No button IR commands defined for this device!\n");
  5051. + return on_off;
  5052. + }
  5053. +
  5054. + if(r5kdev->discrete_power) {
  5055. + //r5000_print("Using discrete power commands\n");
  5056. + if(turn_on) {
  5057. + pwr_command = r5kdev->button->power_on;
  5058. + } else {
  5059. + pwr_command = r5kdev->button->power_off;
  5060. + }
  5061. + } else {
  5062. + pwr_command = r5kdev->button->power;
  5063. + }
  5064. +
  5065. + if(r5kdev->unreliable_power_detect && on_off &&
  5066. + (time(NULL) - *r5kdev->last_command_time > R5K_UNRELIABLE_TIMEOUT)) {
  5067. + //The VIP211 can not be relied upon to be on when it says it is
  5068. + // But 'off' is trustworthy
  5069. + // We assume that if we've recorded or changed channel in the past 5 mins, that we can trust the state
  5070. + printf("Potential unreliable power state detected. Trying to ensure power state!\n");
  5071. + if(r5kdev->discrete_power) {
  5072. + wait_time = 2500000;
  5073. + } else {
  5074. + //We can't trustthe 'on' state, so toggle it off then back on to be sure
  5075. + r5000_send_pwr_cmd(r5kdev, pwr_command, turn_on != 2);
  5076. + r5000_wait_pwr(r5kdev, 0);
  5077. + }
  5078. + } else if(on_off == !!turn_on) {
  5079. + return on_off;
  5080. + }
  5081. +
  5082. + r5000_send_pwr_cmd(r5kdev, pwr_command, turn_on != 2);
  5083. + if(wait_time)
  5084. + usleep(wait_time);
  5085. + return r5000_wait_pwr(r5kdev, !!turn_on);
  5086. + }
  5087. +
  5088. + int r5000_change_channel(r5kdev_t *r5kdev, const char *chan, int mpeg_prog)
  5089. + {
  5090. + char data2[0x80];
  5091. + const char *ptr = NULL;
  5092. + const char *p;
  5093. + const char ignore[1] = {0xfe};
  5094. +
  5095. + r5000_log(0, "r5000_change_channel(%p, %s, %d)", r5kdev, chan, mpeg_prog);
  5096. + printf("Got channel change command: %s (%d)\n", chan, mpeg_prog);
  5097. +
  5098. + if(! r5kdev)
  5099. + return 0;
  5100. + if (chan) {
  5101. + if(! r5kdev->button) {
  5102. + r5000_print("No button IR commands defined for this device!\n");
  5103. + } else {
  5104. + r5000_clear_status(r5kdev, data2);
  5105. + if(r5kdev->button->clear[0] == 0x00) {
  5106. + usb_bulk_write(r5kdev->handle, 1, r5kdev->button->clear,
  5107. + R5K_BUTTON_LEN(r5kdev, r5kdev->button->clear),
  5108. + 5000);
  5109. + usleep(900000);
  5110. + }
  5111. + //usleep(r5kdev->button->delay);
  5112. + //usleep(r5kdev->button->delay);
  5113. + for(p = chan; *p; p++) {
  5114. + printf("Sending button '%c'\n", *p);
  5115. + ptr = NULL;
  5116. + switch(*p) {
  5117. + case '0' : ptr = r5kdev->button->b0; break;
  5118. + case '1' : ptr = r5kdev->button->b1; break;
  5119. + case '2' : ptr = r5kdev->button->b2; break;
  5120. + case '3' : ptr = r5kdev->button->b3; break;
  5121. + case '4' : ptr = r5kdev->button->b4; break;
  5122. + case '5' : ptr = r5kdev->button->b5; break;
  5123. + case '6' : ptr = r5kdev->button->b6; break;
  5124. + case '7' : ptr = r5kdev->button->b7; break;
  5125. + case '8' : ptr = r5kdev->button->b8; break;
  5126. + case '9' : ptr = r5kdev->button->b9; break;
  5127. + case 'P' : ptr = ignore; r5000_power_on_off(r5kdev, 2); break;
  5128. + }
  5129. + if(ptr && ptr[0] == 0x00) {
  5130. + //r5000_clear_status(r5kdev, data2);
  5131. + usb_bulk_write(r5kdev->handle, 1, ptr,
  5132. + R5K_BUTTON_LEN(r5kdev, ptr),
  5133. + 5000);
  5134. + } else if(ptr != ignore) {
  5135. + r5000_print("No button information found for %c\n", *p);
  5136. + }
  5137. + usleep(r5kdev->button->delay);
  5138. + }
  5139. + //r5000_clear_status(r5kdev, data2);
  5140. + if(r5kdev->button->enter[0] == 0x00) {
  5141. + usb_bulk_write(r5kdev->handle, 1, r5kdev->button->enter,
  5142. + R5K_BUTTON_LEN(r5kdev,r5kdev->button->enter),
  5143. + 5000);
  5144. + }
  5145. + }
  5146. + }
  5147. + r5kdev->channel = (mpeg_prog > 0xffff) ? -(mpeg_prog & 0xffff) : mpeg_prog;
  5148. + if(r5kdev->change_channel)
  5149. + r5kdev->change_channel(r5kdev);
  5150. + *r5kdev->last_command_time = time(NULL);
  5151. + return 1;
  5152. + }
  5153. +
  5154. + int r5000_find_stbs(r5kenum_t *devs)
  5155. + {
  5156. + r5000_log(0, "r5000_find_stbs(%p)", devs);
  5157. + devs->count = 0;
  5158. + if(! r5000_usb_init) {
  5159. + r5000_print("R5000 was not initialized before r5000_find_stbs(). Please call r5000_init() first\n");
  5160. + return 0;
  5161. + }
  5162. + devs->count = r5000_dev_map.count;
  5163. + memcpy(devs->serial, r5000_dev_map.serial, 8 * r5000_dev_map.count);
  5164. + return 1;
  5165. + }
  5166. +
  5167. + void r5000_get_fw_version(r5kdev_t *r5kdev, char *fwver)
  5168. + {
  5169. + char buf[128];
  5170. +
  5171. + r5000_clear_status(r5kdev, buf);
  5172. +
  5173. + buf[0]=0x20;
  5174. + buf[1]=0x00;
  5175. + usb_bulk_write(r5kdev->handle, 1, buf, 2, 5000);
  5176. + usleep(100000);
  5177. + usb_bulk_read(r5kdev->handle, 129, buf, 4, 5000);
  5178. + if ((unsigned char)buf[0] == 0xdd) {
  5179. + fwver[0] = buf[1];
  5180. + fwver[1] = buf[2];
  5181. + fwver[2] = buf[3];
  5182. + } else {
  5183. + fwver[0] = 'x';
  5184. + fwver[1] = '.';
  5185. + fwver[2] = 'x';
  5186. + }
  5187. + fwver[3] = 0;
  5188. + }
  5189. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5000.h.svn-base ./libs/libmythtv/r5000/.svn/text-base/r5000.h.svn-base
  5190. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5000.h.svn-base 1969-12-31 16:00:00.000000000 -0800
  5191. --- ./libs/libmythtv/r5000/.svn/text-base/r5000.h.svn-base 2011-04-08 19:29:47.000000000 -0700
  5192. ***************
  5193. *** 0 ****
  5194. --- 1,52 ----
  5195. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  5196. + *
  5197. + * This library is free software; you can redistribute it and/or
  5198. + * modify it under the terms of the GNU Lesser General Public
  5199. + * License as published by the Free Software Foundation; either
  5200. + * version 2.1 of the License, or (at your option) any later version.
  5201. + *
  5202. + * This library is distributed in the hope that it will be useful,
  5203. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5204. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5205. + * Lesser General Public License for more details.
  5206. + *
  5207. + * You should have received a copy of the GNU Lesser General Public
  5208. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  5209. + */
  5210. +
  5211. + #ifndef R5000_H
  5212. + #define R5000_H
  5213. +
  5214. + #ifndef r5kdev_t
  5215. + #define r5kdev_t void
  5216. + #endif
  5217. +
  5218. + #define R5K_MAX_DEVS 10
  5219. + typedef struct {
  5220. + unsigned char serial[R5K_MAX_DEVS][8];
  5221. + int count;
  5222. + } r5kenum_t;
  5223. +
  5224. + typedef enum {
  5225. + R5K_STB_VIP211 = 0,
  5226. + R5K_STB_DIRECTV,
  5227. + R5K_STB_HDD,
  5228. + R5K_STB_DSR,
  5229. + R5K_STB_VIP622,
  5230. + R5K_STB_DISH6000,
  5231. + R5K_STB_MAX,
  5232. + } r5ktype_t;
  5233. +
  5234. + extern int r5000_init(void (*_msgcb)(char *str));
  5235. + extern r5kdev_t *r5000_open(r5ktype_t type, unsigned int (*cb)(unsigned char *buffer, int len, void *callback_data), void *cb_data, const char *serial);
  5236. + extern int r5000_close(r5kdev_t *r5kdev);
  5237. + extern int r5000_start_stream(r5kdev_t *r5kdev);
  5238. + extern int r5000_stop_stream(r5kdev_t *r5kdev);
  5239. + extern int r5000_loop_iterate(r5kdev_t *r5kdev, int timeout_usec);
  5240. + extern int r5000_get_power_state(r5kdev_t *r5kdev);
  5241. + extern int r5000_toggle_on_off(r5kdev_t *r5kdev);
  5242. + extern int r5000_power_on_off(r5kdev_t *r5kdev, int turn_on);
  5243. + extern int r5000_change_channel(r5kdev_t *r5kdev, const char *chan, int mpeg_prog);
  5244. + extern int r5000_find_stbs(r5kenum_t *devs);
  5245. + extern void r5000_get_fw_version(r5kdev_t *r5kdev, char *fwver);
  5246. + #endif //R5000_H
  5247. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5000init.h.svn-base ./libs/libmythtv/r5000/.svn/text-base/r5000init.h.svn-base
  5248. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5000init.h.svn-base 1969-12-31 16:00:00.000000000 -0800
  5249. --- ./libs/libmythtv/r5000/.svn/text-base/r5000init.h.svn-base 2011-04-08 19:29:46.000000000 -0700
  5250. ***************
  5251. *** 0 ****
  5252. --- 1,79 ----
  5253. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  5254. + *
  5255. + * This library is free software; you can redistribute it and/or
  5256. + * modify it under the terms of the GNU Lesser General Public
  5257. + * License as published by the Free Software Foundation; either
  5258. + * version 2.1 of the License, or (at your option) any later version.
  5259. + *
  5260. + * This library is distributed in the hope that it will be useful,
  5261. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5262. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5263. + * Lesser General Public License for more details.
  5264. + *
  5265. + * You should have received a copy of the GNU Lesser General Public
  5266. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  5267. + */
  5268. +
  5269. + #ifndef R5000_INIT_H
  5270. + #define R5000_INIT_H
  5271. +
  5272. + #define R5K_INIT_MAX 9
  5273. + #define R5K_INIT_SERIAL 8
  5274. + #define R5K_DEFAULT_SLEEP 100000
  5275. + typedef struct {
  5276. + int rsleep;
  5277. + int rlen;
  5278. + int wsleep;
  5279. + int wlen;
  5280. + char data[0x40];
  5281. + } r5kinit_t;
  5282. +
  5283. + r5kinit_t r5kinit[R5K_INIT_MAX] = {
  5284. + // 0
  5285. + {R5K_DEFAULT_SLEEP, -1, 0, 64,
  5286. + {0x30}},
  5287. + // 1
  5288. + {R5K_DEFAULT_SLEEP, 1, 0, 64,
  5289. + {0x08, 0x00, 0x20, 0x00, 0x00, 0x3a, 0xd4, 0x29, 0x7c, 0x56, 0x31, 0x44, 0x86, 0x6d, 0x0d, 0x0d,
  5290. + 0x1b, 0x0a, 0xad, 0x0f, 0xd0, 0x2e, 0x94, 0x3f, 0xd4, 0x08, 0xa2, 0x4b, 0x68, 0x14, 0x1f, 0x13,
  5291. + 0x04, 0x62, 0x1b, 0x14, 0xb9, 0x69, 0xcc, 0x25, 0x91, 0x06, 0xc9, 0x26, 0xf9, 0x41, 0x64, 0x46,
  5292. + 0x7d, 0x17, 0x61, 0x09, 0x5c, 0x5b, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
  5293. + // 2
  5294. + {R5K_DEFAULT_SLEEP, 1, 0, 64,
  5295. + {0x08, 0x00, 0x5a, 0x00, 0x00, 0x06, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5296. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5297. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5298. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
  5299. + // 3
  5300. + {R5K_DEFAULT_SLEEP, 1, 0, 64,
  5301. + {0x08, 0x00, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5302. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5303. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5304. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
  5305. + // 4
  5306. + {R5K_DEFAULT_SLEEP, 1, R5K_DEFAULT_SLEEP, 64,
  5307. + {0x08, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5308. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5309. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5310. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
  5311. + // 5
  5312. + {R5K_DEFAULT_SLEEP, 26, 0, 6,
  5313. + {0x08, 0x01, 0x00, 0x00, 0x01, 0x14}},
  5314. + // 6
  5315. + {R5K_DEFAULT_SLEEP, 1, 0, 64,
  5316. + {0x08, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5317. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5318. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5319. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
  5320. + // 7
  5321. + {R5K_DEFAULT_SLEEP, 22, 0, 64,
  5322. + {0x08, 0x01, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5323. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5324. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5325. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
  5326. + // 8
  5327. + {R5K_DEFAULT_SLEEP, 4, 0, 1,
  5328. + {0x20}}
  5329. + };
  5330. +
  5331. + #endif
  5332. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5000_internal.h.svn-base ./libs/libmythtv/r5000/.svn/text-base/r5000_internal.h.svn-base
  5333. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5000_internal.h.svn-base 1969-12-31 16:00:00.000000000 -0800
  5334. --- ./libs/libmythtv/r5000/.svn/text-base/r5000_internal.h.svn-base 2011-04-08 19:29:47.000000000 -0700
  5335. ***************
  5336. *** 0 ****
  5337. --- 1,127 ----
  5338. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  5339. + *
  5340. + * This library is free software; you can redistribute it and/or
  5341. + * modify it under the terms of the GNU Lesser General Public
  5342. + * License as published by the Free Software Foundation; either
  5343. + * version 2.1 of the License, or (at your option) any later version.
  5344. + *
  5345. + * This library is distributed in the hope that it will be useful,
  5346. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5347. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5348. + * Lesser General Public License for more details.
  5349. + *
  5350. + * You should have received a copy of the GNU Lesser General Public
  5351. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  5352. + */
  5353. +
  5354. + #ifndef R5000_INT_H
  5355. + #define R5000_INT_H
  5356. +
  5357. + #include <usb.h>
  5358. + #include <linux/usbdevice_fs.h>
  5359. +
  5360. + #define PRINTHEX(str, data, len) if(1) do { \
  5361. + int _i; \
  5362. + fprintf(stderr, str); \
  5363. + for(_i = 0; _i < (len); _i++) { \
  5364. + fprintf(stderr, "%02x ", (unsigned char)(data)[_i]); \
  5365. + if((_i % 16) == 15) fprintf(stderr, "\n"); \
  5366. + } \
  5367. + if(_i % 16) fprintf(stderr, "\n"); \
  5368. + } while(0)
  5369. +
  5370. + #define R5K_MAX_BUTTON_SIZE 0xF8
  5371. + #define R5K_MAX_PIDS 10
  5372. + #define IS_VIDEO(x) ((x) == 0x02 || (x) == 0x1b || (x) == 0x80)
  5373. +
  5374. + struct r5k_descriptor {
  5375. + unsigned char d[10];
  5376. + };
  5377. +
  5378. + struct r5k_epid {
  5379. + int pid;
  5380. + unsigned char id;
  5381. + struct r5k_descriptor desc;
  5382. + };
  5383. +
  5384. + struct r5000_buttons {
  5385. + int len;
  5386. + int delay;
  5387. + char b0[R5K_MAX_BUTTON_SIZE];
  5388. + char b1[R5K_MAX_BUTTON_SIZE];
  5389. + char b2[R5K_MAX_BUTTON_SIZE];
  5390. + char b3[R5K_MAX_BUTTON_SIZE];
  5391. + char b4[R5K_MAX_BUTTON_SIZE];
  5392. + char b5[R5K_MAX_BUTTON_SIZE];
  5393. + char b6[R5K_MAX_BUTTON_SIZE];
  5394. + char b7[R5K_MAX_BUTTON_SIZE];
  5395. + char b8[R5K_MAX_BUTTON_SIZE];
  5396. + char b9[R5K_MAX_BUTTON_SIZE];
  5397. + char clear[R5K_MAX_BUTTON_SIZE];
  5398. + char enter[R5K_MAX_BUTTON_SIZE];
  5399. + char power[R5K_MAX_BUTTON_SIZE];
  5400. + char power_on[R5K_MAX_BUTTON_SIZE];
  5401. + char power_off[R5K_MAX_BUTTON_SIZE];
  5402. + char guide[R5K_MAX_BUTTON_SIZE];
  5403. + };
  5404. +
  5405. + struct r5kdev {
  5406. + usb_dev_handle *handle;
  5407. + unsigned char serial[8];
  5408. + void *urbblk;
  5409. + struct usbdevfs_urb **urbs;
  5410. + char *buffer;
  5411. + int stb_type;
  5412. + int read_words;
  5413. + void (*process_block)(struct r5kdev *r5kdev, unsigned char *buf, int len);
  5414. + void (*start_stream)(struct r5kdev *r5kdev);
  5415. + void (*change_channel)(struct r5kdev *r5kdev);
  5416. + void *stbdata;
  5417. + unsigned int (*cb)(unsigned char *buffer, int len, void *callback_data);
  5418. + void *cb_data;
  5419. + int nexturb;
  5420. + int streaming;
  5421. + int bytes_read;
  5422. + struct r5000_buttons *button;
  5423. + int power_active_low;
  5424. + int discrete_power;
  5425. + int unreliable_power_detect;
  5426. + int channel;
  5427. + time_t *last_command_time;
  5428. + unsigned char pmt_pkt[188];
  5429. + unsigned char num_pmt_entries;
  5430. + unsigned char pmt_state;
  5431. + unsigned char pmt_next_cc;
  5432. + unsigned char pmt_version;
  5433. + struct r5k_epid pmt[R5K_MAX_PIDS];
  5434. + } r5kdev_t;
  5435. + #define r5kdev_t struct r5kdev
  5436. +
  5437. + #include "r5000.h"
  5438. +
  5439. + extern void r5000_print(const char *fmt, ...);
  5440. + extern unsigned char r5000_pat_pkt[188];
  5441. + extern struct r5k_descriptor r5000_pmt_audio_desc;
  5442. + extern struct r5k_descriptor r5000_pmt_video_desc;
  5443. + extern struct r5k_descriptor r5000_pmt_nowplaying_desc;
  5444. + extern void r5000_reset_pmt(r5kdev_t *r5kdev);
  5445. + extern void r5000_send_pmt(r5kdev_t *r5kdev);
  5446. +
  5447. + //Support for DirecTV and Dish/BEV 6000 boxes
  5448. + extern void pes_init(r5kdev_t *r5kdev);
  5449. + extern void pes_free(r5kdev_t *r5kdev);
  5450. +
  5451. + //Support for ViP series Dish Network boxes
  5452. + extern void vip_init(r5kdev_t *r5kdev);
  5453. + extern void vip_free(r5kdev_t *r5kdev);
  5454. +
  5455. + //Support for HDD and DSR series satellite/cable boxes
  5456. + extern void sat_init(r5kdev_t *r5kdev);
  5457. + extern void sat_free(r5kdev_t *r5kdev);
  5458. +
  5459. + //Buttons
  5460. + extern struct r5000_buttons vip_button_cmd;
  5461. + extern struct r5000_buttons directv_button_cmd;
  5462. + extern struct r5000_buttons dish6000_button_cmd;
  5463. + extern struct r5000_buttons dsr_button_cmd;
  5464. + #endif
  5465. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_directv_buttons.c.svn-base ./libs/libmythtv/r5000/.svn/text-base/r5k_directv_buttons.c.svn-base
  5466. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_directv_buttons.c.svn-base 1969-12-31 16:00:00.000000000 -0800
  5467. --- ./libs/libmythtv/r5000/.svn/text-base/r5k_directv_buttons.c.svn-base 2011-04-08 19:29:47.000000000 -0700
  5468. ***************
  5469. *** 0 ****
  5470. --- 1,129 ----
  5471. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  5472. + *
  5473. + * This library is free software; you can redistribute it and/or
  5474. + * modify it under the terms of the GNU Lesser General Public
  5475. + * License as published by the Free Software Foundation; either
  5476. + * version 2.1 of the License, or (at your option) any later version.
  5477. + *
  5478. + * This library is distributed in the hope that it will be useful,
  5479. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5480. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5481. + * Lesser General Public License for more details.
  5482. + *
  5483. + * You should have received a copy of the GNU Lesser General Public
  5484. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  5485. + */
  5486. +
  5487. + //Support for DirectTV remotes
  5488. +
  5489. + #include "r5000_internal.h"
  5490. +
  5491. + struct r5000_buttons directv_button_cmd =
  5492. + {
  5493. + 0x49, //len
  5494. + 400000, //delay
  5495. + //button 0:
  5496. + {
  5497. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5498. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5499. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05,
  5500. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5501. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  5502. + },
  5503. + //button 1:
  5504. + {
  5505. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5506. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5507. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05,
  5508. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5509. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  5510. + },
  5511. + //button 2:
  5512. + {
  5513. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5514. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5515. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05,
  5516. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f,
  5517. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  5518. + },
  5519. + //button 3:
  5520. + {
  5521. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5522. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5523. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05,
  5524. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f,
  5525. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  5526. + },
  5527. + //button 4:
  5528. + {
  5529. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5530. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5531. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f,
  5532. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05,
  5533. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  5534. + },
  5535. + //button 5:
  5536. + {
  5537. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5538. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5539. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f,
  5540. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05,
  5541. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  5542. + },
  5543. + //button 6:
  5544. + {
  5545. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5546. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5547. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5548. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05,
  5549. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  5550. + },
  5551. + //button 7:
  5552. + {
  5553. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5554. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5555. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5556. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05,
  5557. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  5558. + },
  5559. + //button 8:
  5560. + {
  5561. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5562. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5563. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5564. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05,
  5565. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  5566. + },
  5567. + //button 9:
  5568. + {
  5569. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5570. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5571. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5572. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05,
  5573. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  5574. + },
  5575. + //Clear:
  5576. + {
  5577. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5578. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5579. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f,
  5580. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
  5581. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  5582. + },
  5583. + //Enter:
  5584. + {
  5585. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5586. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5587. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f,
  5588. + 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05,
  5589. + 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  5590. + },
  5591. + //Power
  5592. + {
  5593. + 0x00, 0x43, 0x0a, 0x80, 0xca, 0x00, 0x5a, 0x2d, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f,
  5594. + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5595. + 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05,
  5596. + 0x05, 0x0f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0f, 0x05, 0x05, 0x05, 0x0f,
  5597. + 0x05, 0x05, 0x05, 0x0f, 0x05, 0x0f, 0x05, 0x0f, 0x05,
  5598. + },
  5599. + };
  5600. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_dish6000_buttons.c.svn-base ./libs/libmythtv/r5000/.svn/text-base/r5k_dish6000_buttons.c.svn-base
  5601. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_dish6000_buttons.c.svn-base 1969-12-31 16:00:00.000000000 -0800
  5602. --- ./libs/libmythtv/r5000/.svn/text-base/r5k_dish6000_buttons.c.svn-base 2011-04-08 19:29:47.000000000 -0700
  5603. ***************
  5604. *** 0 ****
  5605. --- 1,190 ----
  5606. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  5607. + *
  5608. + * This library is free software; you can redistribute it and/or
  5609. + * modify it under the terms of the GNU Lesser General Public
  5610. + * License as published by the Free Software Foundation; either
  5611. + * version 2.1 of the License, or (at your option) any later version.
  5612. + *
  5613. + * This library is distributed in the hope that it will be useful,
  5614. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5615. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5616. + * Lesser General Public License for more details.
  5617. + *
  5618. + * You should have received a copy of the GNU Lesser General Public
  5619. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  5620. + */
  5621. +
  5622. + //Support for Dish/BEV 6000 remotes
  5623. +
  5624. + #include "r5000_internal.h"
  5625. +
  5626. + struct r5000_buttons dish6000_button_cmd =
  5627. + {
  5628. + 0x79, //len
  5629. + 800000, //delay
  5630. + //button 0:
  5631. + {
  5632. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  5633. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5634. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  5635. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5636. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  5637. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5638. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  5639. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04,
  5640. + },
  5641. + //button 1:
  5642. + {
  5643. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5644. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5645. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5646. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5647. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5648. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5649. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5650. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  5651. + },
  5652. + //button 2:
  5653. + {
  5654. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5655. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5656. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5657. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5658. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5659. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5660. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5661. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04,
  5662. + },
  5663. + //button 3:
  5664. + {
  5665. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5666. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5667. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5668. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5669. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5670. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5671. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5672. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  5673. + },
  5674. + //button 4:
  5675. + {
  5676. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  5677. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5678. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5679. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5680. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  5681. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5682. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5683. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  5684. + },
  5685. + //button 5:
  5686. + {
  5687. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  5688. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5689. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5690. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5691. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  5692. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5693. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5694. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04,
  5695. + },
  5696. + //button 6:
  5697. + {
  5698. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  5699. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5700. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5701. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5702. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  5703. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5704. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5705. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  5706. + },
  5707. + //button 7:
  5708. + {
  5709. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  5710. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5711. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5712. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5713. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  5714. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5715. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5716. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  5717. + },
  5718. + //button 8:
  5719. + {
  5720. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  5721. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5722. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5723. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5724. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  5725. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5726. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5727. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04,
  5728. + },
  5729. + //button 9:
  5730. + {
  5731. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  5732. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5733. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5734. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5735. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  5736. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5737. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5738. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  5739. + },
  5740. + //Clear:
  5741. + {
  5742. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  5743. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5744. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  5745. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5746. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  5747. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5748. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  5749. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  5750. + },
  5751. + //Enter:
  5752. + {
  5753. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  5754. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5755. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  5756. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5757. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  5758. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5759. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  5760. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  5761. + },
  5762. + //Power
  5763. + {
  5764. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5765. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5766. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5767. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5768. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5769. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5770. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5771. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  5772. + },
  5773. + //Power-On
  5774. + {
  5775. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5776. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5777. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5778. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5779. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5780. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5781. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5782. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04,
  5783. + },
  5784. + //Power-Off
  5785. + {
  5786. + 0x00, 0x67, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5787. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5788. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  5789. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5790. + 0x00, 0x39, 0x0a, 0x80, 0x00, 0x77, 0x04, 0x3a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  5791. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  5792. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  5793. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04,
  5794. + },
  5795. + };
  5796. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_dsr_buttons.c.svn-base ./libs/libmythtv/r5000/.svn/text-base/r5k_dsr_buttons.c.svn-base
  5797. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_dsr_buttons.c.svn-base 1969-12-31 16:00:00.000000000 -0800
  5798. --- ./libs/libmythtv/r5000/.svn/text-base/r5k_dsr_buttons.c.svn-base 2011-04-08 19:29:47.000000000 -0700
  5799. ***************
  5800. *** 0 ****
  5801. --- 1,105 ----
  5802. + /* Copyright 2010 Alan Nisota <alannisota@gmail.com>
  5803. + *
  5804. + * This library is free software; you can redistribute it and/or
  5805. + * modify it under the terms of the GNU Lesser General Public
  5806. + * License as published by the Free Software Foundation; either
  5807. + * version 2.1 of the License, or (at your option) any later version.
  5808. + *
  5809. + * This library is distributed in the hope that it will be useful,
  5810. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5811. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5812. + * Lesser General Public License for more details.
  5813. + *
  5814. + * You should have received a copy of the GNU Lesser General Public
  5815. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  5816. + */
  5817. + //Support for DSR remotes
  5818. +
  5819. + #include "r5000_internal.h"
  5820. +
  5821. + struct r5000_buttons dsr_button_cmd =
  5822. + {
  5823. + 0x00, //len
  5824. + 400000, //delay
  5825. +
  5826. + //button 0:
  5827. + {
  5828. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09,
  5829. + 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x09,
  5830. + 0x09
  5831. + },
  5832. + //button 1:
  5833. + {
  5834. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x1b,
  5835. + 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09,
  5836. + 0x09
  5837. + },
  5838. + //button 2:
  5839. + {
  5840. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
  5841. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x09,
  5842. + 0x09
  5843. + },
  5844. + //button 3:
  5845. + {
  5846. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09,
  5847. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09,
  5848. + 0x09
  5849. + },
  5850. + //button 4:
  5851. + {
  5852. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x09,
  5853. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b,
  5854. + 0x09
  5855. + },
  5856. + //button 5:
  5857. + {
  5858. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b,
  5859. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b,
  5860. + 0x09
  5861. + },
  5862. + //button 6:
  5863. + {
  5864. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x1b,
  5865. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x1b,
  5866. + 0x09
  5867. + },
  5868. + //button 7:
  5869. + {
  5870. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x1b,
  5871. + 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b,
  5872. + 0x09
  5873. + },
  5874. + //button 8:
  5875. + {
  5876. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b,
  5877. + 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b,
  5878. + 0x09
  5879. + },
  5880. + //button 9:
  5881. + {
  5882. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b, 0x09, 0x1b,
  5883. + 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
  5884. + 0x09
  5885. + },
  5886. + //Clear:
  5887. + {
  5888. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b,
  5889. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09,
  5890. + 0x09
  5891. + },
  5892. + //Enter:
  5893. + {
  5894. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b,
  5895. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09,
  5896. + 0x09
  5897. + },
  5898. + //Power
  5899. + {
  5900. + 0x00, 0x1b, 0x0a, 0x80, 0xcb, 0x00, 0x2d, 0x12, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x1b,
  5901. + 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1b, 0x09, 0x09, 0x09, 0x09,
  5902. + 0x09
  5903. + }
  5904. + };
  5905. +
  5906. +
  5907. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_misc.c.svn-base ./libs/libmythtv/r5000/.svn/text-base/r5k_misc.c.svn-base
  5908. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_misc.c.svn-base 1969-12-31 16:00:00.000000000 -0800
  5909. --- ./libs/libmythtv/r5000/.svn/text-base/r5k_misc.c.svn-base 2011-04-08 19:29:47.000000000 -0700
  5910. ***************
  5911. *** 0 ****
  5912. --- 1,158 ----
  5913. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  5914. + *
  5915. + * This library is free software; you can redistribute it and/or
  5916. + * modify it under the terms of the GNU Lesser General Public
  5917. + * License as published by the Free Software Foundation; either
  5918. + * version 2.1 of the License, or (at your option) any later version.
  5919. + *
  5920. + * This library is distributed in the hope that it will be useful,
  5921. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5922. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5923. + * Lesser General Public License for more details.
  5924. + *
  5925. + * You should have received a copy of the GNU Lesser General Public
  5926. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  5927. + */
  5928. +
  5929. + #include <stdio.h>
  5930. + #include <string.h>
  5931. + #include "r5000_internal.h"
  5932. +
  5933. + unsigned char r5000_pat_pkt[188] = {
  5934. + 0x47, 0x40, 0x00, 0x13, 0x00, 0x00, 0xb0, 0x0d, 0x00, 0x06, 0xc5, 0x00, 0x00, 0x00, 0x01, 0xe0,
  5935. + 0x21, 0x19, 0x3a, 0x82, 0xc4, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  5936. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  5937. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  5938. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  5939. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  5940. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  5941. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  5942. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  5943. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  5944. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  5945. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  5946. +
  5947. +
  5948. + struct r5k_descriptor r5000_pmt_audio_desc = {{0x06, 0x0a, 0x04, 0x65, 0x6e, 0x67, 0x00}};
  5949. + struct r5k_descriptor r5000_pmt_video_desc = {{0x00}};
  5950. + struct r5k_descriptor r5000_pmt_nowplaying_desc = {{0x00}};
  5951. +
  5952. + //taken and adapted from libdtv, (c) Rolf Hakenes
  5953. + // CRC32 lookup table for polynomial 0x04c11db7
  5954. + static unsigned int crc_table[256] = {
  5955. + 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
  5956. + 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
  5957. + 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,
  5958. + 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
  5959. + 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3,
  5960. + 0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
  5961. + 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef,
  5962. + 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
  5963. + 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb,
  5964. + 0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
  5965. + 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
  5966. + 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
  5967. + 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4,
  5968. + 0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
  5969. + 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08,
  5970. + 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
  5971. + 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc,
  5972. + 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
  5973. + 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050,
  5974. + 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
  5975. + 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
  5976. + 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
  5977. + 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1,
  5978. + 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
  5979. + 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5,
  5980. + 0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
  5981. + 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9,
  5982. + 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
  5983. + 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd,
  5984. + 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
  5985. + 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
  5986. + 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
  5987. + 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2,
  5988. + 0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
  5989. + 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e,
  5990. + 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
  5991. + 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a,
  5992. + 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
  5993. + 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676,
  5994. + 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
  5995. + 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
  5996. + 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
  5997. + 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4};
  5998. +
  5999. + static void r5000_calc_crc(unsigned char *out, const unsigned char *d, int len)
  6000. + {
  6001. + register int i;
  6002. + unsigned int crc = 0xFFFFFFFF;
  6003. + const unsigned char *u=(const unsigned char*)d; // Saves '& 0xff'
  6004. +
  6005. + for (i=0; i<len; i++)
  6006. + crc = (crc << 8) ^ crc_table[((crc >> 24) ^ *u++)];
  6007. +
  6008. + *out++ = (crc >> 24) & 0xff;
  6009. + *out++ = (crc >> 16) & 0xff;
  6010. + *out++ = (crc >> 8) & 0xff;
  6011. + *out++ = (crc >> 0) & 0xff;
  6012. + }
  6013. +
  6014. + static void r5000_build_pmt(r5kdev_t *r5kdev)
  6015. + {
  6016. + int i;
  6017. + unsigned char *ptr;
  6018. + unsigned char ts[188] = {
  6019. + 0x47, 0x40, 0x21, 0x10,
  6020. + 0x00, 0x02,
  6021. + 0xb0, 0x00, //length
  6022. + 0x00, 0x01,
  6023. + 0xc1, //version<<1 (5 bits) | current_next
  6024. + 0x00, 0x00, //section/last_section
  6025. + 0xf0, 0x00, //PCR_PID
  6026. + 0xf0, 0x00}; //Program Info Length
  6027. +
  6028. + ts[3] = 0x10 | r5kdev->pmt_next_cc;
  6029. +
  6030. + //Change the PMT version every time we rebuild the PMT
  6031. + ts[10] |= r5kdev->pmt_version << 1;
  6032. + r5kdev->pmt_version = (r5kdev->pmt_version + 1) % 32;
  6033. +
  6034. + r5000_print("Building PMT\n");
  6035. + ptr = ts + 17;
  6036. + for(i = 0; i < r5kdev->num_pmt_entries; i++) {
  6037. + *ptr++ = r5kdev->pmt[i].id;
  6038. + *ptr++ = 0xe0 | (r5kdev->pmt[i].pid>>8);
  6039. + *ptr++ = r5kdev->pmt[i].pid & 0xff;
  6040. + *ptr++ = 0xf0;
  6041. + memcpy(ptr, r5kdev->pmt[i].desc.d, r5kdev->pmt[i].desc.d[0]+1);
  6042. + ptr += r5kdev->pmt[i].desc.d[0]+1;
  6043. + if(IS_VIDEO(r5kdev->pmt[i].id)) {
  6044. + ts[13] = 0xe0 | (r5kdev->pmt[i].pid >> 8);
  6045. + ts[14] = r5kdev->pmt[i].pid & 0xff;
  6046. + }
  6047. + }
  6048. + ts[7] = (ptr - ts) - 8/*header*/ + 4/*CRC*/;
  6049. + r5000_calc_crc(ptr, ts + 5, (ptr - ts) - 5);
  6050. + memset(ptr+4, 0xff, 188 - (ptr + 4 - ts));
  6051. + memcpy(r5kdev->pmt_pkt, ts, 188);
  6052. + //PRINTHEX("PMT", r5kdev->pmt_pkt, 188);
  6053. + }
  6054. +
  6055. + void r5000_reset_pmt(r5kdev_t *r5kdev)
  6056. + {
  6057. + r5kdev->num_pmt_entries = 0;
  6058. + r5kdev->pmt_state = 0;
  6059. + r5kdev->pmt_pkt[0] = 0;
  6060. + }
  6061. +
  6062. + void r5000_send_pmt(r5kdev_t *r5kdev)
  6063. + {
  6064. + if(r5kdev->pmt_pkt[0] != 0x47) {
  6065. + r5000_build_pmt(r5kdev);
  6066. + }
  6067. + r5kdev->pmt_pkt[3] = 0x10 | r5kdev->pmt_next_cc;
  6068. + r5kdev->pmt_next_cc = (r5kdev->pmt_next_cc + 1) & 0x0f;
  6069. + r5kdev->cb(r5kdev->pmt_pkt, 188, r5kdev->cb_data);
  6070. + }
  6071. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_pes.c.svn-base ./libs/libmythtv/r5000/.svn/text-base/r5k_pes.c.svn-base
  6072. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_pes.c.svn-base 1969-12-31 16:00:00.000000000 -0800
  6073. --- ./libs/libmythtv/r5000/.svn/text-base/r5k_pes.c.svn-base 2011-04-08 19:29:47.000000000 -0700
  6074. ***************
  6075. *** 0 ****
  6076. --- 1,316 ----
  6077. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  6078. + *
  6079. + * This library is free software; you can redistribute it and/or
  6080. + * modify it under the terms of the GNU Lesser General Public
  6081. + * License as published by the Free Software Foundation; either
  6082. + * version 2.1 of the License, or (at your option) any later version.
  6083. + *
  6084. + * This library is distributed in the hope that it will be useful,
  6085. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6086. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6087. + * Lesser General Public License for more details.
  6088. + *
  6089. + * You should have received a copy of the GNU Lesser General Public
  6090. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  6091. + */
  6092. +
  6093. + //Support for DirecTV boxes
  6094. + #include <netinet/in.h>
  6095. + #include <string.h>
  6096. +
  6097. + #include "r5000_internal.h"
  6098. +
  6099. + #define DTV_VPID 0x1322
  6100. + #define DTV_APID 0x1333
  6101. + #define DTV_PAT_PMT_COUNT 5000
  6102. +
  6103. + struct r5000_dtv {
  6104. + unsigned char vbuf[188*2+4];
  6105. + unsigned char abuf[188*2+6];
  6106. + unsigned char *video;
  6107. + unsigned char *audio;
  6108. + unsigned int vpos;
  6109. + unsigned int apos;
  6110. + unsigned int vstart;
  6111. + unsigned int astart;
  6112. + unsigned int video_cc;
  6113. + unsigned int audio_cc;
  6114. + unsigned int vstate;
  6115. + unsigned int pic_pos;
  6116. + int alen;
  6117. + unsigned int pat_pmt_count;
  6118. + };
  6119. +
  6120. + //The following are used to convert DirectTV into TS format
  6121. + static int directv_make_empty_pes(unsigned char *ptr, unsigned char type)
  6122. + {
  6123. + ptr[0] = 0x00;
  6124. + ptr[1] = 0x00;
  6125. + ptr[2] = 0x01;
  6126. + ptr[3] = type;
  6127. + ptr[4] = 0x00;
  6128. + ptr[5] = 0x00;
  6129. + ptr[6] = 0x80;
  6130. + ptr[7] = 0x00; //2 MSB represent PTS/DTS flag
  6131. + ptr[8] = 0x0a;
  6132. + ptr[9] = 0xff;
  6133. + ptr[10] = 0xff;
  6134. + ptr[11] = 0xff;
  6135. + ptr[12] = 0xff;
  6136. + ptr[13] = 0xff;
  6137. + ptr[14] = 0xff;
  6138. + ptr[15] = 0xff;
  6139. + ptr[16] = 0xff;
  6140. + ptr[17] = 0xff;
  6141. + ptr[18] = 0xff;
  6142. + return 19;
  6143. + }
  6144. +
  6145. + static void directv_make_pespts(unsigned char *outptr, unsigned int pts)
  6146. + {
  6147. + pts = htonl(pts);
  6148. + unsigned char *inpts = (unsigned char *)&pts;
  6149. + outptr[0] = 0x01 |
  6150. + ((inpts[0] & 0xC0) >>5);
  6151. + outptr[1] = ((inpts[0] & 0x3F) << 2) |
  6152. + ((inpts[1] & 0xC0) >> 6);
  6153. + outptr[2] = 0x01 | ((inpts[1] & 0x3F) << 2) |
  6154. + ((inpts[2] & 0x80) >> 6);
  6155. + outptr[3] = ((inpts[2] & 0x7F) << 1) |
  6156. + ((inpts[3] & 0x80) >> 7);
  6157. + outptr[4] = 0x01 | ((inpts[3] & 0x7F) << 1);
  6158. + }
  6159. +
  6160. + static void directv_update_video_pes(unsigned char *ptr, int pos)
  6161. + {
  6162. + //pos points at the 1st char after a pic start code
  6163. + int picture_coding_type;
  6164. + int hdr_len;
  6165. + unsigned int pts1, dts1;
  6166. + unsigned char *buf = ptr + pos;
  6167. + picture_coding_type = (buf[1] >> 3) & 0x07;
  6168. + hdr_len = (picture_coding_type > 1) ? 5 : 4;
  6169. + if(buf[hdr_len + 3] == 0xb5)
  6170. + hdr_len += 9;
  6171. + if(buf[hdr_len + 3] == 0xb2) {
  6172. + pts1 = ((buf[hdr_len+6] & 0x03) << 30) +
  6173. + ((buf[hdr_len+7] & 0x7f) << 23) +
  6174. + ((buf[hdr_len+8]) << 15) +
  6175. + ((buf[hdr_len+9] & 0x7f) << 8) +
  6176. + buf[hdr_len+10];
  6177. + dts1 = ((buf[hdr_len+13] & 0x03) << 30) +
  6178. + ((buf[hdr_len+14] & 0x7f) << 23) +
  6179. + ((buf[hdr_len+15]) << 15) +
  6180. + ((buf[hdr_len+16] & 0x7f) << 8) +
  6181. + buf[hdr_len+17];
  6182. + //NOTE: This is wrong. DSS timestamps only have a resolution of 2^32/300
  6183. + //r5000_print("pts: %08x/%f dts: %08x/%f\n", pts1, pts1 / 27000000.0, dts1, dts1 / 27000000.0);
  6184. + ptr[7] |= 0xc0;
  6185. + directv_make_pespts(ptr+9, pts1/300);
  6186. + ptr[9] |= 0x30;
  6187. + directv_make_pespts(ptr+14, dts1/300);
  6188. + ptr[14] |= 0x10;
  6189. + }
  6190. + }
  6191. +
  6192. + static void directv_fix_audio_pts(unsigned char *ptr)
  6193. + {
  6194. + unsigned int pts = ((ptr[0] & 0x06) << 29) +
  6195. + (ptr[1] << 22) +
  6196. + ((ptr[2] & 0xfe) << 14) +
  6197. + (ptr[3] << 7) +
  6198. + (ptr[4] >> 1);
  6199. + directv_make_pespts(ptr, pts/300);
  6200. + ptr[0] |= 0x20;
  6201. + }
  6202. +
  6203. +
  6204. + static void pes_write_ts(r5kdev_t *r5kdev, unsigned char *ptr, int len, int pid, int start, unsigned int *cc)
  6205. + {
  6206. + int stuff = 184 - len;
  6207. + //Note: we know that there are 188 bytes allocated before 'ptr'
  6208. + // that we can use for the header
  6209. + if(stuff > 0) {
  6210. + int stuff1 = stuff;
  6211. + while(stuff1 > 2) {
  6212. + *--ptr = 0xff;
  6213. + stuff1--;
  6214. + }
  6215. + if(stuff1 == 2) {
  6216. + *--ptr = 0x00;
  6217. + }
  6218. + *--ptr = stuff - 1;
  6219. + *--ptr = 0x30 | *cc;
  6220. + } else {
  6221. + *--ptr = 0x10 | *cc;
  6222. + }
  6223. + *--ptr = pid & 0xff;
  6224. + *--ptr = (start << 6) | (pid >> 8);
  6225. + *--ptr = 0x47;
  6226. + r5kdev->cb(ptr, 188, r5kdev->cb_data);
  6227. + *cc = (*cc+1) & 0x0f;
  6228. + }
  6229. +
  6230. + static void pes_process_block(r5kdev_t *r5kdev, unsigned char *buf, int len)
  6231. + {
  6232. + int i;
  6233. + struct r5000_dtv *dtv = (struct r5000_dtv *)r5kdev->stbdata;
  6234. + for(i = 0; i < len; i+=2) {
  6235. + unsigned char data = buf[i];
  6236. + unsigned char type = buf[i+1];
  6237. + if(0xff == type) {
  6238. + //video
  6239. + dtv->video[dtv->vpos++] = data;
  6240. + if(dtv->vpos > 4 && dtv->video[dtv->vpos-2] == 0x01 &&
  6241. + dtv->video[dtv->vpos-3] == 0x00 && dtv->video[dtv->vpos-4] == 0x00) {
  6242. + if (data == 0xe0) {
  6243. + //HD video header (PES)
  6244. + pes_write_ts(r5kdev, dtv->video, dtv->vpos - 4, DTV_VPID, dtv->vstart, &dtv->video_cc);
  6245. + dtv->pat_pmt_count++;
  6246. + dtv->video[0] = 0x00;
  6247. + dtv->video[1] = 0x00;
  6248. + dtv->video[2] = 0x01;
  6249. + dtv->video[3] = 0xe0;
  6250. + dtv->vpos = 4;
  6251. + dtv->vstart = 1;
  6252. + dtv->vstate = data;
  6253. + } else if (r5kdev->stb_type == R5K_STB_DIRECTV &&
  6254. + (data == 0xb3 || data == 0x00)) {
  6255. + if (dtv->vstate == 0xff) {
  6256. + dtv->vstate = data;
  6257. + pes_write_ts(r5kdev, dtv->video, dtv->vpos - 4, DTV_VPID, dtv->vstart, &dtv->video_cc);
  6258. + dtv->pat_pmt_count++;
  6259. + //Create a PES header, but no PTS/DTS info yet so just use stuffing bytes
  6260. + dtv->vpos = directv_make_empty_pes(dtv->video, 0xe0);
  6261. + dtv->video[dtv->vpos++] = 0x00;
  6262. + dtv->video[dtv->vpos++] = 0x00;
  6263. + dtv->video[dtv->vpos++] = 0x01;
  6264. + dtv->video[dtv->vpos++] = data;
  6265. + dtv->vstart = 1;
  6266. + dtv->pic_pos = dtv->vpos;
  6267. + }
  6268. + }
  6269. + }
  6270. + if(dtv->vpos == 188) {
  6271. + if (dtv->vstate == 0x00)
  6272. + //We found pic frame without a PES header (SD)
  6273. + directv_update_video_pes(dtv->video, dtv->pic_pos);
  6274. + pes_write_ts(r5kdev, dtv->video, 184, DTV_VPID, dtv->vstart, &dtv->video_cc);
  6275. + dtv->pat_pmt_count++;
  6276. + dtv->video[0] = dtv->video[184];
  6277. + dtv->video[1] = dtv->video[185];
  6278. + dtv->video[2] = dtv->video[186];
  6279. + dtv->video[3] = dtv->video[187];
  6280. + dtv->vpos = 4;
  6281. + dtv->vstart = 0;
  6282. + dtv->vstate = 0xff;
  6283. + }
  6284. + } else if(0xfe == type) {
  6285. + //audio
  6286. + dtv->audio[dtv->apos++] = data;
  6287. + dtv->alen--;
  6288. + if(dtv->alen <= 0 && dtv->apos > 6 && dtv->audio[dtv->apos-3] == 0xbd && dtv->audio[dtv->apos-4] == 0x01 &&
  6289. + dtv->audio[dtv->apos-5] == 0x00 && dtv->audio[dtv->apos-6] == 0x00) {
  6290. + dtv->alen = (dtv->audio[dtv->apos-2] << 8) + data;
  6291. + pes_write_ts(r5kdev, dtv->audio, dtv->apos - 6, DTV_APID, dtv->astart, &dtv->audio_cc);
  6292. + dtv->pat_pmt_count++;
  6293. + dtv->audio[0] = 0x00;
  6294. + dtv->audio[1] = 0x00;
  6295. + dtv->audio[2] = 0x01;
  6296. + dtv->audio[3] = 0xbd;
  6297. + dtv->audio[4] = dtv->audio[dtv->apos-2];
  6298. + dtv->audio[5] = data;
  6299. + dtv->apos = 6;
  6300. + dtv->astart = 1;
  6301. + r5kdev->pmt[1].id = 0x81; //AC3
  6302. + } else if(dtv->alen <= 0 && dtv->apos > 6 && dtv->audio[dtv->apos-3] == 0xc0 && dtv->audio[dtv->apos-4] == 0x01 &&
  6303. + dtv->audio[dtv->apos-5] == 0x00 && dtv->audio[dtv->apos-6] == 0x00) {
  6304. + dtv->alen = (dtv->audio[dtv->apos-2] << 8) + data;
  6305. + pes_write_ts(r5kdev, dtv->audio, dtv->apos - 6, DTV_APID, dtv->astart, &dtv->audio_cc);
  6306. + dtv->pat_pmt_count++;
  6307. + dtv->audio[0] = 0x00;
  6308. + dtv->audio[1] = 0x00;
  6309. + dtv->audio[2] = 0x01;
  6310. + dtv->audio[3] = 0xc0;
  6311. + if (r5kdev->stb_type == R5K_STB_DIRECTV) {
  6312. + dtv->audio[4] = (dtv->alen + 3) >> 8;
  6313. + dtv->audio[5] = (dtv->alen + 3) & 0xff;
  6314. + dtv->audio[6] = 0x80;
  6315. + dtv->audio[7] = 0x80;
  6316. + dtv->audio[8] = 0x05;
  6317. + dtv->apos = 9;
  6318. + } else {
  6319. + dtv->audio[4] = dtv->audio[dtv->apos-2];
  6320. + dtv->audio[5] = data;
  6321. + dtv->apos = 6;
  6322. + }
  6323. + dtv->astart = 1;
  6324. + r5kdev->pmt[1].id = 0x04; //MP2
  6325. + } else if(dtv->apos == 190) {
  6326. + if(dtv->astart && dtv->audio[3] == 0xc0 && r5kdev->stb_type == R5K_STB_DIRECTV)
  6327. + directv_fix_audio_pts(dtv->audio+9);
  6328. + pes_write_ts(r5kdev, dtv->audio, 184, DTV_APID, dtv->astart, &dtv->audio_cc);
  6329. + dtv->pat_pmt_count++;
  6330. + dtv->audio[0] = dtv->audio[184];
  6331. + dtv->audio[1] = dtv->audio[185];
  6332. + dtv->audio[2] = dtv->audio[186];
  6333. + dtv->audio[3] = dtv->audio[187];
  6334. + dtv->audio[4] = dtv->audio[188];
  6335. + dtv->audio[5] = dtv->audio[189];
  6336. + dtv->apos = 6;
  6337. + dtv->astart = 0;
  6338. + }
  6339. + }
  6340. + }
  6341. + if(r5kdev->pmt[1].id && dtv->pat_pmt_count > DTV_PAT_PMT_COUNT) {
  6342. + r5kdev->cb(r5000_pat_pkt, 188, r5kdev->cb_data);
  6343. + r5000_send_pmt(r5kdev);
  6344. + dtv->pat_pmt_count = 0;
  6345. + }
  6346. + }
  6347. +
  6348. + static void pes_start_stream(r5kdev_t *r5kdev)
  6349. + {
  6350. + struct r5000_dtv *dtv = (struct r5000_dtv *)r5kdev->stbdata;
  6351. + dtv->vstart = 0;
  6352. + dtv->astart = 0;
  6353. + dtv->vpos = 0;
  6354. + dtv->apos = 0;
  6355. + dtv->video_cc = 0;
  6356. + dtv->audio_cc = 0;
  6357. + dtv->vstate = 0xff;
  6358. + dtv->pat_pmt_count = DTV_PAT_PMT_COUNT;
  6359. + }
  6360. +
  6361. + void pes_init(r5kdev_t *r5kdev)
  6362. + {
  6363. + struct r5000_dtv *dtv = (struct r5000_dtv *)calloc(1, sizeof(struct r5000_dtv));
  6364. + dtv->video = dtv->vbuf + 188;
  6365. + dtv->audio = dtv->abuf + 188;
  6366. + dtv->pat_pmt_count = DTV_PAT_PMT_COUNT;
  6367. + dtv->vstate = 0xff;
  6368. + r5kdev->stbdata = dtv;
  6369. + r5kdev->pmt[0].id = 0x02; //MPEG2
  6370. + r5kdev->pmt[0].pid = DTV_VPID;
  6371. + r5kdev->pmt[0].desc = r5000_pmt_video_desc;
  6372. + r5kdev->pmt[1].id = 0x00;
  6373. + r5kdev->pmt[1].pid = DTV_APID;
  6374. + r5kdev->pmt[1].desc = r5000_pmt_audio_desc;
  6375. + r5kdev->num_pmt_entries = 2;
  6376. + r5kdev->process_block = pes_process_block;
  6377. + r5kdev->start_stream = pes_start_stream;
  6378. + if(r5kdev->stb_type == R5K_STB_DIRECTV) {
  6379. + r5kdev->button = &directv_button_cmd;
  6380. + r5kdev->power_active_low = 1;
  6381. + } else {
  6382. + r5kdev->button = &dish6000_button_cmd;
  6383. + r5kdev->power_active_low = 0;
  6384. + r5kdev->discrete_power = 1;
  6385. + }
  6386. + r5kdev->read_words = 1;
  6387. + }
  6388. +
  6389. + void pes_free(r5kdev_t *r5kdev)
  6390. + {
  6391. + free(r5kdev->stbdata);
  6392. + }
  6393. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_sat.c.svn-base ./libs/libmythtv/r5000/.svn/text-base/r5k_sat.c.svn-base
  6394. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_sat.c.svn-base 1969-12-31 16:00:00.000000000 -0800
  6395. --- ./libs/libmythtv/r5000/.svn/text-base/r5k_sat.c.svn-base 2011-04-08 19:29:47.000000000 -0700
  6396. ***************
  6397. *** 0 ****
  6398. --- 1,475 ----
  6399. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  6400. + *
  6401. + * This library is free software; you can redistribute it and/or
  6402. + * modify it under the terms of the GNU Lesser General Public
  6403. + * License as published by the Free Software Foundation; either
  6404. + * version 2.1 of the License, or (at your option) any later version.
  6405. + *
  6406. + * This library is distributed in the hope that it will be useful,
  6407. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6408. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6409. + * Lesser General Public License for more details.
  6410. + *
  6411. + * You should have received a copy of the GNU Lesser General Public
  6412. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  6413. + */
  6414. +
  6415. + //Support for Dish Network ViP211/ViP422 boxes
  6416. + #include <stdio.h>
  6417. + #include <string.h>
  6418. + #include "r5000_internal.h"
  6419. +
  6420. + #define DTV_PAT_PMT_COUNT 5000
  6421. + #define MAX_PKT_SIZE 272
  6422. + #define MAX_PAT_SECTIONS 1
  6423. + #define MAX_SIDS 200
  6424. + #define MAX_EPIDS 5
  6425. +
  6426. + struct pat {
  6427. + int version;
  6428. + unsigned char last_section;
  6429. + unsigned char section_seen[MAX_PAT_SECTIONS];
  6430. + unsigned int crc[MAX_PAT_SECTIONS];
  6431. + unsigned int pmts[MAX_SIDS];
  6432. + int pmt_count;
  6433. + };
  6434. +
  6435. + struct sids {
  6436. + unsigned short sid;
  6437. + unsigned int crc;
  6438. + unsigned char seen_name;
  6439. + struct r5k_epid epid[MAX_EPIDS];
  6440. + unsigned char epid_count;
  6441. + };
  6442. +
  6443. + struct r5000_sat {
  6444. + unsigned char buf[MAX_PKT_SIZE];
  6445. + unsigned int pos;
  6446. + int offset;
  6447. + unsigned char sync;
  6448. + unsigned char bytesize;
  6449. + unsigned char sync_byte;
  6450. + unsigned int has_sync_byte;
  6451. + unsigned int pat_pmt_count;
  6452. + unsigned int packet_size;
  6453. + unsigned int allowed_packet_size[8];
  6454. +
  6455. + unsigned int current_sid;
  6456. + struct pat pats;
  6457. + struct sids *sids;
  6458. + };
  6459. +
  6460. + static int sat_read_pat_pkt(unsigned char *pes, struct pat *pat, unsigned int size) {
  6461. + unsigned int sec, end, crc, current_next;
  6462. + int version;
  6463. + unsigned char *ptr, last_sec;
  6464. +
  6465. + if (pes[0] != 0x00) {
  6466. + r5000_print("read_pat: expected PAT table 0x00 but got 0x%02x\n", pes[0]);
  6467. + return -1;
  6468. + }
  6469. + end = (((pes[1] & 0x03) << 8 | pes[2]) + 3 - 4);
  6470. + if(end > size-4) {
  6471. + r5000_print("read_pat: invalid PAT table size (%d > %d)\n", end, size-4);
  6472. + return -1;
  6473. + }
  6474. + crc = (pes[end]<<24) | (pes[end+1]<<16) | (pes[end+2]<<8) | pes[end+3];
  6475. + version = (pes[5] >> 1) & 0x1f;
  6476. + current_next = pes[5] & 0x01;
  6477. + sec = pes[6];
  6478. + last_sec = pes[7];
  6479. + if(! current_next)
  6480. + //ignore inactive PAT
  6481. + return 0;
  6482. + if(last_sec >= MAX_PAT_SECTIONS) {
  6483. + r5000_print("read_pat: illegal section count %d > %d\n",
  6484. + last_sec, MAX_PAT_SECTIONS);
  6485. + return -1;
  6486. + }
  6487. + if (pat->version != version || last_sec != pat->last_section ||
  6488. + pat->crc[sec] != crc) {
  6489. + pat->version = version;
  6490. + pat->last_section = last_sec;
  6491. + pat->pmt_count = 0;
  6492. + memset(pat->section_seen, 0, sizeof(pat->section_seen));
  6493. + }
  6494. + if(pat->section_seen[sec])
  6495. + return 0;
  6496. + pat->crc[sec] = crc;
  6497. + pat->section_seen[sec] = 1;
  6498. + for(ptr = pes + 8; ptr < pes + end; ptr += 4) {
  6499. + int sid, pid;
  6500. + sid = (ptr[0] << 8) | ptr[1];
  6501. + pid = ((ptr[2] & 0x1F) << 8) | ptr[3];
  6502. + r5000_print("found PID: %04x for sid: %d\n", pid, sid);
  6503. + if(sid != 0) {
  6504. + pat->pmts[pat->pmt_count++] = (sid << 16) | pid;
  6505. + }
  6506. + }
  6507. + return 1;
  6508. + }
  6509. +
  6510. + static struct sids *sat_read_pmt_pkt(unsigned char *buf, struct sids *sids,
  6511. + unsigned int size) {
  6512. + //
  6513. + // NOTE we aren't using last_sec here yet!
  6514. + //
  6515. +
  6516. + struct sids *sidptr = sids;
  6517. + unsigned int count, skip, pos, crc, current_next;
  6518. + int sid, sec, last_sec, pcrpid, epid, type;
  6519. + if (buf[0] != 0x02) {
  6520. + r5000_print("read_pmt expected table 0x02 but got 0x%02x\n", buf[0]);
  6521. + return NULL;
  6522. + }
  6523. + count = (((buf[1] & 0x03) << 8) | buf[2]) + 3 - 4;
  6524. + sid = (buf[3] << 8) | buf[4];
  6525. + current_next = buf[5] & 0x01;
  6526. + crc = (buf[count]<<24) | (buf[count+1]<<16) | (buf[count+2]<<8) | buf[count+3];
  6527. + sec = buf[6];
  6528. + last_sec = buf[7];
  6529. + pcrpid = ((buf[8] & 0x1F) << 8) | buf[9];
  6530. + skip = ((buf[10] & 0x03) << 8) | buf[11];
  6531. + if(skip > count - 12 || count > size) {
  6532. + r5000_print("skip: %d > count: %d - 12 || count > size: %d\n",
  6533. + skip, count, size);
  6534. + return NULL;
  6535. + }
  6536. + if(! current_next) {
  6537. + r5000_print("read_pmt ignoring future PMT\n");
  6538. + return NULL;
  6539. + }
  6540. + while(sidptr->sid != 0) {
  6541. + if(sidptr->sid == sid)
  6542. + break;
  6543. + sidptr++;
  6544. + }
  6545. + if(sidptr->sid == 0) {
  6546. + // We weren't expecting this sid
  6547. + r5000_print("read_pmt found unexpected sid: %d\n", sidptr->sid);
  6548. + return sidptr;
  6549. + }
  6550. + if(sidptr->crc == crc) {
  6551. + //sid is unchanged
  6552. + //r5000_print("read_pmt found identical crc (%08x) for %d\n", crc, sidptr->sid);
  6553. + return NULL;
  6554. + }
  6555. + memset(sidptr, 0, sizeof(struct sids));
  6556. +
  6557. + r5000_print("read_pmt: sid: %d pcrpid: %d skip: %d count: %d\n", sid, pcrpid, skip, count);
  6558. + sidptr->sid = sid;
  6559. + sidptr->crc = crc;
  6560. + sidptr->epid_count = 0;
  6561. + for(pos = 12 + skip; pos < count;) {
  6562. + struct r5k_epid *pidptr = &sidptr->epid[sidptr->epid_count];
  6563. + type = buf[pos];
  6564. + epid = ((buf[pos+1] & 0x1F) << 8) | buf[pos+2];
  6565. + skip = ((buf[pos+3] & 0x03) << 8) | buf[pos+4];
  6566. + pidptr->pid = epid;
  6567. + pidptr->id = type == 0x80 ? 0x02 : type;
  6568. + memcpy(pidptr->desc.d, buf + pos + 4, skip + 1);
  6569. + sidptr->epid_count++;
  6570. + r5000_print("read_pmt: epid %04x (type %02x, skip=%d) mapped to sid %d\n", epid, type, skip, sid);
  6571. + pos += 5 + skip;
  6572. + }
  6573. + return sidptr;
  6574. + }
  6575. +
  6576. + void sat_find_chname(unsigned char *buf, struct sids *sids, unsigned int size) {
  6577. + struct sids *sidptr = sids;
  6578. + unsigned int count;
  6579. + int sid;
  6580. + unsigned char str[20], *strptr = str;
  6581. + while(size) {
  6582. + count = (((buf[1] & 0x03) << 8) | buf[2]) + 3;
  6583. + if(buf[0] == 0x41) {
  6584. + buf += count;
  6585. + size -= count;
  6586. + continue;
  6587. + }
  6588. + if(buf[0] == 0xc1) {
  6589. + unsigned char *ptr = buf+16;
  6590. + sid = (buf[7]<<8) | buf[8];
  6591. + while(sidptr->sid != 0) {
  6592. + if(sidptr->sid == sid)
  6593. + break;
  6594. + sidptr++;
  6595. + }
  6596. + if(sidptr->sid == 0) {
  6597. + // We weren't expecting this sid
  6598. + return;
  6599. + }
  6600. + if(sidptr->seen_name)
  6601. + return;
  6602. + sidptr->seen_name = 1;
  6603. + while(*ptr >= 0x20 && *ptr < 0x7b && (strptr-str) < (int)(sizeof(str)-1)) {
  6604. + *strptr++ = *ptr++;
  6605. + }
  6606. + *strptr = 0;
  6607. + r5000_print("sid: %d is channel %s\n", sid, str);
  6608. + return;
  6609. + }
  6610. + return;
  6611. + }
  6612. + }
  6613. +
  6614. + int sat_add_pmt(r5kdev_t *r5kdev, struct r5k_epid *epid)
  6615. + {
  6616. + int i;
  6617. + int is_video = IS_VIDEO(epid->id);
  6618. +
  6619. + for(i = 0; i < r5kdev->num_pmt_entries; i++) {
  6620. + if(r5kdev->pmt[i].pid == epid->pid) {
  6621. + if(r5kdev->pmt[i].id == epid->id)
  6622. + return 0;
  6623. + //different table_id for existing pid. Reset
  6624. + r5000_reset_pmt(r5kdev);
  6625. + break;
  6626. + }
  6627. + if(is_video) {
  6628. + if(IS_VIDEO(r5kdev->pmt[i].id)) {
  6629. + //a video entry already exists. Reset
  6630. + r5000_reset_pmt(r5kdev);
  6631. + break;
  6632. + }
  6633. + }
  6634. + }
  6635. + //Didn't find this PID, add it
  6636. + if(i == R5K_MAX_PIDS)
  6637. + return 0;
  6638. + r5000_print("Adding %04x: %02x (desc_len=%d) @ %08x\n", epid->pid, epid->id, epid->desc.d[0], r5kdev->bytes_read);
  6639. + r5kdev->pmt[r5kdev->num_pmt_entries++] = *epid;
  6640. + r5kdev->pmt_state |= is_video ? 0x01 : 0x02;
  6641. + return 1;
  6642. + }
  6643. +
  6644. + void sat_process_ts(r5kdev_t *r5kdev, unsigned char *buf)
  6645. + {
  6646. + struct r5000_sat *sat = (struct r5000_sat *)r5kdev->stbdata;
  6647. + int pid;
  6648. + int i, j, k;
  6649. + pid = ((buf[1] << 8) | buf[2]) & 0x1fff;
  6650. + if(pid == 0x1fff)
  6651. + return;
  6652. + if(pid == 0 && (buf[1] & 0x40)) {
  6653. + //Always read PAT in case we changed transponders
  6654. + if(sat_read_pat_pkt(buf+buf[4]+5, &sat->pats, 188-buf[4]-5) > 0) {
  6655. + r5000_print("Found new PAT\n");
  6656. + if(sat->pats.pmt_count) {
  6657. + sat->sids = (struct sids *)realloc(sat->sids, sizeof(struct sids)*(sat->pats.pmt_count+1));
  6658. + memset(sat->sids, 0, sizeof(struct sids)*(sat->pats.pmt_count+1));
  6659. + //Pre load sids so we don't overrun if the PMT changes before the PAT
  6660. + for(i = 0; i < sat->pats.pmt_count; i++) {
  6661. + sat->sids[i].sid = sat->pats.pmts[i]>>16;
  6662. + }
  6663. + sat->sids[i].sid = 0;
  6664. + r5000_reset_pmt(r5kdev);
  6665. + }
  6666. + } else if(r5kdev->pmt_state == 0x03) {
  6667. + r5kdev->cb(r5000_pat_pkt, 188, r5kdev->cb_data);
  6668. + r5000_send_pmt(r5kdev);
  6669. + sat->pat_pmt_count = 0;
  6670. + }
  6671. + return;
  6672. + }
  6673. + //Always reread PMT in case the pids have changed
  6674. + for(i = 0; i < sat->pats.pmt_count; i++) {
  6675. + if(pid == (unsigned short)(sat->pats.pmts[i])) {
  6676. + #if 0
  6677. + {
  6678. + char s[80];
  6679. + FILE *fh;
  6680. + sprintf(s, "0x%04x.ts", pid);
  6681. + fh= fopen(s, "a");
  6682. + fwrite(buf, 188, 1, fh);
  6683. + fclose(fh);
  6684. + }
  6685. + #endif
  6686. + //r5000_print("PID: %04x - %04x (%d) %02x %02x %02x %02x %02x\n", pid, (unsigned short)(sat->pats.pmts[i]), i, buf[1], buf[2], buf[3], buf[4], buf[5]);
  6687. + if(buf[1] & 0x40 && buf[4]+5 < 188) {
  6688. + if(buf[buf[4]+5] == 0x02) {
  6689. + struct sids *sidptr;
  6690. + if((sidptr = sat_read_pmt_pkt(buf+buf[4]+5, sat->sids, 188-buf[4]-5))) {
  6691. + if(sidptr->sid == 0) {
  6692. + //Unexpected sid, reset PAT;
  6693. + memset(&sat->pats, 0, sizeof(struct pat));
  6694. + } else if(sat->current_sid == sidptr->sid) {
  6695. + r5000_reset_pmt(r5kdev);
  6696. + sat->current_sid = 0;
  6697. + }
  6698. + }
  6699. + //} else if(buf[buf[4]+5] == 0xc1 || buf[buf[4]+5] == 0x41) {
  6700. + // sat_find_chname(buf+buf[4]+5, sat->sids, 188-buf[4]-5);
  6701. + }
  6702. + }
  6703. + return;
  6704. + }
  6705. + if(! sat->current_sid) {
  6706. + for(j = 0; j < sat->sids[i].epid_count; j++) {
  6707. + if(pid == sat->sids[i].epid[j].pid &&
  6708. + IS_VIDEO(sat->sids[i].epid[j].id) &&
  6709. + (!r5kdev->channel || r5kdev->channel == sat->sids[i].sid)) {
  6710. + //Found unencrypted video. Choose this one
  6711. + // Assume this is MPEG2. Don't know what MPEG4 looks like yet
  6712. + sat->current_sid = sat->sids[i].sid;
  6713. + r5000_print("Found decrypted sid %d\n", sat->current_sid);
  6714. + if (sat_add_pmt(r5kdev, &sat->sids[i].epid[j])) {
  6715. + //This is a new Video PID
  6716. + for(k = 0; k < sat->sids[i].epid_count; k++) {
  6717. + if(sat->sids[i].epid[k].id == 0x81 ||
  6718. + sat->sids[i].epid[k].id == 0xbd) {
  6719. + sat_add_pmt(r5kdev, &sat->sids[i].epid[k]);
  6720. + }
  6721. + }
  6722. + r5kdev->cb(r5000_pat_pkt, 188, r5kdev->cb_data);
  6723. + r5000_send_pmt(r5kdev);
  6724. + sat->pat_pmt_count = 0;
  6725. + }
  6726. + r5kdev->cb(sat->buf, 188, r5kdev->cb_data);
  6727. + return;
  6728. + }
  6729. + }
  6730. + }
  6731. + }
  6732. + for(i = 0; i < r5kdev->num_pmt_entries; i++) {
  6733. + if(pid == r5kdev->pmt[i].pid) {
  6734. + r5kdev->cb(sat->buf, 188, r5kdev->cb_data);
  6735. + sat->pat_pmt_count++;
  6736. + return;
  6737. + }
  6738. + }
  6739. + #if 0
  6740. + //r5000_print("Ignoring PID: %04x\n", pid);
  6741. + {
  6742. + char s[80];
  6743. + FILE *fh;
  6744. + sprintf(s, "0x%04x.ts", pid);
  6745. + fh= fopen(s, "a");
  6746. + fwrite(buf, 188, 1, fh);
  6747. + fclose(fh);
  6748. + }
  6749. + #endif
  6750. + }
  6751. +
  6752. + static void sat_process_block(r5kdev_t *r5kdev, unsigned char *buf, int len)
  6753. + {
  6754. + struct r5000_sat *sat = (struct r5000_sat *)r5kdev->stbdata;
  6755. +
  6756. + int pos;
  6757. + if(! r5kdev->streaming)
  6758. + return;
  6759. + if(len <= 0)
  6760. + return;
  6761. +
  6762. + for(pos = sat->offset; pos < len; pos += sat->bytesize) {
  6763. + if(! sat->sync) {
  6764. + if(buf[pos] == 0x47) {
  6765. + int i;
  6766. + if ((int)(pos + (sat->allowed_packet_size[0]<<1)) < len) {
  6767. + if((buf[pos+1] & 0xfc) == 0xfc && (buf[pos+3] & 0xfc) == 0xfc &&
  6768. + (buf[pos+5] & 0xfc) == 0xfc && (buf[pos+7] & 0xfc) == 0xfc) {
  6769. + sat->bytesize = 2;
  6770. + }
  6771. + for(i=0; sat->allowed_packet_size[i] != 0; i++) {
  6772. + if(buf[pos+(sat->allowed_packet_size[i] * sat->bytesize)] == 0x47) {
  6773. + r5000_print("(%d) Found %d byte sync at %08x: bytesize = %d\n",
  6774. + r5kdev->nexturb, sat->allowed_packet_size[i],
  6775. + r5kdev->bytes_read+pos, sat->bytesize);
  6776. + sat->packet_size = sat->allowed_packet_size[i];
  6777. + sat->sync = 1;
  6778. + sat->buf[0] = 0x47;
  6779. + sat->pos = 1;
  6780. + break;
  6781. + }
  6782. + }
  6783. + }
  6784. + }
  6785. + continue;
  6786. + }
  6787. + if (sat->pos == 0 && buf[pos] != 0x47) {
  6788. + sat->sync = 0;
  6789. + sat->bytesize = 1;
  6790. + r5000_print("(%d)Lost sync at %08x\n", r5kdev->nexturb,
  6791. + r5kdev->bytes_read+pos);
  6792. + continue;
  6793. + }
  6794. + if(sat->pos == 3 && (buf[pos] & 0xc0) != 0x00) {
  6795. + // Encrypted channel, skip this packet
  6796. + sat->pos = 0;
  6797. + pos += sat->bytesize * (sat->packet_size - 4); //Loop adds additional 2
  6798. + continue;
  6799. + }
  6800. + sat->buf[sat->pos++] = buf[pos];
  6801. + if (sat->pos == sat->packet_size) {
  6802. + sat_process_ts(r5kdev, sat->buf);
  6803. + //if packet size > 188, assume remaining bytes are parity and ignore
  6804. + sat->pos = 0;
  6805. + }
  6806. + }
  6807. + sat->offset = pos - len;
  6808. + if(r5kdev->pmt_state == 0x03 && sat->pat_pmt_count > DTV_PAT_PMT_COUNT) {
  6809. + r5kdev->cb(r5000_pat_pkt, 188, r5kdev->cb_data);
  6810. + r5000_send_pmt(r5kdev);
  6811. + sat->pat_pmt_count = 0;
  6812. + }
  6813. + }
  6814. +
  6815. + static void sat_start_stream(r5kdev_t *r5kdev)
  6816. + {
  6817. + struct r5000_sat *sat = (struct r5000_sat *)r5kdev->stbdata;
  6818. + sat->offset = 0;
  6819. + sat->sync = 0;
  6820. + sat->pos = 0;
  6821. + sat->bytesize = 1;
  6822. +
  6823. + //Clear any defined PAT or PMT data
  6824. + if(sat->sids) {
  6825. + free(sat->sids);
  6826. + sat->sids = 0;
  6827. + }
  6828. + memset(&sat->pats, 0, sizeof(struct pat));
  6829. + sat->pat_pmt_count = DTV_PAT_PMT_COUNT;
  6830. + }
  6831. +
  6832. + static void sat_change_channel(r5kdev_t *r5kdev)
  6833. + {
  6834. + r5000_reset_pmt(r5kdev);
  6835. + }
  6836. +
  6837. + void sat_init(r5kdev_t *r5kdev)
  6838. + {
  6839. + struct r5000_sat *sat =
  6840. + (struct r5000_sat *)calloc(1, sizeof(struct r5000_sat));
  6841. + r5kdev->stbdata = sat;
  6842. + sat->pat_pmt_count = DTV_PAT_PMT_COUNT;
  6843. + if(r5kdev->stb_type == R5K_STB_HDD) {
  6844. + sat->sync_byte = 0xff;
  6845. + sat->has_sync_byte = 1;
  6846. + sat->allowed_packet_size[0] = 272;
  6847. + sat->allowed_packet_size[1] = 233;
  6848. + sat->allowed_packet_size[2] = 204;
  6849. + sat->allowed_packet_size[3] = 188;
  6850. + sat->allowed_packet_size[4] = 0;
  6851. + } else {
  6852. + sat->allowed_packet_size[0] = 188;
  6853. + sat->allowed_packet_size[1] = 0;
  6854. + }
  6855. + r5kdev->process_block = sat_process_block;
  6856. + r5kdev->start_stream = sat_start_stream;
  6857. + r5kdev->change_channel = &sat_change_channel;
  6858. + if(r5kdev->stb_type == R5K_STB_DSR) {
  6859. + r5kdev->power_active_low = 1;
  6860. + }
  6861. + #ifdef R5K_DSR_BUTTONS
  6862. + r5kdev->button = &dsr_button_cmd;
  6863. + #endif
  6864. + }
  6865. +
  6866. + void sat_free(r5kdev_t *r5kdev)
  6867. + {
  6868. + struct r5000_sat *sat = (struct r5000_sat *)r5kdev->stbdata;
  6869. + if(sat->sids)
  6870. + free(sat->sids);
  6871. + free(r5kdev->stbdata);
  6872. + }
  6873. +
  6874. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_vip_buttons.c.svn-base ./libs/libmythtv/r5000/.svn/text-base/r5k_vip_buttons.c.svn-base
  6875. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_vip_buttons.c.svn-base 1969-12-31 16:00:00.000000000 -0800
  6876. --- ./libs/libmythtv/r5000/.svn/text-base/r5k_vip_buttons.c.svn-base 2011-04-08 19:29:47.000000000 -0700
  6877. ***************
  6878. *** 0 ****
  6879. --- 1,215 ----
  6880. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  6881. + *
  6882. + * This library is free software; you can redistribute it and/or
  6883. + * modify it under the terms of the GNU Lesser General Public
  6884. + * License as published by the Free Software Foundation; either
  6885. + * version 2.1 of the License, or (at your option) any later version.
  6886. + *
  6887. + * This library is distributed in the hope that it will be useful,
  6888. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6889. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6890. + * Lesser General Public License for more details.
  6891. + *
  6892. + * You should have received a copy of the GNU Lesser General Public
  6893. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  6894. + */
  6895. +
  6896. +
  6897. + #include "r5000_internal.h"
  6898. + struct r5000_buttons vip_button_cmd =
  6899. + {
  6900. + 0x00, //len
  6901. + 400000, //delay
  6902. + //button 0
  6903. + {
  6904. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  6905. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6906. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  6907. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6908. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e,
  6909. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6910. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  6911. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6912. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  6913. + },
  6914. + //button 1
  6915. + {
  6916. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  6917. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6918. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6919. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6920. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  6921. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6922. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  6923. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6924. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  6925. + },
  6926. + //button 2
  6927. + {
  6928. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  6929. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6930. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6931. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6932. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  6933. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6934. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  6935. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6936. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  6937. + },
  6938. + //button 3
  6939. + {
  6940. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  6941. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6942. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6943. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6944. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  6945. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6946. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  6947. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6948. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  6949. + },
  6950. + //button 4
  6951. + {
  6952. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  6953. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6954. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  6955. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6956. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  6957. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6958. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  6959. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6960. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  6961. + },
  6962. + //button 5
  6963. + {
  6964. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  6965. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6966. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  6967. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6968. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  6969. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6970. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  6971. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6972. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  6973. + },
  6974. + //button 6
  6975. + {
  6976. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  6977. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6978. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  6979. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6980. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  6981. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6982. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  6983. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6984. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  6985. + },
  6986. + //button 7
  6987. + {
  6988. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  6989. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6990. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  6991. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6992. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  6993. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6994. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  6995. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  6996. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  6997. + },
  6998. + //button 8
  6999. + {
  7000. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  7001. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7002. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  7003. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7004. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  7005. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7006. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  7007. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7008. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  7009. + },
  7010. + //button 9
  7011. + {
  7012. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e,
  7013. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7014. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  7015. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7016. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  7017. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7018. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  7019. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7020. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  7021. + },
  7022. + //button Clear
  7023. + {
  7024. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  7025. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7026. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  7027. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7028. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e,
  7029. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7030. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  7031. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7032. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  7033. + },
  7034. + //button Enter
  7035. + {
  7036. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  7037. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7038. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  7039. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7040. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e,
  7041. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7042. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  7043. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7044. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  7045. + },
  7046. + //button Power
  7047. + {
  7048. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7049. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7050. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7051. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7052. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  7053. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7054. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  7055. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7056. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  7057. + },
  7058. + //button Power-On
  7059. + {
  7060. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7061. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7062. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7063. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7064. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x1a,
  7065. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7066. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  7067. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7068. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  7069. + },
  7070. + //button Power-Off
  7071. + {
  7072. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e,
  7073. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7074. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a,
  7075. + 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7076. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x0e, 0x04, 0x1a,
  7077. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7078. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x0e,
  7079. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7080. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  7081. + },
  7082. + //button Guide
  7083. + {
  7084. + 0x00, 0x89, 0x0a, 0x80, 0x00, 0x00, 0x04, 0x39, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e,
  7085. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7086. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a,
  7087. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7088. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a, 0x04, 0x0e,
  7089. + 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7090. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x3a, 0x04, 0x1a,
  7091. + 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x0e, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a,
  7092. + 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04, 0x1a, 0x04,
  7093. + },
  7094. + };
  7095. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_vip.c.svn-base ./libs/libmythtv/r5000/.svn/text-base/r5k_vip.c.svn-base
  7096. *** ../../mythtv/mythtv/libs/libmythtv/r5000/.svn/text-base/r5k_vip.c.svn-base 1969-12-31 16:00:00.000000000 -0800
  7097. --- ./libs/libmythtv/r5000/.svn/text-base/r5k_vip.c.svn-base 2011-04-08 19:29:47.000000000 -0700
  7098. ***************
  7099. *** 0 ****
  7100. --- 1,246 ----
  7101. + /* Copyright 2008 Alan Nisota <alannisota@gmail.com>
  7102. + *
  7103. + * This library is free software; you can redistribute it and/or
  7104. + * modify it under the terms of the GNU Lesser General Public
  7105. + * License as published by the Free Software Foundation; either
  7106. + * version 2.1 of the License, or (at your option) any later version.
  7107. + *
  7108. + * This library is distributed in the hope that it will be useful,
  7109. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7110. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7111. + * Lesser General Public License for more details.
  7112. + *
  7113. + * You should have received a copy of the GNU Lesser General Public
  7114. + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  7115. + */
  7116. +
  7117. + //Support for Dish Network ViP211/ViP422 boxes
  7118. + #include <stdio.h>
  7119. + #include <string.h>
  7120. + #include <sys/time.h>
  7121. + #include "r5000_internal.h"
  7122. +
  7123. + struct r5000_vip {
  7124. + unsigned char leftover[188];
  7125. + int offset;
  7126. + int pos;
  7127. + };
  7128. + #define CHECK_CONTINUITY 1
  7129. + #ifdef CHECK_CONTINUITY
  7130. + static unsigned char continuity[0x2000];
  7131. + #endif
  7132. +
  7133. + #define PMT_READY(_r5kdev) (((_r5kdev)->pmt_state == 0x03) || ((_r5kdev)->channel < 0 && (_r5kdev)->pmt_state == 0x02))
  7134. +
  7135. + #define IS_PRIVATE_SECTION(x) (x == 0x05)
  7136. +
  7137. + enum {
  7138. + R5K_STREAMTYPE_VIDEO,
  7139. + R5K_STREAMTYPE_AUDIO,
  7140. + R5K_STREAMTYPE_PRIVATE,
  7141. + };
  7142. +
  7143. + static struct timeval last_tv;
  7144. + void vip_add_pmt(r5kdev_t *r5kdev, int pid, int table_id)
  7145. + {
  7146. + int i;
  7147. + struct r5000_vip *vip = (struct r5000_vip *)r5kdev->stbdata;
  7148. +
  7149. + int streamtype = IS_VIDEO(table_id) ? R5K_STREAMTYPE_VIDEO : (IS_PRIVATE_SECTION(table_id) ? R5K_STREAMTYPE_PRIVATE : R5K_STREAMTYPE_AUDIO);
  7150. +
  7151. + for(i = 0; i < r5kdev->num_pmt_entries; i++) {
  7152. + if(r5kdev->pmt[i].pid == pid) {
  7153. + if(r5kdev->pmt[i].id == table_id) {
  7154. + if (streamtype == R5K_STREAMTYPE_VIDEO && r5kdev->pmt_state == 0x03) {
  7155. + //If we haven't seen a PAT or PMT in 500ms, send one
  7156. + struct timeval tv, tv_test;
  7157. + gettimeofday(&tv, NULL);
  7158. + timersub(&tv, &last_tv, &tv_test);
  7159. + if(tv.tv_sec > 0 || tv.tv_usec > 500 * 1000) {
  7160. + r5kdev->cb(r5000_pat_pkt, 188, r5kdev->cb_data);
  7161. + r5000_send_pmt(r5kdev);
  7162. + last_tv = tv;
  7163. + }
  7164. + }
  7165. + return;
  7166. + }
  7167. + //different table_id for existing pid. Reset
  7168. + r5000_reset_pmt(r5kdev);
  7169. + break;
  7170. + }
  7171. + if(streamtype == R5K_STREAMTYPE_VIDEO) {
  7172. + if(IS_VIDEO(r5kdev->pmt[i].id)) {
  7173. + //a video entry already exists. Reset
  7174. + r5000_reset_pmt(r5kdev);
  7175. + break;
  7176. + }
  7177. + }
  7178. + }
  7179. + //Didn't find this PID, add it
  7180. + if(i == R5K_MAX_PIDS)
  7181. + return;
  7182. + gettimeofday(&last_tv, NULL);
  7183. + r5000_print("Adding %04x: %02x @ %08x\n", pid, table_id, r5kdev->bytes_read + vip->pos);
  7184. + r5kdev->pmt[r5kdev->num_pmt_entries].pid = pid;
  7185. + r5kdev->pmt[r5kdev->num_pmt_entries].id = table_id;
  7186. + switch(streamtype) {
  7187. + case R5K_STREAMTYPE_VIDEO:
  7188. + r5kdev->pmt[r5kdev->num_pmt_entries].desc = r5000_pmt_video_desc;
  7189. + r5kdev->pmt_state |= 0x01;
  7190. + break;
  7191. + case R5K_STREAMTYPE_AUDIO:
  7192. + r5kdev->pmt[r5kdev->num_pmt_entries].desc = r5000_pmt_audio_desc;
  7193. + r5kdev->pmt_state |= 0x02;
  7194. + break;
  7195. + case R5K_STREAMTYPE_PRIVATE:
  7196. + r5kdev->pmt[r5kdev->num_pmt_entries].desc = r5000_pmt_nowplaying_desc;
  7197. + break;
  7198. + }
  7199. + r5kdev->num_pmt_entries++;
  7200. + //Force rebuild of PMT
  7201. + r5kdev->pmt_pkt[0] = 0;
  7202. + }
  7203. +
  7204. + void vip_force_pmt(r5kdev_t *r5kdev, unsigned char *buf)
  7205. + {
  7206. + int stream_id, pid, afc, af_size = 0;
  7207. +
  7208. + pid = ((buf[1] << 8) | buf[2]) & 0x1fff;
  7209. + if(pid == 0x1fff)
  7210. + return;
  7211. + #ifdef CHECK_CONTINUITY
  7212. + if(pid >= 0x1000) {
  7213. + struct r5000_vip *vip = (struct r5000_vip *)r5kdev->stbdata;
  7214. + unsigned char cont = buf[3] & 0x0f;
  7215. + if(continuity[pid] != cont && (buf[3] & 0x30) != 0x20) {
  7216. + r5000_print("Continuity (0x%04x) %d != %d @%08x\n",
  7217. + pid, cont, continuity[pid], r5kdev->bytes_read + vip->pos);
  7218. + }
  7219. + continuity[pid] = (cont + 1) & 0x0f;
  7220. + }
  7221. + #endif
  7222. + if(pid == 0) {
  7223. + gettimeofday(&last_tv, NULL);
  7224. + r5kdev->cb(r5000_pat_pkt, 188, r5kdev->cb_data);
  7225. + if(PMT_READY(r5kdev))
  7226. + r5000_send_pmt(r5kdev);
  7227. + } else {
  7228. + if(pid != 0x21)
  7229. + r5kdev->cb(buf, 188, r5kdev->cb_data);
  7230. + //Only interested in PES packets starting in this TS packet
  7231. + if (!(buf[1] & 0x40))
  7232. + return;
  7233. + afc = (buf[3]>>4) & 0x03;
  7234. + if(afc == 0x2)
  7235. + return;
  7236. + if(afc == 0x3)
  7237. + af_size = buf[4]+1;
  7238. + if(buf[4+af_size] != 0x00 || buf[5+af_size] != 0x00 || buf[6+af_size] != 0x01)
  7239. + return;
  7240. + //We have a PES packet
  7241. + stream_id = buf[7+af_size];
  7242. + if((stream_id & 0xf0) == 0xe0) {
  7243. + //Video stream (we need the adaptation field)
  7244. + if(0) {
  7245. + PRINTHEX("data", buf, af_size+8);
  7246. + }
  7247. + if(afc == 0x03) {
  7248. + if(buf[5] & 0x02) {
  7249. + // Has private data, this is MPEG4
  7250. + vip_add_pmt(r5kdev, pid, 0x1b);
  7251. + } else { //if(buf[5] & 0x10) {
  7252. + // Has PCR and no private data, this is MPEG2
  7253. + vip_add_pmt(r5kdev, pid, 0x02);
  7254. + }
  7255. + } else {
  7256. + // No PCR, maybe this is ATSC?
  7257. + vip_add_pmt(r5kdev, pid, 0x02);
  7258. + }
  7259. + } else if((stream_id & 0xf0) == 0xc0) {
  7260. + //Audio stream
  7261. + vip_add_pmt(r5kdev, pid, 0x04);
  7262. + } else if(stream_id == 0xbd) {
  7263. + //Audio stream
  7264. + vip_add_pmt(r5kdev, pid, 0x81);
  7265. + }
  7266. + }
  7267. + }
  7268. +
  7269. + static void vip_process_block(r5kdev_t *r5kdev, unsigned char *buf, int len)
  7270. + {
  7271. + struct r5000_vip *vip = (struct r5000_vip *)r5kdev->stbdata;
  7272. +
  7273. + int sync = 1;
  7274. + if(! r5kdev->streaming)
  7275. + return;
  7276. + if(len <= 0)
  7277. + return;
  7278. +
  7279. + vip->pos = vip->offset;
  7280. + while(vip->pos < len) {
  7281. + if(buf[vip->pos] != 0x47 || (vip->pos <len-1 && buf[vip->pos+1] == 0xff))
  7282. + goto nosync;
  7283. + // If we get here, buf[vip->pos] == 0x47
  7284. + if(vip->offset) {
  7285. + //previous data exists and is part of a good packet
  7286. + memcpy(vip->leftover+188-vip->offset, buf, vip->offset);
  7287. + vip_force_pmt(r5kdev, vip->leftover);
  7288. + vip->offset = 0;
  7289. + }
  7290. + if(vip->pos+188 <= len) {
  7291. + //at least one full packet is available
  7292. + if(vip->pos+188 < len && buf[vip->pos+188] != 0x47)
  7293. + goto nosync;
  7294. + } else {
  7295. + //Out of data, but the partial packet may be ok.
  7296. + memcpy(vip->leftover, buf+vip->pos, len-vip->pos);
  7297. + vip->offset = 188-(len-vip->pos);
  7298. + break;
  7299. + }
  7300. + //If we get here, we have a good packet
  7301. + vip_force_pmt(r5kdev, buf+vip->pos);
  7302. + if(! sync)
  7303. + r5000_print("(%d) Found sync @ %08x\n", r5kdev->nexturb, r5kdev->bytes_read+vip->pos);
  7304. + sync = 1;
  7305. + vip->pos+=188;
  7306. + continue;
  7307. + nosync:
  7308. + vip->offset=0;
  7309. + if(sync)
  7310. + r5000_print("(%d)Lost sync @ %08x\n", r5kdev->nexturb, r5kdev->bytes_read+vip->pos);
  7311. + sync = 0;
  7312. + vip->pos++;
  7313. + }
  7314. + }
  7315. +
  7316. + static void vip_start_stream(r5kdev_t *r5kdev)
  7317. + {
  7318. + struct r5000_vip *vip = (struct r5000_vip *)r5kdev->stbdata;
  7319. + vip->offset = 0;
  7320. + }
  7321. +
  7322. + static void vip_change_channel(r5kdev_t *r5kdev)
  7323. + {
  7324. + r5000_reset_pmt(r5kdev);
  7325. + }
  7326. +
  7327. + void vip_init(r5kdev_t *r5kdev)
  7328. + {
  7329. + struct r5000_vip *vip = (struct r5000_vip *)malloc(sizeof(struct r5000_vip));
  7330. + r5kdev->stbdata = vip;
  7331. + r5kdev->process_block = vip_process_block;
  7332. + r5kdev->start_stream = vip_start_stream;
  7333. + r5kdev->button = &vip_button_cmd;
  7334. + r5kdev->change_channel = &vip_change_channel;
  7335. + r5kdev->discrete_power = 1;
  7336. + if(r5kdev->stb_type == R5K_STB_VIP211)
  7337. + r5kdev->unreliable_power_detect = 1;
  7338. + if(r5kdev->stb_type == R5K_STB_VIP622)
  7339. + r5kdev->power_active_low = 1;
  7340. + }
  7341. +
  7342. + void vip_free(r5kdev_t *r5kdev)
  7343. + {
  7344. + free(r5kdev->stbdata);
  7345. + }
  7346. +
  7347. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000channel.cpp ./libs/libmythtv/r5000channel.cpp
  7348. *** ../../mythtv/mythtv/libs/libmythtv/r5000channel.cpp 1969-12-31 16:00:00.000000000 -0800
  7349. --- ./libs/libmythtv/r5000channel.cpp 2013-02-16 10:52:50.014567132 -0800
  7350. ***************
  7351. *** 0 ****
  7352. --- 1,215 ----
  7353. + /**
  7354. + * R5000Channel
  7355. + * Copyright (c) 2005 by Jim Westfall, Dave Abrahams
  7356. + * Copyright (c) 2006 by Daniel Kristjansson
  7357. + * Distributed as part of MythTV under GPL v2 and later.
  7358. + */
  7359. +
  7360. + #include "mythcontext.h"
  7361. + #include "tv_rec.h"
  7362. + #include "r5000channel.h"
  7363. +
  7364. + #define LOC QString("R5kChan(%1): ").arg(GetDevice())
  7365. + #define LOC_WARN QString("R5kChan(%1), Warning: ").arg(GetDevice())
  7366. + #define LOC_ERR QString("R5kChan(%1), Error: ").arg(GetDevice())
  7367. +
  7368. + R5000Channel::R5000Channel(TVRec *parent, const QString &_videodevice,const QString &_r5ktype, bool pocc) :
  7369. + DTVChannel(parent),
  7370. + videodevice(_videodevice),
  7371. + power_on_channel_change(pocc),
  7372. + device(NULL),
  7373. + current_channel(""),
  7374. + current_mpeg_prog(0),
  7375. + isopen(false),
  7376. + tuning_delay(0)
  7377. + {
  7378. + int type = R5000Device::GetDeviceType(_r5ktype);
  7379. + device = new R5000Device(type, videodevice);
  7380. +
  7381. + InitializeInputs();
  7382. + }
  7383. +
  7384. + bool R5000Channel::SetChannelByString(const QString &channum)
  7385. + {
  7386. + QString loc = LOC + QString("SetChannelByString(%1)").arg(channum);
  7387. + bool ok = false;
  7388. + LOG(VB_CHANNEL, LOG_DEBUG, LOC);
  7389. +
  7390. + InputMap::const_iterator it = m_inputs.find(m_currentInputID);
  7391. + if (it == m_inputs.end())
  7392. + return false;
  7393. +
  7394. + QString tvformat, modulation, freqtable, freqid, dtv_si_std;
  7395. + int finetune;
  7396. + uint64_t frequency;
  7397. + int mpeg_prog_num;
  7398. + uint atsc_major, atsc_minor, mplexid, tsid, netid;
  7399. + if (!ChannelUtil::GetChannelData(
  7400. + (*it)->sourceid, channum,
  7401. + tvformat, modulation, freqtable, freqid,
  7402. + finetune, frequency,
  7403. + dtv_si_std, mpeg_prog_num, atsc_major, atsc_minor, tsid, netid,
  7404. + mplexid, m_commfree))
  7405. + {
  7406. + LOG(VB_GENERAL, LOG_DEBUG, LOC + " " + QString(
  7407. + "Requested channel '%1' is on input '%2' "
  7408. + "which is in a busy input group")
  7409. + .arg(channum).arg(m_currentInputID));
  7410. +
  7411. + return false;
  7412. + }
  7413. + uint mplexid_restriction;
  7414. + if (!IsInputAvailable(m_currentInputID, mplexid_restriction))
  7415. + {
  7416. + LOG(VB_GENERAL, LOG_DEBUG, LOC + " " + QString(
  7417. + "Requested channel '%1' is on input '%2' "
  7418. + "which is in a busy input group")
  7419. + .arg(channum).arg(m_currentInputID));
  7420. +
  7421. + return false;
  7422. + }
  7423. +
  7424. + if (!(*it)->externalChanger.isEmpty())
  7425. + {
  7426. + ok = ChangeExternalChannel((*it)->externalChanger, freqid);
  7427. + // -1 resets any state without executing a channel change
  7428. + device->SetChannel(fw_opts.model, 0, mpeg_prog_num);
  7429. + SetSIStandard("mpeg");
  7430. + SetDTVInfo(0,0,0,0,1);
  7431. + }
  7432. + else
  7433. + {
  7434. + ok = isopen && SetChannelByNumber(freqid, mpeg_prog_num);
  7435. + }
  7436. +
  7437. + if (ok)
  7438. + {
  7439. + if (tuning_delay) {
  7440. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + " " + QString(
  7441. + "Adding additional delay: %1ms").arg(tuning_delay));
  7442. + usleep(tuning_delay * 1000);
  7443. + }
  7444. + // Set the current channum to the new channel's channum
  7445. + QString tmp = channum;
  7446. + tmp.detach();
  7447. + m_curchannelname = tmp;
  7448. + tmp.detach();
  7449. + (*it)->startChanNum = tmp;
  7450. + }
  7451. +
  7452. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + " " + ((ok) ? "success" : "failure"));
  7453. +
  7454. + return ok;
  7455. + }
  7456. +
  7457. + bool R5000Channel::Open(void)
  7458. + {
  7459. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "Open()");
  7460. +
  7461. + if (m_inputs.find(m_currentInputID) == m_inputs.end())
  7462. + return false;
  7463. +
  7464. + if (!device)
  7465. + return false;
  7466. +
  7467. + if (isopen)
  7468. + return true;
  7469. +
  7470. + if (!device->OpenPort())
  7471. + return false;
  7472. +
  7473. + isopen = true;
  7474. +
  7475. + return true;
  7476. + }
  7477. +
  7478. + void R5000Channel::Close(void)
  7479. + {
  7480. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "Close()");
  7481. + if (isopen)
  7482. + {
  7483. + device->ClosePort();
  7484. + isopen = false;
  7485. + }
  7486. + }
  7487. +
  7488. + QString R5000Channel::GetDevice(void) const
  7489. + {
  7490. + return videodevice;
  7491. + }
  7492. +
  7493. + bool R5000Channel::SetPowerState(bool on)
  7494. + {
  7495. + if (!isopen)
  7496. + {
  7497. + LOG(VB_GENERAL, LOG_DEBUG, LOC_ERR +
  7498. + "SetPowerState() called on closed R5000Channel.");
  7499. +
  7500. + return false;
  7501. + }
  7502. + if (power_on_channel_change)
  7503. + return R5000Device::kAVCPowerOn;
  7504. +
  7505. + return device->SetPowerState(on);
  7506. + }
  7507. +
  7508. + R5000Device::PowerState R5000Channel::GetPowerState(void) const
  7509. + {
  7510. + if (!isopen)
  7511. + {
  7512. + LOG(VB_GENERAL, LOG_DEBUG, LOC_ERR +
  7513. + "GetPowerState() called on closed R5000Channel.");
  7514. +
  7515. + return R5000Device::kAVCPowerQueryFailed;
  7516. + }
  7517. +
  7518. + if (power_on_channel_change)
  7519. + return R5000Device::kAVCPowerOn;
  7520. +
  7521. + return device->GetPowerState();
  7522. + }
  7523. +
  7524. + bool R5000Channel::Retune(void)
  7525. + {
  7526. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "Retune()");
  7527. +
  7528. + if (! power_on_channel_change && R5000Device::kAVCPowerOff == GetPowerState())
  7529. + {
  7530. + LOG(VB_GENERAL, LOG_DEBUG, LOC_ERR +
  7531. + "STB is turned off, must be on to retune.");
  7532. +
  7533. + return false;
  7534. + }
  7535. +
  7536. + if (current_channel.length())
  7537. + return SetChannelByNumber(current_channel, current_mpeg_prog);
  7538. +
  7539. + return false;
  7540. + }
  7541. +
  7542. + bool R5000Channel::SetChannelByNumber(const QString &channel, int mpeg_prog)
  7543. + {
  7544. + LOG(VB_CHANNEL, LOG_DEBUG, QString("SetChannelByNumber(%1)").arg(channel));
  7545. + current_channel = channel;
  7546. + current_mpeg_prog = mpeg_prog;
  7547. +
  7548. + if (! power_on_channel_change && R5000Device::kAVCPowerOff == GetPowerState())
  7549. + {
  7550. + LOG(VB_GENERAL, LOG_DEBUG, LOC_WARN +
  7551. + "STB is turned off, must be on to set channel.");
  7552. +
  7553. + SetSIStandard("mpeg");
  7554. + SetDTVInfo(0,0,0,0,1);
  7555. +
  7556. + return true; // signal monitor will call retune later...
  7557. + }
  7558. +
  7559. + QString tmpchan = (power_on_channel_change ? "P" : "") + channel;
  7560. + if (! device->SetChannel(fw_opts.model, tmpchan, mpeg_prog))
  7561. + return false;
  7562. +
  7563. + SetSIStandard("mpeg");
  7564. + SetDTVInfo(0,0,0,0,1);
  7565. +
  7566. + return true;
  7567. + }
  7568. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000channel.h ./libs/libmythtv/r5000channel.h
  7569. *** ../../mythtv/mythtv/libs/libmythtv/r5000channel.h 1969-12-31 16:00:00.000000000 -0800
  7570. --- ./libs/libmythtv/r5000channel.h 2013-02-16 10:52:50.014567132 -0800
  7571. ***************
  7572. *** 0 ****
  7573. --- 1,56 ----
  7574. + /**
  7575. + * R5000Channel
  7576. + * Copyright (c) 2008 by Alan Nisota
  7577. + * Copyright (c) 2005 by Jim Westfall and Dave Abrahams
  7578. + * Distributed as part of MythTV under GPL v2 and later.
  7579. + */
  7580. +
  7581. + #ifndef _R5000CHANNEL_H_
  7582. + #define _R5000CHANNEL_H_
  7583. +
  7584. + #include "tv_rec.h"
  7585. + #include "dtvchannel.h"
  7586. + #include "r5000device.h"
  7587. +
  7588. + class R5000Channel : public DTVChannel
  7589. + {
  7590. + public:
  7591. + R5000Channel(TVRec *parent, const QString &videodevice,
  7592. + const QString &_r5ktype, bool pocc);
  7593. + ~R5000Channel() { Close(); }
  7594. +
  7595. + // Commands
  7596. + virtual bool Open(void);
  7597. + virtual void Close(void);
  7598. +
  7599. + virtual bool TuneMultiplex(uint /*mplexid*/, QString /*inputname*/)
  7600. + { return false; }
  7601. + virtual bool Tune(const DTVMultiplex &/*tuning*/, QString /*inputname*/)
  7602. + { return false; }
  7603. + virtual bool Retune(void);
  7604. +
  7605. + // Sets
  7606. + virtual bool SetChannelByString(const QString &chan);
  7607. + virtual bool SetChannelByNumber(const QString &channel, int mpeg_prog);
  7608. + virtual bool SetPowerState(bool on);
  7609. + void SetSlowTuning(uint how_slow_in_ms)
  7610. + { tuning_delay = how_slow_in_ms; }
  7611. +
  7612. + // Gets
  7613. + virtual bool IsOpen(void) const { return isopen; }
  7614. + virtual R5000Device::PowerState GetPowerState(void) const;
  7615. + virtual QString GetDevice(void) const;
  7616. + virtual R5000Device *GetR5000Device(void) { return device; }
  7617. +
  7618. + protected:
  7619. + QString videodevice;
  7620. + FireWireDBOptions fw_opts;
  7621. + bool power_on_channel_change;
  7622. + R5000Device *device;
  7623. + QString current_channel;
  7624. + uint current_mpeg_prog;
  7625. + bool isopen;
  7626. + uint tuning_delay;///< Extra delay to add
  7627. + };
  7628. +
  7629. + #endif // _R5000CHANNEL_H_
  7630. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000device.cpp ./libs/libmythtv/r5000device.cpp
  7631. *** ../../mythtv/mythtv/libs/libmythtv/r5000device.cpp 1969-12-31 16:00:00.000000000 -0800
  7632. --- ./libs/libmythtv/r5000device.cpp 2013-02-16 10:52:50.014567132 -0800
  7633. ***************
  7634. *** 0 ****
  7635. --- 1,464 ----
  7636. + /**
  7637. + * R5000Device
  7638. + * Copyright (c) 2008 by Alan Nisota
  7639. + * Copyright (c) 2005 by Jim Westfall
  7640. + * Distributed as part of MythTV under GPL v2 and later.
  7641. + */
  7642. +
  7643. + // C++ headers
  7644. + #include <algorithm>
  7645. +
  7646. + // Qt headers
  7647. + #include <QMap>
  7648. +
  7649. + // for usleep
  7650. + #include <unistd.h>
  7651. +
  7652. + // MythTV headers
  7653. + #include "r5000device.h"
  7654. + #include "mythcontext.h"
  7655. + #include "mythlogging.h"
  7656. + #include "pespacket.h"
  7657. + #include "mthread.h"
  7658. + #include "mythtimer.h"
  7659. +
  7660. + #define LOC QString("R5kDev: ")
  7661. + #define LOC_WARN QString("R5kDev, Warning: ")
  7662. + #define LOC_ERR QString("R5kDev, Error: ")
  7663. +
  7664. + static int r5k_init = 0;
  7665. + QMap<uint64_t,QString> R5000Device::s_id_to_model;
  7666. + QMutex R5000Device::s_static_lock;
  7667. +
  7668. + unsigned int r5000_device_tspacket_handler(unsigned char *tspacket, int len, void *callback_data)
  7669. + {
  7670. + R5000Device *fw = (R5000Device*) callback_data;
  7671. + if (! fw)
  7672. + return 0;
  7673. + if (len > 0)
  7674. + fw->BroadcastToListeners(tspacket, len);
  7675. + return 1;
  7676. + }
  7677. +
  7678. + void r5000_msg(char * msg)
  7679. + {
  7680. + LOG(VB_GENERAL, LOG_INFO, LOC +
  7681. + QString("R5kLib: ") + msg);
  7682. + }
  7683. +
  7684. + class R5kPriv
  7685. + {
  7686. + public:
  7687. + R5kPriv() :
  7688. + reset_timer_on(false),
  7689. + run_port_handler(false), is_port_handler_running(false),
  7690. + channel(-1),
  7691. + is_streaming(false)
  7692. + {
  7693. + }
  7694. +
  7695. + bool reset_timer_on;
  7696. + MythTimer reset_timer;
  7697. +
  7698. + bool run_port_handler;
  7699. + bool is_port_handler_running;
  7700. + QMutex start_stop_port_handler_lock;
  7701. +
  7702. + int channel;
  7703. +
  7704. + bool is_streaming;
  7705. +
  7706. + QDateTime stop_streaming_timer;
  7707. + pthread_t port_handler_thread;
  7708. +
  7709. + static QMutex s_lock;
  7710. + };
  7711. + QMutex R5kPriv::s_lock;
  7712. +
  7713. + //callback functions
  7714. + void *r5000_device_port_handler_thunk(void *param);
  7715. +
  7716. + R5000Device::R5000Device(int type, QString serial) :
  7717. + m_type(type),
  7718. + m_serial(serial),
  7719. + m_last_channel(""), m_last_crc(0),
  7720. + m_buffer_cleared(true), m_open_port_cnt(0),
  7721. + m_lock(), m_priv(new R5kPriv())
  7722. + {
  7723. + QMutexLocker locker(&s_static_lock);
  7724. + usbdev = NULL;
  7725. + if (! r5k_init)
  7726. + r5k_init = r5000_init(r5000_msg);
  7727. + }
  7728. +
  7729. + R5000Device::~R5000Device()
  7730. + {
  7731. + if (usbdev)
  7732. + {
  7733. + LOG(VB_GENERAL, LOG_DEBUG, LOC_ERR + "ctor called with open port");
  7734. + while (usbdev)
  7735. + ClosePort();
  7736. + }
  7737. +
  7738. + if (m_priv)
  7739. + {
  7740. + delete m_priv;
  7741. + m_priv = NULL;
  7742. + }
  7743. + }
  7744. +
  7745. + void R5000Device::AddListener(TSDataListener *listener)
  7746. + {
  7747. + QMutexLocker locker(&m_lock);
  7748. + if (listener)
  7749. + {
  7750. + vector<TSDataListener*>::iterator it =
  7751. + find(m_listeners.begin(), m_listeners.end(), listener);
  7752. +
  7753. + if (it == m_listeners.end())
  7754. + m_listeners.push_back(listener);
  7755. + }
  7756. +
  7757. + LOG(VB_RECORD, LOG_INFO, LOC +
  7758. + QString("AddListener() %1").arg(m_listeners.size()));
  7759. + if (!m_listeners.empty())
  7760. + {
  7761. + StartStreaming();
  7762. + }
  7763. + }
  7764. +
  7765. + void R5000Device::RemoveListener(TSDataListener *listener)
  7766. + {
  7767. + QMutexLocker locker(&m_lock);
  7768. + vector<TSDataListener*>::iterator it = m_listeners.end();
  7769. +
  7770. + do
  7771. + {
  7772. + it = find(m_listeners.begin(), m_listeners.end(), listener);
  7773. + if (it != m_listeners.end())
  7774. + m_listeners.erase(it);
  7775. + }
  7776. + while (it != m_listeners.end());
  7777. +
  7778. + LOG(VB_RECORD, LOG_INFO, LOC +
  7779. + QString("RemoveListener() %1").arg(m_listeners.size()));
  7780. + if (m_listeners.empty())
  7781. + {
  7782. + StopStreaming();
  7783. + }
  7784. + }
  7785. +
  7786. + bool R5000Device::StartStreaming(void)
  7787. + {
  7788. + if (m_priv->is_streaming)
  7789. + return m_priv->is_streaming;
  7790. +
  7791. + if (! usbdev)
  7792. + {
  7793. + LOG(VB_GENERAL, LOG_DEBUG, LOC_ERR + "Device not open");
  7794. + return false;
  7795. + }
  7796. + if (r5000_start_stream(usbdev))
  7797. + {
  7798. + m_priv->is_streaming = true;
  7799. + }
  7800. + else
  7801. + {
  7802. + LOG(VB_GENERAL, LOG_DEBUG, LOC_ERR + "Starting A/V streaming ");
  7803. + }
  7804. +
  7805. + LOG(VB_RECORD, LOG_DEBUG, LOC + "Starting A/V streaming -- done");
  7806. +
  7807. + return m_priv->is_streaming;
  7808. + }
  7809. +
  7810. + bool R5000Device::StopStreaming(void)
  7811. + {
  7812. + if (m_priv->is_streaming)
  7813. + {
  7814. + LOG(VB_RECORD, LOG_DEBUG, LOC + "Stopping A/V streaming -- really");
  7815. +
  7816. + m_priv->is_streaming = false;
  7817. +
  7818. + r5000_stop_stream(usbdev);
  7819. + }
  7820. +
  7821. + LOG(VB_RECORD, LOG_DEBUG, LOC + "Stopped A/V streaming");
  7822. +
  7823. + return true;
  7824. + }
  7825. +
  7826. + bool R5000Device::SetPowerState(bool on)
  7827. + {
  7828. + QMutexLocker locker(&m_lock);
  7829. + QString cmdStr = (on) ? "on" : "off";
  7830. + LOG(VB_RECORD, LOG_DEBUG, LOC + QString("Powering %1").arg(cmdStr));
  7831. + r5000_power_on_off(usbdev, on);
  7832. + return true;
  7833. + }
  7834. +
  7835. + R5000Device::PowerState R5000Device::GetPowerState(void)
  7836. + {
  7837. + QMutexLocker locker(&m_lock);
  7838. + int on_off;
  7839. +
  7840. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "Requesting STB Power State");
  7841. + on_off = r5000_get_power_state(usbdev);
  7842. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + (on_off ? "On" : "Off"));
  7843. + return on_off ? kAVCPowerOn : kAVCPowerOff;
  7844. + }
  7845. +
  7846. + bool R5000Device::SetChannel(const QString &panel_model,
  7847. + const QString &channel, uint mpeg_prog)
  7848. + {
  7849. + LOG(VB_CHANNEL, LOG_DEBUG, QString("SetChannel(model %1, chan %2 mpeg_prog %3)")
  7850. + .arg(panel_model).arg(channel).arg(mpeg_prog));
  7851. +
  7852. + QMutexLocker locker(&m_lock);
  7853. + LOG(VB_CHANNEL, LOG_DEBUG, "SetChannel() -- locked");
  7854. + if (! r5000_change_channel(usbdev, channel.toAscii().constData(), mpeg_prog))
  7855. + LOG(VB_GENERAL, LOG_DEBUG, LOC + "Failed to set channel");
  7856. + return true;
  7857. + }
  7858. +
  7859. + void R5000Device::BroadcastToListeners(
  7860. + const unsigned char *data, uint dataSize)
  7861. + {
  7862. + QMutexLocker locker(&m_lock);
  7863. + if ((dataSize >= TSPacket::kSize) && (data[0] == SYNC_BYTE) &&
  7864. + ((data[1] & 0x1f) == 0) && (data[2] == 0))
  7865. + {
  7866. + ProcessPATPacket(*((const TSPacket*)data));
  7867. + }
  7868. +
  7869. + vector<TSDataListener*>::iterator it = m_listeners.begin();
  7870. + for (; it != m_listeners.end(); ++it)
  7871. + (*it)->AddData(data, dataSize);
  7872. + }
  7873. +
  7874. + void R5000Device::SetLastChannel(const QString &channel)
  7875. + {
  7876. + m_buffer_cleared = (channel == m_last_channel);
  7877. + m_last_channel = channel;
  7878. +
  7879. + LOG(VB_GENERAL, LOG_DEBUG, QString("SetLastChannel(%1): cleared: %2")
  7880. + .arg(channel).arg(m_buffer_cleared ? "yes" : "no"));
  7881. + }
  7882. +
  7883. + void R5000Device::ProcessPATPacket(const TSPacket &tspacket)
  7884. + {
  7885. + if (!tspacket.TransportError() && !tspacket.Scrambled() &&
  7886. + tspacket.HasPayload() && tspacket.PayloadStart() && !tspacket.PID())
  7887. + {
  7888. + PESPacket pes = PESPacket::View(tspacket);
  7889. + uint crc = pes.CalcCRC();
  7890. + m_buffer_cleared |= (crc != m_last_crc);
  7891. + m_last_crc = crc;
  7892. + #if 0
  7893. + LOG(VB_RECORD, LOG_DEBUG, LOC +
  7894. + QString("ProcessPATPacket: CRC 0x%1 cleared: %2")
  7895. + .arg(crc,0,16).arg(m_buffer_cleared ? "yes" : "no"));
  7896. + #endif
  7897. + }
  7898. + else
  7899. + {
  7900. + LOG(VB_GENERAL, LOG_DEBUG, LOC_ERR + "Can't handle large PAT's");
  7901. + }
  7902. + }
  7903. +
  7904. + QString R5000Device::GetModelName(uint vendor_id, uint model_id)
  7905. + {
  7906. + QMutexLocker locker(&s_static_lock);
  7907. + /*
  7908. + if (s_id_to_model.empty())
  7909. + fw_init(s_id_to_model);
  7910. +
  7911. + QString ret = s_id_to_model[(((uint64_t) vendor_id) << 32) | model_id];
  7912. +
  7913. + if (ret.isEmpty())
  7914. + return "GENERIC";
  7915. + */
  7916. + return "R5000";
  7917. + }
  7918. +
  7919. + bool R5000Device::IsSTBSupported(const QString &panel_model)
  7920. + {
  7921. + return true;
  7922. + }
  7923. +
  7924. + bool R5000Device::OpenPort(void)
  7925. + {
  7926. + LOG(VB_RECORD, LOG_DEBUG, LOC + "Starting Port Handler Thread");
  7927. + QMutexLocker mlocker(&m_lock);
  7928. + LOG(VB_RECORD, LOG_DEBUG, LOC + "Starting Port Handler Thread -- locked");
  7929. + if (usbdev)
  7930. + {
  7931. + m_open_port_cnt++;
  7932. + return true;
  7933. + }
  7934. +
  7935. + if (m_serial.length())
  7936. + {
  7937. + LOG(VB_RECORD, LOG_DEBUG, LOC + QString("Opening R5000 device type %1 with serial#: "+ m_serial).arg(m_type));
  7938. + usbdev = r5000_open((r5ktype_t)m_type, r5000_device_tspacket_handler, this, m_serial.toAscii().constData());
  7939. + }
  7940. + else
  7941. + {
  7942. + LOG(VB_RECORD, LOG_DEBUG, LOC + "Opening R5000 device with unknown serial#");
  7943. + usbdev = r5000_open((r5ktype_t)m_type, r5000_device_tspacket_handler, this, NULL);
  7944. + }
  7945. + if (! usbdev)
  7946. + {
  7947. + LOG(VB_GENERAL, LOG_DEBUG, LOC + "Failed to open R5000 device");
  7948. + return false;
  7949. + }
  7950. +
  7951. + LOG(VB_RECORD, LOG_DEBUG, LOC + "Starting port handler thread");
  7952. + m_priv->run_port_handler = true;
  7953. + pthread_create(&m_priv->port_handler_thread, NULL,
  7954. + r5000_device_port_handler_thunk, this);
  7955. +
  7956. + LOG(VB_RECORD, LOG_DEBUG, LOC + "Waiting for port handler thread to start");
  7957. + while (!m_priv->is_port_handler_running)
  7958. + {
  7959. + m_lock.unlock();
  7960. + usleep(5000);
  7961. + m_lock.lock();
  7962. + }
  7963. +
  7964. + LOG(VB_RECORD, LOG_DEBUG, LOC + "Port handler thread started");
  7965. +
  7966. + m_open_port_cnt++;
  7967. +
  7968. + return true;
  7969. + }
  7970. +
  7971. + bool R5000Device::ClosePort(void)
  7972. + {
  7973. + LOG(VB_RECORD, LOG_DEBUG, LOC + "Stopping Port Handler Thread");
  7974. + QMutexLocker locker(&m_priv->start_stop_port_handler_lock);
  7975. + LOG(VB_RECORD, LOG_DEBUG, LOC + "Stopping Port Handler Thread -- locked");
  7976. +
  7977. + QMutexLocker mlocker(&m_lock);
  7978. +
  7979. + LOG(VB_RECORD, LOG_DEBUG, LOC + "ClosePort()");
  7980. +
  7981. + if (m_open_port_cnt < 1)
  7982. + return false;
  7983. +
  7984. + m_open_port_cnt--;
  7985. +
  7986. + if (m_open_port_cnt != 0)
  7987. + return true;
  7988. +
  7989. + if (!usbdev)
  7990. + return false;
  7991. +
  7992. + LOG(VB_RECORD, LOG_DEBUG, LOC + "Waiting for port handler thread to stop");
  7993. + m_priv->run_port_handler = false;
  7994. + while (m_priv->is_port_handler_running)
  7995. + {
  7996. + m_lock.unlock();
  7997. + usleep(5000);
  7998. + m_lock.lock();
  7999. + }
  8000. + LOG(VB_RECORD, LOG_DEBUG, LOC + "Joining port handler thread");
  8001. + pthread_join(m_priv->port_handler_thread, NULL);
  8002. +
  8003. + r5000_close(usbdev);
  8004. + usbdev = NULL;
  8005. +
  8006. + return true;
  8007. + }
  8008. +
  8009. + void *r5000_device_port_handler_thunk(void *param)
  8010. + {
  8011. + R5000Device *mon = (R5000Device*) param;
  8012. + mon->RunPortHandler();
  8013. + return NULL;
  8014. + }
  8015. +
  8016. + void R5000Device::RunPortHandler(void)
  8017. + {
  8018. + LOG(VB_RECORD, LOG_DEBUG, LOC + "RunPortHandler -- start");
  8019. + m_lock.lock();
  8020. + LOG(VB_RECORD, LOG_DEBUG, LOC + "RunPortHandler -- got first lock");
  8021. + m_priv->is_port_handler_running = true;
  8022. + m_lock.unlock();
  8023. +
  8024. + while (m_priv->run_port_handler)
  8025. + {
  8026. + if (m_priv->is_streaming)
  8027. + {
  8028. + // This will timeout after 10ms regardless of data availability
  8029. + r5000_loop_iterate(usbdev, 10);
  8030. + }
  8031. + else
  8032. + {
  8033. + usleep(10000);
  8034. + }
  8035. + }
  8036. +
  8037. + m_lock.lock();
  8038. + m_priv->is_port_handler_running = false;
  8039. + m_lock.unlock();
  8040. + LOG(VB_RECORD, LOG_DEBUG, LOC + "RunPortHandler -- end");
  8041. + }
  8042. +
  8043. + QStringList R5000Device::GetSTBList(void)
  8044. + {
  8045. + QStringList STBList;
  8046. + int i;
  8047. + r5kenum_t r5k_stbs;
  8048. + if (! r5k_init)
  8049. + {
  8050. + r5k_init = r5000_init(r5000_msg);
  8051. + if (! r5k_init)
  8052. + return STBList;
  8053. + }
  8054. + if (! r5000_find_stbs(&r5k_stbs))
  8055. + LOG(VB_GENERAL, LOG_DEBUG, LOC + "Locating R5000 devices failed."
  8056. + " This may be a permission problem");
  8057. +
  8058. + for (i = 0; i < r5k_stbs.count; i++)
  8059. + STBList.append((char *)r5k_stbs.serial[i]);
  8060. + return STBList;
  8061. + }
  8062. +
  8063. + int R5000Device::GetDeviceType(const QString &r5ktype)
  8064. + {
  8065. + QString type = r5ktype.toUpper();
  8066. + if (type == "DIRECTV")
  8067. + {
  8068. + return R5K_STB_DIRECTV;
  8069. + }
  8070. + else if ("VIP211/VIP622/DISH411" == type ||
  8071. + "VIP211/VIP422" == type ||
  8072. + "VIP211" == type ||
  8073. + "VIP411" == type)
  8074. + {
  8075. + return R5K_STB_VIP211;
  8076. + }
  8077. + else if ("STARCHOICE/DSR" == type)
  8078. + {
  8079. + return R5K_STB_DSR;
  8080. + }
  8081. + else if ("HDD-200" == type)
  8082. + {
  8083. + return R5K_STB_HDD;
  8084. + }
  8085. + else if ("VIP622" == type ||
  8086. + "VIP722" == type ||
  8087. + "BEV9242" == type)
  8088. + {
  8089. + return R5K_STB_VIP622;
  8090. + }
  8091. + else if ("DISH6000" == type)
  8092. + {
  8093. + return R5K_STB_DISH6000;
  8094. + }
  8095. + else
  8096. + {
  8097. + return R5K_STB_VIP211;
  8098. + }
  8099. + }
  8100. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000device.h ./libs/libmythtv/r5000device.h
  8101. *** ../../mythtv/mythtv/libs/libmythtv/r5000device.h 1969-12-31 16:00:00.000000000 -0800
  8102. --- ./libs/libmythtv/r5000device.h 2013-02-16 10:52:50.018567158 -0800
  8103. ***************
  8104. *** 0 ****
  8105. --- 1,110 ----
  8106. + /**
  8107. + * R5000Device
  8108. + * Copyright (c) 2005 by Jim Westfall
  8109. + * Distributed as part of MythTV under GPL v2 and later.
  8110. + */
  8111. +
  8112. + #ifndef _R5000_DEVICE_H_
  8113. + #define _R5000_DEVICE_H_
  8114. +
  8115. + // C++ headers
  8116. + #include <vector>
  8117. + using namespace std;
  8118. +
  8119. + // Qt headers
  8120. + #include <qstring.h>
  8121. + #include <qmutex.h>
  8122. +
  8123. + // MythTV headers
  8124. + #include "streamlisteners.h"
  8125. +
  8126. + extern "C" {
  8127. + #include "r5000/r5000.h"
  8128. + }
  8129. +
  8130. + class TSPacket;
  8131. + class R5kPriv;
  8132. + class R5000Device
  8133. + {
  8134. + public:
  8135. +
  8136. + // Public enums
  8137. + typedef enum
  8138. + {
  8139. + kAVCPowerOn,
  8140. + kAVCPowerOff,
  8141. + kAVCPowerUnknown,
  8142. + kAVCPowerQueryFailed,
  8143. + } PowerState;
  8144. +
  8145. +
  8146. + // AVC param 0
  8147. + typedef enum
  8148. + {
  8149. + kAVCPowerStateOn = 0x70,
  8150. + kAVCPowerStateOff = 0x60,
  8151. + kAVCPowerStateQuery = 0x7f,
  8152. + } IEEE1394UnitPowerParam0;
  8153. +
  8154. + R5000Device(int type, QString serial);
  8155. + ~R5000Device();
  8156. +
  8157. + bool OpenPort(void);
  8158. + bool ClosePort(void);
  8159. + void RunPortHandler(void);
  8160. +
  8161. + // Commands
  8162. + virtual bool ResetBus(void) { return false; }
  8163. +
  8164. + virtual void AddListener(TSDataListener*);
  8165. + virtual void RemoveListener(TSDataListener*);
  8166. +
  8167. + // Sets
  8168. + virtual bool SetPowerState(bool on);
  8169. + virtual bool SetChannel(const QString &panel_model,
  8170. + const QString &channel, uint mpeg_prog);
  8171. +
  8172. + // Gets
  8173. + bool IsSTBBufferCleared(void) const { return m_buffer_cleared; }
  8174. +
  8175. + // non-const Gets
  8176. + virtual PowerState GetPowerState(void);
  8177. +
  8178. + // Statics
  8179. + static bool IsSTBSupported(const QString &model);
  8180. + static QString GetModelName(uint vendorid, uint modelid);
  8181. + static QStringList GetSTBList(void);
  8182. + static int GetDeviceType(const QString &r5ktype);
  8183. + void BroadcastToListeners(
  8184. + const unsigned char *data, uint dataSize);
  8185. +
  8186. + protected:
  8187. +
  8188. + bool GetSubunitInfo(uint8_t table[32]);
  8189. +
  8190. + void SetLastChannel(const QString &channel);
  8191. + void ProcessPATPacket(const TSPacket&);
  8192. + bool StartStreaming(void);
  8193. + bool StopStreaming(void);
  8194. +
  8195. + int m_type;
  8196. + QString m_serial;
  8197. + uint m_subunitid;
  8198. + uint m_speed;
  8199. + QString m_last_channel;
  8200. + uint m_last_crc;
  8201. + bool m_buffer_cleared;
  8202. +
  8203. + uint m_open_port_cnt;
  8204. + vector<TSDataListener*> m_listeners;
  8205. + mutable QMutex m_lock;
  8206. +
  8207. + /// Vendor ID + Model ID to R5000Device STB model string
  8208. + static QMap<uint64_t,QString> s_id_to_model;
  8209. + static QMutex s_static_lock;
  8210. + private:
  8211. + r5kdev_t *usbdev;
  8212. + R5kPriv *m_priv;
  8213. + };
  8214. +
  8215. + #endif // _FIREWIRE_DEVICE_H_
  8216. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000recorder.cpp ./libs/libmythtv/r5000recorder.cpp
  8217. *** ../../mythtv/mythtv/libs/libmythtv/r5000recorder.cpp 1969-12-31 16:00:00.000000000 -0800
  8218. --- ./libs/libmythtv/r5000recorder.cpp 2013-02-16 10:52:50.010567105 -0800
  8219. ***************
  8220. *** 0 ****
  8221. --- 1,285 ----
  8222. + /**
  8223. + * R5000Recorder
  8224. + * Copyright (c) 2005 by Jim Westfall and Dave Abrahams
  8225. + * Distributed as part of MythTV under GPL v2 and later.
  8226. + */
  8227. +
  8228. + // MythTV includes
  8229. + #include "r5000recorder.h"
  8230. + #include "r5000channel.h"
  8231. + #include "mythcontext.h"
  8232. + #include "mpegtables.h"
  8233. + #include "mpegstreamdata.h"
  8234. + #include "tv_rec.h"
  8235. +
  8236. + #define LOC QString("R5000RecBase(%1): ").arg(channel->GetDevice())
  8237. + #define LOC_ERR QString("R5000RecBase(%1), Error: ").arg(channel->GetDevice())
  8238. +
  8239. + R5000Recorder::R5000Recorder(TVRec *rec, R5000Channel *chan) :
  8240. + DTVRecorder(rec),
  8241. + channel(chan), isopen(false)
  8242. + {
  8243. + //_wait_for_keyframe_option = false;
  8244. + }
  8245. +
  8246. + R5000Recorder::~R5000Recorder()
  8247. + {
  8248. + Close();
  8249. + }
  8250. +
  8251. + bool R5000Recorder::Open(void)
  8252. + {
  8253. + if (!isopen)
  8254. + isopen = channel->GetR5000Device()->OpenPort();
  8255. +
  8256. + return isopen;
  8257. + }
  8258. +
  8259. + void R5000Recorder::Close(void)
  8260. + {
  8261. + if (isopen)
  8262. + {
  8263. + channel->GetR5000Device()->ClosePort();
  8264. + isopen = false;
  8265. + }
  8266. + }
  8267. +
  8268. + void R5000Recorder::StartStreaming(void)
  8269. + {
  8270. + channel->GetR5000Device()->AddListener(this);
  8271. + }
  8272. +
  8273. + void R5000Recorder::StopStreaming(void)
  8274. + {
  8275. + channel->GetR5000Device()->RemoveListener(this);
  8276. + }
  8277. +
  8278. + void R5000Recorder::StartRecording(void)
  8279. + {
  8280. + LOG(VB_RECORD, LOG_DEBUG, LOC + "StartRecording");
  8281. +
  8282. + if (!Open())
  8283. + {
  8284. + _error = true;
  8285. + return;
  8286. + }
  8287. +
  8288. + request_recording = true;
  8289. + recording = true;
  8290. +
  8291. + StartStreaming();
  8292. +
  8293. + while (request_recording)
  8294. + {
  8295. + if (!PauseAndWait())
  8296. + usleep(50 * 1000);
  8297. + }
  8298. +
  8299. + StopStreaming();
  8300. + FinishRecording();
  8301. +
  8302. + recording = false;
  8303. + }
  8304. +
  8305. + void R5000Recorder::run(void)
  8306. + {
  8307. + LOG(VB_RECORD, LOG_INFO, LOC + "run");
  8308. +
  8309. + if (!Open())
  8310. + {
  8311. + _error = "Failed to open R5000 device";
  8312. + LOG(VB_GENERAL, LOG_ERR, LOC + _error);
  8313. + return;
  8314. + }
  8315. +
  8316. + {
  8317. + QMutexLocker locker(&pauseLock);
  8318. + request_recording = true;
  8319. + recording = true;
  8320. + recordingWait.wakeAll();
  8321. + }
  8322. +
  8323. + StartStreaming();
  8324. +
  8325. + while (IsRecordingRequested() && !IsErrored())
  8326. + {
  8327. + if (PauseAndWait())
  8328. + continue;
  8329. +
  8330. + if (!IsRecordingRequested())
  8331. + break;
  8332. +
  8333. + { // sleep 1 seconds unless StopRecording() or Unpause() is called,
  8334. + // just to avoid running this too often.
  8335. + QMutexLocker locker(&pauseLock);
  8336. + if (!request_recording || request_pause)
  8337. + continue;
  8338. + unpauseWait.wait(&pauseLock, 1000);
  8339. + }
  8340. + }
  8341. +
  8342. + StopStreaming();
  8343. + FinishRecording();
  8344. +
  8345. + QMutexLocker locker(&pauseLock);
  8346. + recording = false;
  8347. + recordingWait.wakeAll();
  8348. + }
  8349. +
  8350. + void R5000Recorder::AddData(const unsigned char *data, uint len)
  8351. + {
  8352. + uint bufsz = buffer.size();
  8353. + if ((SYNC_BYTE == data[0]) && (TSPacket::kSize == len) &&
  8354. + (TSPacket::kSize > bufsz))
  8355. + {
  8356. + if (bufsz)
  8357. + buffer.clear();
  8358. +
  8359. + ProcessTSPacket(*(reinterpret_cast<const TSPacket*>(data)));
  8360. + return;
  8361. + }
  8362. +
  8363. + buffer.insert(buffer.end(), data, data + len);
  8364. + bufsz += len;
  8365. +
  8366. + int sync_at = -1;
  8367. + for (uint i = 0; (i < bufsz) && (sync_at < 0); i++)
  8368. + {
  8369. + if (buffer[i] == SYNC_BYTE)
  8370. + sync_at = i;
  8371. + }
  8372. +
  8373. + if (sync_at < 0)
  8374. + return;
  8375. +
  8376. + if (bufsz < 30 * TSPacket::kSize)
  8377. + return; // build up a little buffer
  8378. +
  8379. + while (sync_at + TSPacket::kSize < bufsz)
  8380. + {
  8381. + ProcessTSPacket(*(reinterpret_cast<const TSPacket*>(
  8382. + &buffer[0] + sync_at)));
  8383. +
  8384. + sync_at += TSPacket::kSize;
  8385. + }
  8386. +
  8387. + buffer.erase(buffer.begin(), buffer.begin() + sync_at);
  8388. +
  8389. + return;
  8390. + }
  8391. +
  8392. + bool R5000Recorder::ProcessTSPacket(const TSPacket &tspacket)
  8393. + {
  8394. + if (tspacket.TransportError())
  8395. + return true;
  8396. +
  8397. + if (tspacket.Scrambled())
  8398. + return true;
  8399. +
  8400. + if (! GetStreamData())
  8401. + return true;
  8402. + if (tspacket.HasAdaptationField())
  8403. + GetStreamData()->HandleAdaptationFieldControl(&tspacket);
  8404. +
  8405. + if (tspacket.HasPayload())
  8406. + {
  8407. + const unsigned int lpid = tspacket.PID();
  8408. + // Pass or reject packets based on PID, and parse info from them
  8409. + if (lpid == GetStreamData()->VideoPIDSingleProgram())
  8410. + {
  8411. + ProgramMapTable *pmt = GetStreamData()->PMTSingleProgram();
  8412. + uint video_stream_type = pmt->StreamType(pmt->FindPID(lpid));
  8413. +
  8414. + if (video_stream_type == StreamID::H264Video)
  8415. + _buffer_packets = !FindH264Keyframes(&tspacket);
  8416. + else if (StreamID::IsVideo(video_stream_type))
  8417. + _buffer_packets = !FindMPEG2Keyframes(&tspacket);
  8418. +
  8419. + if ((video_stream_type != StreamID::H264Video) || _seen_sps)
  8420. + BufferedWrite(tspacket);
  8421. + }
  8422. + else if (GetStreamData()->IsAudioPID(lpid))
  8423. + {
  8424. + _buffer_packets = !FindAudioKeyframes(&tspacket);
  8425. + BufferedWrite(tspacket);
  8426. + }
  8427. + else if (GetStreamData()->IsListeningPID(lpid))
  8428. + GetStreamData()->HandleTSTables(&tspacket);
  8429. + else if (GetStreamData()->IsWritingPID(lpid))
  8430. + BufferedWrite(tspacket);
  8431. + }
  8432. +
  8433. + return true;
  8434. + }
  8435. +
  8436. + void R5000Recorder::SetOptionsFromProfile(RecordingProfile *profile,
  8437. + const QString &videodev,
  8438. + const QString &audiodev,
  8439. + const QString &vbidev)
  8440. + {
  8441. + (void)videodev;
  8442. + (void)audiodev;
  8443. + (void)vbidev;
  8444. + (void)profile;
  8445. + }
  8446. +
  8447. + // documented in recorderbase.cpp
  8448. + bool R5000Recorder::PauseAndWait(int timeout)
  8449. + {
  8450. + if (request_pause)
  8451. + {
  8452. + LOG(VB_RECORD, LOG_INFO, LOC +
  8453. + QString("PauseAndWait(%1) -- pause").arg(timeout));
  8454. + if (!IsPaused(true))
  8455. + {
  8456. + StopStreaming();
  8457. + paused = true;
  8458. + pauseWait.wakeAll();
  8459. + if (tvrec)
  8460. + tvrec->RecorderPaused();
  8461. + }
  8462. + QMutex unpause_lock;
  8463. + unpause_lock.lock();
  8464. + unpauseWait.wait(&unpause_lock, timeout);
  8465. + }
  8466. + if (!request_pause && IsPaused(true))
  8467. + {
  8468. + LOG(VB_RECORD, LOG_INFO, LOC +
  8469. + QString("PauseAndWait(%1) -- unpause").arg(timeout));
  8470. + StartStreaming();
  8471. + paused = false;
  8472. + }
  8473. + return paused;
  8474. + }
  8475. +
  8476. + void R5000Recorder::SetStreamData(void)
  8477. + {
  8478. + _stream_data->AddMPEGSPListener(this);
  8479. +
  8480. + if (_stream_data->DesiredProgram() >= 0)
  8481. + _stream_data->SetDesiredProgram(_stream_data->DesiredProgram());
  8482. + }
  8483. +
  8484. + void R5000Recorder::HandleSingleProgramPAT(ProgramAssociationTable *pat)
  8485. + {
  8486. + if (!pat)
  8487. + {
  8488. + LOG(VB_RECORD, LOG_DEBUG, LOC + "HandleSingleProgramPAT(NULL)");
  8489. + return;
  8490. + }
  8491. + int next = (pat->tsheader()->ContinuityCounter()+1)&0xf;
  8492. + pat->tsheader()->SetContinuityCounter(next);
  8493. + BufferedWrite(*(reinterpret_cast<const TSPacket*>(pat->tsheader())));
  8494. + }
  8495. +
  8496. + void R5000Recorder::HandleSingleProgramPMT(ProgramMapTable *pmt)
  8497. + {
  8498. + if (!pmt)
  8499. + {
  8500. + LOG(VB_RECORD, LOG_DEBUG, LOC + "HandleSingleProgramPMT(NULL)");
  8501. + return;
  8502. + }
  8503. + int next = (pmt->tsheader()->ContinuityCounter()+1)&0xf;
  8504. + pmt->tsheader()->SetContinuityCounter(next);
  8505. + BufferedWrite(*(reinterpret_cast<const TSPacket*>(pmt->tsheader())));
  8506. + }
  8507. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000recorder.h ./libs/libmythtv/r5000recorder.h
  8508. *** ../../mythtv/mythtv/libs/libmythtv/r5000recorder.h 1969-12-31 16:00:00.000000000 -0800
  8509. --- ./libs/libmythtv/r5000recorder.h 2013-02-16 10:52:50.014567132 -0800
  8510. ***************
  8511. *** 0 ****
  8512. --- 1,69 ----
  8513. + /**
  8514. + * R5000Recorder
  8515. + * Copyright (c) 2005 by Jim Westfall
  8516. + * Distributed as part of MythTV under GPL v2 and later.
  8517. + */
  8518. +
  8519. + #ifndef _R5000RECORDER_H_
  8520. + #define _R5000RECORDER_H_
  8521. +
  8522. + // MythTV headers
  8523. + #include "dtvrecorder.h"
  8524. + #include "tspacket.h"
  8525. + #include "streamlisteners.h"
  8526. +
  8527. + class TVRec;
  8528. + class R5000Channel;
  8529. +
  8530. + /** \class R5000Recorder
  8531. + * \brief This is a specialization of DTVRecorder used to
  8532. + * handle DVB and ATSC streams from a firewire input.
  8533. + *
  8534. + * \sa DTVRecorder
  8535. + */
  8536. + class R5000Recorder : public DTVRecorder,
  8537. + // public MPEGSingleProgramStreamListener,
  8538. + public TSDataListener
  8539. + {
  8540. + friend class MPEGStreamData;
  8541. + friend class TSPacketProcessor;
  8542. +
  8543. + public:
  8544. + R5000Recorder(TVRec *rec, R5000Channel *chan);
  8545. + virtual ~R5000Recorder();
  8546. +
  8547. + // Commands
  8548. + bool Open(void);
  8549. + void Close(void);
  8550. +
  8551. + void StartStreaming(void);
  8552. + void StopStreaming(void);
  8553. +
  8554. + void StartRecording(void);
  8555. + void run(void);
  8556. + bool PauseAndWait(int timeout = 100);
  8557. +
  8558. + void AddData(const unsigned char *data, uint dataSize);
  8559. + bool ProcessTSPacket(const TSPacket &tspacket);
  8560. +
  8561. + // Sets
  8562. + void SetOptionsFromProfile(RecordingProfile *profile,
  8563. + const QString &videodev,
  8564. + const QString &audiodev,
  8565. + const QString &vbidev);
  8566. + void SetStreamData(void);
  8567. +
  8568. + // MPEG Single Program
  8569. + void HandleSingleProgramPAT(ProgramAssociationTable*);
  8570. + void HandleSingleProgramPMT(ProgramMapTable*);
  8571. +
  8572. + protected:
  8573. + R5000Recorder(TVRec *rec);
  8574. +
  8575. + private:
  8576. + R5000Channel *channel;
  8577. + bool isopen;
  8578. + vector<unsigned char> buffer;
  8579. + };
  8580. +
  8581. + #endif // _R5000RECORDER_H_
  8582. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000signalmonitor.cpp ./libs/libmythtv/r5000signalmonitor.cpp
  8583. *** ../../mythtv/mythtv/libs/libmythtv/r5000signalmonitor.cpp 1969-12-31 16:00:00.000000000 -0800
  8584. --- ./libs/libmythtv/r5000signalmonitor.cpp 2013-02-16 10:52:50.010567105 -0800
  8585. ***************
  8586. *** 0 ****
  8587. --- 1,294 ----
  8588. + // -*- Mode: c++ -*-
  8589. + // Copyright (c) 2006, Daniel Thor Kristjansson
  8590. +
  8591. + #include <pthread.h>
  8592. + #include <fcntl.h>
  8593. + #include <unistd.h>
  8594. + #include <sys/select.h>
  8595. +
  8596. + #include "mythcontext.h"
  8597. + #include "mythdbcon.h"
  8598. + #include "atscstreamdata.h"
  8599. + #include "mpegtables.h"
  8600. + #include "atsctables.h"
  8601. + #include "r5000channel.h"
  8602. + #include "r5000signalmonitor.h"
  8603. +
  8604. + #define LOC QString("R5kSM(%1): ").arg(channel->GetDevice())
  8605. + #define LOC_WARN QString("R5kSM(%1), Warning: ").arg(channel->GetDevice())
  8606. + #define LOC_ERR QString("R5kSM(%1), Error: ").arg(channel->GetDevice())
  8607. +
  8608. + const uint R5000SignalMonitor::kPowerTimeout = 3000; /* ms */
  8609. + const uint R5000SignalMonitor::kBufferTimeout = 5000; /* ms */
  8610. +
  8611. + QMap<void*,uint> R5000SignalMonitor::pat_keys;
  8612. + QMutex R5000SignalMonitor::pat_keys_lock;
  8613. +
  8614. + /** \fn R5000SignalMonitor::R5000SignalMonitor(int,R5000Channel*,uint,const char*)
  8615. + * \brief Initializes signal lock and signal values.
  8616. + *
  8617. + * Start() must be called to actually begin continuous
  8618. + * signal monitoring. The timeout is set to 3 seconds,
  8619. + * and the signal threshold is initialized to 0%.
  8620. + *
  8621. + * \param db_cardnum Recorder number to monitor,
  8622. + * if this is less than 0, SIGNAL events will not be
  8623. + * sent to the frontend even if SetNotifyFrontend(true)
  8624. + * is called.
  8625. + * \param _channel R5000Channel for card
  8626. + * \param _flags Flags to start with
  8627. + * \param _name Name for Qt signal debugging
  8628. + */
  8629. + R5000SignalMonitor::R5000SignalMonitor(
  8630. + int db_cardnum,
  8631. + R5000Channel *_channel,
  8632. + uint64_t _flags, const char *_name) :
  8633. + DTVSignalMonitor(db_cardnum, _channel, _flags),
  8634. + dtvMonitorRunning(false),
  8635. + stb_needs_retune(true),
  8636. + stb_needs_to_wait_for_pat(false),
  8637. + stb_needs_to_wait_for_power(false)
  8638. + {
  8639. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "ctor");
  8640. +
  8641. + signalStrength.SetThreshold(65);
  8642. +
  8643. + AddFlags(kSigMon_WaitForSig);
  8644. +
  8645. + stb_needs_retune =
  8646. + (R5000Device::kAVCPowerOff == _channel->GetPowerState());
  8647. + }
  8648. +
  8649. + /** \fn R5000SignalMonitor::~R5000SignalMonitor()
  8650. + * \brief Stops signal monitoring and table monitoring threads.
  8651. + */
  8652. + R5000SignalMonitor::~R5000SignalMonitor()
  8653. + {
  8654. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "dtor");
  8655. + Stop();
  8656. + }
  8657. +
  8658. + /** \fn R5000SignalMonitor::Stop(void)
  8659. + * \brief Stop signal monitoring and table monitoring threads.
  8660. + */
  8661. + void R5000SignalMonitor::Stop(void)
  8662. + {
  8663. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "Stop() -- begin");
  8664. + SignalMonitor::Stop();
  8665. + if (dtvMonitorRunning)
  8666. + {
  8667. + dtvMonitorRunning = false;
  8668. + pthread_join(table_monitor_thread, NULL);
  8669. + }
  8670. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "Stop() -- end");
  8671. + }
  8672. +
  8673. + void R5000SignalMonitor::HandlePAT(const ProgramAssociationTable *pat)
  8674. + {
  8675. + AddFlags(kDTVSigMon_PATSeen);
  8676. +
  8677. + R5000Channel *fwchan = dynamic_cast<R5000Channel*>(channel);
  8678. + if (!fwchan)
  8679. + return;
  8680. +
  8681. + bool crc_bogus = !fwchan->GetR5000Device()->IsSTBBufferCleared();
  8682. + if (crc_bogus && stb_needs_to_wait_for_pat &&
  8683. + (stb_wait_for_pat_timer.elapsed() < (int)kBufferTimeout))
  8684. + {
  8685. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "HandlePAT() ignoring PAT");
  8686. + uint tsid = pat->TransportStreamID();
  8687. + GetStreamData()->SetVersionPAT(tsid, -1,0);
  8688. + return;
  8689. + }
  8690. +
  8691. + if (crc_bogus && stb_needs_to_wait_for_pat)
  8692. + {
  8693. + LOG(VB_GENERAL, LOG_DEBUG, LOC_WARN + "Wait for valid PAT timed out");
  8694. + stb_needs_to_wait_for_pat = false;
  8695. + }
  8696. +
  8697. + DTVSignalMonitor::HandlePAT(pat);
  8698. + }
  8699. +
  8700. + void R5000SignalMonitor::HandlePMT(uint pnum, const ProgramMapTable *pmt)
  8701. + {
  8702. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "HandlePMT()");
  8703. +
  8704. + AddFlags(kDTVSigMon_PMTSeen);
  8705. +
  8706. + if (!HasFlags(kDTVSigMon_PATMatch))
  8707. + {
  8708. + GetStreamData()->SetVersionPMT(pnum, -1,0);
  8709. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "HandlePMT() ignoring PMT");
  8710. + return;
  8711. + }
  8712. +
  8713. + DTVSignalMonitor::HandlePMT(pnum, pmt);
  8714. + }
  8715. +
  8716. + void *R5000SignalMonitor::TableMonitorThread(void *param)
  8717. + {
  8718. + R5000SignalMonitor *mon = (R5000SignalMonitor*) param;
  8719. + mon->RunTableMonitor();
  8720. + return NULL;
  8721. + }
  8722. +
  8723. + void R5000SignalMonitor::RunTableMonitor(void)
  8724. + {
  8725. + stb_needs_to_wait_for_pat = true;
  8726. + stb_wait_for_pat_timer.start();
  8727. + dtvMonitorRunning = true;
  8728. +
  8729. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "RunTableMonitor(): -- begin");
  8730. +
  8731. + R5000Channel *lchan = dynamic_cast<R5000Channel*>(channel);
  8732. + if (!lchan)
  8733. + {
  8734. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "RunTableMonitor(): -- err end");
  8735. + dtvMonitorRunning = false;
  8736. + return;
  8737. + }
  8738. +
  8739. + R5000Device *dev = lchan->GetR5000Device();
  8740. +
  8741. + dev->OpenPort();
  8742. + dev->AddListener(this);
  8743. +
  8744. + while (dtvMonitorRunning && GetStreamData())
  8745. + usleep(100000);
  8746. +
  8747. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "RunTableMonitor(): -- shutdown ");
  8748. +
  8749. + dev->RemoveListener(this);
  8750. + dev->ClosePort();
  8751. +
  8752. + dtvMonitorRunning = false;
  8753. +
  8754. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "RunTableMonitor(): -- end");
  8755. + }
  8756. +
  8757. + void R5000SignalMonitor::AddData(const unsigned char *data, uint len)
  8758. + {
  8759. + if (!dtvMonitorRunning)
  8760. + return;
  8761. +
  8762. + if (GetStreamData())
  8763. + GetStreamData()->ProcessData((unsigned char *)data, len);
  8764. + }
  8765. +
  8766. + /** \fn R5000SignalMonitor::UpdateValues(void)
  8767. + * \brief Fills in frontend stats and emits status Qt signals.
  8768. + *
  8769. + * This function uses five ioctl's FE_READ_SNR, FE_READ_SIGNAL_STRENGTH
  8770. + * FE_READ_BER, FE_READ_UNCORRECTED_BLOCKS, and FE_READ_STATUS to obtain
  8771. + * statistics from the frontend.
  8772. + *
  8773. + * This is automatically called by MonitorLoop(), after Start()
  8774. + * has been used to start the signal monitoring thread.
  8775. + */
  8776. + void R5000SignalMonitor::UpdateValues(void)
  8777. + {
  8778. + if (!running || exit)
  8779. + return;
  8780. +
  8781. + //if (!IsChannelTuned())
  8782. + // return;
  8783. +
  8784. + if (dtvMonitorRunning)
  8785. + {
  8786. + EmitStatus();
  8787. + if (IsAllGood())
  8788. + SendMessageAllGood();
  8789. + // TODO dtv signals...
  8790. +
  8791. + update_done = true;
  8792. + return;
  8793. + }
  8794. +
  8795. + if (stb_needs_to_wait_for_power &&
  8796. + (stb_wait_for_power_timer.elapsed() < (int)kPowerTimeout))
  8797. + {
  8798. + return;
  8799. + }
  8800. + stb_needs_to_wait_for_power = false;
  8801. +
  8802. + R5000Channel *fwchan = dynamic_cast<R5000Channel*>(channel);
  8803. + if (!fwchan)
  8804. + return;
  8805. +
  8806. + if (HasFlags(kFWSigMon_WaitForPower) && !HasFlags(kFWSigMon_PowerMatch))
  8807. + {
  8808. + bool retried = false;
  8809. + while (true)
  8810. + {
  8811. + R5000Device::PowerState power = fwchan->GetPowerState();
  8812. + if (R5000Device::kAVCPowerOn == power)
  8813. + {
  8814. + AddFlags(kFWSigMon_PowerSeen | kFWSigMon_PowerMatch);
  8815. + }
  8816. + else if (R5000Device::kAVCPowerOff == power)
  8817. + {
  8818. + AddFlags(kFWSigMon_PowerSeen);
  8819. + fwchan->SetPowerState(true);
  8820. + stb_wait_for_power_timer.start();
  8821. + stb_needs_to_wait_for_power = true;
  8822. + }
  8823. + else
  8824. + {
  8825. + bool qfailed = (R5000Device::kAVCPowerQueryFailed == power);
  8826. + if (qfailed && !retried)
  8827. + {
  8828. + retried = true;
  8829. + continue;
  8830. + }
  8831. +
  8832. + LOG(VB_RECORD, LOG_INFO, "Can't determine if STB is power on, "
  8833. + "assuming it is...");
  8834. + AddFlags(kFWSigMon_PowerSeen | kFWSigMon_PowerMatch);
  8835. + }
  8836. + break;
  8837. + }
  8838. + }
  8839. +
  8840. + bool isLocked = !HasFlags(kFWSigMon_WaitForPower) ||
  8841. + HasFlags(kFWSigMon_WaitForPower | kFWSigMon_PowerMatch);
  8842. +
  8843. + if (isLocked && stb_needs_retune)
  8844. + {
  8845. + fwchan->Retune();
  8846. + isLocked = stb_needs_retune = false;
  8847. + }
  8848. +
  8849. + // Set SignalMonitorValues from info from card.
  8850. + {
  8851. + QMutexLocker locker(&statusLock);
  8852. + signalStrength.SetValue(isLocked ? 100 : 0);
  8853. + signalLock.SetValue(isLocked ? 1 : 0);
  8854. + }
  8855. +
  8856. + EmitStatus();
  8857. + if (IsAllGood())
  8858. + SendMessageAllGood();
  8859. +
  8860. + // Start table monitoring if we are waiting on any table
  8861. + // and we have a lock.
  8862. + if (isLocked && GetStreamData() &&
  8863. + HasAnyFlag(kDTVSigMon_WaitForPAT | kDTVSigMon_WaitForPMT |
  8864. + kDTVSigMon_WaitForMGT | kDTVSigMon_WaitForVCT |
  8865. + kDTVSigMon_WaitForNIT | kDTVSigMon_WaitForSDT))
  8866. + {
  8867. + pthread_create(&table_monitor_thread, NULL,
  8868. + TableMonitorThread, this);
  8869. +
  8870. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "UpdateValues() -- "
  8871. + "Waiting for table monitor to start");
  8872. +
  8873. + while (!dtvMonitorRunning)
  8874. + usleep(50);
  8875. +
  8876. + LOG(VB_CHANNEL, LOG_DEBUG, LOC + "UpdateValues() -- "
  8877. + "Table monitor started");
  8878. + }
  8879. +
  8880. + update_done = true;
  8881. + }
  8882. diff -crBN ../../mythtv/mythtv/libs/libmythtv/r5000signalmonitor.h ./libs/libmythtv/r5000signalmonitor.h
  8883. *** ../../mythtv/mythtv/libs/libmythtv/r5000signalmonitor.h 1969-12-31 16:00:00.000000000 -0800
  8884. --- ./libs/libmythtv/r5000signalmonitor.h 2013-02-16 10:52:50.018567158 -0800
  8885. ***************
  8886. *** 0 ****
  8887. --- 1,61 ----
  8888. + // -*- Mode: c++ -*-
  8889. +
  8890. + #ifndef _R5000SIGNALMONITOR_H_
  8891. + #define _R5000SIGNALMONITOR_H_
  8892. +
  8893. + #include <qmap.h>
  8894. + #include <qmutex.h>
  8895. + #include <qdatetime.h>
  8896. +
  8897. + #include "dtvsignalmonitor.h"
  8898. + #include "r5000device.h"
  8899. + //#include "util.h"
  8900. +
  8901. + class R5000Channel;
  8902. +
  8903. + class R5000SignalMonitor : public DTVSignalMonitor, public TSDataListener
  8904. + {
  8905. + public:
  8906. + R5000SignalMonitor(int db_cardnum, R5000Channel *_channel,
  8907. + uint64_t _flags = kFWSigMon_WaitForPower,
  8908. + const char *_name = "R5000SignalMonitor");
  8909. +
  8910. + virtual void HandlePAT(const ProgramAssociationTable*);
  8911. + virtual void HandlePMT(uint, const ProgramMapTable*);
  8912. +
  8913. + void Stop(void);
  8914. +
  8915. + protected:
  8916. + R5000SignalMonitor(void);
  8917. + R5000SignalMonitor(const R5000SignalMonitor&);
  8918. + virtual ~R5000SignalMonitor();
  8919. +
  8920. + virtual void UpdateValues(void);
  8921. +
  8922. + static void *TableMonitorThread(void *param);
  8923. + void RunTableMonitor(void);
  8924. +
  8925. + bool SupportsTSMonitoring(void);
  8926. +
  8927. + void AddData(const unsigned char *data, uint dataSize);
  8928. +
  8929. + public:
  8930. + static const uint kPowerTimeout;
  8931. + static const uint kBufferTimeout;
  8932. +
  8933. + protected:
  8934. + bool dtvMonitorRunning;
  8935. + pthread_t table_monitor_thread;
  8936. + bool stb_needs_retune;
  8937. + bool stb_needs_to_wait_for_pat;
  8938. + bool stb_needs_to_wait_for_power;
  8939. + MythTimer stb_wait_for_pat_timer;
  8940. + MythTimer stb_wait_for_power_timer;
  8941. +
  8942. + vector<unsigned char> buffer;
  8943. +
  8944. + static QMap<void*,uint> pat_keys;
  8945. + static QMutex pat_keys_lock;
  8946. + };
  8947. +
  8948. + #endif // _R5000SIGNALMONITOR_H_
  8949. diff -crBN ../../mythtv/mythtv/libs/libmythtv/recorders/channelbase.cpp ./libs/libmythtv/recorders/channelbase.cpp
  8950. *** ../../mythtv/mythtv/libs/libmythtv/recorders/channelbase.cpp 2013-02-16 10:36:55.184163115 -0800
  8951. --- ./libs/libmythtv/recorders/channelbase.cpp 2013-02-16 10:52:50.014567132 -0800
  8952. ***************
  8953. *** 26,31 ****
  8954. --- 26,32 ----
  8955. #include "firewirechannel.h"
  8956. #include "mythcorecontext.h"
  8957. #include "cetonchannel.h"
  8958. + #include "r5000channel.h"
  8959. #include "dummychannel.h"
  8960. #include "tvremoteutil.h"
  8961. #include "channelbase.h"
  8962. ***************
  8963. *** 1195,1200 ****
  8964. --- 1196,1210 ----
  8965. channel = new CetonChannel(tvrec, genOpt.videodev);
  8966. #endif
  8967. }
  8968. + else if (genOpt.cardtype == "R5000")
  8969. + {
  8970. + #ifdef USING_R5000
  8971. + channel = new R5000Channel(tvrec, genOpt.videodev, fwOpt.model, dvbOpt.dvb_on_demand);
  8972. + dynamic_cast<R5000Channel*>(channel)->SetSlowTuning(
  8973. + dvbOpt.dvb_tuning_delay);
  8974. + #endif
  8975. + }
  8976. +
  8977. else if (CardUtil::IsV4L(genOpt.cardtype))
  8978. {
  8979. #ifdef USING_V4L2
  8980. diff -crBN ../../mythtv/mythtv/libs/libmythtv/recorders/recorderbase.cpp ./libs/libmythtv/recorders/recorderbase.cpp
  8981. *** ../../mythtv/mythtv/libs/libmythtv/recorders/recorderbase.cpp 2013-02-16 10:36:55.188163142 -0800
  8982. --- ./libs/libmythtv/recorders/recorderbase.cpp 2013-02-16 10:52:50.018567158 -0800
  8983. ***************
  8984. *** 9,20 ****
  8985. --- 9,22 ----
  8986. #include "firewirechannel.h"
  8987. #include "importrecorder.h"
  8988. #include "cetonrecorder.h"
  8989. + #include "r5000recorder.h"
  8990. #include "dummychannel.h"
  8991. #include "hdhrrecorder.h"
  8992. #include "iptvrecorder.h"
  8993. #include "mpegrecorder.h"
  8994. #include "recorderbase.h"
  8995. #include "cetonchannel.h"
  8996. + #include "r5000channel.h"
  8997. #include "asirecorder.h"
  8998. #include "dvbrecorder.h"
  8999. #include "hdhrchannel.h"
  9000. ***************
  9001. *** 649,654 ****
  9002. --- 651,663 ----
  9003. recorder = new ImportRecorder(tvrec);
  9004. #endif
  9005. }
  9006. + else if (genOpt.cardtype == "R5000")
  9007. + {
  9008. + #ifdef USING_R5000
  9009. + recorder = new R5000Recorder(
  9010. + tvrec, dynamic_cast<R5000Channel*>(channel));
  9011. + #endif // USING_R5000
  9012. + }
  9013. else if (CardUtil::IsV4L(genOpt.cardtype))
  9014. {
  9015. #ifdef USING_V4L2
  9016. diff -crBN ../../mythtv/mythtv/libs/libmythtv/recorders/signalmonitor.cpp ./libs/libmythtv/recorders/signalmonitor.cpp
  9017. *** ../../mythtv/mythtv/libs/libmythtv/recorders/signalmonitor.cpp 2013-02-16 10:36:55.188163142 -0800
  9018. --- ./libs/libmythtv/recorders/signalmonitor.cpp 2013-02-16 10:52:50.018567158 -0800
  9019. ***************
  9020. *** 54,59 ****
  9021. --- 54,64 ----
  9022. # include "cetonchannel.h"
  9023. #endif
  9024.  
  9025. + #ifdef USING_R5000
  9026. + # include "r5000signalmonitor.h"
  9027. + # include "r5000channel.h"
  9028. + #endif
  9029. +
  9030. #undef DBG_SM
  9031. #define DBG_SM(FUNC, MSG) LOG(VB_CHANNEL, LOG_DEBUG, \
  9032. QString("SM[%1](%2)::%3: %4").arg(capturecardnum) \
  9033. diff -crBN ../../mythtv/mythtv/libs/libmythtv/transporteditor.cpp ./libs/libmythtv/transporteditor.cpp
  9034. *** ../../mythtv/mythtv/libs/libmythtv/transporteditor.cpp 2013-02-16 10:36:55.192163169 -0800
  9035. --- ./libs/libmythtv/transporteditor.cpp 2013-02-16 10:52:50.014567132 -0800
  9036. ***************
  9037. *** 739,745 ****
  9038. left->addChild(new Modulation(id, nType));
  9039. }
  9040. else if ((CardUtil::FIREWIRE == nType) ||
  9041. ! (CardUtil::FREEBOX == nType))
  9042. {
  9043. left->addChild(new DTVStandard(id, true, true));
  9044. }
  9045. --- 739,746 ----
  9046. left->addChild(new Modulation(id, nType));
  9047. }
  9048. else if ((CardUtil::FIREWIRE == nType) ||
  9049. ! (CardUtil::FREEBOX == nType) ||
  9050. ! (CardUtil::R5000 == nType))
  9051. {
  9052. left->addChild(new DTVStandard(id, true, true));
  9053. }
  9054. diff -crBN ../../mythtv/mythtv/libs/libmythtv/tv_rec.cpp ./libs/libmythtv/tv_rec.cpp
  9055. *** ../../mythtv/mythtv/libs/libmythtv/tv_rec.cpp 2013-02-16 10:36:55.196163195 -0800
  9056. --- ./libs/libmythtv/tv_rec.cpp 2013-02-16 10:52:50.010567105 -0800
  9057. ***************
  9058. *** 29,34 ****
  9059. --- 29,35 ----
  9060. #include "remoteutil.h"
  9061. #include "ringbuffer.h"
  9062. #include "mythlogging.h"
  9063. + #include "r5000channel.h"
  9064. #include "v4lchannel.h"
  9065. #include "dialogbox.h"
  9066. #include "jobqueue.h"
  9067. ***************
  9068. *** 1155,1160 ****
  9069. --- 1156,1170 ----
  9070. return dynamic_cast<DTVChannel*>(channel);
  9071. }
  9072.  
  9073. + R5000Channel *TVRec::GetR5000Channel(void)
  9074. + {
  9075. + #ifdef USING_R5000
  9076. + return dynamic_cast<R5000Channel*>(channel);
  9077. + #else
  9078. + return NULL;
  9079. + #endif // USING_R5000
  9080. + }
  9081. +
  9082. V4LChannel *TVRec::GetV4LChannel(void)
  9083. {
  9084. #ifdef USING_V4L2
  9085. diff -crBN ../../mythtv/mythtv/libs/libmythtv/tv_rec.h ./libs/libmythtv/tv_rec.h
  9086. *** ../../mythtv/mythtv/libs/libmythtv/tv_rec.h 2013-02-16 10:36:55.196163195 -0800
  9087. --- ./libs/libmythtv/tv_rec.h 2013-02-16 10:52:50.010567105 -0800
  9088. ***************
  9089. *** 46,51 ****
  9090. --- 46,52 ----
  9091. class V4LChannel;
  9092. class HDHRChannel;
  9093. class CetonChannel;
  9094. + class R5000Channel;
  9095.  
  9096. class MPEGStreamData;
  9097. class ProgramMapTable;
  9098. ***************
  9099. *** 266,271 ****
  9100. --- 267,273 ----
  9101. bool enter_power_save_mode);
  9102. void CloseChannel(void);
  9103. DTVChannel *GetDTVChannel(void);
  9104. + R5000Channel *GetR5000Channel(void);
  9105. V4LChannel *GetV4LChannel(void);
  9106.  
  9107. bool SetupSignalMonitor(
  9108. diff -crBN ../../mythtv/mythtv/libs/libmythtv/videosource.cpp ./libs/libmythtv/videosource.cpp
  9109. *** ../../mythtv/mythtv/libs/libmythtv/videosource.cpp 2013-02-16 10:36:55.204163247 -0800
  9110. --- ./libs/libmythtv/videosource.cpp 2013-02-16 10:52:50.018567158 -0800
  9111. ***************
  9112. *** 36,41 ****
  9113. --- 36,42 ----
  9114. #include "frequencies.h"
  9115. #include "diseqcsettings.h"
  9116. #include "firewiredevice.h"
  9117. + #include "r5000device.h"
  9118. #include "compat.h"
  9119. #include "mythdb.h"
  9120. #include "mythdirs.h"
  9121. ***************
  9122. *** 1541,1546 ****
  9123. --- 1542,1642 ----
  9124. _oldValue = v;
  9125. };
  9126.  
  9127. + class R5000TuningDelay : public SpinBoxSetting, public CaptureCardDBStorage
  9128. + {
  9129. + public:
  9130. + R5000TuningDelay(const CaptureCard &parent) :
  9131. + SpinBoxSetting(this, 0, 2000, 25),
  9132. + CaptureCardDBStorage(this, parent, "dvb_tuning_delay")
  9133. + {
  9134. + setLabel(QObject::tr("R5000 Tuning Delay (msec)"));
  9135. + setHelpText(
  9136. + QObject::tr("Some STBS (for example the ViP boxes) require "
  9137. + "additional time after setting the channel before starting recording. "
  9138. + "This is especially necessary if different channels use different codecs."));
  9139. + };
  9140. + };
  9141. +
  9142. + class R5000SendPowerBeforeChannel : public CheckBoxSetting, public CaptureCardDBStorage
  9143. + {
  9144. + public:
  9145. + R5000SendPowerBeforeChannel(const CaptureCard &parent) :
  9146. + CheckBoxSetting(this),
  9147. + CaptureCardDBStorage(this, parent, "dvb_on_demand")
  9148. + {
  9149. + setValue(false);
  9150. + setLabel(QObject::tr("Turn on before Channel Change"));
  9151. + setHelpText(QObject::tr(
  9152. + "On some STBs klike the ViP211, the power on/off "
  9153. + "detection isn't reliable if you let the box go into "
  9154. + "standby. This forces a 'power-on' command before "
  9155. + "changing channels. This will very likely do the "
  9156. + "wrong thing for non ViP boxes."));
  9157. +
  9158. + };
  9159. + };
  9160. +
  9161. + class R5000Serial : public ComboBoxSetting, public CaptureCardDBStorage
  9162. + {
  9163. + public:
  9164. + R5000Serial(const CaptureCard &parent) :
  9165. + ComboBoxSetting(this),
  9166. + CaptureCardDBStorage(this, parent, "videodevice")
  9167. + {
  9168. + setLabel(QObject::tr("Serial #"));
  9169. + #ifdef USING_R5000
  9170. + QStringList serials = R5000Device::GetSTBList();
  9171. + for (int i = 0; i < serials.size(); i++)
  9172. + {
  9173. + addSelection(serials[i]);
  9174. + }
  9175. + #endif // USING_R5000
  9176. + }
  9177. + };
  9178. +
  9179. + class R5000Model : public ComboBoxSetting, public CaptureCardDBStorage
  9180. + {
  9181. + public:
  9182. + R5000Model(const CaptureCard &parent) :
  9183. + ComboBoxSetting(this),
  9184. + CaptureCardDBStorage(this, parent, "firewire_model")
  9185. + {
  9186. + setLabel(QObject::tr("R5000 STB type"));
  9187. + addSelection("VIP211");
  9188. + addSelection("VIP411");
  9189. + addSelection("VIP622");
  9190. + addSelection("VIP722");
  9191. + addSelection("BEV9242");
  9192. + addSelection("DISH6000");
  9193. + addSelection("DIRECTV");
  9194. + addSelection("STARCHOICE/DSR");
  9195. + addSelection("HDD-200");
  9196. + QString help = QObject::tr(
  9197. + "Choose the type of R5000 enabled STB you are using.");
  9198. + setHelpText(help);
  9199. + }
  9200. + };
  9201. +
  9202. + class R5000ConfigurationGroup : public VerticalConfigurationGroup
  9203. + {
  9204. + public:
  9205. + R5000ConfigurationGroup(CaptureCard& a_parent):
  9206. + VerticalConfigurationGroup(false, true, false, false),
  9207. + parent(a_parent)
  9208. + {
  9209. + setUseLabel(false);
  9210. + addChild(new R5000SendPowerBeforeChannel(parent));
  9211. + addChild(new R5000TuningDelay(parent));
  9212. + addChild(new R5000Serial(parent));
  9213. + addChild(new R5000Model(parent));
  9214. + addChild(new EmptyAudioDevice(parent));
  9215. + addChild(new EmptyVBIDevice(parent));
  9216. + };
  9217. +
  9218. + private:
  9219. + CaptureCard &parent;
  9220. + };
  9221. +
  9222. class IPTVHost : public LineEditSetting, public CaptureCardDBStorage
  9223. {
  9224. public:
  9225. ***************
  9226. *** 2287,2292 ****
  9227. --- 2383,2392 ----
  9228. addTarget("CETON", new CetonConfigurationGroup(parent));
  9229. #endif // USING_CETON
  9230.  
  9231. + #ifdef USING_R5000
  9232. + addTarget("R5000", new R5000ConfigurationGroup(parent));
  9233. + #endif // USING_R5000
  9234. +
  9235. // for testing without any actual tuner hardware:
  9236. addTarget("IMPORT", new ImportConfigurationGroup(parent));
  9237. addTarget("DEMO", new DemoConfigurationGroup(parent));
  9238. ***************
  9239. *** 2500,2505 ****
  9240. --- 2600,2609 ----
  9241. QObject::tr("Ceton Cablecard tuner "), "CETON");
  9242. #endif // USING_CETON
  9243.  
  9244. + #ifdef USING_R5000
  9245. + setting->addSelection(QObject::tr("R5000 Capable STB"), "R5000");
  9246. + #endif // USING_R5000
  9247. +
  9248. setting->addSelection(QObject::tr("Import test recorder"), "IMPORT");
  9249. setting->addSelection(QObject::tr("Demo test recorder"), "DEMO");
  9250. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement