Skip to content

Commit

Permalink
Merge pull request #1 from Telmate/PS-1394
Browse files Browse the repository at this point in the history
Implement a release() method because the module destructors are not b…
  • Loading branch information
avis authored Sep 26, 2017
2 parents e7b9d0d + 53191b1 commit 63491f4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,25 @@ TelmateFrameGrabberImpl::TelmateFrameGrabberImpl(
std::shared_ptr<MediaPipeline> mediaPipeline) :
OpenCVFilterImpl(config,
std::dynamic_pointer_cast<MediaPipelineImpl> (mediaPipeline)) {

GST_DEBUG("TelmateFrameGrabberImpl::"
"TelmateFrameGrabberImpl() "
"called, %s ", this->epName.c_str());

}

TelmateFrameGrabberImpl::~TelmateFrameGrabberImpl() {



}
void TelmateFrameGrabberImpl::release() {

std::shared_ptr<MediaObject> p = TelmateFrameGrabberOpenCVImpl::getSharedPtr();
p.reset();
return;
}


int TelmateFrameGrabberImpl::getSnapInterval() {
return TelmateFrameGrabberOpenCVImpl::snapInterval;
Expand Down Expand Up @@ -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> mediaPipeline) const {

return new TelmateFrameGrabberImpl(config, mediaPipeline);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class TelmateFrameGrabberImpl :

virtual void Serialize(JsonSerializer &serializer);


void release();

int getSnapInterval();
void setSnapInterval(int snapInterval);
void setOutputFormat(int outputFormat);
Expand All @@ -65,6 +68,7 @@ class TelmateFrameGrabberImpl :
};

static StaticConstructor staticConstructor;

};

} // namespace telmateframegrabber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -26,25 +28,28 @@ TelmateFrameGrabberOpenCVImpl::TelmateFrameGrabberOpenCVImpl() {
this->frameQueue = new boost::lockfree::queue<VideoFrame *>(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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -133,10 +137,6 @@ void TelmateFrameGrabberOpenCVImpl::queueHandler() {
}
}

while (!this->frameQueue->empty()) {
GST_ERROR("Emptying frameQueue..");
goto empty_queue;
}
}

std::string TelmateFrameGrabberOpenCVImpl::getCurrentTimestampString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ class TelmateFrameGrabberOpenCVImpl : public virtual OpenCVProcess {

virtual void process(cv::Mat &mat);

void release();

boost::atomic<int> framesCounter;
int snapInterval;
std::string storagePath;
std::string epName;
int outputFormat; // 0x0=JPEG 0x1=PNG



protected:
std::shared_ptr<MediaObject> getSharedPtr() {
try {
Expand Down

0 comments on commit 63491f4

Please sign in to comment.