Skip to content

Commit

Permalink
fixed issue #3 and issue #4. Issue #3 fixed by adding an additional c…
Browse files Browse the repository at this point in the history
…aps filter to the CPipelineHelper::build_pipeline_display(). On Nvidia TX1 and TX2, the videosink found by autovideosink seems to not advertise the formats it supports, so we must tell the converter element manually to convert the RGB image to I420 (or something else). Issue #4 fixed by moving gst buffer wrapping from CInstantCameraAppSrc::InitCamera() to CInstantCameraAppSrc::retrieve_image()
  • Loading branch information
MattsProjects committed Mar 6, 2018
1 parent 963e80c commit 6898823
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
20 changes: 10 additions & 10 deletions source/CInstantCameraAppSrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,6 @@ bool CInstantCameraAppSrc::InitCamera(int width, int height, int framesPerSecond
// Initialize the Pylon image to a blank image on the off chance that the very first m_Image can't be supplied by the instant camera (ie: missing trigger signal)
m_Image.Reset(pixelType, m_width, m_height);

// create a gst buffer wrapping the image container's buffer
m_gstBuffer = gst_buffer_new_wrapped_full(
(GstMemoryFlags)GST_MEMORY_FLAG_PHYSICALLY_CONTIGUOUS,
(gpointer)m_Image.GetBuffer(),
m_Image.GetImageSize(),
0,
m_Image.GetImageSize(),
NULL,
NULL);

m_isInitialized = true;

return true;
Expand Down Expand Up @@ -422,6 +412,16 @@ bool CInstantCameraAppSrc::retrieve_image()
cout << "Will push last good image instead..." << endl;
}

// create a gst buffer wrapping the image container's buffer
m_gstBuffer = gst_buffer_new_wrapped_full(
(GstMemoryFlags)GST_MEMORY_FLAG_PHYSICALLY_CONTIGUOUS,
(gpointer)m_Image.GetBuffer(),
m_Image.GetImageSize(),
0,
m_Image.GetImageSize(),
NULL,
NULL);

// Push the gst buffer wrapping the image buffer to the source pads of the AppSrc element, where it's picked up by the rest of the pipeline
GstFlowReturn ret;
g_signal_emit_by_name(m_appsrc, "push-buffer", m_gstBuffer, &ret);
Expand Down
17 changes: 15 additions & 2 deletions source/CPipelineHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,23 @@ bool CPipelineHelper::build_pipeline_display()

if (!convert){ cout << "Could not make convert" << endl; return false; }
if (!sink){ cout << "Could not make sink" << endl; return false; }

// if you are using nvidia tx1/tx2, the built-in video sink that is found by autovideosink does not advertise it needs conversion (it does not support RGB).
// so we must use a filter such that the converter knows to convert the image format.
// if you are using a video sink that supports RGB, then you do not need to convert to i420 and you can remove this filter and save some cpu load.
GstElement *filter;
GstCaps *filter_caps;
filter = gst_element_factory_make("capsfilter", "filter");
filter_caps = gst_caps_new_simple("video/x-raw",
"format", G_TYPE_STRING, "I420",
NULL);

g_object_set(G_OBJECT(filter), "caps", filter_caps, NULL);
gst_caps_unref(filter_caps);

// add and link the pipeline elements
gst_bin_add_many(GST_BIN(m_pipeline), m_source, m_videoScaler, m_videoScalerCaps, convert, sink, NULL);
gst_element_link_many(m_source, m_videoScaler, m_videoScalerCaps, convert, sink, NULL);
gst_bin_add_many(GST_BIN(m_pipeline), m_source, m_videoScaler, m_videoScalerCaps, convert, filter, sink, NULL);
gst_element_link_many(m_source, m_videoScaler, m_videoScalerCaps, convert, filter, sink, NULL);


cout << "Pipeline Made." << endl;
Expand Down

0 comments on commit 6898823

Please sign in to comment.