# Path: utils/process.py
# def run_cmd(cmd, shell=False):
#     env = dict(os.environ)
#     env["LANG"] = "C"
#     if shell:
#         args = cmd
#     else:
#         args = shlex.split(cmd)
#     p = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=shell)
#     stdout, stderr = p.communicate()
#     rc = p.returncode
#     if rc != 0:
#         if '|' in cmd:
#             raise Exception('Command %s failed, maybe shell=True is required' %cmd)
#         else:
#             raise Exception('Command %s failed, error: %s' % (cmd, stderr))
#     elif contains_errors(stderr):
#         raise Exception('Command %s had an error' %cmd)
#     return rc, stdout, stderr
# 
# Path: utils/v4l.py
# def v4l_get_current_device():
#     return os.environ.get('V4L2_TEST_DEVICE', '/dev/video0')


import os
from utils.process import run_cmd
from utils.v4l import v4l_get_current_device
    from utils.run import run_test
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2015, Florent Thiery 


framerates = [60, 30, 25]

resolutions = [
    (3840, 2160),
    (1920, 1200),
    (1920, 1080),
    (1280, 720),
    (1024, 768),
]

cmd_pattern = 'gst-launch-1.0 v4l2src num-buffers=1 device=%s ! "video/x-raw, width=(int)%s, height=(int)%s, framerate=(fraction)%s/1" ! fakesink'

def run():
    results = list()
    at_least_one_success = False
    for f in framerates:
        for r in resolutions:
            info = "Scaling test %sx%s@%s" %(r[0], r[1], f)
            cmd = cmd_pattern %(v4l_get_current_device(), r[0], r[1], f)
            try:

# Path: utils/process.py
# def run_cmd(cmd, shell=False):
#     env = dict(os.environ)
#     env["LANG"] = "C"
#     if shell:
#         args = cmd
#     else:
#         args = shlex.split(cmd)
#     p = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=shell)
#     stdout, stderr = p.communicate()
#     rc = p.returncode
#     if rc != 0:
#         if '|' in cmd:
#             raise Exception('Command %s failed, maybe shell=True is required' %cmd)
#         else:
#             raise Exception('Command %s failed, error: %s' % (cmd, stderr))
#     elif contains_errors(stderr):
#         raise Exception('Command %s had an error' %cmd)
#     return rc, stdout, stderr
# 
# Path: utils/v4l.py
# def v4l_get_current_device():
#     return os.environ.get('V4L2_TEST_DEVICE', '/dev/video0')


# Path: tests/v4l/scaling.py
import os
from utils.process import run_cmd
from utils.v4l import v4l_get_current_device
    from utils.run import run_test

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2015, Florent Thiery 


framerates = [60, 30, 25]

resolutions = [
    (3840, 2160),
    (1920, 1200),
    (1920, 1080),
    (1280, 720),
    (1024, 768),
]

cmd_pattern = 'gst-launch-1.0 v4l2src num-buffers=1 device=%s ! "video/x-raw, width=(int)%s, height=(int)%s, framerate=(fraction)%s/1" ! fakesink'

def run():
    results = list()
    at_least_one_success = False
    for f in framerates:
        for r in resolutions:
            info = "Scaling test %sx%s@%s" %(r[0], r[1], f)
            cmd = cmd_pattern %(v4l_get_current_device(), r[0], r[1], f)
            try:

                run_cmd(cmd)