audiopath.c 11.2 KB
Newer Older
1 2
/* IDirectMusicAudioPath Implementation
 *
3
 * Copyright (C) 2003-2004 Rok Mandeljc
4
 *
5 6 7 8
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
9 10 11
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
14
 *
15 16 17
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 19 20
 */

#include "dmime_private.h"
21
#include "dmobject.h"
22

23
WINE_DEFAULT_DEBUG_CHANNEL(dmime);
24

25
struct IDirectMusicAudioPathImpl {
26
    IDirectMusicAudioPath IDirectMusicAudioPath_iface;
27
    struct dmobject dmobj;
28 29 30 31 32
    LONG ref;
    IDirectMusicPerformance8* pPerf;
    IDirectMusicGraph*        pToolGraph;
    IDirectSoundBuffer*       pDSBuffer;
    IDirectSoundBuffer*       pPrimary;
33

34
    BOOL fActive;
35 36
};

37 38 39 40 41 42 43
static inline struct IDirectMusicAudioPathImpl *impl_from_IDirectMusicAudioPath(IDirectMusicAudioPath *iface)
{
    return CONTAINING_RECORD(iface, struct IDirectMusicAudioPathImpl, IDirectMusicAudioPath_iface);
}

static inline struct IDirectMusicAudioPathImpl *impl_from_IPersistStream(IPersistStream *iface)
{
44
    return CONTAINING_RECORD(iface, struct IDirectMusicAudioPathImpl, dmobj.IPersistStream_iface);
45 46
}

47 48
void set_audiopath_perf_pointer(IDirectMusicAudioPath *iface, IDirectMusicPerformance8 *performance)
{
49
    struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
50 51 52 53 54
    This->pPerf = performance;
}

void set_audiopath_dsound_buffer(IDirectMusicAudioPath *iface, IDirectSoundBuffer *buffer)
{
55
    struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
56 57 58 59 60
    This->pDSBuffer = buffer;
}

void set_audiopath_primary_dsound_buffer(IDirectMusicAudioPath *iface, IDirectSoundBuffer *buffer)
{
61
    struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
62 63 64
    This->pPrimary = buffer;
}

65 66 67
/*****************************************************************************
 * IDirectMusicAudioPathImpl implementation
 */
68 69
static HRESULT WINAPI IDirectMusicAudioPathImpl_QueryInterface (IDirectMusicAudioPath *iface, REFIID riid, void **ppobj)
{
70
    struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
71

72
    TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
73

74
    *ppobj = NULL;
75

76
    if (IsEqualIID (riid, &IID_IDirectMusicAudioPath) || IsEqualIID (riid, &IID_IUnknown))
77
        *ppobj = &This->IDirectMusicAudioPath_iface;
78
    else if (IsEqualIID (riid, &IID_IDirectMusicObject))
79
        *ppobj = &This->dmobj.IDirectMusicObject_iface;
80
    else if (IsEqualIID (riid, &IID_IPersistStream))
81
        *ppobj = &This->dmobj.IPersistStream_iface;
82

83 84 85
    if (*ppobj) {
        IUnknown_AddRef((IUnknown*)*ppobj);
        return S_OK;
86
    }
87

88 89
    WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
    return E_NOINTERFACE;
90 91
}

92 93
static ULONG WINAPI IDirectMusicAudioPathImpl_AddRef (IDirectMusicAudioPath *iface)
{
94
    struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
95
    ULONG ref = InterlockedIncrement(&This->ref);
96

97
    TRACE("(%p): AddRef from %d\n", This, ref - 1);
98

99 100
    DMIME_LockModule();
    return ref;
101 102
}

103 104
static ULONG WINAPI IDirectMusicAudioPathImpl_Release (IDirectMusicAudioPath *iface)
{
105
    struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
106 107 108 109 110
    ULONG ref = InterlockedDecrement(&This->ref);

    TRACE("(%p): ReleaseRef to %d\n", This, ref);

    if (ref == 0) {
111 112
        if (This->pPrimary)
            IDirectSoundBuffer_Release(This->pPrimary);
113
        if (This->pDSBuffer)
114
            IDirectSoundBuffer_Release(This->pDSBuffer);
115 116 117 118 119 120
        This->pPerf = NULL;
        HeapFree(GetProcessHeap(), 0, This);
    }

    DMIME_UnlockModule();
    return ref;
121 122
}

