[perl-GStreamer] Make the read-metadata.pl example more robust



commit f8e2e6610cc278c64c5fb797960d687730449a88
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date:   Sun Apr 11 14:23:02 2010 +0200

    Make the read-metadata.pl example more robust
    
    Sporadically, we will encounter an "error" message (about a missing sink
    element) before a "tag" message even for a valid file.  So instead of
    aborting on an "error" message, just continue.  Also, shorten the wait
    time for state changes from 5 to 0.5 seconds, and improve the error
    message for unknown file types.

 examples/read-metadata.pl |   21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)
---
diff --git a/examples/read-metadata.pl b/examples/read-metadata.pl
index 96b830b..af6b31a 100644
--- a/examples/read-metadata.pl
+++ b/examples/read-metadata.pl
@@ -29,7 +29,7 @@
 use strict;
 use warnings;
 use Glib qw(TRUE FALSE);
-use GStreamer qw(GST_SECOND);
+use GStreamer qw(GST_MSECOND);
 
 my ($filename, $pipeline, $source);
 
@@ -51,11 +51,17 @@ sub message_loop {
       last;
     }
 
-    if ($message -> type & "error" or
-        $message -> type & "eos") {
+    if ($message -> type & "eos") {
+      # End of stream, no tags found yet -> return undef
       return undef;
     }
 
+    if ($message -> type & "error") {
+      # decodebin complains about not having an element attached to its output.
+      # Sometimes this happens even before the "tag" message, so just continue.
+      next;
+    }
+
     elsif ($message -> type & "tag") {
       my $new_tags = $message -> tag_list();
       foreach (keys %$new_tags) {
@@ -110,15 +116,10 @@ foreach (@ARGV) {
   my $sret = $pipeline -> set_state("paused");
 
   if ("async" eq $sret) {
-    my ($result, $state, undef) = $pipeline -> get_state(5 * GST_SECOND);
-
-    if ("success" ne $result) {
-      printf "State change failed for %s. Aborting\n", $filename;
-      last;
-    }
+    ($sret, undef, undef) = $pipeline -> get_state(500 * GST_MSECOND);
   }
 
-  elsif ($sret ne "success") {
+  if ("success" ne $sret) {
     printf "%s - Could not read file\n", $filename;
     next;
   }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]