From 0552dc0768f95375da4c2a6126430f2593abf47d Mon Sep 17 00:00:00 2001 From: wangcongtao Date: Tue, 23 Feb 2021 18:06:39 +0800 Subject: [PATCH 1/9] opt --- .idea/gradle.xml | 1 - .../module/service/MogoServiceProvider.java | 6 +- .../com/mogo/module/service/MogoServices.java | 4 +- .../intent/ADASStatusIntentHandler.java | 4 +- .../service/location/MogoRTKLocation.java | 164 ++++------------- .../module/service/spi/SPIRealTimeUpload.java | 4 +- .../MogoRefreshStrategyController.java | 2 +- .../SnapshotLocationController.java | 123 +++++++++++++ .../uploadintime/SnapshotUploadInTime.java | 171 ------------------ 9 files changed, 171 insertions(+), 308 deletions(-) create mode 100644 modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotLocationController.java delete mode 100644 modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotUploadInTime.java diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 4ff10f68a5..83405b8de1 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -91,7 +91,6 @@ diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServiceProvider.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServiceProvider.java index fd8276d2da..baa8ddec73 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServiceProvider.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServiceProvider.java @@ -99,9 +99,9 @@ public class MogoServiceProvider implements IMogoModuleProvider { public void init( Context context ) { Logger.d( TAG, "init" ); MarkerServiceHandler.init( context ); - if ( DebugConfig.isNeedUploadCoordinatesDurationInTime() ) { - MogoRTKLocation.getInstance().init(); - } +// if ( DebugConfig.isNeedUploadCoordinatesDurationInTime() ) { +// } + MogoRTKLocation.getInstance().init(); MogoServices.getInstance().preInit( context ); MogoServices.getInstance().init( AbsMogoApplication.getApp() ); UiThreadHandler.postDelayed( () -> { diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServices.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServices.java index 6438bf0b5a..98272ec65f 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServices.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServices.java @@ -47,7 +47,7 @@ import com.mogo.module.service.refresh.CustomRefreshStrategy; import com.mogo.module.service.refresh.RefreshObject; import com.mogo.module.service.strategy.CarIconDisplayStrategy; import com.mogo.module.service.ttsConfig.TtsConfigModleData; -import com.mogo.module.service.uploadintime.SnapshotUploadInTime; +import com.mogo.module.service.uploadintime.SnapshotLocationController; import com.mogo.realtime.api.MoGoAiCloudRealTime; import com.mogo.service.adas.IMogoADASController; import com.mogo.service.adas.IMogoAdasCarDataCallback; @@ -982,7 +982,7 @@ public class MogoServices implements IMogoMapListener, e.printStackTrace(); } MarkerServiceHandler.getApis().getMapServiceApi().getMapUIController().syncLocation2Map( data ); - SnapshotUploadInTime.getInstance().syncAdasLocationInfo( data ); + SnapshotLocationController.getInstance().syncAdasLocationInfo( data ); } catch ( Exception e ) { e.printStackTrace(); } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/ADASStatusIntentHandler.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/ADASStatusIntentHandler.java index 6d335d0afd..08feacc8f9 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/ADASStatusIntentHandler.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/ADASStatusIntentHandler.java @@ -8,7 +8,7 @@ import com.mogo.module.service.MarkerServiceHandler; import com.mogo.module.service.ServiceConst; import com.mogo.module.service.carinfo.CarStateInfo; import com.mogo.module.service.receiver.MogoReceiver; -import com.mogo.module.service.uploadintime.SnapshotUploadInTime; +import com.mogo.module.service.uploadintime.SnapshotLocationController; import com.mogo.utils.logger.Logger; import com.mogo.utils.network.utils.GsonUtil; @@ -73,7 +73,7 @@ class ADASStatusIntentHandler implements IntentHandler { data.putOpt( "acceleration", stateInfo.getValues().getAcceleration() ); data.putOpt( "yawRate", stateInfo.getValues().getYaw_rate() ); MarkerServiceHandler.getApis().getMapServiceApi().getMapUIController().syncLocation2Map( data ); - SnapshotUploadInTime.getInstance().syncAdasLocationInfo( data ); + SnapshotLocationController.getInstance().syncAdasLocationInfo( data ); } catch ( Exception e ) { e.printStackTrace(); } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/location/MogoRTKLocation.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/location/MogoRTKLocation.java index afdf3b93a1..3bbe6d2ed6 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/location/MogoRTKLocation.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/location/MogoRTKLocation.java @@ -1,37 +1,21 @@ package com.mogo.module.service.location; -import android.content.BroadcastReceiver; import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; -import android.os.Handler; -import android.os.Message; import com.mogo.commons.AbsMogoApplication; -import com.mogo.commons.debug.DebugConfig; -import com.mogo.module.service.uploadintime.SnapshotUploadInTime; +import com.mogo.module.service.uploadintime.SnapshotLocationController; import com.mogo.realtime.entity.CloudLocationInfo; -import com.mogo.utils.WorkThreadHandler; import com.mogo.utils.logger.Logger; -import java.util.ArrayList; -import java.util.List; - public class MogoRTKLocation { private static final String TAG = "MogoRTKLocation"; - private static final int MSG_DATA_CHANGED = 0x100; - private static final long MSG_DATA_INTERNAL = 500L; - - private Handler mHandler; private LocationManager locationManager; - private RTKLocationListener rtkLocationListener; - private List cacheList = new ArrayList<>(); public static MogoRTKLocation getInstance() { return RTKHolder.rtkLoc; @@ -42,151 +26,79 @@ public class MogoRTKLocation { } private MogoRTKLocation() { - mHandler = new Handler(WorkThreadHandler.newInstance( TAG ).getLooper() ) { - @Override - public void handleMessage(Message msg) { - super.handleMessage(msg); - if (msg.what == MSG_DATA_CHANGED) { - mHandler.sendEmptyMessageDelayed(MSG_DATA_CHANGED, uploadDelay); - sendLocationData(); - -// Logger.d(TAG,"handleMessage开始发送消息"); - } - } - }; - mHandler.sendEmptyMessage(MSG_DATA_CHANGED); - Logger.d(TAG,"构造方法开始发送消息"); - } - - public interface RTKLocationListener { - void onLocationChanged(int dataAccuracy, List cloudLocationInfos); - } - - private void sendLocationData() { - - List list = null; - int dataAccuracy = 0; - if ( DebugConfig.isUseAdasRtkLocationInfo() ) { - dataAccuracy = 1; - list = new ArrayList<>(SnapshotUploadInTime.getInstance().getSendLocationData()); - } - if ( list == null || list.isEmpty() ) { - dataAccuracy = 0; - list = new ArrayList<>(cacheList); - } - if (cacheList != null && cacheList.size() > 0) { - cacheList.clear(); - } - if (rtkLocationListener != null) { - rtkLocationListener.onLocationChanged(dataAccuracy, list); - } - } - - public void registerRTKLocationListener(RTKLocationListener locationListener) { - rtkLocationListener = locationListener; - } - - public void unregisterRTKLocationListener(){ - rtkLocationListener = null; } public void init() { - locationManager = (LocationManager) AbsMogoApplication.getApp().getApplicationContext().getSystemService(Context.LOCATION_SERVICE); - String provider = locationManager.getBestProvider(getCriteria(), true); - Logger.d(TAG, "init provider : " + provider); - if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { + locationManager = ( LocationManager ) AbsMogoApplication.getApp().getApplicationContext().getSystemService( Context.LOCATION_SERVICE ); + String provider = locationManager.getBestProvider( getCriteria(), true ); + Logger.d( TAG, "init provider : " + provider ); + if ( locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) { try { - locationManager.requestLocationUpdates(provider, 0, 0, locationListener); - Location location = locationManager.getLastKnownLocation(provider); - if (location != null) { - Logger.i(TAG, "location : " + location.toString()); + locationManager.requestLocationUpdates( provider, 0, 0, locationListener ); + Location location = locationManager.getLastKnownLocation( provider ); + if ( location != null ) { + Logger.i( TAG, "location : " + location.toString() ); } - } catch (Exception e) { + } catch ( Exception e ) { e.printStackTrace(); - Logger.d(TAG, "RTK LocationManager requestLocationUpdates has Exception : " + e.getMessage()); + Logger.d( TAG, "RTK LocationManager requestLocationUpdates has Exception : " + e.getMessage() ); } } else { - Logger.d(TAG, "RTK LocationManager Provider GPS_PROVIDER unable"); + Logger.d( TAG, "RTK LocationManager Provider GPS_PROVIDER unable" ); } - - // 注册修改上报间隔的广播, 临时使用,后面可直接干掉,发送广播的地方在EntranceFragment - IntentFilter filter = new IntentFilter("com.mogo.launcher.action.FIX_UPLOAT_DELAY"); - AbsMogoApplication.getApp().registerReceiver(fixUploadDelayReceiver, filter); } private Criteria getCriteria() { Criteria criteria = new Criteria(); - criteria.setAccuracy(Criteria.ACCURACY_FINE); //高精 - criteria.setAltitudeRequired(false); - criteria.setBearingRequired(true); - criteria.setSpeedRequired(true); - criteria.setPowerRequirement(Criteria.POWER_LOW); + criteria.setAccuracy( Criteria.ACCURACY_FINE ); //高精 + criteria.setAltitudeRequired( false ); + criteria.setBearingRequired( true ); + criteria.setSpeedRequired( true ); + criteria.setPowerRequirement( Criteria.POWER_LOW ); return criteria; } private LocationListener locationListener = new LocationListener() { @Override - public void onLocationChanged(Location location) { - if (location != null) { + public void onLocationChanged( Location location ) { + if ( location != null ) { CloudLocationInfo cloudLocationInfo = new CloudLocationInfo(); - cloudLocationInfo.setAlt(location.getAltitude()); - cloudLocationInfo.setHeading(location.getBearing()); - cloudLocationInfo.setLat(location.getLatitude()); - cloudLocationInfo.setLon(location.getLongitude()); - cloudLocationInfo.setSpeed(location.getSpeed()); - cloudLocationInfo.setSatelliteTime(location.getTime()); - cloudLocationInfo.setSystemTime(System.currentTimeMillis()); + cloudLocationInfo.setAlt( location.getAltitude() ); + cloudLocationInfo.setHeading( location.getBearing() ); + cloudLocationInfo.setLat( location.getLatitude() ); + cloudLocationInfo.setLon( location.getLongitude() ); + cloudLocationInfo.setSpeed( location.getSpeed() ); + cloudLocationInfo.setSatelliteTime( location.getTime() ); + cloudLocationInfo.setSystemTime( System.currentTimeMillis() ); cloudLocationInfo.convertCoor2GCJ02(); - cacheList.add(cloudLocationInfo); + SnapshotLocationController.getInstance().syncLocationInfo( cloudLocationInfo ); } else { - Logger.e(TAG, "location == null"); + Logger.e( TAG, "location == null" ); } } @Override - public void onStatusChanged(String provider, int status, Bundle extras) { - Logger.d(TAG, "onStatusChanged status: " + status); + public void onStatusChanged( String provider, int status, Bundle extras ) { + Logger.d( TAG, "onStatusChanged status: " + status ); } @Override - public void onProviderEnabled(String provider) { - Logger.d(TAG, "onProviderEnabled"); + public void onProviderEnabled( String provider ) { + Logger.d( TAG, "onProviderEnabled" ); } @Override - public void onProviderDisabled(String provider) { - Logger.d(TAG, "onProviderEnabled"); + public void onProviderDisabled( String provider ) { + Logger.d( TAG, "onProviderEnabled" ); } }; public void stop() { - Logger.d(TAG, "stop RTK Location"); - if (locationManager != null && locationListener != null) { - locationManager.removeUpdates(locationListener); + Logger.d( TAG, "stop RTK Location" ); + if ( locationManager != null && locationListener != null ) { + locationManager.removeUpdates( locationListener ); } else { - Logger.d(TAG, "stop failed , reason : loc" + locationManager + " , or loc listener: " + locationListener + " is null"); - } - } - - private long uploadDelay = MSG_DATA_INTERNAL; - - private FixUploadDelayReceiver fixUploadDelayReceiver = new FixUploadDelayReceiver(); - - private class FixUploadDelayReceiver extends BroadcastReceiver{ - @Override - public void onReceive(Context context, Intent intent) { - uploadDelay = intent.getIntExtra("fixTime", 0); - } - } - - /** - * 默认保持{@link #uploadDelay}间隔进行位置上报,如遇服务端控制,进行上报间隔修改 - * @param delay 上报间隔 - */ - public void resetUploadDelay(long delay) { - if (mHandler != null && mHandler.hasMessages(MSG_DATA_CHANGED)) { - mHandler.removeMessages(MSG_DATA_CHANGED); - mHandler.sendEmptyMessageDelayed(MSG_DATA_CHANGED, delay); + Logger.d( TAG, "stop failed , reason : loc" + locationManager + " , or loc listener: " + locationListener + " is null" ); } } } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/spi/SPIRealTimeUpload.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/spi/SPIRealTimeUpload.java index 6d8be6e2fa..94150778a4 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/spi/SPIRealTimeUpload.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/spi/SPIRealTimeUpload.java @@ -1,7 +1,7 @@ package com.mogo.module.service.spi; import com.elegant.spi.annotations.Service; -import com.mogo.module.service.MarkerServiceHandler; +import com.mogo.module.service.uploadintime.SnapshotLocationController; import com.mogo.realtime.api.IRealTimeProvider; import com.mogo.realtime.entity.ADASRecognizedResult; import com.mogo.realtime.entity.CloudLocationInfo; @@ -20,6 +20,6 @@ public class SPIRealTimeUpload implements IRealTimeProvider { @Override public List getLocationMsg() { - return null; + return SnapshotLocationController.getInstance().getSendLocationData(); } } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/strategy/MogoRefreshStrategyController.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/strategy/MogoRefreshStrategyController.java index cf1fd09e11..505564565c 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/strategy/MogoRefreshStrategyController.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/strategy/MogoRefreshStrategyController.java @@ -38,7 +38,7 @@ public class MogoRefreshStrategyController implements IMogoRefreshStrategyContro @Override public void resetLocationUpDelay(long delay) { - MogoRTKLocation.getInstance().resetUploadDelay(delay); +// MogoRTKLocation.getInstance().resetUploadDelay(delay); } @Override diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotLocationController.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotLocationController.java new file mode 100644 index 0000000000..6963a99047 --- /dev/null +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotLocationController.java @@ -0,0 +1,123 @@ +package com.mogo.module.service.uploadintime; + +import com.mogo.realtime.entity.CloudLocationInfo; +import com.mogo.utils.logger.Logger; + +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public +/** + * @author congtaowang + * @since 2020/12/14 + * + * 实时坐标 + */ +class SnapshotLocationController { + + private static final String TAG = "SnapshotLocationController"; + + private static volatile SnapshotLocationController sInstance; + + private SnapshotLocationController() { + } + + public static SnapshotLocationController getInstance() { + if ( sInstance == null ) { + synchronized ( SnapshotLocationController.class ) { + if ( sInstance == null ) { + sInstance = new SnapshotLocationController(); + } + } + } + return sInstance; + } + + public synchronized void release() { + sInstance = null; + } + + private Object readResolve() { + // 阻止反序列化,必须实现 Serializable 接口 + return sInstance; + } + + private List< CloudLocationInfo > mLocationList = new ArrayList<>(); + + /** + * 同步从定位来的数据(也可能是rtk) + * + * @param cli + */ + public void syncLocationInfo( CloudLocationInfo cli ) { + if ( cli == null ) { + return; + } + mLocationList.add( cli ); + } + + // adda 工控机数据缓存 + private List< CloudLocationInfo > mMachineCacheList = new ArrayList<>(); + + /** + * 同步从工控机来的数据 + * + * @param data + */ + public void syncAdasLocationInfo( JSONObject data ) { + if ( data == null ) { + return; + } + Logger.d( TAG, "同步到rtk数据" ); + double lon = data.optDouble( "lon", -1 ); + double lat = data.optDouble( "lat", -1 ); + double alt = data.optDouble( "alt", -1 ); + double heading = data.optDouble( "heading", -1 ); + double acceleration = data.optDouble( "acceleration", -1 ); + double yawRate = data.optDouble( "yawRate", -1 ); + double speed = data.optDouble( "speed", -1 ); + long satelliteTime = 0L; + try { + satelliteTime = Long.valueOf( data.optString( "satelliteTime" ) ); + } catch ( Exception e ) { + e.printStackTrace(); + } + + CloudLocationInfo cloudLocationInfo = new CloudLocationInfo(); + cloudLocationInfo.setAlt( alt ); + cloudLocationInfo.setHeading( heading ); + cloudLocationInfo.setLat( lat ); + cloudLocationInfo.setLon( lon ); + cloudLocationInfo.setSpeed( speed ); + cloudLocationInfo.setSatelliteTime( satelliteTime ); + cloudLocationInfo.setSystemTime( System.currentTimeMillis() ); + cloudLocationInfo.convertCoor2GCJ02(); + mMachineCacheList.add( cloudLocationInfo ); + } + + /** + * 获取某一段时间内的坐标集合 + * + * @return + */ + public List< CloudLocationInfo > getSendLocationData() { + + List< CloudLocationInfo > list = null; + int dataAccuracy = 0; + if ( mMachineCacheList != null ) { + dataAccuracy = 1; + list = new ArrayList<>( mMachineCacheList ); + mMachineCacheList.clear(); + } + if ( list == null || list.isEmpty() ) { + dataAccuracy = 0; + if ( mLocationList != null ) { + list = new ArrayList<>( mLocationList ); + mLocationList.clear(); + } + } + return list; + } +} diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotUploadInTime.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotUploadInTime.java deleted file mode 100644 index b24e2d4111..0000000000 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotUploadInTime.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.mogo.module.service.uploadintime; - -import android.content.Context; - -import com.mogo.commons.utils.MortonCode; -import com.mogo.module.service.MarkerServiceHandler; -import com.mogo.module.service.location.MogoRTKLocation; -import com.mogo.module.service.utils.SimpleLocationCorrectStrategy; -import com.mogo.module.service.websocket.LocationResult; -import com.mogo.module.service.websocket.OnePerSecondSendContent; -import com.mogo.realtime.entity.CloudLocationInfo; -import com.mogo.service.adas.entity.ADASRecognizedResult; -import com.mogo.service.connection.IMogoOnWebSocketMessageListener; -import com.mogo.service.connection.WebSocketMsgType; -import com.mogo.utils.logger.Logger; - -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.List; - -public -/* - * @author congtaowang - * @since 2020/12/14 - * - * 实时上报坐标、识别物体 - */ -class SnapshotUploadInTime implements MogoRTKLocation.RTKLocationListener { - - private static final String TAG = "SnapshotUploadInTime"; - - private static volatile SnapshotUploadInTime sInstance; - private Context mContext; - - private SnapshotUploadInTime() { - } - - public static SnapshotUploadInTime getInstance() { - if ( sInstance == null ) { - synchronized ( SnapshotUploadInTime.class ) { - if ( sInstance == null ) { - sInstance = new SnapshotUploadInTime(); - } - } - } - return sInstance; - } - - public synchronized void release() { - sInstance = null; - } - - private Object readResolve() { - // 阻止反序列化,必须实现 Serializable 接口 - return sInstance; - } - - public void start( Context context ) { - mContext = context.getApplicationContext(); - MogoRTKLocation.getInstance().registerRTKLocationListener( this ); - } - - public void stop() { - MogoRTKLocation.getInstance().unregisterRTKLocationListener(); - MogoRTKLocation.getInstance().stop(); - } - - @Override - public void onLocationChanged( int dataAccuracy, List cloudLocationInfos ) { - startSendCarLocationAndAdasRecognizedResult2Server( dataAccuracy, cloudLocationInfos ); - } - - private CloudLocationInfo mLastInfo; - - private void startSendCarLocationAndAdasRecognizedResult2Server( int dataAccuracy, List< CloudLocationInfo > cloudLocationInfo ) { - CloudLocationInfo lastInfo = null; - // 如果数组内容不为空,就用数组最后一个值 - if ( cloudLocationInfo != null && !cloudLocationInfo.isEmpty() ) { - lastInfo = cloudLocationInfo.get( cloudLocationInfo.size() - 1 ); - mLastInfo = lastInfo; - } - if ( lastInfo == null ) { - lastInfo = mLastInfo; - } - LocationResult locationResult = null; - if ( lastInfo != null ) { - // 定位点预测纠偏 - lastInfo = SimpleLocationCorrectStrategy.getInstance().correct( lastInfo ); - locationResult = new LocationResult(); - locationResult.dataAccuracy = dataAccuracy; - if ( lastInfo != null ) { - locationResult.lastCoordinate = lastInfo; - locationResult.mortonCode = MortonCode.wrapEncodeMorton( lastInfo.getLon(), lastInfo.getLat() ); - } - locationResult.coordinates = new ArrayList<>(); - locationResult.sn = com.mogo.commons.network.Utils.getSn(); - if ( cloudLocationInfo == null || cloudLocationInfo.isEmpty() ) { - locationResult.coordinates.addAll( new ArrayList<>() ); - } else { - locationResult.coordinates.addAll( cloudLocationInfo ); - } - } - List< ADASRecognizedResult > recognizedResults = MarkerServiceHandler.getADASController().getLastADASRecognizedResult(); - Logger.d( TAG, "发送的adas识别数量 = %s", recognizedResults == null ? 0 : recognizedResults.size() ); - OnePerSecondSendContent content = new OnePerSecondSendContent(); - content.self = locationResult; - content.adas = recognizedResults; - - if ( content.self == null && - ( content.adas == null || content.adas.isEmpty() ) ) { - Logger.d( TAG, "no information 2 sent" ); - return; - } - - - MarkerServiceHandler.getApis().getWebSocketManagerApi( mContext ).sendMsg( content, new IMogoOnWebSocketMessageListener() { - @Override - public WebSocketMsgType getDownLinkType() { - return null; - } - - @Override - public WebSocketMsgType getUpLinkType() { - return WebSocketMsgType.MSG_TYPE_UPLINK_CAR_DATA; - } - } ); - } - - // adda 工控机数据缓存 - private List< CloudLocationInfo > cacheList = new ArrayList<>(); - - public void syncAdasLocationInfo( JSONObject data ) { - if ( data == null ) { - return; - } - Logger.d( TAG, "同步到rtk数据" ); - double lon = data.optDouble( "lon", -1 ); - double lat = data.optDouble( "lat", -1 ); - double alt = data.optDouble( "alt", -1 ); - double heading = data.optDouble( "heading", -1 ); - double acceleration = data.optDouble( "acceleration", -1 ); - double yawRate = data.optDouble( "yawRate", -1 ); - double speed = data.optDouble( "speed", -1 ); - long satelliteTime = 0L; - try { - satelliteTime = Long.valueOf( data.optString( "satelliteTime" ) ); - } catch ( Exception e ) { - e.printStackTrace(); - } - - CloudLocationInfo cloudLocationInfo = new CloudLocationInfo(); - cloudLocationInfo.setAlt( alt ); - cloudLocationInfo.setHeading( heading ); - cloudLocationInfo.setLat( lat ); - cloudLocationInfo.setLon( lon ); - cloudLocationInfo.setSpeed( speed ); - cloudLocationInfo.setSatelliteTime( satelliteTime ); - cloudLocationInfo.setSystemTime( System.currentTimeMillis() ); - cloudLocationInfo.convertCoor2GCJ02(); - cacheList.add( cloudLocationInfo ); - } - - public List< CloudLocationInfo > getSendLocationData() { - List< CloudLocationInfo > list = new ArrayList<>( cacheList ); - if ( cacheList != null && cacheList.size() > 0 ) { - cacheList.clear(); - } - return list; - } -} From 8d83104472a2249c74b9357bd8448d877d658670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Tue, 23 Feb 2021 18:33:36 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=BA=86=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E5=8A=A8=E6=80=81=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mogo/launcher/MogoApplication.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/mogo/launcher/MogoApplication.java b/app/src/main/java/com/mogo/launcher/MogoApplication.java index 4bfe42b333..9162724aaf 100644 --- a/app/src/main/java/com/mogo/launcher/MogoApplication.java +++ b/app/src/main/java/com/mogo/launcher/MogoApplication.java @@ -198,7 +198,19 @@ public class MogoApplication extends AbsMogoApplication { // 配置云服务API MoGoAiCloudClientConfig clientConfig = MoGoAiCloudClientConfig.getInstance(); // 设置网络环境:HTTP_DNS_ENV_QA、HTTP_DNS_ENV_RELEASE、HTTP_DNS_ENV_DEV - clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_QA); + switch ( DebugConfig.getNetMode() ) { + case DebugConfig.NET_MODE_DEV: + clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_DEV); + break; + case DebugConfig.NET_MODE_QA: + clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_QA); + break; + case DebugConfig.NET_MODE_DEMO: + clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_DEMO); + break; + default: + clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_RELEASE); + } // 设置是否是第三APP登录 clientConfig.setThirdLogin(true); // 设置是否输出日志 From bba3e1eba60281a01c39a7c87cb3eaa086169bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Tue, 23 Feb 2021 18:35:46 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E5=85=B3=E9=97=AD=E5=BB=B6=E8=BF=9F?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/mogo/launcher/MogoApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/mogo/launcher/MogoApplication.java b/app/src/main/java/com/mogo/launcher/MogoApplication.java index b58c7e6745..15bc7463e8 100644 --- a/app/src/main/java/com/mogo/launcher/MogoApplication.java +++ b/app/src/main/java/com/mogo/launcher/MogoApplication.java @@ -163,7 +163,7 @@ public class MogoApplication extends AbsMogoApplication { protected void init() { super.init(); final IMogoServiceApis apis = MogoApisHandler.getInstance().getApis(); - prepareBaseService( apis, 2_000L ); + prepareBaseService( apis, 0L ); } @Override From a903d6c225226b6f2191307d0d93def0ab0e249f Mon Sep 17 00:00:00 2001 From: lixiaopeng Date: Tue, 23 Feb 2021 19:34:28 +0800 Subject: [PATCH 4/9] opt upload --- .idea/gradle.xml | 1 + .../service/CarCorderController.kt | 90 +++++++++---------- 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 83405b8de1..4ff10f68a5 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -91,6 +91,7 @@ diff --git a/libraries/tanlulib/src/main/java/com/zhidao/roadcondition/service/CarCorderController.kt b/libraries/tanlulib/src/main/java/com/zhidao/roadcondition/service/CarCorderController.kt index 159f420e5c..c64ffaec9a 100644 --- a/libraries/tanlulib/src/main/java/com/zhidao/roadcondition/service/CarCorderController.kt +++ b/libraries/tanlulib/src/main/java/com/zhidao/roadcondition/service/CarCorderController.kt @@ -170,7 +170,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // mFromType // ) - getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, CarCorderController.mainInfoId)?.let { uploadRoadInfo(it) } + getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, CarCorderController.mainInfoId)?.let { uploadRoadInfo(it) } //地图上打点 taskAsync(3_000) { @@ -213,7 +213,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // mFromType // ) - getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } } @@ -259,7 +259,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // mLatitude, mSpeed) if (photoPath != null) { - getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } } } else { @@ -283,7 +283,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // ) if (photoPath != null) { - getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } } } } @@ -303,7 +303,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // ) if (photoPath != null) { - getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } } } @@ -343,13 +343,11 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { entity?.let { if (it.isCustom) { -// compressVideo(videoPath, thumbnailPath, it) - getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + compressVideo(videoPath, thumbnailPath, it) } else if (entity.fromType in STRATEGY_UPLOAD_TYPE_ARRAY) { // 属于策略上报 -// compressVideo(videoPath, thumbnailPath, it) - getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + compressVideo(videoPath, thumbnailPath, it) } else { Log.d( @@ -360,16 +358,14 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { Log.d(TAG, "onTakeVideoSuccess 111 abs =" + (abs(minSpeedVideo) / 3.6f)) if (speed >= (abs(minSpeedVideo) / 3.6f)) { //获取视频以及缩略图成功,开始上报 -// compressVideo(videoPath, thumbnailPath, it) - getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + compressVideo(videoPath, thumbnailPath, it) } } if (minSpeedVideo > 0 && maxSpeedVideo > 0) { Log.d(TAG, "onTakeVideoSuccess minSpeedVideo > 0 -- speed = $speed") if ((speed >= (minSpeedVideo / 3.6f)) && speed <= (maxSpeedVideo / 3.6f)) { -// compressVideo(videoPath, thumbnailPath, it) - getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + compressVideo(videoPath, thumbnailPath, it) } else { } } else { @@ -414,7 +410,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // mFromType // ) - getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } //地图上打点 taskAsync(3_000) { @@ -429,24 +425,24 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { /** * 压缩视频并且上传 */ -// private fun compressVideo(videoPath: String, thumbnailPath: String, entity: TakeEntity) { -// Log.d( -// TAG, -// "outputVideoPath = " + outputVideoPath + ">> videoPath=" + videoPath + " isCustom = ${entity.isCustom}" -// ) -// val startTime = System.currentTimeMillis() -// Thread(Runnable { -// try { -// VideoProcessor.processor(AbsMogoApplication.getApp().applicationContext) -// .input(videoPath) -// .output(outputVideoPath) -// .removeAudio(true) -// .outWidth(1920) -// .outHeight(1080) -// .bitrate(2000 * 1024) -// .frameRate(25) -// .process() -// Log.d(TAG, "compress cost time =" + (System.currentTimeMillis() - startTime)) + private fun compressVideo(videoPath: String, thumbnailPath: String, entity: TakeEntity) { + Log.d( + TAG, + "outputVideoPath = " + outputVideoPath + ">> videoPath=" + videoPath + " isCustom = ${entity.isCustom}" + ) + val startTime = System.currentTimeMillis() + Thread(Runnable { + try { + VideoProcessor.processor(AbsMogoApplication.getApp().applicationContext) + .input(videoPath) + .output(outputVideoPath) + .removeAudio(true) + .outWidth(1920) + .outHeight(1080) + .bitrate(2000 * 1024) + .frameRate(25) + .process() + Log.d(TAG, "compress cost time =" + (System.currentTimeMillis() - startTime)) // CosStatusController().uploadFile( // mutableListOf(outputVideoPath, thumbnailPath), // entity, @@ -457,17 +453,19 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // mLatitude, // mSpeed // ) -// -// //删除压缩前的视频 -// deletePicFile(videoPath) -// } catch (e: Exception) { -// Log.e(TAG, "compressVideo e = $e") -// //删除压缩前的视频 -// deletePicFile(videoPath) -// e.printStackTrace() -// } -// }).start() -// } + + getInfo(outputVideoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + + //删除压缩前的视频 + deletePicFile(videoPath) + } catch (e: Exception) { + Log.e(TAG, "compressVideo e = $e") + //删除压缩前的视频 + deletePicFile(videoPath) + e.printStackTrace() + } + }).start() + } /** * 上报路况的视频和图片 @@ -475,7 +473,9 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { fun uploadRoadInfo(info: UploadInfo) { MogoUploadManager.getInstance(AbsMogoApplication.getApp().applicationContext).uploadInfo(info, object : ITanluUploadCallback { override fun onSuccess(result: BaseData) { - + if (result != null) { + Log.d(TAG, "result =" + result.result); + } } override fun onFailure(code: Int) { @@ -531,7 +531,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // mFromType // ) - getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } } From 7d994c1937aa4fe104945e0a3508705921ffc186 Mon Sep 17 00:00:00 2001 From: liujing Date: Tue, 23 Feb 2021 19:46:07 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E7=9B=B4=E6=92=AD=E6=8B=89=E6=B5=81?= =?UTF-8?q?=E6=8D=A2zego->view=E6=B7=BB=E5=8A=A0=20=20=E5=BE=85=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/mogo-module-v2x/build.gradle | 1 + .../module/v2x/view/CarZegoLiveVideoView.java | 272 ++++++++++++++++++ .../res/layout/view_video_layout_see_live.xml | 10 +- 3 files changed, 281 insertions(+), 2 deletions(-) create mode 100644 modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java diff --git a/modules/mogo-module-v2x/build.gradle b/modules/mogo-module-v2x/build.gradle index 2eaadb3a28..b84e556603 100644 --- a/modules/mogo-module-v2x/build.gradle +++ b/modules/mogo-module-v2x/build.gradle @@ -69,6 +69,7 @@ dependencies { kapt rootProject.ext.dependencies.roomAnnotationProcessor kapt rootProject.ext.dependencies.aroutercompiler + api rootProject.ext.dependencies.mogoaicloudtrafficlive if (Boolean.valueOf(RELEASE)) { implementation rootProject.ext.dependencies.mogomap diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java new file mode 100644 index 0000000000..99e264edaf --- /dev/null +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java @@ -0,0 +1,272 @@ +package com.mogo.module.v2x.view; + +import android.content.Context; +import android.content.Intent; +import android.graphics.PorterDuff; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.SurfaceView; +import android.view.View; +import android.widget.ProgressBar; +import android.widget.TextView; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.core.content.ContextCompat; + +import com.mogo.cloud.trafficlive.api.MoGoAiCloudTrafficLive; +import com.mogo.commons.AbsMogoApplication; +import com.mogo.commons.voice.AIAssist; +import com.mogo.module.common.entity.MarkerCarInfo; +import com.mogo.module.v2x.R; +import com.mogo.module.v2x.V2XServiceManager; +import com.mogo.module.v2x.entity.net.V2XLivePushVoRes; +import com.mogo.module.v2x.network.V2XRefreshCallback; +import com.mogo.module.v2x.voice.V2XVoiceCallbackListener; +import com.mogo.module.v2x.voice.V2XVoiceConstants; +import com.mogo.module.v2x.voice.V2XVoiceManager; +import com.mogo.utils.logger.Logger; + +import static com.mogo.module.v2x.V2XConst.MODULE_NAME; + +/** + * @author liujing + * @description 描述 + * @since: 2021/2/23 + */ +public class CarZegoLiveVideoView extends RoundLayout { + private SurfaceView mTxcVideoView; + private ProgressBar mLoading; + // private TXLivePlayer mLivePlayer; + private ConstraintLayout mClLoadError; + private TextView mTvRefreshButton; + + private MarkerCarInfo.CarLiveInfo mCarLiveInfo; + // 重新刷新直播流 + private V2XVoiceCallbackListener v2XVoiceCallbackRefreshListener = new V2XVoiceCallbackListener() { + @Override + public void onCallback(String command, Intent intent) { + mLoading.setVisibility(VISIBLE); + mClLoadError.setVisibility(GONE); + if (mCarLiveInfo != null) { + startLive(mCarLiveInfo); + } + } + }; + + public CarZegoLiveVideoView(Context context) { + this(context, null); + } + + public CarZegoLiveVideoView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public CarZegoLiveVideoView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initView(context); + } + + private void initView(Context context) { + LayoutInflater.from(context) + .inflate(R.layout.view_video_layout_see_live, this); + //mPlayerView 即 step1 中添加的界面 view + mTxcVideoView = findViewById(R.id.surface); +// //创建 player 对象 +// mLivePlayer = new TXLivePlayer(context); +// //关键 player 对象与界面 view +// mLivePlayer.setPlayerView(mTxcVideoView); +// mLivePlayer.setMute(true); +// mLivePlayer.enableHardwareDecode(true); + + mLoading = findViewById(R.id.loading); + mLoading.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, R.color.live_video_progress_bar_loading_color), PorterDuff.Mode.MULTIPLY); + + mClLoadError = findViewById(R.id.clLoadError); + mTvRefreshButton = findViewById(R.id.tvRefreshButton); + mTvRefreshButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + mLoading.setVisibility(VISIBLE); + mClLoadError.setVisibility(GONE); + if (mCarLiveInfo != null) { + startLive(mCarLiveInfo); + } + } + }); + } + + /** + * 设置直播信息 + */ + public void setCarLiveInfo(MarkerCarInfo.CarLiveInfo carLiveInfo) { + mCarLiveInfo = carLiveInfo; + } + + /** + * 开始直播 + * + * @param carLiveInfo 要直播的车机,如果没有直播的地址需要重新获取最新的直播地址 + */ + public void startLive(MarkerCarInfo.CarLiveInfo carLiveInfo) { + // 进行直播播放 + if (mTxcVideoView != null + && carLiveInfo != null) { + if (!TextUtils.isEmpty(carLiveInfo.getVideoUrl())) { + AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live)); + setCarLiveInfo(carLiveInfo); + playLiveVideo(carLiveInfo); + } + // 根据SN重新获取直播流地址 + else { + V2XServiceManager + .getV2XRefreshModel() + .livePush(new V2XRefreshCallback() { + @Override + public void onSuccess(V2XLivePushVoRes result) { + AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live)); + mClLoadError.setVisibility(GONE); + mClLoadError.setVisibility(GONE); + try { + MarkerCarInfo.CarLiveInfo carRealLiveInfo = new MarkerCarInfo.CarLiveInfo(); + carRealLiveInfo.setVideoUrl(result.getResult().getPlayUrl().getRtmp()); + carRealLiveInfo.setVideoSn(carLiveInfo.getVideoSn()); + carRealLiveInfo.setVideoChannel(result.getResult().getVideoChannel()); + setCarLiveInfo(carLiveInfo); + playLiveVideo(carRealLiveInfo); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void onFail(String msg) { + Logger.e(MODULE_NAME, "播放器:" + msg); + AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live_error)); + mLoading.setVisibility(GONE); + mClLoadError.setVisibility(VISIBLE); + } + }, carLiveInfo.getVideoSn(), 0); + } + } + } + + /** + * 播放直播流,且开始心跳 + */ + private void playLiveVideo(MarkerCarInfo.CarLiveInfo carLiveInfo) { + startHeartLive(carLiveInfo); + if (mTxcVideoView != null) { +// MoGoAiCloudTrafficLive.viewVehicleHeadLive(this.getApplication(), liveSn, surfaceView, this); +// mLivePlayer.startPlay(carLiveInfo.getVideoUrl(), TXLivePlayer.PLAY_TYPE_LIVE_RTMP); +// mLivePlayer.setPlayListener(new ITXLivePlayListener() { +// @Override +// public void onPlayEvent(int event, Bundle bundle) { +// Logger.w(MODULE_NAME, "播放器:onPlayEvent==" + event + "===bundle===" + bundle); +// if (event == TXLiveConstants.PLAY_EVT_PLAY_LOADING) { +// mLoading.setVisibility(VISIBLE); +// mClLoadError.setVisibility(GONE); +// } else if (event == TXLiveConstants.PLAY_EVT_PLAY_BEGIN) { +// refreshStatusToListener(true); +// mLoading.setVisibility(GONE); +// mClLoadError.setVisibility(GONE); +// } else if (event < 0) { +// refreshStatusToListener(false); +// AIAssist.getInstance(V2XUtils.getApp()).speakTTSVoice("直播获取识败,可以对我说重试", null); +// stopLive(mCarLiveInfo); +// mLoading.setVisibility(GONE); +// mClLoadError.setVisibility(VISIBLE); +// // 注册语音交互 +// V2XVoiceManager.INSTANCE +// .registerWakeCmd(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_CAR_LIVE, +// v2XVoiceCallbackRefreshListener) +// .registerUnWakeVoice(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_LIVE_UN_WAKEUP, +// v2XVoiceCallbackRefreshListener); +// } +// } +// +// @Override +// public void onNetStatus(Bundle bundle) { +// //Logger.w(MODULE_NAME, "播放器:onNetStatus===bundle===" + bundle); +// } +// }); + } + } + + // 刷新直播心跳 + private void startHeartLive(MarkerCarInfo.CarLiveInfo carLiveInfo) { + try { + if (!TextUtils.isEmpty(carLiveInfo.getVideoSn()) + && !TextUtils.isEmpty(carLiveInfo.getVideoChannel())) { + V2XServiceManager + .getV2XRefreshModel() + .refreshHeartBeat(carLiveInfo.getVideoSn(), + carLiveInfo.getVideoChannel(), + null); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void stopLive(MarkerCarInfo.CarLiveInfo carLiveInfo) { + try { + Logger.w(MODULE_NAME, "心跳:关闭直播..."); + // 暂停 +// mLivePlayer.pause(); +// // true 代表清除最后一帧画面 +// mLivePlayer.stopPlay(true); +// mTxcVideoView.onDestroy(); + // 停止推流 + V2XServiceManager + .getV2XRefreshModel() + .livePush(new V2XRefreshCallback() { + @Override + public void onSuccess(V2XLivePushVoRes result) { + Logger.d(MODULE_NAME, "播放器:" + result); + } + + @Override + public void onFail(String msg) { + Logger.e(MODULE_NAME, "播放器:" + msg); + } + }, carLiveInfo.getVideoSn(), 1); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + if (mCarLiveInfo != null) { + startLive(mCarLiveInfo); + } + } + + @Override + protected void onDetachedFromWindow() { + stopLive(mCarLiveInfo); + mLoading.setVisibility(VISIBLE); + // 反注册语音交互 + V2XVoiceManager.INSTANCE + .unRegisterWakeCmd(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_CAR_LIVE) + .unRegisterUnWakeVoice(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_LIVE_UN_WAKEUP); + super.onDetachedFromWindow(); + } + + private void refreshStatusToListener(boolean videoPlaying) { + if (onVideoStatusChange != null) { + onVideoStatusChange.videoPlaying(videoPlaying); + } + } + + private V2XCarLiveVideoView.OnVideoStatusChange onVideoStatusChange; + + public void addOnVideoStatusChangeListener(V2XCarLiveVideoView.OnVideoStatusChange onVideoStatusChange) { + this.onVideoStatusChange = onVideoStatusChange; + } + + public interface OnVideoStatusChange { + void videoPlaying(boolean videoPlaying); + } +} diff --git a/modules/mogo-module-v2x/src/main/res/layout/view_video_layout_see_live.xml b/modules/mogo-module-v2x/src/main/res/layout/view_video_layout_see_live.xml index 0ad6257f83..303b339fe0 100644 --- a/modules/mogo-module-v2x/src/main/res/layout/view_video_layout_see_live.xml +++ b/modules/mogo-module-v2x/src/main/res/layout/view_video_layout_see_live.xml @@ -7,8 +7,14 @@ android:background="@color/live_video_background_color" app:roundLayoutRadius="@dimen/dp_20"> - + + + + + + From 874e9f80d641308b1458fb8346d79504409ecbcb Mon Sep 17 00:00:00 2001 From: liujing Date: Tue, 23 Feb 2021 19:50:54 +0800 Subject: [PATCH 6/9] =?UTF-8?q?Revert=20"=E7=9B=B4=E6=92=AD=E6=8B=89?= =?UTF-8?q?=E6=B5=81=E6=8D=A2zego->view=E6=B7=BB=E5=8A=A0=20=20=E5=BE=85?= =?UTF-8?q?=E9=AA=8C=E8=AF=81"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 7d994c1937aa4fe104945e0a3508705921ffc186. --- modules/mogo-module-v2x/build.gradle | 1 - .../module/v2x/view/CarZegoLiveVideoView.java | 272 ------------------ .../res/layout/view_video_layout_see_live.xml | 10 +- 3 files changed, 2 insertions(+), 281 deletions(-) delete mode 100644 modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java diff --git a/modules/mogo-module-v2x/build.gradle b/modules/mogo-module-v2x/build.gradle index b84e556603..2eaadb3a28 100644 --- a/modules/mogo-module-v2x/build.gradle +++ b/modules/mogo-module-v2x/build.gradle @@ -69,7 +69,6 @@ dependencies { kapt rootProject.ext.dependencies.roomAnnotationProcessor kapt rootProject.ext.dependencies.aroutercompiler - api rootProject.ext.dependencies.mogoaicloudtrafficlive if (Boolean.valueOf(RELEASE)) { implementation rootProject.ext.dependencies.mogomap diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java deleted file mode 100644 index 99e264edaf..0000000000 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java +++ /dev/null @@ -1,272 +0,0 @@ -package com.mogo.module.v2x.view; - -import android.content.Context; -import android.content.Intent; -import android.graphics.PorterDuff; -import android.text.TextUtils; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.SurfaceView; -import android.view.View; -import android.widget.ProgressBar; -import android.widget.TextView; -import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.core.content.ContextCompat; - -import com.mogo.cloud.trafficlive.api.MoGoAiCloudTrafficLive; -import com.mogo.commons.AbsMogoApplication; -import com.mogo.commons.voice.AIAssist; -import com.mogo.module.common.entity.MarkerCarInfo; -import com.mogo.module.v2x.R; -import com.mogo.module.v2x.V2XServiceManager; -import com.mogo.module.v2x.entity.net.V2XLivePushVoRes; -import com.mogo.module.v2x.network.V2XRefreshCallback; -import com.mogo.module.v2x.voice.V2XVoiceCallbackListener; -import com.mogo.module.v2x.voice.V2XVoiceConstants; -import com.mogo.module.v2x.voice.V2XVoiceManager; -import com.mogo.utils.logger.Logger; - -import static com.mogo.module.v2x.V2XConst.MODULE_NAME; - -/** - * @author liujing - * @description 描述 - * @since: 2021/2/23 - */ -public class CarZegoLiveVideoView extends RoundLayout { - private SurfaceView mTxcVideoView; - private ProgressBar mLoading; - // private TXLivePlayer mLivePlayer; - private ConstraintLayout mClLoadError; - private TextView mTvRefreshButton; - - private MarkerCarInfo.CarLiveInfo mCarLiveInfo; - // 重新刷新直播流 - private V2XVoiceCallbackListener v2XVoiceCallbackRefreshListener = new V2XVoiceCallbackListener() { - @Override - public void onCallback(String command, Intent intent) { - mLoading.setVisibility(VISIBLE); - mClLoadError.setVisibility(GONE); - if (mCarLiveInfo != null) { - startLive(mCarLiveInfo); - } - } - }; - - public CarZegoLiveVideoView(Context context) { - this(context, null); - } - - public CarZegoLiveVideoView(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public CarZegoLiveVideoView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - initView(context); - } - - private void initView(Context context) { - LayoutInflater.from(context) - .inflate(R.layout.view_video_layout_see_live, this); - //mPlayerView 即 step1 中添加的界面 view - mTxcVideoView = findViewById(R.id.surface); -// //创建 player 对象 -// mLivePlayer = new TXLivePlayer(context); -// //关键 player 对象与界面 view -// mLivePlayer.setPlayerView(mTxcVideoView); -// mLivePlayer.setMute(true); -// mLivePlayer.enableHardwareDecode(true); - - mLoading = findViewById(R.id.loading); - mLoading.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, R.color.live_video_progress_bar_loading_color), PorterDuff.Mode.MULTIPLY); - - mClLoadError = findViewById(R.id.clLoadError); - mTvRefreshButton = findViewById(R.id.tvRefreshButton); - mTvRefreshButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - mLoading.setVisibility(VISIBLE); - mClLoadError.setVisibility(GONE); - if (mCarLiveInfo != null) { - startLive(mCarLiveInfo); - } - } - }); - } - - /** - * 设置直播信息 - */ - public void setCarLiveInfo(MarkerCarInfo.CarLiveInfo carLiveInfo) { - mCarLiveInfo = carLiveInfo; - } - - /** - * 开始直播 - * - * @param carLiveInfo 要直播的车机,如果没有直播的地址需要重新获取最新的直播地址 - */ - public void startLive(MarkerCarInfo.CarLiveInfo carLiveInfo) { - // 进行直播播放 - if (mTxcVideoView != null - && carLiveInfo != null) { - if (!TextUtils.isEmpty(carLiveInfo.getVideoUrl())) { - AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live)); - setCarLiveInfo(carLiveInfo); - playLiveVideo(carLiveInfo); - } - // 根据SN重新获取直播流地址 - else { - V2XServiceManager - .getV2XRefreshModel() - .livePush(new V2XRefreshCallback() { - @Override - public void onSuccess(V2XLivePushVoRes result) { - AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live)); - mClLoadError.setVisibility(GONE); - mClLoadError.setVisibility(GONE); - try { - MarkerCarInfo.CarLiveInfo carRealLiveInfo = new MarkerCarInfo.CarLiveInfo(); - carRealLiveInfo.setVideoUrl(result.getResult().getPlayUrl().getRtmp()); - carRealLiveInfo.setVideoSn(carLiveInfo.getVideoSn()); - carRealLiveInfo.setVideoChannel(result.getResult().getVideoChannel()); - setCarLiveInfo(carLiveInfo); - playLiveVideo(carRealLiveInfo); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - public void onFail(String msg) { - Logger.e(MODULE_NAME, "播放器:" + msg); - AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live_error)); - mLoading.setVisibility(GONE); - mClLoadError.setVisibility(VISIBLE); - } - }, carLiveInfo.getVideoSn(), 0); - } - } - } - - /** - * 播放直播流,且开始心跳 - */ - private void playLiveVideo(MarkerCarInfo.CarLiveInfo carLiveInfo) { - startHeartLive(carLiveInfo); - if (mTxcVideoView != null) { -// MoGoAiCloudTrafficLive.viewVehicleHeadLive(this.getApplication(), liveSn, surfaceView, this); -// mLivePlayer.startPlay(carLiveInfo.getVideoUrl(), TXLivePlayer.PLAY_TYPE_LIVE_RTMP); -// mLivePlayer.setPlayListener(new ITXLivePlayListener() { -// @Override -// public void onPlayEvent(int event, Bundle bundle) { -// Logger.w(MODULE_NAME, "播放器:onPlayEvent==" + event + "===bundle===" + bundle); -// if (event == TXLiveConstants.PLAY_EVT_PLAY_LOADING) { -// mLoading.setVisibility(VISIBLE); -// mClLoadError.setVisibility(GONE); -// } else if (event == TXLiveConstants.PLAY_EVT_PLAY_BEGIN) { -// refreshStatusToListener(true); -// mLoading.setVisibility(GONE); -// mClLoadError.setVisibility(GONE); -// } else if (event < 0) { -// refreshStatusToListener(false); -// AIAssist.getInstance(V2XUtils.getApp()).speakTTSVoice("直播获取识败,可以对我说重试", null); -// stopLive(mCarLiveInfo); -// mLoading.setVisibility(GONE); -// mClLoadError.setVisibility(VISIBLE); -// // 注册语音交互 -// V2XVoiceManager.INSTANCE -// .registerWakeCmd(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_CAR_LIVE, -// v2XVoiceCallbackRefreshListener) -// .registerUnWakeVoice(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_LIVE_UN_WAKEUP, -// v2XVoiceCallbackRefreshListener); -// } -// } -// -// @Override -// public void onNetStatus(Bundle bundle) { -// //Logger.w(MODULE_NAME, "播放器:onNetStatus===bundle===" + bundle); -// } -// }); - } - } - - // 刷新直播心跳 - private void startHeartLive(MarkerCarInfo.CarLiveInfo carLiveInfo) { - try { - if (!TextUtils.isEmpty(carLiveInfo.getVideoSn()) - && !TextUtils.isEmpty(carLiveInfo.getVideoChannel())) { - V2XServiceManager - .getV2XRefreshModel() - .refreshHeartBeat(carLiveInfo.getVideoSn(), - carLiveInfo.getVideoChannel(), - null); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void stopLive(MarkerCarInfo.CarLiveInfo carLiveInfo) { - try { - Logger.w(MODULE_NAME, "心跳:关闭直播..."); - // 暂停 -// mLivePlayer.pause(); -// // true 代表清除最后一帧画面 -// mLivePlayer.stopPlay(true); -// mTxcVideoView.onDestroy(); - // 停止推流 - V2XServiceManager - .getV2XRefreshModel() - .livePush(new V2XRefreshCallback() { - @Override - public void onSuccess(V2XLivePushVoRes result) { - Logger.d(MODULE_NAME, "播放器:" + result); - } - - @Override - public void onFail(String msg) { - Logger.e(MODULE_NAME, "播放器:" + msg); - } - }, carLiveInfo.getVideoSn(), 1); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - if (mCarLiveInfo != null) { - startLive(mCarLiveInfo); - } - } - - @Override - protected void onDetachedFromWindow() { - stopLive(mCarLiveInfo); - mLoading.setVisibility(VISIBLE); - // 反注册语音交互 - V2XVoiceManager.INSTANCE - .unRegisterWakeCmd(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_CAR_LIVE) - .unRegisterUnWakeVoice(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_LIVE_UN_WAKEUP); - super.onDetachedFromWindow(); - } - - private void refreshStatusToListener(boolean videoPlaying) { - if (onVideoStatusChange != null) { - onVideoStatusChange.videoPlaying(videoPlaying); - } - } - - private V2XCarLiveVideoView.OnVideoStatusChange onVideoStatusChange; - - public void addOnVideoStatusChangeListener(V2XCarLiveVideoView.OnVideoStatusChange onVideoStatusChange) { - this.onVideoStatusChange = onVideoStatusChange; - } - - public interface OnVideoStatusChange { - void videoPlaying(boolean videoPlaying); - } -} diff --git a/modules/mogo-module-v2x/src/main/res/layout/view_video_layout_see_live.xml b/modules/mogo-module-v2x/src/main/res/layout/view_video_layout_see_live.xml index 303b339fe0..0ad6257f83 100644 --- a/modules/mogo-module-v2x/src/main/res/layout/view_video_layout_see_live.xml +++ b/modules/mogo-module-v2x/src/main/res/layout/view_video_layout_see_live.xml @@ -7,14 +7,8 @@ android:background="@color/live_video_background_color" app:roundLayoutRadius="@dimen/dp_20"> - - - - - - - From fd93948876952e0d600563806d10da0388e7a07a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Tue, 23 Feb 2021 20:00:05 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=BA=86SDK=E7=9A=84?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index 97a676134e..c8b1d0b7c8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -155,19 +155,19 @@ LOGLIB_VERSION = 1.0.4 ######## MogoAiCloudSDK Version # 网络请求 -MOGO_NETWORK_VERSION=1.0.33-SNAPSHOT +MOGO_NETWORK_VERSION=1.0.34-SNAPSHOT # 鉴权 -MOGO_PASSPORT_VERSION=1.0.33-SNAPSHOT +MOGO_PASSPORT_VERSION=1.0.34-SNAPSHOT # 常链接 -MOGO_SOCKET_VERSION=1.0.33-SNAPSHOT +MOGO_SOCKET_VERSION=1.0.34-SNAPSHOT # 数据采集 -MOGO_REALTIME_VERSION=1.0.33-SNAPSHOT +MOGO_REALTIME_VERSION=1.0.34-SNAPSHOT # 探路,道路事件发布,获取 -MOGO_TANLU_VERSION=1.0.33-SNAPSHOT +MOGO_TANLU_VERSION=1.0.34-SNAPSHOT # 直播推流 -MOGO_LIVE_VERSION=1.0.33-SNAPSHOT +MOGO_LIVE_VERSION=1.0.34-SNAPSHOT # 直播拉流 -MOGO_TRAFFICLIVE_VERSION=1.0.33-SNAPSHOT +MOGO_TRAFFICLIVE_VERSION=1.0.34-SNAPSHOT ######## Foundation MogoAiCloud Module # mogoAiCloud apk services From 5f853029b634539f71e72e4daeb35be469021c6f Mon Sep 17 00:00:00 2001 From: lixiaopeng Date: Tue, 23 Feb 2021 21:01:53 +0800 Subject: [PATCH 8/9] opt --- gradle.properties | 14 +++++++------- .../java/com/mogo/module/share/TanluManager.java | 12 +++++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/gradle.properties b/gradle.properties index c8b1d0b7c8..612baf2239 100644 --- a/gradle.properties +++ b/gradle.properties @@ -155,19 +155,19 @@ LOGLIB_VERSION = 1.0.4 ######## MogoAiCloudSDK Version # 网络请求 -MOGO_NETWORK_VERSION=1.0.34-SNAPSHOT +MOGO_NETWORK_VERSION=1.0.35-SNAPSHOT # 鉴权 -MOGO_PASSPORT_VERSION=1.0.34-SNAPSHOT +MOGO_PASSPORT_VERSION=1.0.35-SNAPSHOT # 常链接 -MOGO_SOCKET_VERSION=1.0.34-SNAPSHOT +MOGO_SOCKET_VERSION=1.0.35-SNAPSHOT # 数据采集 -MOGO_REALTIME_VERSION=1.0.34-SNAPSHOT +MOGO_REALTIME_VERSION=1.0.35-SNAPSHOT # 探路,道路事件发布,获取 -MOGO_TANLU_VERSION=1.0.34-SNAPSHOT +MOGO_TANLU_VERSION=1.0.35-SNAPSHOT # 直播推流 -MOGO_LIVE_VERSION=1.0.34-SNAPSHOT +MOGO_LIVE_VERSION=1.0.35-SNAPSHOT # 直播拉流 -MOGO_TRAFFICLIVE_VERSION=1.0.34-SNAPSHOT +MOGO_TRAFFICLIVE_VERSION=1.0.35-SNAPSHOT ######## Foundation MogoAiCloud Module # mogoAiCloud apk services diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/TanluManager.java b/modules/mogo-module-share/src/main/java/com/mogo/module/share/TanluManager.java index ada9bed5b4..79767d4021 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/TanluManager.java +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/TanluManager.java @@ -628,7 +628,6 @@ public class TanluManager implements IMogoMarkerClickListener, private void showBonndsRoadtion() { Logger.e(TAG, "showBonndsRoadtion markerExploreWayList.size() = " + markerExploreWayList.size()); - Logger.d(TAG, "showBonndsRoadtion getMogoList().size() = " + getMogoList().size()); //经度 Double longit = TanluServiceManager.getLocationClient().getLastKnowLocation().getLongitude(); //纬度 @@ -642,8 +641,15 @@ public class TanluManager implements IMogoMarkerClickListener, moveNotFresh(); //第一个参数:调用者,第二个参数:当前自车的位置,第三个参数:需要显示在范围内的点(不包含自车的位置) //第四个参数:显示范围的UI边界,第五个参数:是否锁定自车位置(看业务需要) - mMApUIController.showBounds(ShareConstants.MODEL_NAME, null, - getMogoList(), rect, false); + if (getMogoList() != null && getMogoList().size() > 0) { + Log.d(TAG, "showBonndsRoadtion size = " + getMogoList().size()); + MogoLatLng mogoLatLng = new MogoLatLng(lat, longit); + mMApUIController.showBounds(ShareConstants.MODEL_NAME, mogoLatLng, + getMogoList(), rect, false); + } else { + Log.e(TAG, "getMogoList() == null "); + } + } From 8db2d0a654c31bbc05166ecda004e234c3770f3c Mon Sep 17 00:00:00 2001 From: liujing Date: Wed, 24 Feb 2021 15:35:44 +0800 Subject: [PATCH 9/9] =?UTF-8?q?[add]=E5=89=8D=E8=BD=A6=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2zego=20ps:=E8=8E=B7=E5=8F=96=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/mogo-module-v2x/build.gradle | 1 + .../scene/livecar/V2XVoiceCallLiveBiz.java | 5 +- .../livecar/V2XVoiceCallLiveCarWindow.java | 5 +- .../livecar/V2XVoiceCallLiveScenario.java | 3 +- .../module/v2x/view/CarZegoLiveVideoView.java | 261 ++++++++++++++++++ .../item_v2x_see_frontcar_live_video.xml | 2 +- .../res/layout/view_video_layout_see_live.xml | 5 +- 7 files changed, 273 insertions(+), 9 deletions(-) create mode 100644 modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java diff --git a/modules/mogo-module-v2x/build.gradle b/modules/mogo-module-v2x/build.gradle index 2eaadb3a28..b84e556603 100644 --- a/modules/mogo-module-v2x/build.gradle +++ b/modules/mogo-module-v2x/build.gradle @@ -69,6 +69,7 @@ dependencies { kapt rootProject.ext.dependencies.roomAnnotationProcessor kapt rootProject.ext.dependencies.aroutercompiler + api rootProject.ext.dependencies.mogoaicloudtrafficlive if (Boolean.valueOf(RELEASE)) { implementation rootProject.ext.dependencies.mogomap diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/livecar/V2XVoiceCallLiveBiz.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/livecar/V2XVoiceCallLiveBiz.java index 11ea4647d4..caef8fffb8 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/livecar/V2XVoiceCallLiveBiz.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/livecar/V2XVoiceCallLiveBiz.java @@ -14,6 +14,7 @@ import com.mogo.module.v2x.entity.net.V2XLiveCrossRoad; import com.mogo.module.v2x.network.V2XRefreshCallback; import com.mogo.module.v2x.network.V2XRefreshModel; import com.mogo.module.v2x.utils.ToastUtils; +import com.mogo.module.v2x.view.V2XCarLiveVideoView; import com.mogo.module.v2x.voice.V2XVoiceCallbackListener; import com.mogo.module.v2x.voice.V2XVoiceManager; import com.mogo.service.statusmanager.StatusDescriptor; @@ -52,6 +53,7 @@ public class V2XVoiceCallLiveBiz { } private Context mContext; + private V2XVoiceCallLiveScenario mV2XVoiceCallLiveScenario = new V2XVoiceCallLiveScenario(); //语音词指令 查看前车视频回调 private V2XVoiceCallbackListener v2XVoiceCallbackFrontLiveCarListener = (command, intent) -> { @@ -107,8 +109,7 @@ public class V2XVoiceCallLiveBiz { return; } V2XMessageEntity v2XMessageEntity = buildCallLiveParams(liveCarSn, null); -// V2XVoiceCallLiveScenario.getInstance().setV2XWindow(new V2XVoiceCallLiveCarWindow()); -// V2XVoiceCallLiveScenario.getInstance().init(v2XMessageEntity); + mV2XVoiceCallLiveScenario.init(v2XMessageEntity); } public void getOpenRoadCameraLive() { diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/livecar/V2XVoiceCallLiveCarWindow.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/livecar/V2XVoiceCallLiveCarWindow.java index d70cf7a504..1908b5bb6b 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/livecar/V2XVoiceCallLiveCarWindow.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/livecar/V2XVoiceCallLiveCarWindow.java @@ -6,7 +6,6 @@ import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; -import android.widget.RelativeLayout; import android.widget.TextView; import com.mogo.module.common.entity.MarkerCarInfo; @@ -16,7 +15,7 @@ import com.mogo.module.v2x.V2XServiceManager; import com.mogo.module.v2x.listener.V2XWindowStatusListener; import com.mogo.module.v2x.scenario.scene.V2XBasWindow; import com.mogo.module.v2x.scenario.view.IV2XWindow; -import com.mogo.module.v2x.view.V2XCarLiveVideoView; +import com.mogo.module.v2x.view.CarZegoLiveVideoView; import com.mogo.utils.logger.Logger; import static com.mogo.module.v2x.V2XConst.MODULE_NAME; @@ -24,7 +23,7 @@ import static com.mogo.module.v2x.V2XConst.MODULE_NAME; public class V2XVoiceCallLiveCarWindow extends V2XBasWindow implements IV2XWindow { - private V2XCarLiveVideoView mV2XCarLiveVideoView; + private CarZegoLiveVideoView mV2XCarLiveVideoView; private TextView tvCountDown; private ImageView ivVideoPlayingSign; private boolean isVideoPlay = false; diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/livecar/V2XVoiceCallLiveScenario.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/livecar/V2XVoiceCallLiveScenario.java index 70a240ad6a..0f358c70b7 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/livecar/V2XVoiceCallLiveScenario.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/livecar/V2XVoiceCallLiveScenario.java @@ -12,6 +12,7 @@ import com.mogo.module.v2x.V2XConst; import com.mogo.module.v2x.V2XServiceManager; import com.mogo.module.v2x.scenario.impl.AbsV2XScenario; import com.mogo.module.v2x.utils.V2XUtils; +import com.mogo.module.v2x.view.CarZegoLiveVideoView; import com.mogo.service.windowview.IMogoTopViewStatusListener; import com.mogo.utils.TipToast; import com.mogo.utils.logger.Logger; @@ -25,7 +26,7 @@ import static com.mogo.module.v2x.V2XConst.MODULE_NAME; public class V2XVoiceCallLiveScenario extends AbsV2XScenario implements IMogoTopViewStatusListener { public V2XVoiceCallLiveScenario() { - + setV2XWindow(new V2XVoiceCallLiveCarWindow()); } @Override diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java new file mode 100644 index 0000000000..5e1eb94ee1 --- /dev/null +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java @@ -0,0 +1,261 @@ +package com.mogo.module.v2x.view; + +import android.content.Context; +import android.content.Intent; +import android.graphics.PorterDuff; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.SurfaceView; +import android.view.View; +import android.widget.ProgressBar; +import android.widget.TextView; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.core.content.ContextCompat; + +import com.mogo.cloud.trafficlive.api.ITrafficLiveCallBack; +import com.mogo.cloud.trafficlive.api.MoGoAiCloudTrafficLive; +import com.mogo.commons.AbsMogoApplication; +import com.mogo.commons.voice.AIAssist; +import com.mogo.module.common.entity.MarkerCarInfo; +import com.mogo.module.v2x.R; +import com.mogo.module.v2x.V2XServiceManager; +import com.mogo.module.v2x.entity.net.V2XLivePushVoRes; +import com.mogo.module.v2x.network.V2XRefreshCallback; +import com.mogo.module.v2x.utils.V2XUtils; +import com.mogo.module.v2x.voice.V2XVoiceCallbackListener; +import com.mogo.module.v2x.voice.V2XVoiceConstants; +import com.mogo.module.v2x.voice.V2XVoiceManager; +import com.mogo.utils.logger.Logger; +import com.tencent.rtmp.ui.TXCloudVideoView; + +import static com.mogo.module.v2x.V2XConst.MODULE_NAME; + +/** + * @author liujing + * @description 描述 + * @since: 2021/2/23 + */ +public class CarZegoLiveVideoView extends RoundLayout { + private SurfaceView mSurfaceView; + private ProgressBar mLoading; + private ConstraintLayout mClLoadError; + private TextView mTvRefreshButton; + + private MarkerCarInfo.CarLiveInfo mCarLiveInfo; + // 重新刷新直播流 + private V2XVoiceCallbackListener v2XVoiceCallbackRefreshListener = new V2XVoiceCallbackListener() { + @Override + public void onCallback(String command, Intent intent) { + mLoading.setVisibility(VISIBLE); + mClLoadError.setVisibility(GONE); + if (mCarLiveInfo != null) { + startLive(mCarLiveInfo); + } + } + }; + + public CarZegoLiveVideoView() { + this(V2XServiceManager.getContext(), null); + } + + public CarZegoLiveVideoView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public CarZegoLiveVideoView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initView(context); + } + + private void initView(Context context) { + LayoutInflater.from(context) + .inflate(R.layout.view_video_layout_see_live, this); + mSurfaceView = findViewById(R.id.surfaceView); + mSurfaceView.setZOrderOnTop(true); + mLoading = findViewById(R.id.loading); + mLoading.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, R.color.live_video_progress_bar_loading_color), PorterDuff.Mode.MULTIPLY); + + mClLoadError = findViewById(R.id.clLoadError); + mTvRefreshButton = findViewById(R.id.tvRefreshButton); + mTvRefreshButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + mLoading.setVisibility(VISIBLE); + mClLoadError.setVisibility(GONE); + if (mCarLiveInfo != null) { + startLive(mCarLiveInfo); + } + } + }); + } + + /** + * 设置直播信息 + */ + public void setCarLiveInfo(MarkerCarInfo.CarLiveInfo carLiveInfo) { + mCarLiveInfo = carLiveInfo; + } + + /** + * 开始直播 + * + * @param carLiveInfo 要直播的车机,如果没有直播的地址需要重新获取最新的直播地址 + */ + public void startLive(MarkerCarInfo.CarLiveInfo carLiveInfo) { + // 进行直播播放 + if (mSurfaceView != null + && carLiveInfo != null) { + if (!TextUtils.isEmpty(carLiveInfo.getVideoUrl())) { + AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live)); + setCarLiveInfo(carLiveInfo); + playLiveVideo(carLiveInfo); + } + // 根据SN重新获取直播流地址 + else { + V2XServiceManager + .getV2XRefreshModel() + .livePush(new V2XRefreshCallback() { + @Override + public void onSuccess(V2XLivePushVoRes result) { + AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live)); + mClLoadError.setVisibility(GONE); + mClLoadError.setVisibility(GONE); + try { + MarkerCarInfo.CarLiveInfo carRealLiveInfo = new MarkerCarInfo.CarLiveInfo(); + carRealLiveInfo.setVideoUrl(result.getResult().getPlayUrl().getRtmp()); + carRealLiveInfo.setVideoSn(carLiveInfo.getVideoSn()); + carRealLiveInfo.setVideoChannel(result.getResult().getVideoChannel()); + setCarLiveInfo(carLiveInfo); + playLiveVideo(carRealLiveInfo); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void onFail(String msg) { + Logger.e(MODULE_NAME, "播放器:" + msg); + AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live_error)); + mLoading.setVisibility(GONE); + mClLoadError.setVisibility(VISIBLE); + } + }, carLiveInfo.getVideoSn(), 0); + } + } + } + + /** + * 播放直播流,且开始心跳 + */ + private void playLiveVideo(MarkerCarInfo.CarLiveInfo carLiveInfo) { + startHeartLive(carLiveInfo); + if (mSurfaceView != null) { + MoGoAiCloudTrafficLive.viewVehicleHeadLive(AbsMogoApplication.getApp(), carLiveInfo.getVideoSn(), mSurfaceView, new ITrafficLiveCallBack() { + @Override + public void onLive() { + mLoading.setVisibility(VISIBLE); + mClLoadError.setVisibility(GONE); + refreshStatusToListener(true); + mLoading.setVisibility(GONE); + mClLoadError.setVisibility(GONE); + } + + @Override + public void onDisConnect() { + + } + + @Override + public void onError(String errorMsg) { + refreshStatusToListener(false); + AIAssist.getInstance(V2XUtils.getApp()).speakTTSVoice("直播获取识败,可以对我说重试", null); + stopLive(mCarLiveInfo); + mLoading.setVisibility(GONE); + mClLoadError.setVisibility(VISIBLE); + // 注册语音交互 + V2XVoiceManager.INSTANCE + .registerWakeCmd(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_CAR_LIVE, + v2XVoiceCallbackRefreshListener) + .registerUnWakeVoice(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_LIVE_UN_WAKEUP, + v2XVoiceCallbackRefreshListener); + } + }); + } + } + + // 刷新直播心跳 + private void startHeartLive(MarkerCarInfo.CarLiveInfo carLiveInfo) { + try { + if (!TextUtils.isEmpty(carLiveInfo.getVideoSn()) + && !TextUtils.isEmpty(carLiveInfo.getVideoChannel())) { + V2XServiceManager + .getV2XRefreshModel() + .refreshHeartBeat(carLiveInfo.getVideoSn(), + carLiveInfo.getVideoChannel(), + null); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void stopLive(MarkerCarInfo.CarLiveInfo carLiveInfo) { + try { + Logger.w(MODULE_NAME, "心跳:关闭直播..."); + // 暂停 + MoGoAiCloudTrafficLive.stopLive(carLiveInfo.getVideoSn()); + // 停止推流 + V2XServiceManager + .getV2XRefreshModel() + .livePush(new V2XRefreshCallback() { + @Override + public void onSuccess(V2XLivePushVoRes result) { + Logger.d(MODULE_NAME, "播放器:" + result); + } + + @Override + public void onFail(String msg) { + Logger.e(MODULE_NAME, "播放器:" + msg); + } + }, carLiveInfo.getVideoSn(), 1); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + if (mCarLiveInfo != null) { + startLive(mCarLiveInfo); + } + } + + @Override + protected void onDetachedFromWindow() { + stopLive(mCarLiveInfo); + mLoading.setVisibility(VISIBLE); + // 反注册语音交互 + V2XVoiceManager.INSTANCE + .unRegisterWakeCmd(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_CAR_LIVE) + .unRegisterUnWakeVoice(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_LIVE_UN_WAKEUP); + super.onDetachedFromWindow(); + } + + private void refreshStatusToListener(boolean videoPlaying) { + if (onVideoStatusChange != null) { + onVideoStatusChange.videoPlaying(videoPlaying); + } + } + + private V2XCarLiveVideoView.OnVideoStatusChange onVideoStatusChange; + + public void addOnVideoStatusChangeListener(V2XCarLiveVideoView.OnVideoStatusChange onVideoStatusChange) { + this.onVideoStatusChange = onVideoStatusChange; + } + + public interface OnVideoStatusChange { + void videoPlaying(boolean videoPlaying); + } +} diff --git a/modules/mogo-module-v2x/src/main/res/layout/item_v2x_see_frontcar_live_video.xml b/modules/mogo-module-v2x/src/main/res/layout/item_v2x_see_frontcar_live_video.xml index 8ecc584a7d..5296ed1c01 100644 --- a/modules/mogo-module-v2x/src/main/res/layout/item_v2x_see_frontcar_live_video.xml +++ b/modules/mogo-module-v2x/src/main/res/layout/item_v2x_see_frontcar_live_video.xml @@ -15,7 +15,7 @@ android:layout_centerInParent="true" android:src="@drawable/v2x_icon_live_logo" /> - -