Android平台GB28181设备接入模块分辨率发生变化怎么办?
2023-06-13 09:16:05 时间
技术背景
我们在做Android平台gb28181设备接入模块的时候,遇到这样的情况,比如横竖屏分辨率不锁定,采集摄像头的时候,可以实现,横屏状态采集横屏,竖屏状态采集竖屏,简单来说,横屏状态比如采集的1280*720的,竖屏状态,采集的数据源成了720*1280。
这块对我们来说,已经轻车熟路了,老早就已经处理,分辨率发生变化的时候,会重启encoder,确保正常兼容,不幸的是,好多gb28181平台侧,对分辨率切换,支持的并不友好,分辨率发生变化的时候,有些国标平台播放上来的视频流的时候,会直接crash。
分辨率变化,其实多数国标平台厂商都可以兼容,或者说应该兼容,如果国标平台侧不兼容的话,我们可以在android平台gb28181设备接入侧做一定的处理。
技术实现
以Android的camera2为例,我们做了“锁定图像方向”选项:
对应的代码实现如下:
class ButtonCameraImageOrientationLockListener implements View.OnClickListener {
public void onClick(View v) {
is_need_lock_image_orientation_ = !is_need_lock_image_orientation_;
if (cur_image_orientation_ >= 0)
cur_image_orientation_ = orientation_;
if(camera2Helper != null)
cameraImageRotationDegree_ = camera2Helper.getCameraImageRotationDegree(cur_image_orientation_ < 0 ?orientation_ : cur_image_orientation_);
btnCameraImageOrientationLock.setText(is_need_lock_image_orientation_?"解锁图像方向" : "锁定图像方向");
}
}
其中,getCameraImageRotationDegree实现如下:
public int getCameraImageRotationDegree(int device_degree) {
if (device_degree < 0)
return -1;
String camera_id = getCameraId();
int degree;
if (CAMERA_ID_BACK.equals(camera_id)) {
degree = (mSensorOrientation + device_degree + 360) % 360;
Log.i(TAG, "getCameraImageRotationDegree BACK device_degree:" + device_degree
+ " SENSOR_ORIENTATION:" + mSensorOrientation + " degree:" + degree);
}
else {
degree = (mSensorOrientation - device_degree + 360) % 360;
Log.i(TAG, "getCameraImageRotationDegree FRONT device_degree:" + device_degree
+ " SENSOR_ORIENTATION:" + mSensorOrientation + " degree:" + degree);
}
return degree;
}
针对摄像头rotation变化监测listener:
/*
* Github: https://github.com/daniulive/SmarterStreaming
*/
class OnOriChangedListener implements OrientationDetector.OriginListener {
@Override
public void onOrientationChanged(int orientation, int rotation) {
orientation_ = orientation;
if (!is_need_lock_image_orientation_ || cur_image_orientation_ < 0)
cur_image_orientation_ = orientation_;
Log.i(TAG, "onOrientationChanged:" + orientation + " rotation:" + rotation + " rotation.toString:" + Camera2Helper.getRotationString(rotation));
if(camera2Helper != null) {
camera2Helper.updateOrientation(orientation);
cameraImageRotationDegree_ = camera2Helper.getCameraImageRotationDegree(cur_image_orientation_ < 0 ?orientation_ : cur_image_orientation_);
}
if (layer_post_thread_ != null ) {
int rotation_degree = cameraImageRotationDegree_;
if (rotation_degree < 0)
layer_post_thread_.updateVideoSize(0, 0);
else if (90 == rotation_degree || 270 == rotation_degree)
layer_post_thread_.updateVideoSize(video_height_, video_width_);
else
layer_post_thread_.updateVideoSize(video_width_, video_height_);
}
}
}
总结
值得一提的是,如果视频分辨率发生变化,本地录像的话,一般来说会切换新的录像文件,国标平台侧如果做的比较好的话,一般都会兼容这种分辨率变化的场景,起码确保分辨率切换的时候,不至于直接crash。
实际上,比如一些执法记录仪等场景下,只需要一个固定的采集方向即可,这种情况下,锁定方向,反而是最好的。
相关文章
- 加密狗android,Android系统加密狗的设计与实现
- android 常用加密,分享一下Android各种类型的加密
- android activity自动跳转,Android activity跳转之finish()方法的作用
- android deeplink流程,Android Deeplink探究[通俗易懂]
- android进阶之了解Android系统与开机过程
- android activity singletask,Android Activity启动模式之singleTask实例详解
- android 定时器重置,Android定时器延迟和重置[通俗易懂]
- android toast全屏,Android Toast实现全屏显示
- android触摸屏事件,Android Touch事件分析
- Android平台GB28181设备接入模块摄像头采集方向不对怎么办?
- android开发艺术探索学习 之 结合Activity的生命周期了解Activity的LaunchMode
- Android Foreground Service
- 如何使用scrcpy管理和控制你的Android设备
- 【错误记录】Android Studio 编译报错 ( Could not find com.android.tools.build:gradle:4.2.1. )
- [android] 天气app布局练习详解手机开发
- 关于Android的UI测试详解手机开发
- Android 服务详解手机开发
- Android解压Zip包详解编程语言
- Android Progressbar自定义菊花效果
- Android实现PHP连接MySQL进行数据交互(android通过php连接mysql)
- 通过JavaScript或PHP检测Android设备的代码
- android手机获取gps和基站的经纬度地址实现代码
- Android系统自带样式(android:theme)
- 基于android示例程序(bitmapfun)高效加载图片让人无语地方
- Android中的android:layout_weight使用详解
- android中去掉窗口全屏显示的简单方法
- Android中使用ListView实现漂亮的表格效果