diff --git a/src/common/compression.cpp b/src/common/compression.cpp index 07bd11d3c..d9819c702 100644 --- a/src/common/compression.cpp +++ b/src/common/compression.cpp @@ -30,8 +30,8 @@ const char *compression_methods[] = { #if defined(HAVE_LZO1X_H) #include -lzo_compression_c::lzo_compression_c(): - compression_c(COMPRESSION_LZO) { +lzo_compressor_c::lzo_compressor_c(): + compressor_c(COMPRESSION_LZO) { int result; if ((result = lzo_init()) != LZO_E_OK) @@ -41,21 +41,21 @@ lzo_compression_c::lzo_compression_c(): mxerror("lzo_malloc(LZO1X_999_MEM_COMPRESS) failed.\n"); } -lzo_compression_c::~lzo_compression_c() { +lzo_compressor_c::~lzo_compressor_c() { safefree(wrkmem); } unsigned char * -lzo_compression_c::decompress(unsigned char *buffer, - int &size) { - die("lzo_compression_c::decompress() not implemented\n"); +lzo_compressor_c::decompress(unsigned char *buffer, + int &size) { + die("lzo_compressor_c::decompress() not implemented\n"); return NULL; } unsigned char * -lzo_compression_c::compress(unsigned char *buffer, - int &size) { +lzo_compressor_c::compress(unsigned char *buffer, + int &size) { unsigned char *dst; int result, dstsize; @@ -67,7 +67,7 @@ lzo_compression_c::compress(unsigned char *buffer, mxerror("LZO compression failed. Result: %d\n", result); dstsize = lzo_dstsize; - mxverb(3, "lzo_compression_c: Compression from %d to %d, %d%%\n", + mxverb(3, "lzo_compressor_c: Compression from %d to %d, %d%%\n", size, dstsize, dstsize * 100 / size); raw_size += size; @@ -83,16 +83,16 @@ lzo_compression_c::compress(unsigned char *buffer, #endif // HAVE_LZO1X_H #if defined(HAVE_ZLIB_H) -zlib_compression_c::zlib_compression_c(): - compression_c(COMPRESSION_ZLIB) { +zlib_compressor_c::zlib_compressor_c(): + compressor_c(COMPRESSION_ZLIB) { } -zlib_compression_c::~zlib_compression_c() { +zlib_compressor_c::~zlib_compressor_c() { } unsigned char * -zlib_compression_c::decompress(unsigned char *buffer, - int &size) { +zlib_compressor_c::decompress(unsigned char *buffer, + int &size) { int result, dstsize, n; unsigned char *dst; z_stream d_stream; @@ -122,7 +122,7 @@ zlib_compression_c::decompress(unsigned char *buffer, dstsize = d_stream.total_out; inflateEnd(&d_stream); - mxverb(3, "zlib_compression_c: Decompression from %d to %d, %d%%\n", + mxverb(3, "zlib_compressor_c: Decompression from %d to %d, %d%%\n", size, dstsize, dstsize * 100 / size); dst = (unsigned char *)saferealloc(dst, dstsize); @@ -132,8 +132,8 @@ zlib_compression_c::decompress(unsigned char *buffer, } unsigned char * -zlib_compression_c::compress(unsigned char *buffer, - int &size) { +zlib_compressor_c::compress(unsigned char *buffer, + int &size) { int result, dstsize, n; unsigned char *dst; z_stream c_stream; @@ -161,7 +161,7 @@ zlib_compression_c::compress(unsigned char *buffer, dstsize = c_stream.total_out; deflateEnd(&c_stream); - mxverb(3, "zlib_compression_c: Compression from %d to %d, %d%%\n", + mxverb(3, "zlib_compressor_c: Compression from %d to %d, %d%%\n", size, dstsize, dstsize * 100 / size); dst = (unsigned char *)saferealloc(dst, dstsize); @@ -173,20 +173,20 @@ zlib_compression_c::compress(unsigned char *buffer, #endif // HAVE_ZLIB_H #if defined(HAVE_BZLIB_H) -bzlib_compression_c::bzlib_compression_c(): - compression_c(COMPRESSION_BZ2) { +bzlib_compressor_c::bzlib_compressor_c(): + compressor_c(COMPRESSION_BZ2) { } -bzlib_compression_c::~bzlib_compression_c() { +bzlib_compressor_c::~bzlib_compressor_c() { } unsigned char * -bzlib_compression_c::decompress(unsigned char *buffer, - int &size) { +bzlib_compressor_c::decompress(unsigned char *buffer, + int &size) { int result; bz_stream d_stream; - die("bzlib_compression_c::decompress() not implemented\n"); + die("bzlib_compressor_c::decompress() not implemented\n"); d_stream.bzalloc = NULL; d_stream.bzfree = NULL; @@ -201,8 +201,8 @@ bzlib_compression_c::decompress(unsigned char *buffer, } unsigned char * -bzlib_compression_c::compress(unsigned char *buffer, - int &size) { +bzlib_compressor_c::compress(unsigned char *buffer, + int &size) { unsigned char *dst; int result, dstsize; bz_stream c_stream; @@ -227,7 +227,7 @@ bzlib_compression_c::compress(unsigned char *buffer, dstsize = 2 * size - c_stream.avail_out; - mxverb(3, "bzlib_compression_c: Compression from %d to %d, %d%%\n", + mxverb(3, "bzlib_compressor_c: Compression from %d to %d, %d%%\n", size, dstsize, dstsize * 100 / size); raw_size += size; @@ -244,7 +244,7 @@ bzlib_compression_c::compress(unsigned char *buffer, #endif // HAVE_BZLIB_H -compression_c::~compression_c() { +compressor_c::~compressor_c() { if (items != 0) mxverb(2, "compression: Overall stats: raw size: %lld, compressed " "size: %lld, items: %lld, ratio: %.2f%%, avg bytes per item: " @@ -252,36 +252,36 @@ compression_c::~compression_c() { compressed_size * 100.0 / raw_size, compressed_size / items); } -compression_c * -compression_c::create(compression_method_e method) { +compressor_ptr +compressor_c::create(compression_method_e method) { if ((method <= COMPRESSION_UNSPECIFIED) || (method > COMPRESSION_NUM)) - return NULL; + return compressor_ptr(); return create(compression_methods[method]); } -compression_c * -compression_c::create(const char *method) { +compressor_ptr +compressor_c::create(const char *method) { #if defined(HAVE_LZO1X_H) if (!strcasecmp(method, compression_methods[COMPRESSION_LZO])) - return new lzo_compression_c(); + return compressor_ptr(new lzo_compressor_c()); #endif // HAVE_LZO1X_H #if defined(HAVE_ZLIB_H) if (!strcasecmp(method, compression_methods[COMPRESSION_ZLIB])) - return new zlib_compression_c(); + return compressor_ptr(new zlib_compressor_c()); #endif // HAVE_ZLIB_H #if defined(HAVE_BZLIB_H) if (!strcasecmp(method, compression_methods[COMPRESSION_BZ2])) - return new bzlib_compression_c(); + return compressor_ptr(new bzlib_compressor_c()); #endif // HAVE_BZLIB_H if (!strcasecmp(method, "none")) - return new compression_c(COMPRESSION_NONE); + return compressor_ptr(new compressor_c(COMPRESSION_NONE)); - return NULL; + return compressor_ptr(); } // ------------------------------------------------------------------------ @@ -432,7 +432,7 @@ content_decoder_c::initialize(KaxTrackEntry &ktentry) { break; #else if (NULL == zlib_compressor.get()) - zlib_compressor = auto_ptr(new zlib_compression_c()); + zlib_compressor = auto_ptr(new zlib_compressor_c()); #endif } else if (1 == enc.comp_algo) { #if !defined(HAVE_BZLIB_H) @@ -442,7 +442,7 @@ content_decoder_c::initialize(KaxTrackEntry &ktentry) { break; #else if (NULL == bzlib_compressor.get()) - bzlib_compressor = auto_ptr(new bzlib_compression_c()); + bzlib_compressor = auto_ptr(new bzlib_compressor_c()); #endif } else if (enc.comp_algo == 2) { #if !defined(HAVE_LZO1X_H) @@ -452,7 +452,7 @@ content_decoder_c::initialize(KaxTrackEntry &ktentry) { break; #else if (NULL == lzo1x_compressor.get()) - lzo1x_compressor = auto_ptr(new lzo_compression_c()); + lzo1x_compressor = auto_ptr(new lzo_compressor_c()); #endif } else { mxwarn("Track %d has been compressed with an unknown/unsupported " @@ -479,7 +479,7 @@ content_decoder_c::reverse(unsigned char *&data, unsigned char *new_data, *old_data; bool modified; vector::const_iterator ce; - compression_c *compressor; + compressor_c *compressor; if (!ok) return false; diff --git a/src/common/compression.h b/src/common/compression.h index c7c575e69..088b35479 100644 --- a/src/common/compression.h +++ b/src/common/compression.h @@ -21,6 +21,7 @@ #include #include "common.h" +#include "smart_pointers.h" using namespace libmatroska; @@ -36,17 +37,20 @@ enum compression_method_e { extern const char *MTX_DLL_API xcompression_methods[]; -class MTX_DLL_API compression_c { +class compressor_c; +typedef counted_ptr compressor_ptr; + +class MTX_DLL_API compressor_c { protected: compression_method_e method; int64_t raw_size, compressed_size, items; public: - compression_c(compression_method_e _method): + compressor_c(compression_method_e _method): method(_method), raw_size(0), compressed_size(0), items(0) { }; - virtual ~compression_c(); + virtual ~compressor_c(); compression_method_e get_method() { return method; @@ -60,20 +64,20 @@ public: return (unsigned char *)safememdup(buffer, size); }; - static compression_c *create(compression_method_e method); - static compression_c *create(const char *method); + static compressor_ptr create(compression_method_e method); + static compressor_ptr create(const char *method); }; #if defined(HAVE_LZO1X_H) #include -class MTX_DLL_API lzo_compression_c: public compression_c { +class MTX_DLL_API lzo_compressor_c: public compressor_c { protected: lzo_byte *wrkmem; public: - lzo_compression_c(); - virtual ~lzo_compression_c(); + lzo_compressor_c(); + virtual ~lzo_compressor_c(); virtual unsigned char *decompress(unsigned char *buffer, int &size); virtual unsigned char *compress(unsigned char *buffer, int &size); @@ -83,10 +87,10 @@ public: #if defined(HAVE_ZLIB_H) #include -class MTX_DLL_API zlib_compression_c: public compression_c { +class MTX_DLL_API zlib_compressor_c: public compressor_c { public: - zlib_compression_c(); - virtual ~zlib_compression_c(); + zlib_compressor_c(); + virtual ~zlib_compressor_c(); virtual unsigned char *decompress(unsigned char *buffer, int &size); virtual unsigned char *compress(unsigned char *buffer, int &size); @@ -96,10 +100,10 @@ public: #if defined(HAVE_BZLIB_H) #include -class MTX_DLL_API bzlib_compression_c: public compression_c { +class MTX_DLL_API bzlib_compressor_c: public compressor_c { public: - bzlib_compression_c(); - virtual ~bzlib_compression_c(); + bzlib_compressor_c(); + virtual ~bzlib_compressor_c(); virtual unsigned char *decompress(unsigned char *buffer, int &size); virtual unsigned char *compress(unsigned char *buffer, int &size); @@ -124,7 +128,7 @@ enum content_encoding_scope_e { class MTX_DLL_API content_decoder_c { protected: vector encodings; - auto_ptr zlib_compressor, bzlib_compressor, lzo1x_compressor; + auto_ptr zlib_compressor, bzlib_compressor, lzo1x_compressor; bool ok; public: diff --git a/src/merge/pr_generic.cpp b/src/merge/pr_generic.cpp index a6925151d..321b8c0db 100644 --- a/src/merge/pr_generic.cpp +++ b/src/merge/pr_generic.cpp @@ -266,7 +266,6 @@ generic_packetizer_c::~generic_packetizer_c() { delete ti; safefree(hcodec_private); - delete timecode_factory; } void @@ -772,8 +771,7 @@ generic_packetizer_c::set_headers() { *static_cast(&GetChild(*c_comp)) = hcompression - 1; - compressor = - counted_ptr(compression_c::create(hcompression)); + compressor = compressor_c::create(hcompression); } if (no_lacing) @@ -1084,7 +1082,7 @@ generic_packetizer_c::connect(generic_packetizer_c *src, htrack_default_duration = src->htrack_default_duration; huid = src->huid; hcompression = src->hcompression; - compressor = counted_ptr(compression_c::create(hcompression)); + compressor = compressor_c::create(hcompression); last_cue_timecode = src->last_cue_timecode; correction_timecode_offset = 0; if (_append_timecode_offset == -1) diff --git a/src/merge/pr_generic.h b/src/merge/pr_generic.h index 10038d0d1..318697f6b 100644 --- a/src/merge/pr_generic.h +++ b/src/merge/pr_generic.h @@ -433,7 +433,7 @@ protected: int hvideo_display_width, hvideo_display_height; compression_method_e hcompression; - counted_ptr compressor; + compressor_ptr compressor; timecode_factory_c *timecode_factory;