Skip to content

Commit

Permalink
latest modifications before refactoring into new projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricky Ng-Adam committed Jul 9, 2011
1 parent 06843b4 commit 541572c
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 9 deletions.
3 changes: 2 additions & 1 deletion ART7/ImageStreamingClient/AndroidManifest.xml
Expand Up @@ -10,7 +10,8 @@
<service android:name="VideoStreamingReceiverService"> <service android:name="VideoStreamingReceiverService">
</service> </service>
<activity android:name="ClientActivity" <activity android:name="ClientActivity"
android:label="@string/app_name"> android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
Expand Down
Binary file modified ART7/ImageStreamingClient/bin/ImageStreamingClient.apk
Binary file not shown.
Binary file modified ART7/ImageStreamingClient/bin/classes.dex
Binary file not shown.
Binary file modified ART7/ImageStreamingClient/bin/resources.ap_
Binary file not shown.
4 changes: 2 additions & 2 deletions ART7/ImageStreamingClient/res/layout/main.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent" 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> <ImageView android:id="@+id/imageView1" android:layout_height="match_parent" android:layout_width="match_parent" android:src="@drawable/icon"></ImageView>
</LinearLayout> </LinearLayout>
Expand Up @@ -13,6 +13,7 @@
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;


import com.xinchejian.art.video.client.VideoStreamingReceiverService.LocalBinder; import com.xinchejian.art.video.client.VideoStreamingReceiverService.LocalBinder;
Expand All @@ -25,13 +26,17 @@ public class ClientActivity extends Activity {
private ImageView imageView; private ImageView imageView;
private Handler imageUpdaterHandler = new Handler(); private Handler imageUpdaterHandler = new Handler();
private VideoStreamingReceiverClient videoStreamingReceiverClient; private VideoStreamingReceiverClient videoStreamingReceiverClient;
private long startTime;


private void changePauseState(boolean flag) { private void changePauseState(boolean flag) {
lock.lock(); lock.lock();
try { try {
isPaused = flag; isPaused = flag;
imageUpdaterHandler.removeCallbacks(imageUpdaterRunnable); imageUpdaterHandler.removeCallbacks(imageUpdaterRunnable);
if(!flag) { if(!flag) {
displayed = 0;
underflow = 0;
startTime = System.currentTimeMillis();
imageUpdaterHandler.postDelayed(imageUpdaterRunnable, 200); imageUpdaterHandler.postDelayed(imageUpdaterRunnable, 200);
} }
isPausedCondition.signal(); isPausedCondition.signal();
Expand All @@ -56,6 +61,9 @@ public void onServiceDisconnected(ComponentName className) {
changePauseState(true); changePauseState(true);
} }
}; };
private TextView textViewStatus;
protected int displayed;
protected int underflow;


/** Called when the activity is first created. */ /** Called when the activity is first created. */
@Override @Override
Expand All @@ -64,6 +72,7 @@ public void onCreate(Bundle savedInstanceState) {
startService(); startService();
setContentView(R.layout.main); setContentView(R.layout.main);
imageView = (ImageView) findViewById(R.id.imageView1); imageView = (ImageView) findViewById(R.id.imageView1);
textViewStatus = (TextView) findViewById(R.id.textViewStatus);
} }


@Override @Override
Expand Down Expand Up @@ -102,14 +111,21 @@ private void bindService() {
@Override @Override
public void run() { public void run() {
//Log.d(TAG, "Updating client UI"); //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(); Bitmap nextBitmap = videoStreamingReceiverClient.getNextBitmap();
if(nextBitmap != null) { if(nextBitmap != null) {
imageView.setImageBitmap(nextBitmap); imageView.setImageBitmap(nextBitmap);
displayed++;
} else {
underflow++;
} }
lock.lock(); lock.lock();
try { try {
if(!isPaused) { if(!isPaused) {
imageUpdaterHandler.postDelayed(imageUpdaterRunnable, 200); imageUpdaterHandler.postDelayed(imageUpdaterRunnable, 40);
} }
} finally { } finally {
lock.unlock(); lock.unlock();
Expand Down
Expand Up @@ -12,4 +12,8 @@ public VideoStreamingReceiverClient(VideoStreamingReceiverService service) {
public Bitmap getNextBitmap() { public Bitmap getNextBitmap() {
return service.getNextBitmap(); return service.getNextBitmap();
} }

public String getStatus() {
return service.getStatus();
}
} }
Expand Up @@ -45,6 +45,8 @@ public void onStart(Intent intent, int startId) {
private byte[] buffer; private byte[] buffer;
private int[] secondaryBuffer; private int[] secondaryBuffer;
private LinkedBlockingQueue<Bitmap> bitmaps = new LinkedBlockingQueue<Bitmap>(5); private LinkedBlockingQueue<Bitmap> bitmaps = new LinkedBlockingQueue<Bitmap>(5);
protected int received;
protected int dropped;


private Runnable clientThreadRunnable = new Runnable() { private Runnable clientThreadRunnable = new Runnable() {


Expand Down Expand Up @@ -77,6 +79,9 @@ public void run() {
return; return;
} }
Log.d(TAG, "Client connected to server"); Log.d(TAG, "Client connected to server");
received = 0;
dropped = 0;
startTime = System.currentTimeMillis();
while (socket.isConnected()) { while (socket.isConnected()) {
lock.lock(); lock.lock();
try { try {
Expand All @@ -97,6 +102,7 @@ public void run() {
int compressed; int compressed;
int width; int width;
int height; int height;
boolean compression;
try { try {
socket.setSoTimeout(5000); socket.setSoTimeout(5000);
} catch (SocketException e) { } catch (SocketException e) {
Expand All @@ -107,6 +113,7 @@ public void run() {
compressed = dataInputStream.readInt(); compressed = dataInputStream.readInt();
width = dataInputStream.readInt(); width = dataInputStream.readInt();
height = dataInputStream.readInt(); height = dataInputStream.readInt();
compression = dataInputStream.readBoolean();
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error reading header information", e); Log.e(TAG, "Error reading header information", e);
break; break;
Expand All @@ -121,11 +128,16 @@ public void run() {
Log.e(TAG, "Invalid image size"); Log.e(TAG, "Invalid image size");
break; break;
} }
InflaterInputStream inflater = new InflaterInputStream(dataInputStream); InputStream readFrom;
if(compression) {
readFrom = new InflaterInputStream(dataInputStream);
} else {
readFrom = dataInputStream;
}
try { try {
int read = 0; int read = 0;
while(read != uncompressed) { while(read != uncompressed) {
read += inflater.read(buffer, read, uncompressed - read); read += readFrom.read(buffer, read, uncompressed - read);
} }
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Failed reading stream!"); Log.e(TAG, "Failed reading stream!");
Expand All @@ -136,9 +148,12 @@ public void run() {
} }
try { try {
Bitmap processImage = processImage(buffer, uncompressed, width, height); Bitmap processImage = processImage(buffer, uncompressed, width, height);
if(bitmaps.remainingCapacity() > 0) { if(bitmaps.remainingCapacity() < 1) {
bitmaps.put(processImage); bitmaps.take();
} dropped++;
}
bitmaps.put(processImage);
received++;
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
Expand All @@ -160,6 +175,7 @@ private Bitmap processImage(byte[] buffer, int uncompressed, int width, int heig
return Bitmap.createBitmap(secondaryBuffer, width, height, Config.ARGB_8888); return Bitmap.createBitmap(secondaryBuffer, width, height, Config.ARGB_8888);
} }
}; };
private long startTime;
/** /**
* Class used for the client Binder. Because we know this service always * 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. * runs in the same process as its clients, we don't need to deal with IPC.
Expand Down Expand Up @@ -290,4 +306,11 @@ public Bitmap getNextBitmap() {
return null; 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.