Index: libhb/Jamfile
===================================================================
--- libhb/Jamfile	(revision 1147)
+++ libhb/Jamfile	(working copy)
@@ -10,8 +10,8 @@
 ipodutil.cpp common.c hb.c ports.c scan.c work.c decmpeg2.c encavcodec.c update.c
 demuxmpeg.c fifo.c render.c reader.c muxcommon.c muxmp4.c sync.c stream.c
 decsub.c deca52.c decdca.c encfaac.c declpcm.c encx264.c decavcodec.c encxvid.c
-muxavi.c enclame.c muxogm.c encvorbis.c dvd.c muxmkv.c deblock.c deinterlace.c 
-denoise.c detelecine.c lang.c ;
+muxavi.c enclame.c muxogm.c encvorbis.c enctheora.c dvd.c muxmkv.c 
+deblock.c deinterlace.c denoise.c detelecine.c lang.c ;
 
 Library libhb : $(LIBHB_SRC) ;
 
Index: libhb/hb.c
===================================================================
--- libhb/hb.c	(revision 1147)
+++ libhb/hb.c	(working copy)
@@ -223,6 +223,7 @@
 	hb_register( &hb_encfaac ); 
 	hb_register( &hb_enclame ); 
 	hb_register( &hb_encvorbis ); 
+	hb_register( &hb_enctheora ); 
 	
 	return h;
 }
Index: libhb/Makefile
===================================================================
--- libhb/Makefile	(revision 1147)
+++ libhb/Makefile	(working copy)
@@ -24,7 +24,8 @@
 SRCS = common.c hb.c ports.c scan.c work.c decmpeg2.c encavcodec.c \
 	   update.c demuxmpeg.c fifo.c render.c reader.c muxcommon.c stream.c \
 	   muxmp4.c sync.c decsub.c deca52.c decdca.c encfaac.c declpcm.c encx264.c \
-	   decavcodec.c encxvid.c muxmkv.c muxavi.c enclame.c muxogm.c encvorbis.c \
+	   decavcodec.c encxvid.c muxmkv.c muxavi.c enclame.c muxogm.c \
+	   encvorbis.c enctheora.c \
 	   dvd.c  ipodutil.cpp deblock.c deinterlace.c denoise.c detelecine.c lang.c
 OTMP = $(SRCS:%.c=%.o) 
 OBJS = $(OTMP:%.cpp=%.o)
@@ -37,6 +38,7 @@
 		   ../contrib/lib/libmpeg2.a ../contrib/lib/libmpeg2convert.a \
 		   ../contrib/lib/libvorbis.a ../contrib/lib/libvorbisenc.a \
 		   ../contrib/lib/libvorbisfile.a ../contrib/lib/libogg.a \
+		   ../contrib/lib/libtheora.a \
 		   ../contrib/lib/libsamplerate.a ../contrib/lib/libx264.a \
 		   ../contrib/lib/libxvidcore.a  ../contrib/lib/libmp4v2.a \
 		   ../contrib/lib/libmkv.a ../contrib/lib/libswscale.a
@@ -48,6 +50,7 @@
 		   ../contrib/lib/libmp3lame.a ../contrib/lib/libmpeg2.a \
 		   ../contrib/lib/libmpeg2convert.a ../contrib/lib/libvorbis.a \
 		   ../contrib/lib/libvorbisenc.a ../contrib/lib/libvorbisfile.a \
+		   ../contrib/lib/libtheora.a \
 		   ../contrib/lib/libogg.a ../contrib/lib/libsamplerate.a \
 		   ../contrib/lib/libx264.a ../contrib/lib/libxvidcore.a \
 		   ../contrib/lib/libmp4v2.a ../contrib/lib/libmkv.a \
Index: libhb/hb.h
===================================================================
--- libhb/hb.h	(revision 1147)
+++ libhb/hb.h	(working copy)
@@ -32,6 +32,7 @@
 hb_register( &hb_encfaac ); \
 hb_register( &hb_enclame ); \
 hb_register( &hb_encvorbis ); \
