Skip to content

Commit

Permalink
compat: camera: Allow applications to turn on preview callbacks
Browse files Browse the repository at this point in the history
This is required for Oxide in order for it to receive software frames
  • Loading branch information
chrisccoulson committed Dec 9, 2015
1 parent a8fa02c commit d09ac2d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
15 changes: 15 additions & 0 deletions compat/camera/camera_compatibility_layer.cpp
Expand Up @@ -117,6 +117,9 @@ void CameraControl::postData(
if (listener->on_data_compressed_image_cb)
listener->on_data_compressed_image_cb(data->pointer(), data->size(), listener->context);
break;
case CAMERA_MSG_PREVIEW_FRAME:
if (listener->on_preview_frame_cb)
listener->on_preview_frame_cb(data->pointer(), data->size(), listener->context);
default:
break;
}
Expand Down Expand Up @@ -810,6 +813,18 @@ void android_camera_take_snapshot(CameraControl* control)
control->camera->takePicture(CAMERA_MSG_SHUTTER | CAMERA_MSG_COMPRESSED_IMAGE);
}

void android_camera_set_preview_callback_mode(CameraControl* control, PreviewCallbackMode mode)
{
REPORT_FUNCTION();
assert(control);

android::Mutex::Autolock al(control->guard);

control->camera->setPreviewCallbackFlags(
mode == PREVIEW_CALLBACK_ENABLED ?
CAMERA_FRAME_CALLBACK_FLAG_CAMCORDER : CAMERA_FRAME_CALLBACK_FLAG_NOOP);
}

void android_camera_set_preview_format(CameraControl* control, CameraPixelFormat pf)
{
REPORT_FUNCTION();
Expand Down
5 changes: 4 additions & 1 deletion hybris/camera/camera.c
Expand Up @@ -53,7 +53,7 @@ HYBRIS_IMPLEMENT_VOID_FUNCTION2(camera, android_camera_set_scene_mode,
HYBRIS_IMPLEMENT_VOID_FUNCTION2(camera, android_camera_set_auto_focus_mode,
struct CameraControl*, AutoFocusMode);
HYBRIS_IMPLEMENT_VOID_FUNCTION2(camera, android_camera_set_preview_format,
struct CameraControl*, CameraPixelFormat);
struct CameraControl*, CameraPixelFormat);
HYBRIS_IMPLEMENT_VOID_FUNCTION3(camera, android_camera_set_picture_size,
struct CameraControl*, int, int);
HYBRIS_IMPLEMENT_VOID_FUNCTION3(camera, android_camera_set_thumbnail_size,
Expand Down Expand Up @@ -136,3 +136,6 @@ HYBRIS_IMPLEMENT_VOID_FUNCTION2(camera, android_camera_start_zoom, struct Camera
HYBRIS_IMPLEMENT_VOID_FUNCTION2(camera, android_camera_set_zoom, struct CameraControl*, int32_t);
HYBRIS_IMPLEMENT_VOID_FUNCTION1(camera, android_camera_stop_zoom, struct CameraControl*);
HYBRIS_IMPLEMENT_VOID_FUNCTION1(camera, android_camera_take_snapshot, struct CameraControl*);

HYBRIS_IMPLEMENT_VOID_FUNCTION2(camera, android_camera_set_preview_callback_mode,
struct CameraControl*, PreviewCallbackMode);
13 changes: 13 additions & 0 deletions hybris/include/hybris/camera/camera_compatibility_layer.h
Expand Up @@ -37,6 +37,12 @@ extern "C" {
FRONT_FACING_CAMERA_TYPE
} CameraType;

typedef enum
{
PREVIEW_CALLBACK_DISABLED,
PREVIEW_CALLBACK_ENABLED
} PreviewCallbackMode;

struct CameraControl;

typedef void (*on_msg_error)(void* context);
Expand All @@ -47,6 +53,7 @@ extern "C" {
typedef void (*on_data_raw_image)(void* data, uint32_t data_size, void* context);
typedef void (*on_data_compressed_image)(void* data, uint32_t data_size, void* context);
typedef void (*on_preview_texture_needs_update)(void* context);
typedef void (*on_preview_frame)(void* data, uint32_t data_size, void* context);

struct CameraControlListener
{
Expand All @@ -73,6 +80,9 @@ extern "C" {
on_preview_texture_needs_update on_preview_texture_needs_update_cb;

void* context;

// Called when there is a new preview frame
on_preview_frame on_preview_frame_cb;
};

// Initializes a connection to the camera, returns NULL on error.
Expand Down Expand Up @@ -135,6 +145,9 @@ extern "C" {
// completed. Ideally, this is done from the raw data callback.
void android_camera_take_snapshot(struct CameraControl* control);

// Enable or disable the preview callback for clients that want software frames
void android_camera_set_preview_callback_mode(struct CameraControl* control, PreviewCallbackMode mode);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit d09ac2d

Please sign in to comment.