Skip to content

Commit

Permalink
Merge pull request #10 from Telmate/VID-2108
Browse files Browse the repository at this point in the history
Add Cleanup method
  • Loading branch information
avis authored Jul 23, 2018
2 parents b45d5a9 + 417b7bf commit c4c1658
Show file tree
Hide file tree
Showing 6 changed files with 324 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GST_DEBUG_CATEGORY_STATIC(GST_CAT_DEFAULT);

namespace kurento {
namespace module {
namespace telmateframegrabber {
namespace telmate {

TelmateFrameGrabberImpl::TelmateFrameGrabberImpl(
const boost::property_tree::ptree &config,
Expand All @@ -28,6 +28,22 @@ TelmateFrameGrabberImpl::TelmateFrameGrabberImpl(
"TelmateFrameGrabberImpl() "
"called, %s ", this->epName.c_str());


g_object_set (element, "filter-factory", "opencvfilter", NULL);

g_object_get (G_OBJECT (element), "filter", &opencvfilter, NULL);

if (opencvfilter == nullptr) {
throw KurentoException (MEDIA_OBJECT_NOT_AVAILABLE,
"Media Object not available");
}

g_object_set (opencvfilter, "target-object",
static_cast<kurento::TelmateFrameGrabberOpenCVImpl *> (this), NULL);

g_object_unref (opencvfilter);


}

TelmateFrameGrabberImpl::~TelmateFrameGrabberImpl() {
Expand All @@ -47,6 +63,13 @@ void TelmateFrameGrabberImpl::release() {
}


void TelmateFrameGrabberImpl::cleanup() {

TelmateFrameGrabberOpenCVImpl *p = (TelmateFrameGrabberOpenCVImpl*) opencvfilter;
p->cleanup();
return;
}

int TelmateFrameGrabberImpl::getSnapInterval() {
return TelmateFrameGrabberOpenCVImpl::snapInterval;
}
Expand Down Expand Up @@ -91,6 +114,6 @@ TelmateFrameGrabberImpl::StaticConstructor::StaticConstructor() {
GST_DEFAULT_NAME);
}

} // namespace telmateframegrabber
} // namespace telmat
} // namespace module
} // namespace kurento
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

