From 807d835c2bfc5d794a74f9690d1fafbe55ff88cc Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 2 Apr 2010 14:43:05 -0500 Subject: First draft of skin weights in .mesh asset --- indra/llcommon/llsdserialize.cpp | 137 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) (limited to 'indra/llcommon/llsdserialize.cpp') diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index cf337be161..c341b15539 100644 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -39,6 +39,7 @@ #include #include "apr_base64.h" +#include "zlib/zlib.h" // for davep's dirty little zip functions #if !LL_WINDOWS #include // htonl & ntohl @@ -1989,3 +1990,139 @@ std::ostream& operator<<(std::ostream& s, const LLSD& llsd) return s; } + +//dirty little zippers -- yell at davep if these are horrid + +//return a string containing gzipped bytes of binary serialized LLSD +// VERY inefficient -- creates several copies of LLSD block in memory +std::string zip_llsd(LLSD& data) +{ + std::stringstream llsd_strm; + + LLSDSerialize::serialize(data, llsd_strm, LLSDSerialize::LLSD_BINARY); + + z_stream strm; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + + S32 ret = deflateInit(&strm, Z_BEST_COMPRESSION); + if (ret != Z_OK) + { + llwarns << "Failed to compress LLSD block." << llendl; + return std::string(); + } + + std::string source = llsd_strm.str(); + + strm.avail_in = source.size(); + strm.next_in = (U8*) source.data(); + U8* output = new U8[strm.avail_in]; + strm.avail_out = strm.avail_in; + strm.next_out = output; + ret = deflate(&strm, Z_FINISH); + if (ret != Z_STREAM_END) + { + delete [] output; + llwarns << "Failed to compress LLSD block." << llendl; + } + + std::string::size_type size = source.size()-strm.avail_out; + + std::string result((char*) output, size); + deflateEnd(&strm); + delete [] output; + + return result; +} + +//decompress a block of LLSD from provided istream +// not very efficient -- creats a copy of decompressed LLSD block in memory +// and deserializes from that copy using LLSDSerialize +bool unzip_llsd(LLSD& data, std::istream& is, S32 size) +{ + U8* result = NULL; + U32 cur_size = 0; + z_stream strm; + + const U32 CHUNK = 65536; + + U8 *in = new U8[size]; + is.read((char*) in, size); + + U8 out[CHUNK]; + + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + strm.avail_in = size; + strm.next_in = in; + + S32 ret = inflateInit(&strm); + + if (ret != Z_OK) + { + llerrs << "WTF?" << llendl; + } + + do + { + strm.avail_out = CHUNK; + strm.next_out = out; + ret = inflate(&strm, Z_NO_FLUSH); + if (ret == Z_STREAM_ERROR) + { + inflateEnd(&strm); + free(result); + delete [] in; + return false; + } + + switch (ret) + { + case Z_NEED_DICT: + ret = Z_DATA_ERROR; + case Z_DATA_ERROR: + case Z_MEM_ERROR: + inflateEnd(&strm); + free(result); + delete [] in; + return false; + break; + } + + U32 have = CHUNK-strm.avail_out; + + result = (U8*) realloc(result, cur_size + have); + memcpy(result+cur_size, out, have); + cur_size += have; + + } while (strm.avail_out == 0); + + inflateEnd(&strm); + delete [] in; + + if (ret != Z_STREAM_END) + { + free(result); + return false; + } + + //result now points to the decompressed LLSD block + { + std::string res_str((char*) result, cur_size); + std::istringstream istr(res_str); + + if (!LLSDSerialize::deserialize(data, istr, cur_size)) + { + llwarns << "Failed to unzip LLSD block" << llendl; + return false; + } + } + + free(result); + return true; +} + + + -- cgit v1.2.3 From de663d15df69aa6961f984f9f1c440f1fe2b3efb Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 6 Apr 2010 17:37:31 -0500 Subject: Cleanup from review. --- indra/llcommon/llsdserialize.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/llcommon/llsdserialize.cpp') diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index c341b15539..fdeb93e27f 100644 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -2025,6 +2025,7 @@ std::string zip_llsd(LLSD& data) { delete [] output; llwarns << "Failed to compress LLSD block." << llendl; + return std::string(); } std::string::size_type size = source.size()-strm.avail_out; @@ -2116,6 +2117,7 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size) if (!LLSDSerialize::deserialize(data, istr, cur_size)) { llwarns << "Failed to unzip LLSD block" << llendl; + free(result); return false; } } -- cgit v1.2.3 From 90e3d83a5cb35e98a02a3017dd79ebc272bbfe85 Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Tue, 21 Sep 2010 13:26:52 -0400 Subject: Fix for build failures - disabling tcmalloc for now --- indra/llcommon/llsdserialize.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 indra/llcommon/llsdserialize.cpp (limited to 'indra/llcommon/llsdserialize.cpp') diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp old mode 100644 new mode 100755 -- cgit v1.2.3 From 35c81f75ac9c134052debb21f6467012859a1fc6 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 24 Sep 2010 23:52:32 -0500 Subject: Fix for bad zipping of meshes and add mesh icon back to repository. --- indra/llcommon/llsdserialize.cpp | 53 ++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'indra/llcommon/llsdserialize.cpp') diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index fdeb93e27f..03d2b9c3fe 100755 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -2001,6 +2001,8 @@ std::string zip_llsd(LLSD& data) LLSDSerialize::serialize(data, llsd_strm, LLSDSerialize::LLSD_BINARY); + const U32 CHUNK = 65536; + z_stream strm; strm.zalloc = Z_NULL; strm.zfree = Z_NULL; @@ -2015,24 +2017,55 @@ std::string zip_llsd(LLSD& data) std::string source = llsd_strm.str(); + U8 out[CHUNK]; + strm.avail_in = source.size(); strm.next_in = (U8*) source.data(); - U8* output = new U8[strm.avail_in]; - strm.avail_out = strm.avail_in; - strm.next_out = output; - ret = deflate(&strm, Z_FINISH); - if (ret != Z_STREAM_END) + U8* output = NULL; + + U32 cur_size = 0; + + U32 have = 0; + + do { - delete [] output; - llwarns << "Failed to compress LLSD block." << llendl; - return std::string(); + strm.avail_out = CHUNK; + strm.next_out = out; + + ret = deflate(&strm, Z_FINISH); + if (ret == Z_OK || ret == Z_STREAM_END) + { //copy result into output + if (strm.avail_out >= CHUNK) + { + llerrs << "WTF?" << llendl; + } + + have = CHUNK-strm.avail_out; + output = (U8*) realloc(output, cur_size+have); + memcpy(output+cur_size, out, have); + cur_size += have; + } + else + { + free(output); + llwarns << "Failed to compress LLSD block." << llendl; + return std::string(); + } } + while (strm.avail_out == 0); - std::string::size_type size = source.size()-strm.avail_out; + std::string::size_type size = cur_size; std::string result((char*) output, size); deflateEnd(&strm); - delete [] output; + free(output); + + std::istringstream test(result); + LLSD test_sd; + if (!unzip_llsd(test_sd, test, result.size())) + { + llerrs << "Invalid compression result!" << llendl; + } return result; } -- cgit v1.2.3 From 23b4dc61893f90abd49957a9b377312012fa0161 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 29 Sep 2010 18:10:27 -0500 Subject: Fix for serialization deprecation problems. --- indra/llcommon/llsdserialize.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'indra/llcommon/llsdserialize.cpp') diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index cce3e5d16e..fe7072d01a 100644 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -1999,7 +1999,7 @@ std::string zip_llsd(LLSD& data) { std::stringstream llsd_strm; - LLSDSerialize::serialize(data, llsd_strm, LLSDSerialize::LLSD_BINARY); + LLSDSerialize::toBinary(data, llsd_strm); const U32 CHUNK = 65536; @@ -2052,7 +2052,7 @@ std::string zip_llsd(LLSD& data) return std::string(); } } - while (strm.avail_out == 0); + while (ret == Z_OK); std::string::size_type size = cur_size; @@ -2060,12 +2060,14 @@ std::string zip_llsd(LLSD& data) deflateEnd(&strm); free(output); +#if 0 //verify results work with unzip_llsd std::istringstream test(result); LLSD test_sd; if (!unzip_llsd(test_sd, test, result.size())) { llerrs << "Invalid compression result!" << llendl; } +#endif return result; } @@ -2131,7 +2133,7 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size) memcpy(result+cur_size, out, have); cur_size += have; - } while (strm.avail_out == 0); + } while (ret == Z_OK); inflateEnd(&strm); delete [] in; @@ -2145,9 +2147,18 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size) //result now points to the decompressed LLSD block { std::string res_str((char*) result, cur_size); - std::istringstream istr(res_str); - if (!LLSDSerialize::deserialize(data, istr, cur_size)) + std::string deprecated_header(""); + + if (res_str.substr(0, deprecated_header.size()) == deprecated_header) + { + res_str = res_str.substr(deprecated_header.size()+1, cur_size); + } + cur_size = res_str.size(); + + std::istringstream istr(res_str); + + if (!LLSDSerialize::fromBinary(data, istr, cur_size)) { llwarns << "Failed to unzip LLSD block" << llendl; free(result); -- cgit v1.2.3 From a5619d16f74863168f45b04b37cc6383e1a92263 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Wed, 13 Oct 2010 07:24:37 -0400 Subject: correct licenses (fix problem with license change merge) --- indra/llcommon/llsdserialize.cpp | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'indra/llcommon/llsdserialize.cpp') diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index fe7072d01a..67cc707a01 100644 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -4,31 +4,25 @@ * @date 2006-03-05 * @brief Implementation of LLSD parsers and formatters * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2009, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at - * http://secondlifegrid.net/programs/open_source/licensing/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -- cgit v1.2.3 From 6b9a2d24cce8efaa72c2fd60655998844394312d Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 30 Mar 2011 18:38:22 -0500 Subject: SH-477 Better mesh streaming cost estimation. --- indra/llcommon/llsdserialize.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'indra/llcommon/llsdserialize.cpp') diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index f3cbfab77a..5be5ecc492 100644 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -2095,11 +2095,6 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size) S32 ret = inflateInit(&strm); - if (ret != Z_OK) - { - llerrs << "WTF?" << llendl; - } - do { strm.avail_out = CHUNK; -- cgit v1.2.3