? aclocal.m4
? autom4te.cache
? config.log
? config.status
? configure
? dvbtv.patch
? gstdvbtv
? libtool
Index: gstdvbsrc.c
===================================================================
RCS file: /cvs/gstreamer/gst-sandbox/dvb-elements/dvbsrc/gstdvbsrc.c,v
retrieving revision 1.7
diff -u -r1.7 gstdvbsrc.c
--- gstdvbsrc.c	19 Dec 2004 23:24:06 -0000	1.7
+++ gstdvbsrc.c	16 Mar 2005 12:09:32 -0000
@@ -777,8 +777,6 @@
  */
 
 
-//static gboolean plugin_init(GModule *module, GstPlugin *plugin);
-
 
 /* entry point to initialize the plug-in
  * initialize the plug-in itself
Index: gstdvbtv.c
===================================================================
RCS file: /cvs/gstreamer/gst-sandbox/dvb-elements/dvbsrc/gstdvbtv.c,v
retrieving revision 1.4
diff -u -r1.4 gstdvbtv.c
--- gstdvbtv.c	19 Dec 2004 23:24:06 -0000	1.4
+++ gstdvbtv.c	16 Mar 2005 12:09:33 -0000
@@ -10,11 +10,10 @@
 
 static struct termios tio_orig;
 
-#define CHANNEL_FILE "channels.conf.sat"
 #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;
@@ -25,28 +24,34 @@
 GstElement *mad;
 GstElement *mpeg2dec;
 GstElement *mpegdemux;
-GstElement *work_thread, *audio_thread, *video_thread;
+GstElement *source_thread, *work_thread, *audio_thread, *video_thread;
 
 GList* channel_list;
 GList* channel = NULL;
 gint channel_count = 0;
 
+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"};
+
+
 
 typedef struct {
   char *name;
   int freq;
   char *params;
-  /* decoded params */
+  /* decoded params (-1: unknown)*/
   int bandwidth;         
   int code_rate_hp;      
   int code_rate_lp;      
   int guard_int;         
-  gboolean h_pol;
-  gboolean inversion;
+  int h_pol;       /* 0: v_pol, 1:h_pol */
+  int inversion;   /* 0: no,    1:yes   */
   int modulation;        
   int transmission_mode; 
   int hierarchy;         
@@ -75,12 +80,36 @@
   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,
-	       "pol", chn_data->h_pol ? "H" : "V",
-	       "srate",chn_data->symbol_rate,
-	       "pids", pids,
-	       NULL);
 
+
+  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,
@@ -90,24 +119,6 @@
 }
 
 
-void
-replace_demux() {
-  gst_element_set_state(GST_ELEMENT(work_thread), GST_STATE_PAUSED);
-  //gst_element_set_state(GST_ELEMENT(audio_thread), GST_STATE_READY);
-  //gst_element_set_state(GST_ELEMENT(video_thread), GST_STATE_READY);
-
-  gst_element_unlink(GST_ELEMENT(ts2ps), mpegdemux);
-  gst_element_unlink(GST_ELEMENT(mpegdemux), queue1);
-  gst_element_unlink(GST_ELEMENT(mpegdemux), queue2);
-  gst_bin_remove(GST_BIN(work_thread), mpegdemux);
-  //  g_object_unref(mpegdemux);
-  mpegdemux = gst_element_factory_make("mpegdemux","mpegdemux");
-  gst_bin_add(GST_BIN(work_thread), mpegdemux);
-  gst_element_link(ts2ps, mpegdemux);
-  g_signal_connect(G_OBJECT(mpegdemux), "new_pad", G_CALLBACK(mpegdemux_new_pad), NULL);
-  gst_element_set_state(GST_ELEMENT(work_thread), GST_STATE_PLAYING);
-}
-
 gboolean
 idle_func (gpointer data)
 {
@@ -134,8 +145,7 @@
     case NEXT_KEY:
       channel = g_list_next(channel);
       if (!channel)
-	channel = channel_list;        // set first channel
-      // replace_demux();
+	channel = channel_list;        /* set first channel */
       tune_channel((ChannelInfo*) channel->data);
       fprintf(stderr, "Next, %s\n", ((ChannelInfo*) channel->data)->name);
       break;
@@ -143,7 +153,6 @@
       channel = g_list_previous(channel);
       if (!channel)
 	channel = g_list_last(channel_list);
-      // replace_demux();
       tune_channel((ChannelInfo*) channel->data);
       fprintf(stderr, "Prev, %s\n", ((ChannelInfo*) channel->data)->name);
       break;
@@ -158,18 +167,21 @@
   return busy;
 }
 
+
 static void
 dvbsrc_signal_quality(GstElement *dvbsrc, gint strength, gint snr) {
-  // This would be nice to toggle into an OSD
+  /* 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);
 }
 
+
 static void
 mpegdemux_new_pad (GstElement *parse, GstPad *pad, GObject *object)
 {
@@ -192,20 +204,13 @@
   gst_element_set_state(GST_ELEMENT (work_thread), GST_STATE_PLAYING);
 }
 
+
 int
 main (int argc, char **argv)
 {
   int channel_no = 1;
-  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);
+  setup_terminal();
   
   if (argc < 2) {
     printf( "\nUsage: gstdvbtv <channel-num>\n\n");
@@ -215,12 +220,12 @@
   gst_init(&argc, &argv);
   g_type_init();
 
-  // Build Pipeline:                          
-  //                             / { queue1 ! mpeg2dec ! xvimagesink } 
-  //  dvbsrc ! ts2ps ! mpegdemux 
-  //                             \ { queue2 ! mad ! osssink }
+  /* 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");
@@ -238,11 +243,12 @@
   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(work_thread), dvbsrc, ts2ps, mpegdemux, NULL);
-
+  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);
 
@@ -254,6 +260,17 @@
 
   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);
@@ -262,17 +279,24 @@
     sleep(1);
   }
 
-  if (!read_channels(CHANNEL_FILE)) {
-    printf("Could not read %s channels from %s.\n", adapter_type_str[adapter_type], CHANNEL_FILE);
+  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, "Channels #%d does not exist. Only %d channels available.\n",
-	   channel_no, g_list_length(channel_list));
-    fprintf(stderr, "Playing #0.");
+    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
@@ -288,12 +312,47 @@
 
   fprintf(stderr, "Finishing up\n");
 
-  tcsetattr(0,TCSANOW,&tio_orig);
+  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);
+
+  /* non-blocking read from stdin */
+  fcntl(0, F_SETFL, O_NONBLOCK);
+}
+
+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;
+}
+
 /* return true if at least one channel was parsed correctly */
 gboolean
 read_channels(const char* filename) {
@@ -319,7 +378,7 @@
       gchar ** tmp_fields = NULL;
       int count = 0;
 
-      // Ignore group delimiters
+      /* Ignore group delimiters */
       if (line_buf[0] == ':')
 	continue;
 
@@ -335,7 +394,7 @@
       if (count != 13 || fields[count] != NULL)
 	goto end; /* try next line */
 
-      channel = g_malloc(sizeof(ChannelInfo));
+      channel = new_channel();
       channel->name = g_strdup(fields[0]);
       channel->freq = (int) g_ascii_strtod(fields[1], NULL);
       params = g_strdup(fields[2]);
