mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-24 11:54:01 +00:00
Made the memory_c::grab() function more useful.
This commit is contained in:
parent
d458c26ff6
commit
0f774fa0fd
@ -832,12 +832,8 @@ generic_packetizer_c::add_packet(memory_c &mem,
|
||||
if (compressor != NULL) {
|
||||
pack->data = compressor->compress(mem.data, length);
|
||||
mem.release();
|
||||
} else if (!mem.is_free)
|
||||
pack->data = (unsigned char *)safememdup(mem.data, mem.size);
|
||||
else {
|
||||
pack->data = mem.data;
|
||||
mem.lock();
|
||||
}
|
||||
} else
|
||||
pack->data = mem.grab();
|
||||
pack->length = length;
|
||||
pack->timecode = timecode;
|
||||
pack->bref = bref;
|
||||
@ -890,23 +886,10 @@ generic_packetizer_c::add_packet(memories_c &mems,
|
||||
mems[i]->release();
|
||||
}
|
||||
} else {
|
||||
if (!mems[0]->is_free)
|
||||
pack->data = (unsigned char *)safememdup(mems[0]->data, length);
|
||||
else {
|
||||
pack->data = mems[0]->data;
|
||||
mems[0]->lock();
|
||||
}
|
||||
pack->data = mems[0]->grab();
|
||||
for (i = 1; i < mems.size(); i++) {
|
||||
if (!mems[i]->is_free) {
|
||||
add_length = mems[i]->size;
|
||||
pack->data_adds[i - 1] = (unsigned char *)safememdup(mems[i]->data,
|
||||
add_length);
|
||||
pack->data_adds_lengths[i - 1] = add_length;
|
||||
} else {
|
||||
pack->data_adds[i - 1] = mems[i]->data;
|
||||
pack->data_adds_lengths[i - 1] = mems[i]->size;
|
||||
mems[i]->lock();
|
||||
}
|
||||
pack->data_adds[i - 1] = mems[i]->grab();
|
||||
pack->data_adds_lengths[i - 1] = mems[i]->size;
|
||||
}
|
||||
}
|
||||
pack->length = length;
|
||||
|
@ -88,14 +88,14 @@ public:
|
||||
is_free = false;
|
||||
return 0;
|
||||
}
|
||||
memory_c *grab() {
|
||||
unsigned char *grab() {
|
||||
if (size == 0)
|
||||
die("memory_c::grab(): size == 0\n");
|
||||
if (is_free) {
|
||||
is_free = false;
|
||||
return new memory_c(data, size, true);
|
||||
return data;
|
||||
}
|
||||
return new memory_c((unsigned char *)safememdup(data, size), size, true);
|
||||
return (unsigned char *)safememdup(data, size);
|
||||
}
|
||||
int release() {
|
||||
if (is_free) {
|
||||
|
Loading…
Reference in New Issue
Block a user