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 <unistd.h>
#include <camera/NdkCameraDevice.h>
#include <camera/NdkCameraManager.h>
#include <media/NdkImage.h>
#include <media/NdkImageReader.h>
#include "libavformat/avformat.h"
#include "libavformat/demux.h"
#include "libavformat/internal.h"
#include "libavutil/avstring.h"
#include "libavutil/display.h"
#include "libavutil/imgutils.h"
#include "libavutil/log.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixfmt.h"
#include "libavutil/threadmessage.h"
#include "libavutil/time.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 FFInputFormat ff_android_camera_demuxer
 

Macro Definition Documentation

◆ IMAGE_FORMAT_ANDROID

#define IMAGE_FORMAT_ANDROID   AIMAGE_FORMAT_YUV_420_888

Definition at line 51 of file android_camera.c.

◆ MAX_BUF_COUNT

#define MAX_BUF_COUNT   2

Definition at line 53 of file android_camera.c.

◆ VIDEO_STREAM_INDEX

#define VIDEO_STREAM_INDEX   0

Definition at line 54 of file android_camera.c.

◆ VIDEO_TIMEBASE_ANDROID

#define VIDEO_TIMEBASE_ANDROID   1000000000

Definition at line 55 of file android_camera.c.

◆ RETURN_CASE

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

Definition at line 57 of file android_camera.c.

◆ RETURN_DEFAULT

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

Definition at line 58 of file android_camera.c.

◆ OFFSET

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

Definition at line 847 of file android_camera.c.

◆ DEC

#define DEC   AV_OPT_FLAG_DECODING_PARAM

Definition at line 848 of file android_camera.c.

Function Documentation

◆ camera_status_string()

static const char* camera_status_string ( camera_status_t  val)
static

Definition at line 96 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 118 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 146 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 159 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 168 of file android_camera.c.

Referenced by open_camera().

◆ open_camera()

static int open_camera ( AVFormatContext avctx)
static

Definition at line 177 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 227 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 242 of file android_camera.c.

Referenced by android_camera_read_header().

◆ match_framerate()

static void match_framerate ( AVFormatContext avctx)
static

Definition at line 287 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 338 of file android_camera.c.

Referenced by image_available().

◆ image_available()

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

Definition at line 377 of file android_camera.c.

Referenced by create_image_reader().

◆ create_image_reader()

static int create_image_reader ( AVFormatContext avctx)
static

Definition at line 489 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 524 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 529 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 534 of file android_camera.c.

Referenced by create_capture_session().

◆ create_capture_session()

static int create_capture_session ( AVFormatContext avctx)
static

Definition at line 539 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 629 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 641 of file android_camera.c.

Referenced by add_video_stream().

◆ add_video_stream()

static int add_video_stream ( AVFormatContext avctx)
static

Definition at line 667 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 698 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 775 of file android_camera.c.

◆ android_camera_read_packet()

static int android_camera_read_packet ( AVFormatContext avctx,
AVPacket pkt 
)
static

Definition at line 828 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 849 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 857 of file android_camera.c.

◆ ff_android_camera_demuxer

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

Definition at line 865 of file android_camera.c.

options
static const AVOption options[]
Definition: android_camera.c:849
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
Definition: opt.h:315
DEC
#define DEC
Definition: android_camera.c:848
android_camera_read_close
static int android_camera_read_close(AVFormatContext *avctx)
Definition: android_camera.c:698
read_close
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:143
AndroidCameraCtx
Definition: android_camera.c:60
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_read_callback.c:42
android_camera_read_header
static int android_camera_read_header(AVFormatContext *avctx)
Definition: android_camera.c:775
framerate
float framerate
Definition: av1_levels.c:29
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:540
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:828
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
Definition: opt.h:303
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
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:94
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:468
OFFSET
#define OFFSET(x)
Definition: android_camera.c:847
android_camera_class
static const AVClass android_camera_class
Definition: android_camera.c:857
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259