Index: ChangeLog
===================================================================
RCS file: /cvs/gstreamer/gst-sandbox/dvb-elements/dvbsrc/ChangeLog,v
retrieving revision 1.2
diff -u -r1.2 ChangeLog
--- ChangeLog	27 Mar 2006 08:31:54 -0000	1.2
+++ ChangeLog	15 Jun 2006 12:43:28 -0000
@@ -1,3 +1,14 @@
+2006-06-15  Johannes Schmid <jhs@cvs.gnome.org>
+
+	* gstdvbsrc.c
+	* gstdvbsrc.h
+	
+	Ported to gstreamer-0.10, fixed dvb-t
+
+	* configure.ac:
+	
+	gstreamer-0.10, bumped version to 0.2.0	
+
 2006-03-27  Tim-Philipp MÃ¼ller  <tim at centricular dot net>
 
 	Patch by: Martin Eikermann  <meiker at upb dot de>
Index: Makefile.am
===================================================================
RCS file: /cvs/gstreamer/gst-sandbox/dvb-elements/dvbsrc/Makefile.am,v
retrieving revision 1.1
diff -u -r1.1 Makefile.am
--- Makefile.am	14 Sep 2004 19:09:26 -0000	1.1
+++ Makefile.am	15 Jun 2006 12:43:28 -0000
@@ -12,7 +12,7 @@
 
 # flags used to compile this plugin
 # we use the GST_LIBS flags because we might be using plug-in libs
-libgstdvbsrc_la_CFLAGS = $(GST_LIBS_CFLAGS) -I /usr/include/ -I /usr/include/dvb/ -DGST_DEBUG_COLOR -DGST_DEBUG_ENABLED -DGST_INFO_ENABLED -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
+libgstdvbsrc_la_CFLAGS = -Wall -O0 $(GST_LIBS_CFLAGS) -I /usr/include/ -I /usr/include/dvb/ -DGST_DEBUG_COLOR -DGST_DEBUG_ENABLED -DGST_INFO_ENABLED -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
 
 libgstdvbsrc_la_LDFLAGS = $(GST_LIBS_LIBS)
 
Index: channels.conf.terr
===================================================================
RCS file: /cvs/gstreamer/gst-sandbox/dvb-elements/dvbsrc/channels.conf.terr,v
retrieving revision 1.1
diff -u -r1.1 channels.conf.terr
--- channels.conf.terr	19 Dec 2004 23:21:24 -0000	1.1
+++ channels.conf.terr	15 Jun 2006 12:43:28 -0000
@@ -1,82 +1,23 @@
-: UK channels for Crystal Palace, London
-701 (TV):529833:I0C34D0M16B8T2G32Y0:T:27500:203:407:0:0:19456:0:0:0
-702 (TV):529833:I0C34D0M16B8T2G32Y0:T:27500:204:411,412:0:0:19520:0:0:0
-BBC FOUR (TV):529833:I0C34D0M16B8T2G32Y0:T:27500:201:401,402:0:0:16832:0:0:0
-BBC NEWS 24 (TV):505833:I0C34D0M16B8T2G32Y0:T:27500:640:641:0:0:4415:0:0:0
-BBC ONE (TV):505833:I0C34D0M16B8T2G32Y0:T:27500:600:601,602:0:0:4164:0:0:0
-BBC THREE (TV):505833:I0C34D0M16B8T2G32Y0:T:27500:620:621,622:0:0:4351:0:0:0
-BBC TWO (TV):505833:I0C34D0M16B8T2G32Y0:T:27500:610:611,612:0:2:4228:0:0:0
-bid-up.tv (TV):561833:I0C23D0M64B8T2G32Y0:T:27500:6273:6274:0:0:14272:0:0:0
-CBBC (TV):505833:I0C34D0M16B8T2G32Y0:T:27500:620:621,622:0:0:4671:0:0:0
-Cbeebies (TV):529833:I0C34D0M16B8T2G32Y0:T:27500:201:401,402:0:0:16960:0:0:0
-Ch 14 (TV):481833:I0C23D0M64B8T2G32Y0:T:27500:2840:2841:2843:0:0:8800:0:0
-Ch 32 (TV):537833:I0C34D0M16B8T2G32Y0:T:27500:501:502,504:0:0:25984:0:0:0
-Ch 44 (TV):537833:I0C34D0M16B8T2G32Y0:T:27500:501:502,504:0:0:26048:0:0:0
-Channel 4 (TV):481833:I0C23D0M64B8T2G32Y0:T:27500:2827:2828,2830:0:0:8384:0:0:0
-f tn (TV):537833:I0C34D0M16B8T2G32Y0:T:27500:301:302,304:0:0:25856:0:0:0
-five (TV):561833:I0C23D0M64B8T2G32Y0:T:27500:6017:6018,6019:0:0:12866:0:0:0
-ITV 1 (TV):481833:I0C23D0M64B8T2G32Y0:T:27500:512:650,660:0:0:8261:0:0:0
-ITV 2 (TV):481833:I0C23D0M64B8T2G32Y0:T:27500:2818:2819,2821:0:0:8325:0:0:0
-ITV News (TV):481833:I0C23D0M64B8T2G32Y0:T:27500:2850:2851:0:0:8581:0:0:0
-QVC (TV):561833:I0C23D0M64B8T2G32Y0:T:27500:6049:6050:0:0:13120:0:0:0
-Sky News (TV):578166:I0C34D0M16B8T2G32Y0:T:27500:101:102,104:0:0:22080:0:0:0
-Sky Spts News (TV):578166:I0C34D0M16B8T2G32Y0:T:27500:201:202,204:0:0:22144:0:0:0
-Sky Travel (TV):578166:I0C34D0M16B8T2G32Y0:T:27500:301:302,304:0:0:22208:0:0:0
-THE HITS (TV):537833:I0C34D0M16B8T2G32Y0:T:27500:101:102:0:0:25664:0:0:0
-TMF (TV):537833:I0C34D0M16B8T2G32Y0:T:27500:201:202,204:0:0:25728:0:0:0
-TV Travel Shop (TV):561833:I0C23D0M64B8T2G32Y0:T:27500:6161:6162:0:0:13632:0:0:0
-UKBrightIdeas (TV):537833:I0C34D0M16B8T2G32Y0:T:27500:301:302,304:0:0:25792:0:0:0
-UKHistory (TV):578166:I0C34D0M16B8T2G32Y0:T:27500:401:402,404:0:0:22272:0:0:0
-1Xtra BBC (RADIO):529833:I0C34D0M16B8T2G32Y0:T:27500:0:434:0:0:18176:0:0:0
-BBC 5L SportsX (RADIO):529833:I0C34D0M16B8T2G32Y0:T:27500:0:431:0:0:17984:0:0:0
-BBC 6 Music (RADIO):529833:I0C34D0M16B8T2G32Y0:T:27500:0:432:0:0:18048:0:0:0
-BBC 7 (RADIO):529833:I0C34D0M16B8T2G32Y0:T:27500:0:433:0:0:18112:0:0:0
-BBC Asian Net. (RADIO):529833:I0C34D0M16B8T2G32Y0:T:27500:0:435:0:0:18240:0:0:0
-BBC PARLMNT (RADIO):529833:I0C34D0M16B8T2G32Y0:T:27500:0:403:0:0:16768:0:0:0
-BBC R5 Live (RADIO):529833:I0C34D0M16B8T2G32Y0:T:27500:0:430:0:0:17920:0:0:0
-BBC Radio 1 (RADIO):561833:I0C23D0M64B8T2G32Y0:T:27500:0:6210:0:0:14336:0:0:0
-BBC Radio 2 (RADIO):561833:I0C23D0M64B8T2G32Y0:T:27500:0:6226:0:0:14400:0:0:0
-BBC Radio 3 (RADIO):561833:I0C23D0M64B8T2G32Y0:T:27500:0:6242:0:0:14464:0:0:0
-BBC Radio 4 (RADIO):561833:I0C23D0M64B8T2G32Y0:T:27500:0:6258:0:0:14528:0:0:0
-BBC World Sv (RADIO):537833:I0C34D0M16B8T2G32Y0:T:27500:0:1601:0:0:26496:0:0:0
-Ch 15 (RADIO):561833:I0C23D0M64B8T2G32Y0:T:27500:0:660:0:0:14208:0:0:0
-jazz fm (RADIO):537833:I0C34D0M16B8T2G32Y0:T:27500:0:1401:0:0:26368:0:0:0
-Kerrang! (RADIO):537833:I0C34D0M16B8T2G32Y0:T:27500:0:1301:0:0:26304:0:0:0
-KISS (RADIO):537833:I0C34D0M16B8T2G32Y0:T:27500:0:1101:0:0:26176:0:0:0
-oneword (RADIO):537833:I0C34D0M16B8T2G32Y0:T:27500:0:1501:0:0:26432:0:0:0
-Smash Hits! (RADIO):537833:I0C34D0M16B8T2G32Y0:T:27500:0:1201:0:0:26240:0:0:0
-: DVB-T Berlin, Germany
-BBC World:177500:I0C23D0M16B7T8G8Y0:T:27500:49:50:55:0:16387:0:0:0
-FAB:177500:I0C23D0M16B7T8G8Y0:T:27500:3073:3074:3079:0:16576:0:0:0
-WDR:177500:I0C23D0M16B7T8G8Y0:T:27500:241:242:247:0:15:0:0:0
-Südwest BW/RP:177500:I0C23D0M16B7T8G8Y0:T:27500:257:258:263:0:16:0:0:0
-MDR Fernsehen:191500:I0C23D0M16B7T8G8Y0:T:27500:101:102:104:0:1:0:0:0
-arte:191500:I0C23D0M16B7T8G8Y0:T:27500:201:202,203:204:0:2:0:0:0
-NDR Fernsehen:191500:I0C23D0M16B7T8G8Y0:T:27500:301:302:304:0:3:0:0:0
-RTL:506000:I0C23D0M16B8T8G8Y0:T:27500:337:338:343:0:16405:0:0:0
-RTL2:506000:I0C23D0M16B8T8G8Y0:T:27500:353:354:359:0:16406:0:0:0
-Super RTL:506000:I0C23D0M16B8T8G8Y0:T:27500:433:434:439:0:16411:0:0:0
-VOX:506000:I0C23D0M16B8T8G8Y0:T:27500:545:546:551:0:16418:0:0:0
-RBB Brandenburg:522000:I0C23D0M16B8T8G8Y0:T:27500:1101:1102:1104:0:11:0:0:0
-RBB Berlin:522000:I0C23D0M16B8T8G8Y0:T:27500:1201:1202:1204:0:12:0:0:0
-Phoenix:522000:I0C23D0M16B8T8G8Y0:T:27500:1301:1302:1304:0:13:0:0:0
-Das Erste:522000:I0C23D0M16B8T8G8Y0:T:27500:1401:1402:1404:0:14:0:0:0
-ZDF:570000:I0C23D0M16B8T8G8Y0:T:27500:545:546:551:0:514:0:0:0
-Info/3sat:570000:I0C23D0M16B8T8G8Y0:T:27500:561:562:567:0:515:0:0:0
-Doku/KiKa:570000:I0C23D0M16B8T8G8Y0:T:27500:593:594:599:0:517:0:0:0
-Kabel 1:658000:I0C23D0M16B8T8G8Y0:T:27500:161:162:167:0:16394:0:0:0
-N24:658000:I0C23D0M16B8T8G8Y0:T:27500:225:226:231:0:16398:0:0:0
-ProSieben:658000:I0C23D0M16B8T8G8Y0:T:27500:305:306;307:311:0:16403:0:0:0
-SAT.1:658000:I0C23D0M16B8T8G8Y0:T:27500:385:386:391:0:16408:0:0:0
-Testkanal 9live:754000:I0C23D0M16B8T8G8Y0:T:27500:273:274:279:0:16401:0:0:0
-Eurosport:754000:I0C23D0M16B8T8G8Y0:T:27500:577:578:583:0:16420:0:0:0
-DSF:754000:I0C23D0M16B8T8G8Y0:T:27500:129:130:135:0:16392:0:0:0
-VIVA Plus:754000:I0C23D0M16B8T8G8Y0:T:27500:529:530:535:0:16417:0:0:0
-Testkanal Pro7:778000:I0C23D0M16B8T8G8Y0:T:27500:305:306:311:0:16403:0:0:0
-: DVB-T Hannover, Germany
-ARD:554000:I0C12D0M16B8T8G32Y0:T:27500:512:650:513:0:28156:0:0:0
-ZDF:554000:I0C12D0M16B8T8G32Y0:T:27500:513:651:513:0:28160:0:0:0
-NDR:554000:I0C12D0M16B8T8G32Y0:T:27500:514:652:513:0:28162:0:0:0
-RTL:530500:I0C12D0M16B8T8G32Y0:T:27500:512:650:513:0:1:0:0:0
-SAT1:530500:I0C12D0M16B8T8G32Y0:T:27500:513:651:513:0:2:0:0:0
-9Live:530500:I0C12D0M16B8T8G32Y0:T:27500:514:652:513:0:3:0:0:0
+Das Erste;BR:184500:C34D0M16B7T8G4Y0:T:27500:513:514=deu:516:0:32:8468:12289:0
+ZDF;ZDFmobil:578000000:C23D12M16B8T8G4Y0:T:27500:545:546=deu,547=2ch;559=dd:551:0:514:8468:514:0
+Bayerisches FS;BR:778000000:C23D23M16B8T8G4Y0:T:27500:529:530=deu:532:0:33:8468:12545:0
+Info/3sat;ZDFmobil:578000000:C23D12M16B8T8G4Y0:T:27500:561:562=deu,563=2ch;575=dd:567:0:515:8468:514:0
+RTL Television,RTL;RTL World:834000000:C23D12M16B8T8G4Y0:T:27500:337:338=deu:343:0:16405:8468:13314:0
+Sat.1;ProSiebenSat.1:626000:C23D0M16B8T8G4Y0:T:27500:385:386=deu;392=deu:391:0:16408:8468:13057:0
+ProSieben;ProSiebenSat.1:626000:C23D0M16B8T8G4Y0:T:27500:305:306=deu;312=deu:311:0:16403:8468:13057:0
+arte;BR:184500:C34D0M16B7T8G4Y0:T:27500:33:34=deu,35=fra:36:0:2:8468:12289:0
+Eurosport;T-Systems:786000000:C23D12M16B8T8G4Y0:T:27500:577+8190:578=deu:583:0:16420:8468:13058:0
+kabel eins;ProSiebenSat.1:626000:C23D0M16B8T8G4Y0:T:27500:161:162=deu:167:0:16394:8468:13057:0
+RTL2;RTL World:834000000:C23D12M16B8T8G4Y0:T:27500:353:354=deu:359:0:16406:8468:13314:0
+VOX;RTL World:834000000:C23D12M16B8T8G4Y0:T:27500:545:546=deu:551:0:16418:8468:13314:0
+N24;ProSiebenSat.1:626000:C23D0M16B8T8G4Y0:T:27500:225:226=deu:231:0:16398:8468:13057:0
+Super RTL,S RTL;RTL World:834000000:C23D12M16B8T8G4Y0:T:27500:433:434=deu:439:0:16411:8468:13314:0
+Doku/KiKa;ZDFmobil:578000000:C23D12M16B8T8G4Y0:T:27500:593:594=deu:599:0:517:8468:514:0
+Phoenix;BR:184500:C34D0M16B7T8G4Y0:T:27500:49:50=deu:52:0:3:8468:12289:0
+EinsPlus;BR:184500:C34D0M16B7T8G4Y0:T:27500:97:98=deu:516:0:6:8468:12289:0
+BR-alpha;BR:778000000:C23D23M16B8T8G4Y0:T:27500:561:562=deu:564:0:35:8468:12545:0
+SÜDWEST BW;BR:778000000:C23D23M16B8T8G4Y0:T:27500:3601:3602=deu:3604:0:225:8468:12545:0
+hr-fernsehen;BR:778000000:C23D23M16B8T8G4Y0:T:27500:1041:1042=deu:1044:0:65:8468:12545:0
+TELE 5;BetaDigital:786000000:C23D12M16B8T8G4Y0:T:27500:465:466=deu:471:0:16413:8468:13058:0
+Franken TV;T-Systems:786000000:C23D12M16B8T8G4Y0:T:27500:2081:2082=deu:2087:0:18562:8468:13058:0
+MonA TV;T-Systems:786000000:C23D12M16B8T8G4Y0:T:27500:641+102:642=deu,643=eng:0:0:16424:8468:13058:0
Index: configure.ac
===================================================================
RCS file: /cvs/gstreamer/gst-sandbox/dvb-elements/dvbsrc/configure.ac,v
retrieving revision 1.1
diff -u -r1.1 configure.ac
--- configure.ac	14 Sep 2004 19:09:26 -0000	1.1
+++ configure.ac	15 Jun 2006 12:43:28 -0000
@@ -2,7 +2,7 @@
 
 dnl Fill in your package name and version here
 PACKAGE=gst-dvbsrc
-VERSION=0.1.1
+VERSION=0.2.0
 
 dnl these AC_DEFINE_UNQUOTED's are necessary for make dist to work
 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
@@ -17,6 +17,15 @@
 AC_PROG_CC
 AC_PROG_LIBTOOL
 
+CFLAGS_WARNINGS="-Wall -Wmissing-prototypes -Wmissing-declarations -Wparentheses -Wpointer-arith"
+CXXFLAGS_WARNINGS="-Wall -Wparentheses -Wpointer-arith"
+
+AM_CFLAGS="$AM_CFLAGS -O0 -g $CFLAGS_WARNINGS"
+AM_CXXFLAGS="$AM_CXXFLAGS -O0 -g $CXXFLAGS_WARNINGS"
+
+AC_SUBST(AM_CFLAGS)
+AC_SUBST(AM_CXXFLAGS)
+
 dnl Check for pkgconfig first
 AC_CHECK_PROG(HAVE_PKGCONFIG, pkg-config, yes, no)
 
@@ -28,10 +37,10 @@
 dnl Now we're ready to ask for gstreamer libs and cflags
 dnl And we can also ask for the right version of gstreamer
                                                                                 
-GST_REQUIRED=0.8.0
+GST_REQUIRED=0.10.0
                                                                                 
-dnl start with 0.8
-GST_MAJORMINOR=0.8
+dnl start with 0.10
+GST_MAJORMINOR=0.10
 PKG_CHECK_MODULES(GST, \
   gstreamer-$GST_MAJORMINOR >= $GST_REQUIRED,
   HAVE_GST=yes,HAVE_GST=no)
@@ -49,7 +58,7 @@
 AC_SUBST(GST_MAJORMINOR)
 
 dnl If we need them, we can also use the plugin libraries
