Skip to content

Commit f0f28b4

Browse files
committed
finsis-android
1 parent 5b57353 commit f0f28b4

File tree

7 files changed

+567
-35
lines changed

7 files changed

+567
-35
lines changed

.gitignore

+42-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,43 @@
1+
# Built application files
2+
*.apk
3+
*.ap_
4+
5+
# Files for the ART/Dalvik VM
6+
*.dex
7+
8+
# Java class files
9+
*.class
10+
11+
# Generated files
12+
bin/
13+
gen/
14+
out/
15+
16+
# Gradle files
17+
.gradle/
18+
build/
19+
20+
# Local configuration file (sdk path, etc)
21+
local.properties
22+
23+
# Proguard folder generated by Eclipse
24+
proguard/
25+
26+
# Log Files
27+
*.log
28+
29+
# Android Studio Navigation editor temp files
30+
.navigation/
31+
32+
# Android Studio captures folder
33+
captures/
34+
35+
# Intellij
136
*.iml
2-
.gradle
3-
/local.properties
4-
/.idea/workspace.xml
5-
/.idea/libraries
6-
.DS_Store
7-
/build
8-
/captures
9-
.externalNativeBuild
37+
.idea/workspace.xml
38+
39+
# Keystore files
40+
*.jks
41+
42+
# idea
43+
.idea/

.idea/misc.xml

+1-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/AndroidManifest.xml

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.dotengine.linsir.lin_webrtc_demo">
44

5+
<uses-feature android:name="android.hardware.camera" />
6+
<uses-feature android:name="android.hardware.camera.autofocus" />
7+
8+
<uses-permission android:name="android.permission.CAMERA" />
9+
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
10+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
11+
<uses-permission android:name="android.permission.INTERNET" />
12+
<uses-permission android:name="android.permission.WAKE_LOCK" />
13+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
14+
515
<application
616
android:allowBackup="true"
717
android:icon="@mipmap/ic_launcher"
818
android:label="@string/app_name"
919
android:roundIcon="@mipmap/ic_launcher_round"
1020
android:supportsRtl="true"
11-
android:theme="@style/AppTheme">
21+
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
1222
<activity android:name=".MainActivity">
1323
<intent-filter>
1424
<action android:name="android.intent.action.MAIN"/>
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,212 @@
11
package com.dotengine.linsir.lin_webrtc_demo;
22

