XBMC memory leak remedy

XBMC (now Kodi) has always had a tendency of leaking memory, so that it will eventually thrash and crash. My simple solution to this is to run xbmc inside a for loop instead of directly (just run the script from .xinitrc):

xbmc_angel.sh:

#!/bin/bash
while [ 1 ]; do
xbmc
nohup sleep 10
done

…And add the following to the local XBMC user’s crontab:

0 4 * * *       killall xbmc.bin

This will kill XBMC every night at 4 o’clock. And give you a fresh XBMC every day!

How to download videos from Pepper Flash on linux

The new Pepper Flash plugin broke my old script for listing/downloading cached flash/flv videos.

Here is a new script. Uses sudo because the /proc/$PID/fd directory is root only.
This solution is based on silviot‘s solution here: http://superuser.com/questions/622606/how-do-i-save-the-buffered-flash-video-on-linux.

#!/bin/bash
for FLASHPID in $( pgrep -f chrom ) ; do (for FLASHFILE in $(sudo ls -l /proc/$FLASHPID/fd|egrep "(/tmp/Flash|Pepper Data)" | sed -r 's/^.* ([0-9]+) -> .*$/\1/'); do echo /proc/$FLASHPID/fd/$FLASHFILE; done ); done

Then you can just copy the file into home, like:

cp /proc/26493/fd/30 ~/

ReadyNAS RN102 constant activity remedy

My Netgear ReadyNAS RN102 keeps constantly writing to a file /var/readynasd
I don’t want to hold my breath waiting for Netgear to fix this so I took matters into my own hands and implemented a TMPFS fix for my NAS.
What it does is mount /var/readynasd as a tmpfs of 2MB, and copy files to here from /etc/readynas-db on every boot, and copy back every hour, and on shutdown.

Setup instructions

systemctl stop readynasd
mkdir /etc/readynasd-db
cp -a /var/readynasd /etc/readynasd-db/

Edit /lib/systemd/system/tmpdb.service:

[Unit]
Description=Mount RAMFS for SQLITE DB file
Before=readynasd.service

[Service]
Type=oneshot
ExecStart=/bin/sh -c "mount -t tmpfs -o size=2m tmpfs /var/readynasd && cp -a /etc/readynasd-db/readynasd /var/"
#ExecStop=/bin/sh -c "cp -a /var/readynasd /etc/readynasd-db/" # TODO not working
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Edit /etc/cron.daily/tmpdb-sync

#!/bin/bash
cp -a /var/readynasd /etc/readynasd-db/

Now finish up:

chmod +x /etc/cron.daily/tmpdb-sync
systemctl enable tmpdb
reboot

ReadyNAS startup/boot script

I needed to add some startup command to run as root on my Netgear ReadyNAS (RN102). Turns out you don’t have any /etc/rc.local, so I added a new boot script /etc/init.d/local:

#! /bin/sh
### BEGIN INIT INFO
# Provides: local
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Local scripts
# Description: Local scripts
### END INIT INFO

PATH=/sbin:/bin
. /lib/init/vars.sh

do_start () {
hdparm -S 253 /dev/sdc
}

case "$1" in
start)
do_start
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
# No-op
;;
status)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
*)
echo "Usage: $0 start|stop" >&2
exit 3
;;
esac

:

Just type whatever u need inside do_start. I needed to set a higher spindown timeout.

Then:

chmod +x /etc/init.d/local
update-rc.d local defaults

Tested on ReadyNASOS 6.1.6

Getting XBMC to work with AirPlay on iOS7

Since iOS 7 broke Airplay for XBMC, a guy figured out how to get it working again. It involves sending extra Bonjour publishes.

When building ffmpeg make sure to enable gnutls support (required for HTTP Live Streaming over HTTPS)
Make sure that you have enabled airplay and avahi support (in gentoo, use flags airplay, avahi), and that you have libshairplay installed when building XBMC.
https://github.com/juhovh/shairplay (gentoo ebuild here)

So the trick is to publish an extra airplay service with a different name after XBMC has published. For instance after 60 seconds:

avahi-publish -s "iXBMC" _airplay._tcp 36667 "deviceid=FF:FF:FF:FF:FF:FF" "features=0x77" "model=AppleTV3,2" "srcvers=101.28"

Replace FF:FF:FF:FF:FF:FF with your mac address

You can put it in .xinitrc or rc.local, like this:

(sleep 60 && avahi-publish -s "iXBMC" _airplay._tcp 36667 "deviceid=FF:FF:FF:FF:FF:FF" "features=0x77" "model=AppleTV3,2" "srcvers=101.28") &

Source:
ermax @ xbmc forums

Transponders / initial tuning list for Canal Digital DVB-C Trondheim

For some reason, w_scan isn’t working for my Terratec Cinergy C HD PCI. I had some trouble finding initial scan data. But finally I found a list that gives me all channels for Canal Digital cable in Trondheim.

# no-trondheim-CanalDigital (cable)
C 290000000 6950000 NONE QAM256
C 298000000 6950000 NONE QAM256
C 306000000 6950000 NONE QAM64
C 314000000 6950000 NONE QAM64
C 322000000 6950000 NONE QAM64
C 346000000 6950000 NONE QAM64
C 354000000 6950000 NONE QAM64
C 362000000 6950000 NONE QAM64
C 370000000 6950000 NONE QAM64
C 378000000 6950000 NONE QAM64
C 386000000 6950000 NONE QAM64
C 394000000 6950000 NONE QAM64
C 402000000 6950000 NONE QAM64
C 410000000 6950000 NONE QAM256
C 418000000 6950000 NONE QAM64
C 426000000 6950000 NONE QAM64
C 434000000 6950000 NONE QAM64
C 450000000 6950000 NONE QAM64
C 458000000 6950000 NONE QAM64
C 474000000 6950000 NONE QAM64
C 490000000 6950000 NONE QAM256
C 610000000 6950000 NONE QAM64

