Permalink
Browse files

latest modifications before refactoring into new projects.

  • Loading branch information...
Ricky Ng-Adam
Ricky Ng-Adam committed Jul 9, 2011
1 parent 06843b4 commit 541572cb514187b5a5aeec129b24b389c7a2385f
@@ -10,7 +10,8 @@
<service android:name="VideoStreamingReceiverService">
</service>
<activity android:name="ClientActivity"
- android:label="@string/app_name">
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
android:layout_height="fill_parent"
- android:layout_width="match_parent">
+ android:layout_width="match_parent" android:orientation="vertical">
+ <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/textViewStatus" android:text="TextView"></TextView>
<ImageView android:id="@+id/imageView1" android:layout_height="match_parent" android:layout_width="match_parent" android:src="@drawable/icon"></ImageView>
</LinearLayout>
@@ -13,6 +13,7 @@
import android.os.Handler;
import android.os.IBinder;
import android.widget.ImageView;
+import android.widget.TextView;
import android.widget.Toast;
import com.xinchejian.art.video.client.VideoStreamingReceiverService.LocalBinder;
@@ -25,13 +26,17 @@
private ImageView imageView;
private Handler imageUpdaterHandler = new Handler();
private VideoStreamingReceiverClient videoStreamingReceiverClient;
+ private long startTime;
private void changePauseState(boolean flag) {
lock.lock();
try {
isPaused = flag;
imageUpdaterHandler.removeCallbacks(imageUpdaterRunnable);
if(!flag) {
+ displayed = 0;
+ underflow = 0;
+ startTime = System.currentTimeMillis();
imageUpdaterHandler.postDelayed(imageUpdaterRunnable, 200);
}
isPausedCondition.signal();
@@ -56,6 +61,9 @@ public void onServiceDisconnected(ComponentName className) {
changePauseState(true);
}
};
+ private TextView textViewStatus;
+ protected int displayed;
+ protected int underflow;
/** Called when the activity is first created. */
@Override
@@ -64,6 +72,7 @@ public void onCreate(Bundle savedInstanceState) {
startService();
setContentView(R.layout.main);
imageView = (ImageView) findViewById(R.id.imageView1);
+ textViewStatus = (TextView) findViewById(R.id.textViewStatus);
}
@Override
@@ -102,14 +111,21 @@ private void bindService() {
@Override
public void run() {
//Log.d(TAG, "Updating client UI");
+ textViewStatus.setText(videoStreamingReceiverClient.getStatus() + " display fps: " + displayed * 1000
+ / (System.currentTimeMillis() - startTime)
+ + " underflow (Hz) " + (System.currentTimeMillis() - startTime)/((underflow+1)*1000)
+ + " received " + displayed);
Bitmap nextBitmap = videoStreamingReceiverClient.getNextBitmap();
if(nextBitmap != null) {
imageView.setImageBitmap(nextBitmap);
+ displayed++;
+ } else {
+ underflow++;
}
lock.lock();
try {
if(!isPaused) {
- imageUpdaterHandler.postDelayed(imageUpdaterRunnable, 200);
+ imageUpdaterHandler.postDelayed(imageUpdaterRunnable, 40);
}
} finally {
lock.unlock();
@@ -12,4 +12,8 @@ public VideoStreamingReceiverClient(VideoStreamingReceiverService service) {
public Bitmap getNextBitmap() {
return service.getNextBitmap();
}
+
+ public String getStatus() {
+ return service.getStatus();
+ }
}
@@ -45,6 +45,8 @@ public void onStart(Intent intent, int startId) {
private byte[] buffer;
private int[] secondaryBuffer;
private LinkedBlockingQueue<Bitmap> bitmaps = new LinkedBlockingQueue<Bitmap>(5);
+ protected int received;
+ protected int dropped;
private Runnable clientThreadRunnable = new Runnable() {
@@ -77,6 +79,9 @@ public void run() {
return;
}
Log.d(TAG, "Client connected to server");
+ received = 0;
+ dropped = 0;
+ startTime = System.currentTimeMillis();
while (socket.isConnected()) {
lock.lock();
try {
@@ -97,6 +102,7 @@ public void run() {
int compressed;
int width;
int height;
+ boolean compression;
try {
socket.setSoTimeout(5000);
} catch (SocketException e) {
@@ -107,6 +113,7 @@ public void run() {
compressed = dataInputStream.readInt();
width = dataInputStream.readInt();
height = dataInputStream.readInt();
+ compression = dataInputStream.readBoolean();
} catch (IOException e) {
Log.e(TAG, "Error reading header information", e);
break;
@@ -121,11 +128,16 @@ public void run() {
Log.e(TAG, "Invalid image size");
break;
}
- InflaterInputStream inflater = new InflaterInputStream(dataInputStream);
+ InputStream readFrom;
+ if(compression) {
+ readFrom = new InflaterInputStream(dataInputStream);
+ } else {
+ readFrom = dataInputStream;
+ }
try {
int read = 0;
while(read != uncompressed) {
- read += inflater.read(buffer, read, uncompressed - read);
+ read += readFrom.read(buffer, read, uncompressed - read);
}
} catch (IOException e) {
Log.e(TAG, "Failed reading stream!");
@@ -136,9 +148,12 @@ public void run() {
}
try {
Bitmap processImage = processImage(buffer, uncompressed, width, height);
- if(bitmaps.remainingCapacity() > 0) {
- bitmaps.put(processImage);
- }
+ if(bitmaps.remainingCapacity() < 1) {
+ bitmaps.take();
+ dropped++;
+ }
+ bitmaps.put(processImage);
+ received++;
} catch (InterruptedException e) {
e.printStackTrace();
} catch(IllegalArgumentException e) {
@@ -160,6 +175,7 @@ private Bitmap processImage(byte[] buffer, int uncompressed, int width, int heig
return Bitmap.createBitmap(secondaryBuffer, width, height, Config.ARGB_8888);
}
};
+ private long startTime;
/**
* Class used for the client Binder. Because we know this service always
* runs in the same process as its clients, we don't need to deal with IPC.
@@ -290,4 +306,11 @@ public Bitmap getNextBitmap() {
return null;
}
}
+
+ public String getStatus() {
+ return "transfer fps: " + received * 1000
+ / (System.currentTimeMillis() - startTime)
+ + " dropped " + dropped
+ + " received " + received;
+ }
}

0 comments on commit 541572c

Please sign in to comment.