Skip to content

Commit 2086fca

Browse files
SRTPlayer に通信情報を通知するイベントを追加
1 parent 66a0ba0 commit 2086fca

3 files changed

Lines changed: 67 additions & 8 deletions

File tree

dConnectSDK/dConnectLibStreaming/libsrt/src/main/java/org/deviceconnect/android/libsrt/client/SRTClient.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import android.util.Log;
44

5+
import org.deviceconnect.android.libsrt.BuildConfig;
56
import org.deviceconnect.android.libsrt.SRTSocket;
67
import org.deviceconnect.android.libsrt.SRTSocketException;
78
import org.deviceconnect.android.libsrt.SRTStats;
89

9-
import java.io.IOException;
1010
import java.util.Map;
1111
import java.util.Timer;
1212
import java.util.TimerTask;
@@ -20,6 +20,11 @@ public class SRTClient {
2020
*/
2121
static final long DEFAULT_STATS_INTERVAL = 5000;
2222

23+
/**
24+
* デバッグ用タグ.
25+
*/
26+
private static final boolean DEBUG = BuildConfig.DEBUG;
27+
2328
/**
2429
* タグ.
2530
*/
@@ -199,8 +204,11 @@ public void run() {
199204
if (mSRTSessionThread != null) {
200205
SRTSocket socket = mSRTSessionThread.mSRTSocket;
201206
if (socket != null) {
202-
SRTStats stats = socket.getStats();
203-
Log.d(TAG, "stats: " + stats);
207+
SRTStats srtStats = socket.getStats();
208+
if (DEBUG) {
209+
Log.d(TAG, srtStats.toString());
210+
}
211+
postStats(srtStats);
204212
}
205213
}
206214
}
@@ -276,7 +284,7 @@ public void run() {
276284
}
277285

278286
mSRTSocket.connect(mAddress, mPort);
279-
} catch (IOException e) {
287+
} catch (Exception e) {
280288
postOnError(e);
281289
return;
282290
}
@@ -333,12 +341,18 @@ private void postOnDisconnected() {
333341
}
334342
}
335343

336-
private void postOnError(IOException e) {
344+
private void postOnError(Exception e) {
337345
if (mOnEventListener != null) {
338346
mOnEventListener.onError(e);
339347
}
340348
}
341349

350+
private void postStats(SRTStats stats) {
351+
if (mOnEventListener != null) {
352+
mOnEventListener.onStats(stats);
353+
}
354+
}
355+
342356
public interface OnEventListener {
343357
/**
344358
* SRT サーバに接続されたことを通知します.
@@ -368,6 +382,13 @@ public interface OnEventListener {
368382
*
369383
* @param e 失敗原因の例外
370384
*/
371-
void onError(IOException e);
385+
void onError(Exception e);
386+
387+
/**
388+
* SRT サーバとの通信状況を通知します.
389+
*
390+
* @param stats 通信統計情報
391+
*/
392+
void onStats(SRTStats stats);
372393
}
373394
}

dConnectSDK/dConnectLibStreaming/libsrt/src/main/java/org/deviceconnect/android/libsrt/client/SRTPlayer.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package org.deviceconnect.android.libsrt.client;
22

33
import android.net.Uri;
4+
import android.util.Log;
45
import android.view.Surface;
56

67
import org.deviceconnect.android.libmedia.streaming.mpeg2ts.TsConstants;
78
import org.deviceconnect.android.libmedia.streaming.mpeg2ts.TsPacketExtractor;
89
import org.deviceconnect.android.libsrt.BuildConfig;
10+
import org.deviceconnect.android.libsrt.SRTStats;
911
import org.deviceconnect.android.libsrt.client.decoder.audio.AACDecoder;
1012
import org.deviceconnect.android.libsrt.client.decoder.audio.AudioDecoder;
1113
import org.deviceconnect.android.libsrt.client.decoder.video.H264Decoder;
1214
import org.deviceconnect.android.libsrt.client.decoder.video.H265Decoder;
1315
import org.deviceconnect.android.libsrt.client.decoder.video.VideoDecoder;
1416

15-
import java.io.IOException;
1617
import java.util.Map;
1718

1819
/**
@@ -249,6 +250,12 @@ private void postOnError(Exception e) {
249250
}
250251
}
251252

253+
private void postOnStats(SRTStats stats) {
254+
if (mOnEventListener != null) {
255+
mOnEventListener.onStats(stats);
256+
}
257+
}
258+
252259
/**
253260
* デコーダを作成します.
254261
*
@@ -260,6 +267,16 @@ private synchronized void createDecoder(int streamType) {
260267
case TsConstants.STREAM_TYPE_VIDEO_H265:
261268
{
262269
if (mVideoDecoder != null) {
270+
if (DEBUG) {
271+
Log.w(TAG, "VideoDecoder has already existed.");
272+
}
273+
return;
274+
}
275+
276+
if (mSurface == null) {
277+
if (DEBUG) {
278+
Log.w(TAG, "Surface is not set.");
279+
}
263280
return;
264281
}
265282

@@ -277,8 +294,12 @@ private synchronized void createDecoder(int streamType) {
277294
case TsConstants.STREAM_TYPE_AUDIO_AAC:
278295
{
279296
if (mAudioDecoder != null) {
297+
if (DEBUG) {
298+
Log.w(TAG, "AudioEncoder has already existed.");
299+
}
280300
return;
281301
}
302+
282303
mAudioDecoder = new AACDecoder();
283304
mAudioDecoder.setErrorCallback(SRTPlayer.this::postOnError);
284305
mAudioDecoder.onInit();
@@ -330,9 +351,14 @@ public void onDisconnected() {
330351
}
331352

332353
@Override
333-
public void onError(IOException e) {
354+
public void onError(Exception e) {
334355
postOnError(e);
335356
}
357+
358+
@Override
359+
public void onStats(SRTStats stats) {
360+
postOnStats(stats);
361+
}
336362
};
337363

338364
private final TsPacketExtractor.Callback mCallback = new TsPacketExtractor.Callback() {
@@ -386,5 +412,12 @@ public interface OnEventListener {
386412
* @param e エラー原因の例外
387413
*/
388414
void onError(Exception e);
415+
416+
/**
417+
* SRT サーバとの通信状況を通知します.
418+
*
419+
* @param stats 通信統計情報
420+
*/
421+
void onStats(SRTStats stats);
389422
}
390423
}

dConnectSDK/dConnectLibStreaming/srt-player-app/src/main/java/org/deviceconnect/android/srt_player_app/SRTPlayerActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.widget.ProgressBar;
1111

1212
import org.deviceconnect.android.libsrt.SRT;
13+
import org.deviceconnect.android.libsrt.SRTStats;
1314
import org.deviceconnect.android.libsrt.client.SRTPlayer;
1415

1516
import java.util.HashMap;
@@ -105,6 +106,10 @@ public void onError(Exception e) {
105106
Log.e("SRT-PLAYER", "Error", e);
106107
showErrorDialog("エラー", e.getMessage());
107108
}
109+
110+
@Override
111+
public void onStats(SRTStats stats) {
112+
}
108113
});
109114
mSRTPlayer.start();
110115
}

0 commit comments

Comments
 (0)