dmort.c 4.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (C) 2003 Michael Gnnewig
 *
 * This library 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.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 18
 */

19 20
#include <stdarg.h>

21 22
#define COBJMACROS

23
#include "windef.h"
24 25 26 27 28 29 30 31 32 33
#include "winbase.h"
#include "objbase.h"
#include "mediaobj.h"
#include "dmort.h"

#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(msdmo);

/***********************************************************************
34 35 36
 *        MoCreateMediaType    (MSDMO.@)
 *
 * Allocate a new media type structure
37 38 39
 */
HRESULT WINAPI MoCreateMediaType(DMO_MEDIA_TYPE** ppmedia, DWORD cbFormat)
{
40
    HRESULT r;
41

42
    TRACE("%p %u\n", ppmedia, cbFormat);
43

44 45
    if (!ppmedia)
        return E_POINTER;
46

47 48 49
    *ppmedia = CoTaskMemAlloc(sizeof(DMO_MEDIA_TYPE));
    if (!*ppmedia)
        return E_OUTOFMEMORY;
50

51 52 53 54 55 56
    r = MoInitMediaType(*ppmedia, cbFormat);
    if (FAILED(r))
    {
        CoTaskMemFree(*ppmedia);
        *ppmedia = NULL;
    }
57

58
    return r;
59 60 61
}

/***********************************************************************
62 63 64
 *        MoInitMediaType        (MSDMO.@)
 *
 * Initialize media type structure
65 66 67
 */
HRESULT WINAPI MoInitMediaType(DMO_MEDIA_TYPE* pmedia, DWORD cbFormat)
{
68
    TRACE("%p %u\n", pmedia, cbFormat);
69

70 71
    if (!pmedia)
        return E_POINTER;
72

73
    memset(pmedia, 0, sizeof(DMO_MEDIA_TYPE));
74

75 76 77 78 79
    if (cbFormat > 0)
    {
        pmedia->pbFormat = CoTaskMemAlloc(cbFormat);
        if (!pmedia->pbFormat)
            return E_OUTOFMEMORY;
80

81 82
        pmedia->cbFormat = cbFormat;
    }
83

84
    return S_OK;
85 86 87
}

/***********************************************************************
88 89 90
 *        MoDeleteMediaType    (MSDMO.@)
 *
 * Delete a media type structure
91 92 93
 */
HRESULT WINAPI MoDeleteMediaType(DMO_MEDIA_TYPE* pmedia)
{
94
    TRACE("%p\n", pmedia);
95

96 97
    if (!pmedia)
        return E_POINTER;
98

99 100
    MoFreeMediaType(pmedia);
    CoTaskMemFree(pmedia);
101

102
    return S_OK;
103 104 105
}

/***********************************************************************
106 107 108
 *        MoFreeMediaType        (MSDMO.@)
 *
 * Free allocated members of a media type structure
109 110 111
 */
HRESULT WINAPI MoFreeMediaType(DMO_MEDIA_TYPE* pmedia)
{
112
    TRACE("%p\n", pmedia);
113

114 115
    if (!pmedia)
        return E_POINTER;
116

117 118 119 120 121
    if (pmedia->pUnk)
    {
        IUnknown_Release(pmedia->pUnk);
        pmedia->pUnk = NULL;
    }
122

123 124
    CoTaskMemFree(pmedia->pbFormat);
    pmedia->pbFormat = NULL;
125

126
    return S_OK;
127 128 129
}

/***********************************************************************
130 131 132
 *        MoDuplicateMediaType    (MSDMO.@)
 *
 * Duplicates a media type structure
133 134
 */
HRESULT WINAPI MoDuplicateMediaType(DMO_MEDIA_TYPE** ppdst,
135
                                    const DMO_MEDIA_TYPE* psrc)
136
{
137
    HRESULT r;
138

139
    TRACE("%p %p\n", ppdst, psrc);
140

141 142
    if (!ppdst || !psrc)
        return E_POINTER;
143

144 145 146
    *ppdst = CoTaskMemAlloc(sizeof(DMO_MEDIA_TYPE));
    if (!*ppdst)
        return E_OUTOFMEMORY;
147

148 149 150 151 152 153
    r = MoCopyMediaType(*ppdst, psrc);
    if (FAILED(r))
    {
        MoFreeMediaType(*ppdst);
        *ppdst = NULL;
    }
154

155
    return r;
156 157 158
}

/***********************************************************************
159 160 161
 *        MoCopyMediaType        (MSDMO.@)
 *
 * Copy a new media type structure
162 163
 */
HRESULT WINAPI MoCopyMediaType(DMO_MEDIA_TYPE* pdst,
164
                               const DMO_MEDIA_TYPE* psrc)
165
{
166 167 168 169 170
    TRACE("%p %p\n", pdst, psrc);

    if (!pdst || !psrc)
        return E_POINTER;

171 172 173
    pdst->majortype = psrc->majortype;
    pdst->subtype = psrc->subtype;
    pdst->formattype = psrc->formattype;
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199

    pdst->bFixedSizeSamples    = psrc->bFixedSizeSamples;
    pdst->bTemporalCompression = psrc->bTemporalCompression;
    pdst->lSampleSize          = psrc->lSampleSize;
    pdst->cbFormat             = psrc->cbFormat;

    if (psrc->pbFormat && psrc->cbFormat > 0)
    {
        pdst->pbFormat = CoTaskMemAlloc(psrc->cbFormat);
        if (!pdst->pbFormat)
            return E_OUTOFMEMORY;

        memcpy(pdst->pbFormat, psrc->pbFormat, psrc->cbFormat);
    }
    else
        pdst->pbFormat = NULL;

    if (psrc->pUnk)
    {
        pdst->pUnk = psrc->pUnk;
        IUnknown_AddRef(pdst->pUnk);
    }
    else
        pdst->pUnk = NULL;

    return S_OK;
200
}