#!/bin/sh

lAudioTip=$1

FLAGS_DIR="/mnt/mtd/Flags"
SET_MIRROR="initMirrorOn"
SET_FLIP="initFlipOn"
SETTED_MIRROR="MirrorOnFlag"
SETTED_FLIP="FlipOnFlag"

script_path=`echo $0 | awk -F '/' '{for(i=2;i<NF;i++) printf"/"$i}'`
echo $script_path >> test

MIRROR_CONFG=`cat $script_path/mirrorXflip.ini | ./busybox grep "MirrorSwitch:" | sed 's/MirrorSwitch://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
FLIP_CONFG=`cat $script_path/mirrorXflip.ini | ./busybox grep "FlipSwitch:" | sed 's/FlipSwitch://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
if [ "$lAudioTip" != "no" ];then
	./simple_adec_bind_ao -r 8000 -t g711a -i audio/videoConfigStart.pcm
fi
if [ ! -d $FLAGS_DIR ]; then
	mkdir $FLAGS_DIR
fi
# Set Mirror Option
if [ "$MIRROR_CONFG" = "on" ]; then
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/engineVideoMirror.pcm
	fi
	touch $FLAGS_DIR/$SET_MIRROR
elif [ "$MIRROR_CONFG" = "off" ];then
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/closeVideoMirror.pcm
	fi
	if [ -f $FLAGS_DIR/$SETTED_MIRROR ]; then
		rm -rf $FLAGS_DIR/$SETTED_MIRROR
	fi
	if [ -f $FLAGS_DIR/$SET_MIRROR ];then
		rm -rf $FLAGS_DIR/$SET_MIRROR
	fi
else
	echo "MirrorSwitch param error."
fi	

# Set Flip Option
if [ "$FLIP_CONFG" = "on" ]; then
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/engineVedeoFlip.pcm
	fi
	touch $FLAGS_DIR/$SET_FLIP
elif [ "$FLIP_CONFG" = "off" ];then
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/closeVideoFlip.pcm
	fi
	if [ -f $FLAGS_DIR/$SETTED_FLIP ];then
		rm -rf $FLAGS_DIR/$SETTED_FLIP
	fi
	if [ -f $FLAGS_DIR/$SET_FLIP ];then
		rm -rf $FLAGS_DIR/$SET_FLIP
	fi
else
	echo "FlipSwitch param error."
fi
