diff --git a/module/src/server/implementation/objects/TelmateFrameGrabberImpl.cpp b/module/src/server/implementation/objects/TelmateFrameGrabberImpl.cpp index 651e1cf..6e0b5ec 100644 --- a/module/src/server/implementation/objects/TelmateFrameGrabberImpl.cpp +++ b/module/src/server/implementation/objects/TelmateFrameGrabberImpl.cpp @@ -23,9 +23,25 @@ TelmateFrameGrabberImpl::TelmateFrameGrabberImpl( std::shared_ptr mediaPipeline) : OpenCVFilterImpl(config, std::dynamic_pointer_cast (mediaPipeline)) { + + GST_DEBUG("TelmateFrameGrabberImpl::" + "TelmateFrameGrabberImpl() " + "called, %s ", this->epName.c_str()); + } + TelmateFrameGrabberImpl::~TelmateFrameGrabberImpl() { + + + } +void TelmateFrameGrabberImpl::release() { + + std::shared_ptr p = TelmateFrameGrabberOpenCVImpl::getSharedPtr(); + p.reset(); + return; +} + int TelmateFrameGrabberImpl::getSnapInterval() { return TelmateFrameGrabberOpenCVImpl::snapInterval; @@ -55,10 +71,11 @@ void TelmateFrameGrabberImpl::setWebRtcEpName(const std::string &epName) { return; } - MediaObjectImpl * -TelmateFrameGrabberImplFactory::createObject( +MediaObjectImpl * + TelmateFrameGrabberImplFactory::createObject( const boost::property_tree::ptree &config, std::shared_ptr mediaPipeline) const { + return new TelmateFrameGrabberImpl(config, mediaPipeline); } diff --git a/module/src/server/implementation/objects/TelmateFrameGrabberImpl.hpp b/module/src/server/implementation/objects/TelmateFrameGrabberImpl.hpp index 7b022ae..e2055bf 100644 --- a/module/src/server/implementation/objects/TelmateFrameGrabberImpl.hpp +++ b/module/src/server/implementation/objects/TelmateFrameGrabberImpl.hpp @@ -51,6 +51,9 @@ class TelmateFrameGrabberImpl : virtual void Serialize(JsonSerializer &serializer); + + void release(); + int getSnapInterval(); void setSnapInterval(int snapInterval); void setOutputFormat(int outputFormat); @@ -65,6 +68,7 @@ class TelmateFrameGrabberImpl : }; static StaticConstructor staticConstructor; + }; } // namespace telmateframegrabber diff --git a/module/src/server/implementation/objects/TelmateFrameGrabberOpenCVImpl.cpp b/module/src/server/implementation/objects/TelmateFrameGrabberOpenCVImpl.cpp index e8ac1cd..3e6d34f 100644 --- a/module/src/server/implementation/objects/TelmateFrameGrabberOpenCVImpl.cpp +++ b/module/src/server/implementation/objects/TelmateFrameGrabberOpenCVImpl.cpp @@ -14,6 +14,8 @@ GST_DEBUG_CATEGORY_STATIC(GST_CAT_DEFAULT); namespace kurento { TelmateFrameGrabberOpenCVImpl::TelmateFrameGrabberOpenCVImpl() { + + this->thrLoop = true; this->snapInterval = 1000; this->epName = "EP_NAME_UNINITIALIZED"; @@ -26,25 +28,28 @@ TelmateFrameGrabberOpenCVImpl::TelmateFrameGrabberOpenCVImpl() { this->frameQueue = new boost::lockfree::queue(0); this->thr = new boost::thread(boost::bind( &TelmateFrameGrabberOpenCVImpl::queueHandler, this)); - + this->thr->detach(); GST_DEBUG("TelmateFrameGrabberOpenCVImpl::TelmateFrameGrabberOpenCVImpl()"); } TelmateFrameGrabberOpenCVImpl::~TelmateFrameGrabberOpenCVImpl() { - this->thr->join(); + this->thrLoop = false; + + while(queueLength > 0) { + boost::this_thread::sleep_for(boost::chrono::milliseconds(10)); + } + delete this->frameQueue; this->frameQueue = NULL; - delete this->thr; - this->thr = NULL; - GST_DEBUG("TelmateFrameGrabberOpenCVImpl::" "~TelmateFrameGrabberOpenCVImpl() " "called, %s ", this->epName.c_str()); } + /* * This function will be called with each new frame. mat variable * contains the current frame. You should insert your image processing code @@ -77,7 +82,6 @@ void TelmateFrameGrabberOpenCVImpl::queueHandler() { while (this->thrLoop) { if (!this->frameQueue->empty()) { - empty_queue: params.clear(); // clear the vector since the last iteration. this->frameQueue->pop(ptrVf); @@ -133,10 +137,6 @@ void TelmateFrameGrabberOpenCVImpl::queueHandler() { } } - while (!this->frameQueue->empty()) { - GST_ERROR("Emptying frameQueue.."); - goto empty_queue; - } } std::string TelmateFrameGrabberOpenCVImpl::getCurrentTimestampString() { diff --git a/module/src/server/implementation/objects/TelmateFrameGrabberOpenCVImpl.hpp b/module/src/server/implementation/objects/TelmateFrameGrabberOpenCVImpl.hpp index 40404f6..ef1d9c1 100644 --- a/module/src/server/implementation/objects/TelmateFrameGrabberOpenCVImpl.hpp +++ b/module/src/server/implementation/objects/TelmateFrameGrabberOpenCVImpl.hpp @@ -43,12 +43,16 @@ class TelmateFrameGrabberOpenCVImpl : public virtual OpenCVProcess { virtual void process(cv::Mat &mat); + void release(); + boost::atomic framesCounter; int snapInterval; std::string storagePath; std::string epName; int outputFormat; // 0x0=JPEG 0x1=PNG + + protected: std::shared_ptr getSharedPtr() { try {