From f33934505764d66ae56fdfea9dbcc5c6eb08b39b Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 28 Dec 2010 16:57:41 +0100 Subject: Added Transcoder. --- transcode.cpp | 20 ++++++++++++++++++++ transcode.h | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 transcode.cpp create mode 100644 transcode.h diff --git a/transcode.cpp b/transcode.cpp new file mode 100644 index 0000000..249ffb3 --- /dev/null +++ b/transcode.cpp @@ -0,0 +1,20 @@ +#include "transcode.h" + +Transcoder::Transcoder(std::istream& i, HTTPResponse& r, DecoderBase& d, EncoderBase& e) : is(i), res(r), decoder(d), encoder(e) { +} + +void Transcoder::run() { + char data[0x1000]; + bool encoding_fone = false; + while(!encoding_fone) { + size_t decoded_size = 0; + char decoded_data[0x1000]; + if(is.good()) { + is.read(data, 0x1000); + decoded_size = decoder.decode((uint8_t*)data, is.gcount(), (uint8_t*)decoded_data, 0x1000); + } + char encoded_data[0x1000]; + size_t encoded_size = encoder.encode((uint8_t*)decoded_data, decoded_size, (uint8_t*)encoded_data, 0x1000); + res.write(encoded_data, encoded_size); + } +} diff --git a/transcode.h b/transcode.h new file mode 100644 index 0000000..2a63b17 --- /dev/null +++ b/transcode.h @@ -0,0 +1,22 @@ +#ifndef TRANSCODE_H +#define TRANSCODE_H + +#include "decoder.h" +#include "encoder.h" +#include "http.h" + +#include + +class Transcoder { + private: + std::istream& is; + HTTPResponse& res; + DecoderBase& decoder; + EncoderBase& encoder; + + public: + Transcoder(std::istream& i, HTTPResponse& r, DecoderBase& d, EncoderBase& e); + void run(); +}; + +#endif -- cgit v1.2.3