Basic GStreamer "level" example converted from C

Hello all,

I'm trying to convert into Perl the given C example of the "level" element (using a message) found at:

Trivial, right? I'm using Debian/unstable, so GStreamer 0.15-2 (amd64 build) - nothing very bizzare. 42 lines of code that should be printing out an RMS level from testaudiosrc for each channel every second:
use strict;
use warnings;
use GStreamer -init;

my $loop = Glib::MainLoop->new;

my $pipeline = GStreamer::Pipeline->new("sample");
my $caps = GStreamer::Caps->from_string("audio/x-raw-int,channels=2");

my $testsrc = GStreamer::ElementFactory->make("audiotestsrc", "src");
my $convert = GStreamer::ElementFactory->make("audioconvert", "convert");
my $level = GStreamer::ElementFactory->make("level", "level");
my $sink = GStreamer::ElementFactory->make("fakesink", "sink");

$pipeline->add($testsrc, $convert, $level, $sink);
$convert->link_filtered($level, $caps);

$level->set("message", 1);
$level->set("interval", 1000000000); # 1 second interval
$pipeline->get_bus->add_watch(\&hdl_level, $loop);


sub hdl_level {
  my ($bus, $message, $loop) = @_;
  printf "Got message: %s\n", $message->type;
  return unless $message->type eq "element";
  my $structure = $message->get_structure;
  my $name = $structure->get_name;
  return unless $name eq "level";
  my @rms = $structure->get_value("rms");
  foreach (@rms) {
    print "RMS: $_\n";
  return 1;

And my output is:
Got message: [ unknown state-changed ]
Use of uninitialized value in subroutine entry at ./ line 26.
So 1st line is fine, I know the handler callback is registered; but what's uninitalized (at the run() call) and why isn't it printing the RMS output? I can;t see what I've missed from the C example here....

Many thanks,


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