36
36
import java .security .MessageDigest ;
37
37
import java .security .NoSuchAlgorithmException ;
38
38
import java .util .Arrays ;
39
+ import java .util .Timer ;
40
+ import java .util .TimerTask ;
39
41
import java .util .concurrent .ExecutorService ;
40
42
import java .util .concurrent .Executors ;
41
43
@@ -44,6 +46,7 @@ public class CameraActivity extends Activity {
44
46
45
47
private static final String TAG = "CameraActivity" ;
46
48
49
+
47
50
private GLSurfaceView mCameraPreview ;
48
51
49
52
private KSYStreamer mStreamer ;
@@ -62,11 +65,12 @@ public class CameraActivity extends Activity {
62
65
private boolean isFlashOpened = false ;
63
66
private boolean startAuto = false ;
64
67
private boolean audio_mix = false ;
65
- private String mUrl ;
68
+ private boolean printDebugInfo = false ;
69
+ private String mUrl , mDebugInfo = "" ;
66
70
private String mBgmPath = "/sdcard/test.mp3" ;
67
71
private static final String START_STRING = "开始直播" ;
68
72
private static final String STOP_STRING = "停止直播" ;
69
- private TextView mUrlTextView ;
73
+ private TextView mUrlTextView , mDebugInfoTextView ;
70
74
private volatile boolean mAcitivityResumed = false ;
71
75
private KSYStreamerConfig .ENCODE_METHOD encode_method = KSYStreamerConfig .ENCODE_METHOD .SOFTWARE ;
72
76
public final static String URL = "url" ;
@@ -83,15 +87,18 @@ public class CameraActivity extends Activity {
83
87
public final static String FRONT_CAMERA_MIRROR = "front_camera_mirror" ;
84
88
public final static String TEST_SW_FILTER = "testSWFilterInterface" ;
85
89
public final static String MANUAL_FOCUS = "manual_focus" ;
90
+ public static final String SHOW_DEBUGINFO = "SHOW_DEBUGINFO" ;
86
91
92
+ Timer timer ;
87
93
ExecutorService executorService = Executors .newSingleThreadExecutor ();
94
+
88
95
private int frameCount ;
89
96
private boolean testSWFilterInterface ;
90
97
91
98
public static void startActivity (Context context , int fromType ,
92
99
String rtmpUrl , int frameRate , int videoBitrate , int audioBitrate ,
93
100
int videoResolution , boolean encodeWithHEVC , boolean isLandscape , boolean mute_audio , boolean audio_mix , boolean isFrontCameraMirror , KSYStreamerConfig .ENCODE_METHOD encodeMethod , boolean startAuto ,
94
- boolean testSWFilterInterface , boolean manualFocus ) {
101
+ boolean testSWFilterInterface , boolean manualFocus , boolean showDebugInfo ) {
95
102
Intent intent = new Intent (context , CameraActivity .class );
96
103
intent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
97
104
intent .putExtra ("type" , fromType );
@@ -109,6 +116,7 @@ public static void startActivity(Context context, int fromType,
109
116
intent .putExtra (FRONT_CAMERA_MIRROR , isFrontCameraMirror );
110
117
intent .putExtra (TEST_SW_FILTER , testSWFilterInterface );
111
118
intent .putExtra (MANUAL_FOCUS , manualFocus );
119
+ intent .putExtra (SHOW_DEBUGINFO , showDebugInfo );
112
120
context .startActivity (intent );
113
121
}
114
122
@@ -149,6 +157,7 @@ public void handleMessage(Message msg) {
149
157
chronometer .start ();
150
158
mShootingText .setText (STOP_STRING );
151
159
mShootingText .postInvalidate ();
160
+ beginInfoUploadTimer ();
152
161
break ;
153
162
case RecorderConstants .KSYVIDEO_ENCODED_FRAMES_THRESHOLD :
154
163
chronometer .stop ();
@@ -204,8 +213,8 @@ public void handleMessage(Message msg) {
204
213
int videoBitrate = bundle .getInt (VIDEO_BITRATE , 0 );
205
214
if (videoBitrate > 0 ) {
206
215
builder .setMaxAverageVideoBitrate (videoBitrate );
207
- builder .setMinAverageVideoBitrate (videoBitrate * 3 / 5 );
208
- builder .setInitAverageVideoBitrate (videoBitrate * 4 / 5 );
216
+ builder .setMinAverageVideoBitrate (videoBitrate * 2 / 8 );
217
+ builder .setInitAverageVideoBitrate (videoBitrate * 5 / 8 );
209
218
}
210
219
211
220
int audioBitrate = bundle .getInt (AUDIO_BITRATE , 0 );
@@ -228,9 +237,8 @@ public void handleMessage(Message msg) {
228
237
builder .setSecretKeySign (skSign );
229
238
builder .setTimeSecond (timeSec );
230
239
231
- builder .setAudioChannels (1 );
232
240
builder .setSampleAudioRateInHz (44100 );
233
- // builder.setEnableStreamStatModule(false );
241
+ builder .setEnableStreamStatModule (true );
234
242
235
243
boolean landscape = bundle .getBoolean (LANDSCAPE , false );
236
244
builder .setDefaultLandscape (landscape );
@@ -250,6 +258,7 @@ public void handleMessage(Message msg) {
250
258
testSWFilterInterface = bundle .getBoolean (TEST_SW_FILTER , false );
251
259
boolean focus_manual = bundle .getBoolean (MANUAL_FOCUS , false );
252
260
builder .setManualFocus (focus_manual );
261
+ printDebugInfo = bundle .getBoolean (SHOW_DEBUGINFO , false );
253
262
}
254
263
255
264
mStreamer = new KSYStreamer (this );
@@ -258,8 +267,8 @@ public void handleMessage(Message msg) {
258
267
mStreamer .setOnStatusListener (mOnErrorListener );
259
268
mStreamer .setOnLogListener (mOnLogListener );
260
269
mStreamer .setOnNoiseSuppressionListener (mOnNsListener );
261
- mStreamer .enableDebugLog (false );
262
-
270
+ mStreamer .enableDebugLog (true );
271
+ mStreamer . setBeautyFilter ( RecorderConstants . FILTER_BEAUTY_DENOISE );
263
272
if (testSWFilterInterface ) {
264
273
mStreamer .setOnPreviewFrameListener (new OnPreviewFrameListener () {
265
274
@ Override
@@ -343,7 +352,39 @@ public void onClick(View arg0) {
343
352
mFlashView .setEnabled (true );
344
353
345
354
chronometer = (Chronometer ) this .findViewById (R .id .chronometer );
355
+ mDebugInfoTextView = (TextView ) this .findViewById (R .id .debuginfo );
356
+
357
+
358
+ }
359
+
360
+ private void beginInfoUploadTimer () {
361
+ if (printDebugInfo && timer == null ) {
362
+ timer = new Timer ();
363
+ timer .schedule (new TimerTask () {
364
+ @ Override
365
+ public void run () {
366
+ updateDebugInfo ();
367
+ runOnUiThread (new Runnable () {
368
+ @ Override
369
+ public void run () {
370
+ mDebugInfoTextView .setText (mDebugInfo );
371
+ }
372
+ });
373
+ }
374
+ }, 100 , 3000 );
375
+ }
376
+ }
346
377
378
+ private void updateDebugInfo () {
379
+ if (mStreamer == null ) return ;
380
+ mDebugInfo = String .format ("RtmpHostIP()=%s DroppedFrameCount()=%d \n " +
381
+ "ConnectTime()=%d DnsParseTime()=%d \n " +
382
+ "UploadedKB()=%d EncodedFrames()=%d \n " +
383
+ "CurrentBitrate=%f Version()=%s" ,
384
+ mStreamer .getRtmpHostIP (), mStreamer .getDroppedFrameCount (),
385
+ mStreamer .getConnectTime (), mStreamer .getDnsParseTime (),
386
+ mStreamer .getUploadedKBytes (), mStreamer .getEncodedFrames (),
387
+ mStreamer .getCurrentBitrate (), mStreamer .getVersion ());
347
388
}
348
389
349
390
@@ -539,6 +580,9 @@ public void onDestroy() {
539
580
mHandler .removeCallbacksAndMessages (null );
540
581
mHandler = null ;
541
582
}
583
+ if (timer != null ) {
584
+ timer .cancel ();
585
+ }
542
586
}
543
587
544
588
protected int mStopTime = 0 ;
@@ -628,9 +672,6 @@ public void onClick(View view) {
628
672
}
629
673
}
630
674
631
- private void printLog () {
632
- Log .e (TAG , String .format ("getRtmpHostIP()=%s getDroppedFrameCount()=%d getConnectTime()=%d getDnsParseTime()=%d " , mStreamer .getRtmpHostIP (), mStreamer .getDroppedFrameCount (), mStreamer .getConnectTime (), mStreamer .getDnsParseTime ()));
633
- }
634
675
635
676
private String md5 (String string ) {
636
677
byte [] hash ;
0 commit comments