File: dynacodec.h

package info (click to toggle)
openh323 1.18.0.dfsg-9
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 27,676 kB
  • ctags: 26,982
  • sloc: cpp: 178,986; ansic: 33,179; sh: 4,125; makefile: 981
file content (268 lines) | stat: -rw-r--r-- 8,514 bytes parent folder | download | duplicates (5)
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
 * dynacodec.h
 *
 * Dynamic codec loading
 *
 * Open H323 Library
 *
 * Copyright (c) 2003 Equivalence Pty. Ltd.
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 *
 * The Original Code is Open H323 Library.
 *
 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
 *
 * Contributor(s): ______________________________________.
 *
 * $Log: dynacodec.h,v $
 * Revision 1.2  2003/04/30 04:57:13  craigs
 * Changed interface to DLL codec to improve Opal compatibility
 *
 * Revision 1.1  2003/04/27 23:48:24  craigs
 * Initial version
 *
 */

#ifndef _OPALDYNACODEC
#define _OPALDYNACODEC

extern "C" {
#include "dllcodec.h"
};

#include "h323caps.h"

/////////////////////////////////////////////////////////////////////////////

class OpalDLLCodecRec;

class OpalDynaCodecDLL : public PDynaLink
{
  public:
    PCLASSINFO(OpalDynaCodecDLL, PDynaLink);

    OpalDynaCodecDLL(const PFilePath & codec);
    BOOL Load();

    OpalDLLCodecInfo * EnumerateCodecs(unsigned * count);

    static BOOL LoadCodecs();
    static BOOL LoadCodecs(const PDirectory & dir);
    static BOOL LoadCodec(const PFilePath & file);

    static PINDEX AddAudioCapabilities(H323EndPoint & ep,
                                       PINDEX descriptorNum,
                                       PINDEX simultaneousNum,
                                       H323Capabilities & capabilities);

    static PINDEX AddVideoCapabilities(H323EndPoint & ep,
                                       PINDEX descriptorNum,
                                       PINDEX simultaneousNum,
                                       H323Capabilities & capabilities);

    static PINDEX AddCapabilities(H323EndPoint & ep,
                                  PINDEX descriptorNum,
                                  PINDEX simultaneousNum,
                                  H323Capabilities & capabilities,
                                  const PString & type);

    static PDirectory defaultCodecDir;

  protected:
    OpalDLLCodecInfo * (*EnumerateCodecsFn)(unsigned apiVersion, unsigned * count);
    static PMutex mutex;
    static BOOL inited;
    int referenceCount;
};

/////////////////////////////////////////////////////////////////////////////

class OpalDLLCodecRec : public PObject {
  PCLASSINFO(OpalDLLCodecRec, PObject);
  public:
    OpalDLLCodecRec(OpalDynaCodecDLL & _encoder, 
               const PStringToString & _attributes, 
              const OpalDLLCodecInfo & _encoderCodeInfo,
                     OpalMediaFormat * _mediaFormat);

    void * CreateContext() const;
    void DestroyContext(void * context) const;

    H323Capability * CreateCapability(H323EndPoint & ep) const;

    void SetParameter(const PString & attribute, const PString & value) const;
    PString GetParameter(const PString & attribute, const char * defValue = NULL) const;

    OpalDynaCodecDLL & encoder;
    PStringToString    attributes;
    OpalDLLCodecInfo   info;

    OpalMediaFormat  * mediaFormat;
    //H323Capability   * capability;
    //PString            h323Name;
};

/////////////////////////////////////////////////////////////////////////////

class OpalDynaAudioCodec : public H323FramedAudioCodec
{
  PCLASSINFO(OpalDynaAudioCodec, H323FramedAudioCodec)

  public:
    OpalDynaAudioCodec(const OpalDLLCodecRec & _info, Direction direction);
    ~OpalDynaAudioCodec();
    virtual BOOL EncodeFrame(BYTE * buffer, unsigned & length);
    virtual BOOL DecodeFrame(const BYTE * buffer, unsigned length, unsigned & written);

  protected:
    const OpalDLLCodecRec & info;
    void * context;
    unsigned samplesPerFrame;
    unsigned bytesPerFrame;
};

/////////////////////////////////////////////////////////////////////////////

class OpalDynaCodecRegistration : public H323CapabilityRegistration
{
  PCLASSINFO(OpalDynaCodecRegistration, H323CapabilityRegistration);
  public:
    OpalDynaCodecRegistration(const PString & name, 
                              OpalDLLCodecRec * _encoderInfo,
                              OpalDLLCodecRec * _decoderInfo,
                              OpalMediaFormat * _mediaFormat);

