Saturday, November 16, 2013

How to get Sky Germany streamed by an Intel Synology NAS to Android, DLNA Devices & XBox One, legally!

Introduction

After spending almost a year on this topic I have to write some things down, especially for my self since I would jump out of the window if I would loose any of this information.


Why did I do that?

Sky Germany's HD Receiver is shit. It crashes often, consumes a lot of energy, doesn't allow to play Live TV or Recordings on different platforms and the Harddisk is limited (as a cable user currently to 500GB). In these times programming a DVR via Remote on your Television also doesn't sound too good. I would rather use a mobile app for this.
Besides these reasons I am paying 65€ for (a very good) Sky Abo but unfortunately I can only watch it at home. Therefor, streaming is needed. SkyGo is mostly not HD and also doesn't broadcast all channels. The IPTV from the Telekom is... Yah... It's the Telekom... And again I cannot stream!


The Goals

  • All this has to be 100% legal (that actually made it so complicated).
  • Record and watch LiveTV in HD
  • Record and watch simultaneously (at least 2 streams)
  • Watch LiveTV and Recordings on
    • DLNA devices like XBox One, Android and Apple Smartphones
    • XBMC as Media Center Software
  • Transcode Recordings and LiveTV to lower resolutions to watch over Internet

The Hardware

In total the costs of 807€ seem to be high and while writing this I would seriously consider everybody buying an already set up mediacenter but always consider : It is a fully functional NAS which has lots of other possibilities and it only consumes around 30 Watts!

The Software

  • Synology DSM 4.3 or later
  • OSCam 1.20 or later
  • TVHeadend 3.4 or later
  • Serviio DLNA Server
  • DVBLink TV Source
  • Optional : 
    • SAPServer (Session Announcement Protocol)
    • XBMC 12 or later

The Alternatives

Synology Diskstation

I previously had a Synology DS209. It was ARM based and even used 10W less than the current one. But with a CPU power of 1.2Ghz you can forget about transcoding or even streaming more than one HD channel. Also, the Intel based 64Bit Architecture offeres new possibility, all mentioned packages I installed there were only partly available for ARM, but all for Intel.
Am also pretty sure that a QNAP will do the job. I am just more familiar with the Synology Diskstations.

DVBLink 

Am using DVBLink just for the TBS driver... I tried so often to compile the TBS driver on the Synology DiskStation but either it was unstable or only ran for an hour, or couldn't cope with my requirements. 
I am just lazy. 
Installing DVBLink just for the driver seems ridiculous but on the other side it only cost me $15. If you managed to get any DVB-C Sticks running without DVBLink please drop me a line!


The Installation

Hardware

Plugin in the DVB-C Sticks into the USB ports of the Diskstation might sound easy but it isn't. The only information that was missing for me is that DVB-C Sticks in general don't run smoothly via the USB3 ports at the back of the Diskstation. As long as you connect all DVB-C Sticks as well as the Smargo Reader to the front USB2 port (via a self powered HUB) everything works fine. 
After you installed all necessary drivers below you can check the hardware with "dmesg | grep dvb" on the ssh terminal. You should see something like this : 
DiskStation> dmesg | grep dvb
[   66.543114] Em28xx: Initialized (Em28xx dvb Extension) extension
[   66.640714] usbcore: registered new interface driver dvb_usb_ttusb2
[   66.901876] usbcore: registered new interface driver dvb_usb_dib0700
[   67.353256] dvb-usb: found a 'TBS DVBC USB2.0' in cold state, will try to load a firmware
[   67.400659] dvb-usb: downloading firmware from file 'dvb-usb-tbsqbox-dvbc.fw'
[   67.433502] tbsdvbc: start downloading TBSDVBC firmware
[   67.556186] dvb-usb: found a 'TBS DVBC USB2.0' in warm state.
[   67.562642] dvb-usb: will pass the complete MPEG2 transport stream to the software demuxer.
[   67.805165] dvb-usb: MAC address: ff:ff:ff:ff:ff:ff
[   67.838551] tbsdvbc: Attached TBSDVBCFE!
[   67.868525] dvb-usb: schedule remote query interval to 150 msecs.
[   67.874702] dvb-usb: TBS DVBC USB2.0 successfully initialized and connected.
[   67.881848] dvb-usb: found a 'TBS DVBC USB2.0' in cold state, will try to load a firmware
[   67.928490] dvb-usb: downloading firmware from file 'dvb-usb-tbsqbox-dvbc.fw'
[   67.957631] tbsdvbc: start downloading TBSDVBC firmware
[   68.088717] dvb-usb: found a 'TBS DVBC USB2.0' in warm state.
[   68.095034] dvb-usb: will pass the complete MPEG2 transport stream to the software demuxer.
[   68.350075] dvb-usb: MAC address: ff:ff:ff:ff:ff:ff
[   68.380707] tbsdvbc: Attached TBSDVBCFE!
[   68.407848] dvb-usb: schedule remote query interval to 150 msecs.
[   68.414070] dvb-usb: TBS DVBC USB2.0 successfully initialized and connected.
[   68.421469] usbcore: registered new interface driver tbsdvbc


