#!/bin/bash

# Environments
export GST_PLUGIN_PATH=/usr/lib/gstreamer-1.0
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib
export LIBVA_DRIVER_NAME=iHD
export GST_GL_PLATFORM=egl
export DISPLAY=:0

DEV_NAME=${1:-"tevs-ar0144"}

DEFAULT_RES="640x480"
DEFAULT_FMT="UYVY"
CAM_RES="${2:-$DEFAULT_RES}"
IFS='x' read -r -a RES_ARRAY <<< "$CAM_RES"
# VIDEO format setting
VIDEO_WIDTH=${RES_ARRAY[0]}
VIDEO_HEIGHT=${RES_ARRAY[1]}

CAM_FMT="${3:-$DEFAULT_FMT}"

echo "device name: $DEV_NAME"
echo "width: $VIDEO_WIDTH, height: $VIDEO_HEIGHT, format=$CAM_FMT"

gst-launch-1.0 icamerasrc device-name=$DEV_NAME ! \
"video/x-raw,format=$CAM_FMT,width=$VIDEO_WIDTH,height=$VIDEO_HEIGHT" ! videoconvert ! \
xvimagesink sync=false --no-position