    H323Capability * Create(H323EndPoint & ep) const;

    friend class OpalDynaCodecDLL;

  protected:
    OpalDLLCodecRec * encoderInfo;
    OpalDLLCodecRec * decoderInfo;
    OpalMediaFormat * mediaFormat;
};

/////////////////////////////////////////////////////////////////////////////

class OpalDynaCodecNonStandardAudioCapability : public H323NonStandardAudioCapability
{
  PCLASSINFO(OpalDynaCodecNonStandardAudioCapability, H323NonStandardAudioCapability);

  public:
    OpalDynaCodecNonStandardAudioCapability(
      const OpalDLLCodecRec & _info,
      H323EndPoint & _endpoint,
      unsigned maxPacketSize,         /// Maximum size of an audio packet in frames
      unsigned desiredPacketSize,     /// Desired transmit size of an audio packet in frames
      BYTE country,                   /// t35 information
      BYTE extension,                 /// t35 information
      WORD maufacturer,               /// t35 information
      const BYTE * nonstdHeader,      /// nonstandard header
      PINDEX nonstdHeaderLen);

    virtual PObject * Clone() const;
    virtual H323Codec * CreateCodec(H323Codec::Direction direction) const;
    virtual PString GetFormatName() const;

  protected:
    const OpalDLLCodecRec & info;
    H323EndPoint & endpoint;
};

/////////////////////////////////////////////////////////////////////////////

class OpalDynaNonStandardAudioCodec : public OpalDynaAudioCodec
{
  PCLASSINFO(OpalDynaNonStandardAudioCodec, OpalDynaAudioCodec)

  public:
    OpalDynaNonStandardAudioCodec(const OpalDLLCodecRec & _info, Direction direction);
    ~OpalDynaNonStandardAudioCodec();
};

/////////////////////////////////////////////////////////////////////////////

class OpalDynaCodecStandardAudioCapability : public H323AudioCapability
{
  PCLASSINFO(OpalDynaCodecStandardAudioCapability, H323AudioCapability);

  public:
    OpalDynaCodecStandardAudioCapability(
      const OpalDLLCodecRec & _info,
      H323EndPoint & _endpoint,
      unsigned maxPacketSize,         /// Maximum size of an audio packet in frames
      unsigned desiredPacketSize,     /// Desired transmit size of an audio packet in frames
      unsigned subType);

    BOOL OnSendingPDU(H245_AudioCapability & cap, unsigned packetSize) const;
    BOOL OnReceivedPDU(const H245_AudioCapability & cap, unsigned & packetSize);

    PObject * Clone() const;
    H323Codec * CreateCodec(H323Codec::Direction direction) const;
    PString GetFormatName() const;
    unsigned GetSubType() const;

  protected:
    const OpalDLLCodecRec & info;
    H323EndPoint & endpoint;
    unsigned subType;
};

/////////////////////////////////////////////////////////////////////////////

class OpalDynaCodecStandardVideoCapability : public H323VideoCapability
{
  PCLASSINFO(OpalDynaCodecStandardVideoCapability, H323VideoCapability);

  public:
    OpalDynaCodecStandardVideoCapability(
      const OpalDLLCodecRec & _info,
      H323EndPoint & _endpoint,
      unsigned subType);

    BOOL OnSendingPDU(H245_VideoCapability & pdu) const;
    BOOL OnSendingPDU(H245_VideoMode & pdu) const;
    BOOL OnReceivedPDU(const H245_VideoCapability & pdu);

    PObject * Clone() const;
    H323Codec * CreateCodec(H323Codec::Direction direction) const;
    PString GetFormatName() const;
    unsigned GetSubType() const;

  protected:
    const OpalDLLCodecRec & info;
    H323EndPoint & endpoint;
    unsigned subType;
};

/////////////////////////////////////////////////////////////////////////////

class OpalDynaVideoCodec : public H323VideoCodec
{
  PCLASSINFO(OpalDynaVideoCodec, H323VideoCodec)

  public:
    OpalDynaVideoCodec(
      const OpalDLLCodecRec & _info, Direction direction);

    ~OpalDynaVideoCodec();

    BOOL Read(BYTE * buffer,unsigned & length,RTP_DataFrame & rtpFrame);
    BOOL Write(const BYTE * buffer, unsigned length, const RTP_DataFrame & rtp, unsigned & written);

  protected:
    const OpalDLLCodecRec & info;
    void * context;
};


#endif