| 336 | } |
| 337 | |
| 338 | static int get_image_format(AVFormatContext *avctx, AImage *image) |
| 339 | { |
| 340 | AndroidCameraCtx *ctx = avctx->priv_data; |
| 341 | int32_t image_pixelstrides[2]; |
| 342 | uint8_t *image_plane_data[2]; |
| 343 | int plane_data_length[2]; |
| 344 | |
| 345 | for (int i = 0; i < 2; i++) { |
| 346 | AImage_getPlanePixelStride(image, i + 1, &image_pixelstrides[i]); |
| 347 | AImage_getPlaneData(image, i + 1, &image_plane_data[i], &plane_data_length[i]); |
| 348 | } |
| 349 | |
| 350 | if (image_pixelstrides[0] != image_pixelstrides[1]) { |
| 351 | av_log(avctx, AV_LOG_ERROR, |
| 352 | "Pixel strides of U and V plane should have been the same.\n"); |
| 353 | return AVERROR_EXTERNAL; |
| 354 | } |
| 355 | |
| 356 | switch (image_pixelstrides[0]) { |
| 357 | case 1: |
| 358 | ctx->image_format = AV_PIX_FMT_YUV420P; |
| 359 | break; |
| 360 | case 2: |
| 361 | if (image_plane_data[0] < image_plane_data[1]) { |
| 362 | ctx->image_format = AV_PIX_FMT_NV12; |
| 363 | } else { |
| 364 | ctx->image_format = AV_PIX_FMT_NV21; |
| 365 | } |
| 366 | break; |
| 367 | default: |
| 368 | av_log(avctx, AV_LOG_ERROR, |
| 369 | "Unknown pixel stride %d of U and V plane, cannot determine camera image format.\n", |
| 370 | image_pixelstrides[0]); |
| 371 | return AVERROR(ENOSYS); |
| 372 | } |
| 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | static void image_available(void *context, AImageReader *reader) |
| 378 | { |
no test coverage detected