-PKG_CHECK_MODULES(GST_LIBS, gstreamer-libs-$GST_MAJORMINOR >= $GST_REQUIRED,
+PKG_CHECK_MODULES(GST_LIBS, gstreamer-base-$GST_MAJORMINOR >= $GST_REQUIRED,
                   HAVE_GST_LIBS=yes, HAVE_GST_LIBS=no)
                                                                                 
 dnl Give a warning if we don't have gstreamer libs
Index: gstdvbsrc.c
===================================================================
RCS file: /cvs/gstreamer/gst-sandbox/dvb-elements/dvbsrc/gstdvbsrc.c,v
retrieving revision 1.8
diff -u -r1.8 gstdvbsrc.c
--- gstdvbsrc.c	27 Mar 2006 08:31:54 -0000	1.8
+++ gstdvbsrc.c	15 Jun 2006 12:43:28 -0000
@@ -47,205 +47,230 @@
 
 
 static GstElementDetails dvbsrc_details = {
-  "DVB Source",
-  "Source/Video",
-  "Digital Video Broadcast Source",
-  "P2P-VCR, C-Lab, University of Paderborn"
+	"DVB Source",
+	"Source/Video",
+	"Digital Video Broadcast Source",
+	"P2P-VCR, C-Lab, University of Paderborn"
 };
 
 
 /* Object signals and args */
-enum {
-  ADAPTER_TYPE_SIGNAL,
-  QUALITY_SIGNAL,
-  LAST_SIGNAL
+enum
+{
+	ADAPTER_TYPE_SIGNAL,
+	QUALITY_SIGNAL,
+	LAST_SIGNAL
 };
 
 /* Arguments */
-enum {
-  ARG_0,
-  ARG_DVBSRC_ADAPTER_PREFIX,
-  ARG_DVBSRC_DISEQC_SRC,
-  ARG_DVBSRC_FREQ,
-  ARG_DVBSRC_POL,
-  ARG_DVBSRC_PIDS,
-  ARG_DVBSRC_SYM_RATE,
-  ARG_DVBSRC_BUFFER_SIZE,
-  ARG_DVBSRC_BANDWIDTH,
-  ARG_DVBSRC_CODE_RATE_HP,
-  ARG_DVBSRC_CODE_RATE_LP,
-  ARG_DVBSRC_GUARD,
-  ARG_DVBSRC_MODULATION,
-  ARG_DVBSRC_TRANSMISSION_MODE,
-  ARG_DVBSRC_HIERARCHY_INF,
-  ARG_DVBSRC_TUNE
+enum
+{
+	ARG_0,
+	ARG_DVBSRC_ADAPTER_PREFIX,
+	ARG_DVBSRC_DISEQC_SRC,
+	ARG_DVBSRC_FREQ,
+	ARG_DVBSRC_POL,
+	ARG_DVBSRC_PIDS,
+	ARG_DVBSRC_SYM_RATE,
+	ARG_DVBSRC_BANDWIDTH,
+	ARG_DVBSRC_CODE_RATE_HP,
+	ARG_DVBSRC_CODE_RATE_LP,
+	ARG_DVBSRC_GUARD,
+	ARG_DVBSRC_MODULATION,
+	ARG_DVBSRC_TRANSMISSION_MODE,
+	ARG_DVBSRC_HIERARCHY_INF,
+	ARG_DVBSRC_TUNE,
+	ARG_DVBSRC_INVERSION
 };
 
 #define GST_TYPE_DVBSRC_CODE_RATE (gst_dvbsrc_code_rate_get_type ())
 static GType
 gst_dvbsrc_code_rate_get_type (void)
 {
-  static GType dvbsrc_code_rate_type = 0;
-  static GEnumValue code_rate_types[] = {
-    {FEC_NONE, "NONE", "NONE"},
-    {FEC_1_2, "1/2", "1/2"},
-    {FEC_2_3, "2/3", "2/3"},
-    {FEC_3_4, "3/4", "3/4"},
-    {FEC_4_5, "4/5", "4/5"},
-    {FEC_5_6, "5/6", "5/6"},
-    {FEC_6_7, "6/7", "6/7"},
-    {FEC_7_8, "7/8", "7/8"},
-    {FEC_8_9, "8/9", "8/9"},
-    {FEC_AUTO, "AUTO", ""},
-    {0, NULL, NULL},
-  };
- 
-  if (!dvbsrc_code_rate_type) {
-    dvbsrc_code_rate_type =
-        g_enum_register_static ("GstDvbSrcCode_Rate", code_rate_types);
-  }
-  return dvbsrc_code_rate_type;
+	static GType dvbsrc_code_rate_type = 0;
+	static GEnumValue code_rate_types[] = {
+		{FEC_NONE, "NONE", "NONE"},
+		{FEC_1_2, "1/2", "1/2"},
+		{FEC_2_3, "2/3", "2/3"},
+		{FEC_3_4, "3/4", "3/4"},
+		{FEC_4_5, "4/5", "4/5"},
+		{FEC_5_6, "5/6", "5/6"},
+		{FEC_6_7, "6/7", "6/7"},
+		{FEC_7_8, "7/8", "7/8"},
+		{FEC_8_9, "8/9", "8/9"},
+		{FEC_AUTO, "AUTO", ""},
+		{0, NULL, NULL},
+	};
+
+	if (!dvbsrc_code_rate_type)
+	{
+		dvbsrc_code_rate_type =
+			g_enum_register_static ("GstDvbSrcCode_Rate", code_rate_types);
+	}
+	return dvbsrc_code_rate_type;
 }
 
 #define GST_TYPE_DVBSRC_MODULATION (gst_dvbsrc_modulation_get_type ())
 static GType
 gst_dvbsrc_modulation_get_type (void)
 {
-  static GType dvbsrc_modulation_type = 0;
-  static GEnumValue modulation_types[] = {
-    {QPSK, "QPSK", "QPSK"},
-    {QAM_16 , "QAM 16", "QAM 16"},
-    {QAM_32 , "QAM 32", "QAM 32"},
-    {QAM_64 , "QAM 64", "QAM 64"},
-    {QAM_128, "QAM 128", "QAM 128"},
-    {QAM_256, "QAM 256", "QAM 256"},
-    {QAM_AUTO, "AUTO", "AUTO"},
-    {0, NULL, NULL},
-  };
- 
-  if (!dvbsrc_modulation_type) {
-    dvbsrc_modulation_type =
-        g_enum_register_static ("GstDvbSrcModulation", modulation_types);
-  }
-  return dvbsrc_modulation_type;
+	static GType dvbsrc_modulation_type = 0;
+	static GEnumValue modulation_types[] = {
+		{QPSK, "QPSK", "QPSK"},
+		{QAM_16, "QAM 16", "QAM 16"},
+		{QAM_32, "QAM 32", "QAM 32"},
+		{QAM_64, "QAM 64", "QAM 64"},
+		{QAM_128, "QAM 128", "QAM 128"},
+		{QAM_256, "QAM 256", "QAM 256"},
+		{QAM_AUTO, "AUTO", "AUTO"},
+		{0, NULL, NULL},
+	};
+
+	if (!dvbsrc_modulation_type)
+	{
+		dvbsrc_modulation_type =
+			g_enum_register_static ("GstDvbSrcModulation", modulation_types);
+	}
+	return dvbsrc_modulation_type;
 }
 
 #define GST_TYPE_DVBSRC_TRANSMISSION_MODE (gst_dvbsrc_transmission_mode_get_type ())
 static GType
 gst_dvbsrc_transmission_mode_get_type (void)
 {
-  static GType dvbsrc_transmission_mode_type = 0;
-  static GEnumValue transmission_mode_types[] = {
-    {TRANSMISSION_MODE_2K, "2k", "2k"},
-    {TRANSMISSION_MODE_8K, "8k", "8k"},
-    {TRANSMISSION_MODE_AUTO, "AUTO", "AUTO"},
-    {0, NULL, NULL},
-  };
- 
-  if (!dvbsrc_transmission_mode_type) {
-    dvbsrc_transmission_mode_type =
-        g_enum_register_static ("GstDvbSrcTransmission_Mode", transmission_mode_types);
-  }
-  return dvbsrc_transmission_mode_type;
+	static GType dvbsrc_transmission_mode_type = 0;
+	static GEnumValue transmission_mode_types[] = {
+		{TRANSMISSION_MODE_2K, "2k", "2k"},
+		{TRANSMISSION_MODE_8K, "8k", "8k"},
+		{TRANSMISSION_MODE_AUTO, "AUTO", "AUTO"},
+		{0, NULL, NULL},
+	};
+
+	if (!dvbsrc_transmission_mode_type)
+	{
+		dvbsrc_transmission_mode_type =
+			g_enum_register_static ("GstDvbSrcTransmission_Mode",
+									transmission_mode_types);
+	}
+	return dvbsrc_transmission_mode_type;
 }
 
 #define GST_TYPE_DVBSRC_BANDWIDTH (gst_dvbsrc_bandwidth_get_type ())
 static GType
 gst_dvbsrc_bandwidth_get_type (void)
 {
-  static GType dvbsrc_bandwidth_type = 0;
-  static GEnumValue bandwidth_types[] = {
-    {BANDWIDTH_8_MHZ, "8MHz", "8Mhz"},
-    {BANDWIDTH_7_MHZ, "7", "7"},
-    {BANDWIDTH_6_MHZ, "6", "6"},
-    {BANDWIDTH_AUTO,  "AUTO", "AUTO"},
-    {0, NULL, NULL},
-  };
- 
-  if (!dvbsrc_bandwidth_type) {
-    dvbsrc_bandwidth_type =
-        g_enum_register_static ("GstDvbSrcBandwidth", bandwidth_types);
-  }
-  return dvbsrc_bandwidth_type;
+	static GType dvbsrc_bandwidth_type = 0;
+	static GEnumValue bandwidth_types[] = {
+		{BANDWIDTH_8_MHZ, "8MHz", "8Mhz"},
+		{BANDWIDTH_7_MHZ, "7", "7"},
+		{BANDWIDTH_6_MHZ, "6", "6"},
+		{BANDWIDTH_AUTO, "AUTO", "AUTO"},
+		{0, NULL, NULL},
+	};
+
+	if (!dvbsrc_bandwidth_type)
+	{
+		dvbsrc_bandwidth_type =
+			g_enum_register_static ("GstDvbSrcBandwidth", bandwidth_types);
+	}
+	return dvbsrc_bandwidth_type;
 }
 
 #define GST_TYPE_DVBSRC_GUARD (gst_dvbsrc_guard_get_type ())
 static GType
 gst_dvbsrc_guard_get_type (void)
 {
-  static GType dvbsrc_guard_type = 0;
-  static GEnumValue guard_types[] = {
-    {GUARD_INTERVAL_1_32, "32", "32"},
-    {GUARD_INTERVAL_1_16, "16", "16"},
-    {GUARD_INTERVAL_1_8,  "8", "8"},
-    {GUARD_INTERVAL_1_4,  "4", "4"},
-    {GUARD_INTERVAL_AUTO, "AUTO", "AUTO"},
-    {0, NULL, NULL},
-  };
- 
-  if (!dvbsrc_guard_type) {
-    dvbsrc_guard_type =
-        g_enum_register_static ("GstDvbSrcGuard", guard_types);
-  }
-  return dvbsrc_guard_type;
+	static GType dvbsrc_guard_type = 0;
+	static GEnumValue guard_types[] = {
+		{GUARD_INTERVAL_1_32, "32", "32"},
+		{GUARD_INTERVAL_1_16, "16", "16"},
+		{GUARD_INTERVAL_1_8, "8", "8"},
+		{GUARD_INTERVAL_1_4, "4", "4"},
+		{GUARD_INTERVAL_AUTO, "AUTO", "AUTO"},
+		{0, NULL, NULL},
+	};
+
+	if (!dvbsrc_guard_type)
+	{
+		dvbsrc_guard_type =
+			g_enum_register_static ("GstDvbSrcGuard", guard_types);
+	}
+	return dvbsrc_guard_type;
 }
 
 #define GST_TYPE_DVBSRC_HIERARCHY (gst_dvbsrc_hierarchy_get_type ())
 static GType
 gst_dvbsrc_hierarchy_get_type (void)
 {
-  static GType dvbsrc_hierarchy_type = 0;
-  static GEnumValue hierarchy_types[] = {
-    {HIERARCHY_NONE, "NONE", "NONE"},
-    {HIERARCHY_1, "1", "1"},
-    {HIERARCHY_2, "2", "2"},
-    {HIERARCHY_4, "4", "4"},
-    {HIERARCHY_AUTO, "AUTO", "AUTO"},
-    {0, NULL, NULL},
-  };
- 
-  if (!dvbsrc_hierarchy_type) {
-    dvbsrc_hierarchy_type =
-        g_enum_register_static ("GstDvbSrcHierarchy", hierarchy_types);
-  }
-  return dvbsrc_hierarchy_type;
-}
-
-static void	             gst_dvbsrc_base_init	(GstDvbSrcClass *klass);
-static void	             gst_dvbsrc_class_init	(GstDvbSrcClass *klass);
-static void	             gst_dvbsrc_init	        (GstDvbSrc *object);
-static void                  gst_dvbsrc_dispose         (GObject *object);
-static void                  gst_dvbsrc_finalize        (GObject *object);
-static void	             gst_dvbsrc_set_property    (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
-static void	             gst_dvbsrc_get_property    (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
-
-static GstPadLinkReturn      gst_dvbsrc_srcconnect_func (GstPad *pad, GstCaps *caps, gboolean newcaps);
-static GstElementStateReturn gst_dvbsrc_change_state    (GstElement *element);
-static void                  gst_dvbsrc_loop            (GstElement* element);
-GstBuffer *                  gst_dvbsrc_get             (GstPad * pad);
-
-
-static gboolean              gst_dvbsrc_tune             (GstDvbSrc* object);
-static void                  gst_dvbsrc_set_pes_filter   (GstDvbSrc* object);
-static void                  gst_dvbsrc_unset_pes_filters(GstDvbSrc* object);
+	static GType dvbsrc_hierarchy_type = 0;
+	static GEnumValue hierarchy_types[] = {
+		{HIERARCHY_NONE, "NONE", "NONE"},
+		{HIERARCHY_1, "1", "1"},
+		{HIERARCHY_2, "2", "2"},
+		{HIERARCHY_4, "4", "4"},
+		{HIERARCHY_AUTO, "AUTO", "AUTO"},
+		{0, NULL, NULL},
+	};
+
+	if (!dvbsrc_hierarchy_type)
+	{
+		dvbsrc_hierarchy_type =
+			g_enum_register_static ("GstDvbSrcHierarchy", hierarchy_types);
+	}
+	return dvbsrc_hierarchy_type;
+}
 
-static gboolean gst_dvbsrc_frontend_status(GstDvbSrc *object);
-static gboolean gst_dvbsrc_adapter_setup(GstDvbSrc* object);
+#define GST_TYPE_DVBSRC_INVERSION (gst_dvbsrc_inversion_get_type ())
+static GType
+gst_dvbsrc_inversion_get_type (void)
+{
+	static GType dvbsrc_inversion_type = 0;
+	static GEnumValue inversion_types[] = {
+		{INVERSION_AUTO, "AUTO", "AUTO"},
+		{INVERSION_ON, "ON", "ON"},
+		{INVERSION_AUTO, "OFF", "OFF"},
+		{0, NULL, NULL},
+	};
+
+	if (!dvbsrc_inversion_type)
+	{
+		dvbsrc_inversion_type =
+			g_enum_register_static ("GstDvbSrcInversion", inversion_types);
+	}
+	return dvbsrc_inversion_type;
+}
 
-static guint gst_dvbsrc_signals[LAST_SIGNAL] = { 0 };
+static void gst_dvbsrc_dispose (GObject * object);
+static void gst_dvbsrc_finalize (GObject * object);
+static void gst_dvbsrc_set_property (GObject * object, guint prop_id,
+									 const GValue * value, GParamSpec * pspec);
+static void gst_dvbsrc_get_property (GObject * object, guint prop_id,
+									 GValue * value, GParamSpec * pspec);
+
+static GstFlowReturn gst_dvbsrc_create (GstPushSrc * element,
+										GstBuffer ** buffer);
+										
+static gboolean gst_dvbsrc_start (GstBaseSrc * bsrc);
+static gboolean gst_dvbsrc_stop (GstBaseSrc * bsrc);
+static gboolean gst_dvbsrc_unlock (GstBaseSrc * bsrc);
+static gboolean gst_dvbsrc_is_seekable (GstBaseSrc * bsrc);
+static gboolean gst_dvbsrc_get_size (GstBaseSrc * src, guint64 * size);
+
+static gboolean gst_dvbsrc_tune (GstDvbSrc * object);
+static void gst_dvbsrc_set_pes_filter (GstDvbSrc * object);
+static void gst_dvbsrc_unset_pes_filters (GstDvbSrc * object);
 
-static GstElementClass *parent_class = NULL;
+static gboolean gst_dvbsrc_frontend_status (GstDvbSrc * object);
 
-static GstStaticPadTemplate ts_src_factory =
-GST_STATIC_PAD_TEMPLATE (
-  "ts_src",
-  GST_PAD_SRC,
-  GST_PAD_ALWAYS,
-  GST_STATIC_CAPS ("video/mpeg-ts, "
-      "mpegversion = (int) 2,"
-      "systemstream = (boolean) TRUE"
-  )
-);
+static guint gst_dvbsrc_signals[LAST_SIGNAL] = { 0 };
+
+static GstStaticPadTemplate ts_src_factory = GST_STATIC_PAD_TEMPLATE ("src",
+																	  GST_PAD_SRC,
+																	  GST_PAD_ALWAYS,
+																	  GST_STATIC_CAPS
+																	  ("video/mpegts, "
+																	   "mpegversion = (int) 2,"
+																	   "systemstream = (boolean) TRUE"));
 
 /*
  ******************************
@@ -256,33 +281,30 @@
  ******************************
  */
 
+
 static void
-demuxer_start(int fd_demuxer)
+demuxer_start (int fd_demuxer)
 {
-  if (ioctl(fd_demuxer, DMX_START) < 0)
-    g_warning("Could not start demuxer: %d", fd_demuxer);
+	if (ioctl (fd_demuxer, DMX_START) < 0)
+		g_warning ("Could not start demuxer: %d", fd_demuxer);
 }
 
 static void
-demuxer_stop(int fd_demuxer)
+demuxer_stop (int fd_demuxer)
 {
-  if (ioctl(fd_demuxer, DMX_STOP) < 0)
-    g_warning("Could not stop demuxer: %d", fd_demuxer);
+	if (ioctl (fd_demuxer, DMX_STOP) < 0)
+		g_warning ("Could not stop demuxer: %d", fd_demuxer);
 }
 
 
 static void
-gst_dvbsrc_send_discont(GstDvbSrc *object)
+gst_dvbsrc_send_discont (GstDvbSrc * object)
 {
-  GstEvent *event = NULL;
-  if (GST_PAD_IS_USABLE(object->srcpad)) {
-    //*
-    event = gst_event_new_flush();
-    gst_pad_push(object->srcpad, GST_DATA(event));
-    event = gst_event_new_discontinuous(TRUE, GST_FORMAT_DEFAULT);
-    gst_pad_push(object->srcpad, GST_DATA(event));
-    //*/
-  }  
+	GstEvent *event = NULL;
+	event = gst_event_new_flush_start ();
+	gst_pad_push_event (object->srcpad, event);
+	event = gst_event_new_flush_stop ();
+	gst_pad_push_event (object->srcpad, event);
 }
 
 
@@ -295,199 +317,173 @@
  ******************************
  */
 
-
-GType
-gst_dvbsrc_get_type (void)
-{
-  static GType gst_dvbsrc_type = 0;
-
-  if (!gst_dvbsrc_type)
-  {
-    static const GTypeInfo plugin_info =
-    {
-      sizeof (GstDvbSrcClass),
-      (GBaseInitFunc) gst_dvbsrc_base_init, 
-      NULL,
-      (GClassInitFunc) gst_dvbsrc_class_init,
-      NULL,
-      NULL,
-      sizeof (GstDvbSrc),
-      0,
-      (GInstanceInitFunc) gst_dvbsrc_init,
-    };
-    gst_dvbsrc_type = g_type_register_static (GST_TYPE_ELEMENT,
-					      "GstDvbSrc",
-					      &plugin_info, 0);
+#define _do_init(bla) \
     GST_DEBUG_CATEGORY_INIT (gstdvbsrc_debug, "dvbsrc", 0, "DVB Source Element");
 
-  }
-  return gst_dvbsrc_type;
-}
+GST_BOILERPLATE_FULL (GstDvbSrc, gst_dvbsrc, GstPushSrc,
+    GST_TYPE_PUSH_SRC, _do_init);
 
 static void
-gst_dvbsrc_base_init (GstDvbSrcClass *klass)
+gst_dvbsrc_base_init (gpointer gclass)
 {
-  GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
-  gst_element_class_add_pad_template (element_class,
-		      gst_static_pad_template_get (&ts_src_factory));
+	GstDvbSrcClass * klass = (GstDvbSrcClass*) gclass;
+	GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+	gst_element_class_add_pad_template (element_class,
+										gst_static_pad_template_get
+										(&ts_src_factory));
 
-  gst_element_class_set_details (element_class, &dvbsrc_details);
+	gst_element_class_set_details (element_class, &dvbsrc_details);
 }
 
 
 /* initialize the plugin's class */
 static void
-gst_dvbsrc_class_init (GstDvbSrcClass *klass)
+gst_dvbsrc_class_init (GstDvbSrcClass * klass)
 {
-  GObjectClass *gobject_class;
-  GstElementClass *gstelement_class;
-
-  gobject_class = (GObjectClass*) klass;
-  gstelement_class = (GstElementClass*) klass;
-
-  parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
-
-  gobject_class->set_property = gst_dvbsrc_set_property;
-  gobject_class->get_property = gst_dvbsrc_get_property;
-  gobject_class->dispose = gst_dvbsrc_dispose;
-  gobject_class->finalize = gst_dvbsrc_finalize;
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_ADAPTER_PREFIX,
-				   g_param_spec_string ("adapter-prefix",
-							"adapter-prefix",
-							"The adapter prefix. e.g. /dev/dvb/adapter0",
-							"/dev/dvb/adapter0",
-							G_PARAM_READWRITE)
-				   );
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_FREQ,
-				   g_param_spec_int ("freq",
-						     "freq",
-						     "Frequency",
-						     0, G_MAXINT, 0,
-						     G_PARAM_READWRITE)
-				   );
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_POL,
-				   g_param_spec_string ("pol",
-						        "pol",
-						        "Polarity [vhHV] (DVB-S)",
-						        "h",
-						        G_PARAM_READWRITE)
-				   );
-
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_PIDS,
-				   g_param_spec_string ("pids",
-							"pids",
-							"Colon seperated list of pids (eg. 110:120)",
-							"",
-							G_PARAM_WRITABLE)
-				   );
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_SYM_RATE,
-				   g_param_spec_int ("srate",
-						     "srate",
-						     "Symbol Rate (DVB-S, DVB-C)",
-						     0, G_MAXINT, DEFAULT_SYMBOL_RATE,
-						     G_PARAM_READWRITE)
-				   );
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_BUFFER_SIZE,
-				   g_param_spec_int ("buffersize",
-						     "buffersize",
-						     "Buffersize in bytes",
-						     IPACKS, G_MAXINT, DEFAULT_BUFFER_SIZE,
-						     G_PARAM_READWRITE)
-				   );
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_TUNE,
-				   g_param_spec_pointer ("tune",
-							 "tune",
-							 "Atomically tune to channel. (For Apps)",
-							 G_PARAM_WRITABLE)
-				   );
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_DISEQC_SRC,
-				   g_param_spec_int ("diseqc_src",
-						     "diseqc_src",
-						     "DISEqC selected source (-1 disabled) (DVB-S)",
-						     -1, 7, DEFAULT_DISEQC_SRC,
-						     G_PARAM_READWRITE)
-				   );
-
-  /* DVB-T, additional properties */
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_BANDWIDTH,
-				   g_param_spec_enum ("bandwidth",
-						     "bandwidth",
-						     "Bandwidth (DVB-T)",
-						     GST_TYPE_DVBSRC_BANDWIDTH, 1,
-						     G_PARAM_WRITABLE)
-				   );
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_CODE_RATE_HP,
-				   g_param_spec_enum ("code-rate-hp",
-						      "code-rate-hp",
-						      "High Priority Code Rate (DVB-T)",
-						      GST_TYPE_DVBSRC_CODE_RATE, 1,
-						      G_PARAM_WRITABLE)
-				   );
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_CODE_RATE_LP,
-				   g_param_spec_enum ("code-rate-lp",
-						      "code-rate-lp",
-						      "Low Priority Code Rate (DVB-T)",
-						      GST_TYPE_DVBSRC_CODE_RATE, 1,
-						      G_PARAM_WRITABLE)
-				   );
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_GUARD,
-				   g_param_spec_enum ("guard",
-						      "guard",
-						      "Guard Intervall (DVB-T)",
-						      GST_TYPE_DVBSRC_GUARD, 1,
-						      G_PARAM_WRITABLE)
-				   );
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_MODULATION,
-				   g_param_spec_enum ("modulation",
-						      "modulation",
-						      "Modulation (DVB-T)",
-						      GST_TYPE_DVBSRC_MODULATION, 1,
-						      G_PARAM_WRITABLE)
-				   );
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_TRANSMISSION_MODE,
-				   g_param_spec_enum ("trans-mode",
-						      "trans-mode",
-						      "Transmission Mode (DVB-T)",
-						      GST_TYPE_DVBSRC_TRANSMISSION_MODE, 1,
-						      G_PARAM_WRITABLE)
-				   );
-
-  g_object_class_install_property (gobject_class, ARG_DVBSRC_HIERARCHY_INF,
-				   g_param_spec_enum ("hierarchy",
-						      "hierarchy",
-						      "Hierarchy Information (DVB-T)",
-						      GST_TYPE_DVBSRC_HIERARCHY, 1,
-						      G_PARAM_WRITABLE)
-				   );
-
-  gst_dvbsrc_signals[ADAPTER_TYPE_SIGNAL] =
-    g_signal_new ("adapter_type", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
-		  G_STRUCT_OFFSET (GstDvbSrcClass, adapter_type), NULL, NULL,
-		  gst_marshal_VOID__INT, G_TYPE_NONE, 1,
-		  G_TYPE_INT);
-
-  gst_dvbsrc_signals[QUALITY_SIGNAL] =
-    g_signal_new ("signal-quality", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
-		  G_STRUCT_OFFSET (GstDvbSrcClass, signal_quality), NULL, NULL,
-		  gst_marshal_VOID__INT_INT, G_TYPE_NONE, 2,
-		  G_TYPE_INT, G_TYPE_INT);
-
+	GObjectClass *gobject_class;
+	GstElementClass *gstelement_class;
+	GstBaseSrcClass *gstbasesrc_class;
+	GstPushSrcClass *gstpushsrc_class;
+
+	gobject_class = (GObjectClass *) klass;
+	gstelement_class = (GstElementClass *) klass;
+	gstbasesrc_class = (GstBaseSrcClass *) klass;
+	gstpushsrc_class = (GstPushSrcClass *) klass;
+
+	gobject_class->set_property = gst_dvbsrc_set_property;
+	gobject_class->get_property = gst_dvbsrc_get_property;
+	gobject_class->dispose = gst_dvbsrc_dispose;
+	gobject_class->finalize = gst_dvbsrc_finalize;
+	
+	gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_dvbsrc_start);
+	gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_dvbsrc_stop);
+	gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_dvbsrc_unlock);
+	gstbasesrc_class->is_seekable = GST_DEBUG_FUNCPTR (gst_dvbsrc_is_seekable);
+  	gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_dvbsrc_get_size);
+	
+	gstpushsrc_class->create = gst_dvbsrc_create;
 
