File: stream-status.rb

package info (click to toggle)
ruby-gnome 4.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,648 kB
  • sloc: ruby: 67,701; ansic: 67,431; xml: 350; sh: 201; cpp: 45; makefile: 42
file content (106 lines) | stat: -rwxr-xr-x 3,018 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# This sample code is a port of
# gstreamer/tests/examples/streams/stream-status.c. It is licensed
# under the terms of the GNU Library General Public License, version
# 2 or (at your option) later.
#
# Copyright (C) 2013  Ruby-GNOME2 Project Team
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

require "gst"

def event_loop(bus, pipe)

  loop do
    message = bus.poll(Gst::MessageType::ANY, Gst::CLOCK_TIME_NONE)
    raise "message nil" if message.nil?

    case message.type
    when Gst::MessageType::EOS
      puts "received EOS"
      return
    when Gst::MessageType::WARNING
      warning, debug = message.parse_warning
      puts "#{message} #{warning.message}"
    when Gst::MessageType::ERROR
      error, debug = message.parse_error
      puts "#{message} #{error.message}"
      return
    end
  end

end

# create a new bin to hold the elements
bin = Gst::Pipeline.new("pipeline")
raise "'pipeline' gstreamer plugin missing" if bin.nil?

# create a source
fakesrc = Gst::ElementFactory.make("fakesrc", "fakesrc")
raise "'fakesrc' gstreamer plugin missing" if fakesrc.nil?

# and a sink
fakesink = Gst::ElementFactory.make("fakesink", "fakesink")
raise "'fakesink' gstreamer plugin missing" if fakesink.nil?

# add objects to the main pipeline
bin << fakesrc << fakesink

# link the elements
fakesrc >> fakesink

# get the bus, we need to install a sync handler
bin.bus.sync_handler do |bus, message|

  case message.type
  when Gst::MessageType::STREAM_STATUS
    type, owner = message.parse_stream_status

    val = message.stream_status_object

    puts "type:   #{type.inspect}"
    puts "source: #{message.src.path_string}"
    puts "owner:  #{owner.path_string}"
    puts "object: type #{val.type.name}, value #{val.value}"

    # see if we know how to deal with this object
    if val.type == Gst::Task.gtype
      task = val.value
    end

    case type
    when Gst::StreamStatusType::CREATE
      puts "created task #{task}"
    when Gst::StreamStatusType::ENTER
      # puts "raising task priority"
      # setpriority(PRIO_PROCESS, 0, -10)
    when Gst::StreamStatusType::LEAVE
    end
  end

  Gst::BusSyncReply::PASS
end

# start playing
bin.play

# run event loop listening for bus messages until EOS or ERROR
event_loop(bin.bus, bin)

# stop the bin
bin.stop