Forráskód Böngészése

Updated WIP theoraplayer...

Mark Sibly 8 éve
szülő
commit
8a22a7a120

+ 22 - 2
bananas/theoratest/theoratest.monkey2

@@ -16,11 +16,15 @@ Class MyWindow Extends Window
 	
 	Field vidman:VideoManager
 	
+	Field data:DataBuffer
+	
 	Field vidclip:VideoClip
 	
 	Field image:Image
 	
 	Field time:Double
+	
+	Field gain:float=1
 
 	Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
 
@@ -32,7 +36,11 @@ Class MyWindow Extends Window
 		
 		vidman.setAudioInterfaceFactory( audiofactory )
 		
-		vidclip=vidman.createVideoClip( AssetsDir()+"konqi.ogv" )
+		data=DataBuffer.Load( "asset::konqi.ogv" )
+		
+		vidclip=vidman.createVideoClip( data.Data,data.Length )
+'		vidclip=vidman.createVideoClip( AssetsDir()+"konqi.ogv" )
+		If Not vidclip Print "Can't load vidclip!"
 		
 		image=New Image( vidclip.getWidth(),vidclip.getHeight(),PixelFormat.RGB24,TextureFlags.Dynamic )
 		
@@ -54,7 +62,7 @@ Class MyWindow Extends Window
 		
 		vidman.update( elapsed )
 	
-'		vidclip.updateTimerToNextFrame()
+'		vidclip.updateTimerToNextFrame()	'play full speed...
 		
 		Local frame:=vidclip.fetchNextFrame()
 		
@@ -68,9 +76,21 @@ Class MyWindow Extends Window
 		
 		Endif
 		
+		If Keyboard.KeyPressed( Key.Up )
+			gain=Min( gain+.125,1.0 )
+			vidclip.setAudioGain( gain )
+		Else If Keyboard.KeyPressed( Key.Down )
+			gain=Max( gain-.125,0.0 )
+			vidclip.setAudioGain( gain )
+		Endif
+		
 		canvas.BlendMode=BlendMode.Opaque
 		
 		canvas.DrawRect( 0,0,Width,Height,image )
+		
+		canvas.DrawText( "Time position="+vidclip.getTimePosition()+", duration="+vidclip.getDuration(),0,0 )
+		
+		canvas.DrawText( "Audio gain="+vidclip.getAudioGain(),0,16 )
 	End
 	
 End

+ 4 - 0
modules/theoraplayer/native/OpenAL_AudioInterface.cpp

