Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef ROSBAG_STREAM_H
00036 #define ROSBAG_STREAM_H
00037
00038 #include <ios>
00039 #include <stdint.h>
00040 #include <string>
00041
00042 #include <boost/shared_ptr.hpp>
00043
00044 #include <bzlib.h>
00045
00046 #include <roslz4/lz4s.h>
00047
00048 #include "rosbag/exceptions.h"
00049 #include "rosbag/macros.h"
00050
00051 namespace rosbag {
00052
00053 namespace compression
00054 {
00055 enum CompressionType
00056 {
00057 Uncompressed = 0,
00058 BZ2 = 1,
00059 LZ4 = 2,
00060 };
00061 }
00062 typedef compression::CompressionType CompressionType;
00063
00064 class ChunkedFile;
00065
00066 class ROSBAG_DECL Stream
00067 {
00068 public:
00069 Stream(ChunkedFile* file);
00070 virtual ~Stream();
00071
00072 virtual CompressionType getCompressionType() const = 0;
00073
00074 virtual void write(void* ptr, size_t size) = 0;
00075 virtual void read (void* ptr, size_t size) = 0;
00076
00077 virtual void decompress(uint8_t* dest, unsigned int dest_len, uint8_t* source, unsigned int source_len) = 0;
00078
00079 virtual void startWrite();
00080 virtual void stopWrite();
00081
00082 virtual void startRead();
00083 virtual void stopRead();
00084
00085 protected:
00086 FILE* getFilePointer();
00087 uint64_t getCompressedIn();
00088 void setCompressedIn(uint64_t nbytes);
00089 void advanceOffset(uint64_t nbytes);
00090 char* getUnused();
00091 int getUnusedLength();
00092 void setUnused(char* unused);
00093 void setUnusedLength(int nUnused);
00094 void clearUnused();
00095
00096 protected:
00097 ChunkedFile* file_;
00098 };
00099
00100 class ROSBAG_DECL StreamFactory
00101 {
00102 public:
00103 StreamFactory(ChunkedFile* file);
00104
00105 boost::shared_ptr<Stream> getStream(CompressionType type) const;
00106
00107 private:
00108 boost::shared_ptr<Stream> uncompressed_stream_;
00109 boost::shared_ptr<Stream> bz2_stream_;
00110 boost::shared_ptr<Stream> lz4_stream_;
00111 };
00112
00113 class ROSBAG_DECL UncompressedStream : public Stream
00114 {
00115 public:
00116 UncompressedStream(ChunkedFile* file);
00117
00118 CompressionType getCompressionType() const;
00119
00120 void write(void* ptr, size_t size);
00121 void read(void* ptr, size_t size);
00122
00123 void decompress(uint8_t* dest, unsigned int dest_len, uint8_t* source, unsigned int source_len);
00124 };
00125
00129 class ROSBAG_DECL BZ2Stream : public Stream
00130 {
00131 public:
00132 BZ2Stream(ChunkedFile* file);
00133
00134 CompressionType getCompressionType() const;
00135
00136 void startWrite();
00137 void write(void* ptr, size_t size);
00138 void stopWrite();
00139
00140 void startRead();
00141 void read(void* ptr, size_t size);
00142 void stopRead();
00143
00144 void decompress(uint8_t* dest, unsigned int dest_len, uint8_t* source, unsigned int source_len);
00145
00146 private:
00147 int verbosity_;
00148 int block_size_100k_;
00149 int work_factor_;
00150
00151 BZFILE* bzfile_;
00152 int bzerror_;
00153 };
00154
00155
00156
00157 class ROSBAG_DECL LZ4Stream : public Stream
00158 {
00159 public:
00160 LZ4Stream(ChunkedFile* file);
00161 ~LZ4Stream();
00162
00163 CompressionType getCompressionType() const;
00164
00165 void startWrite();
00166 void write(void* ptr, size_t size);
00167 void stopWrite();
00168
00169 void startRead();
00170 void read(void* ptr, size_t size);
00171 void stopRead();
00172
00173 void decompress(uint8_t* dest, unsigned int dest_len, uint8_t* source, unsigned int source_len);
00174
00175 private:
00176 void writeStream(int action);
00177
00178 char *buff_;
00179 int buff_size_;
00180 int block_size_id_;
00181 roslz4_stream lz4s_;
00182 };
00183
00184
00185
00186 }
00187
00188 #endif