00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef __OPAL_RFC4175_H
00032 #define __OPAL_RFC4175_H
00033
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037
00038 #include <ptlib.h>
00039
00040 #include <ptclib/random.h>
00041
00042 #include <opal/transcoders.h>
00043 #include <codec/opalplugin.h>
00044 #include <codec/vidcodec.h>
00045
00046 namespace PWLibStupidLinkerHacks {
00047 extern int rfc4175Loader;
00048 };
00049
00050 #define OPAL_RFC4175_YCbCr420 "RFC4175_YCbCr-4:2:0"
00051 extern const OpalVideoFormat & GetOpalRFC4175_YCbCr420();
00052 #define OpalRFC4175YCbCr420 GetOpalRFC4175_YCbCr420()
00053
00054 #define OPAL_RFC4175_RGB "RFC4175_RGB"
00055 extern const OpalVideoFormat & GetOpalRFC4175_RGB();
00056 #define OpalRFC4175RGB GetOpalRFC4175_RGB()
00057
00058
00060
00061 class OpalRFC4175Transcoder : public OpalVideoTranscoder
00062 {
00063 PCLASSINFO(OpalRFC4175Transcoder, OpalVideoTranscoder);
00064 public:
00065 OpalRFC4175Transcoder(
00066 const OpalMediaFormat & inputMediaFormat,
00067 const OpalMediaFormat & outputMediaFormat
00068 );
00069 virtual PINDEX GetPgroupSize() const = 0;
00070 virtual PINDEX GetColsPerPgroup() const = 0;
00071 virtual PINDEX GetRowsPerPgroup() const = 0;
00072
00073 virtual PINDEX PixelsToBytes(PINDEX pixels) const = 0;
00074 PINDEX RFC4175HeaderSize(PINDEX lines);
00075
00076 struct ScanLineHeader {
00077 PUInt16b length;
00078 PUInt16b y;
00079 PUInt16b offset;
00080 };
00081 };
00082
00084
00085 class OpalRFC4175Encoder : public OpalRFC4175Transcoder
00086 {
00087 PCLASSINFO(OpalRFC4175Encoder, OpalRFC4175Transcoder);
00088 public:
00089 OpalRFC4175Encoder(
00090 const OpalMediaFormat & inputMediaFormat,
00091 const OpalMediaFormat & outputMediaFormat
00092 );
00093
00094 PBoolean ConvertFrames(const RTP_DataFrame & input, RTP_DataFrameList & output);
00095
00096 protected:
00097 virtual void StartEncoding(const RTP_DataFrame & input);
00098 virtual void EndEncoding() = 0;
00099
00100 void EncodeFullFrame();
00101 void EncodeScanLineSegment(PINDEX y, PINDEX offs, PINDEX width);
00102 void AddNewDstFrame();
00103 void FinishOutputFrame();
00104
00105 DWORD extendedSequenceNumber;
00106 PINDEX maximumPacketSize;
00107 unsigned frameHeight;
00108 unsigned frameWidth;
00109
00110 DWORD srcTimestamp;
00111
00112 RTP_DataFrameList * dstFrames;
00113 std::vector<PINDEX> dstScanlineCounts;
00114 PINDEX dstScanLineCount;
00115 PINDEX dstPacketSize;
00116 ScanLineHeader * dstScanLineTable;
00117 };
00118
00120
00121 class OpalRFC4175Decoder : public OpalRFC4175Transcoder
00122 {
00123 PCLASSINFO(OpalRFC4175Decoder, OpalRFC4175Transcoder);
00124 public:
00125 OpalRFC4175Decoder(
00126 const OpalMediaFormat & inputMediaFormat,
00127 const OpalMediaFormat & outputMediaFormat
00128 );
00129 ~OpalRFC4175Decoder();
00130
00131 virtual PINDEX PixelsToBytes(PINDEX pixels) const = 0;
00132 virtual PINDEX BytesToPixels(PINDEX pixels) const = 0;
00133
00134 PBoolean ConvertFrames(const RTP_DataFrame & input, RTP_DataFrameList & output);
00135
00136 protected:
00137 PBoolean Initialise();
00138 virtual PBoolean DecodeFrames(RTP_DataFrameList & output) = 0;
00139
00140 RTP_DataFrameList inputFrames;
00141 std::vector<PINDEX> scanlineCounts;
00142 PINDEX frameWidth, frameHeight;
00143
00144 PBoolean first;
00145 DWORD lastSequenceNumber;
00146 DWORD lastTimeStamp;
00147 };
00148
00150
00153 class Opal_RFC4175YCbCr420_to_YUV420P : public OpalRFC4175Decoder
00154 {
00155 PCLASSINFO(Opal_RFC4175YCbCr420_to_YUV420P, OpalRFC4175Decoder);
00156 public:
00157 Opal_RFC4175YCbCr420_to_YUV420P() : OpalRFC4175Decoder(OpalRFC4175YCbCr420, OpalYUV420P) { }
00158 PINDEX GetPgroupSize() const { return 6; }
00159 PINDEX GetColsPerPgroup() const { return 2; }
00160 PINDEX GetRowsPerPgroup() const { return 2; }
00161
00162 PINDEX PixelsToBytes(PINDEX pixels) const { return pixels*12/8; }
00163 PINDEX BytesToPixels(PINDEX bytes) const { return bytes*8/12; }
00164
00165 PBoolean DecodeFrames(RTP_DataFrameList & output);
00166 };
00167
00168 class Opal_YUV420P_to_RFC4175YCbCr420 : public OpalRFC4175Encoder
00169 {
00170 PCLASSINFO(Opal_YUV420P_to_RFC4175YCbCr420, OpalRFC4175Encoder);
00171 public:
00172 Opal_YUV420P_to_RFC4175YCbCr420() : OpalRFC4175Encoder(OpalYUV420P, OpalRFC4175YCbCr420) { }
00173 PINDEX GetPgroupSize() const { return 6; }
00174 PINDEX GetColsPerPgroup() const { return 2; }
00175 PINDEX GetRowsPerPgroup() const { return 2; }
00176
00177 PINDEX PixelsToBytes(PINDEX pixels) const { return pixels * 12 / 8; }
00178 PINDEX BytesToPixels(PINDEX bytes) const { return bytes * 8 / 12; }
00179
00180 void StartEncoding(const RTP_DataFrame & input);
00181 void EndEncoding();
00182
00183 protected:
00184 BYTE * srcYPlane;
00185 BYTE * srcCbPlane;
00186 BYTE * srcCrPlane;
00187 };
00188
00191 class Opal_RFC4175RGB_to_RGB24 : public OpalRFC4175Decoder
00192 {
00193 PCLASSINFO(Opal_RFC4175RGB_to_RGB24, OpalRFC4175Decoder);
00194 public:
00195 Opal_RFC4175RGB_to_RGB24() : OpalRFC4175Decoder(OpalRFC4175RGB, OpalRGB24) { }
00196 PINDEX GetPgroupSize() const { return 3; }
00197 PINDEX GetColsPerPgroup() const { return 1; }
00198 PINDEX GetRowsPerPgroup() const { return 1; }
00199
00200 PINDEX PixelsToBytes(PINDEX pixels) const { return pixels * 3; }
00201 PINDEX BytesToPixels(PINDEX bytes) const { return bytes / 3; }
00202
00203 PBoolean DecodeFrames(RTP_DataFrameList & output);
00204 };
00205
00206 class Opal_RGB24_to_RFC4175RGB : public OpalRFC4175Encoder
00207 {
00208 PCLASSINFO(Opal_RGB24_to_RFC4175RGB, OpalRFC4175Encoder);
00209 public:
00210 Opal_RGB24_to_RFC4175RGB() : OpalRFC4175Encoder(OpalRGB24, OpalRFC4175RGB) { }
00211 PINDEX GetPgroupSize() const { return 3; }
00212 PINDEX GetColsPerPgroup() const { return 1; }
00213 PINDEX GetRowsPerPgroup() const { return 1; }
00214
00215 PINDEX PixelsToBytes(PINDEX pixels) const { return pixels * 3; }
00216 PINDEX BytesToPixels(PINDEX bytes) const { return bytes / 3; }
00217
00218 void StartEncoding(const RTP_DataFrame & input);
00219 void EndEncoding();
00220
00221 protected:
00222 BYTE * rgbBase;
00223 };
00224
00225
00226 #define OPAL_REGISTER_RFC4175_VIDEO(oformat, rformat) \
00227 OPAL_REGISTER_TRANSCODER(Opal_RFC4175##rformat##_to_##oformat, OpalRFC4175##rformat, Opal##oformat); \
00228 OPAL_REGISTER_TRANSCODER(Opal_##oformat##_to_RFC4175##rformat, Opal##oformat, OpalRFC4175##rformat);
00229
00231
00232 #endif