namespace kurento {
namespace module {
namespace telmateframegrabber {
namespace telmate {
class TelmateFrameGrabberImpl;
} // namespace telmateframegrabber
} // namespace module
} // namespace kurento

namespace kurento {
void Serialize(std::shared_ptr
<kurento::module::telmateframegrabber::
<kurento::module::telmate::
TelmateFrameGrabberImpl> &object, JsonSerializer &serializer);
} /* kurento */

Expand All @@ -30,7 +30,7 @@ class MediaPipelineImpl;

namespace kurento {
namespace module {
namespace telmateframegrabber {
namespace telmate {

class TelmateFrameGrabberImpl :
public OpenCVFilterImpl,
Expand All @@ -53,6 +53,7 @@ class TelmateFrameGrabberImpl :


void release();
void cleanup();

int getSnapInterval();
void setSnapInterval(int snapInterval);
Expand All @@ -62,6 +63,8 @@ class TelmateFrameGrabberImpl :
void setWebRtcEpName(const std::string &epName);

private:
GstElement *opencvfilter{};

class StaticConstructor {
public:
StaticConstructor();
Expand All @@ -71,7 +74,7 @@ class TelmateFrameGrabberImpl :

};

} // namespace telmateframegrabber
} // namespace telmate
} // namespace module
} // namespace kurento

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,32 @@ TelmateFrameGrabberOpenCVImpl::TelmateFrameGrabberOpenCVImpl() {

TelmateFrameGrabberOpenCVImpl::~TelmateFrameGrabberOpenCVImpl() {

this->thrLoop = false;

GST_INFO("Destructor was called for %s", this->epName.c_str());


}

void TelmateFrameGrabberOpenCVImpl::cleanup() {

VideoFrame *ptrVf;

while(!this->frameQueue->empty()) {
this->frameQueue->pop(ptrVf); // blocks
--this->queueLength;
delete ptrVf;
ptrVf = NULL;

}

this->thrLoop = false;
boost::this_thread::sleep_for(boost::chrono::milliseconds(250)); /* Give the processing thread some time to exit() */
GST_INFO("Called release() for %s :: Dequeue completed.", this->epName.c_str());

delete this->frameQueue;
this->frameQueue = NULL;

return;
}


Expand Down Expand Up @@ -132,20 +155,7 @@ void TelmateFrameGrabberOpenCVImpl::queueHandler() {

}

boost::this_thread::sleep_for(boost::chrono::milliseconds(250));

while(!this->frameQueue->empty()) {

this->frameQueue->pop(ptrVf); // blocks
--this->queueLength;
delete ptrVf;
ptrVf = NULL;

}


delete this->frameQueue;
this->frameQueue = NULL;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class TelmateFrameGrabberOpenCVImpl : public virtual OpenCVProcess {
virtual void process(cv::Mat &mat);

void release();
void cleanup();

boost::atomic<int> framesCounter;
int snapInterval;
Expand All @@ -73,6 +74,9 @@ class TelmateFrameGrabberOpenCVImpl : public virtual OpenCVProcess {
}
}

TelmateFrameGrabberOpenCVImpl* getFrameGrabberPtr() {
return this;
}

private:
class StaticConstructor {
Expand Down
132 changes: 132 additions & 0 deletions module/src/server/kmd/telmate.kmd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"name": "telmate",
"version": "0.9.0",
"kurentoVersion": "^6.7.1",
"imports": [
{
"name": "core",
"version": "^6.7.1",
"mavenVersion": "[6.7.1,7.0.0-SNAPSHOT)",
"npmVersion": ">=6.7.1 <7.0.0"
},
{
"name": "elements",
"version": "^6.7.1",
"mavenVersion": "[6.7.1,7.0.0-SNAPSHOT)",
"npmVersion": ">=6.7.1 <7.0.0"
},
{
"name": "filters",
"version": "^6.7.1",
"mavenVersion": "[6.7.1,7.0.0-SNAPSHOT)",
"npmVersion": ">=6.7.1 <7.0.0"
}
],
"code": {
"api": {
"java": {
"mavenGroupId": "org.kurento.module",
"mavenArtifactId": "telmate",
"mavenVersion": "0.9.0",
"packageName": "org.kurento.module.telmate"
},
"js": {
"nodeName": "kurento-module-telmate",
"npmVersion": "0.9.0",
"npmDescription": ""
}
},
"implementation": {
"cppNamespace": "kurento::module::telmate",
"lib": "libkmstelmate"
}
},
"remoteClasses": [
{
"name": "TelmateFrameGrabber",
"doc": "TelmateFrameGrabber interface. Documentation about the module",
"extends": "OpenCVFilter",
"constructor": {
"params": [
{
"name": "mediaPipeline",
"doc": "the parent :rom:cls:`MediaPipeline`",
"type": "MediaPipeline"
}
],
"doc": "Create an element"
},
"methods": [
{
"params": [],
"name": "cleanup",
"doc": "release plugin resources"
},
{
"params": [],
"return": {
"type": "int",
"doc": "Value of current snapshot interval"
},
"name": "getSnapInterval",
"doc": "get Snapshot interval"
},
{
"params": [
{
"name": "snapInterval",
"doc": "Value of snapInterval in milliseconds",
"type": "int"
}
],
"name": "setSnapInterval",
"doc": "set Snapshot interval."
},
{
"params": [],
"return": {
"type": "String",
"doc": "path of snapshots location"
},
"name": "getStoragePath",
"doc": "get the storage location for snapshots"
},
{
"params": [
{
"name": "path",
"doc": "path of snapshots location",
"type": "String"
}
],
"name": "setStoragePath",
"doc": "set the storage location for snapshots"
},
{
"params": [
{
"name": "epName",
"doc": "endpoint name",
"type": "String"
}
],
"name": "setWebRtcEpName",
"doc": "set the webetc endpoint name (used for storage location of snapshots)"
},
{
"params": [
{
"name": "outputFormat",
"doc": "output format",
"type": "int"
}
],
"name": "setOutputFormat",
"doc": "set the image storage format, 0x0=JPEG 0x1=PNG"
}
]
}
],
"complexTypes": [],
"events": []
}
Loading

0 comments on commit c4c1658

Please sign in to comment.