~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to checkbox-old/scripts/gst_pipeline_test

  • Committer: Tarmac
  • Author(s): Brendan Donegan
  • Date: 2013-06-03 11:12:58 UTC
  • mfrom: (2154.2.1 bug1185759)
  • Revision ID: tarmac-20130603111258-1b3m5ydvkf1accts
"[r=zkrynicki][bug=1185759][author=brendan-donegan] automatic merge by tarmac"

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 re
 
5
import sys
 
6
import time
 
7
from gi.repository import Gst
 
8
from subprocess import check_output
 
9
 
 
10
 
 
11
def check_state(device):
 
12
    """Checks whether the sink is available for the given device.
 
13
    """
 
14
    sink_info = check_output(['pacmd', 'list-sinks'],
 
15
                             universal_newlines=True)
 
16
 
 
17
    data = sink_info.split("\n")
 
18
    try:
 
19
        device = re.findall(".*name:\s.*%s.*" % device, sink_info)[0].lstrip()
 
20
        status = data[data.index("\t" + device) + 3]
 
21
    except (IndexError, ValueError):
 
22
        print("Failed to find status for device: %s" % device, file=sys.stderr)
 
23
        return False
 
24
 
 
25
    print("Device: %s %s" % (device.strip(), status.strip()))
 
26
    return status 
 
27
 
 
28
 
 
29
def main():
 
30
    parser = ArgumentParser(description='Simple GStreamer pipeline player')
 
31
    parser.add_argument('PIPELINE',
 
32
        help='Quoted GStreamer pipeline to launch')
 
33
    parser.add_argument('-t', '--timeout',
 
34
        type=int, required=True,
 
35
        help='Timeout for running the pipeline')
 
36
    parser.add_argument('-d', '--device',
 
37
        type=str,
 
38
        help="Device to check for status")
 
39
    args = parser.parse_args()
 
40
 
 
41
    Gst.init(None)
 
42
    element = Gst.parse_launch(args.PIPELINE)
 
43
    element.set_state(Gst.State.PLAYING)
 
44
 
 
45
    if args.timeout:
 
46
        time.sleep(args.timeout)
 
47
 
 
48
    exit_code = 0
 
49
    if args.device:
 
50
        if not check_state(args.device):
 
51
            exit_code = 1
 
52
 
 
53
    element.set_state(Gst.State.NULL)
 
54
 
 
55
    return exit_code
 
56
 
 
57
 
 
58
if __name__ == "__main__":
 
59
    sys.exit(main())