Synology Diskstation

Firmware

Always use the latest firmware. Currently my DS713+ is running the DSM 4.3-3776. 

Root Access & IPKG

For various upcoming actions you need ssh root access to your diskstation as well as the proprietary package manager aka IPKG. I followed this installation process here http://www.synology-wiki.de/index.php/IPKG. Follow the instructions on this page after you enabled the root access to your diskstation.

Optional linux packages

If you don't want to use e.g. built-in editors you can now get common linux packages via IPKG, e.g.
ipkg install nano


Packages

First, add the following 3rd Party Package Sources : 
  • http://packages.synocommunity.com
  • http://packages.pcloadletter.co.uk
  • http://update.10trum.de/packageupdate/getpackages.php
  • http://spk.unzureichende.info
If some of the following packages are still not available with these sources, have a look at this page : http://www.synology-wiki.de/index.php/Paketzentrum_Quellen

We need the following packages : 
  • DVBLink Server **
  • Java Manager
  • MiniSAPServer
  • OSCam
  • Perl
  • Serviio
  • Serviio Console
  • TvHeadend
** If you are a linux pro (unlike me) and you are familiar with cross-compiling drivers for an embedded system like the Diskstation you can skip installing the DVBLink Server since I just use it for enabling the DVB-C Sticks. 


DVBLink

If you will be using DVBLink's driver for TVHeadend you must know that the drivers might get loaded after TVHeadend. Since TVHeadend cannot reload and all DVB devices have to be up on boot time I added a small restart hook to the DVBLink Startup Script to quickly restart TVHeadend if it is loaded completely.

Open /var/packages/DVBLinkServer/scripts/start-stop-status, go down to the cases definition and add the two tvheadend script calls to the end of the start case so that it looks like this
case $1 in
        start)
                check_conflict
                start
                ${SYNOPKG_PKGDEST}/start2.sh
                
                # ADD THESE TWO LINES to restart TVH whenever DVBLink is restarted
                sh /var/packages/tvheadend/scripts/start-stop-status stop
                sh /var/packages/tvheadend/scripts/start-stop-status start

                exit 0
        ;;
        stop)
                ${SYNOPKG_PKGDEST}/stop.sh
                exit 0
        ;;
        status)
                if [ -e ${APP_PATH} ]; then
                        exit 0
                else
                        exit 1
                fi
        ;;
        log)
                echo ${SYNOPKG_PKGDEST}/dvblink_server.log
                exit 0
        ;;
esac


OSCam

OSCam will be our cardserver. It is able to quickly respond to requests like "Dude, whats the key for Sky Atlantic HD again?" and as long as you only use it in your private home there is no law that disallows it. If you open it to the internet and let other people use it they will probably put you in jail since you allow other people to descramble encrypted Sky channels without paying for it.