@@ -190,6 +190,8 @@ void OpenAL_AudioInterface::seek(float time)
 
 OpenAL_AudioInterfaceFactory::OpenAL_AudioInterfaceFactory()
 {
+	return;
+	
 	// openal init is here used only to simplify samples for this plugin
 	// if you want to use this interface in your own program, you'll
 	// probably want to remove the openal init/destory lines
@@ -217,6 +219,8 @@ OpenAL_AudioInterfaceFactory::OpenAL_AudioInterfaceFactory()
 
 OpenAL_AudioInterfaceFactory::~OpenAL_AudioInterfaceFactory()
 {
+	return;
+	
 	if (gDevice != NULL)
 	{
 		alcMakeContextCurrent(NULL);

+ 18 - 3
modules/theoraplayer/native/monkey2_glue.cpp

@@ -3,16 +3,31 @@
 
 #include "theoraplayer.h"
 #include "Manager.h"
+#include "memorydatasource.h"
+
+theoraplayer::Manager *bb_theoraplayer_getManager(){
+
+	if( !theoraplayer::manager ) theoraplayer::init();
+	
+	return theoraplayer::manager;
+}
 
 theoraplayer::VideoClip *bb_theoraplayer_createVideoClip( theoraplayer::Manager *self,const char *filename ){
+
 	return self->createVideoClip( filename );
 }
 
-theoraplayer::Manager *bb_theoraplayer_getManager(){
+//FIXME - leaks MemoryDataSource!
+//
+theoraplayer::VideoClip *bb_theoraplayer_createVideoClip( theoraplayer::Manager *self,const void *data,int length ){
 
-	if( !theoraplayer::manager ) theoraplayer::init();
+	theoraplayer::MemoryDataSource *src=new theoraplayer::MemoryDataSource( (unsigned char*)data,length,"Theora" );
 	
-	return theoraplayer::manager;
+	return self->createVideoClip( src );
 }
 
+theoraplayer::MemoryDataSource *bb_theoraplayer_createMemoryDataSource( const void *data,int length,const char *formatName ){
+
+	return new theoraplayer::MemoryDataSource( (unsigned char*)data,length,formatName );
+}
 

+ 6 - 1
modules/theoraplayer/native/monkey2_glue.h

@@ -7,10 +7,15 @@
 namespace theoraplayer{
 	class Manager;
 	class VideoClip;
+	class MemoryDataSource;
 }
 
+theoraplayer::Manager *bb_theoraplayer_getManager();
+
 theoraplayer::VideoClip *bb_theoraplayer_createVideoClip( theoraplayer::Manager *self,const char *filename );
 
-theoraplayer::Manager *bb_theoraplayer_getManager();
+theoraplayer::VideoClip *bb_theoraplayer_createVideoClip( theoraplayer::Manager *self,const void *data,int length );
+
+theoraplayer::MemoryDataSource *bb_theoraplayer_createMemoryDataSource( const void *data,int length,const char *formatName );
 
 #endif

+ 18 - 0
modules/theoraplayer/native/theoraplayer/src/FileDataSource.cpp

@@ -80,6 +80,15 @@ namespace theoraplayer
 
 	void FileDataSource::seek(int64_t byte_index)
 	{
+
+		if (this->filePtr == NULL) 
+		{
+			this->_openFile();
+		}
+		
+		fseek( this->filePtr,byte_index,SEEK_SET );
+		
+		/*
 		if (this->filePtr == NULL) 
 		{
 			this->_openFile();
@@ -93,6 +102,7 @@ namespace theoraplayer
 		fpos_t fpos = byte_index;
 #endif
 		fsetpos(this->filePtr, &fpos);
+		*/
 	}
 
 	int64_t FileDataSource::getSize()
@@ -110,6 +120,13 @@ namespace theoraplayer
 		{
 			return 0LL;
 		}
+		return ftell( this->filePtr );
+		
+		/*
+		if (this->filePtr == NULL)
+		{
+			return 0LL;
+		}
 #ifdef __linux
 //_LINUX
 		fpos_t pos;
@@ -120,5 +137,6 @@ namespace theoraplayer
 		fgetpos(this->filePtr, &pos);
 		return (int64_t)pos;
 #endif
+		*/
 	}
 }

+ 1 - 1
modules/theoraplayer/native/theoraplayer/src/Thread.cpp

@@ -313,7 +313,7 @@ namespace theoraplayer
 #else
 		((AsyncActionWrapper*)this->id)->asyncAction->Cancel();
 #endif
-#elif defined(_ANDROID)
+#elif defined(__ANDROID__)
 		pthread_kill(*((pthread_t*)this->id), 0);
 #else
 		pthread_cancel(*((pthread_t*)this->id));

+ 57 - 14
modules/theoraplayer/theoraplayer.monkey2

@@ -34,11 +34,17 @@ Namespace theoraplayer
 
 Extern
 
+Enum OutputMode="theoraplayer::OutputMode"
+End
+
 Class VideoManager Extends Void="theoraplayer::Manager" 
 
 	Method setAudioInterfaceFactory( audioFactory:AudioInterfaceFactory )
+	Method getAudioInterfaceFactory:AudioInterfaceFactory()
 
 	Method createVideoClip:VideoClip( filename:CString ) Extension="bb_theoraplayer_createVideoClip"
+	Method createVideoClip:VideoClip( data:Void Ptr,length:Int ) Extension="bb_theoraplayer_createVideoClip"
+	Method destroyVideoClip( clip:VideoClip )
  
  	Method update( time_increase:Float )
  	
@@ -49,34 +55,71 @@ End
 Class VideoClip Extends Void="theoraplayer::VideoClip"
 
 	Method getWidth:Int()
-	
 	Method getHeight:Int()
 	
+	Method hasAlphaChannel:Bool()
+	
+	Method getSubFrameX:Int()
+	Method getSubFrameY:Int()
+	Method getSubFrameWidth:Int()
+	Method getSubFrameHeight:Int()
+	
 	Method getStride:Int()
 	
-	Method updateTimerToNextFrame:Float()
-
-	Method fetchNextFrame:VideoFrame()
+	Method getTimePosition:Float()
 	
-	Method popFrame()
+	Method getDuration:Float()
 	
-	Method getReadyFramesCount:Int()
+	Method getFps:Float()
 	
-	Method play()
+	Method getFramesCount:Int()
+
+	Method getAudioGain:Float()
+	Method setAudioGain( gain:Float )
+
+	Method getPlaybackSpeed:Float()
+	Method setPlaybackSpeed( speed:Float )
+
+	Method getOutputMode:OutputMode()
+	Method setOutputMode( mode:OutputMode )
 	
+	Method isAutoRestart:Bool()
+	Method setAutoRestart( value:Bool )
+
+	Method getPriority:Float()
+	Method setPriority( priority:Float )
+
+	Method getPriorityIndex:Int()
+
+	Method getPrecachedFramesCount:Int()
+	Method setPrecachedFramesCount( count:Int )
+	Method getReadyFramesCount:Int()
+	Method getDisplayedFramesCount:Int()
+	Method getDroppedFramesCount:Int()
+
+	Method isDone:Bool()
+	Method isPaused:Bool()
+
+	Method updateTimerToNextFrame:Float()
+	Method fetchNextFrame:VideoFrame()
+	Method popFrame()
+
+	Method play()
+	Method pause()
+	Method stop()
+	Method restart()
+
+	Method seek( time:Float )
+	Method seekToFrame( frame:Int )
+	Method waitForCache:Float( desiredCacheFactor:Float=0.5,maxWaitTime:Float=1.0 )
+
 End
 
 Class VideoFrame Extends Void="theoraplayer::VideoFrame" 
 
-	Method getFrameNumber:Int()
-	
 	Method getBuffer:UByte Ptr()
-	
-	Method getWidth:Int()
-	
-	Method getHeight:Int()
+	Method getFrameNumber:Int()
 
-	Method getStride:Int()
 End
 
 Class AudioInterfaceFactory Extends Void="theoraplayer::AudioInterfaceFactory"