| 175 | } |
| 176 | |
| 177 | static int open_camera(AVFormatContext *avctx) |
| 178 | { |
| 179 | AndroidCameraCtx *ctx = avctx->priv_data; |
| 180 | camera_status_t ret; |
| 181 | ACameraIdList *camera_ids; |
| 182 | |
| 183 | ret = ACameraManager_getCameraIdList(ctx->camera_mgr, &camera_ids); |
| 184 | if (ret != ACAMERA_OK) { |
| 185 | av_log(avctx, AV_LOG_ERROR, "Failed to get camera id list, error: %s.\n", |
| 186 | camera_status_string(ret)); |
| 187 | return AVERROR_EXTERNAL; |
| 188 | } |
| 189 | |
| 190 | if (ctx->camera_index < camera_ids->numCameras) { |
| 191 | ctx->camera_id = av_strdup(camera_ids->cameraIds[ctx->camera_index]); |
| 192 | if (!ctx->camera_id) { |
| 193 | av_log(avctx, AV_LOG_ERROR, "Failed to allocate memory for camera_id.\n"); |
| 194 | return AVERROR(ENOMEM); |
| 195 | } |
| 196 | } else { |
| 197 | av_log(avctx, AV_LOG_ERROR, "No camera with index %d available.\n", |
| 198 | ctx->camera_index); |
| 199 | return AVERROR(ENXIO); |
| 200 | } |
| 201 | |
| 202 | ACameraManager_deleteCameraIdList(camera_ids); |
| 203 | |
| 204 | ret = ACameraManager_getCameraCharacteristics(ctx->camera_mgr, |
| 205 | ctx->camera_id, &ctx->camera_metadata); |
| 206 | if (ret != ACAMERA_OK) { |
| 207 | av_log(avctx, AV_LOG_ERROR, "Failed to get metadata for camera with id %s, error: %s.\n", |
| 208 | ctx->camera_id, camera_status_string(ret)); |
| 209 | return AVERROR_EXTERNAL; |
| 210 | } |
| 211 | |
| 212 | ctx->camera_state_callbacks.context = avctx; |
| 213 | ctx->camera_state_callbacks.onDisconnected = camera_dev_disconnected; |
| 214 | ctx->camera_state_callbacks.onError = camera_dev_error; |
| 215 | |
| 216 | ret = ACameraManager_openCamera(ctx->camera_mgr, ctx->camera_id, |
| 217 | &ctx->camera_state_callbacks, &ctx->camera_dev); |
| 218 | if (ret != ACAMERA_OK) { |
| 219 | av_log(avctx, AV_LOG_ERROR, "Failed to open camera with id %s, error: %s.\n", |
| 220 | ctx->camera_id, camera_status_string(ret)); |
| 221 | return AVERROR_EXTERNAL; |
| 222 | } |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | static void get_sensor_orientation(AVFormatContext *avctx) |
| 228 | { |
no test coverage detected