shithub: openh264

Download patch

ref: a8286234bba2d693dbf39350b342137aaa2831ea
parent: ab1778a523ae7ee8721f173231ded6048d5251a5
parent: c12cf3b2a016514104ca93e2f2608181d96b66e6
author: huili2 <[email protected]>
date: Fri Jul 25 04:52:20 EDT 2014

Merge pull request #1204 from syureyi/mobile_AT

Mobile at

--- /dev/null
+++ b/autotest/performanceTest/.gitignore
@@ -1,0 +1,13 @@
+#performance test resource folder
+./EncoderPerfTestRes
+./DecoderPerfTestRes
+./DecoderPerfTestRes/*.*
+./EncoderPerfTestRes/*.*
+#performance test result folder
+./TestResultCSV
+#
+.DS_Store
+#.
+./android/report
+./ios/report
+
--- /dev/null
+++ b/autotest/performanceTest/android/run_AutoTest_android.sh
@@ -1,0 +1,138 @@
+#!/bin/bash
+
+AUTO_TEST_ANDROID_PATH=`pwd`
+AUTO_TEST_SRC_PATH="../../../"
+AUTO_TEST_RES_PATH="${AUTO_TEST_ANDROID_PATH}/report"
+mkdir -p ${AUTO_TEST_RES_PATH}
+#Prepare android build enviroment
+echo please set the enviroment variable as:
+echo export ANDROID_HOME="path of android sdk"
+echo export ANDROID_NDK_HOME="path of android ndk"
+ANDROID_SDK_PATH=${ANDROID_HOME}
+ANDROID_NDK_PATH=${ANDROID_NDK_HOME}
+ANDROID_MAKE_PARAMS="OS=android NDKROOT=${ANDROID_NDK_PATH} TARGET=android-19"
+
+if [ "#${ANDROID_SDK_PATH}" = "#" ]
+then
+echo Please set ANDROID_HOME with the path of Android SDK
+exit 1
+fi
+if [ "#${ANDROID_NDK_PATH}" = "#" ]
+then
+echo Please set ANDROID_NDK_HOME with the path of Android NDK
+exit 1
+fi
+#make build
+cd ${AUTO_TEST_SRC_PATH}
+find ./ -name *.o -exec rm -f {} \;
+find ./ -name *.d -exec rm -f {} \;
+make $ANDROID_MAKE_PARAMS
+
+if [ $? -ne 0 ]
+then
+   echo Build error,check with the trace of make
+   exit 1
+fi
+
+ENCDEC=$1
+#find apk
+if [ ${ENCDEC} = "enc" ]
+then
+echo Start to find enc apk
+apk_name=`find ./ -name WelsEncTest-debug.apk`
+if [ "#${apk_name}" = "#" ]
+then
+  echo Fail to find encoder APK.
+  exit 1
+fi
+else
+echo Start to find dec apk
+apk_name=`find ./ -name WelsDecTest-debug.apk`
+if [ "#${apk_name}" = "#" ]
+then
+echo Fail to find decoder APK.
+exit 1
+fi
+fi
+
+#prepare devices
+ADB=${ANDROID_SDK_PATH}/platform-tools/adb
+
+#get devices
+devices=`$ADB devices | awk -F" " '/\tdevice/{print $1}'`
+if [ "#$devices" = "#" ];then
+   echo "Have not any android devices."
+   exit 1
+fi
+
+#run apk
+run_apk() {
+local apk=$1;
+local rand=` date +%s`
+
+if [[ "${apk}" =~ "WelsDecTest-debug.apk" ]]
+then
+   apk_id="com.wels.dec"
+   apk_main="com.wels.dec/.WelsDecTest"
+   test_path="/sdcard/welsdec"
+   log_grep_params="welsdec"
+   test_res=${AUTO_TEST_ANDROID_PATH}/../DecoderPerfTestRes
+   report_file=${AUTO_TEST_RES_PATH}/decPerf_${rand}
+
+fi
+if [[ "${apk}" =~ "WelsEncTest-debug.apk" ]]
+then
+  apk_id="com.wels.enc"
+  apk_main="com.wels.enc/.WelsEncTest"
+  test_path="/sdcard/welsenc"
+  log_grep_params="welsenc"
+  test_res=${AUTO_TEST_ANDROID_PATH}/../EncoderPerfTestRes
+  report_file=${AUTO_TEST_RES_PATH}/encPerf_${rand}
+fi
+
+for dev in $devices; do
+    dev_info_file=${AUTO_TEST_RES_PATH}/${dev}.log
+    $ADB -s $dev uninstall ${apk_id}
+    $ADB -s $dev install -r ${apk}
+    #TODO: output more info about android device such as name,cpu,memory,and also power comsumption.
+    echo `$ADB -s $dev shell cat /system/build.prop |grep ro.product.model | awk -F"=" '{print $2}'`>${dev_info_file}
+    #push resources
+    $ADB -s $dev push ${test_res} ${test_path}
+    #before start logcat,kill logcat
+    pid=`$ADB -s $dev shell ps | grep logcat | awk '{print $2;}'`
+    [ "#$pid" != "#" ] && $ADB -s $dev shell kill $pid >/dev/null
+    $ADB -s $dev logcat -c
+    $ADB -s $dev logcat |grep ${log_grep_params} >${report_file}_${dev}.log &
+    $ADB -s $dev shell am start -n ${apk_main}
+    # check whetehr the app is finished every 2 sec
+    for (( ; ; )); do
+        $ADB -s $dev shell ps | grep ${apk_id}
+        if [ $? -ne 0 ]; then
+            sleep 2
+            $ADB -s $dev shell ps | grep ${apk_id}
+            [ $? -ne 0 ] && break
+        fi
+        sleep 2
+    done
+
+    # kill logcat
+    pid=`$ADB -s $dev shell ps | grep logcat | awk '{print $2;}'`
+    [ "#$pid" != "#" ] && $ADB -s $dev shell kill $pid >/dev/null
+
+    #delete the res
+    $ADB -s $dev shell rm -rf ${test_path}
+done
+}
+for apk in ${apk_name};do
+   run_apk $apk;
+   if [ $? -ne 0 ]
+   then
+     echo There is something wrong happened when run ${apk_name}
+     exit 1
+   else
+     echo Finished $ENCDEC performance test on android
+     echo The test result is at ./android/report/xxx.log
+     echo xxxxxxxxxxxxxxxAndroid $ENCDEC Endxxxxxxxxxxxxxxxx
+   fi
+done
+
binary files /dev/null b/autotest/performanceTest/ios/fruitstrap differ
binary files /dev/null b/autotest/performanceTest/ios/iFileTransfer differ
--- /dev/null
+++ b/autotest/performanceTest/ios/run_AutoTest_ios.sh
@@ -1,0 +1,147 @@
+#!/bin/bash
+
+##############################################################
+#Build ios test ref app
+
+#set the default configuration
+CODEC_TEST_IOS_ARCH="armv7 armv7s arm64"
+CODEC_TEST_IOS_PLATFORM="iphoneos"
+CODEC_TEST_IOS_DEBUG_RELEASE="Release"
+CODEC_TEST_IOS_REPORT_SUBFOLDER="release"
+
+
+buildXcodeProject()
+{
+ xcodebuild ARCHS="${CODEC_TEST_IOS_ARCH}" VALID_ARCHS="${CODEC_TEST_IOS_ARCH}" ONLY_ACTIVE_ARCH=YES -project $1 -target $2 -configuration $3 -sdk ${CODEC_TEST_IOS_PLATFORM} clean build
+
+if [ $? -eq 0 ]; then
+ echo "build $1 $3 successfully"
+ else
+ echo "build $1 $3  fail"
+ exit 1
+ fi
+}
+
+
+
+iosPerformanceTest()
+{
+
+if [ $# -gt 2 ]; then
+echo "Please use command $0 [enc/dec] [release/debug]"
+exit 1
+fi
+
+for PARAM in $*; do
+ if [ "enc" = "${PARAM}" ]; then
+     CODEC_TEST_XCODE_PROJECT_NAME="${AUTO_TEST_SRC_PATH}/codec/build/iOS/enc/encDemo/encDemo.xcodeproj"
+     CODEC_TEST_IOS_PROJECT_NAME="encDemo"
+     CODEC_TEST_IOS_PROJECT_PATH="${AUTO_TEST_SRC_PATH}/codec/build/iOS/enc/encDemo/build"
+     CODEC_TEST_IOS_APP=${CODEC_TEST_IOS_PROJECT_PATH}/${CODEC_TEST_IOS_DEBUG_RELEASE}-iphoneos/${CODEC_TEST_IOS_PROJECT_NAME}.app
+     CODEC_TEST_IOS_APP_ID="cisco.encDemo"
+     CODEC_TEST_RES=${AUTO_TEST_IOS_PATH}/../EncoderPerfTestRes
+     CODEC_TEST_LOG="encPerf"
+ elif [ "dec" = "${PARAM}" ]; then
+     CODEC_TEST_XCODE_PROJECT_NAME="${AUTO_TEST_SRC_PATH}/codec/build/iOS/dec/demo/demo.xcodeproj/"
+     CODEC_TEST_IOS_PROJECT_NAME="demo"
+     CODEC_TEST_IOS_PROJECT_PATH="${AUTO_TEST_SRC_PATH}/codec/build/iOS/dec/demo/build"
+     CODEC_TEST_IOS_APP=${CODEC_TEST_IOS_PROJECT_PATH}/${CODEC_TEST_IOS_DEBUG_RELEASE}-iphoneos/${CODEC_TEST_IOS_PROJECT_NAME}.app
+     CODEC_TEST_IOS_APP_ID="hf.cisco.demo"
+     CODEC_TEST_RES=${AUTO_TEST_IOS_PATH}/../DecoderPerfTestRes
+     CODEC_TEST_LOG="decPerf"
+ elif [ "release" = "${PARAM}" ]; then
+     CODEC_TEST_IOS_DEBUG_RELEASE="Release"
+     CODEC_TEST_IOS_REPORT_SUBFOLDER="release"
+ elif [ "debug" = "${PARAM}" ]; then
+     CODEC_TEST_IOS_DEBUG_RELEASE="Debug"
+     CODEC_TEST_IOS_REPORT_SUBFOLDER="debug"
+ else
+    echo parameters are illegal!!!, please have a check.
+    exit 1
+ fi
+ done
+
+echo "Codec test will run on ${CODEC_TEST_IOS_PLATFORM} with ${CODEC_TEST_IOS_DEBUG_RELEASE}"
+buildXcodeProject ${CODEC_TEST_XCODE_PROJECT_NAME} ${CODEC_TEST_IOS_PROJECT_NAME} ${CODEC_TEST_IOS_DEBUG_RELEASE} ${CODEC_TEST_IOS_PLATFORM}
+
+
+
+
+##############run on ios devices#########################
+# for real device
+if [ ! -d ${CODEC_TEST_IOS_APP} ] ; then
+echo "${CODEC_TEST_IOS_APP} is not found"
+exit 1
+else
+echo "Find app ${CODEC_TEST_IOS_APP}"
+fi
+
+ #ensure instruments not runing
+echo "Try to kill the runing instruments"
+pids_str=`ps x -o pid,command | grep -v grep | grep "instruments" | awk '{printf "%s,", $1}'`
+instruments_pids="${pids_str//,/ }"
+for pid in ${instruments_pids}; do
+echo "Found instruments ${pid}. Killing..."
+kill -9 ${pid} && wait ${pid} &> /dev/null
+done
+
+
+
+DEVICES=`system_profiler SPUSBDataType | sed -n -e '/iPad/,/Serial/p' -e '/iPhone/,/Serial/p' | grep "Serial Number:" | awk -F ": " '{print $2}'`
+if [ "${DEVICES}#" == "#" ]
+then
+echo "Can not find any connected device! please check device is connected to MAC!"
+exit 1
+else
+rand=`date +%s`
+for DEVICE_ID in ${DEVICES}
+do
+echo "Try to run on device:${DEVICE_ID}"
+
+#uninstall the application from device to remove the last result
+./fruitstrap uninstall --bundle ${CODEC_TEST_IOS_APP_ID} --id ${DEVICE_ID}
+if [ $? -ne 0 ]; then
+echo uninstall application: ${CODEC_TEST_IOS_APP} from device: ${DEVICE_ID} is failed!
+fi
+#install the application
+./fruitstrap install --bundle ${CODEC_TEST_IOS_APP} --id ${DEVICE_ID}
+if [ $? -ne 0 ]; then
+echo install application: ${CODEC_TEST_IOS_APP} to device: ${DEVICE_ID} is failed!
+exit 1
+fi
+
+./iFileTransfer -o copy -id ${DEVICE_ID} -app ${CODEC_TEST_IOS_APP_ID} -from ${CODEC_TEST_RES}
+instruments -w ${DEVICE_ID}  -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate ${CODEC_TEST_IOS_APP} -e UIASCRIPT ./uiascript.js -e UIARRESULTPATH /tmp/
+#copy to report folder
+./iFileTransfer -o download -id ${DEVICE_ID} -app ${CODEC_TEST_IOS_APP_ID} -from /Documents/${CODEC_TEST_LOG}.log -to ${CODEC_TEST_IOS_REPORT_PATH}/${CODEC_TEST_LOG}_${DEVICE_ID}_${rand}.log
+if [ $? -ne 0 ]; then
+echo "download file: ${CODEC_TEST_LOG}.log from ${CODEC_TEST_IOS_APP_ID} is failed!"
+exit 1
+fi
+
+done
+fi
+}
+
+AUTO_TEST_IOS_PATH=`pwd`
+AUTO_TEST_SRC_PATH="../../.."
+CODEC_TEST_IOS_REPORT_PATH="${AUTO_TEST_IOS_PATH}/report"
+if [ ! -d ${CODEC_TEST_IOS_REPORT_PATH} ]
+then
+ mkdir -p ${CODEC_TEST_IOS_REPORT_PATH}
+fi
+
+ENCDEC=$1
+#start to get encoder/decoder performance data,default run the xcode with release
+iosPerformanceTest $ENCDEC release
+
+if [ $? -ne 0 ]; then
+echo "Running $ENCDEC demo to get encoder performance is failed!"
+exit 1
+else
+echo Finished $ENCDEC performance test on ios devices
+echo the test result is generated at ./ios/report/xx.loGbash parsePerfData.sh
+echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxIOS $ENCDEC  Endxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+fi
+#TODO:according to the trace of instruments to do some analysis
+find .\ -name *.trace -exec rm -rf {} \;
--- /dev/null
+++ b/autotest/performanceTest/ios/uiascript.js
@@ -1,0 +1,19 @@
+UIATarget.onAlert = function onAlert(alert){
+
+    UIALogger.logMessage("In Alert!");
+	title = alert.name();
+	if (title && title.indexOf("Microphone") !== -1) {
+		UIALogger.logMessage("Alert with title '" + title + "' encountered!");
+		var buttons = alert.buttons();
+		var buttonCount = buttons.length;
+
+		if (buttonCount > 0) {
+			var acceptButton = buttons[buttonCount - 1];
+			acceptButton.tap(); // last button is accept
+		}
+	return true; //forbid the default cancel processing
+    }
+    return false; //using the default cancel processing
+}
+var target = UIATarget.localTarget();
+target.delay(6000);
--- /dev/null
+++ b/autotest/performanceTest/parsePerfData.sh
@@ -1,0 +1,107 @@
+#!/bin/bash
+
+#usage  runGetPerformanceInfo   ${PerformanceLogFile}
+runGetPerformanceInfo_openh264()
+{
+
+	if [ ! $# -eq 2 ]
+	then
+		echo "not enough parameters!"
+		echo "usage: ${0} [android/ios] ${PerformanceLogFile}"
+		return 1
+	fi
+
+	local PerformanceLogFile=$2
+    local FileName=""
+	local Width=""
+	local Height=""
+	local Frames=""
+	local FPS=""
+	local EncodeTime=""
+    if [ $1 = "android" ]
+    then seperatorNum=3
+    else
+        seperatorNum=2
+    fi
+
+	while read line
+	do
+		if [[ $line =~ "enc yuv file"  ]]
+		then
+            FileName=`echo $line | awk 'BEGIN {FS="enc yuv file"} {print $2}'`
+            FileName=`echo $FileName | awk 'BEGIN {FS=":"} {print $2}'`
+        fi
+        if [[ $line =~ "Width" ]]
+        then
+            Width=`echo $line | awk 'BEGIN {FS=":"} {print $'${seperatorNum}'}'`
+        fi
+        if [[ $line =~ "Height" ]]
+        then
+            Height=`echo $line | awk 'BEGIN {FS=":"} {print $'${seperatorNum}'}'`
+        fi
+        if [[ $line =~ "Frames" ]]
+        then
+            Frames=`echo $line | awk 'BEGIN {FS=":"} {print $'${seperatorNum}'}'`
+        fi
+        if [[ $line =~ "FPS" ]]
+        then
+            FPS=`echo $line | awk 'BEGIN {FS=":"} {print $'${seperatorNum}'}'`
+            FPS=`echo $FPS | awk 'BEGIN {FS="fps"} {print $1}'`
+        echo "${FileName},"${Width}x${Height}",${Frames},${FPS}"
+        fi
+
+        if [[  $line =~ "encode time"  ]]
+		then
+			EncodeTime=`echo $line | awk 'BEGIN {FS=":"} {print $'${seperatorNum}'}'` 	
+		fi
+        if [[ $line =~ "height" ]]
+        then
+            Height=`echo $line | awk 'BEGIN {FS=":"} {print $'${seperatorNum}'}'`
+        fi
+        if [[ $line =~ "H264 source file name" ]]
+        then
+            FileName=`echo $line | awk 'BEGIN {FS=":"} {print $'${seperatorNum}'}'`
+       if [ $1 = "ios" ]
+       then
+            FileName=`echo $FileName | awk -F"DecoderPerfTestRes" '{print $2}'`
+            FileName=`echo $FileName | awk -F"/" '{print $2}'`
+       else
+            FileName=`echo $FileName | awk -F"/" '{print $4}'`
+       fi
+      fi
+
+	done <${PerformanceLogFile}
+
+
+}
+AUTO_TEST_RESULT_PATH="./TestResultCSV/"
+
+
+parseLogToCSV()
+{
+if [ $# -ne 1 ]
+then echo "Please input $0 [android/ios]"
+fi
+if [ $* = "android" ]
+then
+     Result_log_path="./android/report/"
+     suffix=android
+     dos2unix ${Result_log_path}*.*
+else
+Result_log_path="./ios/report/"
+suffix=ios
+fi
+Result_log=`ls ${Result_log_path}`
+
+for log in ${Result_log}
+do
+  PerformFile=`echo $log |awk -F"." '{print $1}'`
+  PerformFile=${PerformFile}_${suffix}.csv
+ #inital perfermance file
+ echo "$log,,,">>${AUTO_TEST_RESULT_PATH}${PerformFile}
+ echo "YUV,Resolution,Encodedframes,FPS">>${AUTO_TEST_RESULT_PATH}${PerformFile}
+  runGetPerformanceInfo_openh264 ${suffix} ${Result_log_path}${log}>>${AUTO_TEST_RESULT_PATH}${PerformFile}
+done
+}
+parseLogToCSV android
+parseLogToCSV ios
--- /dev/null
+++ b/autotest/performanceTest/run_perfTest.sh
@@ -1,0 +1,122 @@
+#!bin/bash
+IOS=1
+ANDROID=1
+ENC=1
+DEC=1
+AUTO_TEST_PATH=`pwd`
+
+#Judge to run the test on which kind of mobile
+if [ $# -eq 0 ];then
+echo Default testing will run on android and ios devices meanwhile
+else
+for params in $*; do
+if [ $params = "ios" ];then
+  echo Running the test just on ios devices
+  ANDROID=0
+elif [ $params = "android" ];then
+  echo Running the test just on android devices
+  IOS=0
+elif [ $params = "enc" ];then
+  echo Running the encoder performance test
+  DEC=0
+elif [ $params = "dec" ];then
+  echo Running the decoder performance test
+  ENC=0
+else
+  echo parameters are illegal!!!, ${0} [ios/android] [enc/dec]
+  exit 1
+fi
+done
+fi
+
+#Prepare encoder resources
+if [ ${ENC} = "1" ]
+then
+if [ ! -d ./EncoderPerTestRes ]
+then
+mkdir -p ./EncoderPerfTestRes
+fi
+if [ "#`ls ./EncoderPerfTestRes`" = "#" ]
+then
+echo put yuv and cfg file into ./EncoderPerfTest folder as
+echo case_720p
+echo case_720p/welsenc.cfg
+echo case_720p/layer2.cfg
+echo case_720p/yuv
+echo case_720p/yuv/xxx1.yuv
+echo case_720p/yuv/xxx2.yuv
+echo case_360p
+echo case_360p/welsenc.cfg
+echo ......
+else
+#Run the encoder performance test
+if [ ${IOS} = "1" ]
+then
+echo xxxxxxxxxxxxxxxxIOS ENC Startxxxxxxxxxxxxxxxxxx
+echo Run the Encoder performance test on ios devices
+cd ./ios
+bash run_AutoTest_ios.sh enc
+cd ${AUTO_TEST_PATH}
+fi
+
+if [ ${ANDROID} = "1" ]
+then
+echo xxxxxxxxxxxxxxAndroid ENC Startxxxxxxxxxxxxxxxxxxxx
+echo Run the Encoder performance test on android devices
+cd ./android
+bash run_AutoTest_android.sh enc
+cd ${AUTO_TEST_PATH}
+fi
+fi
+fi
+
+#Prepare decoder resources
+if [ ${DEC} = "1" ]
+then
+if [ ! -d ./DecoderPerfTestRes ]
+then
+mkdir -p ./DecoderPerfTestRes
+fi
+
+if [ "#`ls ./DecoderPerfTestRes`" = "#" ]
+then
+echo put decoded bitstreams into such folder as
+echo xxx1.264
+echo xxx2.264
+echo ........
+else
+#Run the decoder performance test
+if [ ${IOS} = "1" ]
+then
+echo xxxxxxxxxxxxxxxxIOS DEC Startxxxxxxxxxxxxxxxxxx
+echo Run the Decoder performance test on ios devices
+cd ./ios
+bash run_AutoTest_ios.sh dec
+cd ${AUTO_TEST_PATH}
+fi
+
+if [ ${ANDROID} = "1" ]
+then
+echo xxxxxxxxxxxxxxAndroid DEC Startxxxxxxxxxxxxxxxxxxxx
+echo Run the Decoder performance test on android devices
+cd ./android
+bash run_AutoTest_android.sh dec
+cd ${AUTO_TEST_PATH}
+fi
+fi
+fi
+
+#TODO:NOW just generate csv file to display performance data
+cd ${AUTO_TEST_PATH}
+if [[ "#`ls ./ios/report`" == "#" || "#`ls ./android/report`" == "#" ]]
+then
+echo There is nothing result log generated at ios or android devices
+else
+echo Start to generate test result csv file
+#Test result
+mkdir -p ./TestResultCSV
+bash parsePerfData.sh
+echo The csv file locate ./TestResultCSV/xxx.csv
+fi
+
+
--- a/codec/build/android/dec/src/com/wels/dec/WelsDecTest.java
+++ b/codec/build/android/dec/src/com/wels/dec/WelsDecTest.java
@@ -3,6 +3,7 @@
 import android.app.Activity;
 import android.os.Bundle;
 import android.os.Environment;
+import android.os.Process;
 import android.util.Log;
 
 import android.view.KeyEvent;
@@ -15,103 +16,136 @@
 import java.util.Vector;
 
 public class WelsDecTest extends Activity {
-    /** Called when the activity is first created. */
-    private OnClickListener OnClickEvent;
-    private Button mBtnLoad, mBtnStartSW;
+  /** Called when the activity is first created. */
+  private OnClickListener OnClickEvent;
+  private Button mBtnLoad, mBtnStartSW;
 