+hb_register( &hb_enctheora ); \
 
 #define hb_init_express(v,u) \
 hb_init_real( v, u ); \
Index: libhb/enctheora.c
===================================================================
--- libhb/enctheora.c	(revision 0)
+++ libhb/enctheora.c	(revision 0)
@@ -0,0 +1,202 @@
+/* $Id: $
+
+   This file is part of the HandBrake source code.
+   Homepage: <http://handbrake.m0k.org/>.
+   It may be used under the terms of the GNU General Public License. */
+
+#include <stdarg.h>
+
+#include "hb.h"
+
+#include "theora/theora.h"
+
+int  enctheoraInit( hb_work_object_t *, hb_job_t * );
+int  enctheoraWork( hb_work_object_t *, hb_buffer_t **, hb_buffer_t ** );
+void enctheoraClose( hb_work_object_t * );
+
+hb_work_object_t hb_enctheora =
+{
+    WORK_ENCTHEORA,
+    "Theora encoder (libtheora)",
+    enctheoraInit,
+    enctheoraWork,
+    enctheoraClose
+};
+
+struct hb_work_private_s
+{
+    hb_job_t       * job;
+    theora_state     te;
+	ogg_packet       header[3];
+	int	             state;
+};
+
+/***********************************************************************
+ * hb_work_enctheora_init
+ ***********************************************************************
+ *
+ **********************************************************************/
+int enctheoraInit( hb_work_object_t * w, hb_job_t * job )
+{
+    theora_info ti;
+	theora_comment tc;
+	
+    hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) );
+    w->private_data = pv;
+
+    pv->job = job;
+    pv->state = 0;
+	
+    theora_info_init(&ti);
+	ti.width = job->width;
+	ti.height = job->height;
+	
+	/* job frames should always be a multiple of 16 */
+	if ( job->width & 4 )
+	{
+		hb_log( "enctheora: WARNING: frame width %d is not a multiple of 16!", job->width);
+	}
+	ti.frame_width = job->width;
+	ti.offset_x = 0;
+	if ( job->height & 4 )
+	{
+		hb_log( "enctheora: WARNING: frame height %d is not a multiple of 16!", job->height);
+	}
+	ti.frame_height = job->height;
+	ti.offset_y = 0;
+	
+	ti.fps_numerator = job->vrate;
+	ti.fps_denominator = job->vrate_base;
+	
+    if( job->pixel_ratio )
+    {
+        ti.aspect_numerator = job->pixel_aspect_width;
+        ti.aspect_denominator = job->pixel_aspect_height;
+
+        hb_log( "enctheora: encoding with pixel aspect ratio %d:%d",
+                ti.aspect_numerator, ti.aspect_denominator );
+    }
+	else
+	{
+		ti.aspect_numerator = 0;
+		ti.aspect_denominator = 0;
+		
+		hb_log( "enctheora: encoding with an unknown aspect ratio (displayed as 1:1)" );
+	}
+	
+	/* todo: this should be guessable for DVD from the input resolution */
+	ti.colorspace = OC_CS_UNSPECIFIED;
+	ti.pixelformat = OC_PF_420;
+
+    if( job->vquality >= 0.0 && job->vquality <= 1.0 )
+    {
+		/* quality rate-control target */
+		ti.quality = 63.0 * job->vquality;
+		ti.target_bitrate = 0;
+    }
+    else
+    {
+        /* bitrate rate-control target */
+		ti.quality = 0;
+		ti.target_bitrate = job->vbitrate;
+	}
+	
+	ti.dropframes_p = 0;
+	ti.quick_p = 1;
+	ti.keyframe_auto_p = 1;
+	ti.keyframe_frequency = 64;
+	ti.keyframe_frequency_force = 64;
+	ti.keyframe_data_target_bitrate = ti.target_bitrate * 1.5;
+	ti.keyframe_auto_threshold = 80;
+	ti.keyframe_mindistance = 8;
+	ti.noise_sensitivity = 1;
+	ti.sharpness = 0;
+  
+    hb_log( "enctheora: opening libtheora" );
+    theora_encode_init( &(pv->te), &ti );
+	theora_info_clear( &ti );
+
+    /* first header packet (parameters) */
+	theora_encode_header( &pv->te, &pv->header[0] );
+	
+	/* second header packet (metadata) */
+	theora_comment_init( &tc );
+	theora_comment_add_tag( &tc, "Encoder", "HandBreak" );
+	theora_encode_comment( &tc, &(pv->header[1]) );
+	theora_comment_clear( &tc );
+	
+	/* third header packet (tables) */
+	theora_encode_tables( &(pv->te), &(pv->header[2]) );
+	pv->state = 1;
+	
+	return 0;
+}
+
+void enctheoraClose( hb_work_object_t * w )
+{
+    hb_work_private_t * pv = w->private_data;
+	
+	theora_clear( &(pv->te) );
+	if( pv->state > 1 )
+	{
+		ogg_packet_clear( &(pv->header[2]) );
+		ogg_packet_clear( &(pv->header[1]) );
+		ogg_packet_clear( &(pv->header[0]) );
+	}
+    free( pv );
+    w->private_data = NULL;
+}
+
+int enctheoraWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
+                  hb_buffer_t ** buf_out )
+{
+    hb_work_private_t * pv = w->private_data;
+    hb_job_t    * job = pv->job;
+    hb_buffer_t * in = *buf_in, * buf;
+	yuv_buffer    yuv;
+	ogg_packet    op;
+    int           result;
+	
+	/* the libtheora encoder has no latency, so we can quit as soon as there's no more input */
+	if( !in->data )
+	{
+	    buf_out = NULL;
+		return HB_WORK_DONE;
+	}
+
+    /* compress a frame */
+	if( job->grayscale ) {
+		/* todo: make a local uv planes with gray chroma; in->data is y-plane only */
+		return HB_WORK_ERROR;
+	}
+	yuv.y = in->data;
+	yuv.y_stride = job->width;
+	yuv.y_width = job->width;
+	yuv.y_height = job->height;
+	yuv.u = in->data + job->width * job->height;
+	yuv.v = in->data + job->width * job->height * 5 / 4;
+	yuv.uv_stride = job->width / 2;
+	yuv.uv_width = job->width / 2;
+	yuv.uv_height = job->height / 2;
+	result = theora_encode_YUVin( &pv->te, &yuv );
+	if( result != 0 ) return HB_WORK_ERROR;
+	result = theora_encode_packetout( & pv->te, 0, &op ); 
+	if( result != 1 ) return HB_WORK_ERROR;
+
+    /* libtheora owns op.packet; copy it into the buffer list for return */
+	buf = hb_buffer_init(op.bytes);
+	if( !buf ) return HB_WORK_ERROR;
+	memcpy( buf->data, op.packet, op.bytes );
+	buf->size  = op.bytes;
+	buf->start = in->start;
+	buf->stop  = in->stop;
+	buf->frametype = theora_packet_iskeyframe( &op ) ? HB_FRAME_I : HB_FRAME_P;
+		
+    *buf_out = buf;
+
+    return HB_WORK_OK;
+}
+
+
+
+
Index: libhb/internal.h
===================================================================
--- libhb/internal.h	(revision 1147)
+++ libhb/internal.h	(working copy)
@@ -202,7 +202,8 @@
     WORK_DECLPCM,
     WORK_ENCFAAC,
     WORK_ENCLAME,
