FFmpeg
Data Structures | Macros | Functions | Variables
android_camera.c File Reference
#include <errno.h>
#include <pthread.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
#include <camera/NdkCameraDevice.h>
#include <camera/NdkCameraManager.h>
#include <media/NdkImage.h>
#include <media/NdkImageReader.h>
#include "libavformat/avformat.h"
#include "libavformat/internal.h"
#include "libavutil/avstring.h"
#include "libavutil/display.h"
#include "libavutil/imgutils.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixfmt.h"
#include "libavutil/threadmessage.h"
#include "libavutil/time.h"
#include "version.h"

Go to the source code of this file.

Data Structures

struct  AndroidCameraCtx
 

Macros

#define IMAGE_FORMAT_ANDROID   AIMAGE_FORMAT_YUV_420_888
 
#define MAX_BUF_COUNT   2
 
#define VIDEO_STREAM_INDEX   0
 
#define VIDEO_TIMEBASE_ANDROID   1000000000
 
#define RETURN_CASE(x)   case x: return AV_STRINGIFY(x);
 
#define RETURN_DEFAULT(x)   default: return AV_STRINGIFY(x);
 
#define OFFSET(x)   offsetof(AndroidCameraCtx, x)
 
#define DEC   AV_OPT_FLAG_DECODING_PARAM
 

Functions

static const char * camera_status_string (camera_status_t val)
 
static const char * media_status_string (media_status_t val)
 
static const char * error_state_callback_string (int val)
 
static void camera_dev_disconnected (void *context, ACameraDevice *device)
 
static void camera_dev_error (void *context, ACameraDevice *device, int error)
 
static int open_camera (AVFormatContext *avctx)
 
static void get_sensor_orientation (AVFormatContext *avctx)
 
static void match_video_size (AVFormatContext *avctx)
 
static void match_framerate (AVFormatContext *avctx)
 
static int get_image_format (AVFormatContext *avctx, AImage *image)
 
static void image_available (void *context, AImageReader *reader)
 
static int create_image_reader (AVFormatContext *avctx)
 
static void capture_session_closed (void *context, ACameraCaptureSession *session)
 
static void capture_session_ready (void *context, ACameraCaptureSession *session)
 
static void capture_session_active (void *context, ACameraCaptureSession *session)
 
static int create_capture_session (AVFormatContext *avctx)
 
static int wait_for_image_format (AVFormatContext *avctx)
 
static int add_display_matrix (AVFormatContext *avctx, AVStream *st)
 
static int add_video_stream (AVFormatContext *avctx)
 
static int android_camera_read_close (AVFormatContext *avctx)
 
static int android_camera_read_header (AVFormatContext *avctx)
 
static int android_camera_read_packet (AVFormatContext *avctx, AVPacket *pkt)
 

Variables

static const AVOption options []
 
static const AVClass android_camera_class
 
const AVInputFormat ff_android_camera_demuxer
 

Macro Definition Documentation

◆ IMAGE_FORMAT_ANDROID

#define IMAGE_FORMAT_ANDROID   AIMAGE_FORMAT_YUV_420_888

Definition at line 50 of file android_camera.c.

◆ MAX_BUF_COUNT

#define MAX_BUF_COUNT   2

Definition at line 52 of file android_camera.c.

◆ VIDEO_STREAM_INDEX

#define VIDEO_STREAM_INDEX   0

Definition at line 53 of file android_camera.c.

◆ VIDEO_TIMEBASE_ANDROID

#define VIDEO_TIMEBASE_ANDROID   1000000000

Definition at line 54 of file android_camera.c.

◆ RETURN_CASE

#define RETURN_CASE (   x)    case x: return AV_STRINGIFY(x);

Definition at line 56 of file android_camera.c.

◆ RETURN_DEFAULT

#define RETURN_DEFAULT (   x)    default: return AV_STRINGIFY(x);

Definition at line 57 of file android_camera.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(AndroidCameraCtx, x)

Definition at line 844 of file android_camera.c.

◆ DEC

#define DEC   AV_OPT_FLAG_DECODING_PARAM

Definition at line 845 of file android_camera.c.

Function Documentation

◆ camera_status_string()

static const char* camera_status_string ( camera_status_t  val)
static

Definition at line 95 of file android_camera.c.

Referenced by create_capture_session(), and open_camera().

◆ media_status_string()

static const char* media_status_string ( media_status_t  val)
static

Definition at line 117 of file android_camera.c.

Referenced by create_image_reader(), and image_available().

◆ error_state_callback_string()

static const char* error_state_callback_string ( int  val)
static

Definition at line 145 of file android_camera.c.

Referenced by camera_dev_error().

◆ camera_dev_disconnected()

static void camera_dev_disconnected ( void *  context,
ACameraDevice *  device 
)
static

Definition at line 158 of file android_camera.c.

Referenced by open_camera().

◆ camera_dev_error()

static void camera_dev_error ( void *  context,
ACameraDevice *  device,
int  error 
)
static

Definition at line 167 of file android_camera.c.

Referenced by open_camera().

◆ open_camera()

