~ubuntu-branches/ubuntu/trusty/plainbox-provider-checkbox/trusty

« back to all changes in this revision

Viewing changes to bin/gst_pipeline_test

  • Committer: Package Import Robot
  • Author(s): Zygmunt Krynicki
  • Date: 2014-04-07 19:00:31 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140407190031-rf836grml6oilfyt
Tags: 0.4-1
* New upstream release. List of bugfixes:
  https://launchpad.net/plainbox-provider-checkbox/14.04/0.4
* debian/watch: look for new releases on launchpad
* debian/rules: stop using pybuild and use manage.py
  {i18n,build,install,validate} instead. This also drops dependency on
  python3-distutils-extra and replaces that with intltool
* debian/control: drop X-Python3-Version
* debian/control: make plainbox-provider-checkbox depend on python and
  python2.7 (for some scripts) rather than suggesting them.
* debian/upstream/signing-key.asc: Use armoured gpg keys to avoid having to
  keep binary files in Debian packaging. Also, replace that with my key
  since I made the 0.3 release upstream.
* debian/source/lintian-overrides: add an override for warning about no
  source for flash movie with reference to a bug report that discusses that
  issue.
* debian/source/include-binaries: drop (no longer needed)
* debian/patches: drop (no longer needed)
* debian/plainbox-provider-checkbox.lintian-overrides: drop (no longer
  needed)
* Stop being a python3 module, move to from DPMT to PAPT

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
 
 
3
from argparse import ArgumentParser
 
4
import logging
 
5
import re
 
6
import os
 
7
import sys
 
8
import time
 
9
from gi.repository import Gst
 
10
from gi.repository import GLib
 
11
from subprocess import check_output
 
12
 
 
13
 
 
14
def check_state(device):
 
15
    """Checks whether the sink is available for the given device.
 
16
    """
 
17
    sink_info = check_output(['pacmd', 'list-sinks'],
 
18
                             universal_newlines=True)
 
19
 
 
20
    data = sink_info.split("\n")
 
21
    try:
 
22
        device_name = re.findall(".*name:\s.*%s.*" % device, sink_info)[0].lstrip()
 
23
        sink = re.findall(".*name:\s<(.*%s.*)>" % device, sink_info)[0].lstrip()
 
24
        status = data[data.index("\t" + device_name) + 3]
 
25
    except (IndexError, ValueError):
 
26
        logging.error("Failed to find status for device: %s" % device)
 
27
        return False
 
28
 
 
29
    os.environ['PULSE_SINK'] = sink
 
30
    logging.info("[ Pulse sink ]".center(80, '='))
 
31
    logging.info("Device: %s %s" % (device_name.strip(), status.strip()))
 
32
    return status 
 
33
 
 
34
 
 
35
def main():
 
36
    parser = ArgumentParser(description='Simple GStreamer pipeline player')
 
37
    parser.add_argument('PIPELINE',
 
38
        help='Quoted GStreamer pipeline to launch')
 
39
    parser.add_argument('-t', '--timeout',
 
40
        type=int, required=True,
 
41
        help='Timeout for running the pipeline')
 
42
    parser.add_argument('-d', '--device',
 
43
        type=str,
 
44
        help="Device to check for status")
 
45
    args = parser.parse_args()
 
46
 
 
47
    logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO,
 
48
        stream=sys.stdout)
 
49
 
 
50
    exit_code = 0
 
51
    if args.device:
 
52
        if not check_state(args.device):
 
53
            exit_code = 1
 
54
 
 
55
    Gst.init(None)
 
56
    try:
 
57
        print("Attempting to initialize Gstreamer pipeline: {}".format(
 
58
              args.PIPELINE))
 
59
        element = Gst.parse_launch(args.PIPELINE)
 
60
    except GLib.GError as error:
 
61
        print("Specified pipeline couldn't be processed.")
 
62
        print("Error when processing pipeline: {}".format(error))
 
63
        #Exit harmlessly
 
64
        return(2)
 
65
 
 
66
    print("Pipeline initialized, now starting playback.")
 
67
    element.set_state(Gst.State.PLAYING)
 
68
 
 
69
    if args.timeout:
 
70
        time.sleep(args.timeout)
 
71
 
 
72
    element.set_state(Gst.State.NULL)
 
73
 
 
74
    return exit_code
 
75
 
 
76
 
 
77
if __name__ == "__main__":
 
78
    sys.exit(main())