-  gstelement_class->change_state = gst_dvbsrc_change_state;
+	g_object_class_install_property (gobject_class, ARG_DVBSRC_ADAPTER_PREFIX,
+									 g_param_spec_string ("adapter-prefix",
+														  "adapter-prefix",
+														  "The adapter prefix. e.g. /dev/dvb/adapter0",
+														  "/dev/dvb/adapter0",
+														  G_PARAM_READWRITE));
+
+	g_object_class_install_property (gobject_class, ARG_DVBSRC_FREQ,
+									 g_param_spec_int ("freq",
+													   "freq",
+													   "Frequency",
+													   0, G_MAXINT, 0,
+													   G_PARAM_READWRITE));
+
+	g_object_class_install_property (gobject_class, ARG_DVBSRC_POL,
+									 g_param_spec_string ("pol",
+														  "pol",
+														  "Polarity [vhHV] (DVB-S)",
+														  "h",
+														  G_PARAM_READWRITE));
+
+
+	g_object_class_install_property (gobject_class, ARG_DVBSRC_PIDS,
+									 g_param_spec_string ("pids",
+														  "pids",
+														  "Colon seperated list of pids (eg. 110:120)",
+														  "",
+														  G_PARAM_WRITABLE));
+
+	g_object_class_install_property (gobject_class, ARG_DVBSRC_SYM_RATE,
+									 g_param_spec_int ("srate",
+													   "srate",
+													   "Symbol Rate (DVB-S, DVB-C)",
+													   0, G_MAXINT,
+													   DEFAULT_SYMBOL_RATE,
+													   G_PARAM_READWRITE));
+
+	g_object_class_install_property (gobject_class, ARG_DVBSRC_TUNE,
+									 g_param_spec_pointer ("tune",
+														   "tune",
+														   "Atomically tune to channel. (For Apps)",
+														   G_PARAM_WRITABLE));
+
+	g_object_class_install_property (gobject_class, ARG_DVBSRC_DISEQC_SRC,
+									 g_param_spec_int ("diseqc_src",
+													   "diseqc_src",
+													   "DISEqC selected source (-1 disabled) (DVB-S)",
+													   -1, 7,
+													   DEFAULT_DISEQC_SRC,
+													   G_PARAM_READWRITE));
+
+	/* DVB-T, additional properties */
+
+	g_object_class_install_property (gobject_class, ARG_DVBSRC_BANDWIDTH,
+									 g_param_spec_enum ("bandwidth",
+														"bandwidth",
+														"Bandwidth (DVB-T)",
+														GST_TYPE_DVBSRC_BANDWIDTH,
+														1, G_PARAM_WRITABLE));
+
+	g_object_class_install_property (gobject_class, ARG_DVBSRC_CODE_RATE_HP,
+									 g_param_spec_enum ("code-rate-hp",
+														"code-rate-hp",
+														"High Priority Code Rate (DVB-T)",
+														GST_TYPE_DVBSRC_CODE_RATE,
+														1, G_PARAM_WRITABLE));
+
+	g_object_class_install_property (gobject_class, ARG_DVBSRC_CODE_RATE_LP,
+									 g_param_spec_enum ("code-rate-lp",
+														"code-rate-lp",
+														"Low Priority Code Rate (DVB-T)",
+														GST_TYPE_DVBSRC_CODE_RATE,
+														1, G_PARAM_WRITABLE));
+
+	g_object_class_install_property (gobject_class, ARG_DVBSRC_GUARD,
+									 g_param_spec_enum ("guard",
+														"guard",
+														"Guard Intervall (DVB-T)",
+														GST_TYPE_DVBSRC_GUARD,
+														1, G_PARAM_WRITABLE));
+
+	g_object_class_install_property (gobject_class, ARG_DVBSRC_MODULATION,
+									 g_param_spec_enum ("modulation",
+														"modulation",
+														"Modulation (DVB-T)",
+														GST_TYPE_DVBSRC_MODULATION,
+														1, G_PARAM_WRITABLE));
+
+	g_object_class_install_property (gobject_class,
+									 ARG_DVBSRC_TRANSMISSION_MODE,
+									 g_param_spec_enum ("trans-mode",
+														"trans-mode",
+														"Transmission Mode (DVB-T)",
+														GST_TYPE_DVBSRC_TRANSMISSION_MODE,
+														1, G_PARAM_WRITABLE));
+
+	g_object_class_install_property (gobject_class, ARG_DVBSRC_HIERARCHY_INF,
+									 g_param_spec_enum ("hierarchy",
+														"hierarchy",
+														"Hierarchy Information (DVB-T)",
+														GST_TYPE_DVBSRC_HIERARCHY,
+														1, G_PARAM_WRITABLE));
+	g_object_class_install_property (gobject_class, ARG_DVBSRC_INVERSION,
+									 g_param_spec_enum ("inversion",
+														"inversion",
+														"Inversion Information (DVB-T)",
+														GST_TYPE_DVBSRC_INVERSION,
+														1, G_PARAM_WRITABLE));
+
+	gst_dvbsrc_signals[ADAPTER_TYPE_SIGNAL] =
+		g_signal_new ("adapter_type", G_TYPE_FROM_CLASS (klass),
+					  G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDvbSrcClass,
+														  adapter_type), NULL,
+					  NULL, gst_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
+
+	gst_dvbsrc_signals[QUALITY_SIGNAL] =
+		g_signal_new ("signal-quality", G_TYPE_FROM_CLASS (klass),
+					  G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDvbSrcClass,
+														  signal_quality), NULL,
+					  NULL, gst_marshal_VOID__INT_INT, G_TYPE_NONE, 2,
+					  G_TYPE_INT, G_TYPE_INT);
 }
 
 /* initialize the new element
@@ -496,278 +492,311 @@
  * initialize structure
  */
 static void
-gst_dvbsrc_init (GstDvbSrc *object)
+gst_dvbsrc_init (GstDvbSrc * object, GstDvbSrcClass* klass)
 {
-  int i=0;
-  GST_INFO("gst_dvbsrc_init");
+	int i = 0;
+	GST_INFO ("gst_dvbsrc_init");
 
-  object->srcpad = gst_pad_new_from_template(gst_static_pad_template_get (&ts_src_factory), "src");
-  gst_element_set_loop_function (GST_ELEMENT(object), gst_dvbsrc_loop);
-  gst_element_add_pad (GST_ELEMENT (object), object->srcpad);
-
-  object->fd_frontend = -1;
-  object->fd_dvr = -1;
-
-  for (i=0; i<MAX_FILTERS; i++) {
-    object->pids[i] = 0;
-    object->fd_filters[i] = -1;
-  }
-
-  /* Setting standard devices */
-  object->adapter_prefix = g_strdup(DEFAULT_ADAPTER_PREFIX);
-  object->frontend_dev   = g_strconcat(object->adapter_prefix, "/frontend0", NULL);
-  object->demux_dev      = g_strconcat(object->adapter_prefix, "/demux0", NULL);
-  object->dvr_dev        = g_strconcat(object->adapter_prefix, "/dvr0", NULL);
-
-
-  object->buffersize = DEFAULT_BUFFER_SIZE;
-  object->sym_rate   = DEFAULT_SYMBOL_RATE;
-  object->diseqc_src = DEFAULT_DISEQC_SRC;
-  object->send_diseqc = FALSE;
-
-  /* set to something sane for testing purpose */
-  //* 3SAT (Germany) on Astra 19.2 EAST
-  object->diseqc_src = 1;
-  object->pol = DVB_POL_H;
-  object->freq = 11954;
-  object->sym_rate = 27500;
-  object->pids[0] = 210;
-  object->pids[1] = 220;
-  //*/
+	/* We are a live source */
+	gst_base_src_set_live(GST_BASE_SRC(object), TRUE);
 
-  object->tune_mutex = g_mutex_new();
+	/*object->srcpad =
+		gst_pad_new_from_template (gst_static_pad_template_get
+								   (&ts_src_factory), NULL);
+	gst_element_add_pad (GST_ELEMENT (object), object->srcpad);*/
+
+	object->fd_frontend = -1;
+	object->fd_dvr = -1;
+
+	for (i = 0; i < MAX_FILTERS; i++)
+	{
+		object->pids[i] = 0;
+		object->fd_filters[i] = -1;
+	}
+
+	/* Setting standard devices */
+	object->adapter_prefix = g_strdup (DEFAULT_ADAPTER_PREFIX);
+	object->frontend_dev =
+		g_strconcat (object->adapter_prefix, "/frontend0", NULL);
+	object->demux_dev = g_strconcat (object->adapter_prefix, "/demux0", NULL);
+	object->dvr_dev = g_strconcat (object->adapter_prefix, "/dvr0", NULL);
+
+	object->sym_rate = DEFAULT_SYMBOL_RATE;
+	object->diseqc_src = DEFAULT_DISEQC_SRC;
+	object->send_diseqc = FALSE;
+
+	object->tune_mutex = g_mutex_new ();
 }
 
 
 static void
