Camera Monitoring API#
It is called within the scope of the oasis::ui namespace.
Header File#
OasisPreview.h
PreviewFrameObserver Interface#
A user-defined observer object derived from PreviewFrameObserver can be specified for a Preview object using the setPreviewFrameObserver function.
The application can obtain video frames displayed on the screen through the onFrame callback function.
class PreviewFrameObserver : public std::enable_shared_from_this<PreviewFrameObserver>
{
public:
PreviewFrameObserver();
virtual ~PreviewFrameObserver();
virtual void onFrame(int32_t camera_id, uint8_t *frame, int32_t stride_width, int32_t width, int32_t height);
virtual void onNoMediaData(int32_t camera_id);
};
configCameras.
When the video frame format is YUV420, the Y, U, and V channels can be obtained using the formula below:
uint8_t *y = frame;
uint8_t *u = frame + stride_width * height;
uint8_t *v = u + stride_width * height / 4;
configCameras.
Functions#
channel<N>-rotation key value.The key-value map values for each video channel are prefixed with channel<N>- before each key name. <N> starts from 1 and increases by 1.
- 0: Success
- -1: Failure
createPreview.
- 0: Success
- -1: Failure
createPreview.
- 0: Success
- -1: Failure
createPreview.
- 0: Success
- -1: Failure
createPreview.
- true: Operating.
- false: Not operating.
createPreview.
- 0: Success
- -1: Failure
createPreview.
configCameras.
true, and makes the camera video invisible if false.
- 0: Success
- -1: Failure
createPreview.
configCameras.
- true: The camera video is configured to be visible.
- false: The camera video is configured to be invisible.
createPreview.
configCameras.
true, and the video is not shown if false.
- 0: Success
- -1: Failure
createPreview.
configCameras.
- 0: Success
- -1: Failure
createPreview.
configCameras.
- 0: Success
- -1: Failure
createPreview.
configCameras.
- 0: Success
- -1: Failure
createPreview.
configCameras.
- 0: Success
- -1: Failure
createPreview.
configCameras.
true, and makes the camera video invisible if false.
- 0: Success
- -1: Failure
createPreview.
configCameras.
- 1: Configured to be visible.
- 0: Configured to be invisible.
/dev/video<N> device, it obtains the corresponding file descriptor.
createPreview.
configCameras.
/dev/video<N> device. Returns -1 on failure.
createPreview.
configCameras.
- 0: Success
- -1: Failure
createPreview.
configCameras.
- 0: Success
- -1: Failure
createPreview.
configCameras.
true. Deactivates WDR if false.
- 0: Success
- -1: Failure
createPreview.
configCameras.
- 0: Success
- -1: Failure
createPreview.
configCameras.
- 0: Success
- -1: Failure
createPreview.
configCameras.
- 0: Success
- -1: Failure
Example#
Below is an example of monitoring video from the camera device ID 0.
Initializes Oasis.
// Does not use the file system.
oasis::key_value_map_t parameters;
parameters["offs-disable"] = "1";
if(oasis::initialize(parameters) < 0) {
DLOG(DLOG_ERROR, "Oasis init failed\n");
return -1;
}
Initializes the camera device. Here, a single camera device is used.
parameters.clear();
parameters["source-count"] = "1";
parameters["source1-camera-id"] = "0";
parameters["source1-isp-id"] = "0";
parameters["source1-isp-wdr-mode"] = "0";
parameters["source1-capture-format"] = "YUV420";
parameters["source1-capture-buffers"] = "5";
parameters["source1-fps"] = "30";
parameters["source1-subchannel-rotation"] = "0";
parameters["source1-loc"] = "front";
parameters["source1-capture-resolution"] = "1080p";
parameters["source1-sensor-config"] = "./Resource_tp2863/VIC/0/tp2863_1920x1080_ch0.cfg";
parameters["source1-autoscene-config"] = "./Resource_tp2863/AutoScene/autoscene_conf.cfg";
parameters["source1-resource-dir"] = "./Resource_tp2863/";
configCameras(parameters);
Initializes the display device.
parameters.clear();
parameters["memory-type"] = "ion"; //cma
parameters["screen-width"] = "480";
parameters["screen-height"] = "320";
display::setup(parameters);
Configures the GUI. In this example, touch is not used.
parameters.clear();
parameters["system-font-size"] = "10";
parameters["system-font-path"] = "/mnt/sd/consola.ttf";
parameters["display-rotation"] = "0";
parameters["enable-touch"] = "0";
err = ui::setup(parameters);
if (err < 0) {
DLOG(DLOG_ERROR, "Oasis ui::setup failed\n");
return -1;
}
Initializes the Preview object.
parameters.clear();
// Obtains the default screen object and applies its width and height to the media player.
ui::ScreenRef screen = ui::getDefaultScreen();
int32_t screen_width = ui::screenWidth(screen);
int32_t screen_height = ui::screenHeight(screen);
// Creates a user-defined object derived from ui::PreviewFrameObserver.
std::shared_ptr<MyPreviewFrameObserver> observer = std::make_shared<MyPreviewFrameObserver>();
parameters["channel-count"] = "1";
parameters["primary-channel"] = "1";
parameters["channel1-camera-id"] = std::to_string(camera_id);
parameters["channel1-visible"] = "1";
parameters["channel1-rotation"] = std::to_string(rotation);
// Configures the playback screen to full screen.
parameters["channel1-x"] = "0";
parameters["channel1-y"] = "0";
parameters["channel1-width"] = std::to_string(screen_width);
parameters["channel1-height"] = std::to_string(screen_height);
parameters["channel1-zorder"] = "0";
ui::PreviewRef preview = ui::createPreview(0, parameters);
ui::setPreviewFrameObserver(preview, observer);
Configures the screen layout. A Fixed layout container is used inside the top-level Window object, and the video screen is set to full screen.
ui::WindowRef preview_panel = ui::createWindow("Preview1");
ui::FixedRef fixed_layout = ui::createFixed();
ui::containerAdd(preview_panel, fixed_layout);
ui::setFixedSize(preview, screen_width, screen_height);
ui::fixedPut(fixed_layout, preview, 0, 0);
ui::screenAdd(screen, preview_panel);
ui::setVisible(preview_panel, true);
Starts monitoring.
ui::previewStart(preview);
An example of modifying the screen position during playback:
ui::previewSetPos(preview, 0, 100, 100)
Stops monitoring.
ui::previewStop(preview);
Below is the complete code:
#include "OasisAPI.h"
#include "OasisLog.h"
#include "OasisMedia.h"
#include "OasisUI.h"
#include "OasisFS.h"
#include "OasisUtil.h"
#include "OasisDisplay.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <signal.h>
#include <thread>
#include <mutex>
#include <memory>
#include <condition_variable>
using namespace oasis;
static bool continue_previewing = true;
void cancel_handler(int signum)
{
continue_previewing = false;
}
class MyPreviewFrameObserver : public ui::PreviewFrameObserver {
public:
MyPreviewFrameObserver() {}
virtual ~MyPreviewFrameObserver() {}
virtual void onFrame(int32_t camera_id, uint8_t *frame, int32_t stride_width, int32_t width, int32_t height) {
}
virtual void onNoMediaData(int32_t camera_id) {
fprintf(stdout, "no media: camera<%d>\n", camera_id);
}
};
void printUsage(const char *pgname)
{
fprintf(stderr, "USAGE: %s [-r <rotation. 90, 270>] <camera id>\n", pgname);
}
int main(int argc, char *argv[])
{
int32_t err;
int c;
int32_t rotation = 0;
int32_t camera_id = -1;
opterr = 0;
while ((c = getopt(argc, argv, "r:h")) != -1) {
switch (c) {
case 'r':
if(optarg == nullptr) {
fprintf(stderr, "error: bad option argument '%c'\n", optopt);
return -1;
}
rotation = atoi(optarg);
if(rotation != 0 && rotation != 90 /*&& rotation != 180*/ && rotation != 270) {
fprintf(stderr, "bad rotation: %d\n", rotation);
return -1;
}
break;
case 'h':
default:
printUsage(argv[0]);
return -1;
}
}
if(argc-optind < 1) {
fprintf(stderr, "error: invalid or insufficient arguments (%d, %d)\n", argc, optind);
printUsage(argv[0]);
return -1;
}
camera_id = atoi(argv[optind]);
if(camera_id < 0) {
fprintf(stderr, "invalid camera id: %d\n", camera_id);
return -1;
}
signal(SIGINT, cancel_handler);
oasis::key_value_map_t parameters;
////////////////////////////////////////////////////////////////////////////////////////////
// init
parameters["offs-disable"] = "1";
if(oasis::initialize(parameters) < 0) {
DLOG(DLOG_ERROR, "Oasis init failed\n");
return -1;
}
////////////////////////////////////////////////////////////////////////////////////////////
// camera sources
parameters.clear();
parameters["source-count"] = "1";
parameters["source1-camera-id"] = "0";
parameters["source1-isp-id"] = "0";
parameters["source1-isp-wdr-mode"] = "0";
parameters["source1-capture-format"] = "YUV420";
parameters["source1-capture-buffers"] = "5";
parameters["source1-fps"] = "30";
parameters["source1-subchannel-rotation"] = "0";
parameters["source1-loc"] = "front";
parameters["source1-capture-resolution"] = "1080p";
parameters["source1-sensor-config"] = "./Resource_tp2863/VIC/0/tp2863_1920x1080_ch0.cfg";
parameters["source1-autoscene-config"] = "./Resource_tp2863/AutoScene/autoscene_conf.cfg";
parameters["source1-resource-dir"] = "./Resource_tp2863/";
configCameras(parameters);
////////////////////////////////////////////////////////////////////////////////////////////
// display setup
parameters.clear();
parameters["memory-type"] = "ion"; //cma
parameters["screen-width"] = "480";
parameters["screen-height"] = "320";
display::setup(parameters);
//////////////////////////////////////////////////////////////////////////////////////////
// ui setup
parameters.clear();
parameters["system-font-size"] = "10";
parameters["system-font-path"] = "/mnt/sd/consola.ttf";
parameters["display-rotation"] = "0";
parameters["enable-touch"] = "0";
err = ui::setup(parameters);
if (err < 0) {
DLOG(DLOG_ERROR, "Oasis ui::setup failed\n");
return -1;
}
/////////////////////////////////////////////////////////////////////////
// create preview and layout
ui::ScreenRef screen = ui::getDefaultScreen();
int32_t screen_width = ui::screenWidth(screen);
int32_t screen_height = ui::screenHeight(screen);
parameters.clear();
//preview_panel
ui::WindowRef preview_panel = ui::createWindow("Preview1");
ui::FixedRef fixed_layout = ui::createFixed();
ui::containerAdd(preview_panel, fixed_layout);
std::shared_ptr<MyPreviewFrameObserver> observer = std::make_shared<MyPreviewFrameObserver>();
parameters["channel-count"] = "1";
parameters["primary-channel"] = "1";
parameters["channel1-camera-id"] = std::to_string(camera_id);
parameters["channel1-visible"] = "1";
parameters["channel1-rotation"] = std::to_string(rotation);
parameters["channel1-x"] = "0";
parameters["channel1-y"] = "0";
parameters["channel1-width"] = std::to_string(screen_width);
parameters["channel1-height"] = std::to_string(screen_height);
parameters["channel1-zorder"] = "0";
ui::PreviewRef preview = ui::createPreview(0, parameters);
ui::setPreviewFrameObserver(preview, observer);
ui::setFixedSize(preview, screen_width, screen_height);
ui::fixedPut(fixed_layout, preview, 0, 0);
ui::screenAdd(screen, preview_panel);
ui::setVisible(preview_panel, true);
ui::previewStart(preview);
do {
usleep(100000);
} while (continue_previewing);
ui::previewStop(preview);
err = ui::cleanup();
oasis::finalize();
return 0;
}