camera: add TakePicture API implementation (#60)

One of implementation in #6

Signed-off-by: Hidenori Matsubayashi <[email protected]>
This commit is contained in:
Hidenori Matsubayashi
2022-10-23 09:18:05 +09:00
committed by GitHub
parent be5e050ad2
commit ca81dbb391
3 changed files with 62 additions and 5 deletions
+26 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2022 Sony Group Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -77,6 +77,19 @@ bool GstCamera::Stop() {
return true;
}
void GstCamera::TakePicture(OnNotifyCaptured on_notify_captured) {
if (!gst_.camerabin) {
std::cerr << "Failed to take a picture" << std::endl;
return;
}
on_notify_captured_ = on_notify_captured;
std::string filename =
g_strdup_printf("captured_%04u.jpg", captured_count_++);
g_object_set(gst_.camerabin, "location", filename.c_str(), NULL);
g_signal_emit_by_name(gst_.camerabin, "start-capture", NULL);
}
bool GstCamera::SetZoomLevel(float zoom) {
if (zoom_level_ == zoom) {
return true;
@@ -280,6 +293,18 @@ void GstCamera::HandoffHandler(GstElement* fakesink, GstBuffer* buf,
gboolean GstCamera::HandleGstMessage(GstBus* bus, GstMessage* message,
gpointer user_data) {
switch (GST_MESSAGE_TYPE(message)) {
case GST_MESSAGE_ELEMENT: {
auto const* st = gst_message_get_structure(message);
if (st) {
auto* self = reinterpret_cast<GstCamera*>(user_data);
if (gst_structure_has_name(st, "image-done") &&
self->on_notify_captured_) {
auto const* filename = gst_structure_get_string(st, "filename");
self->on_notify_captured_(filename);
}
}
break;
}
case GST_MESSAGE_WARNING: {
gchar* debug;
GError* error;