123 124 125 126
static HRESULT WINAPI IDirectMusicAudioPathImpl_GetObjectInPath (IDirectMusicAudioPath *iface, DWORD dwPChannel, DWORD dwStage, DWORD dwBuffer,
    REFGUID guidObject, WORD dwIndex, REFGUID iidInterface, void** ppObject)
{
	struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
127
	HRESULT hr;
128

129 130
	FIXME("(%p, %d, %d, %d, %s, %d, %s, %p): stub\n", This, dwPChannel, dwStage, dwBuffer, debugstr_dmguid(guidObject),
            dwIndex, debugstr_dmguid(iidInterface), ppObject);
131
	    
132
	switch (dwStage) {
133 134 135
        case DMUS_PATH_BUFFER:
          if (This->pDSBuffer)
          {
136 137 138 139
              if (IsEqualIID (iidInterface, &IID_IUnknown) ||
                  IsEqualIID (iidInterface, &IID_IDirectSoundBuffer)  ||
                  IsEqualIID (iidInterface, &IID_IDirectSoundBuffer8) ||
                  IsEqualIID (iidInterface, &IID_IDirectSound3DBuffer)) {
140
                  return IDirectSoundBuffer_QueryInterface(This->pDSBuffer, iidInterface, ppObject);
141 142 143 144 145
              }

              WARN("Unsupported interface %s\n", debugstr_dmguid(iidInterface));
              *ppObject = NULL;
              return E_NOINTERFACE;
146 147
          }
          break;
148 149

	case DMUS_PATH_PRIMARY_BUFFER: {
150
	  if (IsEqualIID (iidInterface, &IID_IDirectSound3DListener)) {
151
            IDirectSoundBuffer_QueryInterface(This->pPrimary, &IID_IDirectSound3DListener, ppObject);
152
	    return S_OK;
153
	  } else {
154 155 156 157 158 159 160
	    FIXME("bad iid...\n");
	  }
	}
	break;

	case DMUS_PATH_AUDIOPATH_GRAPH:
	  {
161
	    if (IsEqualIID (iidInterface, &IID_IDirectMusicGraph)) {
162 163
	      if (NULL == This->pToolGraph) {
		IDirectMusicGraphImpl* pGraph;
164 165 166
		hr = create_dmgraph(&IID_IDirectMusicGraph, (void**)&pGraph);
		if (FAILED(hr))
		  return hr;
167 168
		This->pToolGraph = (IDirectMusicGraph*) pGraph;
	      }
169
	      *ppObject = This->pToolGraph;
170
	      IDirectMusicGraph_AddRef((LPDIRECTMUSICGRAPH) *ppObject);
171 172 173 174 175 176 177 178 179 180 181 182 183 184
	      return S_OK;
	    }
	  }
	  break;

	case DMUS_PATH_AUDIOPATH_TOOL:
	  {
	    /* TODO */
	  }
	  break;

	case DMUS_PATH_PERFORMANCE:
	  {
	    /* TODO check wanted GUID */
185
	    *ppObject = This->pPerf;
186
	    IUnknown_AddRef((LPUNKNOWN) *ppObject);
187 188 189 190 191 192 193
	    return S_OK;
	  }
	  break;

	case DMUS_PATH_PERFORMANCE_GRAPH:
	  {
	    IDirectMusicGraph* pPerfoGraph = NULL; 
194
	    IDirectMusicPerformance8_GetGraph(This->pPerf, &pPerfoGraph);
195 196
	    if (NULL == pPerfoGraph) {
	      IDirectMusicGraphImpl* pGraph = NULL; 
197 198 199
	      hr = create_dmgraph(&IID_IDirectMusicGraph, (void**)&pGraph);
	      if (FAILED(hr))
		return hr;
200
	      IDirectMusicPerformance8_SetGraph(This->pPerf, (IDirectMusicGraph*) pGraph);
201
	      /* we need release as SetGraph do an AddRef */
202
	      IDirectMusicGraph_Release((LPDIRECTMUSICGRAPH) pGraph);
203 204
	      pPerfoGraph = (LPDIRECTMUSICGRAPH) pGraph;
	    }
205
	    *ppObject = pPerfoGraph;
206 207 208 209 210 211 212 213 214 215 216 217 218
	    return S_OK;
	  }
	  break;

	case DMUS_PATH_PERFORMANCE_TOOL:
	default:
	  break;
	}

	*ppObject = NULL;
	return E_INVALIDARG;
}

219
static HRESULT WINAPI IDirectMusicAudioPathImpl_Activate(IDirectMusicAudioPath *iface, BOOL activate)
220
{
221 222 223 224 225 226 227 228 229 230
    struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);

    FIXME("(%p, %d): semi-stub\n", This, activate);

    if (!!activate == This->fActive)
        return S_FALSE;

    if (!activate && This->pDSBuffer) {
        /* Path is being deactivated */
        IDirectSoundBuffer_Stop(This->pDSBuffer);
231
    }
232 233 234 235

    This->fActive = !!activate;

    return S_OK;
236 237
}

238 239 240
static HRESULT WINAPI IDirectMusicAudioPathImpl_SetVolume (IDirectMusicAudioPath *iface, LONG lVolume, DWORD dwDuration)
{
  struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
241
  FIXME("(%p, %i, %d): stub\n", This, lVolume, dwDuration);
242
  return S_OK;
243 244
}

