• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.wels.enc;
2 
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.os.Environment;
6 import android.os.Process;
7 import android.util.Log;
8 
9 import android.view.KeyEvent;
10 import android.view.View;
11 import android.view.View.OnClickListener;
12 
13 import android.widget.Button;
14 import android.widget.TextView;
15 import java.io.*;
16 import java.util.Vector;
17 
18 public class WelsEncTest extends Activity {
19   /** Called when the activity is first created. */
20   private OnClickListener OnClickEvent;
21   private Button mBtnLoad, mBtnStartSW;
22 
23   final String   mStreamPath = "/sdcard/welsenc/";
24   Vector<String> mCfgFiles = new Vector<String>();
25 
26   @Override
onCreate(Bundle savedInstanceState)27   public void onCreate (Bundle savedInstanceState) {
28     super.onCreate (savedInstanceState);
29     final TextView  tv = new TextView (this);
30     System.out.println ("Here we go ...");
31     Log.i (TAG, "sdcard path:" + Environment.getExternalStorageDirectory().getAbsolutePath());
32     setContentView (R.layout.main);
33 
34     mBtnLoad = (Button)findViewById (R.id.cfg);
35     mBtnStartSW = (Button)findViewById (R.id.buttonSW);
36 
37 
38     OnClickEvent = new OnClickListener() {
39       public void onClick (View v) {
40         switch (v.getId()) {
41         case R.id.cfg: {
42           String cfgFile = mStreamPath + "cfgs.txt";
43           try {
44             BufferedReader bufferedReader = new BufferedReader (new FileReader (cfgFile));
45             String text;
46             while ((text = bufferedReader.readLine()) != null) {
47               mCfgFiles.add (mStreamPath + text);
48               Log.i (TAG, mStreamPath + text);
49             }
50             bufferedReader.close();
51           } catch (IOException e) {
52             Log.e (TAG, e.getMessage());
53           }
54         }
55         break;
56         case R.id.buttonSW: {
57           System.out.println ("encode sequence number = " + mCfgFiles.size());
58           Log.i (TAG, "after click");
59           try {
60             for (int k = 0; k < mCfgFiles.size(); k++) {
61               String cfgFile =  mCfgFiles.get (k);
62               DoEncoderTest (cfgFile);
63             }
64           } catch (Exception e) {
65             Log.e (TAG, e.getMessage());
66           }
67           mCfgFiles.clear();
68           tv.setText ("Encoder is completed!");
69         }
70         break;
71         }
72       }
73     };
74 
75     mBtnLoad.setOnClickListener (OnClickEvent);
76     mBtnStartSW.setOnClickListener (OnClickEvent);
77 
78     System.out.println ("Done!");
79     //run the test automatically,if you not want to autotest, just comment this line
80     runAutoEnc();
81   }
82 
runAutoEnc()83   public void runAutoEnc() {
84     Thread thread = new Thread() {
85 
86       public void run() {
87         Log.i (TAG, "encoder performance test begin");
88         String inYuvfile = null, outBitfile = null, inOrgfile = null, inLayerfile = null;
89         File encCase = new File (mStreamPath);
90         String[] caseNum = encCase.list();
91         if (caseNum == null || caseNum.length == 0) {
92           Log.i (TAG, "have not find any encoder resourse");
93           finish();
94         }
95 
96         for (int i = 0; i < caseNum.length; i++) {
97           String[] yuvName = null;
98           File yuvPath = null;
99           File encCaseNo = new File (mStreamPath + caseNum[i]);
100           String[] encFile = encCaseNo.list();
101 
102           for (int k = 0; k < encFile.length; k++) {
103             if (encFile[k].compareToIgnoreCase ("welsenc.cfg") == 0)
104 
105               inOrgfile = encCaseNo + File.separator + encFile[k];
106 
107             else if (encFile[k].compareToIgnoreCase ("layer2.cfg") == 0)
108               inLayerfile = encCaseNo + File.separator + encFile[k];
109             else if (encFile[k].compareToIgnoreCase ("yuv") == 0) {
110               yuvPath = new File (encCaseNo + File.separator + encFile[k]);
111               yuvName = yuvPath.list();
112             }
113           }
114           for (int m = 0; m < yuvName.length; m++) {
115             inYuvfile = yuvPath + File.separator + yuvName[m];
116             outBitfile = inYuvfile + ".264";
117             Log.i (TAG, "enc yuv file:" + yuvName[m]);
118             DoEncoderAutoTest (inOrgfile, inLayerfile, inYuvfile, outBitfile);
119           }
120         }
121 
122         Log.i (TAG, "encoder performance test finish");
123         finish();
124       }
125 
126     };
127     thread.start();
128 
129   }
130 
131   @Override
onStart()132   public void onStart() {
133     Log.i (TAG, "welsencdemo onStart");
134     super.onStart();
135   }
136 
137   @Override
onDestroy()138   public void onDestroy() {
139     super.onDestroy();
140 
141     Log.i (TAG, "OnDestroy");
142 
143     Process.killProcess (Process.myPid());
144 
145   }
146 
147   @Override
onKeyDown(int keyCode, KeyEvent event)148   public boolean onKeyDown (int keyCode, KeyEvent event) {
149     switch (keyCode) {
150     case KeyEvent.KEYCODE_BACK:
151       return true;
152     default:
153       return super.onKeyDown (keyCode, event);
154     }
155   }
156 
DoEncoderTest(String cfgFileName)157   public native void  DoEncoderTest (String cfgFileName);
DoEncoderAutoTest(String cfgFileName, String layerFileName, String yuvFileName, String outBitsName)158   public native void  DoEncoderAutoTest (String cfgFileName, String layerFileName, String yuvFileName,
159                                          String outBitsName);
160   private static final String TAG = "welsenc";
161   static {
162     try {
163       System.loadLibrary ("openh264");
164       System.loadLibrary ("stlport_shared");
165       System.loadLibrary ("welsencdemo");
Log.v(TAG, "Load libwelsencdemo.so successful")166       Log.v (TAG, "Load libwelsencdemo.so successful");
167     } catch (Exception e) {
168       Log.e (TAG, "Failed to load welsenc" + e.getMessage());
169     }
170   }
171 
172 }
173 
174