mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-24 20:01:53 +00:00
Renamed compression_c to compressor_c. More smart pointer usage.
This commit is contained in:
parent
26791bbf4d
commit
76a506afd2
@ -30,8 +30,8 @@ const char *compression_methods[] = {
|
|||||||
#if defined(HAVE_LZO1X_H)
|
#if defined(HAVE_LZO1X_H)
|
||||||
#include <lzoutil.h>
|
#include <lzoutil.h>
|
||||||
|
|
||||||
lzo_compression_c::lzo_compression_c():
|
lzo_compressor_c::lzo_compressor_c():
|
||||||
compression_c(COMPRESSION_LZO) {
|
compressor_c(COMPRESSION_LZO) {
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if ((result = lzo_init()) != LZO_E_OK)
|
if ((result = lzo_init()) != LZO_E_OK)
|
||||||
@ -41,20 +41,20 @@ lzo_compression_c::lzo_compression_c():
|
|||||||
mxerror("lzo_malloc(LZO1X_999_MEM_COMPRESS) failed.\n");
|
mxerror("lzo_malloc(LZO1X_999_MEM_COMPRESS) failed.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
lzo_compression_c::~lzo_compression_c() {
|
lzo_compressor_c::~lzo_compressor_c() {
|
||||||
safefree(wrkmem);
|
safefree(wrkmem);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *
|
unsigned char *
|
||||||
lzo_compression_c::decompress(unsigned char *buffer,
|
lzo_compressor_c::decompress(unsigned char *buffer,
|
||||||
int &size) {
|
int &size) {
|
||||||
die("lzo_compression_c::decompress() not implemented\n");
|
die("lzo_compressor_c::decompress() not implemented\n");
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *
|
unsigned char *
|
||||||
lzo_compression_c::compress(unsigned char *buffer,
|
lzo_compressor_c::compress(unsigned char *buffer,
|
||||||
int &size) {
|
int &size) {
|
||||||
unsigned char *dst;
|
unsigned char *dst;
|
||||||
int result, dstsize;
|
int result, dstsize;
|
||||||
@ -67,7 +67,7 @@ lzo_compression_c::compress(unsigned char *buffer,
|
|||||||
mxerror("LZO compression failed. Result: %d\n", result);
|
mxerror("LZO compression failed. Result: %d\n", result);
|
||||||
dstsize = lzo_dstsize;
|
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);
|
size, dstsize, dstsize * 100 / size);
|
||||||
|
|
||||||
raw_size += size;
|
raw_size += size;
|
||||||
@ -83,15 +83,15 @@ lzo_compression_c::compress(unsigned char *buffer,
|
|||||||
#endif // HAVE_LZO1X_H
|
#endif // HAVE_LZO1X_H
|
||||||
|
|
||||||
#if defined(HAVE_ZLIB_H)
|
#if defined(HAVE_ZLIB_H)
|
||||||
zlib_compression_c::zlib_compression_c():
|
zlib_compressor_c::zlib_compressor_c():
|
||||||
compression_c(COMPRESSION_ZLIB) {
|
compressor_c(COMPRESSION_ZLIB) {
|
||||||
}
|
}
|
||||||
|
|
||||||
zlib_compression_c::~zlib_compression_c() {
|
zlib_compressor_c::~zlib_compressor_c() {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *
|
unsigned char *
|
||||||
zlib_compression_c::decompress(unsigned char *buffer,
|
zlib_compressor_c::decompress(unsigned char *buffer,
|
||||||
int &size) {
|
int &size) {
|
||||||
int result, dstsize, n;
|
int result, dstsize, n;
|
||||||
unsigned char *dst;
|
unsigned char *dst;
|
||||||
@ -122,7 +122,7 @@ zlib_compression_c::decompress(unsigned char *buffer,
|
|||||||
dstsize = d_stream.total_out;
|
dstsize = d_stream.total_out;
|
||||||
inflateEnd(&d_stream);
|
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);
|
size, dstsize, dstsize * 100 / size);
|
||||||
|
|
||||||
dst = (unsigned char *)saferealloc(dst, dstsize);
|
dst = (unsigned char *)saferealloc(dst, dstsize);
|
||||||
@ -132,7 +132,7 @@ zlib_compression_c::decompress(unsigned char *buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *
|
unsigned char *
|
||||||
zlib_compression_c::compress(unsigned char *buffer,
|
zlib_compressor_c::compress(unsigned char *buffer,
|
||||||
int &size) {
|
int &size) {
|
||||||
int result, dstsize, n;
|
int result, dstsize, n;
|
||||||
unsigned char *dst;
|
unsigned char *dst;
|
||||||
@ -161,7 +161,7 @@ zlib_compression_c::compress(unsigned char *buffer,
|
|||||||
dstsize = c_stream.total_out;
|
dstsize = c_stream.total_out;
|
||||||
deflateEnd(&c_stream);
|
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);
|
size, dstsize, dstsize * 100 / size);
|
||||||
|
|
||||||
dst = (unsigned char *)saferealloc(dst, dstsize);
|
dst = (unsigned char *)saferealloc(dst, dstsize);
|
||||||
@ -173,20 +173,20 @@ zlib_compression_c::compress(unsigned char *buffer,
|
|||||||
#endif // HAVE_ZLIB_H
|
#endif // HAVE_ZLIB_H
|
||||||
|
|
||||||
#if defined(HAVE_BZLIB_H)
|
#if defined(HAVE_BZLIB_H)
|
||||||
bzlib_compression_c::bzlib_compression_c():
|
bzlib_compressor_c::bzlib_compressor_c():
|
||||||
compression_c(COMPRESSION_BZ2) {
|
compressor_c(COMPRESSION_BZ2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bzlib_compression_c::~bzlib_compression_c() {
|
bzlib_compressor_c::~bzlib_compressor_c() {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *
|
unsigned char *
|
||||||
bzlib_compression_c::decompress(unsigned char *buffer,
|
bzlib_compressor_c::decompress(unsigned char *buffer,
|
||||||
int &size) {
|
int &size) {
|
||||||
int result;
|
int result;
|
||||||
bz_stream d_stream;
|
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.bzalloc = NULL;
|
||||||
d_stream.bzfree = NULL;
|
d_stream.bzfree = NULL;
|
||||||
@ -201,7 +201,7 @@ bzlib_compression_c::decompress(unsigned char *buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *
|
unsigned char *
|
||||||
bzlib_compression_c::compress(unsigned char *buffer,
|
bzlib_compressor_c::compress(unsigned char *buffer,
|
||||||
int &size) {
|
int &size) {
|
||||||
unsigned char *dst;
|
unsigned char *dst;
|
||||||
int result, dstsize;
|
int result, dstsize;
|
||||||
@ -227,7 +227,7 @@ bzlib_compression_c::compress(unsigned char *buffer,
|
|||||||
|
|
||||||
dstsize = 2 * size - c_stream.avail_out;
|
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);
|
size, dstsize, dstsize * 100 / size);
|
||||||
|
|
||||||
raw_size += size;
|
raw_size += size;
|
||||||
@ -244,7 +244,7 @@ bzlib_compression_c::compress(unsigned char *buffer,
|
|||||||
|
|
||||||
#endif // HAVE_BZLIB_H
|
#endif // HAVE_BZLIB_H
|
||||||
|
|
||||||
compression_c::~compression_c() {
|
compressor_c::~compressor_c() {
|
||||||
if (items != 0)
|
if (items != 0)
|
||||||
mxverb(2, "compression: Overall stats: raw size: %lld, compressed "
|
mxverb(2, "compression: Overall stats: raw size: %lld, compressed "
|
||||||
"size: %lld, items: %lld, ratio: %.2f%%, avg bytes per item: "
|
"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);
|
compressed_size * 100.0 / raw_size, compressed_size / items);
|
||||||
}
|
}
|
||||||
|
|
||||||
compression_c *
|
compressor_ptr
|
||||||
compression_c::create(compression_method_e method) {
|
compressor_c::create(compression_method_e method) {
|
||||||
if ((method <= COMPRESSION_UNSPECIFIED) ||
|
if ((method <= COMPRESSION_UNSPECIFIED) ||
|
||||||
(method > COMPRESSION_NUM))
|
(method > COMPRESSION_NUM))
|
||||||
return NULL;
|
return compressor_ptr();
|
||||||
|
|
||||||
return create(compression_methods[method]);
|
return create(compression_methods[method]);
|
||||||
}
|
}
|
||||||
|
|
||||||
compression_c *
|
compressor_ptr
|
||||||
compression_c::create(const char *method) {
|
compressor_c::create(const char *method) {
|
||||||
#if defined(HAVE_LZO1X_H)
|
#if defined(HAVE_LZO1X_H)
|
||||||
if (!strcasecmp(method, compression_methods[COMPRESSION_LZO]))
|
if (!strcasecmp(method, compression_methods[COMPRESSION_LZO]))
|
||||||
return new lzo_compression_c();
|
return compressor_ptr(new lzo_compressor_c());
|
||||||
#endif // HAVE_LZO1X_H
|
#endif // HAVE_LZO1X_H
|
||||||
|
|
||||||
#if defined(HAVE_ZLIB_H)
|
#if defined(HAVE_ZLIB_H)
|
||||||
if (!strcasecmp(method, compression_methods[COMPRESSION_ZLIB]))
|
if (!strcasecmp(method, compression_methods[COMPRESSION_ZLIB]))
|
||||||
return new zlib_compression_c();
|
return compressor_ptr(new zlib_compressor_c());
|
||||||
#endif // HAVE_ZLIB_H
|
#endif // HAVE_ZLIB_H
|
||||||
|
|
||||||
#if defined(HAVE_BZLIB_H)
|
#if defined(HAVE_BZLIB_H)
|
||||||
if (!strcasecmp(method, compression_methods[COMPRESSION_BZ2]))
|
if (!strcasecmp(method, compression_methods[COMPRESSION_BZ2]))
|
||||||
return new bzlib_compression_c();
|
return compressor_ptr(new bzlib_compressor_c());
|
||||||
#endif // HAVE_BZLIB_H
|
#endif // HAVE_BZLIB_H
|
||||||
|
|
||||||
if (!strcasecmp(method, "none"))
|
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;
|
break;
|
||||||
#else
|
#else
|
||||||
if (NULL == zlib_compressor.get())
|
if (NULL == zlib_compressor.get())
|
||||||
zlib_compressor = auto_ptr<compression_c>(new zlib_compression_c());
|
zlib_compressor = auto_ptr<compressor_c>(new zlib_compressor_c());
|
||||||
#endif
|
#endif
|
||||||
} else if (1 == enc.comp_algo) {
|
} else if (1 == enc.comp_algo) {
|
||||||
#if !defined(HAVE_BZLIB_H)
|
#if !defined(HAVE_BZLIB_H)
|
||||||
@ -442,7 +442,7 @@ content_decoder_c::initialize(KaxTrackEntry &ktentry) {
|
|||||||
break;
|
break;
|
||||||
#else
|
#else
|
||||||
if (NULL == bzlib_compressor.get())
|
if (NULL == bzlib_compressor.get())
|
||||||
bzlib_compressor = auto_ptr<compression_c>(new bzlib_compression_c());
|
bzlib_compressor = auto_ptr<compressor_c>(new bzlib_compressor_c());
|
||||||
#endif
|
#endif
|
||||||
} else if (enc.comp_algo == 2) {
|
} else if (enc.comp_algo == 2) {
|
||||||
#if !defined(HAVE_LZO1X_H)
|
#if !defined(HAVE_LZO1X_H)
|
||||||
@ -452,7 +452,7 @@ content_decoder_c::initialize(KaxTrackEntry &ktentry) {
|
|||||||
break;
|
break;
|
||||||
#else
|
#else
|
||||||
if (NULL == lzo1x_compressor.get())
|
if (NULL == lzo1x_compressor.get())
|
||||||
lzo1x_compressor = auto_ptr<compression_c>(new lzo_compression_c());
|
lzo1x_compressor = auto_ptr<compressor_c>(new lzo_compressor_c());
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
mxwarn("Track %d has been compressed with an unknown/unsupported "
|
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;
|
unsigned char *new_data, *old_data;
|
||||||
bool modified;
|
bool modified;
|
||||||
vector<kax_content_encoding_t>::const_iterator ce;
|
vector<kax_content_encoding_t>::const_iterator ce;
|
||||||
compression_c *compressor;
|
compressor_c *compressor;
|
||||||
|
|
||||||
if (!ok)
|
if (!ok)
|
||||||
return false;
|
return false;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <matroska/KaxTracks.h>
|
#include <matroska/KaxTracks.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "smart_pointers.h"
|
||||||
|
|
||||||
using namespace libmatroska;
|
using namespace libmatroska;
|
||||||
|
|
||||||
@ -36,17 +37,20 @@ enum compression_method_e {
|
|||||||
|
|
||||||
extern const char *MTX_DLL_API xcompression_methods[];
|
extern const char *MTX_DLL_API xcompression_methods[];
|
||||||
|
|
||||||
class MTX_DLL_API compression_c {
|
class compressor_c;
|
||||||
|
typedef counted_ptr<compressor_c> compressor_ptr;
|
||||||
|
|
||||||
|
class MTX_DLL_API compressor_c {
|
||||||
protected:
|
protected:
|
||||||
compression_method_e method;
|
compression_method_e method;
|
||||||
int64_t raw_size, compressed_size, items;
|
int64_t raw_size, compressed_size, items;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
compression_c(compression_method_e _method):
|
compressor_c(compression_method_e _method):
|
||||||
method(_method), raw_size(0), compressed_size(0), items(0) {
|
method(_method), raw_size(0), compressed_size(0), items(0) {
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~compression_c();
|
virtual ~compressor_c();
|
||||||
|
|
||||||
compression_method_e get_method() {
|
compression_method_e get_method() {
|
||||||
return method;
|
return method;
|
||||||
@ -60,20 +64,20 @@ public:
|
|||||||
return (unsigned char *)safememdup(buffer, size);
|
return (unsigned char *)safememdup(buffer, size);
|
||||||
};
|
};
|
||||||
|
|
||||||
static compression_c *create(compression_method_e method);
|
static compressor_ptr create(compression_method_e method);
|
||||||
static compression_c *create(const char *method);
|
static compressor_ptr create(const char *method);
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(HAVE_LZO1X_H)
|
#if defined(HAVE_LZO1X_H)
|
||||||
#include <lzo1x.h>
|
#include <lzo1x.h>
|
||||||
|
|
||||||
class MTX_DLL_API lzo_compression_c: public compression_c {
|
class MTX_DLL_API lzo_compressor_c: public compressor_c {
|
||||||
protected:
|
protected:
|
||||||
lzo_byte *wrkmem;
|
lzo_byte *wrkmem;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
lzo_compression_c();
|
lzo_compressor_c();
|
||||||
virtual ~lzo_compression_c();
|
virtual ~lzo_compressor_c();
|
||||||
|
|
||||||
virtual unsigned char *decompress(unsigned char *buffer, int &size);
|
virtual unsigned char *decompress(unsigned char *buffer, int &size);
|
||||||
virtual unsigned char *compress(unsigned char *buffer, int &size);
|
virtual unsigned char *compress(unsigned char *buffer, int &size);
|
||||||
@ -83,10 +87,10 @@ public:
|
|||||||
#if defined(HAVE_ZLIB_H)
|
#if defined(HAVE_ZLIB_H)
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
class MTX_DLL_API zlib_compression_c: public compression_c {
|
class MTX_DLL_API zlib_compressor_c: public compressor_c {
|
||||||
public:
|
public:
|
||||||
zlib_compression_c();
|
zlib_compressor_c();
|
||||||
virtual ~zlib_compression_c();
|
virtual ~zlib_compressor_c();
|
||||||
|
|
||||||
virtual unsigned char *decompress(unsigned char *buffer, int &size);
|
virtual unsigned char *decompress(unsigned char *buffer, int &size);
|
||||||
virtual unsigned char *compress(unsigned char *buffer, int &size);
|
virtual unsigned char *compress(unsigned char *buffer, int &size);
|
||||||
@ -96,10 +100,10 @@ public:
|
|||||||
#if defined(HAVE_BZLIB_H)
|
#if defined(HAVE_BZLIB_H)
|
||||||
#include <bzlib.h>
|
#include <bzlib.h>
|
||||||
|
|
||||||
class MTX_DLL_API bzlib_compression_c: public compression_c {
|
class MTX_DLL_API bzlib_compressor_c: public compressor_c {
|
||||||
public:
|
public:
|
||||||
bzlib_compression_c();
|
bzlib_compressor_c();
|
||||||
virtual ~bzlib_compression_c();
|
virtual ~bzlib_compressor_c();
|
||||||
|
|
||||||
virtual unsigned char *decompress(unsigned char *buffer, int &size);
|
virtual unsigned char *decompress(unsigned char *buffer, int &size);
|
||||||
virtual unsigned char *compress(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 {
|
class MTX_DLL_API content_decoder_c {
|
||||||
protected:
|
protected:
|
||||||
vector<kax_content_encoding_t> encodings;
|
vector<kax_content_encoding_t> encodings;
|
||||||
auto_ptr<compression_c> zlib_compressor, bzlib_compressor, lzo1x_compressor;
|
auto_ptr<compressor_c> zlib_compressor, bzlib_compressor, lzo1x_compressor;
|
||||||
bool ok;
|
bool ok;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -266,7 +266,6 @@ generic_packetizer_c::~generic_packetizer_c() {
|
|||||||
delete ti;
|
delete ti;
|
||||||
|
|
||||||
safefree(hcodec_private);
|
safefree(hcodec_private);
|
||||||
delete timecode_factory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -772,8 +771,7 @@ generic_packetizer_c::set_headers() {
|
|||||||
*static_cast<EbmlUInteger *>(&GetChild<KaxContentCompAlgo>(*c_comp)) =
|
*static_cast<EbmlUInteger *>(&GetChild<KaxContentCompAlgo>(*c_comp)) =
|
||||||
hcompression - 1;
|
hcompression - 1;
|
||||||
|
|
||||||
compressor =
|
compressor = compressor_c::create(hcompression);
|
||||||
counted_ptr<compression_c>(compression_c::create(hcompression));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (no_lacing)
|
if (no_lacing)
|
||||||
@ -1084,7 +1082,7 @@ generic_packetizer_c::connect(generic_packetizer_c *src,
|
|||||||
htrack_default_duration = src->htrack_default_duration;
|
htrack_default_duration = src->htrack_default_duration;
|
||||||
huid = src->huid;
|
huid = src->huid;
|
||||||
hcompression = src->hcompression;
|
hcompression = src->hcompression;
|
||||||
compressor = counted_ptr<compression_c>(compression_c::create(hcompression));
|
compressor = compressor_c::create(hcompression);
|
||||||
last_cue_timecode = src->last_cue_timecode;
|
last_cue_timecode = src->last_cue_timecode;
|
||||||
correction_timecode_offset = 0;
|
correction_timecode_offset = 0;
|
||||||
if (_append_timecode_offset == -1)
|
if (_append_timecode_offset == -1)
|
||||||
|
@ -433,7 +433,7 @@ protected:
|
|||||||
int hvideo_display_width, hvideo_display_height;
|
int hvideo_display_width, hvideo_display_height;
|
||||||
|
|
||||||
compression_method_e hcompression;
|
compression_method_e hcompression;
|
||||||
counted_ptr<compression_c> compressor;
|
compressor_ptr compressor;
|
||||||
|
|
||||||
timecode_factory_c *timecode_factory;
|
timecode_factory_c *timecode_factory;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user