summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-10-31 23:11:34 +0000
committerarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-10-31 23:11:34 +0000
commitfcb0620032f646ca6b1958ed059ae46784cd4e9f (patch)
treee8ebb2fcdefc0560255a08e3804035e6e085a752
parentd39a6439a353a4724a6bbc487d09e26c0c74b8d5 (diff)
downloadmpv-fcb0620032f646ca6b1958ed059ae46784cd4e9f.tar.bz2
mpv-fcb0620032f646ca6b1958ed059ae46784cd4e9f.tar.xz
qtaudio - audio decoder using win32 quicktime 5 dlls
based on code by Sascha Sommer <saschasommer@freenet.de> git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@8009 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r--libmpcodecs/Makefile2
-rw-r--r--libmpcodecs/ad.c2
-rw-r--r--libmpcodecs/ad_qtaudio.c291
3 files changed, 294 insertions, 1 deletions
diff --git a/libmpcodecs/Makefile b/libmpcodecs/Makefile
index 27e044934d..96a9761048 100644
--- a/libmpcodecs/Makefile
+++ b/libmpcodecs/Makefile
@@ -4,7 +4,7 @@ include ../config.mak
LIBNAME = libmpcodecs.a
LIBNAME2 = libmpencoders.a
-AUDIO_SRCS=dec_audio.c ad.c ad_liba52.c ad_acm.c ad_alaw.c ad_dk3adpcm.c ad_dshow.c ad_dvdpcm.c ad_ffmpeg.c ad_hwac3.c ad_imaadpcm.c ad_mp3lib.c ad_msadpcm.c ad_pcm.c ad_roqaudio.c ad_msgsm.c ad_faad.c ad_libvorbis.c ad_libmad.c ad_realaud.c ad_libdv.c
+AUDIO_SRCS=dec_audio.c ad.c ad_liba52.c ad_acm.c ad_alaw.c ad_dk3adpcm.c ad_dshow.c ad_dvdpcm.c ad_ffmpeg.c ad_hwac3.c ad_imaadpcm.c ad_mp3lib.c ad_msadpcm.c ad_pcm.c ad_roqaudio.c ad_msgsm.c ad_faad.c ad_libvorbis.c ad_libmad.c ad_realaud.c ad_libdv.c ad_qtaudio.c
VIDEO_SRCS=dec_video.c vd.c vd_null.c vd_realvid.c vd_cinepak.c vd_qtrpza.c vd_ffmpeg.c vd_dshow.c vd_vfw.c vd_vfwex.c vd_odivx.c vd_divx4.c vd_raw.c vd_xanim.c vd_msvidc.c vd_fli.c vd_qtrle.c vd_qtsmc.c vd_roqvideo.c vd_cyuv.c vd_nuv.c vd_libmpeg2.c vd_msrle.c vd_huffyuv.c vd_mpegpes.c vd_svq1.c vd_xvid.c vd_libdv.c vd_lcl.c vd_mtga.c vd_lzo.c
VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c vf_eq2.c vf_halfpack.c vf_dint.c vf_1bpp.c vf_bmovl.c vf_2xsai.c vf_unsharp.c vf_swapuv.c vf_il.c
ENCODER_SRCS=ve.c ve_divx4.c ve_lavc.c ve_vfw.c ve_rawrgb.c ve_libdv.c ve_xvid.c
diff --git a/libmpcodecs/ad.c b/libmpcodecs/ad.c
index 1e7db6b667..52cbaf4a45 100644
--- a/libmpcodecs/ad.c
+++ b/libmpcodecs/ad.c
@@ -36,6 +36,7 @@ extern ad_functions_t mpcodecs_ad_libvorbis;
extern ad_functions_t mpcodecs_ad_libmad;
extern ad_functions_t mpcodecs_ad_realaud;
extern ad_functions_t mpcodecs_ad_libdv;
+extern ad_functions_t mpcodecs_ad_qtaudio;
ad_functions_t* mpcodecs_ad_drivers[] =
{
@@ -59,6 +60,7 @@ ad_functions_t* mpcodecs_ad_drivers[] =
&mpcodecs_ad_dshow,
#endif
&mpcodecs_ad_acm,
+ &mpcodecs_ad_qtaudio,
#endif
#ifdef HAVE_FAAD
&mpcodecs_ad_faad,
diff --git a/libmpcodecs/ad_qtaudio.c b/libmpcodecs/ad_qtaudio.c
new file mode 100644
index 0000000000..bf4b39d0fe
--- /dev/null
+++ b/libmpcodecs/ad_qtaudio.c
@@ -0,0 +1,291 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+#include "config.h"
+
+#ifdef USE_WIN32DLL
+
+#include "ad_internal.h"
+#include "bswap.h"
+
+static ad_info_t info = {
+ "QuickTime Audio Decoder",
+ "qtaudio",
+ "A'rpi",
+ "Sascha Sommer",
+ "uses win32 quicktime DLLs"
+};
+
+LIBAD_EXTERN(qtaudio)
+
+typedef struct OpaqueSoundConverter* SoundConverter;
+typedef unsigned long OSType;
+typedef unsigned long UnsignedFixed;
+typedef uint8_t Byte;
+typedef struct SoundComponentData {
+ long flags;
+ OSType format;
+ short numChannels;
+ short sampleSize;
+ UnsignedFixed sampleRate;
+ long sampleCount;
+ Byte * buffer;
+ long reserved;
+}SoundComponentData;
+
+typedef int (__cdecl* LPFUNC1)(long flag);
+typedef int (__cdecl* LPFUNC2)(const SoundComponentData *, const SoundComponentData *,SoundConverter *);
+typedef int (__cdecl* LPFUNC3)(SoundConverter sc);
+typedef int (__cdecl* LPFUNC4)(void);
+typedef int (__cdecl* LPFUNC5)(SoundConverter sc, OSType selector,void * infoPtr);
+typedef int (__cdecl* LPFUNC6)(SoundConverter sc,
+ unsigned long inputBytesTarget,
+ unsigned long *inputFrames,
+ unsigned long *inputBytes,
+ unsigned long *outputBytes );
+typedef int (__cdecl* LPFUNC7)(SoundConverter sc,
+ const void *inputPtr,
+ unsigned long inputFrames,
+ void *outputPtr,
+ unsigned long *outputFrames,
+ unsigned long *outputBytes );
+typedef int (__cdecl* LPFUNC8)(SoundConverter sc,
+ void *outputPtr,
+ unsigned long *outputFrames,
+ unsigned long *outputBytes);
+typedef int (__cdecl* LPFUNC9)(SoundConverter sc) ;
+
+static HINSTANCE qtml_dll;
+static LPFUNC1 InitializeQTML;
+static LPFUNC2 SoundConverterOpen;
+static LPFUNC3 SoundConverterClose;
+static LPFUNC4 TerminateQTML;
+static LPFUNC5 SoundConverterSetInfo;
+static LPFUNC6 SoundConverterGetBufferSizes;
+static LPFUNC7 SoundConverterConvertBuffer;
+static LPFUNC8 SoundConverterEndConversion;
+static LPFUNC9 SoundConverterBeginConversion;
+
+#define siDecompressionParams 2002876005 // siDecompressionParams = FOUR_CHAR_CODE('wave')
+
+HMODULE WINAPI LoadLibraryA(LPCSTR);
+FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR);
+int WINAPI FreeLibrary(HMODULE);
+
+static int loader_init()
+{
+
+ qtml_dll = LoadLibraryA("qtmlClient.dll");
+ if( qtml_dll == NULL )
+ {
+ printf("failed loading dll\n" );
+ return 1;
+ }
+#if 1
+ InitializeQTML = (LPFUNC1)GetProcAddress(qtml_dll,"InitializeQTML");
+ if ( InitializeQTML == NULL )
+ {
+ printf("failed geting proc address InitializeQTML\n");
+ return 1;
+ }
+ SoundConverterOpen = (LPFUNC2)GetProcAddress(qtml_dll,"SoundConverterOpen");
+ if ( SoundConverterOpen == NULL )
+ {
+ printf("failed getting proc address SoundConverterOpen\n");
+ return 1;
+ }
+ SoundConverterClose = (LPFUNC3)GetProcAddress(qtml_dll,"SoundConverterClose");
+ if ( SoundConverterClose == NULL )
+ {
+ printf("failed getting proc address SoundConverterClose\n");
+ return 1;
+ }
+ TerminateQTML = (LPFUNC4)GetProcAddress(qtml_dll,"TerminateQTML");
+ if ( TerminateQTML == NULL )
+ {
+ printf("failed getting proc address TerminateQTML\n");
+ return 1;
+ }
+ SoundConverterSetInfo = (LPFUNC5)GetProcAddress(qtml_dll,"SoundConverterSetInfo");
+ if ( SoundConverterSetInfo == NULL )
+ {
+ printf("failed getting proc address SoundConverterSetInfo\n");
+ return 1;
+ }
+ SoundConverterGetBufferSizes = (LPFUNC6)GetProcAddress(qtml_dll,"SoundConverterGetBufferSizes");
+ if ( SoundConverterGetBufferSizes == NULL )
+ {
+ printf("failed getting proc address SoundConverterGetBufferSizes\n");
+ return 1;
+ }
+ SoundConverterConvertBuffer = (LPFUNC7)GetProcAddress(qtml_dll,"SoundConverterConvertBuffer");
+ if ( SoundConverterConvertBuffer == NULL )
+ {
+ printf("failed getting proc address SoundConverterConvertBuffer1\n");
+ return 1;
+ }
+ SoundConverterEndConversion = (LPFUNC8)GetProcAddress(qtml_dll,"SoundConverterEndConversion");
+ if ( SoundConverterEndConversion == NULL )
+ {
+ printf("failed getting proc address SoundConverterEndConversion\n");
+ return 1;
+ }
+ SoundConverterBeginConversion = (LPFUNC9)GetProcAddress(qtml_dll,"SoundConverterBeginConversion");
+ if ( SoundConverterBeginConversion == NULL )
+ {
+ printf("failed getting proc address SoundConverterBeginConversion\n");
+ return 1;
+ }
+ printf("Standard init done you may now call supported functions\n");
+#endif
+ printf("loader_init DONE???\n");
+ return 0;
+}
+
+static SoundConverter myConverter = NULL;
+static SoundComponentData InputFormatInfo,OutputFormatInfo;
+
+static int InFrameSize;
+static int OutFrameSize;
+
+static int preinit(sh_audio_t *sh){
+ int error;
+ unsigned long FramesToGet=0; //how many frames the demuxer has to get
+ unsigned long InputBufferSize=0; //size of the input buffer
+ unsigned long OutputBufferSize=0; //size of the output buffer
+ unsigned long WantedBufferSize=0; //the size you want your buffers to be
+
+ printf("win32 libquicktime loader (c) Sascha Sommer\n");
+
+ if(loader_init()) return 0; // failed to load DLL
+
+ printf("loader_init DONE!\n");
+
+#if 1
+ error = InitializeQTML(0L);
+ printf("InitializeQTML:%i\n",error);
+ if(error) return 0;
+
+ OutputFormatInfo.flags = InputFormatInfo.flags = 0;
+ OutputFormatInfo.sampleCount = InputFormatInfo.sampleCount = 0;
+ OutputFormatInfo.buffer = InputFormatInfo.buffer = NULL;
+ OutputFormatInfo.reserved = InputFormatInfo.reserved = 0;
+ OutputFormatInfo.numChannels = InputFormatInfo.numChannels = sh->wf->nChannels;
+ OutputFormatInfo.sampleSize = InputFormatInfo.sampleSize = sh->wf->wBitsPerSample;
+ OutputFormatInfo.sampleRate = InputFormatInfo.sampleRate = sh->wf->nSamplesPerSec;
+ InputFormatInfo.format = bswap_32(sh->format); //1363430706;///*1768775988;//*/1902406962;//qdm2//1768775988;//FOUR_CHAR_CODE('ima4');
+ OutputFormatInfo.format = 1313820229;// FOUR_CHAR_CODE('NONE');
+
+ error = SoundConverterOpen(&InputFormatInfo, &OutputFormatInfo, &myConverter);
+ printf("SoundConverterOpen:%i\n",error);
+ if(error) return 0;
+
+ if(sh->codecdata){
+ error = SoundConverterSetInfo(myConverter,siDecompressionParams,sh->codecdata);
+ printf("SoundConverterSetInfo:%i\n",error);
+ if(error) return 0;
+ }
+
+ WantedBufferSize=OutputFormatInfo.numChannels*OutputFormatInfo.sampleRate*2;
+ error = SoundConverterGetBufferSizes(myConverter,
+ WantedBufferSize,&FramesToGet,&InputBufferSize,&OutputBufferSize);
+ printf("SoundConverterGetBufferSizes:%i\n");
+ printf("WantedBufferSize = %i\n",WantedBufferSize);
+ printf("InputBufferSize = %i\n",InputBufferSize);
+ printf("OutputBufferSize = %i\n",OutputBufferSize);
+ printf("FramesToGet = %i\n",FramesToGet);
+
+ InFrameSize=InputBufferSize/FramesToGet;
+ OutFrameSize=OutputBufferSize/FramesToGet;
+
+ printf("FrameSize: %i -> %i\n",InFrameSize,OutFrameSize);
+
+ error = SoundConverterBeginConversion(myConverter);
+ printf("SoundConverterBeginConversion:%i\n",error);
+ if(error) return 0;
+
+ sh->audio_out_minsize=OutputBufferSize;
+ sh->audio_in_minsize=InputBufferSize;
+
+ sh->channels=sh->wf->nChannels;
+ sh->samplerate=sh->wf->nSamplesPerSec;
+ sh->samplesize=(sh->wf->wBitsPerSample+7)/8;
+
+ sh->i_bps=sh->wf->nAvgBytesPerSec;
+//InputBufferSize*WantedBufferSize/OutputBufferSize;
+
+#endif
+ return 1; // return values: 1=OK 0=ERROR
+}
+
+static int init(sh_audio_t *sh_audio){
+
+ return 1; // return values: 1=OK 0=ERROR
+}
+
+static void uninit(sh_audio_t *sh){
+ int error;
+ unsigned long ConvertedFrames=0;
+ unsigned long ConvertedBytes=0;
+ error=SoundConverterEndConversion(myConverter,NULL,&ConvertedFrames,&ConvertedBytes);
+ printf("SoundConverterEndConversion:%i\n",error);
+ error = SoundConverterClose(myConverter);
+ printf("SoundConverterClose:%i\n",error);
+ error = TerminateQTML();
+ printf("TerminateQTML:%i\n",error);
+ FreeLibrary( qtml_dll );
+ qtml_dll = NULL;
+ printf("qt dll loader uninit done\n");
+}
+
+static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen){
+ int error;
+ unsigned long FramesToGet=0; //how many frames the demuxer has to get
+ unsigned long InputBufferSize=0; //size of the input buffer
+ unsigned long ConvertedFrames=0;
+ unsigned long ConvertedBytes=0;
+
+ FramesToGet=minlen/OutFrameSize;
+ if(FramesToGet*OutFrameSize<minlen &&
+ (FramesToGet+1)*OutFrameSize<=maxlen) ++FramesToGet;
+ if(FramesToGet*InFrameSize>sh->a_in_buffer_size)
+ FramesToGet=sh->a_in_buffer_size/InFrameSize;
+
+ InputBufferSize=FramesToGet*InFrameSize;
+
+ printf("FramesToGet = %i (%i -> %i bytes)\n",FramesToGet,
+ InputBufferSize, FramesToGet*OutFrameSize);
+
+ if(InputBufferSize>sh->a_in_buffer_len){
+ int x=demux_read_data(sh->ds,&sh->a_in_buffer[sh->a_in_buffer_len],
+ InputBufferSize-sh->a_in_buffer_len);
+ if(x>0) sh->a_in_buffer_len+=x;
+ if(InputBufferSize>sh->a_in_buffer_len)
+ FramesToGet=sh->a_in_buffer_len/InFrameSize; // not enough data!
+ }
+
+ error = SoundConverterConvertBuffer(myConverter,sh->a_in_buffer,
+ FramesToGet,buf,&ConvertedFrames,&ConvertedBytes);
+ printf("SoundConverterConvertBuffer:%i\n",error);
+ printf("ConvertedFrames = %i\n",ConvertedFrames);
+ printf("ConvertedBytes = %i\n",ConvertedBytes);
+
+ InputBufferSize=(ConvertedBytes/OutFrameSize)*InFrameSize; // FIXME!!
+ sh->a_in_buffer_len-=InputBufferSize;
+ if(sh->a_in_buffer_len<0) sh->a_in_buffer_len=0; // should not happen...
+ else if(sh->a_in_buffer_len>0){
+ memcpy(sh->a_in_buffer,&sh->a_in_buffer[InputBufferSize],sh->a_in_buffer_len);
+ }
+
+ return ConvertedBytes;
+}
+
+static int control(sh_audio_t *sh,int cmd,void* arg, ...){
+ // various optional functions you MAY implement:
+ return CONTROL_UNKNOWN;
+}
+
+#endif