#!/bin/sh
#
# video
#
# start the video modules 
. /etc/init.d/rc.config
launch="yes"

#++PR261988++
PHONE_MODEL=`CLISettings get CURRENT PHONE_MODEL`
if  [[ x"$PHONE_MODEL" != x"VHE2" ]]; then
    echo "No video for $PHONE_MODEL model !!!"
    exit 0
fi
#--PR261988--

USBENC_VCPDEV=/usr/bin/usbenc-vcpdev-alu
HANTRO_VCPDEV=/usr/bin/hantro-vcpdev-alu

# do the required action
case "$1" in
    start|"")
        if [ "$launch" = "yes" ]; then
                # Start the modules
                if [ -x /etc/init.d/rc.modules.file ]; then 
                        if [  -f /etc/modules.video ]; then 
                                # take care that X rights are not OK into vdec package
                                sh /usr/vdec/memalloc_load.sh
                                /etc/init.d/rc.modules.file /etc/modules.video
                                # registering bellagio (ONLY for tests)
                                if [  -x /usr/bin/omxregister-bellagio ]; then
                                       echo "Registering bellagio..."
                                       /usr/bin/omxregister-bellagio $OMX_BELLAGIO_LIBS
                                fi
                                # start hantro device video support
                                if [  -x $HANTRO_VCPDEV ]; then
                                       echo 0 > /proc/sys/vcp/dbgprint
                                       start-stop-daemon -S -b -x $HANTRO_VCPDEV 
                                       VC_VCPDEV_OPTS="decpipe=0"
                                fi
                                if [ -x $USBENC_VCPDEV ]; then
                                       start-stop-daemon -S -b -x $USBENC_VCPDEV
                                fi
                        else 
                                echoerror \"Cannot find the file containing modules \"; 
                        fi
                else 
                        echoerror \"Cannot start modules.file script\"; 
                fi
        fi
    ;; 
    stop)
        	# Stop the modules
                killall `basename $USBENC_VCPDEV` 2>/dev/null
                killall `basename $HANTRO_VCPDEV` 2>/dev/null
        	if [ -x /etc/init.d/rc.modules.file ]; then 
        		if [  -f /etc/modules.video ]; then 
               			/etc/init.d/rc.modules.file /etc/modules.video unload /etc/modules.no-unload
            		else 
                		echoerror \"Cannot find the file containing modules \"; 
			fi
            	else 
                	echoerror \"Cannot start modules.file script\"; 
        	fi
    ;;
    *)
        echo "Usage $scriptname {start|stop}" >&2
        exit 1
    ;;
esac