Open an ssh terminal and navigate to the configuration of oscam, in my case /usr/local/oscam/var and add these files :
  1. oscam.conf
    As protocol to communicate with TV Headend lateron we will use newcamd. The port of newcamd also contains the CAID which is dependent on your Sky Smartcart, have a look here to find out which should work for you : http://www.zebradem.com/wiki/index.php?title=Smartcard
    [global]
    logfile                       = /usr/local/oscam/var/oscam.log
    
    [newcamd]
    port                          = 15002@09C7:000000
    key                           = 0102030405060708091011121314
    keepalive                     = 1
    mgclient                      = 1
    
    [webif]
    httpport                      = 6060
    httpallowed                   = 127.0.0.1,192.168.1.42
  2. oscam.server
    In the oscam.server configuration we define the reader, in my case I figured out via
    ls -la | grep ttyUSB
    that my smargo reader seems to be plugged into ttyUSB3!
    [reader]
    label                         = smargo
    description                   = Smargo
    protocol                      = smargo
    device                        = /dev/ttyUSB3
    caid                          = 09C7
    boxid                         = 12345678
    detect                        = cd
    group                         = 1
  3. oscam.user
    Last but not least we need a user to authenticate! Again, fill in you own CAID here.
    [account]
    user                          = tvheadend
    pwd                           = tvheadend
    caid                          = 09C7
    group                         = 1

After restarting the oscam package via the Synology Panel you should be able to see the oscam web panel via http://diskstation:6060. Keep in mind that the configuration above restricts the access to 2 IP Adresses, you might want to change that to you own needs, use google!


TV Headend

TV Headend normally runs on port 9981. The Synology Package Manager will tell you which port it chose though.

Lets first create the connection between TV Headend and OSCam. Navigate to Configuration > CSA and add a new entry :

  • Hostname : Most likely "localhost" or the diskstation's IP Address
  • Port : The port we set in the oscam.conf, here 15002
  • Username & Password : Twice tvheadend, just like in the oscam.user
  • DES Key : as set above, 0102030405060708091011121314
  • Update Card : This makes sense since Sky randomly pushes "Entitlement Management Messages" to its Sky Boxes advising the Card Reader to switch some hidden magic. If you don't hit this checkbox you have to put your Sky Card into a Sky Receiver once a month. 
  • Update One : The Smargo Reader is the best I could found but if you allow TV Headend to forward more than one EMM at the time it might screw itself up and crash. Then you would have to restart OSCam. Prevent it by also checking this checkbox. 


Afterwards we're ready to configure our TV Adapters. Click on the Configuration Tab > Configuration and select your TV Adapter. If you cannot see any you either haven't restarted since you installed all packages or your DVB-C setup is incomplete.

First set all configurations like on the screenshot, then "Add DVB Network by location...". This will add some initial Muxes which then will get scanned. You can always open the TVHeadend log at the bottom right. After the process is finished (that can take hours!!!) the third step will get visible : "Map DVB services to channels". 


You can now already download a channel playlist for e.g. the VLC Player by opening http://diskstation:9981/playlist/channels

For Android Phones I can suggest TVHGuide, it also forwards stream urls to e.g. BSPlayer, VLC or the MX Player which are all available in the Play Store.
For iPhones I can recommend the TvhClient. Unfortunately streaming is not working all the time due missing codecs. If you have a jailbroken phone it is possible to install a VLC Player and stream.

XBMC

For your Living Room Clients you can install XBMC. It comes with a plugin for TVHeadend, after configuring the plugin you should be able to watch TV with an extreme fast channel switching time of less than 300ms.

Serviio

For my purposes the Free Edition is still enough. The Pro version adds some nice streaming options for Smartphones but since I am using an Android Phone this is not a problem for me.

We now have a running TV Server that can stream to XBMC and to mobile Clients. If you don't have VDSL at home you most likely will get troubles to stream to the outside world in 1080p and 2x DolbyDTS Sound. That's why we need a Transcoder that can transform/transcode raw streams into more bandwidth saving streams, e.g. an mpeg stream with a resolution of 800x576 and the main audio channel in stereo is way enough for a 3G/4G connection.

I tried Plex, I tried VLC directly, nothing worked as smooth as Serviio.

If you installed the Serviio Web Console you add all of your recordings (and maybe local media files) as shared folders here : http://diskstation/serviioweb


Links