-gst_dvbsrc_set_property (GObject *_object, guint prop_id,
-			 const GValue *value, GParamSpec *pspec)
+gst_dvbsrc_set_property (GObject * _object, guint prop_id,
+						 const GValue * value, GParamSpec * pspec)
 {
-  GstDvbSrc *object;
+	GstDvbSrc *object;
 
-  g_return_if_fail (GST_IS_DVBSRC (_object));
-  object = GST_DVBSRC (_object);
+	g_return_if_fail (GST_IS_DVBSRC (_object));
+	object = GST_DVBSRC (_object);
 
-  switch (prop_id) {
-  case ARG_DVBSRC_ADAPTER_PREFIX: {
-    char delim_str [] = "/\0";
-    if (object->adapter_prefix != NULL) g_free(object->adapter_prefix);
-    object->adapter_prefix = g_value_dup_string(value);
-
-    if (g_str_has_suffix(object->adapter_prefix, "/"))
-      delim_str[0] = '\0';
-
-    object->frontend_dev   = g_strconcat(object->adapter_prefix, delim_str, "frontend0", NULL);
-    object->demux_dev      = g_strconcat(object->adapter_prefix, delim_str, "demux0", NULL);
-    object->dvr_dev        = g_strconcat(object->adapter_prefix, delim_str, "dvr0", NULL);
-    }
-    GST_INFO("Set Property: ARG_DVBSRC_ADAPTER_PREFIX");
-    break;
-  case ARG_DVBSRC_DISEQC_SRC:
-    if (object->diseqc_src != g_value_get_int(value)) {
-      object->diseqc_src = g_value_get_int(value);
-      object->send_diseqc = TRUE;
-    }
-    GST_INFO("Set Property: ARG_DVBSRC_DISEQC_ID");
-    break;
-  case ARG_DVBSRC_FREQ:
-    object->freq = g_value_get_int(value);
-    GST_INFO("Set Property: ARG_DVBSRC_FREQ");
-    break;
-  case ARG_DVBSRC_POL: {
-    const char *s = NULL;
-    s = g_value_get_string(value);
-    if (s != NULL) 
-      object->pol = (s[0] == 'h' || s[0] == 'H') ? DVB_POL_H : DVB_POL_V;
-    }
-    GST_INFO("Set Property: ARG_DVBSRC_POL");
-    break;
-  case ARG_DVBSRC_PIDS: {
-      int pid=0;
-      int pid_count=0;
-      char* pid_string;
-      char** pids;
-      char** tmp;
-
-      GST_INFO("Set Property: ARG_DVBSRC_PIDS");
-      pid_string = g_value_dup_string(value);
-      tmp = pids = g_strsplit(pid_string, ":", MAX_FILTERS);
-      while (*pids != NULL && pid_count < MAX_FILTERS) {
-        pid = strtol(*pids, NULL, 0);
-        if (pid > 0 && pid <= 8192) {
-          GST_INFO("Parsed Pid: %d\n", pid);
-          object->pids[pid_count] = pid;
-          pid_count++;
-        }
-        pids++;
-      }
-      g_strfreev(tmp);
-    }
-    break;
-  case ARG_DVBSRC_SYM_RATE:
-    object->sym_rate = g_value_get_int(value);
-    GST_INFO("Set Property: ARG_DVBSRC_SYM_RATE");
-    break;
-  case ARG_DVBSRC_BUFFER_SIZE:
-    object->buffersize = g_value_get_int(value);
-    GST_INFO("Set Property: ARG_DVBSRC_BUFFER_SIZE");
-    break;
-
-  case ARG_DVBSRC_BANDWIDTH:
-    object->bandwidth = g_value_get_enum(value);
-    break;
-  case ARG_DVBSRC_CODE_RATE_HP:
-    object->code_rate_hp = g_value_get_enum(value);
-    break;
-  case ARG_DVBSRC_CODE_RATE_LP:
-    object->code_rate_lp = g_value_get_enum(value);
-    break;
-  case ARG_DVBSRC_GUARD:
-    object->guard_interval = g_value_get_enum(value);
-    break;
-  case ARG_DVBSRC_MODULATION:
-    object->modulation = g_value_get_enum(value);
-    break;
-  case ARG_DVBSRC_TRANSMISSION_MODE:
-    object->transmission_mode = g_value_get_enum(value);
-    break;
-  case ARG_DVBSRC_HIERARCHY_INF:
-    object->hierarchy_information = g_value_get_enum(value);
-    break;
-  case ARG_DVBSRC_TUNE:
-    GST_INFO("Set Property: ARG_DVBSRC_TUNE");
-    /* if we are in paused/playing state tune now, otherwise in ready to paused state change */
-    if (gst_element_get_state(GST_ELEMENT(object)) > GST_STATE_READY) {
-      gst_dvbsrc_send_discont(object);
-      g_mutex_lock(object->tune_mutex);
-      gst_dvbsrc_tune(object);
-      g_mutex_unlock(object->tune_mutex);
-    }
-    break;
-  default:
-    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-  }
+	switch (prop_id)
+	{
+	case ARG_DVBSRC_ADAPTER_PREFIX:
+	{
+		char delim_str[] = "/\0";
+		if (object->adapter_prefix != NULL)
+			g_free (object->adapter_prefix);
+		object->adapter_prefix = g_value_dup_string (value);
+
+		if (g_str_has_suffix (object->adapter_prefix, "/"))
+			delim_str[0] = '\0';
+
+		object->frontend_dev =
+			g_strconcat (object->adapter_prefix, delim_str, "frontend0", NULL);
+		object->demux_dev =
+			g_strconcat (object->adapter_prefix, delim_str, "demux0", NULL);
+		object->dvr_dev =
+			g_strconcat (object->adapter_prefix, delim_str, "dvr0", NULL);
+	}
+		GST_INFO ("Set Property: ARG_DVBSRC_ADAPTER_PREFIX");
+		break;
+	case ARG_DVBSRC_DISEQC_SRC:
+		if (object->diseqc_src != g_value_get_int (value))
+		{
+			object->diseqc_src = g_value_get_int (value);
+			object->send_diseqc = TRUE;
+		}
+		GST_INFO ("Set Property: ARG_DVBSRC_DISEQC_ID");
+		break;
+	case ARG_DVBSRC_FREQ:
+		object->freq = g_value_get_int (value);
+		GST_INFO ("Set Property: ARG_DVBSRC_FREQ");
+		break;
+	case ARG_DVBSRC_POL:
+	{
+		const char *s = NULL;
+		s = g_value_get_string (value);
+		if (s != NULL)
+			object->pol = (s[0] == 'h' || s[0] == 'H') ? DVB_POL_H : DVB_POL_V;
+	}
+		GST_INFO ("Set Property: ARG_DVBSRC_POL");
+		break;
+	case ARG_DVBSRC_PIDS:
+	{
+		int pid = 0;
+		int pid_count = 0;
+		char *pid_string;
+		char **pids;
+		char **tmp;
+
+		GST_INFO ("Set Property: ARG_DVBSRC_PIDS");
+		pid_string = g_value_dup_string (value);
+		tmp = pids = g_strsplit (pid_string, ":", MAX_FILTERS);
+		while (*pids != NULL && pid_count < MAX_FILTERS)
+		{
+			pid = strtol (*pids, NULL, 0);
+			if (pid > 0 && pid <= 8192)
+			{
+				GST_INFO ("Parsed Pid: %d\n", pid);
+				object->pids[pid_count] = pid;
+				pid_count++;
+			}
+			pids++;
+		}
+		g_strfreev (tmp);
+	}
+		break;
+	case ARG_DVBSRC_SYM_RATE:
+		object->sym_rate = g_value_get_int (value);
+		GST_INFO ("Set Property: ARG_DVBSRC_SYM_RATE");
+		break;
+
+	case ARG_DVBSRC_BANDWIDTH:
+		object->bandwidth = g_value_get_enum (value);
+		break;
+	case ARG_DVBSRC_CODE_RATE_HP:
+		object->code_rate_hp = g_value_get_enum (value);
+		break;
+	case ARG_DVBSRC_CODE_RATE_LP:
+		object->code_rate_lp = g_value_get_enum (value);
+		break;
+	case ARG_DVBSRC_GUARD:
+		object->guard_interval = g_value_get_enum (value);
+		break;
+	case ARG_DVBSRC_MODULATION:
+		object->modulation = g_value_get_enum (value);
+		break;
+	case ARG_DVBSRC_TRANSMISSION_MODE:
+		object->transmission_mode = g_value_get_enum (value);
+		break;
+	case ARG_DVBSRC_HIERARCHY_INF:
+		object->hierarchy_information = g_value_get_enum (value);
+		break;
+	case ARG_DVBSRC_INVERSION:
+		object->inversion = g_value_get_enum(value);
+		break;
+	case ARG_DVBSRC_TUNE:
+		GST_INFO ("Set Property: ARG_DVBSRC_TUNE");
+		/* if we are in paused/playing state tune now, otherwise in ready to paused state change */
+		if (gst_element_get_state
+			(GST_ELEMENT (object), NULL, NULL,
+			 GST_CLOCK_TIME_NONE) > GST_STATE_READY)
+		{
+			gst_dvbsrc_send_discont (object);
+			g_mutex_lock (object->tune_mutex);
+			gst_dvbsrc_tune (object);
+			g_mutex_unlock (object->tune_mutex);
+		}
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+	}
 
 }
 
 
 static void
-gst_dvbsrc_get_property (GObject *_object, guint prop_id,
-			 GValue *value, GParamSpec *pspec)
+gst_dvbsrc_get_property (GObject * _object, guint prop_id,
+						 GValue * value, GParamSpec * pspec)
 {
-  GstDvbSrc *object;
+	GstDvbSrc *object;
 
-  g_return_if_fail (GST_IS_DVBSRC (_object));
-  object = GST_DVBSRC (_object);
+	g_return_if_fail (GST_IS_DVBSRC (_object));
+	object = GST_DVBSRC (_object);
 
-  switch (prop_id)
-  {
-  case ARG_DVBSRC_ADAPTER_PREFIX:
-    g_value_set_string(value, object->adapter_prefix);
-    break;
-  case ARG_DVBSRC_FREQ:
-    g_value_set_int(value, object->freq);
-    break;
-  case ARG_DVBSRC_POL:
-    if (object->pol == DVB_POL_H)
-      g_value_set_string(value, "H");
-    else
-      g_value_set_string(value, "V");
-    break;
-  case ARG_DVBSRC_SYM_RATE:
-    g_value_set_int(value, object->sym_rate);
-    break;
-  case ARG_DVBSRC_BUFFER_SIZE:
-    g_value_set_int(value, object->buffersize);
-    break;
-  case ARG_DVBSRC_DISEQC_SRC:
-    g_value_set_int(value, object->diseqc_src);
-    break;
-  default:
-    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-  }
+	switch (prop_id)
+	{
+	case ARG_DVBSRC_ADAPTER_PREFIX:
+		g_value_set_string (value, object->adapter_prefix);
+		break;
+	case ARG_DVBSRC_FREQ:
+		g_value_set_int (value, object->freq);
+		break;
+	case ARG_DVBSRC_POL:
+		if (object->pol == DVB_POL_H)
+			g_value_set_string (value, "H");
+		else
+			g_value_set_string (value, "V");
+		break;
+	case ARG_DVBSRC_SYM_RATE:
+		g_value_set_int (value, object->sym_rate);
+		break;
+	case ARG_DVBSRC_DISEQC_SRC:
+		g_value_set_int (value, object->diseqc_src);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+	}
 }
 
 static gboolean
-gst_dvbsrc_close_devices(GstDvbSrc *object)
+gst_dvbsrc_close_devices (GstDvbSrc * object)
 {
-  gst_dvbsrc_unset_pes_filters(object);
+	gst_dvbsrc_unset_pes_filters (object);
+
+	close (object->fd_dvr);
+	object->fd_dvr = -1;
+	close (object->fd_frontend);
+	object->fd_frontend = -1;
 
-  close(object->fd_dvr);
-  object->fd_dvr = -1;
-  close(object->fd_frontend);
-  object->fd_frontend = -1;
+	return TRUE;
 }
 
 static gboolean
-gst_dvbsrc_open_devices(GstDvbSrc *object)
+gst_dvbsrc_open_frontend (GstDvbSrc * object)
 {
-  struct dvb_frontend_info fe_info;
-  char *adapter_desc;
+	struct dvb_frontend_info fe_info;
+	char *adapter_desc = NULL;
+
+	GST_INFO ("Using frontend: %s", object->frontend_dev);
+	GST_INFO ("Using dvr:  %s", object->dvr_dev);
+
+	/* open frontend */
+	if ((object->fd_frontend =
+		 open (object->frontend_dev, O_RDWR)) < 0)
+	{
+		close (object->fd_dvr);
+		g_warning ("Could not open frontend: %s, %s", object->frontend_dev,
+				   strerror (errno));
+		return FALSE;
+	}
 
-  GST_INFO("Using frontend: %s", object->frontend_dev);
-  GST_INFO("Using dvr:  %s", object->dvr_dev);
+	if (ioctl (object->fd_frontend, FE_GET_INFO, &fe_info) < 0)
+	{
+		close (object->fd_dvr);
+		close (object->fd_frontend);
 
-  /* open frontend */
-  if ((object->fd_frontend = open(object->frontend_dev, O_RDWR)) < 0) {
-    g_warning("Could not open frontend: %s, %s", object->frontend_dev, strerror(errno));
-    return FALSE;
-  }
-
-  /* open DVR */
-  if ((object->fd_dvr = open(object->dvr_dev, O_RDONLY)) < 0) {
-    g_warning("Could not open dvr device: %s", object->dvr_dev);
-    return FALSE;
-  }
-  
-  if ( ioctl(object->fd_frontend, FE_GET_INFO, &fe_info) < 0){
-    g_warning("Unable to get frontend info: ", strerror(errno));
-    return FALSE;
-  }
-  
-  object->adapter_type = fe_info.type;
-  switch (object->adapter_type) {
-    case FE_QPSK: adapter_desc = "DVB-S"; break;
-    case FE_QAM:  adapter_desc = "DVB-C"; break;
-    case FE_OFDM: adapter_desc = "DVB-T"; break;
-  default:
-    g_error("Unknown frontend type: %d", object->adapter_type);  
-  }
+		g_warning ("Unable to get frontend info: %s", strerror (errno));
+		return FALSE;
+	}
+
+	object->adapter_type = fe_info.type;
+	switch (object->adapter_type)
+	{
+	case FE_QPSK:
+		adapter_desc = "DVB-S";
+		break;
+	case FE_QAM:
+		adapter_desc = "DVB-C";
+		break;
+	case FE_OFDM:
+		adapter_desc = "DVB-T";
+		break;
+	default:
+		g_error ("Unknown frontend type: %d", object->adapter_type);
+	}
 
-  g_signal_emit(G_OBJECT(object), gst_dvbsrc_signals[ADAPTER_TYPE_SIGNAL], 0, object->adapter_type);
+	g_signal_emit (G_OBJECT (object), gst_dvbsrc_signals[ADAPTER_TYPE_SIGNAL],
+				   0, object->adapter_type);
 
-  GST_INFO("DVB card: %s (%s)", fe_info.name, adapter_desc);
+	GST_INFO ("DVB card: %s (%s)", fe_info.name);
+	return TRUE;
 }
 
+static gboolean
+gst_dvbsrc_open_dvr(GstDvbSrc* object)
+{
+	/* open DVR */
+	if ((object->fd_dvr = open (object->dvr_dev, O_RDONLY|O_NONBLOCK)) < 0)
+	{
+		g_warning ("Could not open dvr device: %s", object->dvr_dev);
+		return FALSE;
+	}
+	GST_INFO("Setting buffer size");
+	if (ioctl(object->fd_dvr, DMX_SET_BUFFER_SIZE, 1024 * 1024)<0)
+	{
+		GST_INFO("DMX_SET_BUFFER_SIZE failed");
+		return FALSE;
+	}
+	return TRUE;
+}
 
 static void
-gst_dvbsrc_dispose (GObject *_object)
+gst_dvbsrc_dispose (GObject * _object)
 {
-  GstDvbSrc *object;
-  GST_DEBUG("gst_dvbsrc_dispose");
+	GstDvbSrc *object;
+	GST_DEBUG ("gst_dvbsrc_dispose");
 
-  g_return_if_fail (GST_IS_DVBSRC (_object));
-  object = GST_DVBSRC (_object);
+	g_return_if_fail (GST_IS_DVBSRC (_object));
+	object = GST_DVBSRC (_object);
 }
 
 static void
-gst_dvbsrc_finalize (GObject *_object)
+gst_dvbsrc_finalize (GObject * _object)
 {
-  GstDvbSrc *object;
-  GST_DEBUG("gst_dvbsrc_finalize");
+	GstDvbSrc *object;
+	GST_DEBUG ("gst_dvbsrc_finalize");
 
-  g_return_if_fail (GST_IS_DVBSRC (_object));
-  object = GST_DVBSRC (_object);
+	g_return_if_fail (GST_IS_DVBSRC (_object));
+	object = GST_DVBSRC (_object);
 
-  g_free(object->frontend_dev);
-  g_free(object->demux_dev);
+	g_free (object->frontend_dev);
+	g_free (object->demux_dev);
 
-  /* freeing the mutex segfaults somehow */
-  //  g_mutex_free(object->tune_mutex);
+	/* freeing the mutex segfaults somehow */
+	//  g_mutex_free(object->tune_mutex);
 }
 
 
-
 /*
  ******************************
  *                            *
@@ -784,497 +813,507 @@
  * register the features
  */
 static gboolean
-plugin_init (GstPlugin *plugin)
+plugin_init (GstPlugin * plugin)
 {
-  return gst_element_register (plugin, "dvbsrc", GST_RANK_NONE, GST_TYPE_DVBSRC);
+	return gst_element_register (plugin, "dvbsrc", GST_RANK_NONE,
+								 GST_TYPE_DVBSRC);
 }
 
-GST_PLUGIN_DEFINE (
-  GST_VERSION_MAJOR,
-  GST_VERSION_MINOR,
-  "dvbsrc",
-  "DVB Source",
-  plugin_init,
-  VERSION,
-  "LGPL",
-  "",
-  "University of Paderborn"
-  )
-
-static GstBuffer*
-read_device(int fd, const char *fd_name, int size) {
-  int count = 0;
-  struct pollfd pfd[1];
-  int ret_val = 0;
-  int attempts = 0;
-
-  GstBuffer *buf = gst_buffer_new();
-  g_return_if_fail(GST_IS_BUFFER(buf));
-  GST_BUFFER_DATA(buf) = g_malloc(size);
-
-  
-  if (fd < 0) {
-    return NULL;
-  }
-
-  pfd[0].fd = fd;
-  pfd[0].events = POLLIN;
-
-  while (count < size) {
-    ret_val = poll(pfd, 1, 500);
-    if (ret_val > 0) {
-      if (pfd[0].revents & POLLIN){
-	int tmp = 0;
-	tmp = read(fd, GST_BUFFER_DATA(buf)+count, size-count);
-	if (tmp < 0) {
-	  GST_WARNING("Unable to read from device: %s (%d)", fd_name, errno);
-	  goto fail;
-	}
-	else
-	  count = count + tmp;
-      }
-      else {
-	fprintf(stderr, "revents = %d\n", pfd[0].revents);
-      }
-    }
-    else if (ret_val == 0) {    // poll timeout
-      attempts += 1;
-      GST_INFO("Reading from device %s timedout (%d)", fd_name, attempts);
-      
-      if (attempts == MAX_ATTEMPTS) { 
-	GST_WARNING("Unable to read from device: %s (%d)", fd_name, errno);
-	goto fail;
-      }
-    }
-    else if (errno == -EINTR) { // poll interrupted
-      ;
-    }
-    
-  }
-  
-  GST_BUFFER_SIZE(buf) = count;
-  GST_BUFFER_TIMESTAMP(buf) = GST_CLOCK_TIME_NONE;
-  goto end;
-
- fail:
-  g_free(GST_BUFFER_DATA(buf));
-  GST_BUFFER_DATA(buf) = NULL;
-  GST_BUFFER_SIZE(buf) = 0;
-  gst_buffer_unref(buf);
-  buf = NULL;
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+				   GST_VERSION_MINOR,
+				   "dvbsrc",
+				   "DVB Source",
+				   plugin_init, VERSION, "LGPL", "", "University of Paderborn")
+				   
+static GstBuffer *read_device (int fd, const char *fd_name, int size)
+{
+	int count = 0;
+	struct pollfd pfd[1];
+	int ret_val = 0;
+	int attempts = 0;
+	const int TIMEOUT = 100;
 
- end:
-  return buf;
-}
+	GstBuffer *buf = gst_buffer_new ();
+	
+	g_return_val_if_fail (GST_IS_BUFFER (buf), NULL);
+	GST_BUFFER_DATA (buf) = g_malloc (size);
 
