Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DSMPropertyBag.h « DSUtil « src - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2ec783eebc5a8623a6ec3c6fd8d9725d066ba38a (plain)
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
 * (C) 2003-2006 Gabest
 * (C) 2006-2013, 2017 see Authors.txt
 *
 * This file is part of MPC-HC.
 *
 * MPC-HC is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * MPC-HC 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#pragma once

#include <atlcoll.h>
#include <atlsimpcoll.h>

// IDSMPropertyBag

interface __declspec(uuid("232FD5D2-4954-41E7-BF9B-09E1257B1A95"))
    IDSMPropertyBag :
    public IPropertyBag2
{
    STDMETHOD(SetProperty)(LPCWSTR key, LPCWSTR value) PURE;
    STDMETHOD(SetProperty)(LPCWSTR key, VARIANT* var) PURE;
    STDMETHOD(GetProperty)(LPCWSTR key, BSTR* value) PURE;
    STDMETHOD(DelAllProperties)() PURE;
    STDMETHOD(DelProperty)(LPCWSTR key) PURE;
};

class IDSMPropertyBagImpl : public ATL::CSimpleMap<CStringW, CStringW>, public IDSMPropertyBag, public IPropertyBag
{
    BOOL Add(const CStringW& key, const CStringW& val) {
        return __super::Add(key, val);
    }
    BOOL SetAt(const CStringW& key, const CStringW& val) {
        return __super::SetAt(key, val);
    }

public:
    IDSMPropertyBagImpl();
    virtual ~IDSMPropertyBagImpl();

    // IPropertyBag

    STDMETHODIMP Read(LPCOLESTR pszPropName, VARIANT* pVar, IErrorLog* pErrorLog);
    STDMETHODIMP Write(LPCOLESTR pszPropName, VARIANT* pVar);

    // IPropertyBag2

    STDMETHODIMP Read(ULONG cProperties, PROPBAG2* pPropBag, IErrorLog* pErrLog, VARIANT* pvarValue, HRESULT* phrError);
    STDMETHODIMP Write(ULONG cProperties, PROPBAG2* pPropBag, VARIANT* pvarValue);
    STDMETHODIMP CountProperties(ULONG* pcProperties);
    STDMETHODIMP GetPropertyInfo(ULONG iProperty, ULONG cProperties, PROPBAG2* pPropBag, ULONG* pcProperties);
    STDMETHODIMP LoadObject(LPCOLESTR pstrName, DWORD dwHint, IUnknown* pUnkObject, IErrorLog* pErrLog);

    // IDSMPropertyBag

    STDMETHODIMP SetProperty(LPCWSTR key, LPCWSTR value);
    STDMETHODIMP SetProperty(LPCWSTR key, VARIANT* var);
    STDMETHODIMP GetProperty(LPCWSTR key, BSTR* value);
    STDMETHODIMP DelAllProperties();
    STDMETHODIMP DelProperty(LPCWSTR key);
};

// IDSMResourceBag

interface __declspec(uuid("EBAFBCBE-BDE0-489A-9789-05D5692E3A93"))
    IDSMResourceBag :
    public IUnknown
{
    STDMETHOD_(DWORD, ResGetCount)() PURE;
    STDMETHOD(ResGet)(DWORD iIndex, BSTR* ppName, BSTR* ppDesc, BSTR* ppMime, BYTE** ppData, DWORD* pDataLen, DWORD_PTR* pTag) PURE;
    STDMETHOD(ResSet)(DWORD iIndex, LPCWSTR pName, LPCWSTR pDesc, LPCWSTR pMime, const BYTE* pData, DWORD len, DWORD_PTR tag) PURE;
    STDMETHOD(ResAppend)(LPCWSTR pName, LPCWSTR pDesc, LPCWSTR pMime, BYTE* pData, DWORD len, DWORD_PTR tag) PURE;
    STDMETHOD(ResRemoveAt)(DWORD iIndex) PURE;
    STDMETHOD(ResRemoveAll)(DWORD_PTR tag) PURE;
};

class CDSMResource
{
public:
    DWORD_PTR tag;
    CStringW name, desc, mime;
    CAtlArray<BYTE> data;
    CDSMResource();
    CDSMResource(const CDSMResource& r);
    CDSMResource(LPCWSTR name, LPCWSTR desc, LPCWSTR mime, BYTE* pData, int len, DWORD_PTR tag = 0);
    virtual ~CDSMResource();
    CDSMResource& operator = (const CDSMResource& r);

    // global access to all resources
    static CCritSec m_csResources;
    static CAtlMap<uintptr_t, CDSMResource*> m_resources;
};

class IDSMResourceBagImpl : public IDSMResourceBag
{
protected:
    CAtlArray<CDSMResource> m_resources;

public:
    IDSMResourceBagImpl();