Taken from:
http://mspc.no/forum/showthread.php?tid=612

Custom pwm input range/travel in MultiWii

I use MultiWii for my quadcopter. But I had a problem. My transmitter was not able to send values in the full range (1000-2000), so i had to scale the value from the center point (1500) up, and down.

Replace the fraction 22/20 with whatever scaling value you want, and replace THROTTLEPIN with whatever pin you want to scale.

Here are the changes I made (RX.ino in MultiWii 2.2):

@@ -110,8 +114,13 @@
rcValue[rc_value_pos] = dTime; \
if((rc_value_pos==THROTTLEPIN || rc_value_pos==YAWPIN || \
rc_value_pos==PITCHPIN || rc_value_pos==ROLLPIN) \
- && dTime>FAILSAFE_DETECT_TRESHOLD) \
- GoodPulses |= (1<<rc_value_pos); \
+ && dTime>FAILSAFE_DETECT_TRESHOLD) { \
+ GoodPulses |= (1<<rc_value_pos); \
+ if (rc_value_pos == THROTTLEPIN) { \
+ tmp = ((int16_t)dTime-1500)*22/20+1500; \
+ rcValue[rc_value_pos] = tmp; \
+ } \
+ } \
} \
} else edgeTime[pin_pos] = cTime; \
}
@@ -133,6 +142,7 @@
uint8_t mask;
uint8_t pin;
uint16_t cTime,dTime;
+ int16_t tmp;
static uint16_t edgeTime[8];
static uint8_t PCintLast;
#if defined(FAILSAFE) && !defined(PROMICRO)

XBMC with Canal Digital Norway using tvheadend/oscam for crypted channels on Gentoo

So I decided to set up DVB support on my XBMC, so that i can use XBMC for all my media needs. With oscam, the only hardware we need is a DVB-C card and a cheap PCSC smart card reader.

My TV card is a TerraTecCinergy C DVB-C.
My Smartcard reader is a SDI010 (works with CCID).
I did this on gentoo but it should be just as easy on most Linux OS.

The process

First you need to install CCID and pcsc-lite:

emerge -av pcsc-lite ccid

On gentoo PCSC daemon will auto start when you plug in the USB reader if you add this to /etc/rc.conf:

rc_hotplug="pcscd"

Else you might need to start the service.

Checkout oscam source:

svn co http://www.streamboard.tv/svn/oscam/trunk oscam
cd oscam

Now let’s build oscam with PCSC support:

make pcsc-libusb

Now configure oscam:

mkdir /usr/local/etc

Contents of /usr/local/etc/oscam.conf:

[global]
nice = -1
WaitForCards = 1
logfile = /tmp/oscam.log
usrfile = /tmp/oscamuser.log
cwlogdir = /tmp/cw
[webif]
httpport = 8888
httpallowed = 127.0.0.1
[newcamd]
key = 0102030405060708091011121314
port = 32000@0B00:000000

Note that you should change key to something more non-predictable.

Contents of /usr/local/etc/oscam.server:

[reader]
label                 = canaldigital
protocol              = pcsc
device                = 0
caid                  = 0B00
detect                = cd
ident                 = 0B00:000000
group                 = 1
emmcache              = 1,3,2

Contents of /usr/local/etc/oscam.user:

[account]
user = tvheadend
pwd = tvheadend
uniq = 0
group = 1
ident = 0B00:000000
caid = 0B00
au = canaldigital

Note that you should change user/pwd.

Run oscam:

./Distribution/oscam-1.20-unstable_*-libusb-pcsc

You can see its output from /tmp/oscam.log

Install and start tvheadend:

emerge -av tvheadend
/etc/init.d/tvheadend start
  1. Browse to http://localhost:9981/
  2. Go to Configuration -> Code word client
  3. Add entry
  4. Hostname: your ip
  5. Port: 32000
  6. Username: tvheadend
  7. Password: tvheadend
  8. DES Key: 01:02:03:04:05:06:07:08:09:10:11:12:13:14
  9. Check Enabled and Update card.
  10. Save

Now you can install XBMC tvheadend addon, plugin the smart card and, in theory just start watching TV!

(For XBMC addons i used this ebuild: http://data.gpo.zugaina.org/vdr-devel/media-plugins/xbmc-addon-pvr/xbmc-addon-pvr-9999.ebuild)

References

http://www.satnigmo.com/900/canaldigital-nordic-oscam-config/
http://cardshare-viasat-canaldigital.blogspot.no/2012/08/oscam-config-oscamserver.html
http://www.streamboard.tv/oscam/wiki/CardsList
https://tvheadend.org/projects/tvheadend/wiki/Tvheadend_oscam_ziggo

Building/installing libcec 2 on Raspberry PI

Tested on Raspbian wheezy

On your linux computer

From https://github.com/Pulse-Eight/libcec/tags download libcec-2.0.5-repack.
Apply this patch to configure.ac: https://github.com/vulpesvelox/libcec/commit/3671569235896a7ed448384ea6777a981fd49be9.

tar xvf libcec-2.0.5-repack.tar.gz && cd libcec-libcec-2.0.5-repack
./project/RPi/build.sh "${PWD}"/project/RPi/build

On the PI

apt-get install rsync

On your linux computer

rsync -avz -e ssh project/RPi/build pi@192.168.1.121:
rsync -avz -e ssh project/RPi/deps/lib/liblockdev.* pi@192.168.1.121:build/lib

On the PI

cp -a build/* /usr/local/
/usr/local/bin/cec-client

Fun time!