-static void
-gst_dvbsrc_loop (GstElement *element)
-{
-  static int quality_signal_rate = 0;
+	if (fd < 0)
+	{
+		return NULL;
+	}
 
-  GstBuffer *buf;
-  GstDvbSrc *object = NULL;
-  g_return_if_fail (GST_IS_DVBSRC (element));
-  object = GST_DVBSRC(element);
-
-  /* device can not be tuned during read */
-  g_mutex_lock(object->tune_mutex);
-
-
-  if (object->fd_dvr > -1 && GST_PAD_IS_USABLE(object->srcpad)) {
-    /* --- Read TS from DVR device --- */
-    GST_DEBUG("Reading from dvr device");
-    buf = read_device(object->fd_dvr, object->dvr_dev, object->buffersize);
-    if (buf != NULL) {
-      gst_pad_push(object->srcpad, GST_DATA(buf));
-      
-      /* Every now and then signal signal quality */
-      if (quality_signal_rate == 10) {
-	guint16 strength = 0;
-	guint16 snr = 0;
+	pfd[0].fd = fd;
+	pfd[0].events = POLLIN;
 
-	if ( ioctl(object->fd_frontend, FE_READ_SIGNAL_STRENGTH, &strength) < 0)
-	  g_warning("Unable to read signal strength: ", strerror(errno));
+	while (count < size)
+	{
+		ret_val = poll (pfd, 1, TIMEOUT);
+		if (ret_val > 0)
+		{
+			if (pfd[0].revents & POLLIN)
+			{
+				int tmp = 0;
+				tmp = read (fd, GST_BUFFER_DATA (buf) + count, size - count);
+				if (tmp < 0)
+				{
+					GST_WARNING ("Unable to read from device: %s (%d)", fd_name,
+								 errno);
+					goto fail;
+				}
+				else
+					count = count + tmp;
+			}
+			else
+			{
+				fprintf (stderr, "revents = %d\n", pfd[0].revents);
+			}
+		}
+		else if (ret_val == 0)
+		{						// poll timeout
+			attempts += 1;
+			GST_INFO ("Reading from device %s timedout (%d)", fd_name,
+					  attempts);
+
+			if (attempts == MAX_ATTEMPTS)
+			{
+				GST_WARNING ("Unable to read from device: %s (%d)", fd_name,
+							 errno);
+				goto fail;
+			}
+		}
+		else if (errno == -EINTR)
+		{						// poll interrupted
+			;
+		}
 
-	if ( ioctl(object->fd_frontend, FE_READ_SIGNAL_STRENGTH, &strength) < 0)
-	  g_warning("Unable to read signal strength: ", strerror(errno));
+	}
 	
-	GST_INFO("Signal Quality: %d Strength, %d Signal Noise Ratio", strength, snr);
-	g_signal_emit(G_OBJECT(object), gst_dvbsrc_signals[QUALITY_SIGNAL], 0, strength, snr);
+	GST_BUFFER_SIZE (buf) = count;
+	GST_BUFFER_TIMESTAMP (buf) = GST_CLOCK_TIME_NONE;
+	goto end;
+
+  fail:
+	g_free (GST_BUFFER_DATA (buf));
+	GST_BUFFER_DATA (buf) = NULL;
+	GST_BUFFER_SIZE (buf) = 0;
+	gst_buffer_unref (buf);
+	buf = NULL;
+
+  end:
+	return buf;
+}
+
+static GstFlowReturn
+gst_dvbsrc_create (GstPushSrc * element, GstBuffer ** buf)
+{
+	static int quality_signal_rate = 0;
+	gint buffer_size;
+	GstFlowReturn retval = GST_FLOW_ERROR;
+
+	GstDvbSrc *object = NULL;
+	g_return_val_if_fail (GST_IS_DVBSRC (element), GST_FLOW_ERROR);
+	g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
+	object = GST_DVBSRC (element);
+	//g_object_get(G_OBJECT(object), "blocksize", &buffer_size, NULL);
+	buffer_size = DEFAULT_BUFFER_SIZE;
+	
+	/* device can not be tuned during read */
+	g_mutex_lock (object->tune_mutex);
 
-	quality_signal_rate = 0;
-      }
-      else {
-	quality_signal_rate++;
-      }
 
-    }
-    else {
-      GST_DEBUG("Failed to read from device");
-    }
-  }
+	if (object->fd_dvr > -1)
+	{
+		/* --- Read TS from DVR device --- */
+		GST_DEBUG ("Reading from DVR device");
+		*buf =
+			read_device (object->fd_dvr, object->dvr_dev, buffer_size);
+		if (*buf != NULL)
+		{
+			GstCaps* caps;
+			retval = GST_FLOW_OK;
+		
+			caps = gst_pad_get_caps (GST_BASE_SRC_PAD (object));
+			gst_buffer_set_caps (*buf, caps);
+			gst_caps_unref (caps);
+			
+			/* Every now and then signal signal quality */
+			if (quality_signal_rate == 10)
+			{
+				guint16 strength = 0;
+				guint16 snr = 0;
+
+				if (ioctl
+					(object->fd_frontend, FE_READ_SIGNAL_STRENGTH,
+					 &strength) < 0)
+					g_warning ("Unable to read signal strength: %s",
+							   strerror (errno));
+
+				if (ioctl
+					(object->fd_frontend, FE_READ_SIGNAL_STRENGTH,
+					 &strength) < 0)
+					g_warning ("Unable to read signal strength: %s",
+							   strerror (errno));
+
+				GST_INFO ("Signal Quality: %d Strength, %d Signal Noise Ratio",
+						  strength, snr);
+				g_signal_emit (G_OBJECT (object),
+							   gst_dvbsrc_signals[QUALITY_SIGNAL], 0, strength,
+							   snr);
+
+				quality_signal_rate = 0;
+			}
+			else
+			{
+				quality_signal_rate++;
+			}
+		}
+		else
+		{
+			GST_DEBUG ("Failed to read from device");
+		}
+	}
 
-  g_mutex_unlock(object->tune_mutex);
+	g_mutex_unlock (object->tune_mutex);
+	return retval;
 
 }
 
+static gboolean 
+gst_dvbsrc_start (GstBaseSrc * bsrc)
+{
+	GstDvbSrc* src = GST_DVBSRC(bsrc);
+	gst_dvbsrc_open_frontend (src);
+	gst_dvbsrc_tune (src);
+	if (!gst_dvbsrc_frontend_status(src))
+	{
+		return FALSE;
+	}
+	if (!gst_dvbsrc_open_dvr(src))
+	{
+		GST_ERROR("\nNot able to open dvr_device");
+			return FALSE;
+	}
+	
+	return TRUE;
+}
 
-static GstElementStateReturn
-gst_dvbsrc_change_state (GstElement *element)
+static gboolean 
+gst_dvbsrc_stop (GstBaseSrc * bsrc)
 {
-  GstDvbSrc *object;
+	GstDvbSrc* src = GST_DVBSRC(bsrc);
+	gst_dvbsrc_close_devices (src);
+	return TRUE;
+}
 
-  object = GST_DVBSRC (element);
+static gboolean 
+gst_dvbsrc_unlock (GstBaseSrc * bsrc)
+{
+	return  TRUE;
+}
 
-  GST_INFO ("gst_dvbsrc_change_state");
+static gboolean gst_dvbsrc_is_seekable (GstBaseSrc * bsrc)
+{
+	return FALSE;
+}
 
-  switch (GST_STATE_TRANSITION (element)) {
-  case GST_STATE_NULL_TO_READY:
-    /* Open devices */
-    gst_dvbsrc_open_devices(object);
-  case GST_STATE_READY_TO_PAUSED:
-    /* tune the device  */
-    gst_dvbsrc_tune(object);
-    break;
-  case GST_STATE_PAUSED_TO_PLAYING:
-    /* Check if we have a tuned successfully */
-    /*    if (!gst_dvbsrc_frontend_status(object))
-	  g_warning("Unable to tune to given frequency");*/
+static gboolean gst_dvbsrc_get_size (GstBaseSrc * src, guint64 * size)
+{
+	return FALSE;
+}
 
-    break;
-  case GST_STATE_PLAYING_TO_PAUSED:
-    /* stop demuxers */
-    
+static void
+print_frontend_stats (int fe_fd)
+{
+	fe_status_t status;
+	uint16_t snr, _signal;
+	uint32_t ber, uncorrected_blocks;
+
+	ioctl(fe_fd, FE_READ_STATUS, &status);
+	ioctl(fe_fd, FE_READ_SIGNAL_STRENGTH, &_signal);
+	ioctl(fe_fd, FE_READ_SNR, &snr);
+	ioctl(fe_fd, FE_READ_BER, &ber);
+	ioctl(fe_fd, FE_READ_UNCORRECTED_BLOCKS, &uncorrected_blocks);
+
+	GST_INFO ("status %02x | signal %04x | snr %04x | "
+		"ber %08x | unc %08x | ",
+		status, _signal, snr, ber, uncorrected_blocks);
 
-    /* empty buffers */
-    
-    break;
-  case GST_STATE_PAUSED_TO_READY:
-    /* close devices */
-    gst_dvbsrc_close_devices(object);
+	if (status & FE_HAS_LOCK)
+		GST_INFO("FE_HAS_LOCK");
+}
 
-    break;
-  }
-  parent_class->change_state (element);
+static gboolean
+gst_dvbsrc_frontend_status (GstDvbSrc * object)
+{
+	fe_status_t status = 0;
+	gint i;
+	
+	GST_INFO ("gst_dvbsrc_frontend_status\n");
 
-  return GST_STATE_SUCCESS;
-}
+	if (object->fd_frontend < 0)
+	{
+		GST_ERROR ("Trying to get frontend status from not opened device!");
+		return FALSE;
+	}
+	else
+		GST_INFO ("fd-frontend: %d", object->fd_frontend);
 
+	for (i=0; i<15; i++) 
+	{
+		usleep(1000000);
+		GST_INFO(".");
+		if (ioctl(object->fd_frontend, FE_READ_STATUS, &status) == -1) {
+			perror( "FE_READ_STATUS" );
+			break;
+		}
+		print_frontend_stats(object->fd_frontend);
+		if (status & FE_HAS_LOCK) 
+		{
+			break;
+		}
+	}
 
-static gboolean
-gst_dvbsrc_frontend_status(GstDvbSrc *object)
+	if (!(status & FE_HAS_LOCK)) 
+	{
+		GST_INFO("Not able to lock to the signal on the given frequency\n");
+		return FALSE;
+	}
+	else
+		return TRUE;
+}
+
+struct diseqc_cmd
 {
-  int i,res;
-  struct dvb_frontend_event event;
-  struct dvb_frontend_info fe_info;
-  struct pollfd pfd[1];
-  int status;
-  int ret_val;
-
-
-  GST_INFO("gst_dvbsrc_frontend_status\n");
-  
-  if (object->fd_frontend < 0) {
-    GST_ERROR("Trying to get frontend status from not opened device!");
-    return FALSE;
-  }
-  else 
-    GST_INFO("fd-frontend: %d", object->fd_frontend);
-
-  pfd[0].fd = object->fd_frontend;
-  pfd[0].events = POLLIN;
-
-  event.status=0;
-  while (((event.status & FE_TIMEDOUT)==0) && ((event.status & FE_HAS_LOCK)==0)) {
-    if (poll(pfd, 1, 500)){
-      if (pfd[0].revents & POLLIN){
-        if (status = ioctl(object->fd_frontend, FE_GET_EVENT, &event) < 0){
-	  if (status != -EOVERFLOW) {
-	    perror("FE_GET_EVENT");
-	    return FALSE;
-	  }
-        }
-      }
-      GST_INFO("Frontend Status:");
-      GST_INFO("Signal : %s", event.status & FE_HAS_SIGNAL ? "YES" : "NO");
-      GST_INFO("Carrier: %s", event.status & FE_HAS_CARRIER ? "YES" : "NO");
-      GST_INFO("Viterbi: %s", event.status & FE_HAS_VITERBI ? "YES" : "NO");
-      GST_INFO("Sync   : %s", event.status & FE_HAS_SYNC ? "YES" : "NO");
-      GST_INFO("Lock   : %s", event.status & FE_HAS_LOCK ? "YES" : "NO");
-      GST_INFO("Timeout: %s", event.status & FE_TIMEDOUT ? "YES" : "NO");
-    }
-  }
-
-  if (event.status & FE_HAS_LOCK) {
-      switch(object->adapter_type) {
-         case FE_QPSK:
-	   GST_INFO("Tuned to: %d Hz", (unsigned int)((event.parameters.frequency)+(object->tone==SEC_TONE_OFF ? LOF1 : LOF2)));
-	   GST_INFO("Symbol rate: %d", event.parameters.u.qpsk.symbol_rate);
-	   GST_INFO("FEC inner: %d", event.parameters.u.qpsk.fec_inner);
-           break;
-         case FE_OFDM:
-	   GST_INFO("Tuned to: %dHz", event.parameters.frequency);
-           break;
-         case FE_QAM:
-	   GST_INFO("Tuned to: %dHz", event.parameters.frequency);
-	   GST_INFO("Symbol rate: %d", event.parameters.u.qpsk.symbol_rate);
-	   GST_INFO("FEC inner: %d", event.parameters.u.qpsk.fec_inner);
-           break;
-         default:
-	   g_error("Unknown frontend type: %d", object->adapter_type);  
-      }
-
-      ret_val=0;
-      ioctl(object->fd_frontend,FE_READ_BER,&ret_val);
-      GST_INFO("BitErrRate: %d", ret_val);
-
-      ret_val=0;
-      ioctl(object->fd_frontend,FE_READ_SIGNAL_STRENGTH,&ret_val);
-      GST_INFO("Strength  : %d", ret_val);
-
-      ret_val=0;
-      ioctl(object->fd_frontend,FE_READ_SNR,&ret_val);
-      GST_INFO("SNR       : %d", ret_val);
-
-      ret_val = 0;
-      ioctl(object->fd_frontend,FE_READ_STATUS,&ret_val);
-      GST_INFO("Frontend Status:");
-      GST_INFO("Signal : %s", ret_val & FE_HAS_SIGNAL ? "YES" : "NO");
-      GST_INFO("Carrier: %s", ret_val & FE_HAS_CARRIER ? "YES" : "NO");
-      GST_INFO("Viterbi: %s", ret_val & FE_HAS_VITERBI ? "YES" : "NO");
-      GST_INFO("Sync   : %s", ret_val & FE_HAS_SYNC ? "YES" : "NO");
-      GST_INFO("Lock   : %s", ret_val & FE_HAS_LOCK ? "YES" : "NO");
-      GST_INFO("Timeout: %s", ret_val & FE_TIMEDOUT ? "YES" : "NO");
-  } 
-  else {
-    return FALSE;
-  }
-  return TRUE;  
-}
-
-struct diseqc_cmd {
-   struct dvb_diseqc_master_cmd cmd;
-   uint32_t wait;
+	struct dvb_diseqc_master_cmd cmd;
+	uint32_t wait;
 };
 
-static void diseqc_send_msg(int fd, fe_sec_voltage_t v, struct diseqc_cmd *cmd,
-		     fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b)
+static void
+diseqc_send_msg (int fd, fe_sec_voltage_t v, struct diseqc_cmd *cmd,
+				 fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b)
 {
-   if (ioctl(fd, FE_SET_TONE, SEC_TONE_OFF) == -1)
-      perror("FE_SET_TONE failed");
+	if (ioctl (fd, FE_SET_TONE, SEC_TONE_OFF) == -1)
+		perror ("FE_SET_TONE failed");
 
-   if (ioctl(fd, FE_SET_VOLTAGE, v) == -1)
-      perror("FE_SET_VOLTAGE failed");
+	if (ioctl (fd, FE_SET_VOLTAGE, v) == -1)
+		perror ("FE_SET_VOLTAGE failed");
 
-   usleep(15 * 1000);
+	usleep (15 * 1000);
 
-   if (ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &cmd->cmd) == -1)
-      perror("FE_DISEQC_SEND_MASTER_CMD failed");
+	if (ioctl (fd, FE_DISEQC_SEND_MASTER_CMD, &cmd->cmd) == -1)
+		perror ("FE_DISEQC_SEND_MASTER_CMD failed");
 
-   usleep(cmd->wait * 1000);
-   usleep(15 * 1000);
+	usleep (cmd->wait * 1000);
+	usleep (15 * 1000);
 
-   if (ioctl(fd, FE_DISEQC_SEND_BURST, b) == -1)
-      perror("FE_DISEQC_SEND_BURST failed");
+	if (ioctl (fd, FE_DISEQC_SEND_BURST, b) == -1)
+		perror ("FE_DISEQC_SEND_BURST failed");
 
-   usleep(15 * 1000);
+	usleep (15 * 1000);
 
-   if (ioctl(fd, FE_SET_TONE, t) == -1)
-      perror("FE_SET_TONE failed");
+	if (ioctl (fd, FE_SET_TONE, t) == -1)
+		perror ("FE_SET_TONE failed");
 }
 
 
 /* digital satellite equipment control,
  * specification is available from http://www.eutelsat.com/
  */
-static void diseqc(int secfd, int sat_no, int voltage, int tone)
+static void
+diseqc (int secfd, int sat_no, int voltage, int tone)
 {
-   struct diseqc_cmd cmd =
-       { {{0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00}, 4}, 0 };
+	struct diseqc_cmd cmd = { {{0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00}, 4}, 0 };
 
-   /* param: high nibble: reset bits, low nibble set bits,
-    * bits are: option, position, polarizaion, band
-    */
-   cmd.cmd.msg[3] =
-       0xf0 | (((sat_no * 4) & 0x0f) | (tone == SEC_TONE_ON ? 1 : 0) | (voltage == SEC_VOLTAGE_13 ? 0 : 2));
+	/* param: high nibble: reset bits, low nibble set bits,
+	 * bits are: option, position, polarizaion, band
+	 */
+	cmd.cmd.msg[3] =
+		0xf0 | (((sat_no * 4) & 0x0f) | (tone == SEC_TONE_ON ? 1 : 0) |
+				(voltage == SEC_VOLTAGE_13 ? 0 : 2));
 
-   diseqc_send_msg(secfd, voltage, &cmd, tone,
-		   (sat_no / 4) % 2 ? SEC_MINI_B : SEC_MINI_A);
+	diseqc_send_msg (secfd, voltage, &cmd, tone,
+					 (sat_no / 4) % 2 ? SEC_MINI_B : SEC_MINI_A);
 
 }
 
 
 static gboolean
