wanproxy/xcodec/xcodec_filter.h

89 lines
2.5 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>
#include <proxy/wanproxy.h>
2015-08-31 12:01:44 +00:00
class EncodeFilter : public BufferedFilter
{
private:
WANProxyCodec* codec_;
XCodecCache* cache_;
2015-08-31 12:01:44 +00:00
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:
EncodeFilter (const LogHandle& log, WANProxyCodec* cdc, int flg = 0) : BufferedFilter (log)
2015-08-31 12:01:44 +00:00
{
codec_ = cdc; cache_ = (cdc ? cdc->xcache_ : 0); 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:
WANProxyCodec* codec_;
XCodecCache* encoder_cache_;
2015-08-31 12:01:44 +00:00
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, WANProxyCodec* cdc) : LogisticFilter (log)
2015-08-31 12:01:44 +00:00
{
codec_ = cdc; encoder_cache_ = (cdc ? cdc->xcache_ : 0); decoder_ = 0; decoder_cache_ = 0;
2015-08-31 12:01:44 +00:00
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 */