| | |
| | | int width; |
| | | int height; |
| | | int framerate; |
| | | String simPhone; |
| | | |
| | | // 从JSON解析配置 |
| | | static EncodeConfig fromJson(String jsonConfig) throws JSONException { |
| | |
| | | config.framerate = DEFAULT_FRAME_RATE; |
| | | config.ip = null; |
| | | config.port = 0; |
| | | config.simPhone = null; |
| | | return config; |
| | | } |
| | | |
| | |
| | | config.framerate = json.optInt("framerate", DEFAULT_FRAME_RATE); |
| | | config.ip = json.optString("ip", null); |
| | | config.port = json.optInt("port", 0); |
| | | config.simPhone = json.optString("simPhone", null); |
| | | |
| | | return config; |
| | | } |
| | |
| | | /** |
| | | * 控制H264编码 |
| | | * @param action 操作类型:0-开启h264文件写入,1-停止h264编码并停止写入文件,2-开启网络推送h264(不写入文件),3-停止h264编码并停止网络推送 |
| | | * @param jsonConfig JSON格式的配置参数,包含:ip、port、width、height、framerate |
| | | * @param jsonConfig JSON格式的配置参数,包含:ip、port、width、height、framerate、simPhone |
| | | * @return 0-成功,1-失败 |
| | | */ |
| | | private synchronized int controlEncode(int action, String jsonConfig) { |
| | |
| | | try { |
| | | config = EncodeConfig.fromJson(jsonConfig); |
| | | Log.d(TAG, "Parsed config - width: " + config.width + ", height: " + config.height + |
| | | ", framerate: " + config.framerate + ", ip: " + config.ip + ", port: " + config.port); |
| | | ", framerate: " + config.framerate + ", ip: " + config.ip + ", port: " + config.port + |
| | | ", simPhone: " + config.simPhone); |
| | | } catch (JSONException e) { |
| | | Log.e(TAG, "Failed to parse JSON config: " + jsonConfig, e); |
| | | return 1; // 失败 |
| | |
| | | h264Encoder.setEnableNetworkTransmission(true); |
| | | h264Encoder.setServerAddress(config.ip, config.port); |
| | | |
| | | // 设置协议参数(使用默认值,可根据需要从配置中添加) |
| | | // TODO: 如果需要在JSON配置中添加simCardNumber和logicalChannelNumber,可以在这里解析 |
| | | h264Encoder.setProtocolParams("013120122580", (byte)1); |
| | | // 设置协议参数(使用配置中的simPhone,如果未提供则使用默认值) |
| | | String simPhone = config.simPhone != null && !config.simPhone.trim().isEmpty() |
| | | ? config.simPhone : "013120122580"; |
| | | h264Encoder.setProtocolParams(simPhone, (byte)1); |
| | | |
| | | // 初始化并启动(使用配置中的分辨率) |
| | | int[] resolution = {width, height}; |