nz123
June 17, 2024, 8:23am
1
Hi @Emmanuel ,
In my application I need the ability to remove and recreate the arravissrc element of the gstreamer pipeline, so that if my camera has any issues I can restart it without having to restart my entire pipeline.
I have tried numerous approaches, and I keep getting an error indicating that I can’t write to the camera after I try to create a new element for it (maybe hinting I am not destroying the camera object correctly).
The error is:
0:00:53.138396384 ␛[336m 893␛[00m 0x559a365370 ␛[33;01mWARN ␛[00m ␛[00m aravissrc gstaravis.c:412:gst_aravis_set_caps:<new_source>␛[00m error: Could not set caps on camera "10.42.0.154": [AcquisitionStop] [N105] GigEVision write_memory error (access-denied
I am unable to add the full log / source code as I am a new user.
Any help would be greatly appreciated
Hi Sean,
The ArvCamera object owned by aravissrc is probably not destroyed correctly, and is still in control of the device. It would help if you could open an issue on github with a simple test code axhibiting the issue.
Emmanuel.
nz123
June 17, 2024, 9:33am
3
Thank you for the prompt response. I have added the github issue here:
opened 09:33AM - 17 Jun 24 UTC
**Describe the bug**
I need the ability to remove and recreate the arravissrc … element of the gstreamer pipeline, so that if my camera has any issues I can restart it without having to restart my entire pipeline.
**To Reproduce**
- Create aravissrc element
- Attempt to destroy and create new aravissrc element
- Attempt to start new element
**Expected behavior**
Camera able to restart without crashing gstreamer pipeline
**Camera description:**
Lucid Pheonix
GigE
**Platform description:**
- Aravis version 0.8
- OS: Linux (NVIDIA Jetpack)
- Hardware aarch64
**Additional context**
My main query is about safely destroying the camera object, and if/how to use g_object_unref or gst_object_unref.
```
// Simple script which will start an aravis pipeline, then restart ONLY the camera
#include <chrono>
#include <condition_variable>
#include <cstdlib>
#include <iostream>
#include <mutex>
#include <string>
#include <thread>
#include <gst/gst.h>
int main(int argc, char *argv[])
{
gst_init (&argc, &argv);
GstElement *pipeline = gst_pipeline_new ("aravis_pipeline");
GstElement *source = gst_element_factory_make ("aravissrc", "source");
if (!source) {
std::cerr << "Failed to create the source element." << std::endl;
return false;
}
#define cfg_OffsetY ((1200-1184)/2)
const char *cam1 = "10.42.0.154";
g_object_set(G_OBJECT(source),
"camera-name", cam1,
"num-arv-buffers", 64,
"offset-x", 0,
"offset-y", cfg_OffsetY,
"packet-resend", false,
"packet-size", 9000,
"auto-packet-size", false,
NULL);
std::this_thread::sleep_for(std::chrono::seconds(5));
GstElement *sink = gst_element_factory_make ("fakesink", "fake_sink");
if (!pipeline || !source || !sink) {
g_printerr ("Not all elements could be created.\n");
return -1;
}
gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL);
if (!gst_element_link (source, sink)) {
g_printerr ("Elements could not be linked.\n");
gst_object_unref (pipeline);
return -1;
}
GMainLoop *main_loop = g_main_loop_new(NULL, FALSE);
// CustomData data = {pipeline, main_loop};
std::cout << "Starting the pipeline." << std::endl;
gst_element_set_state(pipeline, GST_STATE_PLAYING);
std::this_thread::sleep_for(std::chrono::seconds(10));
std::cout << "Restarting the camera source." << std::endl;
// gst_element_set_state(pipeline, GST_STATE_PAUSED);
// Restart the camera source
// Stop camera
gst_element_set_state(source, GST_STATE_NULL);
// Wait for data to stop flowing
std::this_thread::sleep_for(std::chrono::seconds(10));
std::cout << "Camera source stopped." << std::endl;
// Remove the source from the pipeline
gst_element_unlink(source, sink);
// Remove the source from the pipeline
gst_bin_remove(GST_BIN(pipeline), source);
// UNREF?
g_object_unref(source);
std::this_thread::sleep_for(std::chrono::seconds(10));
std::cout << "Create a new source." << std::endl;
// Create a new source
GstElement *new_source = gst_element_factory_make ("aravissrc", "new_source");
if (!new_source) {
std::cerr << "Failed to create the source element." << std::endl;
return false;
}
g_object_set(G_OBJECT(new_source),
"camera-name", cam1,
"num-arv-buffers", 64,
"offset-x", 0,
"offset-y", cfg_OffsetY,
"packet-resend", false,
"packet-size", 9000,
"auto-packet-size", false,
NULL);
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "Add to pipeline." << std::endl;
gst_bin_add(GST_BIN(pipeline), new_source);
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "Link to pipeline." << std::endl;
gst_element_link(new_source, sink);
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "sync to pipeline." << std::endl;
gst_element_sync_state_with_parent(new_source);
std::this_thread::sleep_for(std::chrono::seconds(10));
std::cout << "Starting the pipeline." << std::endl;
gst_element_set_state(new_source, GST_STATE_PLAYING);
g_main_loop_run (main_loop);
/* Free resources */
g_main_loop_unref (main_loop);
// gst_object_unref (bus);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
}
```