Merge branch 'live_sdk' of http://gitlab.zhidaoauto.com/ecos/app/MoGoAiCloudSdk into live_sdk
This commit is contained in:
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -26,7 +26,6 @@
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="useQualifiedModuleNames" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
@@ -11,6 +11,7 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveProgressListener;
|
||||
import com.mogo.cloud.live.manager.MoGoLiveManager;
|
||||
import com.mogo.cloud.util.Devices;
|
||||
|
||||
|
||||
public class LivePlayActivity extends AppCompatActivity {
|
||||
@@ -34,12 +35,11 @@ public class LivePlayActivity extends AppCompatActivity {
|
||||
Toast.makeText(getApplicationContext(), buttonView.getText(), Toast.LENGTH_SHORT).show();
|
||||
if (isChecked) {
|
||||
String roomId = etLookRoomId.getText().toString().trim();
|
||||
mStreamId = MoGoLiveManager.STREAM_ID_PREFIX + roomId;
|
||||
MoGoLiveManager.getInstance().init(this.getApplication(), null);
|
||||
MoGoLiveManager.getInstance().loginRoom("F803EB2046PZD00140", roomId);
|
||||
MoGoLiveManager.getInstance().loginRoom(Devices.getSn(), roomId);
|
||||
MoGoLiveManager.getInstance().setLiveProgressListener(listener);
|
||||
} else {
|
||||
MoGoLiveManager.getInstance().stopLive(mStreamId);
|
||||
MoGoLiveManager.getInstance().stopLive();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -83,12 +83,12 @@ public class LivePlayActivity extends AppCompatActivity {
|
||||
};
|
||||
|
||||
private void toggleLive(boolean isChecked) {
|
||||
Log.i(TAG, "toggleLive status : " + isChecked + " , mStreamId : " + mStreamId);
|
||||
if (isChecked) {
|
||||
MoGoLiveManager.getInstance().startLive(mStreamId, surfaceView);
|
||||
mStreamId = MoGoLiveManager.getInstance().startLive(surfaceView);
|
||||
} else {
|
||||
MoGoLiveManager.getInstance().stopLive(mStreamId);
|
||||
MoGoLiveManager.getInstance().stopLive();
|
||||
}
|
||||
Log.i(TAG, "toggleLive status : " + isChecked + " , mStreamId : " + mStreamId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.mogo.cloud;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.cloud.live.manager.CameraFrameManager;
|
||||
import com.mogo.cloud.live.manager.ILiveStreamManager;
|
||||
@@ -21,7 +20,6 @@ public class LivePushActivity extends BaseLiveActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// 初始化直播流管理
|
||||
ILiveStreamManager liveStreamManager = LiveStreamManagerImpl.getInstance(this, Devices.getSn());
|
||||
liveStreamManager.uploadCamStatus(1, 1);
|
||||
@@ -29,22 +27,13 @@ public class LivePushActivity extends BaseLiveActivity {
|
||||
|
||||
@Override
|
||||
public void onVideoFrame(byte[] bytes, int bytesLength) {
|
||||
if (!isLive) {
|
||||
return;
|
||||
}
|
||||
//Log.i(TAG, "onVideoFrame byte length: " + bytesLength);
|
||||
CameraFrameManager.getInstance().notifyYUVData(bytes, 1280, 720, 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleLive(boolean isLive) {
|
||||
Log.i(TAG, "toggleLive : " + isLive);
|
||||
this.isLive = isLive;
|
||||
// if (isLive) {
|
||||
// PushService.startService(this, PushService.ACTION_START_RTMP_PUSH, Devices.getSn());
|
||||
// } else {
|
||||
// PushService.startService(this, PushService.ACTION_STOP_RTMP_PUSH, null);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -103,7 +103,7 @@ public class CameraFrameManager {
|
||||
}
|
||||
|
||||
private void dispatchData(byte[] data) {
|
||||
if (globalDataListener != null && globalDataListener.size() > 0) {
|
||||
if (globalDataListener.size() > 0) {
|
||||
for (IYUVDataListener callback : globalDataListener) {
|
||||
if (callback != null) {
|
||||
callback.onFrame(data);
|
||||
|
||||
@@ -2,10 +2,12 @@ package com.mogo.cloud.live.manager;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveProgressListener;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -88,6 +90,10 @@ public class MoGoLiveManager {
|
||||
* 当前的房间ID
|
||||
*/
|
||||
private String currentRoomId = "";
|
||||
/**
|
||||
* 当前直播流ID
|
||||
*/
|
||||
private String currentStreamId = "";
|
||||
/**
|
||||
* 自定义采集状态,true-初始化完成,false-没有初始化
|
||||
*/
|
||||
@@ -288,8 +294,11 @@ public class MoGoLiveManager {
|
||||
public void loginRoom(String userId, String roomId) {
|
||||
initCustomVideoCapture();
|
||||
currentRoomId = ROOM_ID_PREFIX + roomId;
|
||||
currentStreamId = STREAM_ID_PREFIX + roomId;
|
||||
ZegoUser zegoUser = new ZegoUser(userId, NAME_PREFIX + userId);
|
||||
mExpressEngine.loginRoom(currentRoomId, zegoUser);
|
||||
Log.i(TAG, "loginRoom userId:" + userId + " currentRoomId : " + currentRoomId
|
||||
+ " currentStreamId:" + currentStreamId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -373,22 +382,26 @@ public class MoGoLiveManager {
|
||||
/**
|
||||
* 开始直播
|
||||
*
|
||||
* @param streamId 直播流ID
|
||||
* @param surfaceView 渲染直播的视图
|
||||
*/
|
||||
public void startLive(String streamId, SurfaceView surfaceView) {
|
||||
ZegoCanvas zegoCanvas = new ZegoCanvas(surfaceView);
|
||||
zegoCanvas.viewMode = ZegoViewMode.SCALE_TO_FILL;
|
||||
mExpressEngine.startPlayingStream(streamId, zegoCanvas);
|
||||
public String startLive(SurfaceView surfaceView) {
|
||||
if (!TextUtils.isEmpty(currentStreamId) &&
|
||||
!currentStreamId.equals(STREAM_ID_PREFIX)) {
|
||||
ZegoCanvas zegoCanvas = new ZegoCanvas(surfaceView);
|
||||
zegoCanvas.viewMode = ZegoViewMode.SCALE_TO_FILL;
|
||||
mExpressEngine.startPlayingStream(currentStreamId, zegoCanvas);
|
||||
} else {
|
||||
Logger.e(TAG, "直播ID有误,请重试");
|
||||
}
|
||||
|
||||
return currentStreamId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止直播
|
||||
*
|
||||
* @param streamId 数据流ID
|
||||
*/
|
||||
public void stopLive(String streamId) {
|
||||
mExpressEngine.stopPlayingStream(streamId);
|
||||
public void stopLive() {
|
||||
mExpressEngine.stopPlayingStream(currentStreamId);
|
||||
stopPreview();
|
||||
logOutRoom();
|
||||
}
|
||||
@@ -459,7 +472,6 @@ public class MoGoLiveManager {
|
||||
* 停止观看直播
|
||||
*/
|
||||
public void onDestroyLive() {
|
||||
stopPreview();
|
||||
logOutRoom();
|
||||
destroyEngine();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.mogo.cloud.live.model;
|
||||
|
||||
public class CommandModel {
|
||||
private int type;
|
||||
private String videoChannel;
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getVideoChannel() {
|
||||
return videoChannel;
|
||||
}
|
||||
|
||||
public void setVideoChannel(String videoChannel) {
|
||||
this.videoChannel = videoChannel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CommandModel{" +
|
||||
"type=" + type +
|
||||
", videoChannel='" + videoChannel + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import com.mogo.cloud.socket.SocketManager;
|
||||
/**
|
||||
* Socket常链接工具类
|
||||
*/
|
||||
public class SocketMsgUtils implements IMogoCloudSocketMsgAckListener, IMogoCloudSocketOnMessageListener {
|
||||
public class SocketMsgUtils implements IMogoCloudSocketMsgAckListener {
|
||||
private static final String TAG = "SocketMsgUtils";
|
||||
|
||||
private static final String appId = "liveStream";
|
||||
@@ -21,30 +21,33 @@ public class SocketMsgUtils implements IMogoCloudSocketMsgAckListener, IMogoClou
|
||||
|
||||
private SocketManager mSocketManager;
|
||||
private Context mContext;
|
||||
private IMogoCloudSocketOnMessageListener mMessageListener;
|
||||
|
||||
public static SocketMsgUtils getInstance(Context context) {
|
||||
public static SocketMsgUtils getInstance(Context context, IMogoCloudSocketOnMessageListener listener) {
|
||||
if (sInstance == null) {
|
||||
synchronized (SocketMsgUtils.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new SocketMsgUtils(context.getApplicationContext());
|
||||
sInstance = new SocketMsgUtils(context.getApplicationContext(), listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private SocketMsgUtils(Context context) {
|
||||
private SocketMsgUtils(Context context, IMogoCloudSocketOnMessageListener listener) {
|
||||
mContext = context;
|
||||
initSocket();
|
||||
initSocket(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化长连接
|
||||
*/
|
||||
private void initSocket() {
|
||||
private void initSocket(IMogoCloudSocketOnMessageListener listener) {
|
||||
Log.i(TAG, "初始化长连接……");
|
||||
mSocketManager = SocketManager.getInstance();
|
||||
mMessageListener = listener;
|
||||
mSocketManager.init(mContext);
|
||||
mSocketManager.registerOnMessageListener(401016, this);
|
||||
mSocketManager.registerOnMessageListener(401017, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,21 +64,11 @@ public class SocketMsgUtils implements IMogoCloudSocketMsgAckListener, IMogoClou
|
||||
*/
|
||||
public void release() {
|
||||
mSocketManager.release();
|
||||
mSocketManager.unregisterOnMessageListener(401017, mMessageListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAck(long msgId) {
|
||||
Log.i(TAG, "msgId=" + msgId);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class target() {
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMsgReceived(Object obj) {
|
||||
Log.i(TAG, "onMsgReceived: obj=" + obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,27 +4,25 @@ import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.cloud.live.listener.BizMessageListener;
|
||||
import com.mogo.cloud.live.listener.ILiveStatusListener;
|
||||
import com.mogo.cloud.live.manager.CameraFrameManager;
|
||||
import com.mogo.cloud.live.manager.LiveStreamManagerImpl;
|
||||
import com.mogo.cloud.live.model.CommandModel;
|
||||
import com.mogo.cloud.live.server.PushService;
|
||||
import com.mogo.cloud.live.socket.IotMessageType;
|
||||
import com.mogo.cloud.live.socket.SocketMsgUtils;
|
||||
import com.mogo.cloud.live.socket.SocketRequestUtils;
|
||||
import com.mogo.cloud.socket.IMogoCloudSocketOnMessageListener;
|
||||
import com.mogo.cloud.socket.MsgBody;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import static com.mogo.cloud.live.socket.IotMessageType.MSG_LIVE_PUSH_STATUS;
|
||||
|
||||
|
||||
public class LiveStreamUtils implements BizMessageListener {
|
||||
public class LiveStreamUtils implements IMogoCloudSocketOnMessageListener<CommandModel> {
|
||||
private static final String TAG = "LiveStreamUtils";
|
||||
private static final int POLL_TIME = 30 * 1000;
|
||||
// 循环上报摄像头可直播状态间隔时间
|
||||
private static final int PUSH_CAM_TIME = 10 * 1000;
|
||||
private static final int PUSH_CAM_TIME = 10 * 60 * 1000;
|
||||
// 开始
|
||||
private static final int PUSH_START = 0;
|
||||
// 结束
|
||||
private static final int PUSH_STOP = 1;
|
||||
private static final String C1 = "C_1"; //前置摄像头
|
||||
private static final String C2 = "C_2"; //后置摄像头
|
||||
@@ -37,6 +35,7 @@ public class LiveStreamUtils implements BizMessageListener {
|
||||
private ILiveStatusListener mLiveStatusCallback;
|
||||
private Context mContext;
|
||||
private Handler mHandler;
|
||||
private SocketMsgUtils mSocketMsgUtils;
|
||||
|
||||
public static LiveStreamUtils getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
@@ -56,13 +55,12 @@ public class LiveStreamUtils implements BizMessageListener {
|
||||
initPoll();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
private void init() {
|
||||
// 初始化Socket长连接通道
|
||||
SocketMsgUtils.getInstance(mContext);
|
||||
mSocketMsgUtils = SocketMsgUtils.getInstance(mContext, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,28 +100,16 @@ public class LiveStreamUtils implements BizMessageListener {
|
||||
msgBody.msgType(196614);
|
||||
msgBody.content(SocketRequestUtils.buildDeviceData(cam1Status, cam2Status));
|
||||
|
||||
SocketMsgUtils.getInstance(mContext).uploadCamInfo(msgBody);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(IotMessageType type, String content) {
|
||||
if (type == MSG_LIVE_PUSH_STATUS) {
|
||||
Log.d(TAG, content);
|
||||
rtmpPushHandler(content);
|
||||
}
|
||||
mSocketMsgUtils.uploadCamInfo(msgBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收到长连接指令
|
||||
*
|
||||
* @param str 指令数据
|
||||
* @param videoChannel 指令数据
|
||||
*/
|
||||
private void rtmpPushHandler(String str) {
|
||||
private void rtmpPushHandler(int status, String videoChannel) {
|
||||
try {
|
||||
JSONObject content = new JSONObject(str);
|
||||
int status = content.optInt("status");
|
||||
String videoChannel = content.optString("videoChannel");
|
||||
|
||||
// 前置摄像头
|
||||
if (C1.equals(videoChannel)) {
|
||||
// 停止直播
|
||||
@@ -197,9 +183,20 @@ public class LiveStreamUtils implements BizMessageListener {
|
||||
try {
|
||||
sCam1LiveStatus = 0;
|
||||
sCam2LiveStatus = 0;
|
||||
SocketMsgUtils.getInstance(mContext).release();
|
||||
mSocketMsgUtils.release();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<CommandModel> target() {
|
||||
return CommandModel.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMsgReceived(CommandModel obj) {
|
||||
Log.i(TAG, "onMsgReceived: obj=" + obj);
|
||||
rtmpPushHandler(obj.getType(), obj.getVideoChannel());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class MoGoAiCloudClient {
|
||||
|
||||
// 变量赋值
|
||||
if (mAiCloudClientConfig != null) {
|
||||
mAiCloudClientConfig.setSn(result.sn);
|
||||
mAiCloudClientConfig.setSn("F803EB2046PZD00149");
|
||||
mAiCloudClientConfig.setToken(result.token);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user