LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT message, LPARAM lParam1, LPARAM lParam2) { DRVR* module=(DRVR*)hDriver; int result; #ifndef __svr4__ char qw[300]; #endif #ifdef DETAILED_OUT printf("SendDriverMessage: driver %X, message %X, arg1 %X, arg2 %X\n", hDriver, message, lParam1, lParam2); #endif if (!module || !module->hDriverModule || !module->DriverProc) return -1; #ifndef __svr4__ __asm__ volatile ("fsave (%0)\n\t": :"r"(&qw)); #endif #ifdef WIN32_LOADER Setup_FS_Segment(); #endif STORE_ALL; result=module->DriverProc(module->dwDriverID, hDriver, message, lParam1, lParam2); REST_ALL; #ifndef __svr4__ __asm__ volatile ("frstor (%0)\n\t": :"r"(&qw)); #endif #ifdef DETAILED_OUT printf("\t\tResult: %X\n", result); #endif return result; }
//DrvOpen(LPCSTR lpszDriverName, LPCSTR lpszSectionName, LPARAM lParam2) HDRVR DrvOpen(LPARAM lParam2) { NPDRVR hDriver; char unknown[0x124]; const char* filename = (const char*) ((ICOPEN*) lParam2)->pV1Reserved; #ifdef WIN32_LOADER Setup_LDT_Keeper(); #endif printf("Loading codec DLL: '%s'\n",filename); hDriver = malloc(sizeof(DRVR)); if (!hDriver) return (HDRVR) 0; memset((void*)hDriver, 0, sizeof(DRVR)); #ifdef WIN32_LOADER CodecAlloc(); Setup_FS_Segment(); #endif hDriver->hDriverModule = LoadLibraryA(filename); if (!hDriver->hDriverModule) { printf("Can't open library %s\n", filename); DrvClose((HDRVR)hDriver); return (HDRVR) 0; } hDriver->DriverProc = (DRIVERPROC) GetProcAddress(hDriver->hDriverModule, "DriverProc"); if (!hDriver->DriverProc) { printf("Library %s is not a valid VfW/ACM codec\n", filename); DrvClose((HDRVR)hDriver); return (HDRVR) 0; } TRACE("DriverProc == %X\n", hDriver->DriverProc); SendDriverMessage((HDRVR)hDriver, DRV_LOAD, 0, 0); TRACE("DRV_LOAD Ok!\n"); SendDriverMessage((HDRVR)hDriver, DRV_ENABLE, 0, 0); TRACE("DRV_ENABLE Ok!\n"); hDriver->dwDriverID = ++dwDrvID; // generate new id // open driver and remmeber proper DriverID hDriver->dwDriverID = SendDriverMessage((HDRVR)hDriver, DRV_OPEN, (LPARAM) unknown, lParam2); TRACE("DRV_OPEN Ok!(%X)\n", hDriver->dwDriverID); printf("Loaded DLL driver %s at %x\n", filename, hDriver->hDriverModule); return (HDRVR)hDriver; }
// decode a frame static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ OSErr result = 1; CodecFlags ignore; if(len<=0) return NULL; // skipped frame #if defined(WIN32_LOADER) && !defined(CONFIG_QUICKTIME) Setup_FS_Segment(); #endif result = DecompressSequenceFrameS(imageSeq, data, len, 0, &ignore, NULL); if(result) { mp_msg(MSGT_DECVIDEO,MSGL_ERR,"DecompressSequenceFrameS result=0x%d\n",result); return NULL; } if((int)sh->context==0x73797639){ // Sorenson 16-bit YUV -> std YVU9 int i; PixMap dstPixMap = **GetGWorldPixMap(OutBufferGWorld); short *src0=(short *)((char*)dstPixMap.baseAddr+0x20); for(i=0;i<mpi->h;i++){ int x; unsigned char* dst=mpi->planes[0]+i*mpi->stride[0]; unsigned short* src=src0+i*((mpi->w+15)&(~15)); for(x=0;x<mpi->w;x++) dst[x]=src[x]; } src0+=((mpi->w+15)&(~15))*((mpi->h+15)&(~15)); for(i=0;i<mpi->h/4;i++){ int x; unsigned char* dst=mpi->planes[1]+i*mpi->stride[1]; unsigned short* src=src0+i*(((mpi->w+63)&(~63))/4); for(x=0;x<mpi->w/4;x++) dst[x]=src[x]; src+=((mpi->w+63)&(~63))/4; } src0+=(((mpi->w+63)&(~63))/4)*(((mpi->h+63)&(~63))/4); for(i=0;i<mpi->h/4;i++){ int x; unsigned char* dst=mpi->planes[2]+i*mpi->stride[2]; unsigned short* src=src0+i*(((mpi->w+63)&(~63))/4); for(x=0;x<mpi->w/4;x++) dst[x]=src[x]; src+=((mpi->w+63)&(~63))/4; } } return mpi; }
void DrvClose(HDRVR hDriver) { if (hDriver) { DRVR* d = (DRVR*)hDriver; if (d->hDriverModule) { #ifdef WIN32_LOADER Setup_FS_Segment(); #endif if (d->DriverProc) { SendDriverMessage(hDriver, DRV_CLOSE, 0, 0); d->dwDriverID = 0; SendDriverMessage(hDriver, DRV_FREE, 0, 0); } FreeLibrary(d->hDriverModule); } free(d); } #ifdef WIN32_LOADER CodecRelease(); #endif }
DS_AudioDecoder * DS_AudioDecoder_Open(char* dllname, GUID* guid, WAVEFORMATEX* wf) //DS_AudioDecoder * DS_AudioDecoder_Create(const CodecInfo * info, const WAVEFORMATEX* wf) { DS_AudioDecoder *this; int sz; WAVEFORMATEX* pWF; #ifdef WIN32_LOADER Setup_LDT_Keeper(); Setup_FS_Segment(); #endif this = malloc(sizeof(DS_AudioDecoder)); sz = 18 + wf->cbSize; this->m_sVhdr = malloc(sz); memcpy(this->m_sVhdr, wf, sz); this->m_sVhdr2 = malloc(18); memcpy(this->m_sVhdr2, this->m_sVhdr, 18); pWF = (WAVEFORMATEX*)this->m_sVhdr2; pWF->wFormatTag = 1; pWF->wBitsPerSample = 16; pWF->nBlockAlign = pWF->nChannels * (pWF->wBitsPerSample + 7) / 8; pWF->cbSize = 0; pWF->nAvgBytesPerSec = pWF->nBlockAlign * pWF->nSamplesPerSec; memcpy(&this->in_fmt,wf,sizeof(WAVEFORMATEX)); memset(&this->m_sOurType, 0, sizeof(this->m_sOurType)); this->m_sOurType.majortype=MEDIATYPE_Audio; this->m_sOurType.subtype=MEDIASUBTYPE_PCM; this->m_sOurType.subtype.f1=wf->wFormatTag; this->m_sOurType.formattype=FORMAT_WaveFormatEx; this->m_sOurType.lSampleSize=wf->nBlockAlign; this->m_sOurType.bFixedSizeSamples=1; this->m_sOurType.bTemporalCompression=0; this->m_sOurType.pUnk=0; this->m_sOurType.cbFormat=sz; this->m_sOurType.pbFormat=this->m_sVhdr; memset(&this->m_sDestType, 0, sizeof(this->m_sDestType)); this->m_sDestType.majortype=MEDIATYPE_Audio; this->m_sDestType.subtype=MEDIASUBTYPE_PCM; // this->m_sDestType.subtype.f1=pWF->wFormatTag; this->m_sDestType.formattype=FORMAT_WaveFormatEx; this->m_sDestType.bFixedSizeSamples=1; this->m_sDestType.bTemporalCompression=0; this->m_sDestType.lSampleSize=pWF->nBlockAlign; if (wf->wFormatTag == 0x130) // ACEL hack to prevent memory corruption // obviosly we are missing something here this->m_sDestType.lSampleSize *= 288; this->m_sDestType.pUnk=0; this->m_sDestType.cbFormat=18; //pWF->cbSize; this->m_sDestType.pbFormat=this->m_sVhdr2; //print_wave_header(this->m_sVhdr, MSGL_V); //print_wave_header(this->m_sVhdr2, MSGL_V); /*try*/ { memset(&sampleProcData, 0, sizeof(sampleProcData)); this->m_pDS_Filter = DS_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType,&sampleProcData); if( !this->m_pDS_Filter ) { free(this); return NULL; } //Commit should be done before binary codec start this->m_pDS_Filter->m_pAll->vt->Commit(this->m_pDS_Filter->m_pAll); this->m_pDS_Filter->Start(this->m_pDS_Filter); } /* catch (FatalError& e) { e.PrintAll(); delete[] m_sVhdr; delete[] m_sVhdr2; delete m_pDS_Filter; throw; } */ return this; }
DMO_AudioDecoder * DMO_AudioDecoder_Open(const char* dllname, GUID* guid, WAVEFORMATEX* wf,int out_channels) //DMO_AudioDecoder * DMO_AudioDecoder_Create(const CodecInfo * info, const WAVEFORMATEX* wf) { DMO_AudioDecoder *this; int sz; WAVEFORMATEX* pWF; #ifdef LDT_paranoia Setup_LDT_Keeper(); Setup_FS_Segment(); #endif this = malloc(sizeof(DMO_AudioDecoder)); this->m_iFlushed=1; sz = 18 + wf->cbSize; this->m_sVhdr = malloc(sz); memcpy(this->m_sVhdr, wf, sz); this->m_sVhdr2 = malloc(18); memcpy(this->m_sVhdr2, this->m_sVhdr, 18); pWF = (WAVEFORMATEX*)this->m_sVhdr2; pWF->wFormatTag = 1; pWF->wBitsPerSample = 16; pWF->nChannels = out_channels; pWF->nBlockAlign = 2*pWF->nChannels; //pWF->nChannels * (pWF->wBitsPerSample + 7) / 8; pWF->nAvgBytesPerSec = pWF->nBlockAlign * pWF->nSamplesPerSec; pWF->cbSize = 0; memset(&this->m_sOurType, 0, sizeof(this->m_sOurType)); this->m_sOurType.majortype=MEDIATYPE_Audio; this->m_sOurType.subtype=MEDIASUBTYPE_PCM; this->m_sOurType.subtype.f1=wf->wFormatTag; this->m_sOurType.formattype=FORMAT_WaveFormatEx; this->m_sOurType.lSampleSize=wf->nBlockAlign; this->m_sOurType.bFixedSizeSamples=1; this->m_sOurType.bTemporalCompression=0; this->m_sOurType.cbFormat=sz; this->m_sOurType.pbFormat=this->m_sVhdr; memset(&this->m_sDestType, 0, sizeof(this->m_sDestType)); this->m_sDestType.majortype=MEDIATYPE_Audio; this->m_sDestType.subtype=MEDIASUBTYPE_PCM; this->m_sDestType.formattype=FORMAT_WaveFormatEx; this->m_sDestType.bFixedSizeSamples=1; this->m_sDestType.bTemporalCompression=0; this->m_sDestType.lSampleSize=pWF->nBlockAlign; this->m_sDestType.cbFormat=18; //pWF->cbSize; this->m_sDestType.pbFormat=this->m_sVhdr2; #if 0 print_wave_header((WAVEFORMATEX *)this->m_sVhdr); print_wave_header((WAVEFORMATEX *)this->m_sVhdr2); #endif this->m_pDMO_Filter = DMO_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType); if( !this->m_pDMO_Filter ) { free(this->m_sVhdr); free(this->m_sVhdr2); free(this); return NULL; } return this; }