FFmpeg  4.0
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
 
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.

Referenced by create_image_reader(), and match_video_size().

◆ MAX_BUF_COUNT

#define MAX_BUF_COUNT   2

Definition at line 52 of file android_camera.c.

Referenced by create_image_reader().

◆ VIDEO_STREAM_INDEX

#define VIDEO_STREAM_INDEX   0

Definition at line 53 of file android_camera.c.

Referenced by add_video_stream(), and image_available().

◆ VIDEO_TIMEBASE_ANDROID

#define VIDEO_TIMEBASE_ANDROID   1000000000

Definition at line 54 of file android_camera.c.

Referenced by add_video_stream().

◆ RETURN_CASE

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

◆ RETURN_DEFAULT

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

Definition at line 57 of file android_camera.c.

Referenced by camera_status_string(), and media_status_string().

◆ 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 },
}
#define NULL
Definition: coverity.c:32
#define DEC
#define OFFSET(x)
offset must point to AVRational
Definition: opt.h:236
offset must point to two consecutive integers
Definition: opt.h:233

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,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
static const AVOption options[]

Definition at line 854 of file android_camera.c.

◆ ff_android_camera_demuxer

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,
}
static const AVClass android_camera_class
static int android_camera_read_close(AVFormatContext *avctx)
static int flags
Definition: log.c:55
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
static int android_camera_read_header(AVFormatContext *avctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:530
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
static int android_camera_read_packet(AVFormatContext *avctx, AVPacket *pkt)
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:465

Definition at line 862 of file android_camera.c.