Skip to content

Commit

Permalink
example05 is modified for the new architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
r-shf committed Nov 20, 2014
1 parent d1983be commit 544de04
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 403 deletions.
10 changes: 5 additions & 5 deletions core/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*
*/

#include "Filter.h"
#include "Port.h"
#include "core/Filter.h"
#include "core/Port.h"

#include <iostream>

Filter::Filter(const string &name) : realtime(false), status(FilterStatus::OK), name(name) {
inMsg = nullptr;
outMsg = new Message();
//inMsg = nullptr;
//outMsg = new Message();
}

void Filter::setRealTime(bool rt) {
Expand Down Expand Up @@ -108,7 +108,7 @@ void Filter::runFilter() {
}

Filter::~Filter() {
delete outMsg;
//delete outMsg;
}

//void Filter::setProp(const string & key, const string & val) {
Expand Down
4 changes: 2 additions & 2 deletions core/Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class Filter {
bool realtime;

protected:
Message * inMsg; /**< Input message of the filter */
Message * outMsg; /**< Output message of the filter */
//Message * inMsg; /**< Input message of the filter */
//Message * outMsg; /**< Output message of the filter */

vector<Port*> inputPorts; /**< List of the input ports */
vector<Port*> outputPorts; /**< List of the output ports */
Expand Down
39 changes: 36 additions & 3 deletions core/Port.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ class Port {
string name; /**< The name of the port */
int linked; /**< The number of port connected to this port */



protected:

MediaBuffer<Attribute> * attrbuf;
int attrindex;

PortCaps portCaps;

public:
Expand All @@ -57,7 +62,7 @@ class Port {
* \param owner The owner of the filter
*/
Port(string name) :
name(name), linked(0) {
name(name), linked(0), attrbuf(nullptr), attrindex(0) {

}

Expand Down Expand Up @@ -92,6 +97,10 @@ class Port {
linked++;
}

Attribute * getAttr() {
return attrbuf->at(attrindex)->get();
}

virtual void connectPort(Port* n) {}

/*!
Expand Down Expand Up @@ -132,15 +141,27 @@ class InputPort: public Port {
}

void setBuffer(MediaBuffer<T> * b) {

buf = b;
buf->addConsumer();
}

void setAttrBuffer(MediaBuffer<Attribute> * attrb) {
attrbuf = attrb;
attrbuf->addConsumer();
}

void lockAttr() {
attrbuf->at(attrindex)->consumerLock();
}

void unlockAttr() {
attrbuf->at(attrindex)->consumerUnlock();
attrindex = (attrindex+1) % TMF_BUFFER_SIZE;
}

void lock() {
buf->at(index)->consumerLock();
}


void unlock() {
buf->at(index)->consumerUnlock();
Expand Down Expand Up @@ -195,9 +216,19 @@ class OutputPort: public Port {
*/
OutputPort<T>(string name) : Port(name), index(0) {
buf = new MediaBuffer<T>(TMF_BUFFER_SIZE);
attrbuf = new MediaBuffer<Attribute>(TMF_BUFFER_SIZE);
portCaps.addCaps("template", string(typeid(T).name()));
}

void lockAttr() {
attrbuf->at(attrindex)->producerLock();
}

void unlockAttr() {
attrbuf->at(attrindex)->producerUnlock();
attrindex = (attrindex+1) % TMF_BUFFER_SIZE;
}

void lock() {
buf->at(index)->producerLock();
}
Expand Down Expand Up @@ -235,6 +266,7 @@ class OutputPort: public Port {
this->increaseLinked();
in->increaseLinked();
in->setBuffer(buf);
in->setAttrBuffer(attrbuf);
}

/*!
Expand All @@ -243,6 +275,7 @@ class OutputPort: public Port {
*/
~OutputPort<T>() {
delete buf;
delete attrbuf;
}
};

Expand Down
4 changes: 2 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ target_link_libraries(example03 tmf)
add_executable(example04 example04.cpp)
target_link_libraries(example04 tmf)

add_executable(example2 example2.cpp)
target_link_libraries(example2 tmf)
add_executable(example05 example05.cpp)
target_link_libraries(example05 tmf)

add_executable(example3 example3.cpp)
target_link_libraries(example3 tmf)
Expand Down
File renamed without changes.
26 changes: 15 additions & 11 deletions filters/libav/ImageScalerFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,19 @@ class ImageScalerFilter : public Filter {

int srcWidth, srcHeight, srcFormatInt;

err = inMsg->getPropInt("width", srcWidth);
//if (err == MSG_NOT_FOUND)
// return FILTER_WAIT_FOR_INPUT;

err = inMsg->getPropInt("height", srcHeight);
//if (err == MSG_NOT_FOUND)
// return FILTER_WAIT_FOR_INPUT;

err = inMsg->getPropInt("format", srcFormatInt);
//if (err == MSG_NOT_FOUND)
// return FILTER_WAIT_FOR_INPUT;
/*
* err = inMsg->getPropInt("width", srcWidth);
* //if (err == MSG_NOT_FOUND)
* // return FILTER_WAIT_FOR_INPUT;
*
* err = inMsg->getPropInt("height", srcHeight);
* //if (err == MSG_NOT_FOUND)
* // return FILTER_WAIT_FOR_INPUT;
*
* err = inMsg->getPropInt("format", srcFormatInt);
* //if (err == MSG_NOT_FOUND)
* // return FILTER_WAIT_FOR_INPUT;
*/

AVPixelFormat srcFormat = static_cast<AVPixelFormat>(srcFormatInt);

Expand All @@ -84,9 +86,11 @@ class ImageScalerFilter : public Filter {
// frame->fill(dstWidth, dstHeight, srcFormat);
//}

/*
outMsg->setProp("width", width);
outMsg->setProp("height", height);
outMsg->setPropInt("format", srcFormatInt);
*/


}
Expand Down
37 changes: 23 additions & 14 deletions filters/libav/ImageWriterFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef IMAGEWRITER_H_
#define IMAGEWRITER_H_

#include "core/Port.h"
#include "core/Filter.h"
#include "tools/VideoFrameWriter.h"

Expand All @@ -39,27 +40,24 @@ class ImageWriterFilter: public Filter {

inputPorts.push_back(inputFrame);

videoFrameWriter = nullptr;
videoFrameWriter = 0;
}

void init() {

MessageError err;
//string videoName = getProp("input_video");

int srcWidth, srcHeight, srcFormatInt;

err = inMsg->getPropInt("width", srcWidth);
//if (err == MSG_NOT_FOUND)
// return FILTER_WAIT_FOR_INPUT;
inputFrame->lockAttr();

Attribute * attr = inputFrame->getAttr();

srcWidth = stoi(attr->getProp("width"));

srcHeight = stoi(attr->getProp("height"));

err = inMsg->getPropInt("height", srcHeight);
//if (err == MSG_NOT_FOUND)
// return FILTER_WAIT_FOR_INPUT;
srcFormatInt = stoi(attr->getProp("format"));

err = inMsg->getPropInt("format", srcFormatInt);
//if (err == MSG_NOT_FOUND)
// return FILTER_WAIT_FOR_INPUT;
inputFrame->unlockAttr();

AVPixelFormat srcFormat = static_cast<AVPixelFormat>(srcFormatInt);

Expand All @@ -71,16 +69,27 @@ class ImageWriterFilter: public Filter {
void run() {

inputFrame->lock();

if (inputFrame->getStatus() == SampleStatus::EOS) {
status = FilterStatus::EOS;
inputFrame->unlock();
return;
}

RawFrame * data = inputFrame->get();
videoFrameWriter->writeImage(data);

inputFrame->unlock();
}

~ImageWriterFilter() {
delete inputFrame;
delete videoFrameWriter;
//TODO I don't know why it craches here!
// if(videoFrameWriter)
// delete videoFrameWriter;
}


};

#endif /* IMAGEWRITER_H_ */
19 changes: 12 additions & 7 deletions filters/libav/VideoDecoderFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@ class VideoDecoderFilter: public Filter {

videoReader->dump();

outMsg->setPropInt("width", videoReader->getWidth());
outMsg->setPropInt("height", videoReader->getHeight());
outMsg->setPropInt("format",
static_cast<int>(videoReader->getPixFormat()));
outputFrame->lockAttr();

Attribute * attr = outputFrame->getAttr();

attr->setProp("width", videoReader->getWidth());
attr->setProp("height", videoReader->getHeight());
attr->setProp("format",
static_cast<int>(videoReader->getPixFormat()));

outputFrame->unlockAttr();

}

void run() {
Expand All @@ -65,12 +72,10 @@ class VideoDecoderFilter: public Filter {
int ret = videoReader->readFrame(data);

if (ret == -1) {
outputFrame->setStatus(SampleStatus::EOS);
status = FilterStatus::EOS;
outputFrame->unlock();
}

outputFrame->unlock();

}

~VideoDecoderFilter() {
Expand Down
24 changes: 13 additions & 11 deletions filters/libav/VideoDisplayFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ void VideoDisplayFilter::init() {
MessageError err;
int width, height, pixFmtInt;

err = inMsg->getPropInt("width", width);
//if (err == MSG_NOT_FOUND)
// return FILTER_WAIT_FOR_INPUT;

err = inMsg->getPropInt("height", height);
//if (err == MSG_NOT_FOUND)
// return FILTER_WAIT_FOR_INPUT;

err = inMsg->getPropInt("format", pixFmtInt);
//if (err == MSG_NOT_FOUND)
// return FILTER_WAIT_FOR_INPUT;
/*
* err = inMsg->getPropInt("width", width);
* //if (err == MSG_NOT_FOUND)
* // return FILTER_WAIT_FOR_INPUT;
*
* err = inMsg->getPropInt("height", height);
* //if (err == MSG_NOT_FOUND)
* // return FILTER_WAIT_FOR_INPUT;
*
* err = inMsg->getPropInt("format", pixFmtInt);
* //if (err == MSG_NOT_FOUND)
* // return FILTER_WAIT_FOR_INPUT;
*/

AVPixelFormat pixFmt = static_cast<AVPixelFormat>(pixFmtInt);

Expand Down
Loading

0 comments on commit 544de04

Please sign in to comment.