3-
import android.support.v7.app.AppCompatActivity;
3+
import android.content.Intent;
4+
import android.graphics.Point;
5+
import android.opengl.GLSurfaceView;
46
import android.os.Bundle;
7+
import android.support.v7.app.AppCompatActivity;
8+
import android.widget.Toast;
9+
10+
import org.json.JSONException;
11+
import org.webrtc.MediaStream;
12+
import org.webrtc.VideoRenderer;
13+
import org.webrtc.VideoRendererGui;
14+
15+
import java.util.List;
16+
17+
public class MainActivity extends AppCompatActivity implements WebRtcClient.RtcListener {
18+
19+
20+
private final static int VIDEO_CALL_SENT = 666;
21+
private static final String VIDEO_CODEC_VP9 = "VP9";
22+
private static final String AUDIO_CODEC_OPUS = "opus";
23+
24+
25+
private static final int LOCAL_X_CONNECTING = 0;
26+
private static final int LOCAL_Y_CONNECTING = 0;
27+
private static final int LOCAL_WIDTH_CONNECTING = 100;
28+
private static final int LOCAL_HEIGHT_CONNECTING = 100;
29+
30+
private static final int LOCAL_X_CONNECTED = 72;
31+
private static final int LOCAL_Y_CONNECTED = 72;
32+
private static final int LOCAL_WIDTH_CONNECTED = 25;
33+
private static final int LOCAL_HEIGHT_CONNECTED = 25;
34+
35+
private static final int REMOTE_X = 0;
36+
private static final int REMOTE_Y = 0;
37+
private static final int REMOTE_WIDTH = 100;
38+
private static final int REMOTE_HEIGHT = 100;
39+
private VideoRendererGui.ScalingType scalingType = VideoRendererGui.ScalingType.SCALE_ASPECT_FILL;
40+
41+
private GLSurfaceView vsv;
42+
private VideoRenderer.Callbacks localRender;
43+
private VideoRenderer.Callbacks remoteRender;
44+
private WebRtcClient client;
45+
private String mSocketAddress;
46+
private String callerId;
547

6-
public class MainActivity extends AppCompatActivity {
748

849
@Override
950
protected void onCreate(Bundle savedInstanceState) {
1051
super.onCreate(savedInstanceState);
1152
setContentView(R.layout.activity_main);
53+
54+
55+
mSocketAddress = "http://" + getResources().getString(R.string.host);
56+
mSocketAddress += (":" + getResources().getString(R.string.port) + "/");
57+
58+
vsv = (GLSurfaceView) findViewById(R.id.glview_call);
59+
vsv.setPreserveEGLContextOnPause(true);
60+
vsv.setKeepScreenOn(true);
61+
VideoRendererGui.setView(vsv, new Runnable() {
62+
@Override public void run() {
63+
init();
64+
}
65+
});
66+
67+
remoteRender = VideoRendererGui.create(REMOTE_X,
68+
REMOTE_Y,
69+
REMOTE_WIDTH,
70+
REMOTE_HEIGHT,
71+
scalingType,
72+
false);
73+
74+
localRender = VideoRendererGui.create(LOCAL_X_CONNECTING,
75+
LOCAL_Y_CONNECTING,
76+
LOCAL_WIDTH_CONNECTING,
77+
LOCAL_HEIGHT_CONNECTING,
78+
scalingType,
79+
true);
80+
81+
final Intent intent = getIntent();
82+
final String action = intent.getAction();
83+
84+
if (Intent.ACTION_VIEW.equals(action)) {
85+
final List<String> segments = intent.getData().getPathSegments();
86+
callerId = segments.get(0);
87+
}
88+
89+
90+
}
91+
92+
private void init() {
93+
Point displaySize = new Point();
94+
getWindowManager().getDefaultDisplay().getSize(displaySize);
95+
PeerConnectionParameters params = new PeerConnectionParameters(
96+
true, false, displaySize.x, displaySize.y, 30, 1, VIDEO_CODEC_VP9, true, 1, AUDIO_CODEC_OPUS, true);
97+
98+
client = new WebRtcClient(this, mSocketAddress, params, VideoRendererGui.getEGLContext());
99+
100+
101+
startCam();
102+
}
103+
104+
105+
@Override protected void onPause() {
106+
super.onPause();
107+
vsv.onPause();
108+
if (client != null) {
109+
client.onPause();
110+
}
12111
}
112+
113+
114+
@Override protected void onResume() {
115+
super.onResume();
116+
vsv.onResume();
117+
if (client != null) {
118+
client.onResume();
119+
}
120+
}
121+
122+
123+
@Override protected void onDestroy() {
124+
super.onDestroy();
125+
if (client != null) {
126+
client.onResume();
127+
}
128+
}
129+
130+
@Override public void onCallReady(String callId) {
131+
if (client != null) {
132+
try {
133+
answer(callId);
134+
} catch (JSONException e) {
135+
e.printStackTrace();
136+
}
137+
138+
}else {
139+
call(callId);
140+
}
141+
}
142+
143+
144+
public void answer(String callerId) throws JSONException {
145+
client.sendMessage(callerId,"init",null);
146+
startCam();
147+
148+
}
149+
150+
151+
public void call(String callId){
152+
Intent msg = new Intent(Intent.ACTION_SEND);
153+
msg.putExtra(Intent.EXTRA_TEXT,mSocketAddress+callerId);
154+
msg.setType("text/plain");
155+
startActivityForResult(Intent.createChooser(msg,"Call someone :"),VIDEO_CALL_SENT);
156+
157+
158+
}
159+
160+
@Override public void onStatusChanged(final String newStatus) {
161+
runOnUiThread(new Runnable() {
162+
@Override public void run() {
163+
Toast.makeText(getApplicationContext(), newStatus, Toast.LENGTH_SHORT).show();
164+
}
165+
});
166+
}
167+
168+
@Override public void onLocalStream(MediaStream localStream) {
169+
localStream.videoTracks.get(0).addRenderer(new VideoRenderer(localRender));
170+
VideoRendererGui.update(localRender,
171+
LOCAL_X_CONNECTED,
172+
LOCAL_Y_CONNECTING,
173+
LOCAL_WIDTH_CONNECTING,
174+
LOCAL_HEIGHT_CONNECTING,
175+
scalingType);
176+
}
177+
178+
@Override public void onAddRemoteStream(MediaStream romoteStream, int endPoint) {
179+
VideoRendererGui.update(remoteRender,
180+
REMOTE_X,
181+
REMOTE_Y,
182+
REMOTE_WIDTH,
183+
REMOTE_HEIGHT,
184+
scalingType
185+
);
186+
187+
188+
VideoRendererGui.update(localRender,
189+
LOCAL_X_CONNECTED,
190+
LOCAL_Y_CONNECTED,
191+
LOCAL_WIDTH_CONNECTED,
192+
LOCAL_HEIGHT_CONNECTED,
193+
scalingType);
194+
195+
196+
}
197+
198+
@Override public void onRemoveRemoteStream(int endPoint) {
199+
VideoRendererGui.update(localRender,
200+
LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING,
201+
LOCAL_WIDTH_CONNECTING, LOCAL_HEIGHT_CONNECTING,
202+
scalingType);
203+
}
204+
205+
206+
public void startCam() {
207+
208+
client.start("android_test");
209+
}
210+
211+
13212
}

0 commit comments

Comments
 (0)