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):


while [ 1 ]; do
nohup sleep 10

…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.

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:

Description=Mount RAMFS for SQLITE DB file

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


Edit /etc/cron.daily/tmpdb-sync

cp -a /var/readynasd /etc/readynasd-db/

Now finish up:

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

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
# Provides: local
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Local scripts
# Description: Local scripts

. /lib/init/vars.sh

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

case "$1" in
echo "Error: argument '$1' not supported" >&2
exit 3
# No-op
echo "Error: argument '$1' not supported" >&2
exit 3
echo "Usage: $0 start|stop" >&2
exit 3


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


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") &

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:

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) \
- GoodPulses |= (1<<rc_value_pos); \
+ 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:


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:

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

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

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

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:

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

Note that you should change user/pwd.

Run oscam:


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)



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@
rsync -avz -e ssh project/RPi/deps/lib/liblockdev.* pi@

On the PI

cp -a build/* /usr/local/

Fun time!