-    WORK_ENCVORBIS
+    WORK_ENCVORBIS,
+    WORK_ENCTHEORA
 };
 
 enum
Index: libhb/work.c
===================================================================
--- libhb/work.c	(revision 1147)
+++ libhb/work.c	(working copy)
@@ -211,6 +211,13 @@
             hb_log( " + encoder x264" );
             w = getWork( WORK_ENCX264 );
             break;
+		case HB_VCODEC_THEORA:
+			hb_log( " + encoder theora" );
+			w = getWork( WORK_ENCTHEORA );
+			break;
+		default:
+			hb_log( "ERROR: unhandled video codec" );
+			
     }
     w->fifo_in  = job->fifo_render;
     w->fifo_out = job->fifo_mpeg4;
@@ -481,6 +488,8 @@
             case HB_ACODEC_VORBIS:
                 w = getWork( WORK_ENCVORBIS );
                 break;
+			default:
+				hb_log( " ERROR: unhandled audio codec" );
         }
 
         if( job->acodec != HB_ACODEC_AC3 )
Index: libhb/common.h
===================================================================
--- libhb/common.h	(revision 1147)
+++ libhb/common.h	(working copy)
@@ -158,6 +158,7 @@
 #define HB_VCODEC_FFMPEG 0x000001
 #define HB_VCODEC_XVID   0x000002
 #define HB_VCODEC_X264   0x000004