static int open_camera ( AVFormatContext avctx)
static

Definition at line 176 of file android_camera.c.

Referenced by android_camera_read_header().

◆ get_sensor_orientation()

static void get_sensor_orientation ( AVFormatContext avctx)
static

Definition at line 226 of file android_camera.c.

Referenced by android_camera_read_header().

◆ match_video_size()

static void match_video_size ( AVFormatContext avctx)
static

Definition at line 241 of file android_camera.c.

Referenced by android_camera_read_header().

◆ match_framerate()

static void match_framerate ( AVFormatContext avctx)
static

Definition at line 286 of file android_camera.c.

Referenced by android_camera_read_header().

◆ get_image_format()

static int get_image_format ( AVFormatContext avctx,
AImage *  image 
)
static

Definition at line 337 of file android_camera.c.

Referenced by image_available().

◆ image_available()

static void image_available ( void *  context,
AImageReader *  reader 
)
static

Definition at line 376 of file android_camera.c.

Referenced by create_image_reader().

◆ create_image_reader()

static int create_image_reader ( AVFormatContext avctx)
static

Definition at line 488 of file android_camera.c.

Referenced by android_camera_read_header().

◆ capture_session_closed()

static void capture_session_closed ( void *  context,
ACameraCaptureSession *  session 
)
static

Definition at line 523 of file android_camera.c.

Referenced by create_capture_session().

◆ capture_session_ready()

static void capture_session_ready ( void *  context,
ACameraCaptureSession *  session 
)
static

Definition at line 528 of file android_camera.c.

Referenced by create_capture_session().

◆ capture_session_active()

static void capture_session_active ( void *  context,
ACameraCaptureSession *  session 
)
static

Definition at line 533 of file android_camera.c.

Referenced by create_capture_session().

◆ create_capture_session()

static int create_capture_session ( AVFormatContext avctx)
static

Definition at line 538 of file android_camera.c.

Referenced by android_camera_read_header().

◆ wait_for_image_format()

static int wait_for_image_format ( AVFormatContext avctx)
static

Definition at line 628 of file android_camera.c.

Referenced by add_video_stream().

◆ add_display_matrix()

static int add_display_matrix ( AVFormatContext avctx,
AVStream st 
)
static

Definition at line 640 of file android_camera.c.

Referenced by add_video_stream().

◆ add_video_stream()

static int add_video_stream ( AVFormatContext avctx)
static

Definition at line 664 of file android_camera.c.

Referenced by android_camera_read_header().

◆ android_camera_read_close()

static int android_camera_read_close ( AVFormatContext avctx)
static

Definition at line 695 of file android_camera.c.

Referenced by android_camera_read_header().

◆ android_camera_read_header()

static int android_camera_read_header ( AVFormatContext avctx)
static

Definition at line 772 of file android_camera.c.

◆ android_camera_read_packet()

static int android_camera_read_packet ( AVFormatContext avctx,
AVPacket pkt 
)
static

Definition at line 825 of file android_camera.c.

Variable Documentation

◆ options

const AVOption options[]
static
Initial value:
= {
{ "video_size", "set video size given as a string such as 640x480 or hd720", OFFSET(requested_width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
{ "framerate", "set video frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "30"}, 0, INT_MAX, DEC },
{ "camera_index", "set index of camera to use", OFFSET(camera_index), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
{ "input_queue_size", "set maximum number of frames to buffer", OFFSET(input_queue_size), AV_OPT_TYPE_INT, {.i64 = 5}, 0, INT_MAX, DEC },
{ NULL },
}

Definition at line 846 of file android_camera.c.

◆ android_camera_class

const AVClass android_camera_class
static
Initial value:
= {
.class_name = "android_camera indev",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 854 of file android_camera.c.

◆ ff_android_camera_demuxer

const AVInputFormat ff_android_camera_demuxer
Initial value:
= {
.name = "android_camera",
.long_name = NULL_IF_CONFIG_SMALL("Android camera input device"),
.priv_data_size = sizeof(AndroidCameraCtx),
.priv_class = &android_camera_class,
}

Definition at line 862 of file android_camera.c.

options
static const AVOption options[]
Definition: android_camera.c:846
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
Definition: opt.h:237
DEC
#define DEC
Definition: android_camera.c:845
android_camera_read_close
static int android_camera_read_close(AVFormatContext *avctx)
Definition: android_camera.c:695
framerate
int framerate
Definition: h264_levels.c:65
read_close
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:141
AndroidCameraCtx
Definition: android_camera.c:59
android_camera_read_header
static int android_camera_read_header(AVFormatContext *avctx)
Definition: android_camera.c:772
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:527
NULL
#define NULL
Definition: coverity.c:32
android_camera_read_packet
static int android_camera_read_packet(AVFormatContext *avctx, AVPacket *pkt)
Definition: android_camera.c:825
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:234
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT
@ AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT
Definition: log.h:41
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:464
OFFSET
#define OFFSET(x)
Definition: android_camera.c:844
android_camera_class
static const AVClass android_camera_class
Definition: android_camera.c:854
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561