-gst_dvbsrc_tune (GstDvbSrc *object)
+gst_dvbsrc_tune (GstDvbSrc * object)
 {
-  GstEvent* event = NULL;
-  struct dvb_frontend_parameters feparams;
-  fe_sec_voltage_t voltage;
-
-  int freq = object->freq * 1000;
-  int sym_rate = object->sym_rate * 1000;
-
-  int ret;
-  int pol_vert = 0;
-
-  /* found in mail archive on linuxtv.org
-    What works well for us is:
-    - first establish a TS feed (i.e. tune the frontend and check for success)
-    - then set filters (PES/sections)
-    - then tell the MPEG decoder to start
-    - before tuning: first stop the MPEG decoder, then stop all filters  
-  */
-  GST_INFO("gst_dvbsrc_tune");
-
-  if (object->fd_frontend < 0) {
-    /* frontend not opened yet, tune later */
-    GST_INFO("Frontend not open: tuning later");
-    return FALSE;
-  }
-
-  gst_dvbsrc_unset_pes_filters(object);
-
-  switch(object->adapter_type) {
-    case FE_QPSK:
-
-      GST_INFO("tuning DVB-S to L-Band:%d, Pol:%d, srate=%d, 22kHz=%s",
-	       freq, object->pol, sym_rate, object->tone == SEC_TONE_ON ? "on" : "off");
-      
-      if (freq > 2200000) {
-        // this must be an absolute frequency
-        if (freq < SLOF) {
-          feparams.frequency=(freq-LOF1);
-          if (object->tone < 0) object->tone = SEC_TONE_OFF;
-        } 
-	else {
-          feparams.frequency=(freq-LOF2);
-          if (object->tone < 0) object->tone = SEC_TONE_ON;
-        }
-      }
-      else {
-        // this is an L-Band frequency
-	feparams.frequency=freq;
-      }
-      
-      feparams.inversion = INVERSION_OFF;
-      feparams.u.qpsk.symbol_rate = sym_rate;
-      feparams.u.qpsk.fec_inner = FEC_AUTO;
-
-      if (object->pol == DVB_POL_H) 	 
-	voltage = SEC_VOLTAGE_18; 	 
-      else 	 
-	voltage = SEC_VOLTAGE_13; 	 
-
-      if (object->diseqc_src == -1 || object->send_diseqc == FALSE) {
-	if (ioctl(object->fd_frontend,FE_SET_VOLTAGE,voltage) < 0) { 	 
-	  g_warning("Unable to set voltage on dvb frontend device"); 	 
-	}
-
-	if (ioctl(object->fd_frontend,FE_SET_TONE,object->tone) < 0) { 
-	  g_warning("Error setting tone: %s", strerror(errno));
-	}
-      }
-      else {
-	GST_DEBUG("Sending DISEqC");
-	diseqc(object->fd_frontend, object->diseqc_src, voltage, object->tone);
-	/* Once diseqc source is set, do not set it again until
-	   app decides to change it */
-	object->send_diseqc = FALSE;
-      }
+	struct dvb_frontend_parameters feparams;
+	fe_sec_voltage_t voltage;
+
+	int freq = object->freq;
+	int sym_rate = object->sym_rate * 1000;
+
+	int pol_vert = 0;
+
+	/* found in mail archive on linuxtv.org
+	 * What works well for us is:
+	 * - first establish a TS feed (i.e. tune the frontend and check for success)
+	 * - then set filters (PES/sections)
+	 * - then tell the MPEG decoder to start
+	 * - before tuning: first stop the MPEG decoder, then stop all filters  
+	 */
+	GST_INFO ("gst_dvbsrc_tune");
+
+	if (object->fd_frontend < 0)
+	{
+		/* frontend not opened yet, tune later */
+		GST_INFO ("Frontend not open: tuning later");
+		return FALSE;
+	}
+
+	gst_dvbsrc_unset_pes_filters (object);
 
-      break;
-    case FE_OFDM:
-      if (freq < 1000000) freq *= 1000; // DVB-T needs Hz
-      feparams.frequency = freq;
-      feparams.inversion = INVERSION_OFF;
-      feparams.u.ofdm.bandwidth     = object->bandwidth;
-      feparams.u.ofdm.code_rate_HP  = object->code_rate_hp;
-      feparams.u.ofdm.code_rate_LP  = object->code_rate_lp;
-      feparams.u.ofdm.constellation = object->modulation;
-      feparams.u.ofdm.guard_interval = object->guard_interval;
-      feparams.u.ofdm.transmission_mode = object->transmission_mode;
-      feparams.u.ofdm.hierarchy_information = object->hierarchy_information;
-      GST_INFO("Tuning DVB-T to %dKHz", freq);
-      break;
-    case FE_QAM:
-      GST_INFO("Tuning DVB-C to %d, srate=%d", freq, sym_rate);
-      feparams.frequency= freq;
-      feparams.inversion= INVERSION_OFF;
-      feparams.u.qam.fec_inner = FEC_AUTO;
-      feparams.u.qam.modulation = object->modulation;
-      feparams.u.qam.symbol_rate = sym_rate;
-      break;
-    default:
-      g_error("Unknown frontend type: %d", object->adapter_type);  
-      
-  }
-  usleep(100000);
-
-  /* now tune the frontend */
-  if (ioctl(object->fd_frontend,FE_SET_FRONTEND, &feparams) < 0) {
-    g_warning("Error tuning channel: %s", strerror(errno));
-  }
+	switch (object->adapter_type)
+	{
+	case FE_QPSK:
+
+		GST_INFO ("tuning DVB-S to L-Band:%d, Pol:%d, srate=%d, 22kHz=%s",
+				  freq, object->pol, sym_rate,
+				  object->tone == SEC_TONE_ON ? "on" : "off");
+
+		if (freq > 2200000)
+		{
+			// this must be an absolute frequency
+			if (freq < SLOF)
+			{
+				feparams.frequency = (freq - LOF1);
+				if (object->tone < 0)
+					object->tone = SEC_TONE_OFF;
+			}
+			else
+			{
+				feparams.frequency = (freq - LOF2);
+				if (object->tone < 0)
+					object->tone = SEC_TONE_ON;
+			}
+		}
+		else
+		{
+			// this is an L-Band frequency
+			feparams.frequency = freq;
+		}
+
+		feparams.inversion = INVERSION_OFF;
+		feparams.u.qpsk.symbol_rate = sym_rate;
+		feparams.u.qpsk.fec_inner = FEC_AUTO;
+
+		if (object->pol == DVB_POL_H)
+			voltage = SEC_VOLTAGE_18;
+		else
+			voltage = SEC_VOLTAGE_13;
+
+		if (object->diseqc_src == -1 || object->send_diseqc == FALSE)
+		{
+			if (ioctl (object->fd_frontend, FE_SET_VOLTAGE, voltage) < 0)
+			{
+				g_warning ("Unable to set voltage on dvb frontend device");
+			}
+
+			if (ioctl (object->fd_frontend, FE_SET_TONE, object->tone) < 0)
+			{
+				g_warning ("Error setting tone: %s", strerror (errno));
+			}
+		}
+		else
+		{
+			GST_DEBUG ("Sending DISEqC");
+			diseqc (object->fd_frontend, object->diseqc_src, voltage,
+					object->tone);
+			/* Once diseqc source is set, do not set it again until
+			 * app decides to change it */
+			object->send_diseqc = FALSE;
+		}
+
+		break;
+	case FE_OFDM:
+		feparams.frequency=freq;
+		feparams.u.ofdm.bandwidth = object->bandwidth;
+		feparams.u.ofdm.code_rate_HP = object->code_rate_hp;
+		feparams.u.ofdm.code_rate_LP = object->code_rate_lp;
+		feparams.u.ofdm.constellation = object->modulation;
+		feparams.u.ofdm.transmission_mode = object->transmission_mode;
+		feparams.u.ofdm.guard_interval = object->guard_interval;
+		feparams.u.ofdm.hierarchy_information = object->hierarchy_information;
+		feparams.inversion = object->inversion;
+			
+		GST_INFO("tuning DVB-T to %d Hz\n", freq);
+		break;
+	case FE_QAM:
+		GST_INFO ("Tuning DVB-C to %d, srate=%d", freq, sym_rate);
+		feparams.frequency = freq;
+		feparams.inversion = INVERSION_OFF;
+		feparams.u.qam.fec_inner = FEC_AUTO;
+		feparams.u.qam.modulation = object->modulation;
+		feparams.u.qam.symbol_rate = sym_rate;
+		break;
+	default:
+		g_error ("Unknown frontend type: %d", object->adapter_type);
 
-  /* set pid filters */
-  gst_dvbsrc_set_pes_filter(object);
+	}
+	usleep (100000);
+
+	/* now tune the frontend */
+	if (ioctl (object->fd_frontend, FE_SET_FRONTEND, &feparams) < 0)
+	{
+		g_warning ("Error tuning channel: %s", strerror (errno));
+	}
+
+	/* set pid filters */
+	gst_dvbsrc_set_pes_filter (object);
 
-  return TRUE;
+	return TRUE;
 }
 
 
 static void
-gst_dvbsrc_unset_pes_filters(GstDvbSrc* object)
+gst_dvbsrc_unset_pes_filters (GstDvbSrc * object)
 {
-  int i=0;
-  GST_INFO("clearing PES filter");
+	int i = 0;
+	GST_INFO ("clearing PES filter");
 
-  for (i=0; i<MAX_FILTERS; i++) {
-    if (object->fd_filters[i] == -1) continue;
-    close(object->fd_filters[i]);
-    object->fd_filters[i] = -1;
-  }
+	for (i = 0; i < MAX_FILTERS; i++)
+	{
+		if (object->fd_filters[i] == -1)
+			continue;
+		close (object->fd_filters[i]);
+		object->fd_filters[i] = -1;
+	}
 }
 
 static void
-gst_dvbsrc_set_pes_filter(GstDvbSrc* object)
+gst_dvbsrc_set_pes_filter (GstDvbSrc * object)
 {
-  int* fd;
-  int pid, i;
-  struct dmx_pes_filter_params pes_filter;
-
-  GST_INFO("Setting PES filter");
-
+	int* fd;
+	int pid, i;
+	struct dmx_pes_filter_params pes_filter;
 
-  for (i=0; i<MAX_FILTERS; i++) {
+	GST_INFO("Setting PES filter");
 
-    if (object->pids[i] == 0) continue;
+	for (i=0; i<MAX_FILTERS; i++) {
+		if (object->pids[i] == 0) continue;
+		
+		fd = &object->fd_filters[i];
+		pid = object->pids[i];
 
-    fd = &object->fd_filters[i];
-    pid = object->pids[i];
+		close(*fd);
+		if ((*fd = open(object->demux_dev, O_RDWR)) < 0)
+			g_error("Error opening demuxer: %s (%s)", strerror(errno), object->demux_dev);
 
-    close(*fd);
-    if ((*fd = open(object->demux_dev, O_RDWR)) < 0)
-      g_error("Error opening demuxer: %s (%s)", strerror(errno), object->demux_dev);
-  
-    g_return_if_fail(*fd != -1);
-
-    pes_filter.pid = pid;
-    pes_filter.input = DMX_IN_FRONTEND;
-    pes_filter.output = DMX_OUT_TS_TAP;
-
-    pes_filter.pes_type = DMX_PES_OTHER;
-
-/* DEBUG : only valid for 3Sat on Astra 19.2 EAST */
-/*
-    if (pid == 210)
-      pes_filter.pes_type = DMX_PES_VIDEO;
-    else 
-      pes_filter.pes_type = DMX_PES_AUDIO;
-
-*/
-
-    pes_filter.flags = DMX_IMMEDIATE_START;
-    if (ioctl(*fd, DMX_SET_PES_FILTER, &pes_filter) < 0)
-      g_warning("Error setting PES filter on %s: %s", object->demux_dev, strerror(errno));
-  }
+		g_return_if_fail(*fd != -1);
+	
+		pes_filter.pid = pid;
+		pes_filter.input = DMX_IN_FRONTEND;
+		pes_filter.output = DMX_OUT_TS_TAP;
+		pes_filter.pes_type = DMX_PES_OTHER;	
+		pes_filter.flags = DMX_IMMEDIATE_START;
+		
+		GST_INFO("Setting pes-filter, pid = %d, type = %d", pes_filter.pid, pes_filter.pes_type);
+		
+		if (ioctl(*fd, DMX_SET_PES_FILTER, &pes_filter) < 0)
+			g_warning("Error setting PES filter on %s: %s", object->demux_dev, strerror(errno));
+	}
 }
Index: gstdvbsrc.h
===================================================================
RCS file: /cvs/gstreamer/gst-sandbox/dvb-elements/dvbsrc/gstdvbsrc.h,v
retrieving revision 1.6
diff -u -r1.6 gstdvbsrc.h
--- gstdvbsrc.h	19 Dec 2004 23:24:06 -0000	1.6
+++ gstdvbsrc.h	15 Jun 2006 12:43:28 -0000
@@ -3,6 +3,7 @@
 #define __GST_DVBSRC_H__
 
 #include <gst/gst.h>
+#include <gst/base/gstpushsrc.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -19,11 +20,11 @@
 #define IPACKS 2048
 #define TS_SIZE 188
 #define IN_SIZE TS_SIZE*10 
-#define MAX_ATTEMPTS 5      // limit timeouts for poll
+#define MAX_ATTEMPTS 10      // limit timeouts for poll
 
 #define DEFAULT_ADAPTER_PREFIX "/dev/dvb/adapter0"
-#define DEFAULT_SYMBOL_RATE 27500
-#define DEFAULT_BUFFER_SIZE 8192
+#define DEFAULT_SYMBOL_RATE 0
+#define DEFAULT_BUFFER_SIZE  8192
 #define DEFAULT_DISEQC_SRC -1 /* disabled */
 
 #define MAX_FILTERS 8