+#define HB_VCODEC_THEORA 0x000008
 
     int             vcodec;
     float           vquality;
@@ -523,6 +524,7 @@
 extern hb_work_object_t hb_encfaac;
 extern hb_work_object_t hb_enclame;
 extern hb_work_object_t hb_encvorbis;
+extern hb_work_object_t hb_enctheora;
 
 #define FILTER_OK      0
 #define FILTER_DELAY   1
Index: macosx/Controller.mm
===================================================================
--- macosx/Controller.mm	(revision 1147)
+++ macosx/Controller.mm	(working copy)
@@ -17,7 +17,7 @@
 
 #define _(a) NSLocalizedString(a,NULL)
 
-static int FormatSettings[4][10] =
+static int FormatSettings[4][11] =
   { { HB_MUX_MP4 | HB_VCODEC_FFMPEG | HB_ACODEC_FAAC,
 	  HB_MUX_MP4 | HB_VCODEC_X264   | HB_ACODEC_FAAC,
 	  0,
@@ -30,6 +30,7 @@
 	  HB_MUX_MKV | HB_VCODEC_X264   | HB_ACODEC_AC3,
 	  HB_MUX_MKV | HB_VCODEC_X264   | HB_ACODEC_LAME,
 	  HB_MUX_MKV | HB_VCODEC_X264   | HB_ACODEC_VORBIS,
+	  HB_MUX_MKV | HB_VCODEC_THEORA | HB_ACODEC_VORBIS,
 	  0,
 	  0 },
     { HB_MUX_AVI | HB_VCODEC_FFMPEG | HB_ACODEC_LAME,
@@ -222,6 +223,7 @@
     [fVidEncoderPopUp removeAllItems];
     [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
     [fVidEncoderPopUp addItemWithTitle: @"XviD"];
+	[fVidEncoderPopUp addItemWithTitle: @"libtheora"];
 	
     
 	
@@ -1400,7 +1402,7 @@
 		
         job->h264_13 = [fVidEncoderPopUp indexOfSelectedItem];
     }
-
+	
     /* Video settings */
     if( [fVidRatePopUp indexOfSelectedItem] > 0 )
     {
@@ -2145,6 +2147,7 @@
 			[fDstCodecsPopUp addItemWithTitle:_( @"AVC/H.264 Video / AC-3 Audio" )];
 			[fDstCodecsPopUp addItemWithTitle:_( @"AVC/H.264 Video / MP3 Audio" )];
 			[fDstCodecsPopUp addItemWithTitle:_( @"AVC/H.264 Video / Vorbis Audio" )];
+			[fDstCodecsPopUp addItemWithTitle:_( @"Theora Video / Vorbis Audio" )];
             /* We enable the create chapters checkbox here */
 			[fCreateChapterMarkers setEnabled: YES];
 			break;
@@ -2231,6 +2234,13 @@
         [fVidEncoderPopUp selectItemAtIndex: 0];
 				
     }
+	
+	else if( ( FormatSettings[format][codecs] & HB_VCODEC_THEORA ) )
+	{
+		[fVidEncoderPopUp removeAllItems];
+		[fVidEncoderPopUp addItemWithTitle: @"libtheora"];
+		[fVidEncoderPopUp selectItemAtIndex:0];
+	}
 
     if( FormatSettings[format][codecs] & HB_ACODEC_AC3 )
     {
@@ -2307,7 +2317,15 @@
 		[fVidTurboPassCheck setHidden: YES];
 		[fVidTurboPassCheck setState: NSOffState];
 	}
-	
+	if( ( FormatSettings[format][codecs] & HB_VCODEC_THEORA ) )
+	{
+		[fVidTwoPassCheck setHidden: YES];
+		[fVidTwoPassCheck setState: NSOffState];
+	}
+	else
+	{
+		[fVidTwoPassCheck setHidden: NO];
+	}
 	/* We call method method to change UI to reflect whether a preset is used or not*/
 	[self customSettingUsed: sender];
 }
Index: macosx/HandBrake.xcodeproj/project.pbxproj
===================================================================
--- macosx/HandBrake.xcodeproj/project.pbxproj	(revision 1147)
+++ macosx/HandBrake.xcodeproj/project.pbxproj	(working copy)
@@ -7,6 +7,10 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		08D8C3C80D243B7200355B8B /* enctheora.c in Sources */ = {isa = PBXBuildFile; fileRef = 08D8C3C70D243B7200355B8B /* enctheora.c */; };
+		08D8C3C90D243B7200355B8B /* enctheora.c in Sources */ = {isa = PBXBuildFile; fileRef = 08D8C3C70D243B7200355B8B /* enctheora.c */; };
+		08D8C3EA0D2440CE00355B8B /* libtheora.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 08D8C3E90D2440CE00355B8B /* libtheora.a */; };
+		08D8C47E0D246A8C00355B8B /* libtheora.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 08D8C3E90D2440CE00355B8B /* libtheora.a */; };
 		0D096E010B707D3400A845D4 /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = 526FBC9B0B4CAB100064E04C /* common.c */; };
 		0D096E020B707D3400A845D4 /* deca52.c in Sources */ = {isa = PBXBuildFile; fileRef = 526FBC9D0B4CAB100064E04C /* deca52.c */; };
 		0D096E030B707D3400A845D4 /* decavcodec.c in Sources */ = {isa = PBXBuildFile; fileRef = 526FBC9E0B4CAB100064E04C /* decavcodec.c */; };
