From 13867e21926031b6d16356d02e3665155ff6b4f8 Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Thu, 20 Aug 2020 20:51:42 +0200 Subject: [PATCH] Unified identifyer mechanism (tested and confirmed to produce unique integer < MAX_INT) --- MediaPlayer.cpp | 28 +++++++++++++++------------- MediaPlayer.h | 4 ++-- Scene.cpp | 7 ++----- Scene.h | 1 - Shader.cpp | 2 +- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/MediaPlayer.cpp b/MediaPlayer.cpp index 5e9cfa3..2315779 100644 --- a/MediaPlayer.cpp +++ b/MediaPlayer.cpp @@ -23,10 +23,11 @@ using namespace std; std::list MediaPlayer::registered_; -MediaPlayer::MediaPlayer(string name) : id_(name) +MediaPlayer::MediaPlayer() { - if (std::empty(id_)) - id_ = SystemToolkit::date_time_string(); + // create unique id + auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); + id_ = std::chrono::duration_cast(duration).count() % 1000000000; uri_ = "undefined"; pipeline_ = nullptr; @@ -222,19 +223,19 @@ void MediaPlayer::execute_open() GError *error = NULL; pipeline_ = gst_parse_launch (description.c_str(), &error); if (error != NULL) { - Log::Warning("MediaPlayer %s Could not construct pipeline %s:\n%s", id_.c_str(), description.c_str(), error->message); + Log::Warning("MediaPlayer %s Could not construct pipeline %s:\n%s", std::to_string(id_).c_str(), description.c_str(), error->message); g_clear_error (&error); failed_ = true; return; } - g_object_set(G_OBJECT(pipeline_), "name", id_.c_str(), NULL); + g_object_set(G_OBJECT(pipeline_), "name", std::to_string(id_).c_str(), NULL); // GstCaps *caps = gst_static_caps_get (&frame_render_caps); string capstring = "video/x-raw,format=RGBA,width="+ std::to_string(media_.width) + ",height=" + std::to_string(media_.height); GstCaps *caps = gst_caps_from_string(capstring.c_str()); if (!gst_video_info_from_caps (&v_frame_video_info_, caps)) { - Log::Warning("MediaPlayer %s Could not configure video frame info", id_.c_str()); + Log::Warning("MediaPlayer %s Could not configure video frame info", std::to_string(id_).c_str()); failed_ = true; return; } @@ -278,7 +279,7 @@ void MediaPlayer::execute_open() gst_object_unref (sink); } else { - Log::Warning("MediaPlayer %s Could not configure sink", id_.c_str()); + Log::Warning("MediaPlayer %s Could not configure sink", std::to_string(id_).c_str()); failed_ = true; return; } @@ -290,7 +291,7 @@ void MediaPlayer::execute_open() // set to desired state (PLAY or PAUSE) GstStateChangeReturn ret = gst_element_set_state (pipeline_, desired_state_); if (ret == GST_STATE_CHANGE_FAILURE) { - Log::Warning("MediaPlayer %s Could not open '%s'", id_.c_str(), uri_.c_str()); + Log::Warning("MediaPlayer %s Could not open '%s'", std::to_string(id_).c_str(), uri_.c_str()); failed_ = true; return; } @@ -304,7 +305,8 @@ void MediaPlayer::execute_open() // all good - Log::Info("MediaPlayer %s Opened '%s' (%s %d x %d)", id_.c_str(), uri_.c_str(), media_.codec_name.c_str(), media_.width, media_.height); + Log::Info("MediaPlayer %s Opened '%s' (%s %d x %d)", std::to_string(id_).c_str(), + uri_.c_str(), media_.codec_name.c_str(), media_.width, media_.height); ready_ = true; // register media player @@ -601,7 +603,7 @@ void MediaPlayer::init_texture(guint index) pbo_next_index_ = 1; #ifdef MEDIA_PLAYER_DEBUG - Log::Info("MediaPlayer %s Using Pixel Buffer Object texturing.", id_.c_str()); + Log::Info("MediaPlayer %s Using Pixel Buffer Object texturing.", std::to_string(id_).c_str()); #endif } } @@ -807,11 +809,11 @@ void MediaPlayer::execute_seek_command(GstClockTime target) // Send the event (ASYNC) if (seek_event && !gst_element_send_event(pipeline_, seek_event) ) - Log::Warning("MediaPlayer %s Seek failed", id_.c_str()); + Log::Warning("MediaPlayer %s Seek failed", std::to_string(id_).c_str()); else { seeking_ = true; #ifdef MEDIA_PLAYER_DEBUG - Log::Info("MediaPlayer %s Seek %ld %f", id_.c_str(), seek_pos, rate_); + Log::Info("MediaPlayer %s Seek %ld %f", std::to_string(id_).c_str(), seek_pos, rate_); #endif } @@ -905,7 +907,7 @@ bool MediaPlayer::fill_frame(GstBuffer *buf, FrameStatus status) // get the frame from buffer if ( !gst_video_frame_map (&frame_[write_index_].vframe, &v_frame_video_info_, buf, GST_MAP_READ ) ) { - Log::Info("MediaPlayer %s Failed to map the video buffer", id_.c_str()); + Log::Info("MediaPlayer %s Failed to map the video buffer", std::to_string(id_).c_str()); // free access to frame & exit frame_[write_index_].status = INVALID; frame_[write_index_].access.unlock(); diff --git a/MediaPlayer.h b/MediaPlayer.h index c261d13..8947a43 100644 --- a/MediaPlayer.h +++ b/MediaPlayer.h @@ -72,7 +72,7 @@ public: /** * Constructor of a GStreamer Media Player */ - MediaPlayer( std::string name = std::string() ); + MediaPlayer(); /** * Destructor. */ @@ -240,7 +240,7 @@ public: private: // video player description - std::string id_; + int id_; std::string filename_; std::string uri_; guint textureindex_; diff --git a/Scene.cpp b/Scene.cpp index 1325105..71c16a0 100644 --- a/Scene.cpp +++ b/Scene.cpp @@ -19,15 +19,12 @@ #include #include -int Node::node_counter = 0; - // Node Node::Node() : initialized_(false), visible_(true), refcount_(0) { // create unique id - id_ = ++node_counter; -// auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); -// id_ = std::chrono::duration_cast(duration).count() % 100000000; + auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); + id_ = std::chrono::duration_cast(duration).count() % 1000000000; transform_ = glm::identity(); scale_ = glm::vec3(1.f); diff --git a/Scene.h b/Scene.h index 5f25175..b9dd6fb 100644 --- a/Scene.h +++ b/Scene.h @@ -41,7 +41,6 @@ class Group; */ class Node { - static int node_counter; int id_; bool initialized_; diff --git a/Shader.cpp b/Shader.cpp index 5f4e1f5..4457bae 100644 --- a/Shader.cpp +++ b/Shader.cpp @@ -176,7 +176,7 @@ Shader::Shader() : blending(BLEND_OPACITY) { // create unique id auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); - id_ = std::chrono::duration_cast(duration).count() % 100000000; + id_ = std::chrono::duration_cast(duration).count() % 1000000000; program_ = &simpleShadingProgram; reset();