1 package com.wels.dec; 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 WelsDecTest 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/welsdec/"; 24 Vector<String> mStreamFiles = 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 OnClickEvent = new OnClickListener() { 38 public void onClick (View v) { 39 switch (v.getId()) { 40 case R.id.cfg: { 41 String cfgFile = mStreamPath + "BitStreams.txt"; 42 try { 43 BufferedReader bufferedReader = new BufferedReader (new FileReader (cfgFile)); 44 String text; 45 while ((text = bufferedReader.readLine()) != null) { 46 mStreamFiles.add (mStreamPath + text); 47 Log.i (TAG, mStreamPath + text); 48 } 49 bufferedReader.close(); 50 } catch (IOException e) { 51 Log.e ("WELS_DEC", e.getMessage()); 52 } 53 } 54 break; 55 case R.id.buttonSW: { 56 System.out.println ("decode sequence number = " + mStreamFiles.size()); 57 Log.i ("WSE_DEC", "after click"); 58 try { 59 for (int k = 0; k < mStreamFiles.size(); k++) { 60 String inFile = mStreamFiles.get (k); 61 String outFile = mStreamFiles.get (k) + ".yuv"; 62 Log.i (TAG, "input file:" + inFile + " output file:" + outFile); 63 DoDecoderTest (inFile, outFile); 64 } 65 } catch (Exception e) { 66 Log.e (TAG, e.getMessage()); 67 } 68 mStreamFiles.clear(); 69 tv.setText ("Decoder is completed!"); 70 } 71 break; 72 } 73 } 74 }; 75 76 mBtnLoad.setOnClickListener (OnClickEvent); 77 mBtnStartSW.setOnClickListener (OnClickEvent); 78 79 System.out.println ("Done!"); 80 //if you want to run the demo manually, just comment following 2 lines 81 runAutoDec(); 82 } runAutoDec()83 public void runAutoDec() { 84 Thread thread = new Thread() { 85 86 public void run() { 87 Log.i (TAG, "decoder performance test begin"); 88 89 File bitstreams = new File (mStreamPath); 90 String[] list = bitstreams.list(); 91 if (list == null || list.length == 0) { 92 Log.i (TAG, "have not find any coder resourse"); 93 finish(); 94 } 95 for (int i = 0; i < list.length; i++) { 96 97 String inFile = list[i]; 98 inFile = mStreamPath + inFile; 99 String outFile = inFile + ".yuv"; 100 DoDecoderTest (inFile, outFile); 101 102 103 } 104 Log.i (TAG, "decoder performance test finish"); 105 finish(); 106 } 107 108 }; 109 thread.start(); 110 111 } 112 113 @Override onStart()114 public void onStart() { 115 Log.i ("WSE_DEC", "welsdecdemo onStart"); 116 super.onStart(); 117 } 118 @Override onDestroy()119 public void onDestroy() { 120 super.onDestroy(); 121 122 Log.i (TAG, "OnDestroy"); 123 124 Process.killProcess (Process.myPid()); 125 126 } 127 128 @Override onKeyDown(int keyCode, KeyEvent event)129 public boolean onKeyDown (int keyCode, KeyEvent event) { 130 switch (keyCode) { 131 case KeyEvent.KEYCODE_BACK: 132 return true; 133 default: 134 return super.onKeyDown (keyCode, event); 135 } 136 } 137 DoDecoderTest(String infilename, String outfilename)138 public native void DoDecoderTest (String infilename, String outfilename); 139 private static final String TAG = "welsdec"; 140 static { 141 try { 142 System.loadLibrary ("openh264"); 143 System.loadLibrary ("stlport_shared"); 144 System.loadLibrary ("welsdecdemo"); Log.v(TAG, "Load libwelsdec successful")145 Log.v (TAG, "Load libwelsdec successful"); 146 } catch (Exception e) { 147 Log.e (TAG, "Failed to load welsdec" + e.getMessage()); 148 } 149 } 150 } 151 152