Seperate handler from thread to UI
Signed-off-by: Leo Ma <begeekmyfriend@gmail.com>camera2
parent
a1050c902b
commit
0c24613585
@ -0,0 +1,55 @@
|
||||
package net.ossrs.yasea;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* Created by leo.ma on 2016/11/4.
|
||||
*/
|
||||
|
||||
public class SrsNetworkHandler extends Handler {
|
||||
private static final int MSG_NETWORK_WEAK = 0;
|
||||
private static final int MSG_NETWORK_RESUME = 1;
|
||||
|
||||
private WeakReference<SrsNetworkListener> mWeakListener;
|
||||
|
||||
public SrsNetworkHandler(SrsNetworkListener listener) {
|
||||
mWeakListener = new WeakReference<>(listener);
|
||||
}
|
||||
|
||||
public void notifyNetworkWeak() {
|
||||
sendEmptyMessage(MSG_NETWORK_WEAK);
|
||||
}
|
||||
|
||||
public void notifyNetworkResume() {
|
||||
sendEmptyMessage(MSG_NETWORK_RESUME);
|
||||
}
|
||||
|
||||
@Override // runs on UI thread
|
||||
public void handleMessage(Message msg) {
|
||||
SrsNetworkListener listener = mWeakListener.get();
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg.what) {
|
||||
case MSG_NETWORK_WEAK:
|
||||
listener.onNetworkWeak();
|
||||
break;
|
||||
case MSG_NETWORK_RESUME:
|
||||
listener.onNetworkResume();
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("unknown msg " + msg.what);
|
||||
}
|
||||
}
|
||||
|
||||
interface SrsNetworkListener {
|
||||
|
||||
void onNetworkWeak();
|
||||
|
||||
void onNetworkResume();
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package net.ossrs.yasea;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* Created by leo.ma on 2016/11/4.
|
||||
*/
|
||||
|
||||
public class SrsRecordHandler extends Handler {
|
||||
private static final int MSG_RECORD_PAUSE = 0;
|
||||
private static final int MSG_RECORD_RESUME = 1;
|
||||
private static final int MSG_RECORD_STARTED = 2;
|
||||
private static final int MSG_RECORD_FINISHED = 3;
|
||||
|
||||
private WeakReference<SrsRecordListener> mWeakListener;
|
||||
|
||||
SrsRecordHandler(SrsRecordListener listener) {
|
||||
mWeakListener = new WeakReference<>(listener);
|
||||
}
|
||||
|
||||
public void notifyRecordPause() {
|
||||
sendEmptyMessage(MSG_RECORD_PAUSE);
|
||||
}
|
||||
|
||||
public void notifyRecordResume() {
|
||||
sendEmptyMessage(MSG_RECORD_RESUME);
|
||||
}
|
||||
|
||||
public void notifyRecordStarted(String msg) {
|
||||
obtainMessage(MSG_RECORD_STARTED, msg).sendToTarget();
|
||||
}
|
||||
|
||||
public void notifyRecordFinished(String msg) {
|
||||
obtainMessage(MSG_RECORD_FINISHED, msg).sendToTarget();
|
||||
}
|
||||
|
||||
@Override // runs on UI thread
|
||||
public void handleMessage(Message msg) {
|
||||
SrsRecordListener listener = mWeakListener.get();
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg.what) {
|
||||
case MSG_RECORD_PAUSE:
|
||||
listener.onRecordPause();
|
||||
break;
|
||||
case MSG_RECORD_RESUME:
|
||||
listener.onRecordResume();
|
||||
break;
|
||||
case MSG_RECORD_STARTED:
|
||||
listener.onRecordStarted((String) msg.obj);
|
||||
break;
|
||||
case MSG_RECORD_FINISHED:
|
||||
listener.onRecordFinished((String) msg.obj);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("unknown msg " + msg.what);
|
||||
}
|
||||
}
|
||||
|
||||
interface SrsRecordListener {
|
||||
|
||||
void onRecordPause();
|
||||
|
||||
void onRecordResume();
|
||||
|
||||
void onRecordStarted(String msg);
|
||||
|
||||
void onRecordFinished(String msg);
|
||||
}
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
package net.ossrs.yasea.rtmp;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* Created by leo.ma on 2016/11/3.
|
||||
*/
|
||||
|
||||
public class RtmpHandler extends Handler {
|
||||
|
||||
private static final int MSG_RTMP_CONNECTING = 0;
|
||||
private static final int MSG_RTMP_CONNECTED = 1;
|
||||
private static final int MSG_RTMP_VIDEO_STREAMING = 2;
|
||||
private static final int MSG_RTMP_AUDIO_STREAMING = 3;
|
||||
private static final int MSG_RTMP_STOPPED = 4;
|
||||
private static final int MSG_RTMP_DISCONNECTED = 5;
|
||||
private static final int MSG_RTMP_VIDEO_FPS_CHANGED = 6;
|
||||
private static final int MSG_RTMP_VIDEO_BITRATE_CHANGED = 7;
|
||||
private static final int MSG_RTMP_AUDIO_BITRATE_CHANGED = 8;
|
||||
|
||||
private WeakReference<RtmpListener> mWeakListener;
|
||||
|
||||
public RtmpHandler(RtmpListener listener) {
|
||||
mWeakListener = new WeakReference<>(listener);
|
||||
}
|
||||
|
||||
public void notifyRtmpConnecting(String msg) {
|
||||
obtainMessage(MSG_RTMP_CONNECTING, msg).sendToTarget();
|
||||
}
|
||||
|
||||
public void notifyRtmpConnected(String msg) {
|
||||
obtainMessage(MSG_RTMP_CONNECTED, msg).sendToTarget();
|
||||
}
|
||||
|
||||
public void notifyRtmpVideoStreaming() {
|
||||
sendEmptyMessage(MSG_RTMP_VIDEO_STREAMING);
|
||||
}
|
||||
|
||||
public void notifyRtmpAudioStreaming() {
|
||||
sendEmptyMessage(MSG_RTMP_AUDIO_STREAMING);
|
||||
}
|
||||
|
||||
public void notifyRtmpStopped() {
|
||||
sendEmptyMessage(MSG_RTMP_STOPPED);
|
||||
}
|
||||
|
||||
public void notifyRtmpDisconnected() {
|
||||
sendEmptyMessage(MSG_RTMP_DISCONNECTED);
|
||||
}
|
||||
|
||||
public void notifyRtmpVideoFpsChanged(double fps) {
|
||||
obtainMessage(MSG_RTMP_VIDEO_FPS_CHANGED, fps).sendToTarget();
|
||||
}
|
||||
|
||||
public void notifyRtmpVideoBitrateChanged(double bitrate) {
|
||||
obtainMessage(MSG_RTMP_VIDEO_BITRATE_CHANGED, bitrate).sendToTarget();
|
||||
}
|
||||
|
||||
public void notifyRtmpAudioBitrateChanged(double bitrate) {
|
||||
obtainMessage(MSG_RTMP_AUDIO_BITRATE_CHANGED, bitrate).sendToTarget();
|
||||
}
|
||||
|
||||
@Override // runs on UI thread
|
||||
public void handleMessage(Message msg) {
|
||||
RtmpListener listener = mWeakListener.get();
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg.what) {
|
||||
case MSG_RTMP_CONNECTING:
|
||||
listener.onRtmpConnecting((String) msg.obj);
|
||||
break;
|
||||
case MSG_RTMP_CONNECTED:
|
||||
listener.onRtmpConnected((String) msg.obj);
|
||||
break;
|
||||
case MSG_RTMP_VIDEO_STREAMING:
|
||||
listener.onRtmpVideoStreaming();
|
||||
break;
|
||||
case MSG_RTMP_AUDIO_STREAMING:
|
||||
listener.onRtmpAudioStreaming();
|
||||
break;
|
||||
case MSG_RTMP_STOPPED:
|
||||
listener.onRtmpStopped();
|
||||
break;
|
||||
case MSG_RTMP_DISCONNECTED:
|
||||
listener.onRtmpDisconnected();
|
||||
break;
|
||||
case MSG_RTMP_VIDEO_FPS_CHANGED:
|
||||
listener.onRtmpVideoFpsChanged((double) msg.obj);
|
||||
break;
|
||||
case MSG_RTMP_VIDEO_BITRATE_CHANGED:
|
||||
listener.onRtmpVideoBitrateChanged((double) msg.obj);
|
||||
break;
|
||||
case MSG_RTMP_AUDIO_BITRATE_CHANGED:
|
||||
listener.onRtmpAudioBitrateChanged((double) msg.obj);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("unknown msg " + msg.what);
|
||||
}
|
||||
}
|
||||
|
||||
public interface RtmpListener {
|
||||
|
||||
void onRtmpConnecting(String msg);
|
||||
|
||||
void onRtmpConnected(String msg);
|
||||
|
||||
void onRtmpVideoStreaming();
|
||||
|
||||
void onRtmpAudioStreaming();
|
||||
|
||||
void onRtmpStopped();
|
||||
|
||||
void onRtmpDisconnected();
|
||||
|
||||
void onRtmpVideoFpsChanged(double fps);
|
||||
|
||||
void onRtmpVideoBitrateChanged(double bitrate);
|
||||
|
||||
void onRtmpAudioBitrateChanged(double bitrate);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue