MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / image_available

Function image_available

libavdevice/android_camera.c:377–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

375}
376
377static void image_available(void *context, AImageReader *reader)
378{
379 AVFormatContext *avctx = context;
380 AndroidCameraCtx *ctx = avctx->priv_data;
381 media_status_t media_status;
382 int ret = 0;
383
384 AImage *image;
385 int64_t image_timestamp;
386 int32_t image_linestrides[4];
387 uint8_t *image_plane_data[4];
388 int plane_data_length[4];
389
390 AVPacket pkt;
391 int pkt_buffer_size = 0;
392
393 media_status = AImageReader_acquireLatestImage(reader, &image);
394 if (media_status != AMEDIA_OK) {
395 if (media_status == AMEDIA_IMGREADER_NO_BUFFER_AVAILABLE) {
396 av_log(avctx, AV_LOG_WARNING,
397 "An image reader frame was discarded");
398 } else {
399 av_log(avctx, AV_LOG_ERROR,
400 "Failed to acquire latest image from image reader, error: %s.\n",
401 media_status_string(media_status));
402 ret = AVERROR_EXTERNAL;
403 }
404 goto error;
405 }
406
407 // Silently drop frames when exit is set
408 if (atomic_load(&ctx->exit)) {
409 goto error;
410 }
411
412 // Determine actual image format
413 if (!atomic_load(&ctx->got_image_format)) {
414 ret = get_image_format(avctx, image);
415 if (ret < 0) {
416 av_log(avctx, AV_LOG_ERROR,
417 "Could not get image format of camera.\n");
418 goto error;
419 } else {
420 atomic_store(&ctx->got_image_format, 1);
421 }
422 }
423
424 pkt_buffer_size = av_image_get_buffer_size(ctx->image_format, ctx->width, ctx->height, 1);
425 AImage_getTimestamp(image, &image_timestamp);
426
427 AImage_getPlaneRowStride(image, 0, &image_linestrides[0]);
428 AImage_getPlaneData(image, 0, &image_plane_data[0], &plane_data_length[0]);
429
430 switch (ctx->image_format) {
431 case AV_PIX_FMT_YUV420P:
432 AImage_getPlaneRowStride(image, 1, &image_linestrides[1]);
433 AImage_getPlaneData(image, 1, &image_plane_data[1], &plane_data_length[1]);
434 AImage_getPlaneRowStride(image, 2, &image_linestrides[2]);

Callers

nothing calls this directly

Calls 8

av_logFunction · 0.85
get_image_formatFunction · 0.85
av_image_get_buffer_sizeFunction · 0.85
av_new_packetFunction · 0.85
av_image_copy_to_bufferFunction · 0.85
av_packet_unrefFunction · 0.85

Tested by

no test coverage detected