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
 
AVInputFormat ff_android_camera_demuxer
 

Macro Definition Documentation

#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().

#define MAX_BUF_COUNT   2

Definition at line 52 of file android_camera.c.

Referenced by create_image_reader().

#define VIDEO_STREAM_INDEX   0

Definition at line 53 of file android_camera.c.

Referenced by add_video_stream(), and image_available().

#define VIDEO_TIMEBASE_ANDROID   1000000000

Definition at line 54 of file android_camera.c.

Referenced by add_video_stream().

#define RETURN_CASE (   x)    case x: return AV_STRINGIFY(x);
#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().

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

Definition at line 844 of file android_camera.c.

#define DEC   AV_OPT_FLAG_DECODING_PARAM

Definition at line 845 of file android_camera.c.

Function Documentation

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().

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().

static const char* error_state_callback_string ( int  val)
static

Definition at line 145 of file android_camera.c.

Referenced by camera_dev_error().

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

Definition at line 158 of file android_camera.c.

Referenced by open_camera().

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().

static int open_camera ( AVFormatContext avctx)
static

Definition at line 176 of file android_camera.c.

Referenced by android_camera_read_header().

static void get_sensor_orientation ( AVFormatContext avctx)
static

Definition at line 226 of file android_camera.c.

Referenced by android_camera_read_header().

static void match_video_size ( AVFormatContext avctx)
static

Definition at line 241 of file android_camera.c.

Referenced by android_camera_read_header().

static void match_framerate ( AVFormatContext avctx)
static

Definition at line 286 of file android_camera.c.

Referenced by android_camera_read_header().

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

Definition at line 337 of file android_camera.c.

Referenced by 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().

static int create_image_reader ( AVFormatContext avctx)
static

Definition at line 488 of file android_camera.c.

Referenced by android_camera_read_header().

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

Definition at line 523 of file android_camera.c.

Referenced by create_capture_session().

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

Definition at line 528 of file android_camera.c.

Referenced by create_capture_session().

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

Definition at line 533 of file android_camera.c.

Referenced by 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().

static int wait_for_image_format ( AVFormatContext avctx)
static

Definition at line 628 of file android_camera.c.

Referenced by add_video_stream().

static int add_display_matrix ( AVFormatContext avctx,
AVStream st 
)
static

Definition at line 640 of file android_camera.c.

Referenced by 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().

static int android_camera_read_close ( AVFormatContext avctx)
static

Definition at line 695 of file android_camera.c.

Referenced by android_camera_read_header().

static int android_camera_read_header ( AVFormatContext avctx)
static

Definition at line 772 of file android_camera.c.

static int android_camera_read_packet ( AVFormatContext avctx,
AVPacket pkt 
)
static

Definition at line 825 of file android_camera.c.

Variable Documentation

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
int framerate
Definition: h264_levels.c:65
#define OFFSET(x)
offset must point to AVRational
Definition: opt.h:238
offset must point to two consecutive integers
Definition: opt.h:235

Definition at line 846 of file android_camera.c.

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:235
static const AVOption options[]

Definition at line 854 of file android_camera.c.

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 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:153
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:527
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
#define flags(name, subs,...)
Definition: cbs_av1.c:560
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:458

Definition at line 862 of file android_camera.c.