1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MediaType.h"
namespace mozilla {
namespace media {
MediaType::MediaType()
{
// Zero out our memory. We do it here, rather than in operator new,
// in case this is allocated on the stack.
memset(this, 0, sizeof(MediaType));
lSampleSize = 1;
bFixedSizeSamples = TRUE;
}
MediaType::MediaType(const MediaType& aMediaType)
{
memset(this, 0, sizeof(MediaType));
Assign(aMediaType);
}
MediaType::MediaType(const AM_MEDIA_TYPE* aMediaType)
{
memset(this, 0, sizeof(MediaType));
Assign(aMediaType);
}
MediaType::~MediaType()
{
Clear();
}
void
MediaType::operator delete(void* ptr)
{
CoTaskMemFree((void*)ptr);
}
void*
MediaType::operator new(size_t sz) throw()
{
return CoTaskMemAlloc(sz);
}
void
MediaType::Clear()
{
if (cbFormat) {
CoTaskMemFree(pbFormat);
cbFormat = 0;
pbFormat = NULL;
}
if (pUnk) {
pUnk->Release();
pUnk = NULL;
}
memset(this, 0, sizeof(MediaType));
}
HRESULT
MediaType::Assign(const AM_MEDIA_TYPE* aMediaType)
{
if (!aMediaType)
return E_POINTER;
if (aMediaType == this)
return S_OK;
// Release old data...
Clear();
// Shallow copy.
memcpy(static_cast<AM_MEDIA_TYPE*>(this), aMediaType, sizeof(AM_MEDIA_TYPE));
if (pUnk)
pUnk->AddRef();
// Create deep copy of incoming data...
if (cbFormat) {
pbFormat = (BYTE*)CoTaskMemAlloc(cbFormat);
if (!pbFormat)
return E_OUTOFMEMORY;
memcpy(pbFormat, aMediaType->pbFormat, cbFormat);
}
return S_OK;
}
void
MediaType::Forget()
{
cbFormat = 0;
pbFormat = NULL;
pUnk = NULL;
}
bool
MediaType::IsEqual(const AM_MEDIA_TYPE* aMediaType)
{
if (!aMediaType)
return false;
if (aMediaType == this)
return true;
return IsEqualGUID(majortype, aMediaType->majortype) &&
IsEqualGUID(subtype, aMediaType->subtype) &&
IsEqualGUID(formattype, aMediaType->formattype) &&
(cbFormat == aMediaType->cbFormat) &&
((cbFormat == 0) ||
(pbFormat != NULL &&
aMediaType->pbFormat != NULL &&
(memcmp(pbFormat, aMediaType->pbFormat, cbFormat) == 0)));
}
bool
MediaType::MatchesPartial(const AM_MEDIA_TYPE* aMediaType) const
{
if (!aMediaType)
return false;
if ((aMediaType->majortype != GUID_NULL) &&
(majortype != aMediaType->majortype))
return false;
if ((aMediaType->subtype != GUID_NULL) &&
(subtype != aMediaType->subtype))
return false;
if (aMediaType->formattype != GUID_NULL) {
if (formattype != aMediaType->formattype)
return false;
if (cbFormat != aMediaType->cbFormat)
return false;
if ((cbFormat != 0) &&
(memcmp(pbFormat, aMediaType->pbFormat, cbFormat) != 0))
return false;
}
return true;
}
bool
MediaType::IsPartiallySpecified() const
{
return (majortype == GUID_NULL) || (formattype == GUID_NULL);
}
BYTE*
MediaType::AllocFormatBuffer(SIZE_T aSize)
{
pbFormat = static_cast<BYTE*>(CoTaskMemAlloc(aSize));
return pbFormat;
}
}
}
|