Merge svn changes up to r28549
[mplayer.git] / loader / dmo / dmo.c
blobee6ac27f3c9ceb70d08c58625cf415fb207d9a12
1 /*
2 * Modified for use with MPlayer, detailed changelog at
3 * http://svn.mplayerhq.hu/mplayer/trunk/
4 */
6 #include "config.h"
7 #include "DMO_Filter.h"
8 #include "drv.h"
9 #include "com.h"
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include "win32.h" // printf macro
15 void trapbug();
16 typedef long STDCALL (*GETCLASS) (const GUID*, const GUID*, void**);
18 void DMO_Filter_Destroy(DMO_Filter* This)
20 if (This->m_pOptim)
21 This->m_pOptim->vt->Release((IUnknown*)This->m_pOptim);
22 if (This->m_pInPlace)
23 This->m_pInPlace->vt->Release((IUnknown*)This->m_pInPlace);
24 if (This->m_pMedia)
25 This->m_pMedia->vt->Release((IUnknown*)This->m_pMedia);
27 free(This);
28 #ifdef WIN32_LOADER
29 CodecRelease();
30 #endif
33 DMO_Filter* DMO_FilterCreate(const char* dllname, const GUID* id,
34 DMO_MEDIA_TYPE* in_fmt,
35 DMO_MEDIA_TYPE* out_fmt)
37 HRESULT hr = 0;
38 const char* em = NULL;
39 DMO_Filter* This = (DMO_Filter*) malloc(sizeof(DMO_Filter));
40 if (!This)
41 return NULL;
43 memset(This, 0, sizeof(DMO_Filter));
44 #ifdef WIN32_LOADER
45 CodecAlloc();
46 #endif
48 //This->Start = DS_Filter_Start;
49 //This->Stop = DS_Filter_Stop;
51 for (;;)
53 GETCLASS func;
54 struct IClassFactory* factory = NULL;
55 struct IUnknown* object = NULL;
56 unsigned int i;
57 unsigned long inputs, outputs;
59 This->m_iHandle = LoadLibraryA(dllname);
60 if (!This->m_iHandle)
62 em = "could not open DMO DLL";
63 break;
65 func = (GETCLASS)GetProcAddress((unsigned)This->m_iHandle, "DllGetClassObject");
66 if (!func)
68 em = "illegal or corrupt DMO DLL";
69 break;
71 //trapbug();
72 hr = func(id, &IID_IClassFactory, (void*)&factory);
73 if (hr || !factory)
75 em = "no such class object";
76 break;
78 hr = factory->vt->CreateInstance(factory, 0, &IID_IUnknown, (void*)&object);
79 factory->vt->Release((IUnknown*)factory);
80 if (hr || !object)
82 em = "class factory failure";
83 break;
85 hr = object->vt->QueryInterface(object, &IID_IMediaObject, (void*)&This->m_pMedia);
86 if (hr == 0)
88 /* query for some extra available interface */
89 HRESULT r = object->vt->QueryInterface(object, &IID_IMediaObjectInPlace, (void*)&This->m_pInPlace);
90 if (r == 0 && This->m_pInPlace)
91 printf("DMO dll supports InPlace - PLEASE REPORT to developer\n");
92 r = object->vt->QueryInterface(object, &IID_IDMOVideoOutputOptimizations, (void*)&This->m_pOptim);
93 if (r == 0 && This->m_pOptim)
95 unsigned long flags;
96 r = This->m_pOptim->vt->QueryOperationModePreferences(This->m_pOptim, 0, &flags);
97 printf("DMO dll supports VO Optimizations %ld %lx\n", r, flags);
98 if (flags & DMO_VOSF_NEEDS_PREVIOUS_SAMPLE)
99 printf("DMO dll might use previous sample when requested\n");
102 object->vt->Release((IUnknown*)object);
103 if (hr || !This->m_pMedia)
105 em = "object does not provide IMediaObject interface";
106 break;
108 hr = This->m_pMedia->vt->SetInputType(This->m_pMedia, 0, in_fmt, 0);
109 if (hr)
111 em = "input format not accepted";
112 break;
115 if (0) {
116 DMO_MEDIA_TYPE dmo;
117 //VIDEOINFOHEADER* vi;
118 memset(&dmo, 0, sizeof(dmo));
119 i = This->m_pMedia->vt->GetOutputType(This->m_pMedia, 0, 2, &dmo);
120 Debug printf("GetOutputType %x \n", i);
121 Debug printf("DMO 0x%x (%.4s) 0x%x (%.4s)\n"
122 //Debug printf("DMO 0x%x 0x%x\n"
123 ":: fixszsamp:%d tempcomp:%d sampsz:%ld\n"
124 ":: formtype: 0x%x\n"
125 ":: unk %p cbform: %ld pbform:%p\n",
126 dmo.majortype.f1,
127 (const char*)&dmo.majortype.f1,
128 dmo.subtype.f1,
129 (const char*)&dmo.subtype.f1,
130 dmo.bFixedSizeSamples, dmo.bTemporalCompression,
131 dmo.lSampleSize,
132 dmo.formattype.f1,
133 dmo.pUnk, dmo.cbFormat, dmo.pbFormat
135 /* vi = (VIDEOINFOHEADER*) dmo.pbFormat;
136 vi = (VIDEOINFOHEADER*) out_fmt->pbFormat;
137 for (i = 0; i < out_fmt->cbFormat; i++)
138 Debug printf("BYTE %d %02x %02x\n", i, ((uint8_t*)dmo.pbFormat)[i], ((uint8_t*)out_fmt->pbFormat)[i]);
142 hr = This->m_pMedia->vt->SetOutputType(This->m_pMedia, 0, out_fmt, 0);
143 if (hr)
145 em = "output format no accepted";
146 break;
149 inputs = outputs = 0;
150 hr = This->m_pMedia->vt->GetOutputSizeInfo(This->m_pMedia, 0, &inputs, &outputs);
151 Debug printf("GetOutput r=0x%lx size:%ld align:%ld\n", hr, inputs, outputs);
153 // This->m_pMedia->vt->AllocateStreamingResources(This->m_pMedia);
154 hr = This->m_pMedia->vt->GetStreamCount(This->m_pMedia, &inputs, &outputs);
155 Debug printf("StreamCount r=0x%lx %ld %ld\n", hr, inputs, outputs);
157 break;
159 if (em)
161 DMO_Filter_Destroy(This);
162 printf("IMediaObject ERROR: %p %s (0x%lx : %ld)\n", em, em ? em : "", hr, hr);
163 This = 0;
165 return This;