# Path: utils/time.py
# def time_took(function):
#     before = time.time()
#     try:
#         success = function()
#     except Exception as e:
#         print('Error: %s' %e)
#         return 0
#     after = time.time()
#     took = (after - before) if success else 0
#     return took
# 
# 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.time import time_took
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 


cmd_pattern = "gst-launch-1.0 v4l2src device=%s num-buffers=1 ! fakesink"

MAX_TIME_S = 1

def _run():
    run_cmd(cmd_pattern %v4l_get_current_device())

def run():
    took = time_took(_run)
    if took < 10:
        took_str = "%ims" %(took*1000)
    else:
        took_str = "%.2fs" %took

# Path: utils/time.py
# def time_took(function):
#     before = time.time()
#     try:
#         success = function()
#     except Exception as e:
#         print('Error: %s' %e)
#         return 0
#     after = time.time()
#     took = (after - before) if success else 0
#     return took
# 
# 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/first_buffer_time.py
import os
from utils.time import time_took
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 


cmd_pattern = "gst-launch-1.0 v4l2src device=%s num-buffers=1 ! fakesink"

MAX_TIME_S = 1

def _run():
    run_cmd(cmd_pattern %v4l_get_current_device())

def run():
    took = time_took(_run)
    if took < 10:
        took_str = "%ims" %(took*1000)
    else:
        took_str = "%.2fs" %took

    info = "First buffer arrived after %s (max: %ss)" %(took_str, MAX_TIME_S)