├── CameraClient ├── .gitignore ├── .idea │ ├── .name │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── encodings.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ └── runConfigurations.xml ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── alvin │ │ │ └── cameraclient │ │ │ └── ApplicationTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── alvin │ │ │ │ └── cameraclient │ │ │ │ ├── MainActivity.java │ │ │ │ ├── MyCameraView.java │ │ │ │ ├── MyClientThread.java │ │ │ │ └── MyHandler.java │ │ └── res │ │ │ ├── layout │ │ │ └── activity_main.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── alvin │ │ └── cameraclient │ │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── CameraSource ├── .gitignore ├── .idea │ ├── .name │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── encodings.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ └── runConfigurations.xml ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── alvin │ │ │ └── camerasource │ │ │ └── ApplicationTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── alvin │ │ │ │ └── camerasource │ │ │ │ ├── MainActivity.java │ │ │ │ ├── MyCameraView.java │ │ │ │ └── MyServerThread.java │ │ └── res │ │ │ ├── layout │ │ │ └── activity_main.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── alvin │ │ └── camerasource │ │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle └── README.md /CameraClient/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /CameraClient/.idea/.name: -------------------------------------------------------------------------------- 1 | CameraClient -------------------------------------------------------------------------------- /CameraClient/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /CameraClient/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /CameraClient/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CameraClient/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /CameraClient/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /CameraClient/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CameraClient/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /CameraClient/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /CameraClient/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.example.alvin.cameraclient" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.4.0' 26 | } 27 | -------------------------------------------------------------------------------- /CameraClient/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\AndroidSDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /CameraClient/app/src/androidTest/java/com/example/alvin/cameraclient/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.example.alvin.cameraclient; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /CameraClient/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /CameraClient/app/src/main/java/com/example/alvin/cameraclient/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.alvin.cameraclient; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.Matrix; 7 | import android.graphics.Paint; 8 | import android.graphics.PointF; 9 | import android.graphics.drawable.BitmapDrawable; 10 | import android.hardware.Camera; 11 | import android.media.FaceDetector; 12 | import android.os.AsyncTask; 13 | import android.os.Handler; 14 | import android.os.Message; 15 | import android.support.v7.app.AppCompatActivity; 16 | import android.os.Bundle; 17 | import android.util.Log; 18 | import android.widget.ImageView; 19 | import android.widget.TextView; 20 | 21 | import java.lang.ref.WeakReference; 22 | import java.net.Socket; 23 | 24 | public class MainActivity extends AppCompatActivity { 25 | private TextView mStatus; 26 | private ImageView mCameraView; 27 | public static String SERVERIP = "192.168.43.1"; 28 | public static final int SERVERPORT = 9191; 29 | public MyClientThread mClient; 30 | public Bitmap mLastFrame; 31 | 32 | private int face_count; 33 | private final Handler handler = new MyHandler(this); 34 | 35 | private FaceDetector mFaceDetector = new FaceDetector(320,240,10); 36 | private FaceDetector.Face[] faces = new FaceDetector.Face[10]; 37 | private PointF tmp_point = new PointF(); 38 | private Paint tmp_paint = new Paint(); 39 | 40 | 41 | private Runnable mStatusChecker = new Runnable() { 42 | @Override 43 | public void run() { 44 | try { 45 | handler.post(new Runnable() { 46 | @Override 47 | public void run() { 48 | if (mLastFrame!=null){ 49 | 50 | Bitmap mutableBitmap = mLastFrame.copy(Bitmap.Config.RGB_565, true); 51 | face_count = mFaceDetector.findFaces(mLastFrame, faces); 52 | Log.d("Face_Detection", "Face Count: " + String.valueOf(face_count)); 53 | Canvas canvas = new Canvas(mutableBitmap); 54 | 55 | for (int i = 0; i < face_count; i++) { 56 | FaceDetector.Face face = faces[i]; 57 | tmp_paint.setColor(Color.RED); 58 | tmp_paint.setAlpha(100); 59 | face.getMidPoint(tmp_point); 60 | canvas.drawCircle(tmp_point.x, tmp_point.y, face.eyesDistance(), 61 | tmp_paint); 62 | } 63 | 64 | mCameraView.setImageBitmap(mutableBitmap); 65 | } 66 | 67 | } 68 | }); //this function can change value of mInterval. 69 | } finally { 70 | // 100% guarantee that this always happens, even if 71 | // your update method throws an exception 72 | handler.postDelayed(mStatusChecker, 1000/15); 73 | } 74 | } 75 | }; 76 | 77 | @Override 78 | protected void onCreate(Bundle savedInstanceState) { 79 | super.onCreate(savedInstanceState); 80 | setContentView(R.layout.activity_main); 81 | mCameraView = (ImageView) findViewById(R.id.camera_preview); 82 | new AsyncTask() { 83 | 84 | @Override 85 | protected Void doInBackground(Void... unused) { 86 | // Background Code 87 | Socket s; 88 | try { 89 | s = new Socket(SERVERIP, SERVERPORT); 90 | mClient = new MyClientThread(s, handler); 91 | new Thread(mClient).start(); 92 | } catch (Exception e) { 93 | e.printStackTrace(); 94 | } 95 | return null; 96 | } 97 | 98 | }.execute(); 99 | mStatusChecker.run(); 100 | } 101 | public static Bitmap rotateImage(Bitmap source, float angle) { 102 | if (source != null){ 103 | Bitmap retVal; 104 | 105 | Matrix matrix = new Matrix(); 106 | matrix.postRotate(angle); 107 | retVal = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true); 108 | source.recycle(); 109 | return retVal; 110 | } 111 | return null; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /CameraClient/app/src/main/java/com/example/alvin/cameraclient/MyCameraView.java: -------------------------------------------------------------------------------- 1 | package com.example.alvin.cameraclient; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.Paint; 8 | import android.graphics.PointF; 9 | import android.media.FaceDetector; 10 | import android.media.Image; 11 | import android.util.AttributeSet; 12 | import android.util.Log; 13 | import android.view.View; 14 | import android.widget.ImageView; 15 | 16 | /** 17 | * Created by Alvin on 2016-05-20. 18 | */ 19 | public class MyCameraView extends View { 20 | public Bitmap mNextFrame; 21 | public int face_count; 22 | private FaceDetector mFaceDetector = new FaceDetector(320,240,10); 23 | private FaceDetector.Face[] faces = new FaceDetector.Face[10]; 24 | private PointF tmp_point = new PointF(); 25 | private Paint tmp_paint = new Paint(); 26 | 27 | public MyCameraView(Context context){ 28 | super(context); 29 | faces = new FaceDetector.Face[10]; 30 | } 31 | public MyCameraView(Context context, AttributeSet attrs) { 32 | super(context,attrs); 33 | faces = new FaceDetector.Face[10]; 34 | // The bitmap must be in 565 format (for now). 35 | } 36 | 37 | public void updateImage(Bitmap frame) { 38 | // Set internal configuration to RGB_565 39 | this.mNextFrame = frame; 40 | face_count = mFaceDetector.findFaces(mNextFrame, faces); 41 | Log.d("Face_Detection", "Face Count: " + String.valueOf(face_count)); 42 | } 43 | 44 | public void onDraw(Canvas canvas) { 45 | canvas.drawBitmap(mNextFrame, 0, 0, null); 46 | for (int i = 0; i < face_count; i++) { 47 | FaceDetector.Face face = faces[i]; 48 | tmp_paint.setColor(Color.RED); 49 | tmp_paint.setAlpha(100); 50 | face.getMidPoint(tmp_point); 51 | canvas.drawCircle(tmp_point.x, tmp_point.y, face.eyesDistance(), 52 | tmp_paint); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /CameraClient/app/src/main/java/com/example/alvin/cameraclient/MyClientThread.java: -------------------------------------------------------------------------------- 1 | package com.example.alvin.cameraclient; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.BitmapFactory; 5 | import android.media.FaceDetector; 6 | import android.os.Handler; 7 | import android.os.Message; 8 | import android.util.Log; 9 | 10 | import java.io.DataInputStream; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.net.Socket; 14 | 15 | /** 16 | * Created by Alvin on 2016-05-20. 17 | */ 18 | public class MyClientThread implements Runnable { 19 | private Socket mSocket; 20 | private Handler mHandler; 21 | private Boolean mRunFlag = true; 22 | final private String TAG = "MyClientThread"; 23 | private BitmapFactory.Options bitmap_options = new BitmapFactory.Options(); 24 | 25 | 26 | 27 | public MyClientThread(Socket socket, Handler handler) throws IOException { 28 | this.mSocket = socket; 29 | this.mHandler = handler; 30 | bitmap_options.inPreferredConfig = Bitmap.Config.RGB_565; 31 | //br = new BufferedReader(new InputStreamReader(s.getInputStream())); 32 | } 33 | 34 | @Override 35 | public void run() { 36 | try { 37 | InputStream inStream = null; 38 | try { 39 | inStream = mSocket.getInputStream(); 40 | } catch (Exception e) { 41 | e.printStackTrace(); 42 | } 43 | DataInputStream is = new DataInputStream(inStream); 44 | while (mRunFlag) { 45 | try { 46 | int token = is.readInt(); 47 | if (token == 4) { 48 | if (is.readUTF().equals("#@@#")) { 49 | //System.out.println("before-token" + token); 50 | int imgLength = is.readInt(); 51 | System.out.println("getLength:" + imgLength); 52 | System.out.println("back-token" + is.readUTF()); 53 | byte[] buffer = new byte[imgLength]; 54 | int len = 0; 55 | while (len < imgLength) { 56 | len += is.read(buffer, len, imgLength - len); 57 | } 58 | Message m = mHandler.obtainMessage(); 59 | m.obj = BitmapFactory.decodeByteArray(buffer, 0, buffer.length,bitmap_options); 60 | if (m.obj != null) { 61 | mHandler.sendMessage(m); 62 | } else { 63 | System.out.println("Decode Failed"); 64 | } 65 | } 66 | }else{ 67 | Log.d(TAG,"Skip Dirty bytes!!!!"+Integer.toString(token)); 68 | } 69 | } catch (Exception e) { 70 | e.printStackTrace(); 71 | } 72 | } 73 | } catch (Exception e) { 74 | e.printStackTrace(); 75 | } 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /CameraClient/app/src/main/java/com/example/alvin/cameraclient/MyHandler.java: -------------------------------------------------------------------------------- 1 | package com.example.alvin.cameraclient; 2 | 3 | import android.graphics.Bitmap; 4 | import android.os.Handler; 5 | import android.os.Message; 6 | 7 | import java.lang.ref.WeakReference; 8 | 9 | /** 10 | * Created by Alvin on 2016-05-20. 11 | */ 12 | class MyHandler extends Handler { 13 | private final WeakReference mActivity; 14 | 15 | public MyHandler(MainActivity activity) { 16 | mActivity = new WeakReference(activity); 17 | } 18 | 19 | @Override 20 | public void handleMessage(Message msg) { 21 | MainActivity activity = mActivity.get(); 22 | if (activity != null) { 23 | try { 24 | activity.mLastFrame = (Bitmap) msg.obj; 25 | } catch (Exception e) { 26 | e.printStackTrace(); 27 | } 28 | super.handleMessage(msg); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /CameraClient/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 19 | 29 | 30 | -------------------------------------------------------------------------------- /CameraClient/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucklyric/android-camera-socket-stream/3f1f9c75972811c14940f4278d1e1827267fa82e/CameraClient/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraClient/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucklyric/android-camera-socket-stream/3f1f9c75972811c14940f4278d1e1827267fa82e/CameraClient/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraClient/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucklyric/android-camera-socket-stream/3f1f9c75972811c14940f4278d1e1827267fa82e/CameraClient/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraClient/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucklyric/android-camera-socket-stream/3f1f9c75972811c14940f4278d1e1827267fa82e/CameraClient/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraClient/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucklyric/android-camera-socket-stream/3f1f9c75972811c14940f4278d1e1827267fa82e/CameraClient/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraClient/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /CameraClient/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /CameraClient/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /CameraClient/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CameraClient 3 | 4 | -------------------------------------------------------------------------------- /CameraClient/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /CameraClient/app/src/test/java/com/example/alvin/cameraclient/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.alvin.cameraclient; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /CameraClient/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.1.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /CameraClient/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /CameraClient/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucklyric/android-camera-socket-stream/3f1f9c75972811c14940f4278d1e1827267fa82e/CameraClient/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /CameraClient/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /CameraClient/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /CameraClient/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /CameraClient/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /CameraSource/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /CameraSource/.idea/.name: -------------------------------------------------------------------------------- 1 | CameraSource -------------------------------------------------------------------------------- /CameraSource/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /CameraSource/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /CameraSource/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CameraSource/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /CameraSource/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /CameraSource/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CameraSource/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /CameraSource/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /CameraSource/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.example.alvin.camerasource" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.4.0' 26 | } 27 | -------------------------------------------------------------------------------- /CameraSource/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\AndroidSDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /CameraSource/app/src/androidTest/java/com/example/alvin/camerasource/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.example.alvin.camerasource; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /CameraSource/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /CameraSource/app/src/main/java/com/example/alvin/camerasource/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.alvin.camerasource; 2 | 3 | import android.hardware.Camera; 4 | import android.os.Handler; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.util.Log; 8 | import android.widget.FrameLayout; 9 | import android.widget.TextView; 10 | 11 | import java.net.Inet4Address; 12 | import java.net.InetAddress; 13 | import java.net.NetworkInterface; 14 | import java.net.SocketException; 15 | import java.util.Enumeration; 16 | 17 | public class MainActivity extends AppCompatActivity { 18 | private Camera mCamera; 19 | public MyCameraView mPreview; 20 | public TextView serverStatus; 21 | public static String SERVERIP = "localhost"; 22 | public static final int SERVERPORT = 9191; 23 | private Handler handler = new Handler(); 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_main); 29 | serverStatus = (TextView) findViewById(R.id.textView); 30 | SERVERIP = getLocalIpAddress(); 31 | mCamera = getCameraInstance(); 32 | mPreview = new MyCameraView(this, mCamera); 33 | FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview); 34 | preview.addView(mPreview); 35 | Thread cThread = new Thread(new MyServerThread(this,SERVERIP,SERVERPORT,handler)); 36 | cThread.start(); 37 | } 38 | 39 | /** 40 | * Get local ip address of the phone 41 | * @return ipAddress 42 | */ 43 | private String getLocalIpAddress() { 44 | try { 45 | for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { 46 | NetworkInterface intf = en.nextElement(); 47 | for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { 48 | InetAddress inetAddress = enumIpAddr.nextElement(); 49 | if (!inetAddress.isLoopbackAddress()&& inetAddress instanceof Inet4Address) { return inetAddress.getHostAddress().toString(); } 50 | } 51 | } 52 | } catch (SocketException ex) { 53 | Log.e("ServerActivity", ex.toString()); 54 | } 55 | return null; 56 | } 57 | 58 | /** 59 | * Get camera instance 60 | * @return 61 | */ 62 | public static Camera getCameraInstance() 63 | { 64 | Camera c=null; 65 | try{ 66 | c=Camera.open(); 67 | }catch(Exception e){ 68 | e.printStackTrace(); 69 | } 70 | return c; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /CameraSource/app/src/main/java/com/example/alvin/camerasource/MyCameraView.java: -------------------------------------------------------------------------------- 1 | package com.example.alvin.camerasource; 2 | 3 | import android.content.Context; 4 | import android.graphics.ImageFormat; 5 | import android.graphics.Rect; 6 | import android.graphics.YuvImage; 7 | import android.hardware.Camera; 8 | import android.util.Log; 9 | import android.view.SurfaceHolder; 10 | import android.view.SurfaceView; 11 | 12 | import java.io.ByteArrayOutputStream; 13 | 14 | /** 15 | * Created by Alvin on 2016-05-20. 16 | */ 17 | public class MyCameraView extends SurfaceView implements SurfaceHolder.Callback,Camera.PreviewCallback{ 18 | private SurfaceHolder mHolder; 19 | private Camera mCamera; 20 | private int width; 21 | private int height; 22 | public ByteArrayOutputStream mFrameBuffer; 23 | private Context con; 24 | 25 | /** 26 | * Constructor of the MyCameraView 27 | * @param context 28 | * @param camera 29 | */ 30 | public MyCameraView(Context context,Camera camera){ 31 | super(context); 32 | con=context; 33 | mCamera=camera; 34 | mHolder=getHolder(); 35 | mHolder.addCallback(this); 36 | mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 37 | } 38 | 39 | 40 | /** 41 | * set preview to the camera 42 | * @param holder 43 | */ 44 | public void surfaceCreated(SurfaceHolder holder) { 45 | try { 46 | mCamera.setPreviewDisplay(holder); 47 | } catch (Exception e) { 48 | e.printStackTrace(); 49 | } 50 | } 51 | 52 | /** 53 | * surface destroyed function 54 | * @param holder 55 | */ 56 | public void surfaceDestroyed(SurfaceHolder holder) { 57 | mCamera.setPreviewCallback(null); 58 | mCamera.release(); 59 | mCamera=null; 60 | } 61 | 62 | 63 | /** 64 | * surface changed function 65 | * @param holder 66 | * @param format 67 | * @param w 68 | * @param h 69 | */ 70 | public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 71 | try{ 72 | mCamera.stopPreview(); 73 | } catch (Exception e){ 74 | e.printStackTrace(); 75 | } 76 | try{ 77 | //Configration Camera Parameter(full-size) 78 | Camera.Parameters parameters = mCamera.getParameters(); 79 | parameters.setPreviewSize(320,240); 80 | this.width=parameters.getPreviewSize().width; 81 | this.height=parameters.getPreviewSize().height; 82 | parameters.setPreviewFormat(ImageFormat.NV21); 83 | mCamera.setParameters(parameters); 84 | // mCamera.setDisplayOrientation(90); 85 | mCamera.setPreviewCallback(this); 86 | mCamera.startPreview(); 87 | }catch(Exception e){ 88 | e.printStackTrace(); 89 | } 90 | } 91 | 92 | 93 | /** 94 | * frame call back function 95 | * @param data 96 | * @param camera 97 | */ 98 | public void onPreviewFrame(byte[] data,Camera camera){ 99 | try{ 100 | //convert YuvImage(NV21) to JPEG Image data 101 | YuvImage yuvimage=new YuvImage(data,ImageFormat.NV21,this.width,this.height,null); 102 | System.out.println("WidthandHeight"+yuvimage.getHeight()+"::"+yuvimage.getWidth()); 103 | ByteArrayOutputStream baos=new ByteArrayOutputStream(); 104 | yuvimage.compressToJpeg(new Rect(0,0,this.width,this.height),100,baos); 105 | mFrameBuffer = baos; 106 | }catch(Exception e){ 107 | Log.d("parse","errpr"); 108 | } 109 | } 110 | 111 | } 112 | 113 | -------------------------------------------------------------------------------- /CameraSource/app/src/main/java/com/example/alvin/camerasource/MyServerThread.java: -------------------------------------------------------------------------------- 1 | package com.example.alvin.camerasource; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.util.Log; 6 | 7 | import java.io.BufferedReader; 8 | import java.io.BufferedWriter; 9 | import java.io.DataOutputStream; 10 | import java.io.IOException; 11 | import java.io.InputStreamReader; 12 | import java.io.OutputStream; 13 | import java.io.OutputStreamWriter; 14 | import java.net.ServerSocket; 15 | import java.net.Socket; 16 | 17 | /** 18 | * Created by Alvin on 2016-05-20. 19 | */ 20 | public class MyServerThread implements Runnable { 21 | private int mServerPort; 22 | private String mServerIP; 23 | private Context mContext; 24 | private Handler mHandler; 25 | private MainActivity mActivityInstance; 26 | public MyServerThread(Context context,String serverip,int serverport,Handler handler){ 27 | super(); 28 | mContext=context; 29 | mServerIP = serverip; 30 | mServerPort = serverport; 31 | mHandler = handler; 32 | mActivityInstance = (MainActivity)mContext; 33 | } 34 | public void run(){ 35 | try { 36 | ServerSocket ss = new ServerSocket(mServerPort); 37 | mHandler.post(new Runnable() { 38 | @Override 39 | public void run() { 40 | mActivityInstance.serverStatus.setText("Listening on IP: " + mServerIP); 41 | } 42 | }); 43 | while (true){ 44 | Socket s = ss.accept(); 45 | //socketList.add(ss); 46 | new Thread(new ServerSocketThread(s)).start(); 47 | } 48 | }catch(Exception e){ 49 | Log.d("ServerThread", "run: erro"); 50 | } 51 | } 52 | 53 | public class ServerSocketThread implements Runnable{ 54 | Socket s = null; 55 | // BufferedReader br = null; 56 | //BufferedWriter bw = null; 57 | OutputStream os = null; 58 | public ServerSocketThread(Socket s) throws IOException { 59 | this.s = s; 60 | //br = new BufferedReader(new InputStreamReader(s.getInputStream())); 61 | //bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream())); 62 | } 63 | @Override 64 | public void run() { 65 | if(s !=null){ 66 | String clientIp = s.getInetAddress().toString().replace("/", ""); 67 | int clientPort = s.getPort(); 68 | System.out.println("====client ip====="+clientIp); 69 | System.out.println("====client port====="+clientPort); 70 | try { 71 | 72 | s.setKeepAlive(true); 73 | os = s.getOutputStream(); 74 | while(true){ 75 | //服务器端向客户端发送数据 76 | //dos.write(mPreview.mFrameBuffer.); 77 | DataOutputStream dos = new DataOutputStream(os); 78 | dos.writeInt(4); 79 | dos.writeUTF("#@@#"); 80 | dos.writeInt(mActivityInstance.mPreview.mFrameBuffer.size()); 81 | dos.writeUTF("-@@-"); 82 | dos.flush(); 83 | System.out.println(mActivityInstance.mPreview.mFrameBuffer.size()); 84 | dos.write(mActivityInstance.mPreview.mFrameBuffer.toByteArray()); 85 | //System.out.println("outlength"+mPreview.mFrameBuffer.length); 86 | dos.flush(); 87 | Thread.sleep(1000/15); 88 | } 89 | 90 | } catch (Exception e) { 91 | e.printStackTrace(); 92 | try { 93 | if (os!= null) 94 | os.close(); 95 | 96 | } catch (Exception e2) { 97 | e.printStackTrace(); 98 | } 99 | 100 | } 101 | 102 | 103 | 104 | } 105 | else{ 106 | System.out.println("socket is null"); 107 | 108 | } 109 | } 110 | 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /CameraSource/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 19 | 20 | 30 | 31 | -------------------------------------------------------------------------------- /CameraSource/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucklyric/android-camera-socket-stream/3f1f9c75972811c14940f4278d1e1827267fa82e/CameraSource/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraSource/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucklyric/android-camera-socket-stream/3f1f9c75972811c14940f4278d1e1827267fa82e/CameraSource/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraSource/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucklyric/android-camera-socket-stream/3f1f9c75972811c14940f4278d1e1827267fa82e/CameraSource/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraSource/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucklyric/android-camera-socket-stream/3f1f9c75972811c14940f4278d1e1827267fa82e/CameraSource/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraSource/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucklyric/android-camera-socket-stream/3f1f9c75972811c14940f4278d1e1827267fa82e/CameraSource/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CameraSource/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /CameraSource/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /CameraSource/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /CameraSource/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CameraSource 3 | 4 | -------------------------------------------------------------------------------- /CameraSource/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /CameraSource/app/src/test/java/com/example/alvin/camerasource/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.alvin.camerasource; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /CameraSource/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.1.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /CameraSource/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /CameraSource/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucklyric/android-camera-socket-stream/3f1f9c75972811c14940f4278d1e1827267fa82e/CameraSource/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /CameraSource/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /CameraSource/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /CameraSource/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /CameraSource/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # android-camera-socket-stream 2 | Using socket streaming camera video in real time 3 | --------------------------------------------------------------------------------