@@ -46,13 +47,12 @@
 
 struct _GstDvbSrc
 {
-  GstElement element;
+  GstPushSrc element;
   GstPad* srcpad;
 
   GMutex *tune_mutex;
   gboolean need_tune;
   
-  int buffersize;
   int adapter_type;
 
   char *adapter_prefix;
@@ -78,13 +78,14 @@
   int guard_interval;
   int transmission_mode;
   int hierarchy_information;
+  int inversion;
 
   GstDvbSrcPol pol;
 };
 
 struct _GstDvbSrcClass 
 {
-  GstElementClass parent_class;
+  GstPushSrcClass parent_class;
   
   void (*adapter_type)   (GstElement *element, gint type);
   void (*signal_quality) (GstElement *element, gint strength, gint snr);
Index: gstdvbtv.c
===================================================================
RCS file: /cvs/gstreamer/gst-sandbox/dvb-elements/dvbsrc/gstdvbtv.c,v
retrieving revision 1.5
diff -u -r1.5 gstdvbtv.c
--- gstdvbtv.c	27 Mar 2006 08:31:54 -0000	1.5
+++ gstdvbtv.c	15 Jun 2006 12:43:29 -0000
@@ -11,12 +11,11 @@
 static struct termios tio_orig;
 
 #define ADAPTER_PREFIX "/dev/dvb/adapter0"
-#define PREV_KEY 45  /* + */
-#define NEXT_KEY 43  /* - */
-#define EXIT_KEY 113 /* q */
+#define PREV_KEY 45				/* + */
+#define NEXT_KEY 43				/* - */
+#define EXIT_KEY 113			/* q */
 
 GstElement *dvbsrc;
-GstElement *ts2ps;
 GstElement *audiosink;
 GstElement *videosink;
 GstElement *queue1;
@@ -26,631 +25,695 @@
 GstElement *mpegdemux;
 GstElement *source_thread, *work_thread, *audio_thread, *video_thread;
 
-GList* channel_list;
-GList* channel = NULL;
+GList *channel_list;
+GList *channel = NULL;
 gint channel_count = 0;
 
-void     setup_terminal();
-void     restore_terminal();
-gboolean read_channels(const char* filename);
+void setup_terminal ();
+void restore_terminal ();
+gboolean read_channels (const char *filename);
 
 static gint adapter_type = -1;
 
-static char* adapter_type_str[] = {"DVB-S", "DVB-C", "DVB-T"};
-static char* channel_files[] = {"channels.conf.sat", "channels.conf.cable", "channels.conf.terr"};
+static char *adapter_type_str[] = { "DVB-S", "DVB-C", "DVB-T" };
+static char *channel_files[] =
+	{ "channels.conf.sat", "channels.conf.cable", "channels.conf.terr" };
 
 
 
-typedef struct {
-  char *name;
-  int freq;
-  char *params;
-  /* decoded params (-1: unknown)*/
-  int bandwidth;         
-  int code_rate_hp;      
-  int code_rate_lp;      
-  int guard_int;         
-  int h_pol;       /* 0: v_pol, 1:h_pol */
-  int inversion;   /* 0: no,    1:yes   */
-  int modulation;        
-  int transmission_mode; 
-  int hierarchy;         
-  int source;
-  int symbol_rate;
-  int video_pid;
-  int pcr_pid;
-  int audio_pids[2];
-  int dolby_pids[2];
-  int teletext_pid;
-  int ca;
-  int service_id;
-  int network_id;
-  int transport_stream_id;
-  int radio_id;
+typedef struct
+{
+	char *name;
+	int freq;
+	char *params;
+	/* decoded params (-1: unknown) */
+	int bandwidth;
+	int code_rate_hp;
+	int code_rate_lp;
+	int guard_int;
+	int h_pol;					/* 0: v_pol, 1:h_pol */
+	int inversion;				/* 0: no,    1:yes   */
+	int modulation;
+	int transmission_mode;
+	int hierarchy;
+	int source;
+	int symbol_rate;
+	int video_pid;
+	int pcr_pid;
+	int audio_pids[2];
+	int dolby_pids[2];
+	int teletext_pid;
+	int ca;
+	int service_id;
+	int network_id;
+	int transport_stream_id;
+	int radio_id;
 } ChannelInfo;
 
-static void mpegdemux_new_pad (GstElement *parse, GstPad *pad, GObject *object);
-static ChannelInfo* next_channel ();
+static void mpegdemux_new_pad (GstElement * parse, GstPad * pad,
+							   GObject * object);
+static ChannelInfo *next_channel ();
 
 
-void tune_channel(ChannelInfo * chn_data) {
-  gchar pids[9] = "";
-  g_assert(chn_data->video_pid < 8193);
-  g_assert(chn_data->video_pid >=   0);
-  g_assert(chn_data->audio_pids[0] < 8193);
-  g_assert(chn_data->audio_pids[0] >=   0);
-  sprintf(pids, "%d:%d", chn_data->video_pid, chn_data->audio_pids[0]);
-
-
-  g_object_set(dvbsrc, "freq", chn_data->freq, NULL);
-
-  /* set all parameters we have guarantee for from channel parsing */
-  if (chn_data->h_pol >= 0) 
-    g_object_set(dvbsrc, "pol", chn_data->h_pol ? "H" : "V", NULL);
-  if (chn_data->symbol_rate > 0) 
-    g_object_set(dvbsrc, "srate",chn_data->symbol_rate, NULL);
-  if (chn_data->bandwidth >= 0)
-    g_object_set(dvbsrc, "bandwidth", chn_data->bandwidth, NULL);
-  if (chn_data->code_rate_hp >= 0)
-    g_object_set(dvbsrc, "code-rate-hp", chn_data->code_rate_hp, NULL);
-  if (chn_data->code_rate_lp >= 0)
-    g_object_set(dvbsrc, "code-rate-lp", chn_data->code_rate_lp, NULL);
-  if (chn_data->modulation >= 0)
-    g_object_set(dvbsrc, "modulation", chn_data->modulation, NULL);
-  if (chn_data->transmission_mode >= 0)
-    g_object_set(dvbsrc, "trans-mode", chn_data->transmission_mode, NULL);
-  if (chn_data->guard_int >= 0)
-    g_object_set(dvbsrc, "guard", chn_data->guard_int, NULL);
-  if (chn_data->hierarchy >= 0)
-    g_object_set(dvbsrc, "hierarchy", chn_data->hierarchy, NULL);
-  if (chn_data->inversion > 0) 
-    g_object_set(dvbsrc, "inversion", chn_data->inversion, NULL);
-
-  g_object_set( dvbsrc, "pids", pids, NULL);
-    
-
-  /* now tune */
-  g_object_set(dvbsrc, "tune", -1, NULL);
-
-  g_object_set(ts2ps,
-	       "vpid", chn_data->video_pid,
-	       "apid", chn_data->audio_pids[0],
-	       NULL);
+void
+tune_channel (ChannelInfo * chn_data)
+{
+	gchar pids[9] = "";
+	g_assert (chn_data->video_pid < 8193);
+	g_assert (chn_data->video_pid >= 0);
+	g_assert (chn_data->audio_pids[0] < 8193);
+	g_assert (chn_data->audio_pids[0] >= 0);
+	sprintf (pids, "%d:%d", chn_data->video_pid, chn_data->audio_pids[0]);
+
+
+	g_object_set (dvbsrc, "freq", chn_data->freq, NULL);
+
+	/* set all parameters we have guarantee for from channel parsing */
+	if (chn_data->h_pol >= 0)
+		g_object_set (dvbsrc, "pol", chn_data->h_pol ? "H" : "V", NULL);
+	if (chn_data->symbol_rate > 0)
+		g_object_set (dvbsrc, "srate", chn_data->symbol_rate, NULL);
+	if (chn_data->bandwidth >= 0)
+		g_object_set (dvbsrc, "bandwidth", chn_data->bandwidth, NULL);
+	if (chn_data->code_rate_hp >= 0)
+		g_object_set (dvbsrc, "code-rate-hp", chn_data->code_rate_hp, NULL);
+	if (chn_data->code_rate_lp >= 0)
+		g_object_set (dvbsrc, "code-rate-lp", chn_data->code_rate_lp, NULL);
+	if (chn_data->modulation >= 0)
+		g_object_set (dvbsrc, "modulation", chn_data->modulation, NULL);
+	if (chn_data->transmission_mode >= 0)
+		g_object_set (dvbsrc, "trans-mode", chn_data->transmission_mode, NULL);
+	if (chn_data->guard_int >= 0)
+		g_object_set (dvbsrc, "guard", chn_data->guard_int, NULL);
+	if (chn_data->hierarchy >= 0)
+		g_object_set (dvbsrc, "hierarchy", chn_data->hierarchy, NULL);
+	if (chn_data->inversion > 0)
+		g_object_set (dvbsrc, "inversion", chn_data->inversion, NULL);
+
+	g_object_set (dvbsrc, "pids", pids, NULL);
+
+
+	/* now tune */
+	g_object_set (dvbsrc, "tune", -1, NULL);
+
+	/*g_object_set(ts2ps,
+	 * "vpid", chn_data->video_pid,
+	 * "apid", chn_data->audio_pids[0],
+	 * NULL); */
 }
 
 
 gboolean
 idle_func (gpointer data)
 {
-  guint ch = 0;
-  gboolean busy;
-  fd_set rfds;
-  struct timeval tv;
-  int retval;
-  
-  busy = gst_bin_iterate (GST_BIN (data));
-
-  FD_ZERO(&rfds); FD_SET(0,&rfds);
-  tv.tv_sec=0; tv.tv_usec = 1000;
-  retval=select(1, &rfds, NULL, NULL, &tv);
-  if(retval<=0) return busy;
-  /* Data is available */
-  retval=read(0,&ch,sizeof(guint));
-  if(retval<1) return busy;
-  else {
-
-    switch (ch) {
-    case -1:
-      break;
-    case NEXT_KEY:
-      channel = g_list_next(channel);
-      if (!channel)
-	channel = channel_list;        /* set first channel */
-      tune_channel((ChannelInfo*) channel->data);
-      fprintf(stderr, "Next, %s\n", ((ChannelInfo*) channel->data)->name);
-      break;
-    case PREV_KEY:
-      channel = g_list_previous(channel);
-      if (!channel)
-	channel = g_list_last(channel_list);
-      tune_channel((ChannelInfo*) channel->data);
-      fprintf(stderr, "Prev, %s\n", ((ChannelInfo*) channel->data)->name);
-      break;
-    case EXIT_KEY:
-      gst_main_quit();
-      return FALSE;
-    default:
-      break;
-    }
-    
-  }
-  return busy;
+	guint ch = 0;
+	gboolean busy;
+	fd_set rfds;
+	struct timeval tv;
+	int retval;
+
+	busy = FALSE;
+
+	FD_ZERO (&rfds);
+	FD_SET (0, &rfds);
+	tv.tv_sec = 0;
+	tv.tv_usec = 1000;
+	retval = select (1, &rfds, NULL, NULL, &tv);
+	if (retval <= 0)
+		return busy;
+	/* Data is available */
+	retval = read (0, &ch, sizeof (guint));
+	if (retval < 1)
+		return busy;
+	else
+	{
+
+		switch (ch)
+		{
+		case -1:
+			break;
+		case NEXT_KEY:
+			channel = g_list_next (channel);
+			if (!channel)
+				channel = channel_list;	/* set first channel */
+			tune_channel ((ChannelInfo *) channel->data);
+			fprintf (stderr, "Next, %s\n",
+					 ((ChannelInfo *) channel->data)->name);
+			break;
+		case PREV_KEY:
+			channel = g_list_previous (channel);
+			if (!channel)
+				channel = g_list_last (channel_list);
+			tune_channel ((ChannelInfo *) channel->data);
+			fprintf (stderr, "Prev, %s\n",
+					 ((ChannelInfo *) channel->data)->name);
+			break;
+		case EXIT_KEY:
+			//gst_main_quit();
+			return FALSE;
+		default:
+			break;
+		}
+
+	}
+	return busy;
 }
 
 
 static void
-dvbsrc_signal_quality(GstElement *dvbsrc, gint strength, gint snr) {
-  /* This would be nice to toggle into an OSD */
-  //  printf("Strength: %d, SNR: %d\n", strength, snr);
+dvbsrc_signal_quality (GstElement * dvbsrc, gint strength, gint snr)
+{
+	/* This would be nice to toggle into an OSD */
+	//  printf("Strength: %d, SNR: %d\n", strength, snr);
 }
 
 
 static void
-dvbsrc_adapter_type (GstElement *dvbsrc, gint type, GObject *object) {
-  adapter_type = type;
-  fprintf(stderr, "Using %s adapter %s\n", adapter_type_str[type], ADAPTER_PREFIX);
+dvbsrc_adapter_type (GstElement * dvbsrc, gint type, GObject * object)
+{
+	adapter_type = type;
+	fprintf (stderr, "Using %s adapter %s\n", adapter_type_str[type],
+			 ADAPTER_PREFIX);
 }
 
 
 static void
-mpegdemux_new_pad (GstElement *parse, GstPad *pad, GObject *object)
+mpegdemux_new_pad (GstElement * parse, GstPad * pad, GObject * object)
 {
-  gst_element_set_state(GST_ELEMENT (work_thread), GST_STATE_PAUSED);
+	gst_element_set_state (GST_ELEMENT (work_thread), GST_STATE_PAUSED);
 
-  printf("New Pad: %s\n", gst_pad_get_name (pad));
+	printf ("New Pad: %s\n", gst_pad_get_name (pad));
 
-  /* Link to pads */
-  if (strncmp (gst_pad_get_name (pad), "audio_00", 8) == 0) {
-    gst_pad_link (pad, gst_element_get_pad (queue2, "sink"));
-    gst_element_set_state(audio_thread, GST_STATE_READY);
-    GST_INFO("Audio connected");
-  }
-  else if (strncmp (gst_pad_get_name (pad), "video_0", 6) == 0) {
-    gst_pad_link (pad, gst_element_get_pad (queue1, "sink"));
-    gst_element_set_state(video_thread, GST_STATE_READY);
-    GST_INFO("Video connected");
-  }
+	/* Link to pads */
+	if (strncmp (gst_pad_get_name (pad), "audio_00", 8) == 0)
+	{
+		gst_pad_link (pad, gst_element_get_pad (queue2, "sink"));
+		gst_element_set_state (audio_thread, GST_STATE_READY);
+		GST_INFO ("Audio connected");
+	}
+	else if (strncmp (gst_pad_get_name (pad), "video_0", 6) == 0)
+	{
+		gst_pad_link (pad, gst_element_get_pad (queue1, "sink"));
+		gst_element_set_state (video_thread, GST_STATE_READY);
+		GST_INFO ("Video connected");
+	}
 
-  gst_element_set_state(GST_ELEMENT (work_thread), GST_STATE_PLAYING);
+	gst_element_set_state (GST_ELEMENT (work_thread), GST_STATE_PLAYING);
 }
 
 
 int
 main (int argc, char **argv)
 {
-  int channel_no = 1;
+	int channel_no = 1;
 
-  setup_terminal();
-  
-  if (argc < 2) {
-    printf( "\nUsage: gstdvbtv <channel-num>\n\n");
-    exit(1);
-  }
-
-  gst_init(&argc, &argv);
-  g_type_init();
-
-  /* Build Pipeline:                          
-   *                               / { queue1 ! mpeg2dec ! xvimagesink } 
-   * { dvbsrc ! ts2ps ! mpegdemux } 
-   *                               \ { queue2 ! mad ! osssink }
-   */
-
-  audio_thread = gst_thread_new("audio_thread");
-  queue2 = gst_element_factory_make("queue","queue2");
-  mad = gst_element_factory_make("mad","mad");
-  audiosink = gst_element_factory_make("alsasink", "alsasink");
-  //audiosink = gst_element_factory_make("osssink", "osssink");
-  gst_bin_add_many(GST_BIN(audio_thread), queue2, mad, audiosink, NULL);
-
-  video_thread = gst_thread_new("video_thread");
-  videosink = gst_element_factory_make("xvimagesink", "videosink");
-  mpeg2dec = gst_element_factory_make("mpeg2dec","mpeg2dec");
-  queue1 = gst_element_factory_make("queue","queue1");
-  gst_bin_add_many(GST_BIN(video_thread), queue1, mpeg2dec, videosink, NULL);
-
-  gst_element_link_many(queue2, mad, audiosink, NULL);
-  gst_element_link_many(queue1, mpeg2dec, videosink, NULL);
-
-  work_thread = gst_pipeline_new("main_thread");
-  source_thread = gst_thread_new("source_thread");
-  dvbsrc = gst_element_factory_make("dvbsrc", "dvbsrc");
-  ts2ps = gst_element_factory_make("ts2ps", "ts2ps");
-  mpegdemux = gst_element_factory_make("mpegdemux","mpegdemux");
-  gst_bin_add_many(GST_BIN(source_thread), dvbsrc, ts2ps, mpegdemux, NULL);
-  gst_bin_add(GST_BIN(work_thread), source_thread);
-  gst_bin_add(GST_BIN(work_thread), audio_thread);
-  gst_bin_add(GST_BIN(work_thread), video_thread);
-
-  gst_element_link_many(dvbsrc, ts2ps, mpegdemux, NULL);
-
-  g_signal_connect(G_OBJECT(dvbsrc), "adapter-type", G_CALLBACK(dvbsrc_adapter_type), NULL);
-  g_signal_connect(G_OBJECT(dvbsrc), "signal-quality", G_CALLBACK(dvbsrc_signal_quality), NULL);
-  g_signal_connect(G_OBJECT(mpegdemux), "new_pad", G_CALLBACK(mpegdemux_new_pad), NULL);
-
-  g_object_set(dvbsrc, "adapter-prefix", ADAPTER_PREFIX, NULL);
-
-
-  g_object_set(queue1, "max-size-buffers", 0, NULL);
-  g_object_set(queue2, "max-size-buffers", 0, NULL);
-
-  g_object_set(queue1, "max-size-time", 0LL, NULL);
-  g_object_set(queue2, "max-size-time", 0LL, NULL);
-
-  g_object_set(queue1, "max-size-bytes", 0, NULL);
-  g_object_set(queue2, "max-size-bytes", 0, NULL);
-
-
-  g_idle_add (idle_func, work_thread);
-  /* set ready, so that dvbsrc will signal adapter_type */
-  gst_element_set_state(work_thread, GST_STATE_READY);
-
-  while (adapter_type == -1){
-    sleep(1);
-  }
-
-  if (adapter_type > 2 || adapter_type < 0) {
-    printf("Unknown adapter type (%d). Exiting...\n", adapter_type);
-    restore_terminal();
-    exit(1);
-  }
-
-  if (!read_channels(channel_files[adapter_type])) {
-    printf("Could not read %s channels from %s.\n", adapter_type_str[adapter_type], channel_files[adapter_type]);
-    restore_terminal();
-    exit(1);
-  }
-  
-  channel_no = (int) g_strtod(argv[1], NULL);
-
-  if (g_list_length(channel_list) < channel_no) {
-    fprintf(stderr, "Channel #%d does not exist. Only %d channels available.\n",
-	    channel_no, g_list_length(channel_list));
-    fprintf(stderr, "Tuning to #0.");
-    channel = g_list_nth(channel_list, 0);
-  }
-  else
-    channel = g_list_nth(channel_list, (int) channel_no);
-
-  fprintf(stderr, "Showing: %s\n", ((ChannelInfo*) channel->data)->name);
-  tune_channel((ChannelInfo*) channel->data);
-
-  g_idle_add (idle_func, work_thread);
-  gst_element_set_state(work_thread, GST_STATE_PLAYING);
+	setup_terminal ();
 
-  gst_main();
+	if (argc < 2)
+	{
+		printf ("\nUsage: gstdvbtv <channel-num>\n\n");
+		exit (1);
+	}
 
-  fprintf(stderr, "Finishing up\n");
+	gst_init (&argc, &argv);
+	g_type_init ();
 
-  restore_terminal();
+	/* Build Pipeline:                          
+	 *                               / { queue1 ! mpeg2dec ! xvimagesink } 
+	 * { dvbsrc ! ts2ps ! mpegdemux } 
+	 *                               \ { queue2 ! mad ! osssink }
+	 */
+
+	audio_thread = gst_pipeline_new ("audio_thread");
+	queue2 = gst_element_factory_make ("queue", NULL);
+	g_return_if_fail (queue2 != NULL);
+	mad = gst_element_factory_make ("mad", "mad");
+	audiosink = gst_element_factory_make ("alsasink", "alsasink");
+	//audiosink = gst_element_factory_make("osssink", "osssink");
+	gst_bin_add_many (GST_BIN (audio_thread), queue2, mad, audiosink, NULL);
+
+	video_thread = gst_pipeline_new ("video_thread");
+	videosink = gst_element_factory_make ("xvimagesink", "videosink");
+	mpeg2dec = gst_element_factory_make ("mpeg2dec", "mpeg2dec");
+	queue1 = gst_element_factory_make ("queue", "queue1");
+	gst_bin_add_many (GST_BIN (video_thread), queue1, mpeg2dec, videosink,
+					  NULL);
+
+	gst_element_link_many (queue2, mad, audiosink, NULL);
+	gst_element_link_many (queue1, mpeg2dec, videosink, NULL);
+
+	work_thread = gst_pipeline_new ("main_thread");
+	source_thread = gst_pipeline_new ("source_thread");
+	dvbsrc = gst_element_factory_make ("dvbsrc", "dvbsrc");
+	mpegdemux = gst_element_factory_make ("flutsdemux", "mpegdemux");
+	gst_bin_add_many (GST_BIN (source_thread), dvbsrc, mpegdemux, NULL);
+	gst_bin_add (GST_BIN (work_thread), source_thread);
+	gst_bin_add (GST_BIN (work_thread), audio_thread);
+	gst_bin_add (GST_BIN (work_thread), video_thread);
+
+	gst_element_link_many (dvbsrc, mpegdemux, NULL);
+
+	g_signal_connect (G_OBJECT (dvbsrc), "adapter-type",
+					  G_CALLBACK (dvbsrc_adapter_type), NULL);
+	g_signal_connect (G_OBJECT (dvbsrc), "signal-quality",
+					  G_CALLBACK (dvbsrc_signal_quality), NULL);
+	g_signal_connect (G_OBJECT (mpegdemux), "pad-added",
+					  G_CALLBACK (mpegdemux_new_pad), NULL);
+
+	g_object_set (dvbsrc, "adapter-prefix", ADAPTER_PREFIX, NULL);
+
+
+	g_object_set (queue1, "max-size-buffers", 0, NULL);
+	g_object_set (queue2, "max-size-buffers", 0, NULL);
+
+	g_object_set (queue1, "max-size-time", 0LL, NULL);
+	g_object_set (queue2, "max-size-time", 0LL, NULL);
+
+	g_object_set (queue1, "max-size-bytes", 0, NULL);
+	g_object_set (queue2, "max-size-bytes", 0, NULL);
+
+
+	g_idle_add (idle_func, work_thread);
+	/* set ready, so that dvbsrc will signal adapter_type */
+	gst_element_set_state (work_thread, GST_STATE_READY);
+
+	while (adapter_type == -1)
+	{
+		sleep (1);
+	}
+
+	if (adapter_type > 2 || adapter_type < 0)
+	{
+		printf ("Unknown adapter type (%d). Exiting...\n", adapter_type);
+		restore_terminal ();
+		exit (1);
+	}
 
-  return 0;
+	if (!read_channels (channel_files[adapter_type]))
+	{
+		printf ("Could not read %s channels from %s.\n",
+				adapter_type_str[adapter_type], channel_files[adapter_type]);
+		restore_terminal ();
+		exit (1);
+	}
+
+	channel_no = (int) g_strtod (argv[1], NULL);
+
+	if (g_list_length (channel_list) < channel_no)
+	{
+		fprintf (stderr,
+				 "Channel #%d does not exist. Only %d channels available.\n",
+				 channel_no, g_list_length (channel_list));
+		fprintf (stderr, "Tuning to #0.");
+		channel = g_list_nth (channel_list, 0);
+	}
+	else
+		channel = g_list_nth (channel_list, (int) channel_no);
+
+	fprintf (stderr, "Showing: %s\n", ((ChannelInfo *) channel->data)->name);
+	tune_channel ((ChannelInfo *) channel->data);
+
+	g_idle_add (idle_func, work_thread);
+	gst_element_set_state (work_thread, GST_STATE_PLAYING);
+
+	fprintf (stderr, "Finishing up\n");
+
+	restore_terminal ();
+
+	return 0;
 }
 
 
 void
-setup_terminal() {
-  struct termios tio_new;
-  tcgetattr(0,&tio_orig);
-  tio_new=tio_orig;
-  tio_new.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
-  tio_new.c_cc[VMIN] = 1;
-  tio_new.c_cc[VTIME] = 0;
-  tcsetattr(0,TCSANOW,&tio_new);
+setup_terminal ()
+{
+	struct termios tio_new;
+	tcgetattr (0, &tio_orig);
+	tio_new = tio_orig;
+	tio_new.c_lflag &= ~(ICANON | ECHO);	/* Clear ICANON and ECHO. */
+	tio_new.c_cc[VMIN] = 1;
+	tio_new.c_cc[VTIME] = 0;
+	tcsetattr (0, TCSANOW, &tio_new);
 
-  /* non-blocking read from stdin */
-  fcntl(0, F_SETFL, O_NONBLOCK);
+	/* non-blocking read from stdin */
+	fcntl (0, F_SETFL, O_NONBLOCK);
 }
 
-void restore_terminal() {
-  tcsetattr(0,TCSANOW,&tio_orig);
+void
+restore_terminal ()
+{
+	tcsetattr (0, TCSANOW, &tio_orig);
 }
 
-ChannelInfo*
-new_channel (void) {
- ChannelInfo* channel = g_malloc(sizeof(ChannelInfo));
- /* channel file structure does not guarantee that
-    all necessary params are specified for a channel (-s, -t, -c)*/
- channel->bandwidth         = -1;         
- channel->code_rate_hp      = -1;      
- channel->code_rate_lp      = -1;      
- channel->guard_int         = -1;         
- channel->h_pol             = -1;  
- channel->inversion         = -1;
- channel->modulation        = -1;        
- channel->transmission_mode = -1; 
- channel->hierarchy         = -1;         
- return channel;
+ChannelInfo *
+new_channel (void)
+{
+	ChannelInfo *channel = g_malloc (sizeof (ChannelInfo));
+	/* channel file structure does not guarantee that
+	 * all necessary params are specified for a channel (-s, -t, -c) */
+	channel->bandwidth = -1;
+	channel->code_rate_hp = -1;
+	channel->code_rate_lp = -1;
+	channel->guard_int = -1;
+	channel->h_pol = -1;
+	channel->inversion = -1;
+	channel->modulation = -1;
+	channel->transmission_mode = -1;
+	channel->hierarchy = -1;
+	return channel;
 }
 
 /* return true if at least one channel was parsed correctly */
 gboolean
-read_channels(const char* filename) {
-  FILE *channel_file;
-  gboolean success = FALSE;
-  gchar line_buf [1024];
-  int i;
-
-  channel_file = fopen(filename, "r");
-
-  if (channel_file == (FILE *) 0) {
-    fprintf(stderr, "Could not open channel file: %s\n", filename);
-    return FALSE;
-  }
-
-  /* read channel config line by line */
-  while (!feof(channel_file)) {
-    if (fgets(line_buf, sizeof(line_buf)-1, channel_file)) {
-      ChannelInfo *channel = NULL;
-      gboolean parse_error = FALSE;
-      gchar *params = NULL;
-      gchar ** fields = NULL;
-      gchar ** tmp_fields = NULL;
-      int count = 0;
-
-      /* Ignore group delimiters */
-      if (line_buf[0] == ':')
-	continue;
-
-      fields = g_strsplit(line_buf, ":", 13);
-
-      /* check whether there are 13 values (recent vdr channels.conf format)*/
-      while (count < 13) {
-	if (fields == NULL || fields[count] == NULL) 
-	  break;
-	count++;
-      }
-      
-      if (count != 13 || fields[count] != NULL)
-	goto end; /* try next line */
-
-      channel = new_channel();
-      channel->name = g_strdup(fields[0]);
-      channel->freq = (int) g_ascii_strtod(fields[1], NULL);
-      params = g_strdup(fields[2]);
-
-      switch (fields[3][0]) {
-      case 'S':
-	channel->source = 0;
-	break;
-      case 'T':
-	channel->source = 1;
-	break;
-      case 'C':
-	channel->source = 2;
-	break;
-      default:
-	goto error;
-	break;
-      }
-
-      /* read adapter_type channels only */
-      if (channel->source != adapter_type) {
-	g_free(channel);
-	goto end;
-      }
-
-      /* parse params */
-      i = 0;
-      while (i < strlen(params)) {
-	switch (g_ascii_toupper(params[i])) {
-
-	case 'B':
-	  if (params[i+1] == '6')
-	    channel->bandwidth = 2;
-	  else if (params[i+1] == '7')
-	    channel->bandwidth = 1;
-	  else if (params[i+1] == '8')
-	    channel->bandwidth = 0;
-	  /* AUTO */
-	  else if (params[i+1] == '9' && params[i+2] == '9' && params[i+3] == '9') { 
-	    channel->bandwidth = 3;
-	    i += 2;
-	  }
-	  else 
-	    goto error;
-	  i++;
-	  break;
-
-	case 'C':
-	case 'D': {
-	  int tmp;
-	  if (params[i+1] == '0')
-	   tmp  = 0;
-	  else if (params[i+1] == '1' && params[i+2] == '2')
-	   tmp  = 1;
-	  else if (params[i+1] == '2' && params[i+2] == '3')
-	   tmp  = 2;
-	  else if (params[i+1] == '3' && params[i+2] == '4')
-	   tmp  = 3;
-	  else if (params[i+1] == '4' && params[i+2] == '5')
-	   tmp  = 4;
-	  else if (params[i+1] == '5' && params[i+2] == '6')
-	   tmp  = 5;
-	  else if (params[i+1] == '6' && params[i+2] == '7')
-	   tmp  = 6;
-	  else if (params[i+1] == '7' && params[i+2] == '8')
-	   tmp  = 7;
-	  else if (params[i+1] == '8' && params[i+2] == '9')
-	   tmp  = 8;
-	  /* AUTO */
-	  else if (params[i+1] == '9' && params[i+2] == '9' && params[i+3] == '9') { 
-	    tmp = 9;
-	  }
-	  else 
-	    goto error;
-
-	  if (params[i] == 'C')
-	    channel->code_rate_hp = tmp;
-	  else
-	    channel->code_rate_lp = tmp;
-
-	  if (tmp == 0)
-	    i++;
-	  else if (tmp == 9)
-	    i+=3;
-	  else
-	    i+=2;	    
-	  }
-	  break;
-
-	case 'G':
-	  if (params[i+1] == '4')
-	    channel->guard_int = 3;
-	  else if (params[i+1] == '8')
-	    channel->guard_int = 2;
-	  else if (params[i+1] == '1' && params[i+2] == '6')
-	    { channel->guard_int = 1; i++; }
-	  else if (params[i+1] == '3' && params[i+2] == '2')
-	    { channel->guard_int = 0; i++; }
-	  /* AUTO */
-	  else if (params[i+1] == '9' && params[i+2] == '9' && params[i+3] == '9') { 
-	    channel->guard_int = 4;
-	    i += 2;
-	  }
-	  else 
-	    goto error;
-	  i++;
-	  break;
-
-	case 'H':
-	  channel->h_pol = TRUE;
-	  i++;
-	  break;
-
-	case 'I':
-	  if (params[i+1] == '1')
-	    channel->inversion = TRUE;
-	  else if (params[i+1] == '0')
-	    channel->inversion = FALSE;
-	  else 
-	    goto error;
-	  i++;
-	  break;
-	case 'M':
-	  if (params[i+1] == '0')
-	    channel->modulation = 0;
-	  else if (params[i+1] == '1' && params[i+2] == '6')
-	    channel->modulation = 1;
-	  else if (params[i+1] == '3' && params[i+2] == '2')
-	    channel->modulation = 2;
-	  else if (params[i+1] == '6' && params[i+2] == '4')
-	    channel->modulation = 3;
-	  else if (params[i+1] == '1' && params[i+2] == '2' && params[i+2] == '8')
-	    channel->modulation = 4;
-	  else if (params[i+1] == '2' && params[i+2] == '5' && params[i+3] == '6')
-	    channel->modulation = 5;
-	  /* AUTO */
-	  else if (params[i+1] == '9' && params[i+2] == '9' && params[i+3] == '9')
-	    channel->modulation = 6;
-	  else
-	    goto error;
-
-	  if (channel->modulation >= 4)
-	    i += 3;
-	  else if (channel->modulation >= 1)
-	    i += 2;
-	  else
-	    i++;
-	  break;
-
-	case 'T':
-	  if (params[i+1] == '2')
-	    channel->transmission_mode = 0;
-	  else if (params[i+1] == '8')
-	    channel->transmission_mode = 1;
-	  /* AUTO */
-	  else if (params[i+1] == '9' && params[i+2] == '9' && params[i+3] == '9') { 
-	    channel->transmission_mode = 2;
-	    i += 2;
-	  }
-	  else 
-	    goto error;
-	  i++;
-	  break;
-	case 'V':
-	  channel->h_pol = FALSE;
-	  i++;
-	  break;
-	case 'Y':
-	  if (params[i+1] == '0')
-	    channel->hierarchy = 0;
-	  else if (params[i+1] == '1')
-	    channel->hierarchy = 1;
-	  else if (params[i+1] == '2')
-	    channel->hierarchy = 2;
-	  else if (params[i+1] == '4')
-	    channel->hierarchy = 3;
-	  /* AUTO */
-	  else if (params[i+1] == '9' && params[i+2] == '9' && params[i+3] == '9') { 
-	    channel->hierarchy = 4;
-	    i += 2;
-	  }
-	  else 
-	    goto error;
-	  i++;
-	  break;
-
-	default:
-	  goto error;
-
-	  break;
+read_channels (const char *filename)
+{
+	FILE *channel_file;
+	gboolean success = FALSE;
+	gchar line_buf[1024];
+	int i;
+
+	channel_file = fopen (filename, "r");
+
+	if (channel_file == (FILE *) 0)
+	{
+		fprintf (stderr, "Could not open channel file: %s\n", filename);
+		return FALSE;
 	}
-	i++;
-      }
-
-      channel->symbol_rate = g_ascii_strtod(fields[4], NULL);
 
-      /* parse vpid+pcrpid */
-      tmp_fields = g_strsplit(fields[5], "+", 2);
-      if (tmp_fields[0] != NULL)
-	channel->video_pid = g_ascii_strtod(tmp_fields[0], NULL);
-      else 
-	fprintf(stderr, "Error parsing config file\n");
-      if (tmp_fields[1] != NULL)
-	channel->pcr_pid = g_ascii_strtod(tmp_fields[1], NULL);
-      g_strfreev(tmp_fields);
-
-      /* parse audio pids apid1,apid2;dpid1,dpid2 */
-      tmp_fields = g_strsplit(fields[6], ";", 2);
-      /* audio pids */
-      if (tmp_fields[0] != NULL) {
-	char **audio_fields = g_strsplit(tmp_fields[0], ",", 2);
-	if (audio_fields[0] != NULL)
-	  channel->audio_pids[0] = g_ascii_strtod(audio_fields[0], NULL);
-	else
-	  fprintf(stderr, "Error parsing config file\n");
-	if (audio_fields[1] != NULL)
-	  channel->audio_pids[1] = g_ascii_strtod(audio_fields[1], NULL);
-	g_strfreev(audio_fields);
-      }
-
-      /* dolby pids */
-      if (tmp_fields[1] != NULL) {
-	char **dolby_fields = g_strsplit(tmp_fields[0], ",", 2);
-	if (dolby_fields[0] != NULL)
-	  channel->dolby_pids[0] = g_ascii_strtod(dolby_fields[0], NULL);
-	if (dolby_fields[1] != NULL)
-	  channel->dolby_pids[1] = g_ascii_strtod(dolby_fields[1], NULL);
-	g_strfreev(dolby_fields);
-      }
-      g_strfreev(tmp_fields);
-
-      channel->teletext_pid = g_ascii_strtod(fields[7], NULL);
-      channel->ca = g_ascii_strtod(fields[8], NULL);
-      channel->service_id = g_ascii_strtod(fields[9], NULL);
-      channel->network_id = g_ascii_strtod(fields[10], NULL);
-      channel->transport_stream_id = g_ascii_strtod(fields[11], NULL);
-      channel->radio_id = g_ascii_strtod(fields[12], NULL);
-
-      channel_list = g_list_append(channel_list, channel);
-      channel_count++;
-      success = TRUE;
-      goto end;
-
-    error:
-      fprintf(stderr, "Error parsing config file\n");
-      g_free(channel);
-
-    end:
-      g_strfreev(fields);
-      g_free(params);
-    }
-  }
+	/* read channel config line by line */
+	while (!feof (channel_file))
+	{
+		if (fgets (line_buf, sizeof (line_buf) - 1, channel_file))
+		{
+			ChannelInfo *channel = NULL;
+			gboolean parse_error = FALSE;
+			gchar *params = NULL;
+			gchar **fields = NULL;
+			gchar **tmp_fields = NULL;
+			int count = 0;
+
+			/* Ignore group delimiters */
+			if (line_buf[0] == ':')
+				continue;
+
+			fields = g_strsplit (line_buf, ":", 13);
+
+			/* check whether there are 13 values (recent vdr channels.conf format) */
+			while (count < 13)
+			{
+				if (fields == NULL || fields[count] == NULL)
+					break;
+				count++;
+			}
+
+			if (count != 13 || fields[count] != NULL)
+				goto end;		/* try next line */
+
+			channel = new_channel ();
+			channel->name = g_strdup (fields[0]);
+			channel->freq = (int) g_ascii_strtod (fields[1], NULL);
+			params = g_strdup (fields[2]);
+
+			switch (fields[3][0])
+			{
+			case 'S':
+				channel->source = 0;
+				break;
+			case 'T':
+				channel->source = 1;
+				break;
+			case 'C':
+				channel->source = 2;
+				break;
+			default:
+				goto error;
+				break;
+			}
+
+			/* read adapter_type channels only */
+			/*if (channel->source != adapter_type)
+			{
+				g_free (channel);
+				goto end;
+			}*/
+
+			/* parse params */
+			i = 0;
+			while (i < strlen (params))
+			{
+				switch (g_ascii_toupper (params[i]))
+				{
+
+				case 'B':
+					if (params[i + 1] == '6')
+						channel->bandwidth = 2;
+					else if (params[i + 1] == '7')
+						channel->bandwidth = 1;
+					else if (params[i + 1] == '8')
+						channel->bandwidth = 0;
+					/* AUTO */
+					else if (params[i + 1] == '9' && params[i + 2] == '9'
+							 && params[i + 3] == '9')
+					{
+						channel->bandwidth = 3;
+						i += 2;
+					}
+					else
+						goto error;
+					i++;
+					break;
+
+				case 'C':
+				case 'D':
+				{
+					int tmp;
+					if (params[i + 1] == '0')
+						tmp = 0;
+					else if (params[i + 1] == '1' && params[i + 2] == '2')
+						tmp = 1;
+					else if (params[i + 1] == '2' && params[i + 2] == '3')
+						tmp = 2;
+					else if (params[i + 1] == '3' && params[i + 2] == '4')
+						tmp = 3;
+					else if (params[i + 1] == '4' && params[i + 2] == '5')
+						tmp = 4;
+					else if (params[i + 1] == '5' && params[i + 2] == '6')
+						tmp = 5;
+					else if (params[i + 1] == '6' && params[i + 2] == '7')
+						tmp = 6;
+					else if (params[i + 1] == '7' && params[i + 2] == '8')
+						tmp = 7;
+					else if (params[i + 1] == '8' && params[i + 2] == '9')
+						tmp = 8;
+					/* AUTO */
+					else if (params[i + 1] == '9' && params[i + 2] == '9'
+							 && params[i + 3] == '9')
+					{
+						tmp = 9;
+					}
+					else
+						goto error;
+
+					if (params[i] == 'C')
+						channel->code_rate_hp = tmp;
+					else
+						channel->code_rate_lp = tmp;
+
+					if (tmp == 0)
+						i++;
+					else if (tmp == 9)
+						i += 3;
+					else
+						i += 2;
+				}
+					break;
+
+				case 'G':
+					if (params[i + 1] == '4')
+						channel->guard_int = 3;
+					else if (params[i + 1] == '8')
+						channel->guard_int = 2;
+					else if (params[i + 1] == '1' && params[i + 2] == '6')
+					{
+						channel->guard_int = 1;
+						i++;
+					}
+					else if (params[i + 1] == '3' && params[i + 2] == '2')
+					{
+						channel->guard_int = 0;
+						i++;
+					}
+					/* AUTO */
+					else if (params[i + 1] == '9' && params[i + 2] == '9'
+							 && params[i + 3] == '9')
+					{
+						channel->guard_int = 4;
+						i += 2;
+					}
+					else
+						goto error;
+					i++;
+					break;
+
+				case 'H':
+					channel->h_pol = TRUE;
+					i++;
+					break;
+
+				case 'I':
+					if (params[i + 1] == '1')
+						channel->inversion = TRUE;
+					else if (params[i + 1] == '0')
+						channel->inversion = FALSE;
+					else
+						goto error;
+					i++;
+					break;
+				case 'M':
+					if (params[i + 1] == '0')
+						channel->modulation = 0;
+					else if (params[i + 1] == '1' && params[i + 2] == '6')
+						channel->modulation = 1;
+					else if (params[i + 1] == '3' && params[i + 2] == '2')
+						channel->modulation = 2;
+					else if (params[i + 1] == '6' && params[i + 2] == '4')
+						channel->modulation = 3;
+					else if (params[i + 1] == '1' && params[i + 2] == '2'
+							 && params[i + 2] == '8')
+						channel->modulation = 4;
+					else if (params[i + 1] == '2' && params[i + 2] == '5'
+							 && params[i + 3] == '6')
+						channel->modulation = 5;
+					/* AUTO */
+					else if (params[i + 1] == '9' && params[i + 2] == '9'
+							 && params[i + 3] == '9')
+						channel->modulation = 6;
+					else
+						goto error;
+
+					if (channel->modulation >= 4)
+						i += 3;
+					else if (channel->modulation >= 1)
+						i += 2;
+					else
+						i++;
+					break;
+
+				case 'T':
+					if (params[i + 1] == '2')
+						channel->transmission_mode = 0;
+					else if (params[i + 1] == '8')
+						channel->transmission_mode = 1;
+					/* AUTO */
+					else if (params[i + 1] == '9' && params[i + 2] == '9'
+							 && params[i + 3] == '9')
+					{
+						channel->transmission_mode = 2;
+						i += 2;
+					}
+					else
+						goto error;
+					i++;
+					break;
+				case 'V':
+					channel->h_pol = FALSE;
+					i++;
+					break;
+				case 'Y':
+					if (params[i + 1] == '0')
+						channel->hierarchy = 0;
+					else if (params[i + 1] == '1')
+						channel->hierarchy = 1;
+					else if (params[i + 1] == '2')
+						channel->hierarchy = 2;
+					else if (params[i + 1] == '4')
+						channel->hierarchy = 3;
+					/* AUTO */
+					else if (params[i + 1] == '9' && params[i + 2] == '9'
+							 && params[i + 3] == '9')
+					{
+						channel->hierarchy = 4;
+						i += 2;
+					}
+					else
+						goto error;
+					i++;
+					break;
+
+				default:
+					goto error;
+
+					break;
+				}
+				i++;
+			}
+
+			channel->symbol_rate = g_ascii_strtod (fields[4], NULL);
+
+			/* parse vpid+pcrpid */
+			tmp_fields = g_strsplit (fields[5], "+", 2);
+			if (tmp_fields[0] != NULL)
+				channel->video_pid = g_ascii_strtod (tmp_fields[0], NULL);
+			else
+				fprintf (stderr, "Error parsing config file\n");
+			if (tmp_fields[1] != NULL)
+				channel->pcr_pid = g_ascii_strtod (tmp_fields[1], NULL);
+			g_strfreev (tmp_fields);
+
+			/* parse audio pids apid1,apid2;dpid1,dpid2 */
+			tmp_fields = g_strsplit (fields[6], ";", 2);
+			/* audio pids */
+			if (tmp_fields[0] != NULL)
+			{
+				char **audio_fields = g_strsplit (tmp_fields[0], ",", 2);
+				if (audio_fields[0] != NULL)
+					channel->audio_pids[0] =
+						g_ascii_strtod (audio_fields[0], NULL);
+				else
+					fprintf (stderr, "Error parsing config file\n");
+				if (audio_fields[1] != NULL)
+					channel->audio_pids[1] =
+						g_ascii_strtod (audio_fields[1], NULL);
+				g_strfreev (audio_fields);
+			}
+
+			/* dolby pids */
+			if (tmp_fields[1] != NULL)
+			{
+				char **dolby_fields = g_strsplit (tmp_fields[0], ",", 2);
+				if (dolby_fields[0] != NULL)
+					channel->dolby_pids[0] =
+						g_ascii_strtod (dolby_fields[0], NULL);
+				if (dolby_fields[1] != NULL)
+					channel->dolby_pids[1] =
+						g_ascii_strtod (dolby_fields[1], NULL);
+				g_strfreev (dolby_fields);
+			}
+			g_strfreev (tmp_fields);
+
+			channel->teletext_pid = g_ascii_strtod (fields[7], NULL);
+			channel->ca = g_ascii_strtod (fields[8], NULL);
+			channel->service_id = g_ascii_strtod (fields[9], NULL);
+			channel->network_id = g_ascii_strtod (fields[10], NULL);
+			channel->transport_stream_id = g_ascii_strtod (fields[11], NULL);
+			channel->radio_id = g_ascii_strtod (fields[12], NULL);
+
+			channel_list = g_list_append (channel_list, channel);
+			channel_count++;
+			success = TRUE;
+			goto end;
+
+		  error:
+			fprintf (stderr, "Error parsing config file\n");
+			g_free (channel);
+
+		  end:
+			g_strfreev (fields);
+			g_free (params);
+		}
+	}
 
-  fclose(channel_file);
+	fclose (channel_file);
 
-  return success;
+	return success;
 }
-
-