@@ -203,6 +207,8 @@
 
 /* Begin PBXFileReference section */
 		089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		08D8C3C70D243B7200355B8B /* enctheora.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = enctheora.c; path = ../libhb/enctheora.c; sourceTree = SOURCE_ROOT; };
+		08D8C3E90D2440CE00355B8B /* libtheora.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtheora.a; path = ../contrib/lib/libtheora.a; sourceTree = SOURCE_ROOT; };
 		0D096DFF0B707D1200A845D4 /* libhb.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libhb.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
 		0D6E35760B6BD4F0005AABB3 /* HandBrake.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HandBrake.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		0DF377970B7BF99A00115CB0 /* fakexcode.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = fakexcode.cpp; path = ../test/fakexcode.cpp; sourceTree = SOURCE_ROOT; };
@@ -330,6 +336,7 @@
 			buildActionMask = 2147483647;
 			files = (
 				0D096EA30B70884A00A845D4 /* libz.dylib in Frameworks */,
+				08D8C47E0D246A8C00355B8B /* libtheora.a in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -337,6 +344,7 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				08D8C3EA0D2440CE00355B8B /* libtheora.a in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -387,6 +395,7 @@
 		29B97314FDCFA39411CA2CEA /* HandBrake */ = {
 			isa = PBXGroup;
 			children = (
+				08D8C3E90D2440CE00355B8B /* libtheora.a */,
 				526FBC940B4CAA310064E04C /* Instant HandBrake Sources */,
 				526FBC930B4CAA260064E04C /* HandBrake Sources */,
 				526FBC920B4CAA120064E04C /* HandBrakeCLI Sources */,
@@ -442,6 +451,7 @@
 		526FBC8D0B4CA9F90064E04C /* libhb Sources */ = {
 			isa = PBXGroup;
 			children = (
+				08D8C3C70D243B7200355B8B /* enctheora.c */,
 				B48359A70C82960500E04440 /* lang.c */,
 				EAA526920C3B25D200944FF2 /* stream.c */,
 				0DFA5C7E0B8DD3B60020BC09 /* declpcm.c */,
@@ -816,6 +826,7 @@
 				FC8519550C59A02C0073812C /* deinterlace.c in Sources */,
 				FC8519560C59A02C0073812C /* deblock.c in Sources */,
 				FC8519570C59A02C0073812C /* detelecine.c in Sources */,
+				08D8C3C90D243B7200355B8B /* enctheora.c in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -860,6 +871,7 @@
 				FC8519520C59A02C0073812C /* deblock.c in Sources */,
 				FC8519530C59A02C0073812C /* detelecine.c in Sources */,
 				B48359A80C82960500E04440 /* lang.c in Sources */,
+				08D8C3C80D243B7200355B8B /* enctheora.c in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -1010,7 +1022,11 @@
 				GCC_PREFIX_HEADER = "";
 				HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/../contrib/include";
 				INSTALL_PATH = /usr/local/lib;
-				LIBRARY_SEARCH_PATHS = "";
+				LIBRARY_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(LIBRARY_SEARCH_PATHS_QUOTED_1)",
+				);
+				LIBRARY_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)/../contrib/lib\"";
 				MACOSX_DEPLOYMENT_TARGET = 10.4;
 				OTHER_CFLAGS = (
 					"-D__LIBHB__",
@@ -1069,7 +1085,11 @@
 				GCC_PREFIX_HEADER = "";
 				HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/../contrib/include";
 				INSTALL_PATH = /usr/local/lib;
-				LIBRARY_SEARCH_PATHS = "";
+				LIBRARY_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(LIBRARY_SEARCH_PATHS_QUOTED_1)",
+				);
+				LIBRARY_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)/../contrib/lib\"";
 				MACOSX_DEPLOYMENT_TARGET = 10.4;
 				OTHER_CFLAGS = (
 					"-D__LIBHB__",
@@ -1126,7 +1146,11 @@
 				GCC_PREFIX_HEADER = "";
 				HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/../contrib/include";
 				INSTALL_PATH = /usr/local/lib;
-				LIBRARY_SEARCH_PATHS = "";
+				LIBRARY_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(LIBRARY_SEARCH_PATHS_QUOTED_1)",
+				);
+				LIBRARY_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)/../contrib/lib\"";
 				MACOSX_DEPLOYMENT_TARGET = 10.4;
 				OTHER_CFLAGS = (
 					"-D__LIBHB__",
@@ -1183,7 +1207,11 @@
 				GCC_PREFIX_HEADER = "";
 				HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/../contrib/include";
 				INSTALL_PATH = /usr/local/lib;
-				LIBRARY_SEARCH_PATHS = "";
+				LIBRARY_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(LIBRARY_SEARCH_PATHS_QUOTED_1)",
+				);
+				LIBRARY_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)/../contrib/lib\"";
 				MACOSX_DEPLOYMENT_TARGET = 10.4;
 				OTHER_CFLAGS = (
 					"-D__LIBHB__",
@@ -1237,6 +1265,11 @@
 				GCC_PREFIX_HEADER = "";
 				HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/../contrib/include";
 				INSTALL_PATH = /usr/local/lib;
+				LIBRARY_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(LIBRARY_SEARCH_PATHS_QUOTED_1)",
+				);
+				LIBRARY_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)/../contrib/lib\"";
 				MACOSX_DEPLOYMENT_TARGET = 10.3;
 				OTHER_CFLAGS = (
 					"-D__LIBHB__",
@@ -1422,6 +1455,11 @@
 				GCC_PREFIX_HEADER = "";
 				HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/../contrib/include";
 				INSTALL_PATH = /usr/local/lib;
+				LIBRARY_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(LIBRARY_SEARCH_PATHS_QUOTED_1)",
+				);
+				LIBRARY_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)/../contrib/lib\"";
 				MACOSX_DEPLOYMENT_TARGET = 10.3;
 				OTHER_CFLAGS = (
 					"-D__LIBHB__",
@@ -1452,6 +1490,11 @@
 				GCC_PREFIX_HEADER = "";
 				HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/../contrib/include";
 				INSTALL_PATH = /usr/local/lib;
+				LIBRARY_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(LIBRARY_SEARCH_PATHS_QUOTED_1)",
+				);
+				LIBRARY_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)/../contrib/lib\"";
 				MACOSX_DEPLOYMENT_TARGET = 10.3;
 				OTHER_CFLAGS = (
 					"-D__LIBHB__",
@@ -1481,6 +1524,11 @@
 				GCC_PREFIX_HEADER = "";
 				HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/../contrib/include";
 				INSTALL_PATH = /usr/local/lib;
+				LIBRARY_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(LIBRARY_SEARCH_PATHS_QUOTED_1)",
+				);
+				LIBRARY_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)/../contrib/lib\"";
 				MACOSX_DEPLOYMENT_TARGET = 10.3;
 				OTHER_CFLAGS = (
 					"-D__LIBHB__",
Index: contrib/Jamfile
===================================================================
--- contrib/Jamfile	(revision 1147)
+++ contrib/Jamfile	(working copy)
@@ -291,6 +291,23 @@
 Wget          $(SUBDIR)/libsamplerate.tar.gz : $(SUBDIR)/version_libsamplerate.txt ;
 LibSampleRate $(SUBDIR)/lib/libsamplerate.a  : $(SUBDIR)/libsamplerate.tar.gz ;
 
+# libtheora
+rule LibTheora
+{
+    Depends $(<) : $(>) ;
+    Depends lib  : $(<) ;
+}
+actions LibTheora
+{
+    cd `dirname $(>)` && CONTRIB=`pwd` &&
+    rm -f libtheora && tar xvzf libtheora.tar.gz && cd libtheora-1.0beta2 &&
+    ./configure --prefix=$CONTRIB --with-ogg=$CONTRIB --cache-file=$CONTRIB/config.cache --disable-shared &&
+    make && make install &&
+    strip -S $CONTRIB/lib/libtheora.a
+}
+Wget      $(SUBDIR)/libtheora.tar.gz : $(SUBDIR)/version_libtheora.txt ;
+LibTheora $(SUBDIR)/lib/libtheora.a  : $(SUBDIR)/libtheora.tar.gz ;
+ 
 # libvorbis
 rule LibVorbis
 {
Index: contrib/version_libtheora.txt
===================================================================
--- contrib/version_libtheora.txt	(revision 0)
+++ contrib/version_libtheora.txt	(revision 0)
@@ -0,0 +1 @@
+http://downloads.xiph.org/releases/theora/libtheora-1.0beta2.tar.gz
Index: Jamfile
===================================================================
--- Jamfile	(revision 1147)
+++ Jamfile	(working copy)
@@ -14,7 +14,8 @@
           contrib/lib/libmp4v2.a      contrib/lib/libfaac.a
           contrib/lib/libmp3lame.a    contrib/lib/libmpeg2.a
           contrib/lib/libvorbis.a     contrib/lib/libvorbisenc.a
-          contrib/lib/libogg.a        contrib/lib/libsamplerate.a
+          contrib/lib/libtheora.a     contrib/lib/libogg.a
+          contrib/lib/libsamplerate.a
           contrib/lib/libx264.a       contrib/lib/libxvidcore.a
           contrib/lib/libmkv.a        contrib/lib/libswscale.a ;
 