    void operator += (const CDSMResource& r) { m_resources.Add(r); }

    // IDSMResourceBag

    STDMETHODIMP_(DWORD) ResGetCount();
    STDMETHODIMP ResGet(DWORD iIndex, BSTR* ppName, BSTR* ppDesc, BSTR* ppMime,
                        BYTE** ppData, DWORD* pDataLen, DWORD_PTR* pTag = nullptr);
    STDMETHODIMP ResSet(DWORD iIndex, LPCWSTR pName, LPCWSTR pDesc, LPCWSTR pMime,
                        const BYTE* pData, DWORD len, DWORD_PTR tag = 0);
    STDMETHODIMP ResAppend(LPCWSTR pName, LPCWSTR pDesc, LPCWSTR pMime,
                           BYTE* pData, DWORD len, DWORD_PTR tag = 0);
    STDMETHODIMP ResRemoveAt(DWORD iIndex);
    STDMETHODIMP ResRemoveAll(DWORD_PTR tag = 0);
};

// IDSMChapterBag

interface __declspec(uuid("2D0EBE73-BA82-4E90-859B-C7C48ED3650F"))
    IDSMChapterBag :
    public IUnknown
{
    STDMETHOD_(DWORD, ChapGetCount)() PURE;
    STDMETHOD(ChapGet)(DWORD iIndex, REFERENCE_TIME* prt, BSTR* ppName) PURE;
    STDMETHOD(ChapSet)(DWORD iIndex, REFERENCE_TIME rt, LPCWSTR pName) PURE;
    STDMETHOD(ChapAppend)(REFERENCE_TIME rt, LPCWSTR pName) PURE;
    STDMETHOD(ChapRemoveAt)(DWORD iIndex) PURE;
    STDMETHOD(ChapRemoveAll)() PURE;
    STDMETHOD_(long, ChapLookup)(REFERENCE_TIME* prt, BSTR* ppName) PURE;
    STDMETHOD(ChapSort)() PURE;
};

class CDSMChapter
{
    static int counter;
    int order;

public:
    REFERENCE_TIME rt;
    CStringW name;
    CDSMChapter();
    CDSMChapter(REFERENCE_TIME rt, LPCWSTR name);
    CDSMChapter& operator = (const CDSMChapter& c);

    bool operator <(const CDSMChapter& rhs) const {
        return (rt != rhs.rt) ? rt < rhs.rt : order < rhs.order;
    }
};

class IDSMChapterBagImpl : public IDSMChapterBag
{
protected:
    CAtlArray<CDSMChapter> m_chapters;
    bool m_fSorted;

public:
    IDSMChapterBagImpl();

    void operator += (const CDSMChapter& c) { m_chapters.Add(c); m_fSorted = false; }

    // IDSMChapterBag

    STDMETHODIMP_(DWORD) ChapGetCount();
    STDMETHODIMP ChapGet(DWORD iIndex, REFERENCE_TIME* prt, BSTR* ppName = nullptr);
    STDMETHODIMP ChapSet(DWORD iIndex, REFERENCE_TIME rt, LPCWSTR pName);
    STDMETHODIMP ChapAppend(REFERENCE_TIME rt, LPCWSTR pName);
    STDMETHODIMP ChapRemoveAt(DWORD iIndex);
    STDMETHODIMP ChapRemoveAll();
    STDMETHODIMP_(long) ChapLookup(REFERENCE_TIME* prt, BSTR* ppName = nullptr);
    STDMETHODIMP ChapSort();
};

class CDSMChapterBag : public CUnknown, public IDSMChapterBagImpl
{
public:
    CDSMChapterBag(LPUNKNOWN pUnk, HRESULT* phr);

    DECLARE_IUNKNOWN;
    STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
};

template<class T>
__declspec(nothrow noalias) __forceinline size_t range_bsearch(CAtlArray<T> const& tArray, REFERENCE_TIME rt)
{
    // MAXSIZE_T is returned by this function for status invalid
    ptrdiff_t k = tArray.GetCount() - 1;
    if ((k < 0) || (rt >= tArray[k].rt)) {
        return k;
    }
    size_t ret = MAXSIZE_T;
    if (!k) {
        return ret;
    }

    size_t i = 0, j = k;
    do {
        size_t mid = (i + j) >> 1;
        REFERENCE_TIME midrt = tArray[mid].rt;
        if (rt == midrt) {
            ret = mid;
            break;
        } else if (rt < midrt) {
            ret = MAXSIZE_T;
            if (j == mid) {
                --mid;
            }
            j = mid;
        } else if (rt > midrt) {
            ret = mid;
            if (i == mid) {
                ++mid;
            }
            i = mid;
        }
    } while (i < j);
    return ret;
}