Skip to content

Commit c1cbb54

Browse files
添加截图功能
1 parent e5f0efd commit c1cbb54

File tree

2 files changed

+53
-46
lines changed

2 files changed

+53
-46
lines changed

.idea/misc.xml

Lines changed: 1 addition & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libWSLive/src/main/java/me/lake/librestreaming/ws/StreamLiveCameraView.java

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.graphics.SurfaceTexture;
55
import android.hardware.Camera;
66
import android.util.AttributeSet;
7+
import android.util.Log;
78
import android.view.Gravity;
89
import android.view.TextureView;
910
import android.widget.FrameLayout;
@@ -14,6 +15,7 @@
1415

1516
import me.lake.librestreaming.client.RESClient;
1617
import me.lake.librestreaming.core.listener.RESConnectionListener;
18+
import me.lake.librestreaming.core.listener.RESScreenShotListener;
1719
import me.lake.librestreaming.core.listener.RESVideoChangeListener;
1820
import me.lake.librestreaming.encoder.MediaAudioEncoder;
1921
import me.lake.librestreaming.encoder.MediaEncoder;
@@ -73,7 +75,7 @@ public void init(Context context , StreamAVOption avOption) {
7375
resConfig = StreamConfig.build(context,avOption);
7476
boolean isSucceed = resClient.prepare(resConfig);
7577
if (!isSucceed) {
76-
// Log.w(TAG, "推流prepare方法返回false, 状态异常.");
78+
Log.w(TAG, "推流prepare方法返回false, 状态异常.");
7779
return;
7880
}
7981
initPreviewTextureView();
@@ -197,11 +199,47 @@ public void swapCamera(){
197199
}
198200

199201
/**
200-
* 设置上下文
202+
* 摄像头焦距 [0.0f,1.0f]
201203
*/
202-
public void setContext(Context context){
204+
public void setZoomByPercent(float targetPercent){
203205
if(resClient != null){
204-
resClient.setContext(context);
206+
resClient.setZoomByPercent(targetPercent);
207+
}
208+
}
209+
210+
/**
211+
*摄像头开关闪光灯
212+
*/
213+
public void toggleFlashLight(){
214+
if(resClient != null){
215+
resClient.toggleFlashLight();
216+
}
217+
}
218+
219+
/**
220+
* 推流过程中,重新设置帧率
221+
*/
222+
public void reSetVideoFPS(int fps){
223+
if(resClient != null){
224+
resClient.reSetVideoFPS(fps);
225+
}
226+
}
227+
228+
/**
229+
* 推流过程中,重新设置码率
230+
*/
231+
public void reSetVideoBitrate(int bitrate){
232+
if(resClient != null){
233+
resClient.reSetVideoBitrate(bitrate);
234+
}
235+
}
236+
237+
/**
238+
* 截图
239+
*/
240+
public void takeScreenShot(RESScreenShotListener listener){
241+
if(resClient != null){
242+
resClient.takeScreenShot(listener);
205243
}
206244
}
207245

@@ -223,12 +261,21 @@ public float getSendBufferFreePercent() {
223261
}
224262

225263
/**
226-
* AVSpeed
264+
* AVSpeed 推流速度 和网络相关
227265
*/
228266
public int getAVSpeed() {
229267
return resClient.getAVSpeed();
230268
}
231269

270+
/**
271+
* 设置上下文
272+
*/
273+
public void setContext(Context context){
274+
if(resClient != null){
275+
resClient.setContext(context);
276+
}
277+
}
278+
232279
/**
233280
* destroy
234281
*/
@@ -245,36 +292,6 @@ public void destroy(){
245292
resClient.destroy();
246293
}
247294
}
248-
/**
249-
* 外部调用,2秒轮询
250-
*/
251-
public void fpsVbitPlan() {
252-
if(null == resClient){
253-
return;
254-
}
255-
256-
int target;
257-
int curr = resClient.getVideoBitrate();
258-
259-
if(curr == quality_value_min){
260-
resClient.reSetVideoFPS(16);
261-
}else if(curr == quality_value_max) {
262-
resClient.reSetVideoFPS(20);
263-
}
264-
//Log.e("wangshuo","Bitrate= "+curr);
265-
//Log.e("wangshuo","FreePercent= "+resClient.getSendBufferFreePercent());
266-
if (resClient.getSendBufferFreePercent() <= 0.99f) {//reduce bitrate
267-
if (resClient.getVideoBitrate() > quality_value_min) {
268-
target = (curr / 5 * 4) <= quality_value_min ? quality_value_min:(curr / 5 * 4);
269-
resClient.reSetVideoBitrate(target);
270-
}
271-
} else {//raise bitrate
272-
if (resClient.getVideoBitrate() < quality_value_max) {
273-
target = (curr / 500 * 501) >= quality_value_max ? quality_value_max:(curr / 500 * 501);
274-
resClient.reSetVideoBitrate(target);
275-
}
276-
}
277-
}
278295

279296
/**
280297
* 添加推流状态监听

0 commit comments

Comments
 (0)