-    final String   mStreamPath = "/sdcard/wels-seq/";
-    Vector<String> mStreamFiles = new Vector<String>();
+  final String   mStreamPath = "/sdcard/welsdec/";
+  Vector<String> mStreamFiles = new Vector<String>();
 
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        final TextView  tv = new TextView(this);
-        System.out.println("Here we go ...");
-        Log.i(TAG, "sdcard path:" + Environment.getExternalStorageDirectory().getAbsolutePath());
-        setContentView(R.layout.main);
+  @Override
+  public void onCreate (Bundle savedInstanceState) {
+    super.onCreate (savedInstanceState);
+    final TextView  tv = new TextView (this);
+    System.out.println ("Here we go ...");
+    Log.i (TAG, "sdcard path:" + Environment.getExternalStorageDirectory().getAbsolutePath());
+    setContentView (R.layout.main);
 
-        mBtnLoad = (Button)findViewById(R.id.cfg);
-        mBtnStartSW = (Button)findViewById(R.id.buttonSW);
+    mBtnLoad = (Button)findViewById (R.id.cfg);
+    mBtnStartSW = (Button)findViewById (R.id.buttonSW);
 
-        OnClickEvent = new OnClickListener()
-        {
-            public void onClick(View v)
-            {
-                switch(v.getId())
-                {
-                case R.id.cfg:
-                {
-                    String cfgFile = mStreamPath + "BitStreams.txt";
-                    try {
-                        BufferedReader bufferedReader = new BufferedReader(new FileReader(cfgFile));
-                        String text;
-                        while((text = bufferedReader.readLine()) != null) {
-                            mStreamFiles.add(mStreamPath + text);
-                            Log.i(TAG, mStreamPath + text);
-                        }
-                        bufferedReader.close();
-                    } catch(IOException e) {
-                        Log.e("WELS_DEC", e.getMessage());
-                    }
-                }
-                break;
-                case R.id.buttonSW:
-                {
-                    System.out.println("decode sequence number = " + mStreamFiles.size());
-                    Log.i("WSE_DEC","after click");
-                    try {
-                        for (int k=0; k < mStreamFiles.size(); k++) {
-                            String inFile =  mStreamFiles.get(k);
-                            String outFile =  mStreamFiles.get(k) + ".yuv";
-                            Log.i(TAG, "input file:" + inFile+ "    output file:" + outFile);
-                            DoDecoderTest(inFile, outFile);
-                        }
-                    } catch (Exception e) {
-                        Log.e(TAG, e.getMessage());
-                    }
-                    mStreamFiles.clear();
-                    tv.setText( "Decoder is completed!" );
-                }
-                break;
-                }
+    OnClickEvent = new OnClickListener() {
+      public void onClick (View v) {
+        switch (v.getId()) {
+        case R.id.cfg: {
+          String cfgFile = mStreamPath + "BitStreams.txt";
+          try {
+            BufferedReader bufferedReader = new BufferedReader (new FileReader (cfgFile));
+            String text;
+            while ((text = bufferedReader.readLine()) != null) {
+              mStreamFiles.add (mStreamPath + text);
+              Log.i (TAG, mStreamPath + text);
+            }
+            bufferedReader.close();
+          } catch (IOException e) {
+            Log.e ("WELS_DEC", e.getMessage());
+          }
+        }
+        break;
+        case R.id.buttonSW: {
+          System.out.println ("decode sequence number = " + mStreamFiles.size());
+          Log.i ("WSE_DEC", "after click");
+          try {
+            for (int k = 0; k < mStreamFiles.size(); k++) {
+              String inFile =  mStreamFiles.get (k);
+              String outFile =  mStreamFiles.get (k) + ".yuv";
+              Log.i (TAG, "input file:" + inFile + "    output file:" + outFile);
+              DoDecoderTest (inFile, outFile);
             }
-        };
+          } catch (Exception e) {
+            Log.e (TAG, e.getMessage());
+          }
+          mStreamFiles.clear();
+          tv.setText ("Decoder is completed!");
+        }
+        break;
+        }
+      }
+    };
 
-        mBtnLoad.setOnClickListener(OnClickEvent);
-        mBtnStartSW.setOnClickListener(OnClickEvent);
+    mBtnLoad.setOnClickListener (OnClickEvent);
+    mBtnStartSW.setOnClickListener (OnClickEvent);
 
-        System.out.println("Done!");
-    }
+    System.out.println ("Done!");
+    //if you want to run the demo manually, just comment following 2 lines
+    runAutoDec();
+  }
+  public void runAutoDec() {
+    Thread thread = new Thread() {
 
-    @Override
-    public void onStart()
-    {
-        Log.i("WSE_DEC","welsdecdemo onStart");
-        super.onStart();
-    }
+      public void run() {
+        Log.i (TAG, "decoder performance test begin");
 
-    @Override
-    public boolean onKeyDown(int keyCode, KeyEvent event) {
-        switch (keyCode) {
-        case KeyEvent.KEYCODE_BACK:
-            return true;
-        default:
-            return super.onKeyDown(keyCode, event);
+        File bitstreams = new File (mStreamPath);
+        String[] list = bitstreams.list();
+        if (list == null || list.length == 0) {
+          Log.i (TAG, "have not find any coder resourse");
+          finish();
         }
-    }
+        for (int i = 0; i < list.length; i++) {
 
-    public native void  DoDecoderTest(String infilename, String outfilename);
-    private static final String TAG = "welsdec";
-    static {
-        try {
-            System.loadLibrary("openh264");
-            System.loadLibrary("stlport_shared");
-            System.loadLibrary("welsdecdemo");
-            Log.v(TAG, "Load libwelsdec successful");
+          String inFile = list[i];
+          inFile = mStreamPath + inFile;
+          String outFile = inFile + ".yuv";
+          DoDecoderTest (inFile, outFile);
+
+
         }
-        catch(Exception e) {
-            Log.e(TAG, "Failed to load welsdec"+e.getMessage());
-        }
+        Log.i (TAG, "decoder performance test finish");
+        finish();
+      }
+
+    };
+    thread.start();
+
+  }
+
+  @Override
+  public void onStart() {
+    Log.i ("WSE_DEC", "welsdecdemo onStart");
+    super.onStart();
+  }
+  @Override
+  public void onDestroy() {
+    super.onDestroy();
+
+    Log.i (TAG, "OnDestroy");
+
+    Process.killProcess (Process.myPid());
+
+  }
+
+  @Override
+  public boolean onKeyDown (int keyCode, KeyEvent event) {
+    switch (keyCode) {
+    case KeyEvent.KEYCODE_BACK:
+      return true;
+    default:
+      return super.onKeyDown (keyCode, event);
     }
+  }
+
+  public native void  DoDecoderTest (String infilename, String outfilename);
+  private static final String TAG = "welsdec";
+  static {
+    try {
+      System.loadLibrary ("openh264");
+      System.loadLibrary ("stlport_shared");
+      System.loadLibrary ("welsdecdemo");
+      Log.v (TAG, "Load libwelsdec successful");
+    } catch (Exception e) {
+      Log.e (TAG, "Failed to load welsdec" + e.getMessage());
+    }
+  }
 }
 
--- a/codec/build/android/enc/jni/myjni.cpp
+++ b/codec/build/android/enc/jni/myjni.cpp
@@ -8,6 +8,25 @@
 
 extern "C" int EncMain (int argc, char* argv[]);
 extern "C"
+JNIEXPORT void JNICALL Java_com_wels_enc_WelsEncTest_DoEncoderAutoTest
+(JNIEnv* env, jobject thiz, jstring jsIncfgName, jstring jsInlayerName, jstring jsInyuvName, jstring jsOutbitName) {
+  /**************** Add the native codes/API *****************/
+  const char* argv[]={
+	(char*)("encConsole.exe"),
+	(char*) ((*env).GetStringUTFChars (jsIncfgName, NULL)),
+	(char*)("-org"),
+	(char*) ((*env).GetStringUTFChars (jsInyuvName, NULL)),
+	(char*)("-bf"),
+	(char*) ((*env).GetStringUTFChars (jsOutbitName, NULL)),
+	(char*)("-numl"),
+	(char*)("1"),
+	(char*) ((*env).GetStringUTFChars (jsInlayerName, NULL))
+  };
+  LOGI ("Start to run JNI module!+++");
+  EncMain(sizeof(argv)/sizeof(argv[0]),(char**)&argv[0]);
+  LOGI ("End to run JNI module!+++");
+}
+
 JNIEXPORT void JNICALL Java_com_wels_enc_WelsEncTest_DoEncoderTest
 (JNIEnv* env, jobject thiz, jstring jsFileNameIn) {
   /**************** Add the native codes/API *****************/
--- a/codec/build/android/enc/src/com/wels/enc/WelsEncTest.java
+++ b/codec/build/android/enc/src/com/wels/enc/WelsEncTest.java
@@ -3,6 +3,7 @@
 import android.app.Activity;
 import android.os.Bundle;
 import android.os.Environment;
+import android.os.Process;
 import android.util.Log;
 
 import android.view.KeyEvent;
@@ -15,104 +16,158 @@
 import java.util.Vector;
 
 public class WelsEncTest extends Activity {
-    /** Called when the activity is first created. */
-    private OnClickListener OnClickEvent;
-    private Button mBtnLoad, mBtnStartSW;
+  /** Called when the activity is first created. */
+  private OnClickListener OnClickEvent;
+  private Button mBtnLoad, mBtnStartSW;
 
-    final String   mStreamPath = "/sdcard/wels-seq/";
-    Vector<String> mCfgFiles = new Vector<String>();
+  final String   mStreamPath = "/sdcard/welsenc/";
+  Vector<String> mCfgFiles = new Vector<String>();
 
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        final TextView  tv = new TextView(this);
-        System.out.println("Here we go ...");
-        Log.i(TAG, "sdcard path:" + Environment.getExternalStorageDirectory().getAbsolutePath());
-        setContentView(R.layout.main);
+  @Override
+  public void onCreate (Bundle savedInstanceState) {
+    super.onCreate (savedInstanceState);
+    final TextView  tv = new TextView (this);
+    System.out.println ("Here we go ...");
+    Log.i (TAG, "sdcard path:" + Environment.getExternalStorageDirectory().getAbsolutePath());
+    setContentView (R.layout.main);
 
-        mBtnLoad = (Button)findViewById(R.id.cfg);
-        mBtnStartSW = (Button)findViewById(R.id.buttonSW);
+    mBtnLoad = (Button)findViewById (R.id.cfg);
+    mBtnStartSW = (Button)findViewById (R.id.buttonSW);
 
 
-        OnClickEvent = new OnClickListener()
-        {
-            public void onClick(View v)
-            {
-                switch(v.getId())
-                {
-                case R.id.cfg:
-                {
-                    String cfgFile = mStreamPath + "cfgs.txt";
-                    try {
-                        BufferedReader bufferedReader = new BufferedReader(new FileReader(cfgFile));
-                        String text;
-                        while((text = bufferedReader.readLine()) != null) {
-                            mCfgFiles.add(mStreamPath + text);
-                            Log.i(TAG, mStreamPath + text);
-                        }
-                        bufferedReader.close();
-                    } catch(IOException e) {
-                        Log.e(TAG, e.getMessage());
-                    }
-                }
-                break;
-                case R.id.buttonSW:
-                {
-                    System.out.println("decode sequence number = " + mCfgFiles.size());
-                    Log.i(TAG,"after click");
-                    try {
-                        for (int k=0; k < mCfgFiles.size(); k++) {
-                            String cfgFile =  mCfgFiles.get(k);
-                            DoEncoderTest(cfgFile);
-                        }
-                    } catch (Exception e) {
-                        Log.e(TAG, e.getMessage());
-                    }
-                    mCfgFiles.clear();
-                    tv.setText( "Decoder is completed!" );
-                }
-                break;
-                }
+    OnClickEvent = new OnClickListener() {
+      public void onClick (View v) {
+        switch (v.getId()) {
+        case R.id.cfg: {
+          String cfgFile = mStreamPath + "cfgs.txt";
+          try {
+            BufferedReader bufferedReader = new BufferedReader (new FileReader (cfgFile));
+            String text;
+            while ((text = bufferedReader.readLine()) != null) {
+              mCfgFiles.add (mStreamPath + text);
+              Log.i (TAG, mStreamPath + text);
+            }
+            bufferedReader.close();
+          } catch (IOException e) {
+            Log.e (TAG, e.getMessage());
+          }
+        }
+        break;
+        case R.id.buttonSW: {
+          System.out.println ("encode sequence number = " + mCfgFiles.size());
+          Log.i (TAG, "after click");
+          try {
+            for (int k = 0; k < mCfgFiles.size(); k++) {
+              String cfgFile =  mCfgFiles.get (k);
+              DoEncoderTest (cfgFile);
             }
-        };
+          } catch (Exception e) {
+            Log.e (TAG, e.getMessage());
+          }
+          mCfgFiles.clear();
+          tv.setText ("Encoder is completed!");
+        }
+        break;
+        }
+      }
+    };
 
-        mBtnLoad.setOnClickListener(OnClickEvent);
-        mBtnStartSW.setOnClickListener(OnClickEvent);
+    mBtnLoad.setOnClickListener (OnClickEvent);
+    mBtnStartSW.setOnClickListener (OnClickEvent);
 
-        System.out.println("Done!");
-    }
+    System.out.println ("Done!");
+    //run the test automatically,if you not want to autotest, just comment this line
+    runAutoEnc();
+  }
 
-    @Override
-    public void onStart()
-    {
-        Log.i(TAG,"welsdecdemo onStart");
-        super.onStart();
-    }
+  public void runAutoEnc() {
+    Thread thread = new Thread() {
 
+      public void run() {
+        Log.i (TAG, "encoder performance test begin");
+        String inYuvfile = null, outBitfile = null, inOrgfile = null, inLayerfile = null;
+        File encCase = new File (mStreamPath);
+        String[] caseNum = encCase.list();
+        if (caseNum == null || caseNum.length == 0) {
+          Log.i (TAG, "have not find any encoder resourse");
+          finish();
+        }
 
-    @Override
-    public boolean onKeyDown(int keyCode, KeyEvent event) {
-        switch (keyCode) {
-        case KeyEvent.KEYCODE_BACK:
-            return true;
-        default:
-            return super.onKeyDown(keyCode, event);
+        for (int i = 0; i < caseNum.length; i++) {
+          String[] yuvName = null;
+          File yuvPath = null;
+          File encCaseNo = new File (mStreamPath + caseNum[i]);
+          String[] encFile = encCaseNo.list();
+
+          for (int k = 0; k < encFile.length; k++) {
+            if (encFile[k].compareToIgnoreCase ("welsenc.cfg") == 0)
+
+              inOrgfile = encCaseNo + File.separator + encFile[k];
+
+            else if (encFile[k].compareToIgnoreCase ("layer2.cfg") == 0)
+              inLayerfile = encCaseNo + File.separator + encFile[k];
+            else if (encFile[k].compareToIgnoreCase ("yuv") == 0) {
+              yuvPath = new File (encCaseNo + File.separator + encFile[k]);
+              yuvName = yuvPath.list();
+            }
+          }
+          for (int m = 0; m < yuvName.length; m++) {
+            inYuvfile = yuvPath + File.separator + yuvName[m];
+            outBitfile = inYuvfile + ".264";
+            Log.i (TAG, "enc yuv file:" + yuvName[m]);
+            DoEncoderAutoTest (inOrgfile, inLayerfile, inYuvfile, outBitfile);
+          }
         }
+
+        Log.i (TAG, "encoder performance test finish");
+        finish();
+      }
+
+    };
+    thread.start();
+
+  }
+
+  @Override
+  public void onStart() {
+    Log.i (TAG, "welsencdemo onStart");
+    super.onStart();
+  }
+
+  @Override
+  public void onDestroy() {
+    super.onDestroy();
+
+    Log.i (TAG, "OnDestroy");
+
+    Process.killProcess (Process.myPid());
+
+  }
+
+  @Override
+  public boolean onKeyDown (int keyCode, KeyEvent event) {
+    switch (keyCode) {
+    case KeyEvent.KEYCODE_BACK:
+      return true;
+    default:
+      return super.onKeyDown (keyCode, event);
     }
+  }
 
-    public native void  DoEncoderTest(String cfgFileName);
-    private static final String TAG = "welsenc";
-    static {
-        try {
-            System.loadLibrary("openh264");
-            System.loadLibrary("stlport_shared");
-            System.loadLibrary("welsencdemo");
-            Log.v(TAG, "Load libwelsencdemo.so successful");
-        }
-        catch(Exception e) {
-            Log.e(TAG, "Failed to load welsdec"+e.getMessage());
-        }
+  public native void  DoEncoderTest (String cfgFileName);
+  public native void  DoEncoderAutoTest (String cfgFileName, String layerFileName, String yuvFileName,
+                                         String outBitsName);
+  private static final String TAG = "welsenc";
+  static {
+    try {
+      System.loadLibrary ("openh264");
+      System.loadLibrary ("stlport_shared");
+      System.loadLibrary ("welsencdemo");
+      Log.v (TAG, "Load libwelsencdemo.so successful");
+    } catch (Exception e) {
+      Log.e (TAG, "Failed to load welsenc" + e.getMessage());
     }
+  }
 
 }
 
--- a/codec/build/iOS/dec/demo/demo.xcodeproj/project.pbxproj
+++ b/codec/build/iOS/dec/demo/demo.xcodeproj/project.pbxproj
@@ -53,7 +53,7 @@
 		F0E6634D1810EFA5000C888E /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
 		F0E663511810EFA5000C888E /* demo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "demo-Info.plist"; sourceTree = "<group>"; };
 		F0E663531810EFA5000C888E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
-		F0E663551810EFA5000C888E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+		F0E663551810EFA5000C888E /* main.m */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; path = main.m; sourceTree = "<group>"; };
 		F0E663581810EFA5000C888E /* DEMOAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DEMOAppDelegate.h; sourceTree = "<group>"; };
 		F0E663591810EFA5000C888E /* DEMOAppDelegate.m */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp.preprocessed; path = DEMOAppDelegate.m; sourceTree = "<group>"; };
 		F0E6635B1810EFA5000C888E /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
--- a/codec/build/iOS/dec/demo/demo/main.m
+++ b/codec/build/iOS/dec/demo/demo/main.m
@@ -34,9 +34,90 @@
 
 #import "DEMOAppDelegate.h"
 
-int main(int argc, char *argv[])
-{
-    @autoreleasepool {
-        return UIApplicationMain(argc, argv, nil, NSStringFromClass([DEMOAppDelegate class]));
+extern int DecMain (int argc, char* argv[]);
+
+//redirect NSLog and stdout to logfile
+void redirectLogToDocumentFile() {
+  NSArray* path = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
+  NSString* document = [path objectAtIndex:0];
+  NSString* fileName = [NSString stringWithFormat:@"decPerf.log"];
+  NSString* logPath = [document stringByAppendingPathComponent:fileName];
+
+  NSFileManager* defaultManager = [NSFileManager defaultManager];
+  [defaultManager removeItemAtPath:logPath error:nil];
+
+  freopen ([logPath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout);
+  freopen ([logPath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr);
+}
+
+
+//run auto test to get encoder performance
+int AutoTestDec() {
+
+
+  NSString* document = [[NSString alloc] init];
+  NSArray* paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
+  if ([paths count] == 0) {
+    NSLog (@"could not find document path");
+    return 2;
+  }
+  document = [paths objectAtIndex:0];
+
+
+  NSString* decFilePath = [document stringByAppendingString:@"/DecoderPerfTestRes"];
+  NSFileManager* manage = [NSFileManager defaultManager];
+
+  NSString* outYuvPath = [decFilePath stringByAppendingString:@"/yuv"];
+  [manage removeItemAtPath:outYuvPath error:nil];
+  [manage createDirectoryAtPath:outYuvPath withIntermediateDirectories:YES attributes:nil error: nil];
+
+
+  NSArray* bitstreams = [manage subpathsAtPath:decFilePath];
+  if (bitstreams == nil) {
+    NSLog (@"could not find any bitstream under decoderperfpath");
+    return 1;
+  }
+
+  redirectLogToDocumentFile(); //output to console, just comment this line
+
+  for (int caseNO = 0; caseNO < [bitstreams count]; caseNO++) {
+
+    NSString* caseName = [bitstreams objectAtIndex:caseNO];
+    if ([caseName  isEqual: @"yuv"]) {
+      break;
     }
+    NSString* bitstream = [decFilePath stringByAppendingString:@"/"];
+    bitstream = [bitstream stringByAppendingString:caseName];
+    NSString* yuvFileName = [caseName stringByAppendingString:@".yuv"];
+    NSString* tmpyuvFileName = [outYuvPath stringByAppendingString:@"/"];
+    yuvFileName = [tmpyuvFileName stringByAppendingString:yuvFileName];
+
+    [manage createFileAtPath:yuvFileName contents:nil attributes:nil];
+
+    const char* argvv[] = {
+      "decConsole.exe",
+      [bitstream UTF8String],
+      [yuvFileName UTF8String]
+    };
+    DecMain (sizeof (argvv) / sizeof (argvv[0]), (char**)&argvv[0]);
+    fflush (stdout); // flush the content of stdout instantly
+  }
+
+
+  return 0;
+}
+
+int main (int argc, char* argv[]) {
+  //***For auto testing of decoder performance, call auto test here, if you not want to do auto test, you can comment it manualy
+
+  if (AutoTestDec() == 0)
+    NSLog (@"Auto testing running sucessfully");
+  else
+    NSLog (@"Auto testing running failed");
+  abort();
+  //********
+
+  @autoreleasepool {
+    return UIApplicationMain (argc, argv, nil, NSStringFromClass ([DEMOAppDelegate class]));
+  }
 }
--- a/codec/build/iOS/enc/encDemo/encDemo/main.m
+++ b/codec/build/iOS/enc/encDemo/encDemo/main.m
@@ -35,9 +35,139 @@
 
 #import "AppDelegate.h"
 
-int main(int argc, char * argv[])
-{
-    @autoreleasepool {
-        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
+extern int EncMain (int argc, char** argv);
+
+//redirect NSLog and stdout to logfile
+void redirectLogToDocumentFile() {
+  NSArray* path = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
+  NSString* document = [path objectAtIndex:0];
+  NSString* fileName = [NSString stringWithFormat:@"encPerf.log"];
+  NSString* logPath = [document stringByAppendingPathComponent:fileName];
+
+  NSFileManager* defaultManager = [NSFileManager defaultManager];
+  [defaultManager removeItemAtPath:logPath error:nil];
+
+  freopen ([logPath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout);
+  freopen ([logPath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr);
+}
+
+//to judge whether the path is needed case path
+bool IsOneDeptDir (NSString* path) {
+  BOOL isDir = NO;
+  BOOL isOneDeptDir = NO;
+  NSFileManager* fileManager = [NSFileManager defaultManager];
+  NSArray* dirPathArray = [fileManager subpathsAtPath:path];
+  if ([dirPathArray count] == 0 || dirPathArray == nil)
+    isOneDeptDir = NO;
+  else {
+    for (NSString * dirPath in dirPathArray) {
+      NSString* tmpPath = [path stringByAppendingString:@"/"];
+      tmpPath = [tmpPath stringByAppendingString:dirPath];
+      [fileManager fileExistsAtPath:tmpPath isDirectory:&isDir];
+      if (isDir) {
+        isOneDeptDir = YES;
+        break;
+      }
     }
+  }
+  return isOneDeptDir;
+}
+
+//run auto test to get encoder performance
+int AutoTestEnc() {
+  NSString* document = [[NSString alloc] init];
+  NSArray* paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
+  if ([paths count] == 0) {
+    NSLog (@"could not find document path");
+    return 2;
+  }
+  document = [paths objectAtIndex:0];
+
+  NSString* encFilePath = [document stringByAppendingString:@"/EncoderPerfTestRes"];
+  NSFileManager* manage = [NSFileManager defaultManager];
+
+  NSArray* cases = [manage subpathsAtPath:encFilePath];
+  if (cases == nil) {
+    NSLog (@"could not find any test case under encoderperftest");
+    return 1;
+
+  }
+  redirectLogToDocumentFile();
+  NSMutableArray* dirArray = [[NSMutableArray alloc] init];
+  for (NSString * casePath in cases) {
+
+    NSString* path = [encFilePath stringByAppendingPathComponent:casePath];
+    if (IsOneDeptDir (path)) {
+      [dirArray addObject:casePath];
+    }
+
+  }
+  for (int caseNO = 0; caseNO < [dirArray count]; caseNO++) {
+
+    NSString* caseName = [dirArray objectAtIndex:caseNO];
+    NSString* caseFilePath = [encFilePath stringByAppendingString:@"/"];
+    caseFilePath = [caseFilePath stringByAppendingString:caseName];
+    [manage changeCurrentDirectoryPath:[caseFilePath stringByExpandingTildeInPath]];
+
+    NSString* welscfg = [caseFilePath stringByAppendingString:@"/welsenc.cfg"];
+    NSString* layercfg = [caseFilePath stringByAppendingString:@"/layer2.cfg"];
+    NSString* yuvFilePath = [caseFilePath stringByAppendingString:@"/yuv"];
+    NSString* bitFilePath = [caseFilePath stringByAppendingString:@"/bit"];
+    [manage removeItemAtPath:bitFilePath error:nil];
+    [manage createDirectoryAtPath:bitFilePath withIntermediateDirectories:YES attributes:nil error:nil];
+
+
+    NSArray* files = [manage subpathsAtPath:yuvFilePath];
+
+    [manage changeCurrentDirectoryPath:[bitFilePath stringByExpandingTildeInPath]];
+
+    for (int i = 0; i < [files count]; i++) {
+      NSString* yuvFileName = [files objectAtIndex:i];
+      NSString* bitFileName = [yuvFileName stringByAppendingString:@".264"];
+
+      NSString*  bitFileNamePath = [bitFilePath stringByAppendingString:@"/"];
+      bitFileName = [bitFileNamePath stringByAppendingString:bitFileName];
+
+
+      [manage createFileAtPath:bitFileName contents:nil attributes:nil];
+      [manage changeCurrentDirectoryPath:[yuvFilePath stringByExpandingTildeInPath]];
+      const char* argvv[] = {
+        "dummy",
+        [welscfg UTF8String],
+        "-org",
+        [yuvFileName UTF8String],
+        "-bf",
+        [bitFileName UTF8String],
+        "-numl",
+        "1",
+        [layercfg UTF8String]
+      };
+
+      NSLog (@"WELS_INFO: enc config file: %@", welscfg);
+      NSLog (@"WELS_INFO: enc yuv file: %@", yuvFileName);
+      EncMain (sizeof (argvv) / sizeof (argvv[0]), (char**)&argvv[0]);
+      fflush (stdout); // flush the content of stdout instantly
+    }
+
+  }
+
+
+  return 0;
+}
+
+
+int main (int argc, char* argv[]) {
+
+
+  //***For auto testing of encoder performance, call auto test here, if you not want to do auto test, you can comment it manualy
+
+  if (AutoTestEnc() == 0)
+    NSLog (@"Auto testing running sucessfully");
+  else
+    NSLog (@"Auto testing running failed");
+  abort();
+  //************************
+  @autoreleasepool {
+    return UIApplicationMain (argc, argv, nil, NSStringFromClass ([AppDelegate class]));
+  }
 }