From abf872eeb3d7a7b4102ffc287aaf5ab3c1ca0912 Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Mon, 6 Jul 2009 18:03:42 +0200 Subject: [PATCH 001/166] Fix for bug 502617 (Crash when logging in to Facebook [@ JS_GetClass]). r/sr=smaug. --- dom/base/nsDOMClassInfo.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index fa1d930d0eb..a39814ce1e5 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -5409,7 +5409,12 @@ nsDOMConstructor::HasInstance(nsIXPConnectWrappedNative *wrapper, // This might not be the right object, if XPCNativeWrapping // happened. Get the wrapped native for this object, then get its // JS object. - nsContentUtils::XPConnect()->GetJSObjectOfWrapper(cx, dom_obj, &dom_obj); + JSObject *wrapped_obj; + nsresult rv = nsContentUtils::XPConnect()->GetJSObjectOfWrapper(cx, dom_obj, + &wrapped_obj); + if (NS_SUCCEEDED(rv)) { + dom_obj = wrapped_obj; + } JSClass *dom_class = JS_GET_CLASS(cx, dom_obj); if (!dom_class) { @@ -5418,8 +5423,7 @@ nsDOMConstructor::HasInstance(nsIXPConnectWrappedNative *wrapper, } const nsGlobalNameStruct *name_struct; - nsresult rv = GetNameStruct(NS_ConvertASCIItoUTF16(dom_class->name), - &name_struct); + rv = GetNameStruct(NS_ConvertASCIItoUTF16(dom_class->name), &name_struct); if (!name_struct) { return rv; } From 52826bd8296ddbb1187c805970b488cd0918d9b6 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Mon, 6 Jul 2009 18:13:57 +0200 Subject: [PATCH 002/166] bug 498500 - Mac DMG unpackaging is unreliable, r=ted --- build/package/mac_osx/installdmg.ex | 44 ------------- build/package/mac_osx/unpack-diskimage | 88 ++++++++++++++++++++++++++ toolkit/mozapps/installer/packager.mk | 24 +++---- 3 files changed, 97 insertions(+), 59 deletions(-) delete mode 100644 build/package/mac_osx/installdmg.ex create mode 100755 build/package/mac_osx/unpack-diskimage diff --git a/build/package/mac_osx/installdmg.ex b/build/package/mac_osx/installdmg.ex deleted file mode 100644 index 447ebc27781..00000000000 --- a/build/package/mac_osx/installdmg.ex +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/expect -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is Mozilla Corporation Code. -# -# The Initial Developer of the Original Code is -# Clint Talbert. -# Portions created by the Initial Developer are Copyright (C) 2007 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Armen Zambrano Gasparnian -# Axel Hecht -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** -spawn hdiutil attach -readonly -mountroot /tmp -private -noautoopen $argv -expect { -"byte" {send "G"; exp_continue} -"END" {send "\r"; exp_continue} -"Y/N?" {send "Y\r"; exp_continue} -} diff --git a/build/package/mac_osx/unpack-diskimage b/build/package/mac_osx/unpack-diskimage new file mode 100755 index 00000000000..200d1c3ef91 --- /dev/null +++ b/build/package/mac_osx/unpack-diskimage @@ -0,0 +1,88 @@ +#!/bin/bash +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is the installdmg.sh script from taols utilities +# +# The Initial Developer of the Original Code is +# Mozilla Corporation. +# Portions created by the Initial Developer are Copyright (C) 2009 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Chris AtLee +# Robert Kaiser +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +# Unpack a disk image to a specified target folder +# +# Usage: unpack-diskimage +# +# + +DMG_PATH=$1 +MOUNTPOINT=$2 +TARGETPATH=$3 + +# How long to wait before giving up waiting for the mount to finish (seconds) +TIMEOUT=90 + +# If mnt already exists, then the previous run may not have cleaned up +# properly. We should try to umount and remove the mnt directory. +if [ -d $MOUNTPOINT ]; then + echo "mnt already exists, trying to clean up" + hdiutil detach $MOUNTPOINT -force + rm -rdfv $MOUNTPOINT +fi + +# Install an on-exit handler that will unmount and remove the '$MOUNTPOINT' directory +trap "{ if [ -d $MOUNTPOINT ]; then hdiutil detach $MOUNTPOINT -force; rm -rdfv $MOUNTPOINT; fi; }" EXIT + +mkdir -p $MOUNTPOINT + +hdiutil attach -verbose -noautoopen -mountpoint $MOUNTPOINT "$DMG_PATH" +# Wait for files to show up +# hdiutil uses a helper process, diskimages-helper, which isn't always done its +# work by the time hdiutil exits. So we wait until something shows up in the +# mnt directory. Due to the async nature of diskimages-helper, the best thing +# we can do is to make sure the glob() rsync is making can find files. +i=0 +while [ "$(echo $MOUNTPOINT/*)" == "$MOUNTPOINT/*" ]; do + if [ $i -gt $TIMEOUT ]; then + echo "No files found, exiting" + exit 1 + fi + sleep 1 + i=$(expr $i + 1) +done +# Now we can copy everything out of the $MOUNTPOINT directory into the target directory +rsync -av $MOUNTPOINT/* $MOUNTPOINT/.DS_Store $MOUNTPOINT/.background $MOUNTPOINT/.VolumeIcon.icns $TARGETPATH/. +hdiutil detach $MOUNTPOINT +rm -rdf $MOUNTPOINT +# diskimage-helper prints messages to stdout asynchronously as well, sleep +# for a bit to ensure they don't disturb following commands in a script that +# might parse stdout messages +sleep 5 diff --git a/toolkit/mozapps/installer/packager.mk b/toolkit/mozapps/installer/packager.mk index 65bad62e1c0..7a266d31688 100644 --- a/toolkit/mozapps/installer/packager.mk +++ b/toolkit/mozapps/installer/packager.mk @@ -151,26 +151,20 @@ endif MAKE_PACKAGE = $(_ABS_MOZSRCDIR)/build/package/mac_osx/pkg-dmg \ --source "$(PKG_DMG_SOURCE)" --target "$(PACKAGE)" \ --volname "$(MOZ_APP_DISPLAYNAME)" $(PKG_DMG_FLAGS) +_ABS_DIST = $(call core_abspath,$(DIST)) UNMAKE_PACKAGE = \ set -ex; \ - function cleanup() { \ - hdiutil detach $${DEV_NAME} || \ - { sleep 5 && hdiutil detach $${DEV_NAME} -force; }; \ - return $$1 && $$?; \ - }; \ - unset NEXT_ROOT; \ - export PAGER=true; \ - expect $(_ABS_MOZSRCDIR)/build/package/mac_osx/installdmg.ex $(UNPACKAGE) | tee hdi.output; \ - DEV_NAME=`perl -n -e 'if($$_=~/(\/dev\/disk[^ ]*)/) {print $$1."\n";exit;}'< hdi.output`; \ - MOUNTPOINT=`perl -n -e 'split(/\/dev\/disk[^ ]*/,$$_,2);if($$_[1]=~/(\/.[^\r]*)/) {print $$1;exit;}'< hdi.output` || cleanup 1; \ - rsync -a "$${MOUNTPOINT}/$(_APPNAME)" $(MOZ_PKG_DIR) || cleanup 1; \ + rm -rf $(_ABS_DIST)/unpack.tmp; \ + mkdir -p $(_ABS_DIST)/unpack.tmp; \ + $(_ABS_MOZSRCDIR)/build/package/mac_osx/unpack-diskimage $(UNPACKAGE) /tmp/$(MOZ_PKG_APPNAME)-unpack $(_ABS_DIST)/unpack.tmp; \ + rsync -a "$(_ABS_DIST)/unpack.tmp/$(_APPNAME)" $(MOZ_PKG_DIR); \ test -n "$(MOZ_PKG_MAC_DSSTORE)" && \ - { rsync -a "$${MOUNTPOINT}/.DS_Store" "$(MOZ_PKG_MAC_DSSTORE)" || cleanup 1; }; \ + rsync -a "$(_ABS_DIST)/unpack.tmp/.DS_Store" "$(MOZ_PKG_MAC_DSSTORE)"; \ test -n "$(MOZ_PKG_MAC_BACKGROUND)" && \ - { rsync -a "$${MOUNTPOINT}/.background/`basename "$(MOZ_PKG_MAC_BACKGROUND)"`" "$(MOZ_PKG_MAC_BACKGROUND)" || cleanup 1; }; \ + rsync -a "$(_ABS_DIST)/unpack.tmp/.background/`basename "$(MOZ_PKG_MAC_BACKGROUND)"`" "$(MOZ_PKG_MAC_BACKGROUND)"; \ test -n "$(MOZ_PKG_MAC_ICON)" && \ - { rsync -a "$${MOUNTPOINT}/.VolumeIcon.icns" "$(MOZ_PKG_MAC_ICON)" || cleanup 1; }; \ - cleanup 0; \ + rsync -a "$(_ABS_DIST)/unpack.tmp/.VolumeIcon.icns" "$(MOZ_PKG_MAC_ICON)"; \ + rm -rf $(_ABS_DIST)/unpack.tmp; \ if test -n "$(MOZ_PKG_MAC_RSRC)" ; then \ cp $(UNPACKAGE) $(MOZ_PKG_APPNAME).tmp.dmg && \ hdiutil unflatten $(MOZ_PKG_APPNAME).tmp.dmg && \ From de81a851f52a6bd42bf4a9bd8005e3cd6c931201 Mon Sep 17 00:00:00 2001 From: Mark Finkle Date: Mon, 6 Jul 2009 15:20:10 -0400 Subject: [PATCH 003/166] Bug 499852: up network thread priority on Windows CE, r=vlad, sr=biesi --- netwerk/base/src/nsSocketTransportService2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netwerk/base/src/nsSocketTransportService2.cpp b/netwerk/base/src/nsSocketTransportService2.cpp index 64dd8bb1832..cda54fa0063 100644 --- a/netwerk/base/src/nsSocketTransportService2.cpp +++ b/netwerk/base/src/nsSocketTransportService2.cpp @@ -560,7 +560,7 @@ nsSocketTransportService::Run() gSocketThread = PR_GetCurrentThread(); #ifdef WINCE - SetThreadPriority(GetCurrentThread(), 116); + CeSetThreadPriority(GetCurrentThread(), 116); #endif // add thread event to poll list (mThreadEvent may be NULL) From 9f99b401d678876d61359525529a37fdabfcaf1e Mon Sep 17 00:00:00 2001 From: Serge Gautherie Date: Mon, 6 Jul 2009 22:01:37 +0200 Subject: [PATCH 004/166] Bug 430112 - : 2 "warning: unused variable status"; (Bv1) Split the init to 2 instructions; r=benjamin --- xpcom/glue/nsAutoLock.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xpcom/glue/nsAutoLock.cpp b/xpcom/glue/nsAutoLock.cpp index d310152cc57..21d424c9e1c 100644 --- a/xpcom/glue/nsAutoLock.cpp +++ b/xpcom/glue/nsAutoLock.cpp @@ -450,7 +450,9 @@ void nsAutoMonitor::Exit() } (void) PR_SetThreadPrivate(LockStackTPI, mDown); #endif - PRStatus status = PR_ExitMonitor(mMonitor); + // Split 'status' init to avoid an "unused variable" compiler warning. + PRStatus status; + status = PR_ExitMonitor(mMonitor); NS_ASSERTION(status == PR_SUCCESS, "PR_ExitMonitor failed"); mLockCount -= 1; } @@ -477,7 +479,9 @@ void nsAutoCMonitor::Exit() #ifdef DEBUG (void) PR_SetThreadPrivate(LockStackTPI, mDown); #endif - PRStatus status = PR_CExitMonitor(mLockObject); + // Split 'status' init to avoid an "unused variable" compiler warning. + PRStatus status; + status = PR_CExitMonitor(mLockObject); NS_ASSERTION(status == PR_SUCCESS, "PR_CExitMonitor failed"); mLockCount -= 1; } From ba55c5e88422b7847ba5d317e67afd119518609f Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Mon, 6 Jul 2009 22:09:39 +0200 Subject: [PATCH 005/166] Bug 136936 - TestInterfaceInfo is out of date - nsIServiceManager; r=benjamin --- .../xptinfo/tests/TestInterfaceInfo.cpp | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/xpcom/reflect/xptinfo/tests/TestInterfaceInfo.cpp b/xpcom/reflect/xptinfo/tests/TestInterfaceInfo.cpp index c8715defe04..7fb2280e8f2 100644 --- a/xpcom/reflect/xptinfo/tests/TestInterfaceInfo.cpp +++ b/xpcom/reflect/xptinfo/tests/TestInterfaceInfo.cpp @@ -97,14 +97,14 @@ int main (int argc, char **argv) { fprintf(stderr, "\nparams work?\n"); fprintf(stderr, "\ngetting info for name 'nsIServiceManager'\n"); - iim->GetInfoForName("nsIServiceManager", &info5); + iim->GetInfoForName("nsIComponentManager", &info5); #ifdef DEBUG // ((nsInterfaceInfo *)info5)->print(stderr); #endif // XXX: nsIServiceManager is no more; what do we test with? if (info5 == NULL) { - fprintf(stderr, "\nNo nsIServiceManager; cannot continue.\n"); + fprintf(stderr, "\nNo nsIComponentManager; cannot continue.\n"); return 1; } @@ -116,32 +116,39 @@ int main (int argc, char **argv) { fprintf(stderr, "method %d, name %s\n", i, mi->GetName()); } - // 7 is GetServiceWithListener, which has juicy params. - info5->GetMethodInfo(7, &mi); -// uint8 paramcount = mi->GetParamCount(); + // 4 is getServiceByContractID, which has juicy params. + info5->GetMethodInfo(6, &mi); - nsXPTParamInfo param2 = mi->GetParam(2); - // should be IID for nsIShutdownListener + const nsXPTParamInfo& param2 = mi->GetParam(1); + // should be IID for the service nsIID *nsISL; - info5->GetIIDForParam(7, ¶m2, &nsISL); -// const nsIID *nsISL = param2.GetInterfaceIID(info5); - fprintf(stderr, "iid assoc'd with param 2 of method 7 of GetServiceWithListener - %s\n", nsISL->ToString()); + info5->GetIIDForParam(6, ¶m2, &nsISL); + fprintf(stderr, "iid assoc'd with param 1 of method 6 - createInstanceByContractID - %s\n", nsISL->ToString()); // if we look up the name? char *nsISLname; iim->GetNameForIID(nsISL, &nsISLname); fprintf(stderr, "which is called %s\n", nsISLname); - fprintf(stderr, "\nhow about one defined in a different typelib\n"); - nsXPTParamInfo param3 = mi->GetParam(3); - // should be IID for nsIShutdownListener - nsIID *nsISS; - info5->GetIIDForParam(7, ¶m3, &nsISS); -// const nsIID *nsISS = param3.GetInterfaceIID(info5); - fprintf(stderr, "iid assoc'd with param 3 of method 7 of GetServiceWithListener - %s\n", nsISS->ToString()); - // if we look up the name? - char *nsISSname; - iim->GetNameForIID(nsISS, &nsISSname); - fprintf(stderr, "which is called %s\n", nsISSname); + fprintf(stderr, "\nNow check the last param\n"); + const nsXPTParamInfo& param3 = mi->GetParam(3); + + if (param3.GetType().TagPart() != nsXPTType::T_INTERFACE_IS) { + fprintf(stderr, "Param 3 is not type interface is\n"); + // Not returning an error, because this could legitamately change + } + // lets see what arg this refers to + uint8 argnum; + info5->GetInterfaceIsArgNumberForParam(6, ¶m3, &argnum); + fprintf(stderr, "param 3 referrs to param %d of method 6 - createInstanceByContractID\n", (PRUint32)argnum); + // Get the type of the parameter referred to + const nsXPTParamInfo& arg_param = mi->GetParam(argnum); + const nsXPTType& arg_type = arg_param.GetType(); + // Check to make sure it refers to the proper param + if(!arg_type.IsPointer() || arg_type.TagPart() != nsXPTType::T_IID) { + fprintf(stderr, "Param 3 of method 6 refers to a non IID parameter\n"); + // Not returning an error, because this could legitamately change + } + return 0; } From 39dbda8899b184c132d0bd079555df539dc18c7b Mon Sep 17 00:00:00 2001 From: Steven Michaud Date: Mon, 6 Jul 2009 15:59:46 -0500 Subject: [PATCH 006/166] Stop nsMenuItemIconX object from possibly outliving its nsMenuObjectX owner. b=499600 r=josh --- widget/src/cocoa/nsMenuItemIconX.h | 10 ++++++++-- widget/src/cocoa/nsMenuItemIconX.mm | 18 ++++++++++++++++++ widget/src/cocoa/nsMenuItemX.mm | 4 ++++ widget/src/cocoa/nsMenuX.mm | 4 ++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/widget/src/cocoa/nsMenuItemIconX.h b/widget/src/cocoa/nsMenuItemIconX.h index 4be98534a50..ee203ab5b35 100644 --- a/widget/src/cocoa/nsMenuItemIconX.h +++ b/widget/src/cocoa/nsMenuItemIconX.h @@ -79,13 +79,19 @@ public: // icon. The request may not complete until after LoadIcon returns. nsresult LoadIcon(nsIURI* aIconURI); + // Unless we take precautions, we may outlive the object that created us + // (mMenuObject, which owns our native menu item (mNativeMenuItem)). + // Destroy() should be called from mMenuObject's destructor to prevent + // this from happening. See bug 499600. + void Destroy(); + protected: nsCOMPtr mContent; nsCOMPtr mIconRequest; - nsMenuObjectX* mMenuObject; + nsMenuObjectX* mMenuObject; // [weak] PRPackedBool mLoadedIcon; PRPackedBool mSetIcon; - NSMenuItem* mNativeMenuItem; + NSMenuItem* mNativeMenuItem; // [weak] }; #endif // nsMenuItemIconX_h_ diff --git a/widget/src/cocoa/nsMenuItemIconX.mm b/widget/src/cocoa/nsMenuItemIconX.mm index 700970f4ec7..175928999c8 100644 --- a/widget/src/cocoa/nsMenuItemIconX.mm +++ b/widget/src/cocoa/nsMenuItemIconX.mm @@ -97,6 +97,19 @@ nsMenuItemIconX::~nsMenuItemIconX() mIconRequest->CancelAndForgetObserver(NS_BINDING_ABORTED); } +// Called from mMenuObjectX's destructor, to prevent us from outliving it +// (as might otherwise happen if calls to our imgIDecoderObserver methods +// are still outstanding). mMenuObjectX owns our nNativeMenuItem. +void nsMenuItemIconX::Destroy() +{ + if (mIconRequest) { + mIconRequest->CancelAndForgetObserver(NS_BINDING_ABORTED); + mIconRequest = nsnull; + } + mMenuObject = nsnull; + mNativeMenuItem = nil; +} + nsresult nsMenuItemIconX::SetupIcon() { @@ -126,6 +139,9 @@ nsMenuItemIconX::SetupIcon() nsresult nsMenuItemIconX::GetIconURI(nsIURI** aIconURI) { + if (!mMenuObject) + return NS_ERROR_FAILURE; + // Mac native menu items support having both a checkmark and an icon // simultaneously, but this is unheard of in the cross-platform toolkit, // seemingly because the win32 theme is unable to cope with both at once. @@ -320,6 +336,8 @@ nsMenuItemIconX::OnStopFrame(imgIRequest* aRequest, if (mLoadedIcon) return NS_OK; + if (!mNativeMenuItem) return NS_ERROR_FAILURE; + nsCOMPtr frame = aFrame; nsCOMPtr image = do_GetInterface(frame); if (!image) return NS_ERROR_FAILURE; diff --git a/widget/src/cocoa/nsMenuItemX.mm b/widget/src/cocoa/nsMenuItemX.mm index f6577dc2dca..290712eb1ae 100644 --- a/widget/src/cocoa/nsMenuItemX.mm +++ b/widget/src/cocoa/nsMenuItemX.mm @@ -72,6 +72,10 @@ nsMenuItemX::~nsMenuItemX() { NS_OBJC_BEGIN_TRY_ABORT_BLOCK; + // Prevent the icon object from outliving us. + if (mIcon) + mIcon->Destroy(); + // autorelease the native menu item so that anything else happening to this // object happens before the native menu item actually dies [mNativeMenuItem autorelease]; diff --git a/widget/src/cocoa/nsMenuX.mm b/widget/src/cocoa/nsMenuX.mm index 734d5935d62..36f0d2573bd 100644 --- a/widget/src/cocoa/nsMenuX.mm +++ b/widget/src/cocoa/nsMenuX.mm @@ -117,6 +117,10 @@ nsMenuX::~nsMenuX() { NS_OBJC_BEGIN_TRY_ABORT_BLOCK; + // Prevent the icon object from outliving us. + if (mIcon) + mIcon->Destroy(); + RemoveAll(); [mNativeMenu setDelegate:nil]; From 4cc2512ac85c39a303001a52713be2d9370113d3 Mon Sep 17 00:00:00 2001 From: Johnny Stenback Date: Mon, 6 Jul 2009 13:56:18 -0700 Subject: [PATCH 007/166] Fixing bug 502137. Removing dead code relating to plugin scripting, and updating some comments. r+sr=mrbkap@gmail.com --HG-- extra : rebase_source : 2101080c410c9656cdbfc4503479470545c9f351 --- dom/base/nsDOMClassInfo.cpp | 140 +++--------------------------------- dom/base/nsDOMClassInfo.h | 8 --- 2 files changed, 9 insertions(+), 139 deletions(-) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index a39814ce1e5..2e7603dc0db 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -9273,12 +9273,6 @@ nsHTMLSelectElementSH::SetProperty(nsIXPConnectWrappedNative *wrapper, // HTMLObject/EmbedElement helper -// This resolve hook makes embed.nsIFoo work as if -// QueryInterface(Components.interfaces.nsIFoo) was called on the -// plugin instance, the result of calling QI, assuming it's -// successful, will be defined on the embed element as a nsIFoo -// property. - // static nsresult nsHTMLPluginObjElementSH::GetPluginInstanceIfSafe(nsIXPConnectWrappedNative *wrapper, @@ -9452,32 +9446,14 @@ nsHTMLPluginObjElementSH::SetupProtoChain(nsIXPConnectWrappedNative *wrapper, // | // |__ xpc wrapped native embed node // - // pi.__proto__.__proto__ - // ^ ^ ^ - // | | |__ Object.prototype - // | | - // | |__ plugin proto (not shared in the xpc wrapper case) + // pi.__proto__ + // ^ ^ + // | |__ Object.prototype // | - // |__ xpc wrapped native pi (plugin instance) + // |__ Plugin NPRuntime JS object wrapper // // Now, after the above prototype setup the prototype chain should - // look like this if the plugin had a proto (other than - // Object.prototype): - // - // this.__proto__.__proto__.__proto__.__proto__ - // ^ ^ ^ ^ ^ - // | | | | |__ Object.prototype - // | | | | - // | | | |__ xpc embed wrapper proto (shared) - // | | | - // | | |__ plugin proto (not shared in the xpc wrapper case) - // | | - // | |__ xpc wrapped native pi (plugin instance) - // | - // |__ xpc wrapped native embed node - // - // If the plugin's proto was Object.prototype, the prototype chain - // should look like this: + // look like this: // // this.__proto__.__proto__.__proto__ // ^ ^ ^ ^ @@ -9485,7 +9461,7 @@ nsHTMLPluginObjElementSH::SetupProtoChain(nsIXPConnectWrappedNative *wrapper, // | | | // | | |__ xpc embed wrapper proto (shared) // | | - // | |__ pi (plugin instance) NPRuntime JS object wrapper + // | |__ Plugin NPRuntime JS object wrapper // | // |__ xpc wrapped native embed node // @@ -9633,9 +9609,9 @@ nsHTMLPluginObjElementSH::Call(nsIXPConnectWrappedNative *wrapper, nsresult rv = GetPluginInstanceIfSafe(wrapper, obj, getter_AddRefs(pi)); NS_ENSURE_SUCCESS(rv, rv); - if (!pi) { - // No plugin around for this object. - + // If obj is a native wrapper, or if there's no plugin around for + // this object, throw. + if (!ObjectIsNativeWrapper(cx, obj) || !pi) { return NS_ERROR_NOT_AVAILABLE; } @@ -9660,21 +9636,6 @@ nsHTMLPluginObjElementSH::Call(nsIXPConnectWrappedNative *wrapper, } -// HTMLAppletElement helper - -// static -nsresult -nsHTMLPluginObjElementSH::GetJavaPluginJSObject(JSContext *cx, JSObject *obj, - nsIPluginInstance *plugin_inst, - JSObject **plugin_obj, - JSObject **plugin_proto) -{ - return NS_OK; -} - - -// HTMLEmbed/ObjectElement helper - nsresult nsHTMLPluginObjElementSH::GetPluginJSObject(JSContext *cx, JSObject *obj, nsIPluginInstance *plugin_inst, @@ -9696,89 +9657,6 @@ nsHTMLPluginObjElementSH::GetPluginJSObject(JSContext *cx, JSObject *obj, return NS_OK; } -NS_IMETHODIMP -nsHTMLPluginObjElementSH::NewResolve(nsIXPConnectWrappedNative *wrapper, - JSContext *cx, JSObject *obj, jsval id, - PRUint32 flags, JSObject **objp, - PRBool *_retval) -{ - if (!JSVAL_IS_STRING(id)) { - return NS_OK; - } - - // This code resolves embed.nsIFoo to the nsIFoo wrapper of the - // plugin/applet instance. We only want to do that for plugin - // instances that are not scriptable using NPRuntime or are Java - // plugin instances. - - nsCOMPtr pi; - nsresult rv = GetPluginInstanceIfSafe(wrapper, obj, getter_AddRefs(pi)); - NS_ENSURE_SUCCESS(rv, rv); - - // Bail if we don't have a plugin instance or this is an NPRuntime or Java - // plugin since the following code is only useful for XPCOM plugins. - JSObject *jsobj; - if (pi) - pi->GetJSObject(cx, &jsobj); - if (!pi || jsobj) { - return nsHTMLElementSH::NewResolve(wrapper, cx, obj, id, flags, objp, - _retval); - } - - JSObject *proto = ::JS_GetPrototype(cx, obj); - - if (!proto || strcmp(STOBJ_GET_CLASS(proto)->name, NPRUNTIME_JSCLASS_NAME)) { - // This is not an NPRuntime plugin or Java plugin, continue on... - - JSString *str = JSVAL_TO_STRING(id); - char* cstring = ::JS_GetStringBytes(str); - - nsCOMPtr - iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID)); - NS_ENSURE_TRUE(iim, NS_ERROR_UNEXPECTED); - - nsIID* iid = nsnull; - - nsresult rv = iim->GetIIDForName(cstring, &iid); - - if (NS_SUCCEEDED(rv) && iid) { - // Notify the PluginHost that this one is scriptable -- it - // will need some special treatment later - - nsCOMPtr pluginHost = do_GetService(MOZ_PLUGIN_HOST_CONTRACTID); - if (pluginHost) - pluginHost->SetIsScriptableInstance(pi, PR_TRUE); - - nsCOMPtr holder; - rv = sXPConnect->WrapNative(cx, obj, pi, *iid, getter_AddRefs(holder)); - - if (NS_SUCCEEDED(rv)) { - JSObject* ifaceObj; - - rv = holder->GetJSObject(&ifaceObj); - - if (NS_SUCCEEDED(rv)) { - nsMemory::Free(iid); - - *_retval = ::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str), - ::JS_GetStringLength(str), - OBJECT_TO_JSVAL(ifaceObj), nsnull, - nsnull, JSPROP_ENUMERATE); - - *objp = obj; - - return *_retval ? NS_OK : NS_ERROR_FAILURE; - } - } - } - - nsMemory::Free(iid); - } - - return nsHTMLElementSH::NewResolve(wrapper, cx, obj, id, flags, objp, - _retval); -} - // HTMLOptionsCollection helper diff --git a/dom/base/nsDOMClassInfo.h b/dom/base/nsDOMClassInfo.h index 532900fea4b..9a71ab3bb30 100644 --- a/dom/base/nsDOMClassInfo.h +++ b/dom/base/nsDOMClassInfo.h @@ -1089,15 +1089,7 @@ protected: JSObject **plugin_obj, JSObject **plugin_proto); - static nsresult GetJavaPluginJSObject(JSContext *cx, JSObject *obj, - nsIPluginInstance *plugin_inst, - JSObject **plugin_obj, - JSObject **plugin_proto); - public: - NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj, jsval id, PRUint32 flags, - JSObject **objp, PRBool *_retval); NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj, JSObject **parentObj); NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, From 523bba425640690aa9f93f76c88090b99f9b8edc Mon Sep 17 00:00:00 2001 From: Johnny Stenback Date: Mon, 6 Jul 2009 14:00:23 -0700 Subject: [PATCH 008/166] Fixing bug 501725. Use nsDependentSubstring() on strings that are not null terminated. r+sr=mrbkap@gmail.com --HG-- extra : rebase_source : 7f657cd0465c3a568f6cfc534d6fbd4876e0776d --- parser/html/nsHtml5Portability.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser/html/nsHtml5Portability.cpp b/parser/html/nsHtml5Portability.cpp index 2340b87850d..ed6871d4554 100644 --- a/parser/html/nsHtml5Portability.cpp +++ b/parser/html/nsHtml5Portability.cpp @@ -121,7 +121,7 @@ nsHtml5Portability::releaseElement(nsIContent* element) PRBool nsHtml5Portability::localEqualsBuffer(nsIAtom* local, PRUnichar* buf, PRInt32 offset, PRInt32 length) { - return local->Equals(nsDependentString(buf + offset, buf + offset + length)); + return local->Equals(nsDependentSubstring(buf + offset, buf + offset + length)); } PRBool From c4f6146af5f32110dd32e3d01d676e7328a76047 Mon Sep 17 00:00:00 2001 From: Johnny Stenback Date: Mon, 6 Jul 2009 14:01:45 -0700 Subject: [PATCH 009/166] Fixing bug 501531. Make some functions static. r+sr=mrbkap@gmail.com --HG-- extra : rebase_source : ef972db0100f2856724af0c9a958cada10a8e2c4 --- js/src/xpconnect/src/xpccomponents.cpp | 58 +++++++++++++------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/js/src/xpconnect/src/xpccomponents.cpp b/js/src/xpconnect/src/xpccomponents.cpp index 50b63b90ab5..969e3f2ab6f 100644 --- a/js/src/xpconnect/src/xpccomponents.cpp +++ b/js/src/xpconnect/src/xpccomponents.cpp @@ -1532,10 +1532,10 @@ public: virtual ~nsXPCComponents_ID(); private: - NS_METHOD CallOrConstruct(nsIXPConnectWrappedNative *wrapper, - JSContext * cx, JSObject * obj, - PRUint32 argc, jsval * argv, - jsval * vp, PRBool *_retval); + static nsresult CallOrConstruct(nsIXPConnectWrappedNative *wrapper, + JSContext * cx, JSObject * obj, + PRUint32 argc, jsval * argv, + jsval * vp, PRBool *_retval); }; /***************************************************************************/ @@ -1675,7 +1675,8 @@ nsXPCComponents_ID::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval); } -NS_METHOD +// static +nsresult nsXPCComponents_ID::CallOrConstruct(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, PRUint32 argc, jsval * argv, @@ -1759,10 +1760,10 @@ public: virtual ~nsXPCComponents_Exception(); private: - NS_METHOD CallOrConstruct(nsIXPConnectWrappedNative *wrapper, - JSContext * cx, JSObject * obj, - PRUint32 argc, jsval * argv, - jsval * vp, PRBool *_retval); + static nsresult CallOrConstruct(nsIXPConnectWrappedNative *wrapper, + JSContext * cx, JSObject * obj, + PRUint32 argc, jsval * argv, + jsval * vp, PRBool *_retval); }; /***************************************************************************/ @@ -1902,7 +1903,8 @@ nsXPCComponents_Exception::Construct(nsIXPConnectWrappedNative *wrapper, JSConte return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval); } -NS_METHOD +// static +nsresult nsXPCComponents_Exception::CallOrConstruct(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, PRUint32 argc, jsval * argv, @@ -2048,10 +2050,10 @@ public: virtual ~nsXPCConstructor(); private: - NS_METHOD CallOrConstruct(nsIXPConnectWrappedNative *wrapper, - JSContext * cx, JSObject * obj, - PRUint32 argc, jsval * argv, - jsval * vp, PRBool *_retval); + nsresult CallOrConstruct(nsIXPConnectWrappedNative *wrapper, + JSContext * cx, JSObject * obj, + PRUint32 argc, jsval * argv, + jsval * vp, PRBool *_retval); private: nsIJSCID* mClassID; nsIJSIID* mInterfaceID; @@ -2227,7 +2229,8 @@ nsXPCConstructor::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx, return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval); } -NS_METHOD +// static +nsresult nsXPCConstructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, PRUint32 argc, jsval * argv, @@ -2317,10 +2320,10 @@ public: virtual ~nsXPCComponents_Constructor(); private: - NS_METHOD CallOrConstruct(nsIXPConnectWrappedNative *wrapper, - JSContext * cx, JSObject * obj, - PRUint32 argc, jsval * argv, - jsval * vp, PRBool *_retval); + static nsresult CallOrConstruct(nsIXPConnectWrappedNative *wrapper, + JSContext * cx, JSObject * obj, + PRUint32 argc, jsval * argv, + jsval * vp, PRBool *_retval); }; /***************************************************************************/ @@ -2459,7 +2462,8 @@ nsXPCComponents_Constructor::Construct(nsIXPConnectWrappedNative *wrapper, JSCon return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval); } -NS_METHOD +// static +nsresult nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, PRUint32 argc, jsval * argv, @@ -2658,13 +2662,10 @@ public: virtual ~nsXPCComponents_utils_Sandbox(); private: - // XXXjst: This method (and other CallOrConstruct()'s in this - // file) doesn't need to be virtual, could even be a static - // method! - NS_METHOD CallOrConstruct(nsIXPConnectWrappedNative *wrapper, - JSContext * cx, JSObject * obj, - PRUint32 argc, jsval * argv, - jsval * vp, PRBool *_retval); + static nsresult CallOrConstruct(nsIXPConnectWrappedNative *wrapper, + JSContext * cx, JSObject * obj, + PRUint32 argc, jsval * argv, + jsval * vp, PRBool *_retval); }; class nsXPCComponents_Utils : @@ -3301,7 +3302,8 @@ nsXPCComponents_utils_Sandbox::Construct(nsIXPConnectWrappedNative *wrapper, return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval); } -NS_IMETHODIMP +// static +nsresult nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, PRUint32 argc, jsval * argv, From 6eebedacb5aecb61d460b7259da46424dfee49aa Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Tue, 7 Jul 2009 07:22:42 +0900 Subject: [PATCH 010/166] =?UTF-8?q?Bug=20502503=20=E2=80=93=20Components.r?= =?UTF-8?q?esult=20should=20be=20Components.results=20in=20nsXULAppInstall?= =?UTF-8?q?.js;=20r=3Dbenjamin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xulrunner/setup/nsXULAppInstall.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xulrunner/setup/nsXULAppInstall.js b/xulrunner/setup/nsXULAppInstall.js index c467e17f5bd..76a27fbee94 100644 --- a/xulrunner/setup/nsXULAppInstall.js +++ b/xulrunner/setup/nsXULAppInstall.js @@ -213,7 +213,7 @@ const AppInstall = { iid.equals(nsISupports)) return this; - throw Components.result.NS_ERROR_NO_INTERFACE; + throw Components.results.NS_ERROR_NO_INTERFACE; }, /* nsIXULAppInstall */ From 631190e88b84e4787956bf2573c02471e29f1a0d Mon Sep 17 00:00:00 2001 From: Nick Kreeger Date: Mon, 6 Jul 2009 15:31:23 -0700 Subject: [PATCH 011/166] Fixing bug 502723 - updater checks the wrong MAX_PATH define. Patch my Mook . r=robstrong. --- toolkit/mozapps/update/src/updater/updater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolkit/mozapps/update/src/updater/updater.cpp b/toolkit/mozapps/update/src/updater/updater.cpp index 90f1fe08d09..49e21c9d30a 100644 --- a/toolkit/mozapps/update/src/updater/updater.cpp +++ b/toolkit/mozapps/update/src/updater/updater.cpp @@ -120,7 +120,7 @@ void LaunchChild(int argc, char **argv); #ifndef MAXPATHLEN # ifdef PATH_MAX # define MAXPATHLEN PATH_MAX -# elif defined(_MAX_PATH) +# elif defined(MAX_PATH) # define MAXPATHLEN MAX_PATH # elif defined(_MAX_PATH) # define MAXPATHLEN _MAX_PATH From f4bcd0bfffa398ea3e9a3f25b55417589af34f1f Mon Sep 17 00:00:00 2001 From: Chris Double Date: Tue, 7 Jul 2009 10:10:04 +1200 Subject: [PATCH 012/166] Bug 500254 - Update libvorbis - rs=roc --HG-- extra : rebase_source : f53b6ad720004d2fca0d643af11e0b565acf9d55 --- media/libvorbis/COPYING | 2 +- media/libvorbis/README | 12 +- media/libvorbis/README_MOZILLA | 17 +- media/libvorbis/bug498827.patch | 53 -- media/libvorbis/bug498853.patch | 31 -- media/libvorbis/include/vorbis/codec.h | 26 +- media/libvorbis/lib/backends.h | 21 +- media/libvorbis/lib/bitrate.h | 2 +- media/libvorbis/lib/codebook.h | 22 +- media/libvorbis/lib/codec_internal.h | 39 +- media/libvorbis/lib/envelope.h | 2 +- media/libvorbis/lib/highlevel.h | 4 +- media/libvorbis/lib/lookup.h | 2 +- media/libvorbis/lib/lookup_data.h | 271 +++++----- media/libvorbis/lib/lpc.h | 4 +- media/libvorbis/lib/lsp.h | 6 +- media/libvorbis/lib/masking.h | 6 +- media/libvorbis/lib/mdct.h | 2 +- media/libvorbis/lib/misc.h | 5 +- media/libvorbis/lib/os.h | 64 ++- media/libvorbis/lib/psy.h | 78 +-- media/libvorbis/lib/registry.h | 8 +- media/libvorbis/lib/scales.h | 11 +- media/libvorbis/lib/smallft.h | 2 +- media/libvorbis/lib/vorbis_analysis.c | 32 +- media/libvorbis/lib/vorbis_bitrate.c | 52 +- media/libvorbis/lib/vorbis_block.c | 310 ++++++------ media/libvorbis/lib/vorbis_codebook.c | 178 +++---- media/libvorbis/lib/vorbis_envelope.c | 101 ++-- media/libvorbis/lib/vorbis_floor0.c | 28 +- media/libvorbis/lib/vorbis_floor1.c | 630 ++++++++++++------------ media/libvorbis/lib/vorbis_info.c | 148 +++--- media/libvorbis/lib/vorbis_lookup.c | 4 +- media/libvorbis/lib/vorbis_lpc.c | 32 +- media/libvorbis/lib/vorbis_lsp.c | 60 +-- media/libvorbis/lib/vorbis_mapping0.c | 460 ++++++++--------- media/libvorbis/lib/vorbis_mdct.c | 282 +++++------ media/libvorbis/lib/vorbis_psy.c | 441 +++++++++-------- media/libvorbis/lib/vorbis_registry.c | 20 +- media/libvorbis/lib/vorbis_res0.c | 428 ++++++++-------- media/libvorbis/lib/vorbis_sharedbook.c | 320 ++++++------ media/libvorbis/lib/vorbis_smallft.c | 14 +- media/libvorbis/lib/vorbis_synthesis.c | 4 +- media/libvorbis/lib/vorbis_window.c | 28 +- media/libvorbis/lib/window.h | 2 +- media/libvorbis/update.sh | 2 - 46 files changed, 2174 insertions(+), 2092 deletions(-) delete mode 100644 media/libvorbis/bug498827.patch delete mode 100644 media/libvorbis/bug498853.patch diff --git a/media/libvorbis/COPYING b/media/libvorbis/COPYING index 7cf076b68fa..28de72a9705 100644 --- a/media/libvorbis/COPYING +++ b/media/libvorbis/COPYING @@ -1,4 +1,4 @@ -Copyright (c) 2002-2004 Xiph.org Foundation +Copyright (c) 2002-2008 Xiph.org Foundation Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions diff --git a/media/libvorbis/README b/media/libvorbis/README index 279e32d7dd8..3e969e0ceb8 100644 --- a/media/libvorbis/README +++ b/media/libvorbis/README @@ -79,23 +79,25 @@ The user website for Ogg Vorbis software and audio is http://vorbis.com/ BUILDING FROM TRUNK: Development source is under subversion revision control at -http://svn.xiph.org/trunk/vorbis/. You will also need the -newest versions of autoconf, automake, and libtool in order -to compile vorbis from development source. A configure script +https://svn.xiph.org/trunk/vorbis/. You will also need the +newest versions of autoconf, automake, libtool and pkg-config in +order to compile Vorbis from development source. A configure script is provided for you in the source tarball distributions. [update or checkout latest source] ./autogen.sh - make + make and as root if desired: make install -This will install the vorbis libraries (static and shared) into +This will install the Vorbis libraries (static and shared) into /usr/local/lib, includes into /usr/local/include and API manpages (once we write some) into /usr/local/man. +Documentation building requires xsltproc and pdfxmltex. + BUILDING FROM TARBALL DISTRIBUTIONS: ./configure diff --git a/media/libvorbis/README_MOZILLA b/media/libvorbis/README_MOZILLA index 415498c97e3..f489f66b3c8 100644 --- a/media/libvorbis/README_MOZILLA +++ b/media/libvorbis/README_MOZILLA @@ -1,17 +1,14 @@ -The source from this directory was copied from the libvorbis-1.2.0 -source distribution using the update.sh script. The only changes made -were those applied by update.sh and the addition/upate of Makefile.in -files for the Mozilla build system. +The source from this directory was copied from the libvorbis +subversion repository using the update.sh script. The only changes +made were those applied by update.sh and the addition/upate of +Makefile.in files for the Mozilla build system. + +The svn revision number used was r16183. Some files are renamed during the copy to prevent clashes with object file names with other Mozilla libraries. -BUG 455372 - WinCE LibVorbis No FPU Support on WinMobile, removed FPU -support for builds with WINCE defined. - -BUG 469639 - Failed to build firefox trunk on OpenSolaris +alloca.diff - Bug 469639 - Failed to build firefox trunk on OpenSolaris bug481601.patch is appled to fix bug 481601. bug487519.patch: fix for bug 487519. -bug498827.patch: fix for bug 498827 bug498855.patch: fix for bug 498855 -bug498853.patch: fix for bug 498853 \ No newline at end of file diff --git a/media/libvorbis/bug498827.patch b/media/libvorbis/bug498827.patch deleted file mode 100644 index 8ceecd24d4a..00000000000 --- a/media/libvorbis/bug498827.patch +++ /dev/null @@ -1,53 +0,0 @@ -diff --git a/media/libvorbis/lib/vorbis_info.c b/media/libvorbis/lib/vorbis_info.c -index 5a9d209..1d50526 100644 ---- a/media/libvorbis/lib/vorbis_info.c -+++ b/media/libvorbis/lib/vorbis_info.c -@@ -16,16 +16,17 @@ - ********************************************************************/ - - /* general handling of the header and the vorbis_info structure (and - substructures) */ - - #include - #include - #include -+#include - #include - #include "vorbis/codec.h" - #include "codec_internal.h" - #include "codebook.h" - #include "registry.h" - #include "window.h" - #include "psy.h" - #include "misc.h" -@@ -230,27 +231,27 @@ static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){ - err_out: - vorbis_info_clear(vi); - return(OV_EBADHEADER); - } - - static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){ - int i; - int vendorlen=oggpack_read(opb,32); -- if(vendorlen<0)goto err_out; -+ if(vendorlen<0||vendorlen>opb->storage)goto err_out; - vc->vendor=_ogg_calloc(vendorlen+1,1); - _v_readstring(opb,vc->vendor,vendorlen); - vc->comments=oggpack_read(opb,32); -- if(vc->comments<0)goto err_out; -+ if(vc->comments<0||vc->comments>(LONG_MAX>>2)||vc->comments<<2>opb->storage)goto err_out; - vc->user_comments=_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments)); - vc->comment_lengths=_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths)); - - for(i=0;icomments;i++){ - int len=oggpack_read(opb,32); -- if(len<0)goto err_out; -+ if(len<0||len>opb->storage)goto err_out; - vc->comment_lengths[i]=len; - vc->user_comments[i]=_ogg_calloc(len+1,1); - _v_readstring(opb,vc->user_comments[i],len); - } - if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */ - - return(0); - err_out: diff --git a/media/libvorbis/bug498853.patch b/media/libvorbis/bug498853.patch deleted file mode 100644 index fa3dde39a7f..00000000000 --- a/media/libvorbis/bug498853.patch +++ /dev/null @@ -1,31 +0,0 @@ -diff --git a/media/libvorbis/lib/vorbis_info.c b/media/libvorbis/lib/vorbis_info.c -index 1d50526..1356cb4 100644 ---- a/media/libvorbis/lib/vorbis_info.c -+++ b/media/libvorbis/lib/vorbis_info.c -@@ -126,20 +126,22 @@ int vorbis_comment_query_count(vorbis_comment *vc, char *tag){ - } - - return count; - } - - void vorbis_comment_clear(vorbis_comment *vc){ - if(vc){ - long i; -- for(i=0;icomments;i++) -- if(vc->user_comments[i])_ogg_free(vc->user_comments[i]); -- if(vc->user_comments)_ogg_free(vc->user_comments); -- if(vc->comment_lengths)_ogg_free(vc->comment_lengths); -+ if (vc->user_comments) { -+ for(i=0;icomments;i++) -+ if(vc->user_comments[i])_ogg_free(vc->user_comments[i]); -+ _ogg_free(vc->user_comments); -+ } -+ if(vc->comment_lengths)_ogg_free(vc->comment_lengths); - if(vc->vendor)_ogg_free(vc->vendor); - memset(vc,0,sizeof(*vc)); - } - } - - /* blocksize 0 is guaranteed to be short, 1 is guaranteed to be long. - They may be equal, but short will never ge greater than long */ - int vorbis_info_blocksize(vorbis_info *vi,int zo){ diff --git a/media/libvorbis/include/vorbis/codec.h b/media/libvorbis/include/vorbis/codec.h index c62b2d5873c..5f8766e1f85 100644 --- a/media/libvorbis/include/vorbis/codec.h +++ b/media/libvorbis/include/vorbis/codec.h @@ -11,7 +11,7 @@ ******************************************************************** function: libvorbis codec headers - last mod: $Id: codec.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -166,11 +166,11 @@ extern void vorbis_info_init(vorbis_info *vi); extern void vorbis_info_clear(vorbis_info *vi); extern int vorbis_info_blocksize(vorbis_info *vi,int zo); extern void vorbis_comment_init(vorbis_comment *vc); -extern void vorbis_comment_add(vorbis_comment *vc, char *comment); +extern void vorbis_comment_add(vorbis_comment *vc, const char *comment); extern void vorbis_comment_add_tag(vorbis_comment *vc, - char *tag, char *contents); -extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count); -extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag); + const char *tag, const char *contents); +extern char *vorbis_comment_query(vorbis_comment *vc, const char *tag, int count); +extern int vorbis_comment_query_count(vorbis_comment *vc, const char *tag); extern void vorbis_comment_clear(vorbis_comment *vc); extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb); @@ -178,17 +178,19 @@ extern int vorbis_block_clear(vorbis_block *vb); extern void vorbis_dsp_init(vorbis_dsp_state *v); extern void vorbis_dsp_clear(vorbis_dsp_state *v); extern double vorbis_granule_time(vorbis_dsp_state *v, - ogg_int64_t granulepos); + ogg_int64_t granulepos); + +extern const char *vorbis_version_string(void); /* Vorbis PRIMITIVES: analysis/DSP layer ****************************/ extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi); extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op); extern int vorbis_analysis_headerout(vorbis_dsp_state *v, - vorbis_comment *vc, - ogg_packet *op, - ogg_packet *op_comm, - ogg_packet *op_code); + vorbis_comment *vc, + ogg_packet *op, + ogg_packet *op_comm, + ogg_packet *op_code); extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals); extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals); extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb); @@ -196,12 +198,12 @@ extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op); extern int vorbis_bitrate_addblock(vorbis_block *vb); extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, - ogg_packet *op); + ogg_packet *op); /* Vorbis PRIMITIVES: synthesis layer *******************************/ extern int vorbis_synthesis_idheader(ogg_packet *op); extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc, - ogg_packet *op); + ogg_packet *op); extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi); extern int vorbis_synthesis_restart(vorbis_dsp_state *v); diff --git a/media/libvorbis/lib/backends.h b/media/libvorbis/lib/backends.h index a8cbd4d1803..be16e1a6eaa 100644 --- a/media/libvorbis/lib/backends.h +++ b/media/libvorbis/lib/backends.h @@ -12,7 +12,7 @@ function: libvorbis backend and mapping structures; needed for static mode headers - last mod: $Id: backends.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -35,7 +35,7 @@ typedef struct{ void (*free_look) (vorbis_look_floor *); void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *); int (*inverse2) (struct vorbis_block *,vorbis_look_floor *, - void *buffer,float *); + void *buffer,float *); } vorbis_func_floor; typedef struct{ @@ -89,16 +89,16 @@ typedef struct{ void (*pack) (vorbis_info_residue *,oggpack_buffer *); vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *); vorbis_look_residue *(*look) (vorbis_dsp_state *, - vorbis_info_residue *); + vorbis_info_residue *); void (*free_info) (vorbis_info_residue *); void (*free_look) (vorbis_look_residue *); long **(*class) (struct vorbis_block *,vorbis_look_residue *, - float **,int *,int); + float **,int *,int); int (*forward) (oggpack_buffer *,struct vorbis_block *, - vorbis_look_residue *, - float **,float **,int *,int,long **); + vorbis_look_residue *, + float **,float **,int *,int,long **); int (*inverse) (struct vorbis_block *,vorbis_look_residue *, - float **,int *,int); + float **,int *,int); } vorbis_func_residue; typedef struct vorbis_info_residue0{ @@ -113,15 +113,14 @@ typedef struct vorbis_info_residue0{ int secondstages[64]; /* expanded out to pointers in lookup */ int booklist[256]; /* list of second stage books */ - float classmetric1[64]; - float classmetric2[64]; - + const float classmetric1[64]; + const float classmetric2[64]; } vorbis_info_residue0; /* Mapping backend generic *****************************************/ typedef struct{ void (*pack) (vorbis_info *,vorbis_info_mapping *, - oggpack_buffer *); + oggpack_buffer *); vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *); void (*free_info) (vorbis_info_mapping *); int (*forward) (struct vorbis_block *vb); diff --git a/media/libvorbis/lib/bitrate.h b/media/libvorbis/lib/bitrate.h index db48fcb645a..9f0a0179fd6 100644 --- a/media/libvorbis/lib/bitrate.h +++ b/media/libvorbis/lib/bitrate.h @@ -11,7 +11,7 @@ ******************************************************************** function: bitrate tracking and management - last mod: $Id: bitrate.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ diff --git a/media/libvorbis/lib/codebook.h b/media/libvorbis/lib/codebook.h index 02c8e12656d..2d82337abcf 100644 --- a/media/libvorbis/lib/codebook.h +++ b/media/libvorbis/lib/codebook.h @@ -11,7 +11,7 @@ ******************************************************************** function: basic shared codebook operations - last mod: $Id: codebook.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -40,8 +40,8 @@ typedef struct static_codebook{ /* mapping ***************************************************************/ int maptype; /* 0=none - 1=implicitly populated values from map column - 2=listed arbitrary values */ + 1=implicitly populated values from map column + 2=listed arbitrary values */ /* The below does a linear, single monotonic sequence mapping. */ long q_min; /* packed 32 bit float; quant value 0 maps to minval */ @@ -50,8 +50,8 @@ typedef struct static_codebook{ int q_sequencep; /* bitflag */ long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map - map == 2: list of dim*entries quantized entry vals - */ + map == 2: list of dim*entries quantized entry vals + */ /* encode helpers ********************************************************/ struct encode_aux_nearestmatch *nearest_tree; @@ -142,18 +142,18 @@ extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c); extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b); extern int vorbis_book_errorv(codebook *book, float *a); extern int vorbis_book_encodev(codebook *book, int best,float *a, - oggpack_buffer *b); + oggpack_buffer *b); extern long vorbis_book_decode(codebook *book, oggpack_buffer *b); extern long vorbis_book_decodevs_add(codebook *book, float *a, - oggpack_buffer *b,int n); + oggpack_buffer *b,int n); extern long vorbis_book_decodev_set(codebook *book, float *a, - oggpack_buffer *b,int n); + oggpack_buffer *b,int n); extern long vorbis_book_decodev_add(codebook *book, float *a, - oggpack_buffer *b,int n); + oggpack_buffer *b,int n); extern long vorbis_book_decodevv_add(codebook *book, float **a, - long off,int ch, - oggpack_buffer *b,int n); + long off,int ch, + oggpack_buffer *b,int n); diff --git a/media/libvorbis/lib/codec_internal.h b/media/libvorbis/lib/codec_internal.h index 9cefef195f5..2d36439fd17 100644 --- a/media/libvorbis/lib/codec_internal.h +++ b/media/libvorbis/lib/codec_internal.h @@ -11,7 +11,7 @@ ******************************************************************** function: libvorbis codec headers - last mod: $Id: codec_internal.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -34,9 +34,9 @@ typedef struct vorbis_block_internal{ int blocktype; oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed; - blob [PACKETBLOBS/2] points to - the oggpack_buffer in the - main vorbis_block */ + blob [PACKETBLOBS/2] points to + the oggpack_buffer in the + main vorbis_block */ } vorbis_block_internal; typedef void vorbis_look_floor; @@ -133,5 +133,36 @@ typedef struct codec_setup_info { extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi); extern void _vp_global_free(vorbis_look_psy_global *look); + + +typedef struct { + int sorted_index[VIF_POSIT+2]; + int forward_index[VIF_POSIT+2]; + int reverse_index[VIF_POSIT+2]; + + int hineighbor[VIF_POSIT]; + int loneighbor[VIF_POSIT]; + int posts; + + int n; + int quant_q; + vorbis_info_floor1 *vi; + + long phrasebits; + long postbits; + long frames; +} vorbis_look_floor1; + + + +extern int *floor1_fit(vorbis_block *vb,vorbis_look_floor1 *look, + const float *logmdct, /* in */ + const float *logmask); +extern int *floor1_interpolate_fit(vorbis_block *vb,vorbis_look_floor1 *look, + int *A,int *B, + int del); +extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb, + vorbis_look_floor1 *look, + int *post,int *ilogmask); #endif diff --git a/media/libvorbis/lib/envelope.h b/media/libvorbis/lib/envelope.h index dc64ac121d3..83a32258ece 100644 --- a/media/libvorbis/lib/envelope.h +++ b/media/libvorbis/lib/envelope.h @@ -11,7 +11,7 @@ ******************************************************************** function: PCM data envelope analysis and manipulation - last mod: $Id: envelope.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ diff --git a/media/libvorbis/lib/highlevel.h b/media/libvorbis/lib/highlevel.h index 5a4ab8fd892..aafe0f7d809 100644 --- a/media/libvorbis/lib/highlevel.h +++ b/media/libvorbis/lib/highlevel.h @@ -11,7 +11,7 @@ ******************************************************************** function: highlevel encoder setup struct seperated out for vorbisenc clarity - last mod: $Id: highlevel.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -23,7 +23,7 @@ typedef struct highlevel_byblocktype { } highlevel_byblocktype; typedef struct highlevel_encode_setup { - void *setup; + const void *setup; int set_in_stone; double base_setting; diff --git a/media/libvorbis/lib/lookup.h b/media/libvorbis/lib/lookup.h index e9e22f285a5..0d0d4984710 100644 --- a/media/libvorbis/lib/lookup.h +++ b/media/libvorbis/lib/lookup.h @@ -11,7 +11,7 @@ ******************************************************************** function: lookup based functions - last mod: $Id: lookup.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ diff --git a/media/libvorbis/lib/lookup_data.h b/media/libvorbis/lib/lookup_data.h index b3a022a5d74..a60e7b8c70a 100644 --- a/media/libvorbis/lib/lookup_data.h +++ b/media/libvorbis/lib/lookup_data.h @@ -11,7 +11,7 @@ ******************************************************************** function: lookup data; generated by lookups.pl; edit there - last mod: $Id: lookup_data.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -19,76 +19,76 @@ #ifdef FLOAT_LOOKUP #define COS_LOOKUP_SZ 128 -static float COS_LOOKUP[COS_LOOKUP_SZ+1]={ - +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f, - +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f, - +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f, - +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f, - +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f, - +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f, - +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f, - +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f, - +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f, - +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f, - +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f, - +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f, - +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f, - +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f, - +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f, - +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f, - +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f, - -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f, - -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f, - -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f, - -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f, - -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f, - -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f, - -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f, - -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f, - -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f, - -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f, - -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f, - -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f, - -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f, - -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f, - -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f, - -1.0000000000000f, +static const float COS_LOOKUP[COS_LOOKUP_SZ+1]={ + +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f, + +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f, + +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f, + +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f, + +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f, + +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f, + +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f, + +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f, + +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f, + +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f, + +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f, + +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f, + +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f, + +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f, + +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f, + +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f, + +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f, + -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f, + -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f, + -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f, + -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f, + -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f, + -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f, + -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f, + -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f, + -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f, + -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f, + -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f, + -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f, + -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f, + -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f, + -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f, + -1.0000000000000f, }; #define INVSQ_LOOKUP_SZ 32 -static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={ - 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f, - 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f, - 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f, - 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f, - 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f, - 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f, - 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f, - 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f, - 1.000000000000f, +static const float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={ + 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f, + 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f, + 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f, + 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f, + 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f, + 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f, + 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f, + 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f, + 1.000000000000f, }; #define INVSQ2EXP_LOOKUP_MIN (-32) #define INVSQ2EXP_LOOKUP_MAX 32 -static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\ +static const float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\ INVSQ2EXP_LOOKUP_MIN+1]={ - 65536.f, 46340.95001f, 32768.f, 23170.47501f, - 16384.f, 11585.2375f, 8192.f, 5792.618751f, - 4096.f, 2896.309376f, 2048.f, 1448.154688f, - 1024.f, 724.0773439f, 512.f, 362.038672f, - 256.f, 181.019336f, 128.f, 90.50966799f, - 64.f, 45.254834f, 32.f, 22.627417f, - 16.f, 11.3137085f, 8.f, 5.656854249f, - 4.f, 2.828427125f, 2.f, 1.414213562f, - 1.f, 0.7071067812f, 0.5f, 0.3535533906f, - 0.25f, 0.1767766953f, 0.125f, 0.08838834765f, - 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f, - 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f, - 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f, - 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f, - 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f, - 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f, - 1.525878906e-05f, + 65536.f, 46340.95001f, 32768.f, 23170.47501f, + 16384.f, 11585.2375f, 8192.f, 5792.618751f, + 4096.f, 2896.309376f, 2048.f, 1448.154688f, + 1024.f, 724.0773439f, 512.f, 362.038672f, + 256.f, 181.019336f, 128.f, 90.50966799f, + 64.f, 45.254834f, 32.f, 22.627417f, + 16.f, 11.3137085f, 8.f, 5.656854249f, + 4.f, 2.828427125f, 2.f, 1.414213562f, + 1.f, 0.7071067812f, 0.5f, 0.3535533906f, + 0.25f, 0.1767766953f, 0.125f, 0.08838834765f, + 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f, + 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f, + 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f, + 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f, + 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f, + 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f, + 1.525878906e-05f, }; #endif @@ -98,90 +98,93 @@ static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\ #define FROMdB_SHIFT 5 #define FROMdB2_SHIFT 3 #define FROMdB2_MASK 31 -static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={ - 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f, - 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f, - 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f, - 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f, - 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f, - 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f, - 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f, - 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f, - 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f, + +#ifdef FLOAT_LOOKUP +static const float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={ + 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f, + 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f, + 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f, + 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f, + 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f, + 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f, + 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f, + 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f, + 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f, }; -static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={ - 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f, - 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f, - 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f, - 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f, - 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f, - 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f, - 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f, - 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f, +static const float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={ + 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f, + 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f, + 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f, + 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f, + 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f, + 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f, + 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f, + 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f, }; +#endif #ifdef INT_LOOKUP #define INVSQ_LOOKUP_I_SHIFT 10 #define INVSQ_LOOKUP_I_MASK 1023 -static long INVSQ_LOOKUP_I[64+1]={ - 92682l, 91966l, 91267l, 90583l, - 89915l, 89261l, 88621l, 87995l, - 87381l, 86781l, 86192l, 85616l, - 85051l, 84497l, 83953l, 83420l, - 82897l, 82384l, 81880l, 81385l, - 80899l, 80422l, 79953l, 79492l, - 79039l, 78594l, 78156l, 77726l, - 77302l, 76885l, 76475l, 76072l, - 75674l, 75283l, 74898l, 74519l, - 74146l, 73778l, 73415l, 73058l, - 72706l, 72359l, 72016l, 71679l, - 71347l, 71019l, 70695l, 70376l, - 70061l, 69750l, 69444l, 69141l, - 68842l, 68548l, 68256l, 67969l, - 67685l, 67405l, 67128l, 66855l, - 66585l, 66318l, 66054l, 65794l, - 65536l, +static const long INVSQ_LOOKUP_I[64+1]={ + 92682l, 91966l, 91267l, 90583l, + 89915l, 89261l, 88621l, 87995l, + 87381l, 86781l, 86192l, 85616l, + 85051l, 84497l, 83953l, 83420l, + 82897l, 82384l, 81880l, 81385l, + 80899l, 80422l, 79953l, 79492l, + 79039l, 78594l, 78156l, 77726l, + 77302l, 76885l, 76475l, 76072l, + 75674l, 75283l, 74898l, 74519l, + 74146l, 73778l, 73415l, 73058l, + 72706l, 72359l, 72016l, 71679l, + 71347l, 71019l, 70695l, 70376l, + 70061l, 69750l, 69444l, 69141l, + 68842l, 68548l, 68256l, 67969l, + 67685l, 67405l, 67128l, 66855l, + 66585l, 66318l, 66054l, 65794l, + 65536l, }; #define COS_LOOKUP_I_SHIFT 9 #define COS_LOOKUP_I_MASK 511 #define COS_LOOKUP_I_SZ 128 -static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={ - 16384l, 16379l, 16364l, 16340l, - 16305l, 16261l, 16207l, 16143l, - 16069l, 15986l, 15893l, 15791l, - 15679l, 15557l, 15426l, 15286l, - 15137l, 14978l, 14811l, 14635l, - 14449l, 14256l, 14053l, 13842l, - 13623l, 13395l, 13160l, 12916l, - 12665l, 12406l, 12140l, 11866l, - 11585l, 11297l, 11003l, 10702l, - 10394l, 10080l, 9760l, 9434l, - 9102l, 8765l, 8423l, 8076l, - 7723l, 7366l, 7005l, 6639l, - 6270l, 5897l, 5520l, 5139l, - 4756l, 4370l, 3981l, 3590l, - 3196l, 2801l, 2404l, 2006l, - 1606l, 1205l, 804l, 402l, - 0l, -401l, -803l, -1204l, - -1605l, -2005l, -2403l, -2800l, - -3195l, -3589l, -3980l, -4369l, - -4755l, -5138l, -5519l, -5896l, - -6269l, -6638l, -7004l, -7365l, - -7722l, -8075l, -8422l, -8764l, - -9101l, -9433l, -9759l, -10079l, - -10393l, -10701l, -11002l, -11296l, - -11584l, -11865l, -12139l, -12405l, - -12664l, -12915l, -13159l, -13394l, - -13622l, -13841l, -14052l, -14255l, - -14448l, -14634l, -14810l, -14977l, - -15136l, -15285l, -15425l, -15556l, - -15678l, -15790l, -15892l, -15985l, - -16068l, -16142l, -16206l, -16260l, - -16304l, -16339l, -16363l, -16378l, - -16383l, +static const long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={ + 16384l, 16379l, 16364l, 16340l, + 16305l, 16261l, 16207l, 16143l, + 16069l, 15986l, 15893l, 15791l, + 15679l, 15557l, 15426l, 15286l, + 15137l, 14978l, 14811l, 14635l, + 14449l, 14256l, 14053l, 13842l, + 13623l, 13395l, 13160l, 12916l, + 12665l, 12406l, 12140l, 11866l, + 11585l, 11297l, 11003l, 10702l, + 10394l, 10080l, 9760l, 9434l, + 9102l, 8765l, 8423l, 8076l, + 7723l, 7366l, 7005l, 6639l, + 6270l, 5897l, 5520l, 5139l, + 4756l, 4370l, 3981l, 3590l, + 3196l, 2801l, 2404l, 2006l, + 1606l, 1205l, 804l, 402l, + 0l, -401l, -803l, -1204l, + -1605l, -2005l, -2403l, -2800l, + -3195l, -3589l, -3980l, -4369l, + -4755l, -5138l, -5519l, -5896l, + -6269l, -6638l, -7004l, -7365l, + -7722l, -8075l, -8422l, -8764l, + -9101l, -9433l, -9759l, -10079l, + -10393l, -10701l, -11002l, -11296l, + -11584l, -11865l, -12139l, -12405l, + -12664l, -12915l, -13159l, -13394l, + -13622l, -13841l, -14052l, -14255l, + -14448l, -14634l, -14810l, -14977l, + -15136l, -15285l, -15425l, -15556l, + -15678l, -15790l, -15892l, -15985l, + -16068l, -16142l, -16206l, -16260l, + -16304l, -16339l, -16363l, -16378l, + -16383l, }; #endif diff --git a/media/libvorbis/lib/lpc.h b/media/libvorbis/lib/lpc.h index 82917807f70..2091afa171c 100644 --- a/media/libvorbis/lib/lpc.h +++ b/media/libvorbis/lib/lpc.h @@ -11,7 +11,7 @@ ******************************************************************** function: LPC low level routines - last mod: $Id: lpc.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -24,6 +24,6 @@ extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m); extern void vorbis_lpc_predict(float *coeff,float *prime,int m, - float *data,long n); + float *data,long n); #endif diff --git a/media/libvorbis/lib/lsp.h b/media/libvorbis/lib/lsp.h index 2c49b673d97..e16130e4faa 100644 --- a/media/libvorbis/lib/lsp.h +++ b/media/libvorbis/lib/lsp.h @@ -11,7 +11,7 @@ ******************************************************************** function: LSP (also called LSF) conversion routines - last mod: $Id: lsp.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -22,7 +22,7 @@ extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m); extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln, - float *lsp,int m, - float amp,float ampoffset); + float *lsp,int m, + float amp,float ampoffset); #endif diff --git a/media/libvorbis/lib/masking.h b/media/libvorbis/lib/masking.h index c10be9a5e13..785062aceaa 100644 --- a/media/libvorbis/lib/masking.h +++ b/media/libvorbis/lib/masking.h @@ -11,7 +11,7 @@ ******************************************************************** function: masking curve data for psychoacoustics - last mod: $Id: masking.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -22,7 +22,7 @@ overly for only a bin or two of savings. */ #define MAX_ATH 88 -static float ATH[]={ +static const float ATH[]={ /*15*/ -51, -52, -53, -54, -55, -56, -57, -58, /*31*/ -59, -60, -61, -62, -63, -64, -65, -66, /*63*/ -67, -68, -69, -70, -71, -72, -73, -74, @@ -48,7 +48,7 @@ static float ATH[]={ /* (Vorbis 0dB, the loudest possible tone, is assumed to be ~100dB SPL for collection of these curves) */ -static float tonemasks[P_BANDS][6][EHMER_MAX]={ +static const float tonemasks[P_BANDS][6][EHMER_MAX]={ /* 62.5 Hz */ {{ -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -62, -62, -65, -73, diff --git a/media/libvorbis/lib/mdct.h b/media/libvorbis/lib/mdct.h index 58a6ac04642..54c45a38e5c 100644 --- a/media/libvorbis/lib/mdct.h +++ b/media/libvorbis/lib/mdct.h @@ -11,7 +11,7 @@ ******************************************************************** function: modified discrete cosine transform prototypes - last mod: $Id: mdct.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ diff --git a/media/libvorbis/lib/misc.h b/media/libvorbis/lib/misc.h index 27ecc2c093c..f319386fb63 100644 --- a/media/libvorbis/lib/misc.h +++ b/media/libvorbis/lib/misc.h @@ -11,7 +11,7 @@ ******************************************************************** function: miscellaneous prototypes - last mod: $Id: misc.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -24,11 +24,12 @@ extern int analysis_noisy; extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes); extern void _vorbis_block_ripcord(vorbis_block *vb); extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB, - ogg_int64_t off); + ogg_int64_t off); #ifdef DEBUG_MALLOC #define _VDBG_GRAPHFILE "malloc.m" +#undef _VDBG_GRAPHFILE extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line); extern void _VDBG_free(void *ptr,char *file,long line); diff --git a/media/libvorbis/lib/os.h b/media/libvorbis/lib/os.h index 5bfaa7a688c..e72edbb049a 100644 --- a/media/libvorbis/lib/os.h +++ b/media/libvorbis/lib/os.h @@ -13,7 +13,7 @@ ******************************************************************** function: #ifdef jail to whip a few platforms into the UNIX ideal. - last mod: $Id: os.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -83,7 +83,9 @@ void *_alloca(size_t size); # define max(x,y) ((x)<(y)?(y):(x)) #endif -#if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__) && !defined(WINCE) + +/* Special i386 GCC implementation */ +#if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__) # define VORBIS_FPU_CONTROL /* both GCC and MSVC are kinda stupid about rounding/casting to int. Because of encapsulation constraints (GCC can't see inside the asm @@ -98,10 +100,10 @@ static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){ ogg_int16_t ret; ogg_int16_t temp; __asm__ __volatile__("fnstcw %0\n\t" - "movw %0,%%dx\n\t" - "orw $62463,%%dx\n\t" - "movw %%dx,%1\n\t" - "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx"); + "movw %0,%%dx\n\t" + "orw $62463,%%dx\n\t" + "movw %%dx,%1\n\t" + "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx"); *fpu=ret; } @@ -117,21 +119,23 @@ static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise, __asm__("fistl %0": "=m"(i) : "t"(f)); return(i); } -#endif +#endif /* Special i386 GCC implementation */ -#if defined(_WIN32) && !defined(__GNUC__) && !defined(__BORLANDC__) && !defined(WINCE) +/* MSVC inline assembly. 32 bit only; inline ASM isn't implemented in the + * 64 bit compiler */ +#if defined(_MSC_VER) && !defined(_WIN64) && !defined(_WIN32_WCE) # define VORBIS_FPU_CONTROL typedef ogg_int16_t vorbis_fpu_control; static __inline int vorbis_ftoi(double f){ - int i; - __asm{ - fld f - fistp i - } - return i; + int i; + __asm{ + fld f + fistp i + } + return i; } static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){ @@ -140,21 +144,47 @@ static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){ static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){ } -#endif +#endif /* Special MSVC 32 bit implementation */ +/* Optimized code path for x86_64 builds. Uses SSE2 intrinsics. This can be + done safely because all x86_64 CPUs supports SSE2. */ +#if (defined(_MSC_VER) && defined(_WIN64)) || (defined(__GNUC__) && defined (__x86_64__)) +# define VORBIS_FPU_CONTROL + +typedef ogg_int16_t vorbis_fpu_control; + +#include +static __inline int vorbis_ftoi(double f){ + return _mm_cvtsd_si32(_mm_load_sd(&f)); +} + +static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){ +} + +static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){ +} + +#endif /* Special MSVC x64 implementation */ + + +/* If no special implementation was found for the current compiler / platform, + use the default implementation here: */ #ifndef VORBIS_FPU_CONTROL typedef int vorbis_fpu_control; static int vorbis_ftoi(double f){ - return (int)(f+.5); + /* Note: MSVC and GCC (at least on some systems) round towards zero, thus, + the floor() call is required to ensure correct roudning of + negative numbers */ + return (int)floor(f+.5); } /* We don't have special code for this compiler/arch, so do it the slow way */ # define vorbis_fpu_setround(vorbis_fpu_control) {} # define vorbis_fpu_restore(vorbis_fpu_control) {} -#endif +#endif /* default implementation */ #endif /* _OS_H */ diff --git a/media/libvorbis/lib/psy.h b/media/libvorbis/lib/psy.h index 0950558a034..1016dab829c 100644 --- a/media/libvorbis/lib/psy.h +++ b/media/libvorbis/lib/psy.h @@ -11,7 +11,7 @@ ******************************************************************** function: random psychoacoustics (not including preecho) - last mod: $Id: psy.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -115,7 +115,7 @@ typedef struct { } vorbis_look_psy; extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi, - vorbis_info_psy_global *gi,int n,long rate); + vorbis_info_psy_global *gi,int n,long rate); extern void _vp_psy_clear(vorbis_look_psy *p); extern void *_vi_psy_dup(void *source); @@ -123,63 +123,63 @@ extern void _vi_psy_free(vorbis_info_psy *i); extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i); extern void _vp_remove_floor(vorbis_look_psy *p, - float *mdct, - int *icodedflr, - float *residue, - int sliding_lowpass); + float *mdct, + int *icodedflr, + float *residue, + int sliding_lowpass); extern void _vp_noisemask(vorbis_look_psy *p, - float *logmdct, - float *logmask); + float *logmdct, + float *logmask); extern void _vp_tonemask(vorbis_look_psy *p, - float *logfft, - float *logmask, - float global_specmax, - float local_specmax); + float *logfft, + float *logmask, + float global_specmax, + float local_specmax); extern void _vp_offset_and_mix(vorbis_look_psy *p, - float *noise, - float *tone, - int offset_select, - float *logmask, - float *mdct, - float *logmdct); + float *noise, + float *tone, + int offset_select, + float *logmask, + float *mdct, + float *logmdct); extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd); extern float **_vp_quantize_couple_memo(vorbis_block *vb, - vorbis_info_psy_global *g, - vorbis_look_psy *p, - vorbis_info_mapping0 *vi, - float **mdct); + vorbis_info_psy_global *g, + vorbis_look_psy *p, + vorbis_info_mapping0 *vi, + float **mdct); extern void _vp_couple(int blobno, - vorbis_info_psy_global *g, - vorbis_look_psy *p, - vorbis_info_mapping0 *vi, - float **res, - float **mag_memo, - int **mag_sort, - int **ifloor, - int *nonzero, - int sliding_lowpass); + vorbis_info_psy_global *g, + vorbis_look_psy *p, + vorbis_info_mapping0 *vi, + float **res, + float **mag_memo, + int **mag_sort, + int **ifloor, + int *nonzero, + int sliding_lowpass); extern void _vp_noise_normalize(vorbis_look_psy *p, - float *in,float *out,int *sortedindex); + float *in,float *out,int *sortedindex); extern void _vp_noise_normalize_sort(vorbis_look_psy *p, - float *magnitudes,int *sortedindex); + float *magnitudes,int *sortedindex); extern int **_vp_quantize_couple_sort(vorbis_block *vb, - vorbis_look_psy *p, - vorbis_info_mapping0 *vi, - float **mags); + vorbis_look_psy *p, + vorbis_info_mapping0 *vi, + float **mags); extern void hf_reduction(vorbis_info_psy_global *g, - vorbis_look_psy *p, - vorbis_info_mapping0 *vi, - float **mdct); + vorbis_look_psy *p, + vorbis_info_mapping0 *vi, + float **mdct); #endif diff --git a/media/libvorbis/lib/registry.h b/media/libvorbis/lib/registry.h index 568c1f9ebf7..d8e0d591212 100644 --- a/media/libvorbis/lib/registry.h +++ b/media/libvorbis/lib/registry.h @@ -11,7 +11,7 @@ ******************************************************************** function: registry for time, floor, res backends and channel mappings - last mod: $Id: registry.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -25,8 +25,8 @@ #define VI_RESB 3 #define VI_MAPB 1 -extern vorbis_func_floor *_floor_P[]; -extern vorbis_func_residue *_residue_P[]; -extern vorbis_func_mapping *_mapping_P[]; +extern const vorbis_func_floor *const _floor_P[]; +extern const vorbis_func_residue *const _residue_P[]; +extern const vorbis_func_mapping *const _mapping_P[]; #endif diff --git a/media/libvorbis/lib/scales.h b/media/libvorbis/lib/scales.h index 4708b2365ad..65095254d93 100644 --- a/media/libvorbis/lib/scales.h +++ b/media/libvorbis/lib/scales.h @@ -11,7 +11,7 @@ ******************************************************************** function: linear scale -> dB, Bark and Mel scales - last mod: $Id: scales.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -21,11 +21,16 @@ #include #include "os.h" +#ifdef _MSC_VER +/* MS Visual Studio doesn't have C99 inline keyword. */ +#define inline __inline +#endif + /* 20log10(x) */ #define VORBIS_IEEE_FLOAT32 1 #ifdef VORBIS_IEEE_FLOAT32 -static float unitnorm(float x){ +static inline float unitnorm(float x){ union { ogg_uint32_t i; float f; @@ -36,7 +41,7 @@ static float unitnorm(float x){ } /* Segher was off (too high) by ~ .3 decibel. Center the conversion correctly. */ -static float todB(const float *x){ +static inline float todB(const float *x){ union { ogg_uint32_t i; float f; diff --git a/media/libvorbis/lib/smallft.h b/media/libvorbis/lib/smallft.h index 456497326ca..30df9606c97 100644 --- a/media/libvorbis/lib/smallft.h +++ b/media/libvorbis/lib/smallft.h @@ -11,7 +11,7 @@ ******************************************************************** function: fft transform - last mod: $Id: smallft.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ diff --git a/media/libvorbis/lib/vorbis_analysis.c b/media/libvorbis/lib/vorbis_analysis.c index 316e1dcca18..ed1eba14751 100644 --- a/media/libvorbis/lib/vorbis_analysis.c +++ b/media/libvorbis/lib/vorbis_analysis.c @@ -11,7 +11,7 @@ ******************************************************************** function: single-block PCM analysis mode dispatch - last mod: $Id: analysis.c 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -67,6 +67,7 @@ int vorbis_analysis(vorbis_block *vb, ogg_packet *op){ /* there was no great place to put this.... */ void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){ +#if 0 int j; FILE *of; char buffer[80]; @@ -79,31 +80,32 @@ void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB,ogg for(j=0;jvb)return(-1); /* one has been submitted without - being claimed */ + being claimed */ bm->vb=vb; return(0); } @@ -117,15 +117,15 @@ int vorbis_bitrate_addblock(vorbis_block *vb){ if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){ while(choice>0 && this_bits>avg_target_bits && - bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){ - choice--; - this_bits=oggpack_bytes(vbi->packetblob[choice])*8; + bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){ + choice--; + this_bits=oggpack_bytes(vbi->packetblob[choice])*8; } }else if(bm->avg_reservoir+(this_bits-avg_target_bits)avg_reservoir+(this_bits-avg_target_bits)packetblob[choice])*8; + bm->avg_reservoir+(this_bits-avg_target_bits)packetblob[choice])*8; } } @@ -143,9 +143,9 @@ int vorbis_bitrate_addblock(vorbis_block *vb){ /* do we need to force the bitrate up? */ if(this_bitsminmax_reservoir-(min_target_bits-this_bits)<0){ - choice++; - if(choice>=PACKETBLOBS)break; - this_bits=oggpack_bytes(vbi->packetblob[choice])*8; + choice++; + if(choice>=PACKETBLOBS)break; + this_bits=oggpack_bytes(vbi->packetblob[choice])*8; } } } @@ -155,9 +155,9 @@ int vorbis_bitrate_addblock(vorbis_block *vb){ /* do we need to force the bitrate down? */ if(this_bits>max_target_bits){ while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){ - choice--; - if(choice<0)break; - this_bits=oggpack_bytes(vbi->packetblob[choice])*8; + choice--; + if(choice<0)break; + this_bits=oggpack_bytes(vbi->packetblob[choice])*8; } } } @@ -201,19 +201,19 @@ int vorbis_bitrate_addblock(vorbis_block *vb){ }else{ /* inbetween; we want to take reservoir toward but not past desired_fill */ if(bm->minmax_reservoir>desired_fill){ - if(max_target_bits>0){ /* logical bulletproofing against initialization state */ - bm->minmax_reservoir+=(this_bits-max_target_bits); - if(bm->minmax_reservoirminmax_reservoir=desired_fill; - }else{ - bm->minmax_reservoir=desired_fill; - } + if(max_target_bits>0){ /* logical bulletproofing against initialization state */ + bm->minmax_reservoir+=(this_bits-max_target_bits); + if(bm->minmax_reservoirminmax_reservoir=desired_fill; + }else{ + bm->minmax_reservoir=desired_fill; + } }else{ - if(min_target_bits>0){ /* logical bulletproofing against initialization state */ - bm->minmax_reservoir+=(this_bits-min_target_bits); - if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill; - }else{ - bm->minmax_reservoir=desired_fill; - } + if(min_target_bits>0){ /* logical bulletproofing against initialization state */ + bm->minmax_reservoir+=(this_bits-min_target_bits); + if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill; + }else{ + bm->minmax_reservoir=desired_fill; + } } } } diff --git a/media/libvorbis/lib/vorbis_block.c b/media/libvorbis/lib/vorbis_block.c index d7f5974374b..fa854c06e7b 100644 --- a/media/libvorbis/lib/vorbis_block.c +++ b/media/libvorbis/lib/vorbis_block.c @@ -11,7 +11,7 @@ ******************************************************************** function: PCM data vector blocking, windowing and dis/reassembly - last mod: $Id: block.c 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ Handle windowing, overlap-add, etc of the PCM vectors. This is made more amusing by Vorbis' current two allowed block sizes. @@ -75,8 +75,8 @@ static int ilog2(unsigned int v){ | | |endSr | |beginSr | |endSl - |beginSl - |beginW + |beginSl + |beginW */ /* block abstraction setup *********************************************/ @@ -96,10 +96,10 @@ int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){ for(i=0;ipacketblob[i]=&vb->opb; + vbi->packetblob[i]=&vb->opb; }else{ - vbi->packetblob[i]= - _ogg_calloc(1,sizeof(oggpack_buffer)); + vbi->packetblob[i]= + _ogg_calloc(1,sizeof(oggpack_buffer)); } oggpack_writeinit(vbi->packetblob[i]); } @@ -215,16 +215,16 @@ static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){ if(!ci->fullbooks){ ci->fullbooks=_ogg_calloc(ci->books,sizeof(*ci->fullbooks)); for(i=0;ibooks;i++) - vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]); + vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]); } b->psy=_ogg_calloc(ci->psys,sizeof(*b->psy)); for(i=0;ipsys;i++){ _vp_psy_init(b->psy+i, - ci->psy_param[i], - &ci->psy_g_param, - ci->blocksizes[ci->psy_param[i]->blockflag]/2, - vi->rate); + ci->psy_param[i], + &ci->psy_g_param, + ci->blocksizes[ci->psy_param[i]->blockflag]/2, + vi->rate); } v->analysisp=1; @@ -233,10 +233,11 @@ static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){ if(!ci->fullbooks){ ci->fullbooks=_ogg_calloc(ci->books,sizeof(*ci->fullbooks)); for(i=0;ibooks;i++){ - vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]); - /* decode codebooks are now standalone after init */ - vorbis_staticbook_destroy(ci->book_param[i]); - ci->book_param[i]=NULL; + if(vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i])) + return -1; + /* decode codebooks are now standalone after init */ + vorbis_staticbook_destroy(ci->book_param[i]); + ci->book_param[i]=NULL; } } } @@ -310,42 +311,42 @@ void vorbis_dsp_clear(vorbis_dsp_state *v){ private_state *b=v->backend_state; if(b){ - + if(b->ve){ - _ve_envelope_clear(b->ve); - _ogg_free(b->ve); + _ve_envelope_clear(b->ve); + _ogg_free(b->ve); } if(b->transform[0]){ - mdct_clear(b->transform[0][0]); - _ogg_free(b->transform[0][0]); - _ogg_free(b->transform[0]); + mdct_clear(b->transform[0][0]); + _ogg_free(b->transform[0][0]); + _ogg_free(b->transform[0]); } if(b->transform[1]){ - mdct_clear(b->transform[1][0]); - _ogg_free(b->transform[1][0]); - _ogg_free(b->transform[1]); + mdct_clear(b->transform[1][0]); + _ogg_free(b->transform[1][0]); + _ogg_free(b->transform[1]); } if(b->flr){ - if(ci) - for(i=0;ifloors;i++) - _floor_P[ci->floor_type[i]]-> - free_look(b->flr[i]); - _ogg_free(b->flr); + if(ci) + for(i=0;ifloors;i++) + _floor_P[ci->floor_type[i]]-> + free_look(b->flr[i]); + _ogg_free(b->flr); } if(b->residue){ - if(ci) - for(i=0;iresidues;i++) - _residue_P[ci->residue_type[i]]-> - free_look(b->residue[i]); - _ogg_free(b->residue); + if(ci) + for(i=0;iresidues;i++) + _residue_P[ci->residue_type[i]]-> + free_look(b->residue[i]); + _ogg_free(b->residue); } if(b->psy){ - if(ci) - for(i=0;ipsys;i++) - _vp_psy_clear(b->psy+i); - _ogg_free(b->psy); + if(ci) + for(i=0;ipsys;i++) + _vp_psy_clear(b->psy+i); + _ogg_free(b->psy); } if(b->psy_g_look)_vp_global_free(b->psy_g_look); @@ -358,8 +359,8 @@ void vorbis_dsp_clear(vorbis_dsp_state *v){ if(v->pcm){ if(vi) - for(i=0;ichannels;i++) - if(v->pcm[i])_ogg_free(v->pcm[i]); + for(i=0;ichannels;i++) + if(v->pcm[i])_ogg_free(v->pcm[i]); _ogg_free(v->pcm); if(v->pcmret)_ogg_free(v->pcmret); } @@ -405,7 +406,7 @@ float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){ static void _preextrapolate_helper(vorbis_dsp_state *v){ int i; - int order=32; + int order=16; float *lpc=alloca(order*sizeof(*lpc)); float *work=alloca(v->pcm_current*sizeof(*work)); long j; @@ -415,19 +416,30 @@ static void _preextrapolate_helper(vorbis_dsp_state *v){ for(i=0;ivi->channels;i++){ /* need to run the extrapolation in reverse! */ for(j=0;jpcm_current;j++) - work[j]=v->pcm[i][v->pcm_current-j-1]; + work[j]=v->pcm[i][v->pcm_current-j-1]; /* prime as above */ vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order); - + +#if 0 + if(v->vi->channels==2){ + if(i==0) + _analysis_output("predataL",0,work,v->pcm_current-v->centerW,0,0,0); + else + _analysis_output("predataR",0,work,v->pcm_current-v->centerW,0,0,0); + }else{ + _analysis_output("predata",0,work,v->pcm_current-v->centerW,0,0,0); + } +#endif + /* run the predictor filter */ vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order, - order, - work+v->pcm_current-v->centerW, - v->centerW); + order, + work+v->pcm_current-v->centerW, + v->centerW); for(j=0;jpcm_current;j++) - v->pcm[i][v->pcm_current-j-1]=work[j]; + v->pcm[i][v->pcm_current-j-1]=work[j]; } } @@ -461,23 +473,23 @@ int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){ for(i=0;ichannels;i++){ if(v->eofflag>order*2){ - /* extrapolate with LPC to fill in */ - long n; + /* extrapolate with LPC to fill in */ + long n; - /* make a predictor filter */ - n=v->eofflag; - if(n>ci->blocksizes[1])n=ci->blocksizes[1]; - vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order); + /* make a predictor filter */ + n=v->eofflag; + if(n>ci->blocksizes[1])n=ci->blocksizes[1]; + vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order); - /* run the predictor filter */ - vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order, - v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag); + /* run the predictor filter */ + vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order, + v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag); }else{ - /* not enough data to extrapolate (unlikely to happen due to + /* not enough data to extrapolate (unlikely to happen due to guarding the overlap, but bulletproof in case that assumtion goes away). zeroes will do. */ - memset(v->pcm[i]+v->eofflag,0, - (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i])); + memset(v->pcm[i]+v->eofflag,0, + (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i])); } } @@ -527,14 +539,14 @@ int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){ if(bp==-1){ if(v->eofflag==0)return(0); /* not enough data currently to search for a - full long block */ + full long block */ v->nW=0; }else{ if(ci->blocksizes[0]==ci->blocksizes[1]) - v->nW=0; + v->nW=0; else - v->nW=bp; + v->nW=bp; } } @@ -634,8 +646,8 @@ int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){ v->pcm_current-=movementW; for(i=0;ichannels;i++) - memmove(v->pcm[i],v->pcm[i]+movementW, - v->pcm_current*sizeof(*v->pcm[i])); + memmove(v->pcm[i],v->pcm[i]+movementW, + v->pcm_current*sizeof(*v->pcm[i])); v->lW=v->W; @@ -643,16 +655,16 @@ int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){ v->centerW=new_centerNext; if(v->eofflag){ - v->eofflag-=movementW; - if(v->eofflag<=0)v->eofflag=-1; - /* do not add padding to end of stream! */ - if(v->centerW>=v->eofflag){ - v->granulepos+=movementW-(v->centerW-v->eofflag); - }else{ - v->granulepos+=movementW; - } + v->eofflag-=movementW; + if(v->eofflag<=0)v->eofflag=-1; + /* do not add padding to end of stream! */ + if(v->centerW>=v->eofflag){ + v->granulepos+=movementW-(v->centerW-v->eofflag); + }else{ + v->granulepos+=movementW; + } }else{ - v->granulepos+=movementW; + v->granulepos+=movementW; } } } @@ -685,9 +697,11 @@ int vorbis_synthesis_restart(vorbis_dsp_state *v){ } int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){ - if(_vds_shared_init(v,vi,0)) return 1; + if(_vds_shared_init(v,vi,0)){ + vorbis_dsp_clear(v); + return 1; + } vorbis_synthesis_restart(v); - return 0; } @@ -718,7 +732,7 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){ v->sequence=vb->sequence; if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly - was called on block */ + was called on block */ int n=ci->blocksizes[v->W]>>(hs+1); int n0=ci->blocksizes[0]>>(hs+1); int n1=ci->blocksizes[1]>>(hs+1); @@ -746,47 +760,47 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){ for(j=0;jchannels;j++){ /* the overlap/add section */ if(v->lW){ - if(v->W){ - /* large/large */ - float *w=_vorbis_window_get(b->window[1]-hs); - float *pcm=v->pcm[j]+prevCenter; - float *p=vb->pcm[j]; - for(i=0;iwindow[0]-hs); - float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2; - float *p=vb->pcm[j]; - for(i=0;iW){ + /* large/large */ + float *w=_vorbis_window_get(b->window[1]-hs); + float *pcm=v->pcm[j]+prevCenter; + float *p=vb->pcm[j]; + for(i=0;iwindow[0]-hs); + float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2; + float *p=vb->pcm[j]; + for(i=0;iW){ - /* small/large */ - float *w=_vorbis_window_get(b->window[0]-hs); - float *pcm=v->pcm[j]+prevCenter; - float *p=vb->pcm[j]+n1/2-n0/2; - for(i=0;iwindow[0]-hs); - float *pcm=v->pcm[j]+prevCenter; - float *p=vb->pcm[j]; - for(i=0;iW){ + /* small/large */ + float *w=_vorbis_window_get(b->window[0]-hs); + float *pcm=v->pcm[j]+prevCenter; + float *p=vb->pcm[j]+n1/2-n0/2; + for(i=0;iwindow[0]-hs); + float *pcm=v->pcm[j]+prevCenter; + float *p=vb->pcm[j]; + for(i=0;ipcm[j]+thisCenter; - float *p=vb->pcm[j]+n; - for(i=0;ipcm[j]+thisCenter; + float *p=vb->pcm[j]+n; + for(i=0;ipcm_returned=prevCenter; v->pcm_current=prevCenter+ - ((ci->blocksizes[v->lW]/4+ - ci->blocksizes[v->W]/4)>>hs); + ((ci->blocksizes[v->lW]/4+ + ci->blocksizes[v->W]/4)>>hs); } } @@ -835,22 +849,22 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){ /* is this a short page? */ if(b->sample_count>v->granulepos){ - /* corner case; if this is both the first and last audio page, - then spec says the end is cut, not beginning */ - if(vb->eofflag){ - /* trim the end */ - /* no preceeding granulepos; assume we started at zero (we'd - have to in a short single-page stream) */ - /* granulepos could be -1 due to a seek, but that would result - in a long count, not short count */ - - v->pcm_current-=(b->sample_count-v->granulepos)>>hs; - }else{ - /* trim the beginning */ - v->pcm_returned+=(b->sample_count-v->granulepos)>>hs; - if(v->pcm_returned>v->pcm_current) - v->pcm_returned=v->pcm_current; - } + /* corner case; if this is both the first and last audio page, + then spec says the end is cut, not beginning */ + if(vb->eofflag){ + /* trim the end */ + /* no preceeding granulepos; assume we started at zero (we'd + have to in a short single-page stream) */ + /* granulepos could be -1 due to a seek, but that would result + in a long count, not short count */ + + v->pcm_current-=(b->sample_count-v->granulepos)>>hs; + }else{ + /* trim the beginning */ + v->pcm_returned+=(b->sample_count-v->granulepos)>>hs; + if(v->pcm_returned>v->pcm_current) + v->pcm_returned=v->pcm_current; + } } @@ -860,16 +874,16 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){ if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){ if(v->granulepos>vb->granulepos){ - long extra=v->granulepos-vb->granulepos; + long extra=v->granulepos-vb->granulepos; - if(extra) - if(vb->eofflag){ - /* partial last frame. Strip the extra samples off */ - v->pcm_current-=extra>>hs; - } /* else {Shouldn't happen *unless* the bitstream is out of - spec. Either way, believe the bitstream } */ + if(extra) + if(vb->eofflag){ + /* partial last frame. Strip the extra samples off */ + v->pcm_current-=extra>>hs; + } /* else {Shouldn't happen *unless* the bitstream is out of + spec. Either way, believe the bitstream } */ } /* else {Shouldn't happen *unless* the bitstream is out of - spec. Either way, believe the bitstream } */ + spec. Either way, believe the bitstream } */ v->granulepos=vb->granulepos; } } @@ -889,7 +903,7 @@ int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){ if(pcm){ int i; for(i=0;ichannels;i++) - v->pcmret[i]=v->pcm[i]+v->pcm_returned; + v->pcmret[i]=v->pcm[i]+v->pcm_returned; *pcm=v->pcmret; } return(v->pcm_current-v->pcm_returned); @@ -936,9 +950,9 @@ int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){ for(j=0;jchannels;j++){ float *p=v->pcm[j]; for(i=0;ipcm[j]; float *d=v->pcm[j]+(n1-n0)/2; for(i=(n1+n0)/2-1;i>=0;--i) - d[i]=s[i]; + d[i]=s[i]; } v->pcm_returned+=(n1-n0)/2; v->pcm_current+=(n1-n0)/2; @@ -962,10 +976,10 @@ int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){ if(v->lW==0){ /* short/short */ for(j=0;jchannels;j++){ - float *s=v->pcm[j]; - float *d=v->pcm[j]+n1-n0; - for(i=n0-1;i>=0;--i) - d[i]=s[i]; + float *s=v->pcm[j]; + float *d=v->pcm[j]+n1-n0; + for(i=n0-1;i>=0;--i) + d[i]=s[i]; } v->pcm_returned+=n1-n0; v->pcm_current+=n1-n0; @@ -992,4 +1006,4 @@ float *vorbis_window(vorbis_dsp_state *v,int W){ if(b->window[W]-1<0)return NULL; return _vorbis_window_get(b->window[W]-hs); } - + diff --git a/media/libvorbis/lib/vorbis_codebook.c b/media/libvorbis/lib/vorbis_codebook.c index 7bbefa387dc..482e40e8a11 100644 --- a/media/libvorbis/lib/vorbis_codebook.c +++ b/media/libvorbis/lib/vorbis_codebook.c @@ -11,7 +11,7 @@ ******************************************************************** function: basic codebook pack/unpack/code/decode operations - last mod: $Id: codebook.c 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -56,10 +56,10 @@ int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){ long this=c->lengthlist[i]; long last=c->lengthlist[i-1]; if(this>last){ - for(j=last;jentries-count)); - count=i; - } + for(j=last;jentries-count)); + count=i; + } } } oggpack_write(opb,i-count,_ilog(c->entries-count)); @@ -78,16 +78,16 @@ int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){ if(i==c->entries){ oggpack_write(opb,0,1); /* no unused entries */ for(i=0;ientries;i++) - oggpack_write(opb,c->lengthlist[i]-1,5); + oggpack_write(opb,c->lengthlist[i]-1,5); }else{ oggpack_write(opb,1,1); /* we have unused entries; thus we tag */ for(i=0;ientries;i++){ - if(c->lengthlist[i]==0){ - oggpack_write(opb,0,1); - }else{ - oggpack_write(opb,1,1); - oggpack_write(opb,c->lengthlist[i]-1,5); - } + if(c->lengthlist[i]==0){ + oggpack_write(opb,0,1); + }else{ + oggpack_write(opb,1,1); + oggpack_write(opb,c->lengthlist[i]-1,5); + } } } } @@ -118,21 +118,21 @@ int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){ int quantvals; switch(c->maptype){ case 1: - /* a single column of (c->entries/c->dim) quantized values for - building a full value list algorithmically (square lattice) */ - quantvals=_book_maptype1_quantvals(c); - break; + /* a single column of (c->entries/c->dim) quantized values for + building a full value list algorithmically (square lattice) */ + quantvals=_book_maptype1_quantvals(c); + break; case 2: - /* every value (c->entries*c->dim total) specified explicitly */ - quantvals=c->entries*c->dim; - break; + /* every value (c->entries*c->dim total) specified explicitly */ + quantvals=c->entries*c->dim; + break; default: /* NOT_REACHABLE */ - quantvals=-1; + quantvals=-1; } /* quantized values */ for(i=0;iquantlist[i]),c->q_quant); + oggpack_write(opb,labs(c->quantlist[i]),c->q_quant); } break; @@ -159,6 +159,8 @@ int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){ s->entries=oggpack_read(opb,24); if(s->entries==-1)goto _eofout; + if(_ilog(s->dim)+_ilog(s->entries)>24)goto _eofout; + /* codeword ordering.... length ordered or unordered? */ switch((int)oggpack_read(opb,1)){ case 0: @@ -170,19 +172,19 @@ int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){ /* yes, unused entries */ for(i=0;ientries;i++){ - if(oggpack_read(opb,1)){ - long num=oggpack_read(opb,5); - if(num==-1)goto _eofout; - s->lengthlist[i]=num+1; - }else - s->lengthlist[i]=0; + if(oggpack_read(opb,1)){ + long num=oggpack_read(opb,5); + if(num==-1)goto _eofout; + s->lengthlist[i]=num+1; + }else + s->lengthlist[i]=0; } }else{ /* all entries used; no tagging */ for(i=0;ientries;i++){ - long num=oggpack_read(opb,5); - if(num==-1)goto _eofout; - s->lengthlist[i]=num+1; + long num=oggpack_read(opb,5); + if(num==-1)goto _eofout; + s->lengthlist[i]=num+1; } } @@ -194,11 +196,11 @@ int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){ s->lengthlist=_ogg_malloc(sizeof(*s->lengthlist)*s->entries); for(i=0;ientries;){ - long num=oggpack_read(opb,_ilog(s->entries-i)); - if(num==-1)goto _eofout; - for(j=0;jentries;j++,i++) - s->lengthlist[i]=length; - length++; + long num=oggpack_read(opb,_ilog(s->entries-i)); + if(num==-1)goto _eofout; + for(j=0;jentries;j++,i++) + s->lengthlist[i]=length; + length++; } } break; @@ -225,17 +227,17 @@ int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){ int quantvals=0; switch(s->maptype){ case 1: - quantvals=_book_maptype1_quantvals(s); - break; + quantvals=(s->dim==0?0:_book_maptype1_quantvals(s)); + break; case 2: - quantvals=s->entries*s->dim; - break; + quantvals=s->entries*s->dim; + break; } /* quantized values */ s->quantlist=_ogg_malloc(sizeof(*s->quantlist)*quantvals); for(i=0;iquantlist[i]=oggpack_read(opb,s->q_quant); + s->quantlist[i]=oggpack_read(opb,s->q_quant); if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout; } @@ -395,7 +397,7 @@ long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){ } for(i=0,o=0;idim;i++,o+=step) for (j=0;jdim>8){ for(i=0;ivaluelist+entry*book->dim; - for (j=0;jdim;) - a[i++]+=t[j++]; + entry = decode_packed_entry_number(book,b); + if(entry==-1)return(-1); + t = book->valuelist+entry*book->dim; + for (j=0;jdim;) + a[i++]+=t[j++]; } }else{ for(i=0;ivaluelist+entry*book->dim; - j=0; - switch((int)book->dim){ - case 8: - a[i++]+=t[j++]; - case 7: - a[i++]+=t[j++]; - case 6: - a[i++]+=t[j++]; - case 5: - a[i++]+=t[j++]; - case 4: - a[i++]+=t[j++]; - case 3: - a[i++]+=t[j++]; - case 2: - a[i++]+=t[j++]; - case 1: - a[i++]+=t[j++]; - case 0: - break; - } + entry = decode_packed_entry_number(book,b); + if(entry==-1)return(-1); + t = book->valuelist+entry*book->dim; + j=0; + switch((int)book->dim){ + case 8: + a[i++]+=t[j++]; + case 7: + a[i++]+=t[j++]; + case 6: + a[i++]+=t[j++]; + case 5: + a[i++]+=t[j++]; + case 4: + a[i++]+=t[j++]; + case 3: + a[i++]+=t[j++]; + case 2: + a[i++]+=t[j++]; + case 1: + a[i++]+=t[j++]; + case 0: + break; + } } } } @@ -455,21 +457,21 @@ long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){ if(entry==-1)return(-1); t = book->valuelist+entry*book->dim; for (j=0;jdim;) - a[i++]=t[j++]; + a[i++]=t[j++]; } }else{ int i,j; for(i=0;idim;) - a[i++]=0.f; + a[i++]=0.f; } } return(0); } long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch, - oggpack_buffer *b,int n){ + oggpack_buffer *b,int n){ long i,j,entry; int chptr=0; @@ -478,14 +480,14 @@ long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch, entry = decode_packed_entry_number(book,b); if(entry==-1)return(-1); { - const float *t = book->valuelist+entry*book->dim; - for (j=0;jdim;j++){ - a[chptr++][i]+=t[j]; - if(chptr==ch){ - chptr=0; - i++; - } - } + const float *t = book->valuelist+entry*book->dim; + for (j=0;jdim;j++){ + a[chptr++][i]+=t[j]; + if(chptr==ch){ + chptr=0; + i++; + } + } } } } @@ -563,7 +565,7 @@ float test3[TESTSIZE]={ 30,-25,-30,-1,-5,-32,4,3,-2,0}; static_codebook *testlist[]={&_vq_book_lsp20_0, - &_vq_book_res0a_13,NULL}; + &_vq_book_res0a_13,NULL}; float *testvec[]={test1,test3}; int main(){ @@ -612,16 +614,16 @@ int main(){ for(i=0;i.000001){ - fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n", - iv[i],qv[i],i); - exit(1); + fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n", + iv[i],qv[i],i); + exit(1); } - + fprintf(stderr,"OK\n"); ptr++; } diff --git a/media/libvorbis/lib/vorbis_envelope.c b/media/libvorbis/lib/vorbis_envelope.c index 9cb9341374a..8308c2e19a0 100644 --- a/media/libvorbis/lib/vorbis_envelope.c +++ b/media/libvorbis/lib/vorbis_envelope.c @@ -11,7 +11,7 @@ ******************************************************************** function: PCM data envelope analysis - last mod: $Id: envelope.c 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -88,11 +88,10 @@ void _ve_envelope_clear(envelope_lookup *e){ that works better and isn't patented. */ static int _ve_amp(envelope_lookup *ve, - vorbis_info_psy_global *gi, - float *data, - envelope_band *bands, - envelope_filter_state *filters, - long pos){ + vorbis_info_psy_global *gi, + float *data, + envelope_band *bands, + envelope_filter_state *filters){ long n=ve->winlength; int ret=0; long i,j; @@ -183,10 +182,10 @@ static int _ve_amp(envelope_lookup *ve, postmin=min(acc,filters[j].ampbuf[p]); for(i=0;ich;i++){ float *pcm=v->pcm[i]+ve->searchstep*(j); - ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j); + ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS); } ve->mark[j+VE_POST]=0; @@ -276,50 +275,50 @@ long _ve_envelope_search(vorbis_dsp_state *v){ ve->cursor=j; if(ve->mark[j/ve->searchstep]){ - if(j>centerW){ + if(j>centerW){ #if 0 - if(j>ve->curmark){ - float *marker=alloca(v->pcm_current*sizeof(*marker)); - int l,m; - memset(marker,0,sizeof(*marker)*v->pcm_current); - fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n", - seq, - (totalshift+ve->cursor)/44100., - (totalshift+j)/44100.); - _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift); - _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift); + if(j>ve->curmark){ + float *marker=alloca(v->pcm_current*sizeof(*marker)); + int l,m; + memset(marker,0,sizeof(*marker)*v->pcm_current); + fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n", + seq, + (totalshift+ve->cursor)/44100., + (totalshift+j)/44100.); + _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift); + _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift); - _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift); - _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift); - - for(m=0;msearchstep]=ve->filter[m].markers[l]*.1; - _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift); - } + _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift); + _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift); + + for(m=0;msearchstep]=ve->filter[m].markers[l]*.1; + _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift); + } - for(m=0;msearchstep]=ve->filter[m+VE_BANDS].markers[l]*.1; - _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift); - } + for(m=0;msearchstep]=ve->filter[m+VE_BANDS].markers[l]*.1; + _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift); + } - for(l=0;lsearchstep]=ve->mark[l]*.4; - _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift); - - - seq++; - - } + for(l=0;lsearchstep]=ve->mark[l]*.4; + _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift); + + + seq++; + + } #endif - ve->curmark=j; - if(j>=testW)return(1); - return(0); - } + ve->curmark=j; + if(j>=testW)return(1); + return(0); + } } j+=ve->searchstep; } @@ -356,7 +355,7 @@ int _ve_envelope_mark(vorbis_dsp_state *v){ void _ve_envelope_shift(envelope_lookup *e,long shift){ int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks - ahead of ve->current */ + ahead of ve->current */ int smallshift=shift/e->searchstep; memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark)); @@ -364,8 +363,8 @@ void _ve_envelope_shift(envelope_lookup *e,long shift){ #if 0 for(i=0;ich;i++) memmove(e->filter[i].markers, - e->filter[i].markers+smallshift, - (1024-smallshift)*sizeof(*(*e->filter).markers)); + e->filter[i].markers+smallshift, + (1024-smallshift)*sizeof(*(*e->filter).markers)); totalshift+=shift; #endif diff --git a/media/libvorbis/lib/vorbis_floor0.c b/media/libvorbis/lib/vorbis_floor0.c index be6021b6510..687afdeea4f 100644 --- a/media/libvorbis/lib/vorbis_floor0.c +++ b/media/libvorbis/lib/vorbis_floor0.c @@ -11,7 +11,7 @@ ******************************************************************** function: floor backend 0 implementation - last mod: $Id: floor0.c 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -108,8 +108,8 @@ static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){ linear block and mapping sizes */ static void floor0_map_lazy_init(vorbis_block *vb, - vorbis_info_floor *infoX, - vorbis_look_floor0 *look){ + vorbis_info_floor *infoX, + vorbis_look_floor0 *look){ if(!look->linearmap[vb->W]){ vorbis_dsp_state *vd=vb->vd; vorbis_info *vi=vd->vi; @@ -132,7 +132,7 @@ static void floor0_map_lazy_init(vorbis_block *vb, look->linearmap[W]=_ogg_malloc((n+1)*sizeof(**look->linearmap)); for(j=0;jrate/2.f)/n*j) - *scale); /* bark numbers represent band edges */ + *scale); /* bark numbers represent band edges */ if(val>=look->ln)val=look->ln-1; /* guard against the approximation */ look->linearmap[W][j]=val; } @@ -142,7 +142,7 @@ static void floor0_map_lazy_init(vorbis_block *vb, } static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd, - vorbis_info_floor *i){ + vorbis_info_floor *i){ vorbis_info_floor0 *info=(vorbis_info_floor0 *)i; vorbis_look_floor0 *look=_ogg_calloc(1,sizeof(*look)); look->m=info->order; @@ -176,10 +176,10 @@ static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){ float *lsp=_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1)); for(j=0;jm;j+=b->dim) - if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop; + if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop; for(j=0;jm;){ - for(k=0;kdim;k++,j++)lsp[j]+=last; - last=lsp[j-1]; + for(k=0;kdim;k++,j++)lsp[j]+=last; + last=lsp[j-1]; } lsp[look->m]=amp; @@ -191,7 +191,7 @@ static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){ } static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i, - void *memo,float *out){ + void *memo,float *out){ vorbis_look_floor0 *look=(vorbis_look_floor0 *)i; vorbis_info_floor0 *info=look->vi; @@ -203,10 +203,10 @@ static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i, /* take the coefficients back to a spectral envelope curve */ vorbis_lsp_to_curve(out, - look->linearmap[vb->W], - look->n[vb->W], - look->ln, - lsp,look->m,amp,(float)info->ampdB); + look->linearmap[vb->W], + look->n[vb->W], + look->ln, + lsp,look->m,amp,(float)info->ampdB); return(1); } memset(out,0,sizeof(*out)*look->n[vb->W]); @@ -214,7 +214,7 @@ static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i, } /* export hooks */ -vorbis_func_floor floor0_exportbundle={ +const vorbis_func_floor floor0_exportbundle={ NULL,&floor0_unpack,&floor0_look,&floor0_free_info, &floor0_free_look,&floor0_inverse1,&floor0_inverse2 }; diff --git a/media/libvorbis/lib/vorbis_floor1.c b/media/libvorbis/lib/vorbis_floor1.c index 0e06c6dbc3c..6d47459137c 100644 --- a/media/libvorbis/lib/vorbis_floor1.c +++ b/media/libvorbis/lib/vorbis_floor1.c @@ -11,7 +11,7 @@ ******************************************************************** function: floor backend 1 implementation - last mod: $Id: floor1.c 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -30,24 +30,6 @@ #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */ -typedef struct { - int sorted_index[VIF_POSIT+2]; - int forward_index[VIF_POSIT+2]; - int reverse_index[VIF_POSIT+2]; - - int hineighbor[VIF_POSIT]; - int loneighbor[VIF_POSIT]; - int posts; - - int n; - int quant_q; - vorbis_info_floor1 *vi; - - long phrasebits; - long postbits; - long frames; -} vorbis_look_floor1; - typedef struct lsfit_acc{ long x0; long x1; @@ -74,9 +56,9 @@ static void floor1_free_look(vorbis_look_floor *i){ vorbis_look_floor1 *look=(vorbis_look_floor1 *)i; if(look){ /*fprintf(stderr,"floor 1 bit usage %f:%f (%f total)\n", - (float)look->phrasebits/look->frames, - (float)look->postbits/look->frames, - (float)(look->postbits+look->phrasebits)/look->frames);*/ + (float)look->phrasebits/look->frames, + (float)look->postbits/look->frames, + (float)(look->postbits+look->phrasebits)/look->frames);*/ memset(look,0,sizeof(*look)); _ogg_free(look); @@ -138,6 +120,9 @@ static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){ } } +static int icomp(const void *a,const void *b){ + return(**(int **)a-**(int **)b); +} static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){ codec_setup_info *ci=vi->codec_setup; @@ -163,7 +148,7 @@ static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){ for(k=0;k<(1<class_subs[j]);k++){ info->class_subbook[j][k]=oggpack_read(opb,8)-1; if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books) - goto err_out; + goto err_out; } } @@ -176,25 +161,32 @@ static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){ for(;kpostlist[k+2]=oggpack_read(opb,rangebits); if(t<0 || t>=(1<postlist[0]=0; info->postlist[1]=1<postlist+j; + qsort(sortpointer,count+2,sizeof(*sortpointer),icomp); + + for(j=1;jreverse_index[look->forward_index[i]]=i; /* we actually need the post values too */ for(i=0;isorted_index[i]=info->postlist[look->forward_index[i]]; - + /* quantize values to multiplier spec */ switch(info->mult){ case 1: /* 1024 -> 256 */ @@ -253,12 +245,12 @@ static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd, for(j=0;jpostlist[j]; if(x>lx && xcurrentx){ - hi=j; - hx=x; + hi=j; + hx=x; } } look->loneighbor[i]=lo; @@ -271,13 +263,13 @@ static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd, static int render_point(int x0,int x1,int y0,int y1,int x){ y0&=0x7fff; /* mask off flag */ y1&=0x7fff; - + { int dy=y1-y0; int adx=x1-x0; int ady=abs(dy); int err=ady*(x-x0); - + int off=err/adx; if(dy<0)return(y0-off); return(y0+off); @@ -291,7 +283,7 @@ static int vorbis_dBquant(const float *x){ return i; } -static float FLOOR1_fromdB_LOOKUP[256]={ +static const float FLOOR1_fromdB_LOOKUP[256]={ 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F, 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F, 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F, @@ -414,10 +406,9 @@ static void render_line0(int x0,int x1,int y0,int y1,int *d){ /* the floor has already been filtered to only include relevant sections */ static int accumulate_fit(const float *flr,const float *mdct, - int x0, int x1,lsfit_acc *a, - int n,vorbis_info_floor1 *info){ + int x0, int x1,lsfit_acc *a, + int n,vorbis_info_floor1 *info){ long i; - int quantized=vorbis_dBquant(flr+x0); long xa=0,ya=0,x2a=0,y2a=0,xya=0,na=0, xb=0,yb=0,x2b=0,y2b=0,xyb=0,nb=0; @@ -430,19 +421,19 @@ static int accumulate_fit(const float *flr,const float *mdct, int quantized=vorbis_dBquant(flr+i); if(quantized){ if(mdct[i]+info->twofitatten>=flr[i]){ - xa += i; - ya += quantized; - x2a += i*i; - y2a += quantized*quantized; - xya += i*quantized; - na++; + xa += i; + ya += quantized; + x2a += i*i; + y2a += quantized*quantized; + xya += i*quantized; + na++; }else{ - xb += i; - yb += quantized; - x2b += i*i; - y2b += quantized*quantized; - xyb += i*quantized; - nb++; + xb += i; + yb += quantized; + x2b += i*i; + y2b += quantized*quantized; + xyb += i*quantized; + nb++; } } } @@ -469,7 +460,7 @@ static int accumulate_fit(const float *flr,const float *mdct, return(na); } -static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){ +static int fit_line(lsfit_acc *a,int fits,int *y0,int *y1){ long x=0,y=0,x2=0,y2=0,xy=0,an=0,i; long x0=a[0].x0; long x1=a[fits-1].x1; @@ -500,28 +491,34 @@ static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){ xy+= *y1 * x1; an++; } - - if(an){ + + { /* need 64 bit multiplies, which C doesn't give portably as int */ double fx=x; - double fy=y; double fx2=x2; - double fxy=xy; - double denom=1./(an*fx2-fx*fx); - double a=(fy*fx2-fxy*fx)*denom; - double b=(an*fxy-fx*fy)*denom; - *y0=rint(a+b*x0); - *y1=rint(a+b*x1); - - /* limit to our range! */ - if(*y0>1023)*y0=1023; - if(*y1>1023)*y1=1023; - if(*y0<0)*y0=0; - if(*y1<0)*y1=0; - - }else{ - *y0=0; - *y1=0; + double denom=(an*fx2-fx*fx); + + if(denom>0.){ + double fy=y; + double fxy=xy; + + double a=(fy*fx2-fxy*fx)/denom; + double b=(an*fxy-fx*fy)/denom; + *y0=rint(a+b*x0); + *y1=rint(a+b*x1); + + /* limit to our range! */ + if(*y0>1023)*y0=1023; + if(*y1>1023)*y1=1023; + if(*y0<0)*y0=0; + if(*y1<0)*y1=0; + + return 0; + }else{ + *y0=0; + *y1=0; + return 1; + } } } @@ -531,13 +528,13 @@ static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){ for(i=0;itwofitatten>=mask[x]){ if(val){ - if(y+info->maxovermaxunder>val)return(1); + if(y+info->maxovermaxunder>val)return(1); } } } - + if(info->maxover*info->maxover/n>info->maxerr)return(0); if(info->maxunder*info->maxunder/n>info->maxerr)return(0); if(mse/n>info->maxerr)return(1); @@ -595,11 +592,9 @@ static int post_Y(int *A,int *B,int pos){ return (A[pos]+B[pos])>>1; } -static int seq=0; - int *floor1_fit(vorbis_block *vb,vorbis_look_floor1 *look, - const float *logmdct, /* in */ - const float *logmask){ + const float *logmdct, /* in */ + const float *logmask){ long i,j; vorbis_info_floor1 *info=look->vi; long n=look->n; @@ -627,8 +622,8 @@ int *floor1_fit(vorbis_block *vb,vorbis_look_floor1 *look, }else{ for(i=0;isorted_index[i], - look->sorted_index[i+1],fits+i, - n,info); + look->sorted_index[i+1],fits+i, + n,info); } if(nonzero){ @@ -650,70 +645,82 @@ int *floor1_fit(vorbis_block *vb,vorbis_look_floor1 *look, int sortpos=look->reverse_index[i]; int ln=loneighbor[sortpos]; int hn=hineighbor[sortpos]; - + /* eliminate repeat searches of a particular range with a memo */ if(memo[ln]!=hn){ - /* haven't performed this error search yet */ - int lsortpos=look->reverse_index[ln]; - int hsortpos=look->reverse_index[hn]; - memo[ln]=hn; - - { - /* A note: we want to bound/minimize *local*, not global, error */ - int lx=info->postlist[ln]; - int hx=info->postlist[hn]; - int ly=post_Y(fit_valueA,fit_valueB,ln); - int hy=post_Y(fit_valueA,fit_valueB,hn); - - if(ly==-1 || hy==-1){ - exit(1); - } + /* haven't performed this error search yet */ + int lsortpos=look->reverse_index[ln]; + int hsortpos=look->reverse_index[hn]; + memo[ln]=hn; + + { + /* A note: we want to bound/minimize *local*, not global, error */ + int lx=info->postlist[ln]; + int hx=info->postlist[hn]; + int ly=post_Y(fit_valueA,fit_valueB,ln); + int hy=post_Y(fit_valueA,fit_valueB,hn); - if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){ - /* outside error bounds/begin search area. Split it. */ - int ly0=-200; - int ly1=-200; - int hy0=-200; - int hy1=-200; - fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1); - fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1); - - /* store new edge values */ - fit_valueB[ln]=ly0; - if(ln==0)fit_valueA[ln]=ly0; - fit_valueA[i]=ly1; - fit_valueB[i]=hy0; - fit_valueA[hn]=hy1; - if(hn==1)fit_valueB[hn]=hy1; - - if(ly1>=0 || hy0>=0){ - /* store new neighbor values */ - for(j=sortpos-1;j>=0;j--) - if(hineighbor[j]==hn) - hineighbor[j]=i; - else - break; - for(j=sortpos+1;j=0 || hy0>=0){ + /* store new neighbor values */ + for(j=sortpos-1;j>=0;j--) + if(hineighbor[j]==hn) + hineighbor[j]=i; + else + break; + for(j=sortpos+1;jpostlist[hn]; int y0=output[ln]; int y1=output[hn]; - + int predicted=render_point(x0,x1,y0,y1,info->postlist[i]); int vx=post_Y(fit_valueA,fit_valueB,i); - + if(vx>=0 && predicted!=vx){ - output[i]=vx; + output[i]=vx; }else{ - output[i]= predicted|0x8000; + output[i]= predicted|0x8000; } } } return(output); - + } - + int *floor1_interpolate_fit(vorbis_block *vb,vorbis_look_floor1 *look, - int *A,int *B, - int del){ + int *A,int *B, + int del){ long i; long posts=look->posts; int *output=NULL; - + if(A && B){ output=_vorbis_block_alloc(vb,sizeof(*output)*posts); - + + /* overly simpleminded--- look again post 1.2 */ for(i=0;i>16; if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000; @@ -762,18 +770,16 @@ int *floor1_interpolate_fit(vorbis_block *vb,vorbis_look_floor1 *look, int floor1_encode(oggpack_buffer *opb,vorbis_block *vb, - vorbis_look_floor1 *look, - int *post,int *ilogmask){ + vorbis_look_floor1 *look, + int *post,int *ilogmask){ long i,j; vorbis_info_floor1 *info=look->vi; - long n=look->n; long posts=look->posts; codec_setup_info *ci=vb->vd->vi->codec_setup; int out[VIF_POSIT+2]; static_codebook **sbooks=ci->book_param; codebook *books=ci->fullbooks; - static long seq=0; /* quantize values to multiplier spec */ if(post){ @@ -781,17 +787,17 @@ int floor1_encode(oggpack_buffer *opb,vorbis_block *vb, int val=post[i]&0x7fff; switch(info->mult){ case 1: /* 1024 -> 256 */ - val>>=2; - break; + val>>=2; + break; case 2: /* 1024 -> 128 */ - val>>=3; - break; + val>>=3; + break; case 3: /* 1024 -> 86 */ - val/=12; - break; + val/=12; + break; case 4: /* 1024 -> 64 */ - val>>=4; - break; + val>>=4; + break; } post[i]=val | (post[i]&0x8000); } @@ -807,53 +813,53 @@ int floor1_encode(oggpack_buffer *opb,vorbis_block *vb, int x1=info->postlist[hn]; int y0=post[ln]; int y1=post[hn]; - + int predicted=render_point(x0,x1,y0,y1,info->postlist[i]); - + if((post[i]&0x8000) || (predicted==post[i])){ - post[i]=predicted|0x8000; /* in case there was roundoff jitter - in interpolation */ - out[i]=0; + post[i]=predicted|0x8000; /* in case there was roundoff jitter + in interpolation */ + out[i]=0; }else{ - int headroom=(look->quant_q-predictedquant_q-predicted:predicted); - - int val=post[i]-predicted; - - /* at this point the 'deviation' value is in the range +/- max - range, but the real, unique range can always be mapped to - only [0-maxrange). So we want to wrap the deviation into - this limited range, but do it in the way that least screws - an essentially gaussian probability distribution. */ - - if(val<0) - if(val<-headroom) - val=headroom-val-1; - else - val=-1-(val<<1); - else - if(val>=headroom) - val= val+headroom; - else - val<<=1; - - out[i]=val; - post[ln]&=0x7fff; - post[hn]&=0x7fff; + int headroom=(look->quant_q-predictedquant_q-predicted:predicted); + + int val=post[i]-predicted; + + /* at this point the 'deviation' value is in the range +/- max + range, but the real, unique range can always be mapped to + only [0-maxrange). So we want to wrap the deviation into + this limited range, but do it in the way that least screws + an essentially gaussian probability distribution. */ + + if(val<0) + if(val<-headroom) + val=headroom-val-1; + else + val=-1-(val<<1); + else + if(val>=headroom) + val= val+headroom; + else + val<<=1; + + out[i]=val; + post[ln]&=0x7fff; + post[hn]&=0x7fff; } } - + /* we have everything we need. pack it out */ /* mark nontrivial floor */ oggpack_write(opb,1,1); - + /* beginning/end post */ look->frames++; look->postbits+=ilog(look->quant_q-1)*2; oggpack_write(opb,out[0],ilog(look->quant_q-1)); oggpack_write(opb,out[1],ilog(look->quant_q-1)); - - + + /* partition by partition */ for(i=0,j=2;ipartitions;i++){ int class=info->partitionclass[i]; @@ -867,70 +873,70 @@ int floor1_encode(oggpack_buffer *opb,vorbis_block *vb, /* generate the partition's first stage cascade value */ if(csubbits){ - int maxval[8]; - for(k=0;kclass_subbook[class][k]; - if(booknum<0){ - maxval[k]=1; - }else{ - maxval[k]=sbooks[info->class_subbook[class][k]]->entries; - } - } - for(k=0;kphrasebits+= - vorbis_book_encode(books+info->class_book[class],cval,opb); - + int maxval[8]; + for(k=0;kclass_subbook[class][k]; + if(booknum<0){ + maxval[k]=1; + }else{ + maxval[k]=sbooks[info->class_subbook[class][k]]->entries; + } + } + for(k=0;kphrasebits+= + vorbis_book_encode(books+info->class_book[class],cval,opb); + #ifdef TRAIN_FLOOR1 - { - FILE *of; - char buffer[80]; - sprintf(buffer,"line_%dx%ld_class%d.vqd", - vb->pcmend/2,posts-2,class); - of=fopen(buffer,"a"); - fprintf(of,"%d\n",cval); - fclose(of); - } + { + FILE *of; + char buffer[80]; + sprintf(buffer,"line_%dx%ld_class%d.vqd", + vb->pcmend/2,posts-2,class); + of=fopen(buffer,"a"); + fprintf(of,"%d\n",cval); + fclose(of); + } #endif } - + /* write post values */ for(k=0;kclass_subbook[class][bookas[k]]; - if(book>=0){ - /* hack to allow training with 'bad' books */ - if(out[j+k]<(books+book)->entries) - look->postbits+=vorbis_book_encode(books+book, - out[j+k],opb); - /*else - fprintf(stderr,"+!");*/ - + int book=info->class_subbook[class][bookas[k]]; + if(book>=0){ + /* hack to allow training with 'bad' books */ + if(out[j+k]<(books+book)->entries) + look->postbits+=vorbis_book_encode(books+book, + out[j+k],opb); + /*else + fprintf(stderr,"+!");*/ + #ifdef TRAIN_FLOOR1 - { - FILE *of; - char buffer[80]; - sprintf(buffer,"line_%dx%ld_%dsub%d.vqd", - vb->pcmend/2,posts-2,class,bookas[k]); - of=fopen(buffer,"a"); - fprintf(of,"%d\n",out[j+k]); - fclose(of); - } + { + FILE *of; + char buffer[80]; + sprintf(buffer,"line_%dx%ld_%dsub%d.vqd", + vb->pcmend/2,posts-2,class,bookas[k]); + of=fopen(buffer,"a"); + fprintf(of,"%d\n",out[j+k]); + fclose(of); + } #endif - } + } } j+=cdim; } - + { /* generate quantized floor equivalent to what we'd unpack in decode */ /* render the lines */ @@ -938,27 +944,25 @@ int floor1_encode(oggpack_buffer *opb,vorbis_block *vb, int lx=0; int ly=post[0]*info->mult; for(j=1;jposts;j++){ - int current=look->forward_index[j]; - int hy=post[current]&0x7fff; - if(hy==post[current]){ - - hy*=info->mult; - hx=info->postlist[current]; - - render_line0(lx,hx,ly,hy,ilogmask); - - lx=hx; - ly=hy; - } + int current=look->forward_index[j]; + int hy=post[current]&0x7fff; + if(hy==post[current]){ + + hy*=info->mult; + hx=info->postlist[current]; + + render_line0(lx,hx,ly,hy,ilogmask); + + lx=hx; + ly=hy; + } } - for(j=hx;jpcmend/2;j++)ilogmask[j]=ly; /* be certain */ - seq++; + for(j=hx;jpcmend/2;j++)ilogmask[j]=ly; /* be certain */ return(1); } }else{ oggpack_write(opb,0,1); memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask)); - seq++; return(0); } } @@ -967,9 +971,9 @@ static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){ vorbis_look_floor1 *look=(vorbis_look_floor1 *)in; vorbis_info_floor1 *info=look->vi; codec_setup_info *ci=vb->vd->vi->codec_setup; - + int i,j,k; - codebook *books=ci->fullbooks; + codebook *books=ci->fullbooks; /* unpack wrapped/predicted values from stream */ if(oggpack_read(&vb->opb,1)==1){ @@ -988,20 +992,20 @@ static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){ /* decode the partition's first stage cascade value */ if(csubbits){ - cval=vorbis_book_decode(books+info->class_book[class],&vb->opb); + cval=vorbis_book_decode(books+info->class_book[class],&vb->opb); - if(cval==-1)goto eop; + if(cval==-1)goto eop; } for(k=0;kclass_subbook[class][cval&(csub-1)]; - cval>>=csubbits; - if(book>=0){ - if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1) - goto eop; - }else{ - fit_value[j+k]=0; - } + int book=info->class_subbook[class][cval&(csub-1)]; + cval>>=csubbits; + if(book>=0){ + if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1) + goto eop; + }else{ + fit_value[j+k]=0; + } } j+=cdim; } @@ -1009,38 +1013,38 @@ static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){ /* unwrap positive values and reconsitute via linear interpolation */ for(i=2;iposts;i++){ int predicted=render_point(info->postlist[look->loneighbor[i-2]], - info->postlist[look->hineighbor[i-2]], - fit_value[look->loneighbor[i-2]], - fit_value[look->hineighbor[i-2]], - info->postlist[i]); + info->postlist[look->hineighbor[i-2]], + fit_value[look->loneighbor[i-2]], + fit_value[look->hineighbor[i-2]], + info->postlist[i]); int hiroom=look->quant_q-predicted; int loroom=predicted; int room=(hiroom=room){ - if(hiroom>loroom){ - val = val-loroom; - }else{ - val = -1-(val-hiroom); - } - }else{ - if(val&1){ - val= -((val+1)>>1); - }else{ - val>>=1; - } - } + if(val>=room){ + if(hiroom>loroom){ + val = val-loroom; + }else{ + val = -1-(val-hiroom); + } + }else{ + if(val&1){ + val= -((val+1)>>1); + }else{ + val>>=1; + } + } - fit_value[i]=val+predicted; - fit_value[look->loneighbor[i-2]]&=0x7fff; - fit_value[look->hineighbor[i-2]]&=0x7fff; + fit_value[i]=val+predicted; + fit_value[look->loneighbor[i-2]]&=0x7fff; + fit_value[look->hineighbor[i-2]]&=0x7fff; }else{ - fit_value[i]=predicted|0x8000; + fit_value[i]=predicted|0x8000; } - + } return(fit_value); @@ -1050,7 +1054,7 @@ static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){ } static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo, - float *out){ + float *out){ vorbis_look_floor1 *look=(vorbis_look_floor1 *)in; vorbis_info_floor1 *info=look->vi; @@ -1068,17 +1072,17 @@ static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo, int current=look->forward_index[j]; int hy=fit_value[current]&0x7fff; if(hy==fit_value[current]){ - - hy*=info->mult; - hx=info->postlist[current]; - - render_line(n,lx,hx,ly,hy,out); - - lx=hx; - ly=hy; + + hy*=info->mult; + hx=info->postlist[current]; + + render_line(n,lx,hx,ly,hy,out); + + lx=hx; + ly=hy; } } - for(j=hx;j header packets - last mod: $Id: info.c 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -32,6 +32,9 @@ #include "misc.h" #include "os.h" +#define GENERAL_VENDOR_STRING "Xiph.Org libVorbis 1.2.2" +#define ENCODE_VENDOR_STRING "Xiph.Org libVorbis I 20090624" + /* helpers */ static int ilog2(unsigned int v){ int ret=0; @@ -43,7 +46,7 @@ static int ilog2(unsigned int v){ return(ret); } -static void _v_writestring(oggpack_buffer *o,char *s, int bytes){ +static void _v_writestring(oggpack_buffer *o,const char *s, int bytes){ while(bytes--){ oggpack_write(o,*s++,8); @@ -60,11 +63,11 @@ void vorbis_comment_init(vorbis_comment *vc){ memset(vc,0,sizeof(*vc)); } -void vorbis_comment_add(vorbis_comment *vc,char *comment){ +void vorbis_comment_add(vorbis_comment *vc,const char *comment){ vc->user_comments=_ogg_realloc(vc->user_comments, - (vc->comments+2)*sizeof(*vc->user_comments)); + (vc->comments+2)*sizeof(*vc->user_comments)); vc->comment_lengths=_ogg_realloc(vc->comment_lengths, - (vc->comments+2)*sizeof(*vc->comment_lengths)); + (vc->comments+2)*sizeof(*vc->comment_lengths)); vc->comment_lengths[vc->comments]=strlen(comment); vc->user_comments[vc->comments]=_ogg_malloc(vc->comment_lengths[vc->comments]+1); strcpy(vc->user_comments[vc->comments], comment); @@ -72,7 +75,7 @@ void vorbis_comment_add(vorbis_comment *vc,char *comment){ vc->user_comments[vc->comments]=NULL; } -void vorbis_comment_add_tag(vorbis_comment *vc, char *tag, char *contents){ +void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, const char *contents){ char *comment=alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */ strcpy(comment, tag); strcat(comment, "="); @@ -92,7 +95,7 @@ static int tagcompare(const char *s1, const char *s2, int n){ return 0; } -char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){ +char *vorbis_comment_query(vorbis_comment *vc, const char *tag, int count){ long i; int found = 0; int taglen = strlen(tag)+1; /* +1 for the = we append */ @@ -104,16 +107,16 @@ char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){ for(i=0;icomments;i++){ if(!tagcompare(vc->user_comments[i], fulltag, taglen)){ if(count == found) - /* We return a pointer to the data, not a copy */ - return vc->user_comments[i] + taglen; + /* We return a pointer to the data, not a copy */ + return vc->user_comments[i] + taglen; else - found++; + found++; } } return NULL; /* didn't find anything */ } -int vorbis_comment_query_count(vorbis_comment *vc, char *tag){ +int vorbis_comment_query_count(vorbis_comment *vc, const char *tag){ int i,count=0; int taglen = strlen(tag)+1; /* +1 for the = we append */ char *fulltag = alloca(taglen+1); @@ -131,9 +134,9 @@ int vorbis_comment_query_count(vorbis_comment *vc, char *tag){ void vorbis_comment_clear(vorbis_comment *vc){ if(vc){ long i; - if (vc->user_comments) { + if(vc->user_comments){ for(i=0;icomments;i++) - if(vc->user_comments[i])_ogg_free(vc->user_comments[i]); + if(vc->user_comments[i])_ogg_free(vc->user_comments[i]); _ogg_free(vc->user_comments); } if(vc->comment_lengths)_ogg_free(vc->comment_lengths); @@ -166,32 +169,32 @@ void vorbis_info_clear(vorbis_info *vi){ for(i=0;imaps;i++) /* unpack does the range checking */ if(ci->map_param[i]) /* this may be cleaning up an aborted - unpack, in which case the below type - cannot be trusted */ - _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]); + unpack, in which case the below type + cannot be trusted */ + _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]); for(i=0;ifloors;i++) /* unpack does the range checking */ if(ci->floor_param[i]) /* this may be cleaning up an aborted - unpack, in which case the below type - cannot be trusted */ - _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]); + unpack, in which case the below type + cannot be trusted */ + _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]); for(i=0;iresidues;i++) /* unpack does the range checking */ if(ci->residue_param[i]) /* this may be cleaning up an aborted - unpack, in which case the below type - cannot be trusted */ - _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]); + unpack, in which case the below type + cannot be trusted */ + _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]); for(i=0;ibooks;i++){ if(ci->book_param[i]){ - /* knows if the book was not alloced */ - vorbis_staticbook_destroy(ci->book_param[i]); + /* knows if the book was not alloced */ + vorbis_staticbook_destroy(ci->book_param[i]); } if(ci->fullbooks) - vorbis_book_clear(ci->fullbooks+i); + vorbis_book_clear(ci->fullbooks+i); } if(ci->fullbooks) - _ogg_free(ci->fullbooks); + _ogg_free(ci->fullbooks); for(i=0;ipsys;i++) _vi_psy_free(ci->psy_param[i]); @@ -238,21 +241,25 @@ static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){ static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){ int i; int vendorlen=oggpack_read(opb,32); - if(vendorlen<0||vendorlen>opb->storage)goto err_out; + if(vendorlen<0)goto err_out; + if(vendorlen+8>opb->storage)goto err_out; vc->vendor=_ogg_calloc(vendorlen+1,1); _v_readstring(opb,vc->vendor,vendorlen); - vc->comments=oggpack_read(opb,32); - if(vc->comments<0||vc->comments>(LONG_MAX>>2)||vc->comments<<2>opb->storage)goto err_out; + i=oggpack_read(opb,32); + if(i<0)goto err_out; + if(4*i+oggpack_bytes(opb)>opb->storage)goto err_out; + vc->comments=i; vc->user_comments=_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments)); vc->comment_lengths=_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths)); - + for(i=0;icomments;i++){ int len=oggpack_read(opb,32); - if(len<0||len>opb->storage)goto err_out; - vc->comment_lengths[i]=len; + if(len<0)goto err_out; + if(len+oggpack_bytes(opb)>opb->storage)goto err_out; + vc->comment_lengths[i]=len; vc->user_comments[i]=_ogg_calloc(len+1,1); _v_readstring(opb,vc->user_comments[i],len); - } + } if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */ return(0); @@ -385,42 +392,42 @@ int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op) memset(buffer,0,6); _v_readstring(&opb,buffer,6); if(memcmp(buffer,"vorbis",6)){ - /* not a vorbis header */ - return(OV_ENOTVORBIS); + /* not a vorbis header */ + return(OV_ENOTVORBIS); } switch(packtype){ case 0x01: /* least significant *bit* is read first */ - if(!op->b_o_s){ - /* Not the initial packet */ - return(OV_EBADHEADER); - } - if(vi->rate!=0){ - /* previously initialized info header */ - return(OV_EBADHEADER); - } + if(!op->b_o_s){ + /* Not the initial packet */ + return(OV_EBADHEADER); + } + if(vi->rate!=0){ + /* previously initialized info header */ + return(OV_EBADHEADER); + } - return(_vorbis_unpack_info(vi,&opb)); + return(_vorbis_unpack_info(vi,&opb)); case 0x03: /* least significant *bit* is read first */ - if(vi->rate==0){ - /* um... we didn't get the initial header */ - return(OV_EBADHEADER); - } + if(vi->rate==0){ + /* um... we didn't get the initial header */ + return(OV_EBADHEADER); + } - return(_vorbis_unpack_comment(vc,&opb)); + return(_vorbis_unpack_comment(vc,&opb)); case 0x05: /* least significant *bit* is read first */ - if(vi->rate==0 || vc->vendor==NULL){ - /* um... we didn;t get the initial header or comments yet */ - return(OV_EBADHEADER); - } + if(vi->rate==0 || vc->vendor==NULL){ + /* um... we didn;t get the initial header or comments yet */ + return(OV_EBADHEADER); + } - return(_vorbis_unpack_books(vi,&opb)); + return(_vorbis_unpack_books(vi,&opb)); default: - /* Not a valid vorbis header type */ - return(OV_EBADHEADER); - break; + /* Not a valid vorbis header type */ + return(OV_EBADHEADER); + break; } } } @@ -454,8 +461,7 @@ static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){ } static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){ - char temp[]="Xiph.Org libVorbis I 20070622"; - int bytes = strlen(temp); + int bytes = strlen(ENCODE_VENDOR_STRING); /* preamble */ oggpack_write(opb,0x03,8); @@ -463,8 +469,8 @@ static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){ /* vendor */ oggpack_write(opb,bytes,32); - _v_writestring(opb,temp, bytes); - + _v_writestring(opb,ENCODE_VENDOR_STRING, bytes); + /* comments */ oggpack_write(opb,vc->comments,32); @@ -472,10 +478,10 @@ static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){ int i; for(i=0;icomments;i++){ if(vc->user_comments[i]){ - oggpack_write(opb,vc->comment_lengths[i],32); - _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]); + oggpack_write(opb,vc->comment_lengths[i],32); + _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]); }else{ - oggpack_write(opb,0,32); + oggpack_write(opb,0,32); } } } @@ -541,7 +547,7 @@ err_out: } int vorbis_commentheader_out(vorbis_comment *vc, - ogg_packet *op){ + ogg_packet *op){ oggpack_buffer opb; @@ -561,10 +567,10 @@ int vorbis_commentheader_out(vorbis_comment *vc, } int vorbis_analysis_headerout(vorbis_dsp_state *v, - vorbis_comment *vc, - ogg_packet *op, - ogg_packet *op_comm, - ogg_packet *op_code){ + vorbis_comment *vc, + ogg_packet *op, + ogg_packet *op_comm, + ogg_packet *op_code){ int ret=OV_EIMPL; vorbis_info *vi=v->vi; oggpack_buffer opb; @@ -645,3 +651,7 @@ double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){ return((double)granulepos/v->vi->rate); return(-1); } + +const char *vorbis_version_string(void){ + return GENERAL_VENDOR_STRING; +} diff --git a/media/libvorbis/lib/vorbis_lookup.c b/media/libvorbis/lib/vorbis_lookup.c index 06c53fee5cf..c8c963378b2 100644 --- a/media/libvorbis/lib/vorbis_lookup.c +++ b/media/libvorbis/lib/vorbis_lookup.c @@ -11,7 +11,7 @@ ******************************************************************** function: lookup based functions - last mod: $Id: lookup.c 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -88,7 +88,7 @@ long vorbis_coslook_i(long a){ int i=a>>COS_LOOKUP_I_SHIFT; int d=a&COS_LOOKUP_I_MASK; return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>> - COS_LOOKUP_I_SHIFT); + COS_LOOKUP_I_SHIFT); } #endif diff --git a/media/libvorbis/lib/vorbis_lpc.c b/media/libvorbis/lib/vorbis_lpc.c index ea2cf90ff6e..b3c09985997 100644 --- a/media/libvorbis/lib/vorbis_lpc.c +++ b/media/libvorbis/lib/vorbis_lpc.c @@ -11,7 +11,7 @@ ******************************************************************** function: LPC low level routines - last mod: $Id: lpc.c 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -62,6 +62,7 @@ float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){ double *aut=alloca(sizeof(*aut)*(m+1)); double *lpc=alloca(sizeof(*lpc)*(m)); double error; + double epsilon; int i,j; /* autocorrelation, p+1 lag coefficients */ @@ -74,14 +75,16 @@ float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){ /* Generate lpc coefficients from autocorr values */ - error=aut[0]; - + /* set our noise floor to about -100dB */ + error=aut[0] * (1. + 1e-10); + epsilon=1e-9*aut[0]+1e-10; + for(i=0;i>25])) - if(!(shift=MLOOP_2[(pi|qi)>>19])) - shift=MLOOP_3[(pi|qi)>>16]; + if(!(shift=MLOOP_2[(pi|qi)>>19])) + shift=MLOOP_3[(pi|qi)>>16]; qi=(qi>>shift)*labs(ilsp[j-1]-wi); pi=(pi>>shift)*labs(ilsp[j]-wi); qexp+=shift; } if(!(shift=MLOOP_1[(pi|qi)>>25])) if(!(shift=MLOOP_2[(pi|qi)>>19])) - shift=MLOOP_3[(pi|qi)>>16]; + shift=MLOOP_3[(pi|qi)>>16]; /* pi,qi normalized collectively, both tracked using qexp */ @@ -181,8 +181,8 @@ void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m, qexp+=shift; if(!(shift=MLOOP_1[(pi|qi)>>25])) - if(!(shift=MLOOP_2[(pi|qi)>>19])) - shift=MLOOP_3[(pi|qi)>>16]; + if(!(shift=MLOOP_2[(pi|qi)>>19])) + shift=MLOOP_3[(pi|qi)>>16]; pi>>=shift; qi>>=shift; @@ -199,7 +199,7 @@ void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m, /* even order filter; still symmetric */ /* p*=p(1-w), q*=q(1+w), let normalization drift because it isn't - worth tracking step by step */ + worth tracking step by step */ pi>>=shift; qi>>=shift; @@ -224,13 +224,13 @@ void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m, qi>>=1; qexp++; }else while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/ - qi<<=1; qexp--; + qi<<=1; qexp--; } amp=vorbis_fromdBlook_i(ampi* /* n.4 */ - vorbis_invsqlook_i(qi,qexp)- - /* m.8, m+n<=8 */ - ampoffseti); /* 8.12[0] */ + vorbis_invsqlook_i(qi,qexp)- + /* m.8, m+n<=8 */ + ampoffseti); /* 8.12[0] */ curve[i]*=amp; while(map[++i]==k)curve[i]*=amp; @@ -245,7 +245,7 @@ void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m, /* side effect: changes *lsp to cosines of lsp */ void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m, - float amp,float ampoffset){ + float amp,float ampoffset){ int i; float wdel=M_PI/ln; for(i=0;i0;i--){ - ppp = new*ppp + pp; - pp = new*pp + p; - p = new*p + defl[i-1]; + ppp = new*ppp + pp; + pp = new*pp + p; + p = new*p + defl[i-1]; } /* Laguerre's method */ denom=(m-1) * ((m-1)*pp*pp - m*p*ppp); if(denom<0) - return(-1); /* complex root! The LPC generator handed us a bad filter */ + return(-1); /* complex root! The LPC generator handed us a bad filter */ if(pp>0){ - denom = pp + sqrt(denom); - if(denom-(EPSILON))denom=-(EPSILON); + denom = pp - sqrt(denom); + if(denom>-(EPSILON))denom=-(EPSILON); } delta = m*p/denom; @@ -378,8 +378,8 @@ static int Newton_Raphson(float *a,int ord,float *r){ double p=a[ord]; for(k=ord-1; k>= 0; k--) { - pp= pp* rooti + p; - p = p * rooti + a[k]; + pp= pp* rooti + p; + p = p * rooti + a[k]; } delta = p/pp; diff --git a/media/libvorbis/lib/vorbis_mapping0.c b/media/libvorbis/lib/vorbis_mapping0.c index 8e5a468624c..4db59ef5b50 100644 --- a/media/libvorbis/lib/vorbis_mapping0.c +++ b/media/libvorbis/lib/vorbis_mapping0.c @@ -11,7 +11,7 @@ ******************************************************************** function: channel mapping 0 implementation - last mod: $Id: mapping0.c 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -56,7 +56,7 @@ static int ilog(unsigned int v){ } static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm, - oggpack_buffer *opb){ + oggpack_buffer *opb){ int i; vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm; @@ -118,10 +118,10 @@ static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb) int testA=info->coupling_ang[i]=oggpack_read(opb,ilog(vi->channels)); if(testM<0 || - testA<0 || - testM==testA || - testM>=vi->channels || - testA>=vi->channels) goto err_out; + testA<0 || + testM==testA || + testM>=vi->channels || + testA>=vi->channels) goto err_out; } } @@ -229,16 +229,6 @@ static float FLOOR1_fromdB_LOOKUP[256]={ #endif -extern int *floor1_fit(vorbis_block *vb,vorbis_look_floor *look, - const float *logmdct, /* in */ - const float *logmask); -extern int *floor1_interpolate_fit(vorbis_block *vb,vorbis_look_floor *look, - int *A,int *B, - int del); -extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb, - vorbis_look_floor *look, - int *post,int *ilogmask); - static int mapping0_forward(vorbis_block *vb){ vorbis_dsp_state *vd=vb->vd; @@ -290,22 +280,28 @@ static int mapping0_forward(vorbis_block *vb){ next major model upgrade. */ #if 0 - if(vi->channels==2) + if(vi->channels==2){ if(i==0) - _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2); + _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2); else - _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2); + _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2); + }else{ + _analysis_output("pcm",seq,pcm,n,0,0,total-n/2); + } #endif /* window the PCM data */ _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW); #if 0 - if(vi->channels==2) + if(vi->channels==2){ if(i==0) - _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2); + _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2); else - _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2); + _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2); + }else{ + _analysis_output("windowed",seq,pcm,n,0,0,total-n/2); + } #endif /* transform the PCM data */ @@ -355,10 +351,12 @@ static int mapping0_forward(vorbis_block *vb){ #if 0 if(vi->channels==2){ if(i==0){ - _analysis_output("fftL",seq,logfft,n/2,1,0,0); + _analysis_output("fftL",seq,logfft,n/2,1,0,0); }else{ - _analysis_output("fftR",seq,logfft,n/2,1,0,0); + _analysis_output("fftR",seq,logfft,n/2,1,0,0); } + }else{ + _analysis_output("fft",seq,logfft,n/2,1,0,0); } #endif @@ -370,7 +368,7 @@ static int mapping0_forward(vorbis_block *vb){ for(i=0;ichannels;i++){ /* the encoder setup assumes that all the modes used by any - specific bitrate tweaking use the same floor */ + specific bitrate tweaking use the same floor */ int submap=info->chmuxlist[i]; @@ -387,7 +385,7 @@ static int mapping0_forward(vorbis_block *vb){ memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS); for(j=0;jchannels==2){ - if(i==0) - _analysis_output("mdctL",seq,logmdct,n/2,1,0,0); - else - _analysis_output("mdctR",seq,logmdct,n/2,1,0,0); + if(i==0) + _analysis_output("mdctL",seq,logmdct,n/2,1,0,0); + else + _analysis_output("mdctR",seq,logmdct,n/2,1,0,0); }else{ - _analysis_output("mdct",seq,logmdct,n/2,1,0,0); + _analysis_output("mdct",seq,logmdct,n/2,1,0,0); } #endif @@ -420,15 +418,17 @@ static int mapping0_forward(vorbis_block *vb){ 'noise_depth' vector, the more tonal that area is) */ _vp_noisemask(psy_look, - logmdct, - noise); /* noise does not have by-frequency offset + logmdct, + noise); /* noise does not have by-frequency offset bias applied yet */ #if 0 if(vi->channels==2){ - if(i==0) - _analysis_output("noiseL",seq,noise,n/2,1,0,0); - else - _analysis_output("noiseR",seq,noise,n/2,1,0,0); + if(i==0) + _analysis_output("noiseL",seq,noise,n/2,1,0,0); + else + _analysis_output("noiseR",seq,noise,n/2,1,0,0); + }else{ + _analysis_output("noise",seq,noise,n/2,1,0,0); } #endif @@ -437,55 +437,61 @@ static int mapping0_forward(vorbis_block *vb){ vector. This includes tone masking, peak limiting and ATH */ _vp_tonemask(psy_look, - logfft, - tone, - global_ampmax, - local_ampmax[i]); + logfft, + tone, + global_ampmax, + local_ampmax[i]); #if 0 if(vi->channels==2){ - if(i==0) - _analysis_output("toneL",seq,tone,n/2,1,0,0); - else - _analysis_output("toneR",seq,tone,n/2,1,0,0); + if(i==0) + _analysis_output("toneL",seq,tone,n/2,1,0,0); + else + _analysis_output("toneR",seq,tone,n/2,1,0,0); + }else{ + _analysis_output("tone",seq,tone,n/2,1,0,0); } #endif /* third step; we offset the noise vectors, overlay tone - masking. We then do a floor1-specific line fit. If we're - performing bitrate management, the line fit is performed - multiple times for up/down tweakage on demand. */ + masking. We then do a floor1-specific line fit. If we're + performing bitrate management, the line fit is performed + multiple times for up/down tweakage on demand. */ #if 0 { float aotuv[psy_look->n]; #endif - _vp_offset_and_mix(psy_look, - noise, - tone, - 1, - logmask, - mdct, - logmdct); - + _vp_offset_and_mix(psy_look, + noise, + tone, + 1, + logmask, + mdct, + logmdct); + #if 0 - if(vi->channels==2){ - if(i==0) - _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0); - else - _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0); - } + if(vi->channels==2){ + if(i==0) + _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0); + else + _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0); + }else{ + _analysis_output("aotuvM1",seq,aotuv,psy_look->n,1,1,0); + } } #endif #if 0 if(vi->channels==2){ - if(i==0) - _analysis_output("mask1L",seq,logmask,n/2,1,0,0); - else - _analysis_output("mask1R",seq,logmask,n/2,1,0,0); + if(i==0) + _analysis_output("mask1L",seq,logmask,n/2,1,0,0); + else + _analysis_output("mask1R",seq,logmask,n/2,1,0,0); + }else{ + _analysis_output("mask1",seq,logmask,n/2,1,0,0); } #endif @@ -495,73 +501,78 @@ static int mapping0_forward(vorbis_block *vb){ if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1); floor_posts[i][PACKETBLOBS/2]= - floor1_fit(vb,b->flr[info->floorsubmap[submap]], - logmdct, - logmask); + floor1_fit(vb,b->flr[info->floorsubmap[submap]], + logmdct, + logmask); /* are we managing bitrate? If so, perform two more fits for later rate tweaking (fits represent hi/lo) */ if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){ - /* higher rate by way of lower noise curve */ + /* higher rate by way of lower noise curve */ - _vp_offset_and_mix(psy_look, - noise, - tone, - 2, - logmask, - mdct, - logmdct); + _vp_offset_and_mix(psy_look, + noise, + tone, + 2, + logmask, + mdct, + logmdct); #if 0 - if(vi->channels==2){ - if(i==0) - _analysis_output("mask2L",seq,logmask,n/2,1,0,0); - else - _analysis_output("mask2R",seq,logmask,n/2,1,0,0); - } + if(vi->channels==2){ + if(i==0) + _analysis_output("mask2L",seq,logmask,n/2,1,0,0); + else + _analysis_output("mask2R",seq,logmask,n/2,1,0,0); + }else{ + _analysis_output("mask2",seq,logmask,n/2,1,0,0); + } #endif - - floor_posts[i][PACKETBLOBS-1]= - floor1_fit(vb,b->flr[info->floorsubmap[submap]], - logmdct, - logmask); + + floor_posts[i][PACKETBLOBS-1]= + floor1_fit(vb,b->flr[info->floorsubmap[submap]], + logmdct, + logmask); - /* lower rate by way of higher noise curve */ - _vp_offset_and_mix(psy_look, - noise, - tone, - 0, - logmask, - mdct, - logmdct); + /* lower rate by way of higher noise curve */ + _vp_offset_and_mix(psy_look, + noise, + tone, + 0, + logmask, + mdct, + logmdct); #if 0 - if(vi->channels==2) - if(i==0) - _analysis_output("mask0L",seq,logmask,n/2,1,0,0); - else - _analysis_output("mask0R",seq,logmask,n/2,1,0,0); + if(vi->channels==2){ + if(i==0) + _analysis_output("mask0L",seq,logmask,n/2,1,0,0); + else + _analysis_output("mask0R",seq,logmask,n/2,1,0,0); + }else{ + _analysis_output("mask0",seq,logmask,n/2,1,0,0); + } #endif - floor_posts[i][0]= - floor1_fit(vb,b->flr[info->floorsubmap[submap]], - logmdct, - logmask); - - /* we also interpolate a range of intermediate curves for + floor_posts[i][0]= + floor1_fit(vb,b->flr[info->floorsubmap[submap]], + logmdct, + logmask); + + /* we also interpolate a range of intermediate curves for intermediate rates */ - for(k=1;kflr[info->floorsubmap[submap]], - floor_posts[i][0], - floor_posts[i][PACKETBLOBS/2], - k*65536/(PACKETBLOBS/2)); - for(k=PACKETBLOBS/2+1;kflr[info->floorsubmap[submap]], - floor_posts[i][PACKETBLOBS/2], - floor_posts[i][PACKETBLOBS-1], - (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2)); + for(k=1;kflr[info->floorsubmap[submap]], + floor_posts[i][0], + floor_posts[i][PACKETBLOBS/2], + k*65536/(PACKETBLOBS/2)); + for(k=PACKETBLOBS/2+1;kflr[info->floorsubmap[submap]], + floor_posts[i][PACKETBLOBS/2], + floor_posts[i][PACKETBLOBS-1], + (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2)); } } } @@ -586,39 +597,39 @@ static int mapping0_forward(vorbis_block *vb){ float **couple_bundle=alloca(sizeof(*couple_bundle)*vi->channels); int *zerobundle=alloca(sizeof(*zerobundle)*vi->channels); int **sortindex=alloca(sizeof(*sortindex)*vi->channels); - float **mag_memo; - int **mag_sort; + float **mag_memo=NULL; + int **mag_sort=NULL; if(info->coupling_steps){ mag_memo=_vp_quantize_couple_memo(vb, - &ci->psy_g_param, - psy_look, - info, - gmdct); + &ci->psy_g_param, + psy_look, + info, + gmdct); mag_sort=_vp_quantize_couple_sort(vb, - psy_look, - info, - mag_memo); + psy_look, + info, + mag_memo); hf_reduction(&ci->psy_g_param, - psy_look, - info, - mag_memo); + psy_look, + info, + mag_memo); } memset(sortindex,0,sizeof(*sortindex)*vi->channels); if(psy_look->vi->normal_channel_p){ for(i=0;ichannels;i++){ - float *mdct =gmdct[i]; - sortindex[i]=alloca(sizeof(**sortindex)*n/2); - _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]); + float *mdct =gmdct[i]; + sortindex[i]=alloca(sizeof(**sortindex)*n/2); + _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]); } } for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2); - k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2); - k++){ + k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2); + k++){ oggpack_buffer *opb=vbi->packetblob[k]; /* start out our new packet blob with packet type and mode */ @@ -628,93 +639,101 @@ static int mapping0_forward(vorbis_block *vb){ /* Encode frame mode, pre,post windowsize, then dispatch */ oggpack_write(opb,modenumber,b->modebits); if(vb->W){ - oggpack_write(opb,vb->lW,1); - oggpack_write(opb,vb->nW,1); + oggpack_write(opb,vb->lW,1); + oggpack_write(opb,vb->nW,1); } /* encode floor, compute masking curve, sep out residue */ for(i=0;ichannels;i++){ - int submap=info->chmuxlist[i]; - float *mdct =gmdct[i]; - float *res =vb->pcm[i]; - int *ilogmask=ilogmaskch[i]= - _vorbis_block_alloc(vb,n/2*sizeof(**gmdct)); + int submap=info->chmuxlist[i]; + float *mdct =gmdct[i]; + float *res =vb->pcm[i]; + int *ilogmask=ilogmaskch[i]= + _vorbis_block_alloc(vb,n/2*sizeof(**gmdct)); - nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]], - floor_posts[i][k], - ilogmask); + nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]], + floor_posts[i][k], + ilogmask); #if 0 - { - char buf[80]; - sprintf(buf,"maskI%c%d",i?'R':'L',k); - float work[n/2]; - for(j=0;jpsy_g_param.sliding_lowpass[vb->W][k]); + _vp_remove_floor(psy_look, + mdct, + ilogmask, + res, + ci->psy_g_param.sliding_lowpass[vb->W][k]); - _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]); + _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]); - + #if 0 - { - char buf[80]; - float work[n/2]; - for(j=0;jcoupling_steps){ - _vp_couple(k, - &ci->psy_g_param, - psy_look, - info, - vb->pcm, - mag_memo, - mag_sort, - ilogmaskch, - nonzero, - ci->psy_g_param.sliding_lowpass[vb->W][k]); + _vp_couple(k, + &ci->psy_g_param, + psy_look, + info, + vb->pcm, + mag_memo, + mag_sort, + ilogmaskch, + nonzero, + ci->psy_g_param.sliding_lowpass[vb->W][k]); } /* classify and encode by submap */ for(i=0;isubmaps;i++){ - int ch_in_bundle=0; - long **classifications; - int resnum=info->residuesubmap[i]; + int ch_in_bundle=0; + long **classifications; + int resnum=info->residuesubmap[i]; - for(j=0;jchannels;j++){ - if(info->chmuxlist[j]==i){ - zerobundle[ch_in_bundle]=0; - if(nonzero[j])zerobundle[ch_in_bundle]=1; - res_bundle[ch_in_bundle]=vb->pcm[j]; - couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2; - } - } - - classifications=_residue_P[ci->residue_type[resnum]]-> - class(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle); - - _residue_P[ci->residue_type[resnum]]-> - forward(opb,vb,b->residue[resnum], - couple_bundle,NULL,zerobundle,ch_in_bundle,classifications); + for(j=0;jchannels;j++){ + if(info->chmuxlist[j]==i){ + zerobundle[ch_in_bundle]=0; + if(nonzero[j])zerobundle[ch_in_bundle]=1; + res_bundle[ch_in_bundle]=vb->pcm[j]; + couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2; + } + } + + classifications=_residue_P[ci->residue_type[resnum]]-> + class(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle); + + /* couple_bundle is destructively overwritten by + the class function if some but not all of the channels are + marked as silence; build a fresh copy */ + ch_in_bundle=0; + for(j=0;jchannels;j++) + if(info->chmuxlist[j]==i) + couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2; + + _residue_P[ci->residue_type[resnum]]-> + forward(opb,vb,b->residue[resnum], + couple_bundle,NULL,zerobundle,ch_in_bundle,classifications); } /* ok, done encoding. Next protopacket. */ @@ -735,7 +754,6 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){ codec_setup_info *ci=vi->codec_setup; private_state *b=vd->backend_state; vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l; - int hs=ci->halfrate_flag; int i,j; long n=vb->pcmend=ci->blocksizes[vb->W]; @@ -772,17 +790,17 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){ int ch_in_bundle=0; for(j=0;jchannels;j++){ if(info->chmuxlist[j]==i){ - if(nonzero[j]) - zerobundle[ch_in_bundle]=1; - else - zerobundle[ch_in_bundle]=0; - pcmbundle[ch_in_bundle++]=vb->pcm[j]; + if(nonzero[j]) + zerobundle[ch_in_bundle]=1; + else + zerobundle[ch_in_bundle]=0; + pcmbundle[ch_in_bundle++]=vb->pcm[j]; } } _residue_P[ci->residue_type[info->residuesubmap[i]]]-> inverse(vb,b->residue[info->residuesubmap[i]], - pcmbundle,zerobundle,ch_in_bundle); + pcmbundle,zerobundle,ch_in_bundle); } /* channel coupling */ @@ -795,21 +813,21 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){ float ang=pcmA[j]; if(mag>0) - if(ang>0){ - pcmM[j]=mag; - pcmA[j]=mag-ang; - }else{ - pcmA[j]=mag; - pcmM[j]=mag+ang; - } + if(ang>0){ + pcmM[j]=mag; + pcmA[j]=mag-ang; + }else{ + pcmA[j]=mag; + pcmM[j]=mag+ang; + } else - if(ang>0){ - pcmM[j]=mag; - pcmA[j]=mag+ang; - }else{ - pcmA[j]=mag; - pcmM[j]=mag-ang; - } + if(ang>0){ + pcmM[j]=mag; + pcmA[j]=mag+ang; + }else{ + pcmA[j]=mag; + pcmM[j]=mag-ang; + } } } @@ -819,7 +837,7 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){ int submap=info->chmuxlist[i]; _floor_P[ci->floor_type[info->floorsubmap[submap]]]-> inverse2(vb,b->flr[info->floorsubmap[submap]], - floormemo[i],pcm); + floormemo[i],pcm); } /* transform the PCM data; takes PCM vector, vb; modifies PCM vector */ @@ -834,7 +852,7 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){ } /* export hooks */ -vorbis_func_mapping mapping0_exportbundle={ +const vorbis_func_mapping mapping0_exportbundle={ &mapping0_pack, &mapping0_unpack, &mapping0_free_info, diff --git a/media/libvorbis/lib/vorbis_mdct.c b/media/libvorbis/lib/vorbis_mdct.c index 206d99f7bc5..9f6dc1d599b 100644 --- a/media/libvorbis/lib/vorbis_mdct.c +++ b/media/libvorbis/lib/vorbis_mdct.c @@ -12,7 +12,7 @@ function: normalized modified discrete cosine transform power of two length transform only [64 <= n ] - last mod: $Id: mdct.c 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ Original algorithm adapted long ago from _The use of multirate filter banks for coding of high quality digital audio_, by T. Sporer, @@ -81,7 +81,7 @@ void mdct_init(mdct_lookup *lookup,int n){ for(i=0;i>j;j++) - if((msb>>j)&i)acc|=1<>j)&i)acc|=1<>1) - 8; @@ -226,33 +226,33 @@ STIN void mdct_butterfly_first(DATA_TYPE *T, do{ r0 = x1[6] - x2[6]; - r1 = x1[7] - x2[7]; - x1[6] += x2[6]; - x1[7] += x2[7]; - x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]); - x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]); - - r0 = x1[4] - x2[4]; - r1 = x1[5] - x2[5]; - x1[4] += x2[4]; - x1[5] += x2[5]; - x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]); - x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]); - - r0 = x1[2] - x2[2]; - r1 = x1[3] - x2[3]; - x1[2] += x2[2]; - x1[3] += x2[3]; - x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]); - x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]); - - r0 = x1[0] - x2[0]; - r1 = x1[1] - x2[1]; - x1[0] += x2[0]; - x1[1] += x2[1]; - x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]); - x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]); - + r1 = x1[7] - x2[7]; + x1[6] += x2[6]; + x1[7] += x2[7]; + x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]); + x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]); + + r0 = x1[4] - x2[4]; + r1 = x1[5] - x2[5]; + x1[4] += x2[4]; + x1[5] += x2[5]; + x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]); + x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]); + + r0 = x1[2] - x2[2]; + r1 = x1[3] - x2[3]; + x1[2] += x2[2]; + x1[3] += x2[3]; + x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]); + x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]); + + r0 = x1[0] - x2[0]; + r1 = x1[1] - x2[1]; + x1[0] += x2[0]; + x1[1] += x2[1]; + x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]); + x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]); + x1-=8; x2-=8; T+=16; @@ -262,9 +262,9 @@ STIN void mdct_butterfly_first(DATA_TYPE *T, /* N/stage point generic N stage butterfly (in place, 2 register) */ STIN void mdct_butterfly_generic(DATA_TYPE *T, - DATA_TYPE *x, - int points, - int trigint){ + DATA_TYPE *x, + int points, + int trigint){ DATA_TYPE *x1 = x + points - 8; DATA_TYPE *x2 = x + (points>>1) - 8; @@ -274,40 +274,40 @@ STIN void mdct_butterfly_generic(DATA_TYPE *T, do{ r0 = x1[6] - x2[6]; - r1 = x1[7] - x2[7]; - x1[6] += x2[6]; - x1[7] += x2[7]; - x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]); - x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]); - - T+=trigint; - - r0 = x1[4] - x2[4]; - r1 = x1[5] - x2[5]; - x1[4] += x2[4]; - x1[5] += x2[5]; - x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]); - x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]); - - T+=trigint; - - r0 = x1[2] - x2[2]; - r1 = x1[3] - x2[3]; - x1[2] += x2[2]; - x1[3] += x2[3]; - x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]); - x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]); - - T+=trigint; - - r0 = x1[0] - x2[0]; - r1 = x1[1] - x2[1]; - x1[0] += x2[0]; - x1[1] += x2[1]; - x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]); - x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]); + r1 = x1[7] - x2[7]; + x1[6] += x2[6]; + x1[7] += x2[7]; + x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]); + x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]); + + T+=trigint; + + r0 = x1[4] - x2[4]; + r1 = x1[5] - x2[5]; + x1[4] += x2[4]; + x1[5] += x2[5]; + x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]); + x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]); + + T+=trigint; + + r0 = x1[2] - x2[2]; + r1 = x1[3] - x2[3]; + x1[2] += x2[2]; + x1[3] += x2[3]; + x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]); + x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]); + + T+=trigint; + + r0 = x1[0] - x2[0]; + r1 = x1[1] - x2[1]; + x1[0] += x2[0]; + x1[1] += x2[1]; + x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]); + x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]); - T+=trigint; + T+=trigint; x1-=8; x2-=8; @@ -315,8 +315,8 @@ STIN void mdct_butterfly_generic(DATA_TYPE *T, } STIN void mdct_butterflies(mdct_lookup *init, - DATA_TYPE *x, - int points){ + DATA_TYPE *x, + int points){ DATA_TYPE *T=init->trig; int stages=init->log2n-5; @@ -345,7 +345,7 @@ void mdct_clear(mdct_lookup *l){ } STIN void mdct_bitreverse(mdct_lookup *init, - DATA_TYPE *x){ + DATA_TYPE *x){ int n = init->n; int *bit = init->bitrev; DATA_TYPE *w0 = x; @@ -361,15 +361,15 @@ STIN void mdct_bitreverse(mdct_lookup *init, REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]); REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]); - w1 -= 4; + w1 -= 4; r0 = HALVE(x0[1] + x1[1]); r1 = HALVE(x0[0] - x1[0]); - w0[0] = r0 + r2; - w1[2] = r0 - r2; - w0[1] = r1 + r3; - w1[3] = r3 - r1; + w0[0] = r0 + r2; + w1[2] = r0 - r2; + w0[1] = r1 + r3; + w1[3] = r3 - r1; x0 = x+bit[2]; x1 = x+bit[3]; @@ -382,14 +382,14 @@ STIN void mdct_bitreverse(mdct_lookup *init, r0 = HALVE(x0[1] + x1[1]); r1 = HALVE(x0[0] - x1[0]); - w0[2] = r0 + r2; - w1[0] = r0 - r2; - w0[3] = r1 + r3; - w1[1] = r3 - r1; + w0[2] = r0 + r2; + w1[0] = r0 - r2; + w0[3] = r1 + r3; + w1[1] = r3 - r1; - T += 4; - bit += 4; - w0 += 4; + T += 4; + bit += 4; + w0 += 4; }while(w0codec_setup; @@ -67,12 +67,12 @@ void _vi_psy_free(vorbis_info_psy *i){ } static void min_curve(float *c, - float *c2){ + float *c2){ int i; for(i=0;ic[i])c[i]=c2[i]; } @@ -84,7 +84,7 @@ static void attenuate_curve(float *c,float att){ } static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n, - float center_boost, float center_decay_rate){ + float center_boost, float center_decay_rate){ int i,j,k,m; float ath[EHMER_MAX]; float workc[P_BANDS][P_LEVELS][EHMER_MAX]; @@ -106,11 +106,11 @@ static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n, for(j=0;jATH[j+k+ath_offset])min=ATH[j+k+ath_offset]; - }else{ - if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1]; - } + if(j+k+ath_offsetATH[j+k+ath_offset])min=ATH[j+k+ath_offset]; + }else{ + if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1]; + } ath[j]=min; } @@ -124,10 +124,10 @@ static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n, /* apply centered curve boost/decay */ for(j=0;j0)adj=0.; - if(adj>0. && center_boost<0)adj=0.; - workc[i][j][k]+=adj; + float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate; + if(adj<0. && center_boost>0)adj=0.; + if(adj>0. && center_boost<0)adj=0.; + workc[i][j][k]+=adj; } } @@ -183,79 +183,79 @@ static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n, for(j=0;jn)lo_bin=n; - if(lo_binn)hi_bin=n; + for(j=0;jn)lo_bin=n; + if(lo_binn)hi_bin=n; - for(;lworkc[k][m][j]) - brute_buffer[l]=workc[k][m][j]; - } + for(;lworkc[k][m][j]) + brute_buffer[l]=workc[k][m][j]; + } - for(;lworkc[k][m][EHMER_MAX-1]) - brute_buffer[l]=workc[k][m][EHMER_MAX-1]; + for(;lworkc[k][m][EHMER_MAX-1]) + brute_buffer[l]=workc[k][m][EHMER_MAX-1]; } /* be equally paranoid about being valid up to next half ocatve */ if(i+1n)lo_bin=n; - if(lo_binn)hi_bin=n; + int l=0; + k=i+1; + for(j=0;jn)lo_bin=n; + if(lo_binn)hi_bin=n; - for(;lworkc[k][m][j]) - brute_buffer[l]=workc[k][m][j]; - } + for(;lworkc[k][m][j]) + brute_buffer[l]=workc[k][m][j]; + } - for(;lworkc[k][m][EHMER_MAX-1]) - brute_buffer[l]=workc[k][m][EHMER_MAX-1]; + for(;lworkc[k][m][EHMER_MAX-1]) + brute_buffer[l]=workc[k][m][EHMER_MAX-1]; } for(j=0;j=n){ - ret[i][m][j+2]=-999.; - }else{ - ret[i][m][j+2]=brute_buffer[bin]; - } - } + int bin=fromOC(j*.125+i*.5-2.)/binHz; + if(bin<0){ + ret[i][m][j+2]=-999.; + }else{ + if(bin>=n){ + ret[i][m][j+2]=-999.; + }else{ + ret[i][m][j+2]=brute_buffer[bin]; + } + } } /* add fenceposts */ for(j=0;j-200.f)break; + if(ret[i][m][j+2]>-200.f)break; ret[i][m][0]=j; for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--) - if(ret[i][m][j+2]>-200.f) - break; + if(ret[i][m][j+2]>-200.f) + break; ret[i][m][1]=j; } @@ -265,7 +265,7 @@ static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n, } void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi, - vorbis_info_psy_global *gi,int n,long rate){ + vorbis_info_psy_global *gi,int n,long rate){ long i,j,lo=-99,hi=1; long maxoc; memset(p,0,sizeof(*p)); @@ -304,14 +304,18 @@ void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi, } } + for(;jath[j]=p->ath[j-1]; + } + for(i=0;inoisewindowlominnoisewindowlo);lo++); + toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++); for(;hi<=n && (hinoisewindowhimin || - toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++); + toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++); p->bark[i]=((lo-1)<<16)+(hi-1); @@ -321,7 +325,7 @@ void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi, p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f; p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n, - vi->tone_centerboost,vi->tone_decay); + vi->tone_centerboost,vi->tone_decay); /* set up rolling noise median */ p->noiseoffset=_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset)); @@ -340,8 +344,8 @@ void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi, for(j=0;jnoiseoffset[j][i]= - p->vi->noiseoff[j][inthalfoc]*(1.-del) + - p->vi->noiseoff[j][inthalfoc+1]*del; + p->vi->noiseoff[j][inthalfoc]*(1.-del) + + p->vi->noiseoff[j][inthalfoc+1]*del; } #if 0 @@ -362,10 +366,10 @@ void _vp_psy_clear(vorbis_look_psy *p){ if(p->bark)_ogg_free(p->bark); if(p->tonecurves){ for(i=0;itonecurves[i][j]); - } - _ogg_free(p->tonecurves[i]); + for(j=0;jtonecurves[i][j]); + } + _ogg_free(p->tonecurves[i]); } _ogg_free(p->tonecurves); } @@ -381,10 +385,10 @@ void _vp_psy_clear(vorbis_look_psy *p){ /* octave/(8*eighth_octave_lines) x scale and dB y scale */ static void seed_curve(float *seed, - const float **curves, - float amp, - int oc, int n, - int linesper,float dBoffset){ + const float **curves, + float amp, + int oc, int n, + int linesper,float dBoffset){ int i,post1; int seedptr; const float *posts,*curve; @@ -408,11 +412,11 @@ static void seed_curve(float *seed, } static void seed_loop(vorbis_look_psy *p, - const float ***curves, - const float *f, - const float *flr, - float *seed, - float specmax){ + const float ***curves, + const float *f, + const float *flr, + float *seed, + float specmax){ vorbis_info_psy *vi=p->vi; long n=p->n,i; float dBoffset=vi->max_curve_dB-specmax; @@ -434,12 +438,12 @@ static void seed_loop(vorbis_look_psy *p, if(oc<0)oc=0; seed_curve(seed, - curves[oc], - max, - p->octave[i]-p->firstoc, - p->total_octave_lines, - p->eighth_octave_lines, - dBoffset); + curves[oc], + max, + p->octave[i]-p->firstoc, + p->total_octave_lines, + p->eighth_octave_lines, + dBoffset); } } } @@ -457,24 +461,24 @@ static void seed_chase(float *seeds, int linesper, long n){ ampstack[stack++]=seeds[i]; }else{ while(1){ - if(seeds[i]1 && ampstack[stack-1]<=ampstack[stack-2] && - i1 && ampstack[stack-1]<=ampstack[stack-2] && + in)endpos=n; for(;pos static void max_seeds(vorbis_look_psy *p, - float *seed, - float *flr){ + float *seed, + float *flr){ long n=p->total_octave_lines; int linesper=p->eighth_octave_lines; long linpos=0; @@ -521,7 +525,7 @@ static void max_seeds(vorbis_look_psy *p, while(pos+1<=end){ pos++; if((seed[pos]>NEGINF && seed[pos]firstoc; @@ -692,7 +696,7 @@ static void bark_noise_hybridmp(int n,const long *b, } } -static float FLOOR1_fromdB_INV_LOOKUP[256]={ +static const float FLOOR1_fromdB_INV_LOOKUP[256]={ 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F, 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F, 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F, @@ -760,10 +764,10 @@ static float FLOOR1_fromdB_INV_LOOKUP[256]={ }; void _vp_remove_floor(vorbis_look_psy *p, - float *mdct, - int *codedflr, - float *residue, - int sliding_lowpass){ + float *mdct, + int *codedflr, + float *residue, + int sliding_lowpass){ int i,n=p->n; @@ -779,19 +783,19 @@ void _vp_remove_floor(vorbis_look_psy *p, } void _vp_noisemask(vorbis_look_psy *p, - float *logmdct, - float *logmask){ + float *logmdct, + float *logmask){ int i,n=p->n; float *work=alloca(n*sizeof(*work)); bark_noise_hybridmp(n,p->bark,logmdct,logmask, - 140.,-1); + 140.,-1); for(i=0;ibark,work,logmask,0., - p->vi->noisewindowfixed); + p->vi->noisewindowfixed); for(i=0;in; @@ -852,12 +856,12 @@ void _vp_tonemask(vorbis_look_psy *p, } void _vp_offset_and_mix(vorbis_look_psy *p, - float *noise, - float *tone, - int offset_select, - float *logmask, - float *mdct, - float *logmdct){ + float *noise, + float *tone, + int offset_select, + float *logmask, + float *mdct, + float *logmdct){ int i,n=p->n; float de, coeffi, cx;/* AoTuV */ float toneatt=p->vi->tone_masteratt[offset_select]; @@ -872,11 +876,11 @@ void _vp_offset_and_mix(vorbis_look_psy *p, /* AoTuV */ /** @ M1 ** - The following codes improve a noise problem. - A fundamental idea uses the value of masking and carries out - the relative compensation of the MDCT. - However, this code is not perfect and all noise problems cannot be solved. - by Aoyumi @ 2004/04/18 + The following codes improve a noise problem. + A fundamental idea uses the value of masking and carries out + the relative compensation of the MDCT. + However, this code is not perfect and all noise problems cannot be solved. + by Aoyumi @ 2004/04/18 */ if(offset_select == 1) { @@ -884,24 +888,24 @@ void _vp_offset_and_mix(vorbis_look_psy *p, val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */ if(val > coeffi){ - /* mdct value is > -17.2 dB below floor */ - - de = 1.0-((val-coeffi)*0.005*cx); - /* pro-rated attenuation: - -0.00 dB boost if mdct value is -17.2dB (relative to floor) - -0.77 dB boost if mdct value is 0dB (relative to floor) - -1.64 dB boost if mdct value is +17.2dB (relative to floor) - etc... */ - - if(de < 0) de = 0.0001; + /* mdct value is > -17.2 dB below floor */ + + de = 1.0-((val-coeffi)*0.005*cx); + /* pro-rated attenuation: + -0.00 dB boost if mdct value is -17.2dB (relative to floor) + -0.77 dB boost if mdct value is 0dB (relative to floor) + -1.64 dB boost if mdct value is +17.2dB (relative to floor) + etc... */ + + if(de < 0) de = 0.0001; }else - /* mdct value is <= -17.2 dB below floor */ - - de = 1.0-((val-coeffi)*0.0003*cx); + /* mdct value is <= -17.2 dB below floor */ + + de = 1.0-((val-coeffi)*0.0003*cx); /* pro-rated attenuation: - +0.00 dB atten if mdct value is -17.2dB (relative to floor) - +0.45 dB atten if mdct value is -34.4dB (relative to floor) - etc... */ + +0.00 dB atten if mdct value is -17.2dB (relative to floor) + +0.45 dB atten if mdct value is -34.4dB (relative to floor) + etc... */ mdct[i] *= de; @@ -923,7 +927,7 @@ float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){ } static void couple_lossless(float A, float B, - float *qA, float *qB){ + float *qA, float *qB){ int test1=fabs(*qA)>fabs(*qB); test1-= fabs(*qA)floorB)-1; int offset=31-abs(floorA-floorB); @@ -995,10 +999,10 @@ static float round_hypot(float a, float b){ /* revert to round hypot for now */ float **_vp_quantize_couple_memo(vorbis_block *vb, - vorbis_info_psy_global *g, - vorbis_look_psy *p, - vorbis_info_mapping0 *vi, - float **mdct){ + vorbis_info_psy_global *g, + vorbis_look_psy *p, + vorbis_info_mapping0 *vi, + float **mdct){ int i,j,n=p->n; float **ret=_vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret)); @@ -1025,9 +1029,9 @@ static int apsort(const void *a, const void *b){ } int **_vp_quantize_couple_sort(vorbis_block *vb, - vorbis_look_psy *p, - vorbis_info_mapping0 *vi, - float **mags){ + vorbis_look_psy *p, + vorbis_info_mapping0 *vi, + float **mags){ if(p->vi->normal_point_p){ @@ -1040,9 +1044,9 @@ int **_vp_quantize_couple_sort(vorbis_block *vb, ret[i]=_vorbis_block_alloc(vb,n*sizeof(**ret)); for(j=0;jn; vorbis_info_psy *vi=p->vi; int partition=vi->normal_partition; @@ -1069,7 +1073,7 @@ void _vp_noise_normalize_sort(vorbis_look_psy *p, } void _vp_noise_normalize(vorbis_look_psy *p, - float *in,float *out,int *sortedindex){ + float *in,float *out,int *sortedindex){ int flag=0,i,j=0,n=p->n; vorbis_info_psy *vi=p->vi; int partition=vi->normal_partition; @@ -1086,25 +1090,25 @@ void _vp_noise_normalize(vorbis_look_psy *p, int k; for(i=j;i=.25f){ - out[k]=rint(in[k]); - acc-=in[k]*in[k]; - flag=1; - }else{ - if(accnormal_thresh)break; - out[k]=unitnorm(in[k]); - acc-=1.; - } + k=sortedindex[i+j-start]; + + if(in[k]*in[k]>=.25f){ + out[k]=rint(in[k]); + acc-=in[k]*in[k]; + flag=1; + }else{ + if(accnormal_thresh)break; + out[k]=unitnorm(in[k]); + acc-=1.; + } } for(;in; @@ -1165,39 +1169,39 @@ void _vp_couple(int blobno, postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]]; for(j=0;jn;j+=partition){ - float acc=0.f; + float acc=0.f; - for(k=0;k=limit && fabs(rM[l])=limit && fabs(rM[l])vi->normal_point_p){ - for(k=0;k=p->vi->normal_thresh;k++){ - int l=mag_sort[i][j+k]; - if(l=pointlimit && rint(qM[l])==0.f){ - qM[l]=unitnorm(qM[l]); - acc-=1.f; - } - } - } + if(rint(qM[l])==0.f)acc+=qM[l]*qM[l]; + }else{ + couple_lossless(rM[l],rA[l],qM+l,qA+l); + } + }else{ + qM[l]=0.; + qA[l]=0.; + } + } + + if(p->vi->normal_point_p){ + for(k=0;k=p->vi->normal_thresh;k++){ + int l=mag_sort[i][j+k]; + if(l=pointlimit && rint(qM[l])==0.f){ + qM[l]=unitnorm(qM[l]); + acc-=1.f; + } + } + } } } } @@ -1217,7 +1221,6 @@ void hf_reduction(vorbis_info_psy_global *g, int i,j,n=p->n, de=0.3*p->m_val; int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2]; - int start=p->vi->normal_start; for(i=0; icoupling_steps; i++){ /* for(j=start; jparts;j++){ - /*fprintf(stderr,"partition %d: ",j);*/ - for(k=0;k<8;k++) - if(look->training_data[k][j]){ - char buffer[80]; - FILE *of; - codebook *statebook=look->partbooks[j][k]; - - /* long and short into the same bucket by current convention */ - sprintf(buffer,"res_part%d_pass%d.vqd",j,k); - of=fopen(buffer,"a"); + /*fprintf(stderr,"partition %d: ",j);*/ + for(k=0;k<8;k++) + if(look->training_data[k][j]){ + char buffer[80]; + FILE *of; + codebook *statebook=look->partbooks[j][k]; + + /* long and short into the same bucket by current convention */ + sprintf(buffer,"res_part%d_pass%d.vqd",j,k); + of=fopen(buffer,"a"); - for(l=0;lentries;l++) - fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]); - - fclose(of); - - /*fprintf(stderr,"%d(%.2f|%.2f) ",k, - look->training_min[k][j],look->training_max[k][j]);*/ + for(l=0;lentries;l++) + fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]); + + fclose(of); + + /*fprintf(stderr,"%d(%.2f|%.2f) ",k, + look->training_min[k][j],look->training_max[k][j]);*/ - _ogg_free(look->training_data[k][j]); - look->training_data[k][j]=NULL; - } - /*fprintf(stderr,"\n");*/ + _ogg_free(look->training_data[k][j]); + look->training_data[k][j]=NULL; + } + /*fprintf(stderr,"\n");*/ } } fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax); /*fprintf(stderr,"residue bit usage %f:%f (%f total)\n", - (float)look->phrasebits/look->frames, - (float)look->postbits/look->frames, - (float)(look->postbits+look->phrasebits)/look->frames);*/ + (float)look->phrasebits/look->frames, + (float)look->postbits/look->frames, + (float)(look->postbits+look->phrasebits)/look->frames);*/ #endif /*vorbis_info_residue0 *info=look->info; fprintf(stderr, - "%ld frames encoded in %ld phrasebits and %ld residue bits " - "(%g/frame) \n",look->frames,look->phrasebits, - look->resbitsflat, - (look->phrasebits+look->resbitsflat)/(float)look->frames); + "%ld frames encoded in %ld phrasebits and %ld residue bits " + "(%g/frame) \n",look->frames,look->phrasebits, + look->resbitsflat, + (look->phrasebits+look->resbitsflat)/(float)look->frames); for(j=0;jparts;j++){ long acc=0; fprintf(stderr,"\t[%d] == ",j); for(k=0;kstages;k++) - if((info->secondstages[j]>>k)&1){ - fprintf(stderr,"%ld,",look->resbits[j][k]); - acc+=look->resbits[j][k]; - } + if((info->secondstages[j]>>k)&1){ + fprintf(stderr,"%ld,",look->resbits[j][k]); + acc+=look->resbits[j][k]; + } fprintf(stderr,":: (%ld vals) %1.2fbits/sample\n",look->resvals[j], - acc?(float)acc/(look->resvals[j]*info->grouping):0); + acc?(float)acc/(look->resvals[j]*info->grouping):0); } fprintf(stderr,"\n");*/ @@ -174,7 +174,7 @@ void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){ oggpack_write(opb,info->end,24); oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and - code with a partitioned book */ + code with a partitioned book */ oggpack_write(opb,info->partitions-1,6); /* possible partition choices */ oggpack_write(opb,info->groupbook,8); /* group huffman book */ @@ -220,8 +220,23 @@ vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){ info->booklist[j]=oggpack_read(opb,8); if(info->groupbook>=ci->books)goto errout; - for(j=0;jbooklist[j]>=ci->books)goto errout; + if(ci->book_param[info->booklist[j]]->maptype==0)goto errout; + } + + /* verify the phrasebook is not specifying an impossible or + inconsistent partitioning scheme. */ + { + int entries = ci->book_param[info->groupbook]->entries; + int dim = ci->book_param[info->groupbook]->dim; + int partvals = 1; + while(dim>0){ + partvals *= info->partitions; + if(partvals > entries) goto errout; + dim--; + } + } return(info); errout: @@ -230,7 +245,7 @@ vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){ } vorbis_look_residue *res0_look(vorbis_dsp_state *vd, - vorbis_info_residue *vr){ + vorbis_info_residue *vr){ vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr; vorbis_look_residue0 *look=_ogg_calloc(1,sizeof(*look)); codec_setup_info *ci=vd->vi->codec_setup; @@ -253,17 +268,20 @@ vorbis_look_residue *res0_look(vorbis_dsp_state *vd, if(stages>maxstage)maxstage=stages; look->partbooks[j]=_ogg_calloc(stages,sizeof(*look->partbooks[j])); for(k=0;ksecondstages[j]&(1<partbooks[j][k]=ci->fullbooks+info->booklist[acc++]; + if(info->secondstages[j]&(1<partbooks[j][k]=ci->fullbooks+info->booklist[acc++]; #ifdef TRAIN_RES - look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries, - sizeof(***look->training_data)); + look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries, + sizeof(***look->training_data)); #endif - } + } } } - look->partvals=rint(pow((float)look->parts,(float)dim)); + look->partvals=1; + for(j=0;jpartvals*=look->parts; + look->stages=maxstage; look->decodemap=_ogg_malloc(look->partvals*sizeof(*look->decodemap)); for(j=0;jpartvals;j++){ @@ -299,14 +317,14 @@ static int local_book_besterror(codebook *book,float *a){ if(valquantthresh[i]){ if(valquantthresh[i-1]){ - for(--i;i>0;--i) - if(val>=tt->quantthresh[i-1]) - break; + for(--i;i>0;--i) + if(val>=tt->quantthresh[i-1]) + break; } }else{ for(++i;ithreshvals-1;++i) - if(valquantthresh[i])break; + if(valquantthresh[i])break; } @@ -322,15 +340,15 @@ static int local_book_besterror(codebook *book,float *a){ best=-1; for(i=0;ientries;i++){ if(c->lengthlist[i]>0){ - float this=0.f; - for(j=0;jdim; int step=n/dim; @@ -367,12 +385,10 @@ static int _encodepart(oggpack_buffer *opb,float *vec, int n, } static long **_01class(vorbis_block *vb,vorbis_look_residue *vl, - float **in,int ch){ + float **in,int ch){ long i,j,k; vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl; vorbis_info_residue0 *info=look->info; - vorbis_info *vi=vb->vd->vi; - codec_setup_info *ci=vi->codec_setup; /* move all this setup out later */ int samples_per_partition=info->grouping; @@ -398,15 +414,15 @@ static long **_01class(vorbis_block *vb,vorbis_look_residue *vl, float max=0.; float ent=0.; for(k=0;kmax)max=fabs(in[j][offset+k]); - ent+=fabs(rint(in[j][offset+k])); + if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]); + ent+=fabs(rint(in[j][offset+k])); } ent*=scale; for(k=0;kclassmetric1[k] && - (info->classmetric2[k]<0 || (int)entclassmetric2[k])) - break; + if(max<=info->classmetric1[k] && + (info->classmetric2[k]<0 || (int)entclassmetric2[k])) + break; partword[j][i]=k; } @@ -421,7 +437,7 @@ static long **_01class(vorbis_block *vb,vorbis_look_residue *vl, sprintf(buffer,"resaux_%d.vqd",look->train_seq); of=fopen(buffer,"a"); for(j=0;jinfo; @@ -463,14 +479,14 @@ static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in, for(j=0;jmagmax)magmax=fabs(in[0][l]); for(k=1;kangmax)angmax=fabs(in[k][l]); - l++; + if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]); + l++; } for(j=0;jclassmetric1[j] && - angmax<=info->classmetric2[j]) - break; + angmax<=info->classmetric2[j]) + break; partword[0][i]=j; @@ -491,17 +507,15 @@ static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in, } static int _01forward(oggpack_buffer *opb, - vorbis_block *vb,vorbis_look_residue *vl, - float **in,int ch, - long **partword, - int (*encode)(oggpack_buffer *,float *,int, - codebook *,long *)){ + vorbis_block *vb,vorbis_look_residue *vl, + float **in,int ch, + long **partword, + int (*encode)(oggpack_buffer *,float *,int, + codebook *,long *)){ long i,j,k,s; vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl; vorbis_info_residue0 *info=look->info; - vorbis_dsp_state *vd=vb->vd; - /* move all this setup out later */ int samples_per_partition=info->grouping; int possible_partitions=info->partitions; @@ -534,59 +548,59 @@ static int _01forward(oggpack_buffer *opb, /* first we encode a partition codeword for each channel */ if(s==0){ - for(j=0;jphrasebook->entries) - look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb); + for(j=0;jphrasebook->entries) + look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb); #if 0 /*def TRAIN_RES*/ - else - fprintf(stderr,"!"); + else + fprintf(stderr,"!"); #endif - - } + + } } /* now we encode interleaved residual values for the partitions */ for(k=0;kbegin; - - for(j=0;jsecondstages[partword[j][i]]&(1<partbooks[partword[j][i]][s]; - if(statebook){ - int ret; - long *accumulator=NULL; - + long offset=i*samples_per_partition+info->begin; + + for(j=0;jsecondstages[partword[j][i]]&(1<partbooks[partword[j][i]][s]; + if(statebook){ + int ret; + long *accumulator=NULL; + #ifdef TRAIN_RES - accumulator=look->training_data[s][partword[j][i]]; - { - int l; - float *samples=in[j]+offset; - for(l=0;ltraining_min[s][partword[j][i]]) - look->training_min[s][partword[j][i]]=samples[l]; - if(samples[l]>look->training_max[s][partword[j][i]]) - look->training_max[s][partword[j][i]]=samples[l]; - } - } + accumulator=look->training_data[s][partword[j][i]]; + { + int l; + float *samples=in[j]+offset; + for(l=0;ltraining_min[s][partword[j][i]]) + look->training_min[s][partword[j][i]]=samples[l]; + if(samples[l]>look->training_max[s][partword[j][i]]) + look->training_max[s][partword[j][i]]=samples[l]; + } + } #endif - - ret=encode(opb,in[j]+offset,samples_per_partition, - statebook,accumulator); - - look->postbits+=ret; - resbits[partword[j][i]]+=ret; - } - } - } + + ret=encode(opb,in[j]+offset,samples_per_partition, + statebook,accumulator); + + look->postbits+=ret; + resbits[partword[j][i]]+=ret; + } + } + } } } } @@ -609,9 +623,9 @@ static int _01forward(oggpack_buffer *opb, /* a truncated packet here just means 'stop working'; it's not an error */ static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl, - float **in,int ch, - long (*decodepart)(codebook *, float *, - oggpack_buffer *,int)){ + float **in,int ch, + long (*decodepart)(codebook *, float *, + oggpack_buffer *,int)){ long i,j,k,l,s; vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl; @@ -635,31 +649,31 @@ static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl, for(s=0;sstages;s++){ /* each loop decodes on partition codeword containing - partitions_per_word partitions */ + partitions_per_word partitions */ for(i=0,l=0;iphrasebook,&vb->opb); - - if(temp==-1)goto eopbreak; - partword[j][l]=look->decodemap[temp]; - if(partword[j][l]==NULL)goto errout; - } - } - - /* now we decode residual values for the partitions */ - for(k=0;kbegin+i*samples_per_partition; - if(info->secondstages[partword[j][l][k]]&(1<partbooks[partword[j][l][k]][s]; - if(stagebook){ - if(decodepart(stagebook,in[j]+offset,&vb->opb, - samples_per_partition)==-1)goto eopbreak; - } - } - } + if(s==0){ + /* fetch the partition word for each channel */ + for(j=0;jphrasebook,&vb->opb); + + if(temp==-1)goto eopbreak; + partword[j][l]=look->decodemap[temp]; + if(partword[j][l]==NULL)goto errout; + } + } + + /* now we decode residual values for the partitions */ + for(k=0;kbegin+i*samples_per_partition; + if(info->secondstages[partword[j][l][k]]&(1<partbooks[partword[j][l][k]][s]; + if(stagebook){ + if(decodepart(stagebook,in[j]+offset,&vb->opb, + samples_per_partition)==-1)goto eopbreak; + } + } + } } } } @@ -672,7 +686,7 @@ static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl, /* residue 0 and 1 are just slight variants of one another. 0 is interleaved, 1 is not */ long **res0_class(vorbis_block *vb,vorbis_look_residue *vl, - float **in,int *nonzero,int ch){ + float **in,int *nonzero,int ch){ /* we encode only the nonzero parts of a bundle */ int i,used=0; for(i=0;ipcmend/2; for(i=0;ipcmend/2; for(i=0;ipcmend/2,used=0; /* don't duplicate the code; use a working vector hack for now and @@ -817,11 +831,11 @@ int res2_forward(oggpack_buffer *opb, /* update the sofar vector */ if(out){ for(i=0;iinfo; @@ -854,27 +868,27 @@ int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl, for(s=0;sstages;s++){ for(i=0,l=0;iphrasebook,&vb->opb); - if(temp==-1)goto eopbreak; - partword[l]=look->decodemap[temp]; - if(partword[l]==NULL)goto errout; - } - - /* now we decode residual values for the partitions */ - for(k=0;ksecondstages[partword[l][k]]&(1<partbooks[partword[l][k]][s]; - - if(stagebook){ - if(vorbis_book_decodevv_add(stagebook,in, - i*samples_per_partition+info->begin,ch, - &vb->opb,samples_per_partition)==-1) - goto eopbreak; - } - } + + if(s==0){ + /* fetch the partition word */ + int temp=vorbis_book_decode(look->phrasebook,&vb->opb); + if(temp==-1)goto eopbreak; + partword[l]=look->decodemap[temp]; + if(partword[l]==NULL)goto errout; + } + + /* now we decode residual values for the partitions */ + for(k=0;ksecondstages[partword[l][k]]&(1<partbooks[partword[l][k]][s]; + + if(stagebook){ + if(vorbis_book_decodevv_add(stagebook,in, + i*samples_per_partition+info->begin,ch, + &vb->opb,samples_per_partition)==-1) + goto eopbreak; + } + } } } } @@ -884,7 +898,7 @@ int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl, } -vorbis_func_residue residue0_exportbundle={ +const vorbis_func_residue residue0_exportbundle={ NULL, &res0_unpack, &res0_look, @@ -895,7 +909,7 @@ vorbis_func_residue residue0_exportbundle={ &res0_inverse }; -vorbis_func_residue residue1_exportbundle={ +const vorbis_func_residue residue1_exportbundle={ &res0_pack, &res0_unpack, &res0_look, @@ -906,7 +920,7 @@ vorbis_func_residue residue1_exportbundle={ &res1_inverse }; -vorbis_func_residue residue2_exportbundle={ +const vorbis_func_residue residue2_exportbundle={ &res0_pack, &res0_unpack, &res0_look, diff --git a/media/libvorbis/lib/vorbis_sharedbook.c b/media/libvorbis/lib/vorbis_sharedbook.c index 1bf4140ed97..2984a9eaf77 100644 --- a/media/libvorbis/lib/vorbis_sharedbook.c +++ b/media/libvorbis/lib/vorbis_sharedbook.c @@ -11,7 +11,7 @@ ******************************************************************** function: basic shared codebook operations - last mod: $Id: sharedbook.c 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -82,49 +82,62 @@ ogg_uint32_t *_make_words(long *l,long n,long sparsecount){ ogg_uint32_t entry=marker[length]; /* when we claim a node for an entry, we also claim the nodes - below it (pruning off the imagined tree that may have dangled - from it) as well as blocking the use of any nodes directly - above for leaves */ + below it (pruning off the imagined tree that may have dangled + from it) as well as blocking the use of any nodes directly + above for leaves */ /* update ourself */ if(length<32 && (entry>>length)){ - /* error condition; the lengths must specify an overpopulated tree */ - _ogg_free(r); - return(NULL); + /* error condition; the lengths must specify an overpopulated tree */ + _ogg_free(r); + return(NULL); } r[count++]=entry; /* Look to see if the next shorter marker points to the node - above. if so, update it and repeat. */ + above. if so, update it and repeat. */ { - for(j=length;j>0;j--){ - - if(marker[j]&1){ - /* have to jump branches */ - if(j==1) - marker[1]++; - else - marker[j]=marker[j-1]<<1; - break; /* invariant says next upper marker would already - have been moved if it was on the same path */ - } - marker[j]++; - } + for(j=length;j>0;j--){ + + if(marker[j]&1){ + /* have to jump branches */ + if(j==1) + marker[1]++; + else + marker[j]=marker[j-1]<<1; + break; /* invariant says next upper marker would already + have been moved if it was on the same path */ + } + marker[j]++; + } } /* prune the tree; the implicit invariant says all the longer - markers were dangling from our just-taken node. Dangle them - from our *new* node. */ + markers were dangling from our just-taken node. Dangle them + from our *new* node. */ for(j=length+1;j<33;j++) - if((marker[j]>>1) == entry){ - entry=marker[j]; - marker[j]=marker[j-1]<<1; - }else - break; + if((marker[j]>>1) == entry){ + entry=marker[j]; + marker[j]=marker[j-1]<<1; + }else + break; }else if(sparsecount==0)count++; } - + + /* sanity check the huffman tree; an underpopulated tree must be + rejected. The only exception is the one-node pseudo-nil tree, + which appears to be underpopulated because the tree doesn't + really exist; there's only one possible 'codeword' or zero bits, + but the above tree-gen code doesn't mark that. */ + if(sparsecount != 1){ + for(i=1;i<33;i++) + if(marker[i] & (0xffffffffUL>>(32-i))){ + _ogg_free(r); + return(NULL); + } + } + /* bitreverse the words because our bitwise packer/unpacker is LSb endian */ for(i=0,count=0;ib->entries){ - vals--; + vals--; }else{ - vals++; + vals++; } } } @@ -193,49 +206,49 @@ float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){ switch(b->maptype){ case 1: /* most of the time, entries%dimensions == 0, but we need to be - well defined. We define that the possible vales at each - scalar is values == entries/dim. If entries%dim != 0, we'll - have 'too few' values (values*dimentries;j++){ - if((sparsemap && b->lengthlist[j]) || !sparsemap){ - float last=0.f; - int indexdiv=1; - for(k=0;kdim;k++){ - int index= (j/indexdiv)%quantvals; - float val=b->quantlist[index]; - val=fabs(val)*delta+mindel+last; - if(b->q_sequencep)last=val; - if(sparsemap) - r[sparsemap[count]*b->dim+k]=val; - else - r[count*b->dim+k]=val; - indexdiv*=quantvals; - } - count++; - } + if((sparsemap && b->lengthlist[j]) || !sparsemap){ + float last=0.f; + int indexdiv=1; + for(k=0;kdim;k++){ + int index= (j/indexdiv)%quantvals; + float val=b->quantlist[index]; + val=fabs(val)*delta+mindel+last; + if(b->q_sequencep)last=val; + if(sparsemap) + r[sparsemap[count]*b->dim+k]=val; + else + r[count*b->dim+k]=val; + indexdiv*=quantvals; + } + count++; + } } break; case 2: for(j=0;jentries;j++){ - if((sparsemap && b->lengthlist[j]) || !sparsemap){ - float last=0.f; - - for(k=0;kdim;k++){ - float val=b->quantlist[j*b->dim+k]; - val=fabs(val)*delta+mindel+last; - if(b->q_sequencep)last=val; - if(sparsemap) - r[sparsemap[count]*b->dim+k]=val; - else - r[count*b->dim+k]=val; - } - count++; - } + if((sparsemap && b->lengthlist[j]) || !sparsemap){ + float last=0.f; + + for(k=0;kdim;k++){ + float val=b->quantlist[j*b->dim+k]; + val=fabs(val)*delta+mindel+last; + if(b->q_sequencep)last=val; + if(sparsemap) + r[sparsemap[count]*b->dim+k]=val; + else + r[count*b->dim+k]=val; + } + count++; + } } break; } @@ -372,12 +385,12 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ for(n=0,i=0;ientries;i++) if(s->lengthlist[i]>0) - c->dec_index[sortindex[n++]]=i; + c->dec_index[sortindex[n++]]=i; c->dec_codelengths=_ogg_malloc(n*sizeof(*c->dec_codelengths)); for(n=0,i=0;ientries;i++) if(s->lengthlist[i]>0) - c->dec_codelengths[sortindex[n++]]=s->lengthlist[i]; + c->dec_codelengths[sortindex[n++]]=s->lengthlist[i]; c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */ if(c->dec_firsttablen<5)c->dec_firsttablen=5; @@ -389,11 +402,11 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ for(i=0;idec_maxlengthdec_codelengths[i]) - c->dec_maxlength=c->dec_codelengths[i]; + c->dec_maxlength=c->dec_codelengths[i]; if(c->dec_codelengths[i]<=c->dec_firsttablen){ - ogg_uint32_t orig=bitreverse(c->codelist[i]); - for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++) - c->dec_firsttable[orig|(j<dec_codelengths[i])]=i+1; + ogg_uint32_t orig=bitreverse(c->codelist[i]); + for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++) + c->dec_firsttable[orig|(j<dec_codelengths[i])]=i+1; } } @@ -404,24 +417,24 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ long lo=0,hi=0; for(i=0;idec_firsttablen); - if(c->dec_firsttable[bitreverse(word)]==0){ - while((lo+1)codelist[lo+1]<=word)lo++; - while( hi=(c->codelist[hi]&mask))hi++; - - /* we only actually have 15 bits per hint to play with here. - In order to overflow gracefully (nothing breaks, efficiency - just drops), encode as the difference from the extremes. */ - { - unsigned long loval=lo; - unsigned long hival=n-hi; - - if(loval>0x7fff)loval=0x7fff; - if(hival>0x7fff)hival=0x7fff; - c->dec_firsttable[bitreverse(word)]= - 0x80000000UL | (loval<<15) | hival; - } - } + ogg_uint32_t word=i<<(32-c->dec_firsttablen); + if(c->dec_firsttable[bitreverse(word)]==0){ + while((lo+1)codelist[lo+1]<=word)lo++; + while( hi=(c->codelist[hi]&mask))hi++; + + /* we only actually have 15 bits per hint to play with here. + In order to overflow gracefully (nothing breaks, efficiency + just drops), encode as the difference from the extremes. */ + { + unsigned long loval=lo; + unsigned long hival=n-hi; + + if(loval>0x7fff)loval=0x7fff; + if(hival>0x7fff)hival=0x7fff; + c->dec_firsttable[bitreverse(word)]= + 0x80000000UL | (loval<<15) | hival; + } + } } } } @@ -463,14 +476,14 @@ int _best(codebook *book, float *a, int step){ i=tt->threshvals>>1; if(a[o]quantthresh[i]){ - for(;i>0;i--) - if(a[o]>=tt->quantthresh[i-1]) - break; - + for(;i>0;i--) + if(a[o]>=tt->quantthresh[i-1]) + break; + }else{ - for(i++;ithreshvals-1;i++) - if(a[o]quantthresh[i])break; + for(i++;ithreshvals-1;i++) + if(a[o]quantthresh[i])break; } @@ -478,8 +491,8 @@ int _best(codebook *book, float *a, int step){ } /* regular lattices are easy :-) */ if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll - use a decision tree after all - and fall through*/ + use a decision tree after all + and fall through*/ return(index); } @@ -497,17 +510,17 @@ int _best(codebook *book, float *a, int step){ long mul=1; float qlast=0; for(k=0,o=0;kmin)/pt->del); - if(pv<0 || pv>=pt->mapentries)break; - entry+=pt->pigeonmap[pv]*mul; - mul*=pt->quantvals; - qlast+=pv*pt->del+pt->min; + pv=(int)((a[o]-qlast-pt->min)/pt->del); + if(pv<0 || pv>=pt->mapentries)break; + entry+=pt->pigeonmap[pv]*mul; + mul*=pt->quantvals; + qlast+=pv*pt->del+pt->min; } }else{ for(k=0,o=step*(dim-1);kmin)/pt->del); - if(pv<0 || pv>=pt->mapentries)break; - entry=entry*pt->quantvals+pt->pigeonmap[pv]; + int pv=(int)((a[o]-pt->min)/pt->del); + if(pv<0 || pv>=pt->mapentries)break; + entry=entry*pt->quantvals+pt->pigeonmap[pv]; } } @@ -517,11 +530,11 @@ int _best(codebook *book, float *a, int step){ /* search the abbreviated list */ long *list=pt->fitlist+pt->fitmap[entry]; for(i=0;ifitlength[entry];i++){ - float this=_dist(dim,book->valuelist+list[i]*dim,a,step); - if(besti==-1 || thisvaluelist+list[i]*dim,a,step); + if(besti==-1 || thisvaluelist+nt->q[ptr]; for(k=0,o=0;k0.f) /* in A */ - ptr= -nt->ptr0[ptr]; + ptr= -nt->ptr0[ptr]; else /* in B */ - ptr= -nt->ptr1[ptr]; + ptr= -nt->ptr1[ptr]; if(ptr<=0)break; } return(-ptr); @@ -556,27 +569,27 @@ int _best(codebook *book, float *a, int step){ float *e=book->valuelist; for(i=0;ientries;i++){ if(c->lengthlist[i]>0){ - float this=_dist(dim,e,a,step); - if(besti==-1 || thisvaluelist+savebest*dim)[i]); + (book->valuelist+savebest*dim)[i]); fprintf(stderr,"\n" - "bruteforce (entry %d, err %g):",besti,best); + "bruteforce (entry %d, err %g):",besti,best); for(i=0;ivaluelist+besti*dim)[i]); + (book->valuelist+besti*dim)[i]); fprintf(stderr,"\n"); }*/ return(besti); @@ -625,7 +638,8 @@ static_codebook test1={ 0, 0,0,0,0, NULL, - NULL,NULL + NULL,NULL,NULL, + 0 }; static float *test1_result=NULL; @@ -636,7 +650,8 @@ static_codebook test2={ 2, -533200896,1611661312,4,0, full_quantlist1, - NULL,NULL + NULL,NULL,NULL, + 0 }; static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2}; @@ -647,7 +662,8 @@ static_codebook test3={ 2, -533200896,1611661312,4,1, full_quantlist1, - NULL,NULL + NULL,NULL,NULL, + 0 }; static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6}; @@ -658,17 +674,18 @@ static_codebook test4={ 1, -533200896,1611661312,4,0, partial_quantlist1, - NULL,NULL + NULL,NULL,NULL, + 0 }; static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3, - -3, 4,-3, 4, 4,-3, -1, 4,-3, - -3,-1,-3, 4,-1,-3, -1,-1,-3, - -3,-3, 4, 4,-3, 4, -1,-3, 4, - -3, 4, 4, 4, 4, 4, -1, 4, 4, - -3,-1, 4, 4,-1, 4, -1,-1, 4, - -3,-3,-1, 4,-3,-1, -1,-3,-1, - -3, 4,-1, 4, 4,-1, -1, 4,-1, - -3,-1,-1, 4,-1,-1, -1,-1,-1}; + -3, 4,-3, 4, 4,-3, -1, 4,-3, + -3,-1,-3, 4,-1,-3, -1,-1,-3, + -3,-3, 4, 4,-3, 4, -1,-3, 4, + -3, 4, 4, 4, 4, 4, -1, 4, 4, + -3,-1, 4, 4,-1, 4, -1,-1, 4, + -3,-3,-1, 4,-3,-1, -1,-3,-1, + -3, 4,-1, 4, 4,-1, -1, 4,-1, + -3,-1,-1, 4,-1,-1, -1,-1,-1}; /* linear, algorithmic mapping, sequential */ static_codebook test5={ @@ -677,17 +694,18 @@ static_codebook test5={ 1, -533200896,1611661312,4,1, partial_quantlist1, - NULL,NULL + NULL,NULL,NULL, + 0 }; static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7, - -3, 1,-2, 4, 8, 5, -1, 3, 0, - -3,-4,-7, 4, 3, 0, -1,-2,-5, - -3,-6,-2, 4, 1, 5, -1,-4, 0, - -3, 1, 5, 4, 8,12, -1, 3, 7, - -3,-4, 0, 4, 3, 7, -1,-2, 2, - -3,-6,-7, 4, 1, 0, -1,-4,-5, - -3, 1, 0, 4, 8, 7, -1, 3, 2, - -3,-4,-5, 4, 3, 2, -1,-2,-3}; + -3, 1,-2, 4, 8, 5, -1, 3, 0, + -3,-4,-7, 4, 3, 0, -1,-2,-5, + -3,-6,-2, 4, 1, 5, -1,-4, 0, + -3, 1, 5, 4, 8,12, -1, 3, 7, + -3,-4, 0, 4, 3, 7, -1,-2, 2, + -3,-6,-7, 4, 1, 0, -1,-4,-5, + -3, 1, 0, 4, 8, 7, -1, 3, 2, + -3,-4,-5, 4, 3, 2, -1,-2,-3}; void run_test(static_codebook *b,float *comp){ float *out=_book_unquantize(b,b->entries,NULL); @@ -701,15 +719,15 @@ void run_test(static_codebook *b,float *comp){ for(i=0;ientries*b->dim;i++) if(fabs(out[i]-comp[i])>.0001){ - fprintf(stderr,"disagreement in unquantized and reference data:\n" - "position %d, %g != %g\n",i,out[i],comp[i]); - exit(1); + fprintf(stderr,"disagreement in unquantized and reference data:\n" + "position %d, %g != %g\n",i,out[i],comp[i]); + exit(1); } }else{ if(out){ fprintf(stderr,"_book_unquantize returned a value array: \n" - " correct result should have been NULL\n"); + " correct result should have been NULL\n"); exit(1); } } diff --git a/media/libvorbis/lib/vorbis_smallft.c b/media/libvorbis/lib/vorbis_smallft.c index a78e9236860..3bfaab5f508 100644 --- a/media/libvorbis/lib/vorbis_smallft.c +++ b/media/libvorbis/lib/vorbis_smallft.c @@ -11,7 +11,7 @@ ******************************************************************** function: *unnormalized* fft transform - last mod: $Id: smallft.c 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -94,10 +94,10 @@ static void drfti1(int n, float *wa, int *ifac){ argld=(float)ld*argh; fi=0.f; for (ii=2;iimap_type[ci->mode_param[mode]->mapping]; return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]-> - mapping])); + mapping])); } /* used to track pcm position without actually performing decode. diff --git a/media/libvorbis/lib/vorbis_window.c b/media/libvorbis/lib/vorbis_window.c index 6cf6d40a12c..ffcd090cc40 100644 --- a/media/libvorbis/lib/vorbis_window.c +++ b/media/libvorbis/lib/vorbis_window.c @@ -11,7 +11,7 @@ ******************************************************************** function: window functions - last mod: $Id: window.c 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ @@ -20,7 +20,7 @@ #include "os.h" #include "misc.h" -static float vwin64[32] = { +static const float vwin64[32] = { 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F, 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F, 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F, @@ -31,7 +31,7 @@ static float vwin64[32] = { 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F, }; -static float vwin128[64] = { +static const float vwin128[64] = { 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F, 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F, 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F, @@ -50,7 +50,7 @@ static float vwin128[64] = { 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F, }; -static float vwin256[128] = { +static const float vwin256[128] = { 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F, 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F, 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F, @@ -85,7 +85,7 @@ static float vwin256[128] = { 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F, }; -static float vwin512[256] = { +static const float vwin512[256] = { 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F, 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F, 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F, @@ -152,7 +152,7 @@ static float vwin512[256] = { 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F, }; -static float vwin1024[512] = { +static const float vwin1024[512] = { 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F, 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F, 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F, @@ -283,7 +283,7 @@ static float vwin1024[512] = { 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F, }; -static float vwin2048[1024] = { +static const float vwin2048[1024] = { 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F, 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F, 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F, @@ -542,7 +542,7 @@ static float vwin2048[1024] = { 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F, }; -static float vwin4096[2048] = { +static const float vwin4096[2048] = { 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F, 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F, 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F, @@ -1057,7 +1057,7 @@ static float vwin4096[2048] = { 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F, }; -static float vwin8192[4096] = { +static const float vwin8192[4096] = { 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F, 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F, 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F, @@ -2084,7 +2084,7 @@ static float vwin8192[4096] = { 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F, }; -static float *vwin[8] = { +static const float *const vwin[8] = { vwin64, vwin128, vwin256, @@ -2095,18 +2095,18 @@ static float *vwin[8] = { vwin8192, }; -float *_vorbis_window_get(int n){ +const float *_vorbis_window_get(int n){ return vwin[n]; } void _vorbis_apply_window(float *d,int *winno,long *blocksizes, - int lW,int W,int nW){ + int lW,int W,int nW){ lW=(W?lW:0); nW=(W?nW:0); { - float *windowLW=vwin[winno[lW]]; - float *windowNW=vwin[winno[nW]]; + const float *windowLW=vwin[winno[lW]]; + const float *windowNW=vwin[winno[nW]]; long n=blocksizes[W]; long ln=blocksizes[lW]; diff --git a/media/libvorbis/lib/window.h b/media/libvorbis/lib/window.h index 192bd9cfe7f..a13babad5e9 100644 --- a/media/libvorbis/lib/window.h +++ b/media/libvorbis/lib/window.h @@ -11,7 +11,7 @@ ******************************************************************** function: window functions - last mod: $Id: window.h 13293 2007-07-24 00:09:47Z xiphmont $ + last mod: $Id$ ********************************************************************/ diff --git a/media/libvorbis/update.sh b/media/libvorbis/update.sh index ffb55d1b523..0f09a5a6b16 100644 --- a/media/libvorbis/update.sh +++ b/media/libvorbis/update.sh @@ -49,6 +49,4 @@ cp $1/AUTHORS ./AUTHORS patch -p3 < ./alloca.diff patch -p3 <./bug481601.patch patch -p3 Date: Mon, 6 Jul 2009 18:23:24 -0700 Subject: [PATCH 013/166] Bug 389462 - columns don't reflow on resize r=roc --- layout/generic/nsBlockFrame.cpp | 12 +++++++- layout/generic/nsColumnSetFrame.cpp | 12 +++++++- layout/reftests/pagination/reftest.list | 2 ++ .../pagination/resize-reflow-000.html | 28 +++++++++++++++++++ .../pagination/resize-reflow-000.ref.html | 22 +++++++++++++++ .../pagination/resize-reflow-001.html | 19 +++++++++++++ .../pagination/resize-reflow-001.inner.html | 26 +++++++++++++++++ .../pagination/resize-reflow-001.ref.html | 22 +++++++++++++++ 8 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 layout/reftests/pagination/resize-reflow-000.html create mode 100644 layout/reftests/pagination/resize-reflow-000.ref.html create mode 100644 layout/reftests/pagination/resize-reflow-001.html create mode 100644 layout/reftests/pagination/resize-reflow-001.inner.html create mode 100644 layout/reftests/pagination/resize-reflow-001.ref.html diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp index 54d4d9b7355..edb8768d3a7 100644 --- a/layout/generic/nsBlockFrame.cpp +++ b/layout/generic/nsBlockFrame.cpp @@ -1777,7 +1777,17 @@ nsBlockFrame::ReflowDirtyLines(nsBlockReflowState& aState) PRBool selfDirty = (GetStateBits() & NS_FRAME_IS_DIRTY) || (aState.mReflowState.mFlags.mVResize && (GetStateBits() & NS_FRAME_CONTAINS_RELATIVE_HEIGHT)); - + + // Reflow our last line if our availableHeight has increased + // so that we (and our last child) pull up content as necessary + if (aState.mReflowState.availableHeight != NS_UNCONSTRAINEDSIZE + && GetNextInFlow() && aState.mReflowState.availableHeight > mRect.height) { + line_iterator lastLine = end_lines(); + if (lastLine != begin_lines()) { + --lastLine; + lastLine->MarkDirty(); + } + } // the amount by which we will slide the current line if it is not // dirty nscoord deltaY = 0; diff --git a/layout/generic/nsColumnSetFrame.cpp b/layout/generic/nsColumnSetFrame.cpp index d7e48e8eac2..4f678a19567 100644 --- a/layout/generic/nsColumnSetFrame.cpp +++ b/layout/generic/nsColumnSetFrame.cpp @@ -591,7 +591,7 @@ nsColumnSetFrame::ReflowChildren(nsHTMLReflowMetrics& aDesiredSize, // content from its next sibling. (Note that it might be the last // column, but not be the last child because the desired number of columns // has changed.) - PRBool skipIncremental = !(GetStateBits() & NS_FRAME_IS_DIRTY) + PRBool skipIncremental = !aReflowState.ShouldReflowAllKids() && !NS_SUBTREE_DIRTY(child) && child->GetNextSibling() && !(aUnboundedLastColumn && columnCount == aConfig.mBalanceColCount - 1) @@ -907,6 +907,16 @@ nsColumnSetFrame::Reflow(nsPresContext* aPresContext, // Initialize OUT parameter aStatus = NS_FRAME_COMPLETE; + // Our children depend on our height if we have a fixed height. + if (aReflowState.ComputedHeight() != NS_AUTOHEIGHT) { + NS_ASSERTION(aReflowState.ComputedHeight() != NS_INTRINSICSIZE, + "Unexpected mComputedHeight"); + AddStateBits(NS_FRAME_CONTAINS_RELATIVE_HEIGHT); + } + else { + RemoveStateBits(NS_FRAME_CONTAINS_RELATIVE_HEIGHT); + } + //------------ Handle Incremental Reflow ----------------- ReflowConfig config = ChooseColumnStrategy(aReflowState); diff --git a/layout/reftests/pagination/reftest.list b/layout/reftests/pagination/reftest.list index 4bbca1acdd7..330baad8e52 100644 --- a/layout/reftests/pagination/reftest.list +++ b/layout/reftests/pagination/reftest.list @@ -23,3 +23,5 @@ fails == border-breaking-004-cols.xhtml border-breaking-002-cols.ref.xhtml == abspos-breaking-000.xhtml abspos-breaking-000.ref.xhtml == abspos-breaking-001.xhtml abspos-breaking-000.ref.xhtml == abspos-breaking-002.xhtml abspos-breaking-000.ref.xhtml +== resize-reflow-000.html resize-reflow-000.ref.html +== resize-reflow-001.html resize-reflow-001.ref.html diff --git a/layout/reftests/pagination/resize-reflow-000.html b/layout/reftests/pagination/resize-reflow-000.html new file mode 100644 index 00000000000..549b04d611f --- /dev/null +++ b/layout/reftests/pagination/resize-reflow-000.html @@ -0,0 +1,28 @@ + + + + Resize Reflow Test + + + +
+x
+ blah
+ blah
+ blah
+ blah +
+
+ + + + + diff --git a/layout/reftests/pagination/resize-reflow-000.ref.html b/layout/reftests/pagination/resize-reflow-000.ref.html new file mode 100644 index 00000000000..5190ce1d1fa --- /dev/null +++ b/layout/reftests/pagination/resize-reflow-000.ref.html @@ -0,0 +1,22 @@ + + + + Resize Reflow Test + + + +
+
+ blah
+ blah
+ blah
+ blah +
+
+ + + diff --git a/layout/reftests/pagination/resize-reflow-001.html b/layout/reftests/pagination/resize-reflow-001.html new file mode 100644 index 00000000000..b28a07d657e --- /dev/null +++ b/layout/reftests/pagination/resize-reflow-001.html @@ -0,0 +1,19 @@ + + +Resize Reflow Harness + + + + + + diff --git a/layout/reftests/pagination/resize-reflow-001.inner.html b/layout/reftests/pagination/resize-reflow-001.inner.html new file mode 100644 index 00000000000..91130ff868c --- /dev/null +++ b/layout/reftests/pagination/resize-reflow-001.inner.html @@ -0,0 +1,26 @@ + + + + Resize Reflow Test + + + + +
+
+ blah
+ blah
+ blah
+ blah +
+
+ + + diff --git a/layout/reftests/pagination/resize-reflow-001.ref.html b/layout/reftests/pagination/resize-reflow-001.ref.html new file mode 100644 index 00000000000..b35efa7c0a9 --- /dev/null +++ b/layout/reftests/pagination/resize-reflow-001.ref.html @@ -0,0 +1,22 @@ + + + + Resize Reflow Test + + + +
+
+ blah
+ blah
+ blah
+ blah +
+
+ + + From 0bd7a100df3f8e97f1ca5c1059cb9b0372bdec92 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Tue, 7 Jul 2009 10:47:08 +0900 Subject: [PATCH 014/166] Bug 498079 Firefox has huge problems to show the Default Browser dialog on the screen r=ere+roc, sr=roc --- widget/src/windows/nsSound.cpp | 83 ++++++++++++++++++++++++++++++++-- widget/src/windows/nsSound.h | 2 + 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/widget/src/windows/nsSound.cpp b/widget/src/windows/nsSound.cpp index 839a301900a..d1c61f12ce5 100644 --- a/widget/src/windows/nsSound.cpp +++ b/widget/src/windows/nsSound.cpp @@ -53,6 +53,68 @@ #include "nsNativeCharsetUtils.h" +class nsSoundPlayer: public nsRunnable { +public: + nsSoundPlayer(nsISound *aSound, const wchar_t* aSoundName) : + mSound(aSound), mSoundName(aSoundName) + { + Init(); + } + + nsSoundPlayer(nsISound *aSound, const nsAString& aSoundName) : + mSound(aSound), mSoundName(aSoundName) + { + Init(); + } + + NS_DECL_NSIRUNNABLE + +protected: + nsString mSoundName; + nsISound *mSound; // Strong, but this will be released from SoundReleaser. + nsCOMPtr mThread; + + void Init() + { + NS_GetCurrentThread(getter_AddRefs(mThread)); + NS_ASSERTION(mThread, "failed to get current thread"); + NS_IF_ADDREF(mSound); + } + + class SoundReleaser: public nsRunnable { + public: + SoundReleaser(nsISound* aSound) : + mSound(aSound) + { + } + + NS_DECL_NSIRUNNABLE + + protected: + nsISound *mSound; + }; +}; + +NS_IMETHODIMP +nsSoundPlayer::Run() +{ + NS_PRECONDITION(!mSoundName.IsEmpty(), "Sound name should not be empty"); + ::PlaySoundW(mSoundName.get(), NULL, SND_NODEFAULT | SND_ALIAS | SND_ASYNC); + nsCOMPtr releaser = new SoundReleaser(mSound); + // Don't release nsISound from here, because here is not an owning thread of + // the nsSound. nsSound must be released in its owning thread. + mThread->Dispatch(releaser, NS_DISPATCH_NORMAL); + return NS_OK; +} + +NS_IMETHODIMP +nsSoundPlayer::SoundReleaser::Run() +{ + NS_IF_RELEASE(mSound); + return NS_OK; +} + + #ifndef SND_PURGE // Not available on Windows CE, and according to MSDN // doesn't do anything on recent windows either. @@ -73,6 +135,10 @@ nsSound::~nsSound() } void nsSound::PurgeLastSound() { + if (mPlayerThread) { + mPlayerThread->Shutdown(); + mPlayerThread = nsnull; + } if (mLastSound) { // Halt any currently playing sound. ::PlaySound(nsnull, nsnull, SND_PURGE); @@ -171,8 +237,12 @@ NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias) PurgeLastSound(); if (!NS_IsMozAliasSound(aSoundAlias)) { - ::PlaySoundW(PromiseFlatString(aSoundAlias).get(), nsnull, - SND_NODEFAULT | SND_ALIAS | SND_ASYNC); + if (aSoundAlias.IsEmpty()) + return NS_OK; + nsCOMPtr player = new nsSoundPlayer(this, aSoundAlias); + NS_ENSURE_TRUE(player, NS_ERROR_OUT_OF_MEMORY); + nsresult rv = NS_NewThread(getter_AddRefs(mPlayerThread), player); + NS_ENSURE_SUCCESS(rv, rv); return NS_OK; } @@ -189,10 +259,13 @@ NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias) sound = L"MenuCommand"; else if (aSoundAlias.Equals(NS_SYSSOUND_MENU_POPUP)) sound = L"MenuPopup"; + else + return NS_OK; - if (sound) - ::PlaySoundW(sound, nsnull, SND_NODEFAULT | SND_ALIAS | SND_ASYNC); - + nsCOMPtr player = new nsSoundPlayer(this, sound); + NS_ENSURE_TRUE(player, NS_ERROR_OUT_OF_MEMORY); + nsresult rv = NS_NewThread(getter_AddRefs(mPlayerThread), player); + NS_ENSURE_SUCCESS(rv, rv); return NS_OK; } diff --git a/widget/src/windows/nsSound.h b/widget/src/windows/nsSound.h index 0845814fdb9..cd2b9ce5bae 100644 --- a/widget/src/windows/nsSound.h +++ b/widget/src/windows/nsSound.h @@ -42,6 +42,7 @@ #include "nsISound.h" #include "nsIStreamLoader.h" +#include "nsThreadUtils.h" class nsSound : public nsISound, public nsIStreamLoaderObserver @@ -60,6 +61,7 @@ private: private: PRUint8* mLastSound; + nsCOMPtr mPlayerThread; }; #endif /* __nsSound_h__ */ From a5c4a947e89f5943791d8a84a79fa92dcd10b780 Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Tue, 7 Jul 2009 14:02:06 +1200 Subject: [PATCH 015/166] Bug 501535 - Don't update poster attribute on