245 246 247
static HRESULT WINAPI IDirectMusicAudioPathImpl_ConvertPChannel (IDirectMusicAudioPath *iface, DWORD dwPChannelIn, DWORD* pdwPChannelOut)
{
  struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
248
  FIXME("(%p, %d, %p): stub\n", This, dwPChannelIn, pdwPChannelOut);
249
  return S_OK;
250 251
}

252
static const IDirectMusicAudioPathVtbl DirectMusicAudioPathVtbl = {
253 254 255
  IDirectMusicAudioPathImpl_QueryInterface,
  IDirectMusicAudioPathImpl_AddRef,
  IDirectMusicAudioPathImpl_Release,
256 257 258 259
  IDirectMusicAudioPathImpl_GetObjectInPath,
  IDirectMusicAudioPathImpl_Activate,
  IDirectMusicAudioPathImpl_SetVolume,
  IDirectMusicAudioPathImpl_ConvertPChannel
260 261
};

262
/* IDirectMusicObject */
263 264
static HRESULT WINAPI path_IDirectMusicObject_ParseDescriptor(IDirectMusicObject *iface,
        IStream *stream, DMUS_OBJECTDESC *desc)
265
{
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
    struct chunk_entry riff = {0};
    HRESULT hr;

    TRACE("(%p, %p, %p)\n", iface, stream, desc);

    if (!stream)
        return E_POINTER;
    if (!desc || desc->dwSize != sizeof(*desc))
        return E_INVALIDARG;

    if ((hr = stream_get_chunk(stream, &riff)) != S_OK)
        return hr;
    if (riff.id != FOURCC_RIFF || riff.type != DMUS_FOURCC_AUDIOPATH_FORM) {
        TRACE("loading failed: unexpected %s\n", debugstr_chunk(&riff));
        stream_skip_chunk(stream, &riff);
        return DMUS_E_CHUNKNOTFOUND;
    }
283

284 285 286 287
    hr = dmobj_parsedescriptor(stream, &riff, desc,
            DMUS_OBJ_OBJECT|DMUS_OBJ_NAME|DMUS_OBJ_CATEGORY|DMUS_OBJ_VERSION);
    if (FAILED(hr))
        return hr;
288

289 290
    desc->guidClass = CLSID_DirectMusicAudioPathConfig;
    desc->dwValidData |= DMUS_OBJ_CLASS;
291

292
    dump_DMUS_OBJECTDESC(desc);
293
    return S_OK;
294 295
}

296 297 298 299 300 301
static const IDirectMusicObjectVtbl dmobject_vtbl = {
    dmobj_IDirectMusicObject_QueryInterface,
    dmobj_IDirectMusicObject_AddRef,
    dmobj_IDirectMusicObject_Release,
    dmobj_IDirectMusicObject_GetDescriptor,
    dmobj_IDirectMusicObject_SetDescriptor,
302
    path_IDirectMusicObject_ParseDescriptor
303 304
};

305
/* IPersistStream */
306
static HRESULT WINAPI path_IPersistStream_Load(IPersistStream *iface, IStream *stream)
307
{
308 309 310
    struct IDirectMusicAudioPathImpl *This = impl_from_IPersistStream(iface);

    FIXME("(%p, %p): Loading not implemented yet\n", This, stream);
311

312 313
    return IDirectMusicObject_ParseDescriptor(&This->dmobj.IDirectMusicObject_iface, stream,
            &This->dmobj.desc);
314
}
315

316 317 318 319 320 321
static const IPersistStreamVtbl persiststream_vtbl = {
    dmobj_IPersistStream_QueryInterface,
    dmobj_IPersistStream_AddRef,
    dmobj_IPersistStream_Release,
    dmobj_IPersistStream_GetClassID,
    unimpl_IPersistStream_IsDirty,
322
    path_IPersistStream_Load,
323 324
    unimpl_IPersistStream_Save,
    unimpl_IPersistStream_GetSizeMax
325
};
326 327

/* for ClassFactory */
328
HRESULT WINAPI create_dmaudiopath(REFIID riid, void **ppobj)
329
{
330 331 332 333 334 335 336 337 338 339
    IDirectMusicAudioPathImpl* obj;
    HRESULT hr;

    obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicAudioPathImpl));
    if (NULL == obj) {
        *ppobj = NULL;
	return E_OUTOFMEMORY;
    }
    obj->IDirectMusicAudioPath_iface.lpVtbl = &DirectMusicAudioPathVtbl;
    obj->ref = 1;
340 341 342 343
    dmobject_init(&obj->dmobj, &CLSID_DirectMusicAudioPathConfig,
            (IUnknown *)&obj->IDirectMusicAudioPath_iface);
    obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_vtbl;
    obj->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
344 345 346 347

    hr = IDirectMusicAudioPath_QueryInterface(&obj->IDirectMusicAudioPath_iface, riid, ppobj);
    IDirectMusicAudioPath_Release(&obj->IDirectMusicAudioPath_iface);
    return hr;
348
}