pull code of origin
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
-keep class com.mogo.realtime.entity.*{*;}
|
||||
-keep class com.mogo.realtime.Interface.*{*;}
|
||||
-keep class com.mogo.realtime.api.*{*;}
|
||||
-keep class com.mogo.realtime.socket.IMogoCloudOnMsgListener{*;}
|
||||
-keep class com.mogo.realtime.socket.IMogoCloudOnAckListener{*;}
|
||||
-keep class com.mogo.realtime.util.MogoLatLng{*;}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mogo.realtime.Interface;
|
||||
package com.mogo.realtime.api;
|
||||
|
||||
import com.mogo.realtime.entity.ADASRecognizedResult;
|
||||
import com.mogo.realtime.entity.CloudLocationInfo;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mogo.realtime.Interface;
|
||||
package com.mogo.realtime.api;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.mogo.realtime.constant;
|
||||
|
||||
public class RealTimeConstant {
|
||||
|
||||
public static final String TAG = "MoGoAiCloud_RealTime";
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.mogo.realtime.core;
|
||||
|
||||
import android.os.SystemClock;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import android.support.annotation.Keep;
|
||||
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.realtime.entity.CloudLocationInfo;
|
||||
import com.mogo.realtime.util.MogoLatLng;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
@@ -39,7 +39,9 @@ public class SimpleLocationCorrectStrategy {
|
||||
private final List<CloudLocationInfo> errList = new ArrayList<>();
|
||||
|
||||
public CloudLocationInfo correct(CloudLocationInfo info) {
|
||||
Logger.d(TAG, "info: " + info.print());
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Logger.d(TAG, "info: " + info.print());
|
||||
}
|
||||
if (isLocationValid(info)) {
|
||||
if (recordLocation()) {
|
||||
historyList.add(info);
|
||||
@@ -48,29 +50,36 @@ public class SimpleLocationCorrectStrategy {
|
||||
if (lastLocation == null) {
|
||||
lastLocation = info;
|
||||
anchorTime = SystemClock.elapsedRealtime();
|
||||
Logger.d(TAG, "第一条数据");
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Logger.d(TAG, "第一条数据");
|
||||
}
|
||||
if (recordLocation()) {
|
||||
validList.add(lastLocation);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
if (lastLocation.equals(info)) {
|
||||
Logger.d(TAG, "相同坐标点==");
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Logger.d(TAG, "相同坐标点==");
|
||||
}
|
||||
return info;
|
||||
}
|
||||
try {
|
||||
float targetDistance =
|
||||
(float) (lastLocation.getSpeed() * (SystemClock.elapsedRealtime() - anchorTime) / 1000) + TARGET_DISTANCE_DEVIATION;
|
||||
float distance = CoordinateUtils.calculateLineDistance(lastLocation.getLon(), lastLocation.getLat(), info.getLon(), info.getLat());
|
||||
Logger.d(TAG,
|
||||
"准备计算{ lastInfo: " + lastLocation.print() + " info: " + info.print() + " targetDistance: " + targetDistance + " distance : " + distance + "}");
|
||||
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Logger.d(TAG,
|
||||
"准备计算{ lastInfo: " + lastLocation.print() + " info: " + info.print() + " targetDistance: " + targetDistance + " distance : " + distance + "}");
|
||||
}
|
||||
if (distance <= targetDistance) {
|
||||
// 新的定位点在目标距离范围内,认为此数据有效
|
||||
lastLocation = info;
|
||||
anchorTime = SystemClock.elapsedRealtime();
|
||||
errCount = 0;
|
||||
Logger.d(TAG, "在范围内,为有效点");
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Logger.d(TAG, "在范围内,为有效点");
|
||||
}
|
||||
if (recordLocation()) {
|
||||
validList.add(lastLocation);
|
||||
}
|
||||
@@ -86,7 +95,9 @@ public class SimpleLocationCorrectStrategy {
|
||||
lastLocation = info;
|
||||
anchorTime = SystemClock.elapsedRealtime();
|
||||
errCount = 0;
|
||||
Logger.d(TAG, "出错次数超限,异常点变有效点");
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Logger.d(TAG, "出错次数超限,异常点变有效点");
|
||||
}
|
||||
return info;
|
||||
} else {
|
||||
// 按照上一个点的方向和速度,计算下一个点的位置,下一个点除坐标点外,其余数据与上一个点相同
|
||||
@@ -102,7 +113,9 @@ public class SimpleLocationCorrectStrategy {
|
||||
lastLocation = nextInfo;
|
||||
anchorTime = SystemClock.elapsedRealtime();
|
||||
errCount++;
|
||||
Logger.d(TAG, "异常点纠偏 info: " + lastLocation);
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Logger.d(TAG, "异常点纠偏 info: " + lastLocation);
|
||||
}
|
||||
if (recordLocation()) {
|
||||
correctList.add(nextInfo);
|
||||
}
|
||||
@@ -110,11 +123,15 @@ public class SimpleLocationCorrectStrategy {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, e, "纠偏异常");
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Logger.e(TAG, e, "纠偏异常");
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
Logger.d(TAG, "定位点异常");
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Logger.d(TAG, "定位点异常");
|
||||
}
|
||||
if (lastLocation == null) {
|
||||
return null;
|
||||
} else {
|
||||
@@ -122,8 +139,10 @@ public class SimpleLocationCorrectStrategy {
|
||||
float targetDistance =
|
||||
(float) (lastLocation.getSpeed() * (SystemClock.elapsedRealtime() - anchorTime) / 1000) + TARGET_DISTANCE_DEVIATION;
|
||||
float distance = CoordinateUtils.calculateLineDistance(lastLocation.getLon(), lastLocation.getLat(), info.getLon(), info.getLat());
|
||||
Logger.d(TAG,
|
||||
"异常定位点\n准备计算{ lastInfo: " + lastLocation.print() + " info: " + info.print() + " targetDistance: " + targetDistance + " distance : " + distance + "}");
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Logger.d(TAG,
|
||||
"异常定位点\n准备计算{ lastInfo: " + lastLocation.print() + " info: " + info.print() + " targetDistance: " + targetDistance + " distance : " + distance + "}");
|
||||
}
|
||||
// 按照上一个点的方向和速度,计算下一个点的位置,下一个点除坐标点外,其余数据与上一个点相同
|
||||
CloudLocationInfo nextInfo = new CloudLocationInfo(lastLocation);
|
||||
MogoLatLng nextLatLon = computerThatLonLat(lastLocation.getLon(),
|
||||
@@ -137,13 +156,17 @@ public class SimpleLocationCorrectStrategy {
|
||||
lastLocation = nextInfo;
|
||||
anchorTime = SystemClock.elapsedRealtime();
|
||||
errCount++;
|
||||
Logger.d(TAG, "异常点纠偏 info: " + lastLocation);
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Logger.d(TAG, "异常点纠偏 info: " + lastLocation);
|
||||
}
|
||||
if (recordLocation()) {
|
||||
correctList.add(nextInfo);
|
||||
}
|
||||
return nextInfo;
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, e, "纠偏异常");
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Logger.e(TAG, e, "纠偏异常");
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,9 @@ import com.mogo.realtime.socket.SocketHandler;
|
||||
*/
|
||||
public class SnapshotUploadInTime implements UploadInTimeHandler.IUploadInTimeListener {
|
||||
|
||||
private static final String TAG = "SnapshotUploadInTime";
|
||||
private static volatile SnapshotUploadInTime sInstance;
|
||||
//是否使用外部定位数据
|
||||
private boolean isUseExternalLocation = false;
|
||||
private final boolean isUseExternalLocation;
|
||||
|
||||
private SnapshotUploadInTime() {
|
||||
isUseExternalLocation = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getIsUseExternalLocation();
|
||||
|
||||
@@ -2,17 +2,17 @@ package com.mogo.realtime.core;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import android.support.annotation.Keep;
|
||||
|
||||
import com.mogo.utils.WorkThreadHandler;
|
||||
|
||||
import static com.mogo.realtime.constant.RealTimeConstant.TAG;
|
||||
|
||||
/**
|
||||
* AI云 实时上报数据频率处理类
|
||||
*/
|
||||
public class UploadInTimeHandler {
|
||||
|
||||
private static final String TAG = "UploadInTimeHandler";
|
||||
private static final int MSG_DATA_CHANGED = 0x100;
|
||||
private static final long MSG_DATA_INTERNAL = 500L;
|
||||
private final long uploadDelay = MSG_DATA_INTERNAL;
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.mogo.realtime.entity;
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import android.support.annotation.RequiresApi;
|
||||
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils;
|
||||
|
||||
|
||||
@@ -14,15 +14,16 @@ import com.mogo.utils.logger.Logger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mogo.realtime.constant.RealTimeConstant.TAG;
|
||||
|
||||
/**
|
||||
* AI云SDK内部定位服务
|
||||
*/
|
||||
public class MogoRTKLocation {
|
||||
|
||||
private static final String TAG = "MogoRTKLocation";
|
||||
|
||||
private LocationManager locationManager;
|
||||
private final List<CloudLocationInfo> cacheList = new ArrayList<>();
|
||||
private CloudLocationInfo locInfo;
|
||||
|
||||
public static MogoRTKLocation getInstance() {
|
||||
return RTKHolder.rtkLoc;
|
||||
@@ -38,7 +39,14 @@ public class MogoRTKLocation {
|
||||
|
||||
public List<CloudLocationInfo> sendLocationData() {
|
||||
List<CloudLocationInfo> list = new ArrayList<>(cacheList);
|
||||
if (cacheList != null && cacheList.size() > 0) {
|
||||
if (cacheList.size() == 0) {
|
||||
if (locInfo != null) {
|
||||
cacheList.add(locInfo);
|
||||
} else {
|
||||
Logger.e(TAG, "暂无定位数据");
|
||||
return list;
|
||||
}
|
||||
} else {
|
||||
cacheList.clear();
|
||||
}
|
||||
return list;
|
||||
@@ -78,7 +86,7 @@ public class MogoRTKLocation {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
private LocationListener locationListener = new LocationListener() {
|
||||
private final LocationListener locationListener = new LocationListener() {
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
if (location != null) {
|
||||
@@ -91,6 +99,7 @@ public class MogoRTKLocation {
|
||||
cloudLocationInfo.setSatelliteTime(location.getTime());
|
||||
cloudLocationInfo.setSystemTime(System.currentTimeMillis());
|
||||
cloudLocationInfo.convertCoor2GCJ02();
|
||||
locInfo = cloudLocationInfo;
|
||||
cacheList.add(cloudLocationInfo);
|
||||
} else {
|
||||
Logger.e(TAG, "location == null");
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mogo.realtime.socket;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.socket.IMogoCloudSocketOnMessageListener;
|
||||
@@ -17,7 +16,9 @@ import com.mogo.realtime.entity.MogoSnapshotSetData;
|
||||
import com.mogo.realtime.entity.OnePerSecondSendContent;
|
||||
import com.mogo.realtime.spi.RealTimeProviderImp;
|
||||
import com.mogo.realtime.util.MortonCode;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
import com.mogo.utils.GsonUtil;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidao.ptech.connsvr.protocol.MogoConnsvr;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -25,15 +26,19 @@ import java.util.List;
|
||||
import static com.mogo.cloud.socket.WebSocketMsgType.MSG_TYPE_ACK;
|
||||
import static com.mogo.cloud.socket.WebSocketMsgType.MSG_TYPE_DOWNLINK_CAR_DATA;
|
||||
import static com.mogo.cloud.socket.WebSocketMsgType.MSG_TYPE_UPLINK_CAR_DATA;
|
||||
import static com.mogo.realtime.constant.RealTimeConstant.TAG;
|
||||
|
||||
/**
|
||||
* Socket长链 业务服务处理类
|
||||
*/
|
||||
public class SocketHandler {
|
||||
|
||||
private static final String TAG = "SocketHandler";
|
||||
private static volatile SocketHandler mInstance;
|
||||
private static final int HEADER_TYPE = MogoConnsvr.MsgType.mogoMsgTypeCollectSvrNoRspReq.getNumber();
|
||||
private static final int HIGH_FREQUENCY_CHANNEL_ID = 0x040002; //高频数据
|
||||
private static final int LOW_FREQUENCY_CHANNEL_ID = 0x040003; //低频数据
|
||||
|
||||
private String mAppId;
|
||||
private long serverTime = 0;
|
||||
private long receiveMsgTime = 0;
|
||||
private CloudLocationInfo mLastInfo;
|
||||
@@ -58,12 +63,10 @@ public class SocketHandler {
|
||||
* @param appId 外部传入
|
||||
*/
|
||||
public void initSocket(Context context, String appId) {
|
||||
SocketManager.getInstance().init(context, appId);
|
||||
int msgType = 0x040003;
|
||||
Log.i(TAG,"msgType : " + msgType);
|
||||
Log.i(TAG,"msgType integer : " + (Integer)msgType);
|
||||
SocketManager.getInstance().registerOnMessageListener(0x040002, onMessageListener);
|
||||
SocketManager.getInstance().registerOnMessageListener(0x040003, onMessageListener);
|
||||
mAppId = appId;
|
||||
SocketManager.getInstance().init(context);
|
||||
SocketManager.getInstance().registerOnMessageListener(HIGH_FREQUENCY_CHANNEL_ID, onMessageListener);
|
||||
SocketManager.getInstance().registerOnMessageListener(LOW_FREQUENCY_CHANNEL_ID, onMessageListener);
|
||||
}
|
||||
|
||||
public void registerOnMsgListener(IMogoCloudOnMsgListener onMsgListener) {
|
||||
@@ -99,11 +102,9 @@ public class SocketHandler {
|
||||
receiveMsgTime = SystemClock.elapsedRealtime();
|
||||
if (webSocketData.getUpUtcTime() > 0) {
|
||||
long nextDelay = webSocketData.getUpUtcTime() - serverTime;
|
||||
if (!MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getIsUseExternalLocation()) {
|
||||
for (IMogoCloudOnAckListener ackListener : onAckListenerList) {
|
||||
if (ackListener != null) {
|
||||
ackListener.onAck(nextDelay);
|
||||
}
|
||||
for (IMogoCloudOnAckListener ackListener : onAckListenerList) {
|
||||
if (ackListener != null) {
|
||||
ackListener.onAck(nextDelay);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,7 +113,7 @@ public class SocketHandler {
|
||||
if (msgType == MSG_TYPE_DOWNLINK_CAR_DATA.getMsgType()) {
|
||||
MogoSnapshotSetData data = GsonUtil.objectFromJson(webSocketData.getData(), MogoSnapshotSetData.class);
|
||||
if (data == null) {
|
||||
Log.e(TAG, "onMsgReceived MogoSnapshotSetData == null ");
|
||||
Logger.e(TAG, "onMsgReceived MogoSnapshotSetData == null ");
|
||||
return;
|
||||
}
|
||||
for (IMogoCloudOnMsgListener listener : onMsgListenerList) {
|
||||
@@ -126,11 +127,12 @@ public class SocketHandler {
|
||||
|
||||
/**
|
||||
* 发送自车和ADAS数据
|
||||
*
|
||||
* @param cloudLocationInfo 自车定位信息
|
||||
*/
|
||||
public void sendMsg(List<CloudLocationInfo> cloudLocationInfo) {
|
||||
if (cloudLocationInfo == null) {
|
||||
Log.e(TAG, "请检查传入数组对象为Null");
|
||||
Logger.e(TAG, "请检查传入数组对象为Null");
|
||||
return;
|
||||
}
|
||||
CloudLocationInfo lastInfo = null;
|
||||
@@ -162,7 +164,7 @@ public class SocketHandler {
|
||||
|
||||
if (content.self == null &&
|
||||
(content.adas == null || content.adas.isEmpty())) {
|
||||
Log.d(TAG, "no information to sent");
|
||||
Logger.d(TAG, "no information to sent");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -173,14 +175,14 @@ public class SocketHandler {
|
||||
webSocketData.setData(GsonUtil.jsonFromObject(content));
|
||||
String msg = GsonUtil.jsonFromObject(webSocketData);
|
||||
|
||||
int msgType = 0x040003; //低频数据
|
||||
int msgType = LOW_FREQUENCY_CHANNEL_ID;
|
||||
if (cloudLocationInfo.size() > 2) {
|
||||
msgType = 0x040002; //高频数据
|
||||
msgType = HIGH_FREQUENCY_CHANNEL_ID;
|
||||
}
|
||||
MsgBody msgBody = new MsgBody();
|
||||
msgBody.msgType(msgType);
|
||||
msgBody.content(msg);
|
||||
SocketManager.getInstance().sendMsg(msgBody, msgId -> {
|
||||
SocketManager.getInstance().sendMsg(mAppId, HEADER_TYPE, msgBody, msgId -> {
|
||||
for (IMogoCloudOnMsgListener listener : onMsgListenerList) {
|
||||
if (listener != null) {
|
||||
listener.onMsgSend(msgId);
|
||||
@@ -190,8 +192,8 @@ public class SocketHandler {
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
SocketManager.getInstance().unregisterOnMessageListener(0x040002, onMessageListener);
|
||||
SocketManager.getInstance().unregisterOnMessageListener(0x040003, onMessageListener);
|
||||
SocketManager.getInstance().unregisterOnMessageListener(HIGH_FREQUENCY_CHANNEL_ID, onMessageListener);
|
||||
SocketManager.getInstance().unregisterOnMessageListener(LOW_FREQUENCY_CHANNEL_ID, onMessageListener);
|
||||
SocketManager.getInstance().release();
|
||||
onMsgListenerList.clear();
|
||||
onAckListenerList.clear();
|
||||
|
||||
@@ -3,8 +3,12 @@ package com.mogo.realtime.spi;
|
||||
|
||||
import com.elegant.spi.AbstractDelegateManager;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
<<<<<<< HEAD
|
||||
import com.mogo.realtime.Interface.IRealTimeProvider;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
=======
|
||||
import com.mogo.realtime.api.IRealTimeProvider;
|
||||
>>>>>>> 17b3ed341e822ad073ace72a78b08f26214c0059
|
||||
|
||||
/**
|
||||
* 提供RealTime SPI接口实例对象管理类
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.mogo.realtime.spi;
|
||||
|
||||
import com.mogo.realtime.Interface.IRealTimeProvider;
|
||||
import com.mogo.realtime.api.IRealTimeProvider;
|
||||
import com.mogo.realtime.entity.ADASRecognizedResult;
|
||||
import com.mogo.realtime.entity.CloudLocationInfo;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.mogo.realtime.util;
|
||||
|
||||
import android.location.Location;
|
||||
|
||||
import com.mogo.realtime.entity.CloudLocationInfo;
|
||||
|
||||
/**
|
||||
* 定位数据类型转换工具
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public class LocationParseUtil {
|
||||
/**
|
||||
* 从Location 转 CloudLocationInfo
|
||||
*
|
||||
* @param info 待转数据
|
||||
* @return 转后数据
|
||||
*/
|
||||
public static CloudLocationInfo locationToCloudLocation(Location info) {
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
CloudLocationInfo cloud = new CloudLocationInfo();
|
||||
cloud.setLat(info.getLatitude());
|
||||
cloud.setLon(info.getLongitude());
|
||||
cloud.setAlt(info.getAltitude());
|
||||
cloud.setHeading(info.getBearing());
|
||||
cloud.setSpeed(info.getSpeed());
|
||||
cloud.setSatelliteTime(info.getTime());
|
||||
cloud.setSystemTime(System.currentTimeMillis());
|
||||
return cloud;
|
||||
}
|
||||
|
||||
public static MogoLatLng cloudLocationToMogoLatLng(CloudLocationInfo info) {
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
return new MogoLatLng(info.getLat(), info.getLon());
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,7 @@ package com.mogo.realtime.util;
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import android.support.annotation.RequiresApi;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
@@ -33,9 +33,9 @@ public class MortonCode {
|
||||
private static final double RULE_MORTON_TO_LONLAT = 360.0 / Math.pow( 2, 32 );
|
||||
|
||||
/**
|
||||
* @param lon
|
||||
* @param lat
|
||||
* @return
|
||||
* @param lon 经度
|
||||
* @param lat 纬度
|
||||
* @return long 莫顿码
|
||||
*/
|
||||
public static long wrapEncodeMorton( Double lon, Double lat ) {
|
||||
DecimalFormat decimalFormat = new DecimalFormat( "#.######" );
|
||||
@@ -46,13 +46,13 @@ public class MortonCode {
|
||||
/**
|
||||
* 编码 morton code
|
||||
*
|
||||
* @param lon
|
||||
* @param lat
|
||||
* @return
|
||||
* @param lon 经度
|
||||
* @param lat 纬度
|
||||
* @return long 莫顿码
|
||||
*/
|
||||
public static long encodeMorton( Double lon, Double lat ) {
|
||||
|
||||
Long bit = 1L;
|
||||
long bit = 1L;
|
||||
long mortonCode = 0L;
|
||||
long x = ( long ) ( lon * RULE_MORTON );
|
||||
long y = ( long ) ( lat * RULE_MORTON );
|
||||
@@ -78,8 +78,8 @@ public class MortonCode {
|
||||
/**
|
||||
* 将莫顿码解码为坐标
|
||||
*
|
||||
* @param mortonCode
|
||||
* @return
|
||||
* @param mortonCode 莫顿码
|
||||
* @return 坐标
|
||||
*/
|
||||
public static double[] decodeMorton( long mortonCode ) {
|
||||
long[] midPoint = mortonCodeToCoord( mortonCode );
|
||||
@@ -95,8 +95,8 @@ public class MortonCode {
|
||||
/**
|
||||
* 莫顿码分别拆解为 编码后的经纬度长整数
|
||||
*
|
||||
* @param mortonCode
|
||||
* @return
|
||||
* @param mortonCode 莫顿码
|
||||
* @return 经纬度 长整数
|
||||
*/
|
||||
private static long[] mortonCodeToCoord( long mortonCode ) {
|
||||
long bit = 1L;
|
||||
@@ -114,7 +114,7 @@ public class MortonCode {
|
||||
/**
|
||||
* 对编码后的经纬度长整数进行解码
|
||||
*
|
||||
* @param midPoint
|
||||
* @param midPoint 经纬度 长整数
|
||||
*/
|
||||
private static void normalizeCoord( long[] midPoint ) {
|
||||
// if x > 180 degrees, then subtract 360 degrees
|
||||
@@ -136,7 +136,6 @@ public class MortonCode {
|
||||
midPoint[1] +=
|
||||
NDS_180_DEGREES + 1; // add 1 because 0 must be counted as well
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mogo.cloud.tanlu;
|
||||
package com.mogo.cloud.tanlu.api;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
@@ -7,12 +7,11 @@ import com.mogo.cloud.network.BaseData;
|
||||
import com.mogo.cloud.network.NetConstants;
|
||||
import com.mogo.cloud.network.RetrofitFactory;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.tanlu.api.IRoadInfoSearchCallback;
|
||||
import com.mogo.cloud.tanlu.bean.RoadInfoRequest;
|
||||
import com.mogo.cloud.tanlu.bean.RoadInfos;
|
||||
import com.mogo.cloud.tanlu.constant.HttpConstant;
|
||||
import com.mogo.cloud.tanlu.net.TanluApiService;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
import com.mogo.utils.GsonUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -74,24 +73,27 @@ public class MogoRoadSearchManager {
|
||||
.subscribe(new Observer<BaseData<RoadInfos>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.d(HttpConstant.TANLU, "queryRoadInfos onSubscribe ");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseData<RoadInfos> roadInfos) {
|
||||
Log.d(HttpConstant.TANLU, "queryRoadInfos onNext roadInfos = " + roadInfos.getResult().getData());
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Log.d(HttpConstant.TAG, "queryRoadInfos onNext roadInfos = " + roadInfos.getResult().getData());
|
||||
}
|
||||
callback.onSuccess(roadInfos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.d(HttpConstant.TANLU, "queryRoadInfos onError ");
|
||||
callback.onError(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.d(HttpConstant.TANLU, "queryRoadInfos onComplete ");
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Log.d(HttpConstant.TAG, "queryRoadInfos onComplete ");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.mogo.cloud.tanlu;
|
||||
package com.mogo.cloud.tanlu.api;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.mogo.cloud.tanlu.api.ITanluUploadCallback;
|
||||
import com.mogo.cloud.tanlu.core.CosUpload;
|
||||
import com.mogo.cloud.tanlu.bean.UploadInfo;
|
||||
|
||||
/**
|
||||
@@ -6,5 +6,5 @@ package com.mogo.cloud.tanlu.constant;
|
||||
* @since 2021/1/20
|
||||
*/
|
||||
public class HttpConstant {
|
||||
public static final String TANLU = "TANLU_MODULE";
|
||||
public static final String TAG = "MoGoAiCloud_TanLu";
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mogo.cloud.tanlu;
|
||||
package com.mogo.cloud.tanlu.core;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
@@ -7,6 +7,7 @@ import android.util.Log;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mogo.cloud.network.BaseData;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.tanlu.api.ITanluUploadCallback;
|
||||
import com.mogo.cloud.tanlu.bean.InformationBody;
|
||||
import com.mogo.cloud.tanlu.bean.UploadInfo;
|
||||
@@ -65,21 +66,23 @@ public class CosUpload implements CosStatusCallback {
|
||||
public void uploadInfo(UploadInfo info, ITanluUploadCallback callback) {
|
||||
mCallback = callback;
|
||||
mUploadInfo = info;
|
||||
Log.d(HttpConstant.TANLU, "videoPath = " + info.getFilePath());
|
||||
|
||||
if (!TextUtils.isEmpty(info.getFilePath())) { //不传路径
|
||||
if (isVideo(info.getFilePath())) {
|
||||
videoCoverImage = getVideoPicPath();
|
||||
Log.d(HttpConstant.TANLU, "videoCoverImage = " + videoCoverImage);
|
||||
boolean isSuccess = getVideoThumbnail(info.getFilePath(), videoCoverImage);
|
||||
Log.d(HttpConstant.TANLU, "isSuccess = " + isSuccess);
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Log.d(HttpConstant.TAG, "isSuccess = " + isSuccess + "--videoCoverImage = " + videoCoverImage);
|
||||
}
|
||||
filePath.add(info.getFilePath());
|
||||
filePath.add(videoCoverImage);
|
||||
} else {
|
||||
videoCoverImage = null;
|
||||
filePath.add(info.getFilePath());
|
||||
}
|
||||
|
||||
Log.e(HttpConstant.TANLU, "filePath.size() = " + filePath.size());
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Log.d(HttpConstant.TAG, "filePath.size() = " + filePath.size());
|
||||
}
|
||||
CosUploadManagerImpl.getInstance(mContext.getApplicationContext())
|
||||
.upload(filePath, mPicEventId, DbPriorityConfig.PRIORITY_HIGH);
|
||||
} else {
|
||||
@@ -90,21 +93,24 @@ public class CosUpload implements CosStatusCallback {
|
||||
|
||||
@Override
|
||||
public void onStartUpload(String eventId, String localPath) {
|
||||
Log.d(HttpConstant.TANLU, "onStartUpload ----> ");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadCosCompleted(String cosPath, String eventId, String downloadUrl, String localPath) {
|
||||
Log.d(HttpConstant.TANLU, "uploadCosCompleted ----> cosPath =" + cosPath + "--eventId =" + eventId);
|
||||
Log.d(HttpConstant.TANLU, "uploadCosCompleted ----> downloadUrl =" + downloadUrl + "--localPath =" + localPath);
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Log.d(HttpConstant.TAG, "uploadCosCompleted ----> cosPath =" + cosPath + "--eventId =" + eventId);
|
||||
Log.d(HttpConstant.TAG, "uploadCosCompleted ----> downloadUrl =" + downloadUrl + "--localPath =" + localPath);
|
||||
}
|
||||
if (filePath.size() == 2) {
|
||||
if (isVideo(localPath)) { //如果是视频 localPath
|
||||
mCosVideoUrl = downloadUrl;
|
||||
} else {
|
||||
mCosPicUrl = downloadUrl;
|
||||
}
|
||||
|
||||
Log.d(HttpConstant.TANLU, "mCosVideoUrl = " + mCosVideoUrl + " >>>mCosPicUrl = " + mCosPicUrl);
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Log.d(HttpConstant.TAG, "mCosVideoUrl = " + mCosVideoUrl + " >>>mCosPicUrl = " + mCosPicUrl);
|
||||
}
|
||||
if (mCosPicUrl != null && mCosVideoUrl != null) {
|
||||
sendInformation();
|
||||
}
|
||||
@@ -116,7 +122,9 @@ public class CosUpload implements CosStatusCallback {
|
||||
|
||||
@Override
|
||||
public void uploadCosFailed(String cosPath, String eventId, String localPath) {
|
||||
Log.e(HttpConstant.TANLU, "uploadCosFailed ----> cosPath = " + cosPath + "--eventId =" + eventId + "--localPath =" + localPath);
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Log.e(HttpConstant.TAG, "uploadCosFailed ----> cosPath = " + cosPath + "--eventId =" + eventId + "--localPath =" + localPath);
|
||||
}
|
||||
sendInformation();
|
||||
}
|
||||
|
||||
@@ -140,20 +148,20 @@ public class CosUpload implements CosStatusCallback {
|
||||
@Override
|
||||
public void onSuccess(BaseData<UploadResult> result) {
|
||||
if (result != null && result.getResult() != null) {
|
||||
Log.d(HttpConstant.TANLU, "uploadRoadInfo result.id = " + result.getResult().id);
|
||||
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
|
||||
Log.d(HttpConstant.TAG, "uploadRoadInfo result.id = " + result.getResult().id);
|
||||
}
|
||||
}
|
||||
mCallback.onSuccess(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int code) {
|
||||
Log.d(HttpConstant.TANLU, " uploadRoadInfo code = " + code);
|
||||
mCallback.onFailure(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.d(HttpConstant.TANLU, "uploadRoadInfo onError e = " + e);
|
||||
mCallback.onError(e);
|
||||
}
|
||||
});
|
||||
@@ -166,7 +174,6 @@ public class CosUpload implements CosStatusCallback {
|
||||
jsonObject.addProperty("thumbnail", mCosPicUrl);
|
||||
jsonObject.addProperty("url", mCosVideoUrl);
|
||||
jsonArray.add(jsonObject);
|
||||
Log.d(HttpConstant.TANLU, "jsonArray.toString() = " + jsonArray.toString());
|
||||
|
||||
informationBody.setData(jsonArray.toString());
|
||||
informationBody.setAddr(mUploadInfo.getAddr());
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mogo.cloud.tanlu;
|
||||
package com.mogo.cloud.tanlu.core;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
@@ -62,8 +62,6 @@ public class UploadManager {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("sn", MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn());
|
||||
map.put("data", gson.toJson(informationBody));
|
||||
Log.d(HttpConstant.TANLU, "info = " + gson.toJson(informationBody));
|
||||
Log.d(HttpConstant.TANLU, "sn = " + MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn());
|
||||
apiService.uploadInformation(map)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@@ -74,13 +72,11 @@ public class UploadManager {
|
||||
|
||||
@Override
|
||||
public void onNext(BaseData<UploadResult> result) {
|
||||
Log.d(HttpConstant.TANLU, "onNext -----> ");
|
||||
callback.onSuccess(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e(HttpConstant.TANLU, "onError -----> e " + e);
|
||||
callback.onError(e);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@ package com.mogo.cloud.tanlu.utils
|
||||
import android.graphics.Bitmap
|
||||
import android.media.MediaMetadataRetriever
|
||||
import android.os.Environment
|
||||
import android.util.Log
|
||||
import androidx.annotation.Keep
|
||||
import android.support.annotation.Keep
|
||||
import java.io.*
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
@@ -36,7 +35,6 @@ fun deletePicFile(filePath: String?): Boolean {
|
||||
//删除某个目录下所有文件
|
||||
fun deleteAllFile(file: File?) { //判断文件不为null或文件目录存在
|
||||
if (file == null || !file.exists()) {
|
||||
Log.e("liyz", "文件删除失败,请检查文件路径是否正确")
|
||||
return
|
||||
}
|
||||
//取得这个目录下的所有子文件对象
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mogo.cloud.tanlu.utils;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
import android.support.annotation.Keep;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
1
modules/mogo-trafficlive/.gitignore
vendored
Normal file
1
modules/mogo-trafficlive/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
42
modules/mogo-trafficlive/build.gradle
Normal file
42
modules/mogo-trafficlive/build.gradle
Normal file
@@ -0,0 +1,42 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.android.compileSdkVersion
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.android.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.android.targetSdkVersion
|
||||
|
||||
versionCode 1
|
||||
versionName "${MOGO_TRAFFICLIVE_VERSION}"
|
||||
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation rootProject.ext.dependencies.rxjava
|
||||
implementation rootProject.ext.dependencies.rxandroid
|
||||
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
implementation "com.mogo.cloud:network:${MOGO_NETWORK_VERSION}"
|
||||
implementation "com.mogo.cloud:live:${MOGO_LIVE_VERSION}"
|
||||
} else {
|
||||
implementation project(":foudations:mogo-network")
|
||||
implementation project(":foudations:mogo-live")
|
||||
}
|
||||
}
|
||||
|
||||
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()
|
||||
2
modules/mogo-trafficlive/consumer-rules.pro
Normal file
2
modules/mogo-trafficlive/consumer-rules.pro
Normal file
@@ -0,0 +1,2 @@
|
||||
-keep class com.mogo.cloud.trafficlive.api.ITrafficLiveCallBack{*;}
|
||||
-keep class com.mogo.cloud.trafficlive.api.MoGoAiCloudTrafficLive{*;}
|
||||
4
modules/mogo-trafficlive/gradle.properties
Normal file
4
modules/mogo-trafficlive/gradle.properties
Normal file
@@ -0,0 +1,4 @@
|
||||
GROUP=com.mogo.cloud
|
||||
POM_ARTIFACT_ID=trafficlive
|
||||
VERSION_CODE=1
|
||||
VERSION_NAME=1.0.0-SNAPSHOT
|
||||
21
modules/mogo-trafficlive/proguard-rules.pro
vendored
Normal file
21
modules/mogo-trafficlive/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
5
modules/mogo-trafficlive/src/main/AndroidManifest.xml
Normal file
5
modules/mogo-trafficlive/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mogo.cloud.trafficlive">
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.mogo.cloud.trafficlive.api;
|
||||
|
||||
public interface ITrafficLiveCallBack {
|
||||
|
||||
default void onLiveStart() {
|
||||
|
||||
}
|
||||
|
||||
default void onLiveStop() {
|
||||
|
||||
}
|
||||
|
||||
default void onLiveConnecting() {
|
||||
|
||||
}
|
||||
|
||||
default void onLiveConnected() {
|
||||
|
||||
}
|
||||
|
||||
void onLive();
|
||||
|
||||
void onDisConnect();
|
||||
|
||||
void onError(String errorMsg);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.mogo.cloud.trafficlive.api;
|
||||
|
||||
import android.app.Application;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
import com.mogo.cloud.trafficlive.core.TrafficLiveManager;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import static com.mogo.cloud.trafficlive.constant.TrafficLiveConstant.TAG;
|
||||
|
||||
public class MoGoAiCloudTrafficLive {
|
||||
|
||||
/**
|
||||
* 查看前方车辆直播
|
||||
*/
|
||||
public static void viewVehicleHeadLive(Application application, String liveSn, SurfaceView surfaceView, ITrafficLiveCallBack callBack) {
|
||||
try {
|
||||
TrafficLiveManager.getInstance().viewVehicleHeadLive(application, liveSn, surfaceView, callBack);
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, " viewVehicleHeadLive error : " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看前方路口直播
|
||||
*/
|
||||
public static void viewIntersectionLive(ITrafficLiveCallBack callBack) {
|
||||
TrafficLiveManager.getInstance().viewIntersectionLive(callBack);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止观看直播
|
||||
*/
|
||||
public static void stopLive(String liveSn) {
|
||||
TrafficLiveManager.getInstance().stopLive(liveSn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭直播组件
|
||||
*/
|
||||
public static void destroyLive() {
|
||||
TrafficLiveManager.getInstance().destroyLive();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否在直播中
|
||||
*
|
||||
* @return 直播状态
|
||||
*/
|
||||
public static boolean isOnLive() {
|
||||
return TrafficLiveManager.getInstance().isOnLive();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.mogo.cloud.trafficlive.constant;
|
||||
|
||||
public class TrafficLiveConstant {
|
||||
|
||||
public static final String TAG = "MoGoAiCloud_TrafficLive";
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.mogo.cloud.trafficlive.core;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.SystemClock;
|
||||
import android.text.TextUtils;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveProgressListener;
|
||||
import com.mogo.cloud.live.listener.IRequestLiveListener;
|
||||
import com.mogo.cloud.live.manager.MoGoLiveManager;
|
||||
import com.mogo.cloud.live.manager.RequestLiveManager;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.trafficlive.api.ITrafficLiveCallBack;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import static com.mogo.cloud.live.constant.LiveConstant.LIVE_TYPE_CLOSE;
|
||||
import static com.mogo.cloud.live.constant.LiveConstant.LIVE_TYPE_OPEN;
|
||||
import static com.mogo.cloud.trafficlive.constant.TrafficLiveConstant.TAG;
|
||||
|
||||
public class TrafficLiveManager implements ILiveProgressListener {
|
||||
|
||||
private static volatile TrafficLiveManager mInstance;
|
||||
private final RequestLiveManager requestLiveManager;
|
||||
private ITrafficLiveCallBack callBack;
|
||||
private SurfaceView surfaceView;
|
||||
private String mStreamId;
|
||||
private boolean isLoginSuccess = false;
|
||||
|
||||
private TrafficLiveManager() {
|
||||
requestLiveManager = RequestLiveManager.getInstance();
|
||||
}
|
||||
|
||||
public static TrafficLiveManager getInstance() {
|
||||
if (mInstance == null) {
|
||||
synchronized (TrafficLiveManager.class) {
|
||||
if (mInstance == null) {
|
||||
mInstance = new TrafficLiveManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
public boolean isOnLive() {
|
||||
return MoGoLiveManager.getInstance().isPlaying();
|
||||
}
|
||||
|
||||
public void viewVehicleHeadLive(Application application, String liveSn, SurfaceView surfaceView, ITrafficLiveCallBack trafficLiveCallBack) throws Exception {
|
||||
if (trafficLiveCallBack == null) {
|
||||
throw new Exception("ITrafficLiveCallBack can not be null");
|
||||
}
|
||||
if (surfaceView == null) {
|
||||
throw new Exception("SurfaceView can not be null");
|
||||
}
|
||||
if (TextUtils.isEmpty(liveSn)) {
|
||||
throw new Exception("liveSn can not be null");
|
||||
}
|
||||
|
||||
this.callBack = trafficLiveCallBack;
|
||||
this.surfaceView = surfaceView;
|
||||
Logger.i(TAG, "申请拉流 systemClock :" + SystemClock.elapsedRealtime() + " SystemTime : " + System.currentTimeMillis());
|
||||
requestLiveManager.requestVehicleHeadLive(LIVE_TYPE_OPEN, liveSn, new IRequestLiveListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Logger.i(TAG, "主播开始直播了 systemClock :" + SystemClock.elapsedRealtime() + " SystemTime : " + System.currentTimeMillis());
|
||||
String sn = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn();
|
||||
mStreamId = MoGoLiveManager.STREAM_ID_PREFIX + liveSn;
|
||||
MoGoLiveManager.getInstance().init(application, null);
|
||||
MoGoLiveManager.getInstance().loginRoom(sn, liveSn);
|
||||
MoGoLiveManager.getInstance().setLiveProgressListener(TrafficLiveManager.this);
|
||||
|
||||
// 直接 查看对应SN的直播
|
||||
MoGoLiveManager.getInstance().startLive(surfaceView);
|
||||
callBack.onLive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
callBack.onError(e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void viewIntersectionLive(ITrafficLiveCallBack callBack) {
|
||||
|
||||
}
|
||||
|
||||
public void stopLive(String liveSn) {
|
||||
requestLiveManager.requestVehicleHeadLive(LIVE_TYPE_CLOSE, liveSn, new IRequestLiveListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
callBack.onError(e.getMessage());
|
||||
}
|
||||
});
|
||||
MoGoLiveManager.getInstance().stopLive();
|
||||
surfaceView = null;
|
||||
callBack = null;
|
||||
isLoginSuccess = false;
|
||||
mStreamId = null;
|
||||
}
|
||||
|
||||
public void destroyLive() {
|
||||
MoGoLiveManager.getInstance().onDestroyLive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEngineStart() {
|
||||
callBack.onLiveStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEngineStop() {
|
||||
callBack.onLiveStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnecting() {
|
||||
callBack.onLiveConnecting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(String roomId) {
|
||||
isLoginSuccess = true;
|
||||
callBack.onLiveConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisConnect() {
|
||||
isLoginSuccess = false;
|
||||
callBack.onDisConnect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDebugError(int errorCode, String funcName, String errorInfo) {
|
||||
Logger.e(TAG, "onDebugError errorCode : " + errorCode + " funcName : " + funcName + " errorInfo : " + errorInfo);
|
||||
callBack.onError(errorInfo);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user