From 0f774fa0fd1113c651687be353c09aa70f01b1d6 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 1 Feb 2005 09:00:39 +0000 Subject: [PATCH] Made the memory_c::grab() function more useful. --- src/merge/pr_generic.cpp | 27 +++++---------------------- src/merge/pr_generic.h | 6 +++--- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/merge/pr_generic.cpp b/src/merge/pr_generic.cpp index 6c1e85775..08c47c8d3 100644 --- a/src/merge/pr_generic.cpp +++ b/src/merge/pr_generic.cpp @@ -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; diff --git a/src/merge/pr_generic.h b/src/merge/pr_generic.h index ebeff663c..027a5d1c8 100644 --- a/src/merge/pr_generic.h +++ b/src/merge/pr_generic.h @@ -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) {