wanproxy/xcodec/xcodec_filter.h

85 lines
2.4 KiB
C
Raw Normal View History

2015-08-31 12:01:44 +00:00
////////////////////////////////////////////////////////////////////////////////
// //
// File: xcodec_filter.h //
// Description: instantiation of encoder/decoder in a data filter pair //
// Project: WANProxy XTech //
// Author: Andreu Vidal Bramfeld-Software //
2016-02-28 19:50:31 +00:00
// Last modified: 2016-02-28 //
2015-08-31 12:01:44 +00:00
// //
////////////////////////////////////////////////////////////////////////////////
#ifndef XCODEC_FILTER_H
#define XCODEC_FILTER_H
#include <set>
#include <common/filter.h>
2016-02-19 13:27:00 +00:00
#include <event/event.h>
#include <event/action.h>
2015-08-31 12:01:44 +00:00
#include <xcodec/xcodec.h>
#include <xcodec/xcodec_cache.h>
#include <xcodec/xcodec_hash.h>
#include <xcodec/xcodec_encoder.h>
#include <xcodec/xcodec_decoder.h>
class EncodeFilter : public BufferedFilter
{
private:
XCodecCache* cache_;
XCodecEncoder* encoder_;
2016-02-19 13:27:00 +00:00
Action* wait_action_;
bool waiting_;
2015-08-31 12:01:44 +00:00
bool sent_eos_;
bool eos_ack_;
public:
2016-02-19 13:27:00 +00:00
EncodeFilter (const LogHandle& log, XCodecCache* cc, int flg = 0) : BufferedFilter (log)
2015-08-31 12:01:44 +00:00
{
2016-02-19 13:27:00 +00:00
cache_ = cc; encoder_ = 0; wait_action_ = 0; waiting_ = (flg & 1); sent_eos_ = eos_ack_ = false;
2015-08-31 12:01:44 +00:00
}
virtual ~EncodeFilter ()
{
2016-02-19 13:27:00 +00:00
if (wait_action_)
wait_action_->cancel ();
2015-08-31 12:01:44 +00:00
delete encoder_;
}
2016-02-28 19:50:31 +00:00
virtual bool consume (Buffer& buf, int flg = 0);
2015-08-31 12:01:44 +00:00
virtual void flush (int flg);
2016-02-19 13:27:00 +00:00
private:
void encode_frame (Buffer& src, Buffer& trg);
void on_read_timeout (Event e);
2015-08-31 12:01:44 +00:00
};
class DecodeFilter : public LogisticFilter
{
private:
XCodecCache* encoder_cache_;
XCodecDecoder* decoder_;
XCodecCache* decoder_cache_;
std::set<uint64_t> unknown_hashes_;
Buffer frame_buffer_;
bool received_eos_;
bool sent_eos_ack_;
bool received_eos_ack_;
bool upflushed_;
public:
DecodeFilter (const LogHandle& log, XCodecCache* cc) : LogisticFilter (log)
{
encoder_cache_ = cc; decoder_ = 0; decoder_cache_ = 0;
received_eos_ = sent_eos_ack_ = received_eos_ack_ = upflushed_ = false;
}
~DecodeFilter ()
{
delete decoder_;
}
2016-02-28 19:50:31 +00:00
virtual bool consume (Buffer& buf, int flg = 0);
2015-08-31 12:01:44 +00:00
virtual void flush (int flg);
};
#endif /* !XCODEC_FILTER_H */