Made the memory_c::grab() function more useful.

This commit is contained in:
Moritz Bunkus 2005-02-01 09:00:39 +00:00
parent d458c26ff6
commit 0f774fa0fd
2 changed files with 8 additions and 25 deletions

View File

@ -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;

View File

@ -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) {