Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Support putFragmentMetadata from kvssink #1122

Merged
merged 27 commits into from
May 16, 2024
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup send_custom_event
niyatim23 committed May 7, 2024
commit 4d6c69c626c94bcf9d9bf1e8ef06f83d9ede37b3
29 changes: 19 additions & 10 deletions samples/kvssink_gstreamer_sample.cpp
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
#include <IotCertCredentialProvider.h>
#include "gstreamer/gstkvssink.h"
#include <thread>
#include <tuple>
#include "include.h"

using namespace std;
@@ -257,29 +258,37 @@ void determine_credentials(GstElement *kvssink, CustomData *data) {
}
}

// Function to send the custom downstream event
static gboolean send_custom_event(gpointer user_data) {
GstElement *kvssink = GST_ELEMENT(user_data);
// Function to get key, value, and persist values
static std::tuple<std::string, std::string, gboolean> get_metadata() {
std::ostringstream metadata_key_stream, metadata_value_stream;

metadata_key_stream << "metadata_key_" << data_global.metadata_counter;
metadata_value_stream << "metadata_value_" << data_global.metadata_counter;

data_global.metadata_counter++;
data_global.persist_flag = !data_global.persist_flag;

return std::make_tuple(metadata_key_stream.str(), metadata_value_stream.str(),
data_global.persist_flag);
}

// Function to send the custom downstream event
static gboolean send_custom_event(gpointer user_data) {
GstElement *kvssink = GST_ELEMENT(user_data);

auto metadata = get_metadata();

// Create the custom event structure
GstStructure *structure = gst_structure_new_empty("kvs-add-metadata");
gst_structure_set(structure, "name", G_TYPE_STRING, metadata_key_stream.str().c_str(), NULL);
gst_structure_set(structure, "value", G_TYPE_STRING, metadata_value_stream.str().c_str(), NULL);
gst_structure_set(structure, "persist", G_TYPE_BOOLEAN, data_global.persist_flag, NULL);
gst_structure_set(structure, "name", G_TYPE_STRING, std::get<0>(metadata).c_str(), NULL);
gst_structure_set(structure, "value", G_TYPE_STRING, std::get<1>(metadata).c_str(), NULL);
gst_structure_set(structure, "persist", G_TYPE_BOOLEAN, std::get<2>(metadata), NULL);

// Create the custom event
GstEvent *event = gst_event_new_custom(GST_EVENT_CUSTOM_DOWNSTREAM, structure);

// Send the custom event to the sink element
gboolean ret = gst_element_send_event(kvssink, event);

data_global.metadata_counter++;
data_global.persist_flag = !data_global.persist_flag;

return ret;
}

2 changes: 1 addition & 1 deletion src/gstreamer/gstkvssink.cpp
Original file line number Diff line number Diff line change
@@ -1162,7 +1162,7 @@ gst_kvs_sink_handle_sink_event (GstCollectPads *pads,
bool is_persist;
niyatim23 marked this conversation as resolved.
Show resolved Hide resolved

if (!gst_structure_has_name(structure, KVS_ADD_METADATA_G_STRUCT_NAME) || data->fragment_metadata_count >= 10) {
LOG_INFO("Current fragment's metadata count " << data->fragment_metadata_count << " . Current metadata cannot be persisted.");
LOG_INFO("Current fragment's metadata count " << data->fragment_metadata_count << " . Max limit reached. Current metadata cannot be persisted.");
goto CleanUp;
}