End of File

From pyTivo - Wiki

Jump to: navigation, search

Years ago TiVo appeared to be taking a path of cooperative development with the open source community. With the release of the HMO protocol and the HME SDK it appeared that TiVo was trying to encourage third party noncommercial development for TiVo. However since the TiVo sponsored competition for HME products there has been no further support or encouragement from TiVo. There has been no update to the SDK yet, many updates and enhancements have been added to the HMO/HME protocols. My assumption is that TiVo is choosing to favor commercial developments and partnerships, most likely because they are in need of cash.

I however, believe they are taking the wrong path. I believe that by embracing the open source community TiVo can create many more features and benefits for TiVo owners and in turn sell more of their product. To that end it is my intention to provide what I have learned in working on pyTivo to the rest of the open source community so that they may avoid mistakes we have made. Most of the development of pyTivo comes from watching how TiVo's own products interact with the TiVo and reverse engineering our own similar solution.

How pyTivo Transfers Streamed Video

  1. TiVo asks for the information about a video
    1. This request is in the form of a webpage request
  2. pyTivo sends back a file size that is as large as the file could possibly be (Example 1Gig)
    1. This data is returned in an XML formated page
  3. TiVo sends a get request for the Video
    1. Again this is sent as an HTTP GET request
  4. pyTivo streams the video as it transcodes
    1. During this time pyTivo does the following:
      1. Determines based on user settings and the dimensions of the file the correct Aspect Ratio and padding
      2. Pipes the output of ffmpeg directly into TCP packets sent to TiVo
  5. Stream abruptly ends at the end of the video (Example 800MB)
    1. ffmpeg has reached the end of the file and transcoding is complete. However because the size of the transcoded file always varies the end of file comes before the total number of bytes TiVo is expecting.
    2. So at this point TiVo is still expecting another 200MB
  6. TiVo waits thinking that network traffic has slowed down the packets, TiVo seems to wait 30 seconds or so.
  7. TiVo then requests the file again asking for the last 200MB.
    1. This request is sent in a second HTTP GET request, however this time TiVo request the range of the file it is still missing. In this case that would be 800MB - 1000MB.
  8. pyTivo responds with a 206 which tells TiVo that the file has ended and sends a short bit of code which I believe equals and End of File line.
    1. pyTivo receives the request and sees that the byte request is beyond the length of the file and is out of range.
    2. pyTivo then responds with an HTTP 206 response, partial content.
      1. This response contains headers stating that there is no more file and to close the connection.
      2. It tells TiVo specifically the range of bytes which it can forget about, in this case 800MB - 1000MB
      3. It sends back three hexadecimal characters in the body of the TCP packet. These are "300D0A" (ASCII "0" (zero) followed by CR-LF (end-of-line)). I have no idea what this means, I only saw it in responses from TiVo Desktop and copied it. My assumption is that this is an End of File signal? Without it TiVo will still recognize that the transfer was not interrupted, but the file will be deleted from the TiVo immediately, which makes me think that TiVo interprets the lack of those characters as a corrupt file.

Hope this helps anyone else out there trying to figure out this protocol. If I have mistakes please feel free to correct them.

Personal tools
Get pytivo at SourceForge.net. Fast, secure and Free Open Source software downloads