OPAL Version 3.10.4

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- File List
- Globals

rfc4175.h
Go to the documentation of this file.
1 /*
2 * rfc4175.h
3 *
4 * RFC4175 transport for uncompressed video
5 *
6 * Open Phone Abstraction Library
7 *
8 * Copyright (C) 2007 Post Increment
9 *
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
14 *
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * The Original Code is Open Phone Abstraction Library.
21 *
22 * The Initial Developer of the Original Code is Post Increment
23 *
24 * Contributor(s): ______________________________________.
25 *
26 * $Revision: 24413 $
27 * $Author: rjongbloed $
28 * $Date: 2010-05-27 19:41:47 -0500 (Thu, 27 May 2010) $
29 */
30
31 #ifndef OPAL_CODEC_RFC4175_H
32 #define OPAL_CODEC_RFC4175_H
33
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37
38 #include <ptlib.h>
39
40 #include <opal/buildopts.h>
41
42 #if OPAL_RFC4175
43
44 #include <ptclib/random.h>
45
46 #include <opal/transcoders.h>
47 #include <codec/opalplugin.h>
48 #include <codec/vidcodec.h>
49
50
51 #define OPAL_RFC4175_YCbCr420 "RFC4175_YCbCr-4:2:0"
52 extern const OpalVideoFormat & GetOpalRFC4175_YCbCr420();
53 #define OpalRFC4175YCbCr420 GetOpalRFC4175_YCbCr420()
54
55 #define OPAL_RFC4175_RGB "RFC4175_RGB"
56 extern const OpalVideoFormat & GetOpalRFC4175_RGB();
57 #define OpalRFC4175RGB GetOpalRFC4175_RGB()
58
59
61
62 class OpalRFC4175Transcoder : public OpalVideoTranscoder
63 {
64 PCLASSINFO(OpalRFC4175Transcoder, OpalVideoTranscoder);
65 public:
66 OpalRFC4175Transcoder(
67 const OpalMediaFormat & inputMediaFormat,
68 const OpalMediaFormat & outputMediaFormat
69 );
70 virtual PINDEX GetPgroupSize() const = 0;
71 virtual PINDEX GetColsPerPgroup() const = 0;
72 virtual PINDEX GetRowsPerPgroup() const = 0;
73
74 virtual PINDEX PixelsToBytes(PINDEX pixels) const = 0;
75 PINDEX RFC4175HeaderSize(PINDEX lines);
76
77 struct ScanLineHeader {
78 PUInt16b m_length;
79 PUInt16b m_y; // has field flag in top bit
80 PUInt16b m_offset; // has last line flag in top bit
81 };
82 };
83
85
86 class OpalRFC4175Encoder : public OpalRFC4175Transcoder
87 {
88 PCLASSINFO(OpalRFC4175Encoder, OpalRFC4175Transcoder);
89 public:
90 OpalRFC4175Encoder(
91 const OpalMediaFormat & inputMediaFormat,
92 const OpalMediaFormat & outputMediaFormat
93 );
94
95 bool ConvertFrames(const RTP_DataFrame & input, RTP_DataFrameList & output);
96
97 protected:
98 virtual void StartEncoding(const RTP_DataFrame & input);
99 virtual void EndEncoding() = 0;
100
101 void EncodeFullFrame();
102 void EncodeScanLineSegment(PINDEX y, PINDEX offs, PINDEX width);
103 void AddNewDstFrame();
104 void FinishOutputFrame();
105
106 DWORD m_extendedSequenceNumber;
107 PINDEX m_maximumPacketSize;
108 unsigned m_frameHeight;
109 unsigned m_frameWidth;
110
111 DWORD m_srcTimestamp;
112
113 RTP_DataFrameList * m_dstFrames;
114 std::vector<PINDEX> m_dstScanlineCounts;
115 PINDEX m_dstScanLineCount;
116 PINDEX m_dstPacketSize;
117 ScanLineHeader * m_dstScanLineTable;
118 };
119
121
122 class OpalRFC4175Decoder : public OpalRFC4175Transcoder
123 {
124 PCLASSINFO(OpalRFC4175Decoder, OpalRFC4175Transcoder);
125 public:
126 OpalRFC4175Decoder(
127 const OpalMediaFormat & inputMediaFormat,
128 const OpalMediaFormat & outputMediaFormat
129 );
130 ~OpalRFC4175Decoder();
131
132 virtual PINDEX PixelsToBytes(PINDEX pixels) const = 0;
133 virtual PINDEX BytesToPixels(PINDEX pixels) const = 0;
134
135 bool ConvertFrames(const RTP_DataFrame & input, RTP_DataFrameList & output);
136
137 protected:
138 void DecodeFramesAndSetFrameSize(RTP_DataFrameList & output);
139 virtual bool DecodeFrames(RTP_DataFrameList & output) = 0;
140
141 RTP_DataFrameList m_inputFrames;
142 std::vector<PINDEX> m_scanlineCounts;
143 PINDEX m_frameWidth, m_frameHeight;
144
145 bool m_first;
146 bool m_missingPackets;
147 PINDEX m_maxWidth;
148 PINDEX m_maxHeight;
149 DWORD m_nextSequenceNumber;
150 DWORD m_lastTimeStamp;
151 DWORD m_timeStampOfFrame;
152 DWORD m_firstSequenceOfFrame;
153 };
154
156
159 class Opal_RFC4175YCbCr420_to_YUV420P : public OpalRFC4175Decoder
160 {
161 PCLASSINFO(Opal_RFC4175YCbCr420_to_YUV420P, OpalRFC4175Decoder);
162 public:
163 Opal_RFC4175YCbCr420_to_YUV420P() : OpalRFC4175Decoder(OpalRFC4175YCbCr420, OpalYUV420P) { }
164 PINDEX GetPgroupSize() const { return 6; }
165 PINDEX GetColsPerPgroup() const { return 2; }
166 PINDEX GetRowsPerPgroup() const { return 2; }
167
168 PINDEX PixelsToBytes(PINDEX pixels) const { return pixels*12/8; }
169 PINDEX BytesToPixels(PINDEX bytes) const { return bytes*8/12; }
170
171 bool DecodeFrames(RTP_DataFrameList & output);
172 };
173
174 class Opal_YUV420P_to_RFC4175YCbCr420 : public OpalRFC4175Encoder
175 {
176 PCLASSINFO(Opal_YUV420P_to_RFC4175YCbCr420, OpalRFC4175Encoder);
177 public:
178 Opal_YUV420P_to_RFC4175YCbCr420() : OpalRFC4175Encoder(OpalYUV420P, OpalRFC4175YCbCr420) { }
179 PINDEX GetPgroupSize() const { return 6; }
180 PINDEX GetColsPerPgroup() const { return 2; }
181 PINDEX GetRowsPerPgroup() const { return 2; }
182
183 PINDEX PixelsToBytes(PINDEX pixels) const { return pixels * 12 / 8; }
184 PINDEX BytesToPixels(PINDEX bytes) const { return bytes * 8 / 12; }
185
186 void StartEncoding(const RTP_DataFrame & input);
187 void EndEncoding();
188
189 protected:
190 BYTE * m_srcYPlane;
191 BYTE * m_srcCbPlane;
192 BYTE * m_srcCrPlane;
193 };
194
197 class Opal_RFC4175RGB_to_RGB24 : public OpalRFC4175Decoder
198 {
199 PCLASSINFO(Opal_RFC4175RGB_to_RGB24, OpalRFC4175Decoder);
200 public:
201 Opal_RFC4175RGB_to_RGB24() : OpalRFC4175Decoder(OpalRFC4175RGB, OpalRGB24) { }
202 PINDEX GetPgroupSize() const { return 3; }
203 PINDEX GetColsPerPgroup() const { return 1; }
204 PINDEX GetRowsPerPgroup() const { return 1; }
205
206 PINDEX PixelsToBytes(PINDEX pixels) const { return pixels * 3; }
207 PINDEX BytesToPixels(PINDEX bytes) const { return bytes / 3; }
208
209 bool DecodeFrames(RTP_DataFrameList & output);
210 };
211
212 class Opal_RGB24_to_RFC4175RGB : public OpalRFC4175Encoder
213 {
214 PCLASSINFO(Opal_RGB24_to_RFC4175RGB, OpalRFC4175Encoder);
215 public:
216 Opal_RGB24_to_RFC4175RGB() : OpalRFC4175Encoder(OpalRGB24, OpalRFC4175RGB) { }
217 PINDEX GetPgroupSize() const { return 3; }
218 PINDEX GetColsPerPgroup() const { return 1; }
219 PINDEX GetRowsPerPgroup() const { return 1; }
220
221 PINDEX PixelsToBytes(PINDEX pixels) const { return pixels * 3; }
222 PINDEX BytesToPixels(PINDEX bytes) const { return bytes / 3; }
223
224 void StartEncoding(const RTP_DataFrame & input);
225 void EndEncoding();
226
227 protected:
228 BYTE * m_rgbBase;
229 };
230
231
232 #define OPAL_REGISTER_RFC4175_VIDEO(oformat, rformat) \
233 OPAL_REGISTER_TRANSCODER(Opal_RFC4175##rformat##_to_##oformat, OpalRFC4175##rformat, Opal##oformat); \
234 OPAL_REGISTER_TRANSCODER(Opal_##oformat##_to_RFC4175##rformat, Opal##oformat, OpalRFC4175##rformat);
235
236 #define OPAL_REGISTER_RFC4175() \
237 OPAL_REGISTER_RFC4175_VIDEO(YUV420P, YCbCr420); \
238 OPAL_REGISTER_RFC4175_VIDEO(RGB24, RGB)
239
240
242
243 #endif // OPAL_RFC4175
244
245 #endif // OPAL_CODEC_RFC4175_H