OPAL  Version 3.14.3
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: 29536 $
27  * $Author: rjongbloed $
28  * $Date: 2013-04-19 18:55:15 +1000 (Fri, 19 Apr 2013) $
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_config.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"
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 
63 {
65  public:
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 
87 {
89  public:
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 
108  unsigned m_frameHeight;
109  unsigned m_frameWidth;
110 
112 
113  RTP_DataFrameList * m_dstFrames;
114  std::vector<PINDEX> m_dstScanlineCounts;
118 };
119 
121 
123 {
125  public:
129  );
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;
144 
145  bool m_first;
147  PINDEX m_maxWidth;
148  PINDEX m_maxHeight;
153 };
154 
156 
160 {
162  public:
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 
175 {
177  public:
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 
198 {
200  public:
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 
213 {
215  public:
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