3 #include <ptclib/pvfiledev.h>
4 #include <opal/transcoders.h>
5 #include <codec/vidcodec.h>
9 #define MAJOR_VERSION 1
10 #define MINOR_VERSION 0
11 #define BUILD_TYPE ReleaseCode
12 #define BUILD_NUMBER 0
14 #define RAW_VIDEO_FORMAT OpalYUV420P
16 class VidCodecTest
: public PProcess
18 PCLASSINFO(VidCodecTest
, PProcess
)
25 namespace PWLibStupidLinkerHacks
{
26 extern int opalLoader
;
29 extern int intelLoader
;
32 PCREATE_PROCESS(VidCodecTest
);
34 VidCodecTest::VidCodecTest()
35 : PProcess("Post Increment", "VidCodecTest",
36 MAJOR_VERSION
, MINOR_VERSION
, BUILD_TYPE
, BUILD_NUMBER
)
38 PWLibStupidLinkerHacks::opalLoader
= 1;
44 OpalTranscoderList keys
= OpalTranscoderFactory::GetKeyList();
45 OpalTranscoderList::const_iterator r
;
46 for (r
= keys
.begin(); r
!= keys
.end(); ++r
) {
47 const OpalMediaFormatPair
& transcoder
= *r
;
48 if (transcoder
.GetInputFormat().GetDefaultSessionID() == OpalMediaFormat::DefaultVideoSessionID
) {
49 cout
<< "Name: " << transcoder
<< "\n"
50 << " Input: " << transcoder
.GetInputFormat() << "\n"
51 << " Output: " << transcoder
.GetOutputFormat() << "\n";
56 ////////////////////////////////////////////////////////////////////////////////
58 void VidCodecTest::Main()
61 << " Version " << GetVersion(TRUE
)
62 << " by " << GetManufacturer()
63 << " on " << GetOSClass() << ' ' << GetOSName()
64 << " (" << GetOSVersion() << '-' << GetOSHardware() << ")\n\n";
66 PConfigArgs
args(GetArguments());
77 PTrace::Initialise(args
.GetOptionCount('t'),
78 args
.HasOption('o') ? (const char *)args
.GetOptionString('o') : NULL
);
81 if ((args
.GetCount() == 1) && (args
[0] *= "list")) {
86 if (args
.GetCount() < 4) {
87 PError
<< "usage: h263test 'encode'|'decode'|'xcode' codec infilename outfilename" << endl
;
91 char coding
= tolower(args
[0][0]);
93 PString inCodec
, outCodec
;
94 OpalTranscoder
* encoder
= NULL
;
95 OpalTranscoder
* decoder
= NULL
;
98 if (coding
== 'd' || coding
== 'x') {
100 //inCodec = "H.264-QCIF";
101 outCodec
= RAW_VIDEO_FORMAT
;
102 decoder
= OpalTranscoder::Create(inCodec
, outCodec
);
103 if (decoder
== NULL
) {
104 PError
<< "error: unable to create decoder of " << inCodec
<< endl
;
108 cout
<< "Created decoder from " << inCodec
<< " to " << outCodec
<< endl
;
111 if (coding
== 'e' || coding
== 'x') {
112 inCodec
= RAW_VIDEO_FORMAT
;
114 encoder
= OpalTranscoder::Create(inCodec
, outCodec
);
115 if (encoder
== NULL
) {
116 PError
<< "error: unable to create encoder of " << outCodec
<< endl
;
120 cout
<< "Created encoder from " << inCodec
<< " to " << outCodec
<< endl
;
124 PError
<< "Valid transcoders are:";
131 if (coding
== 'e' || coding
== 'x') {
132 if (!yuvIn
.Open(args
[2], PFile::ReadOnly
, PFile::MustExist
)) {
133 PError
<< "error: cannot open YUV input file " << args
[2] << endl
;
137 if (coding
== 'd' || coding
== 'x') {
138 if (!yuvOut
.Open(args
[3], PFile::WriteOnly
)) {
139 PError
<< "error: cannot open YUV output file " << args
[3] << endl
;
145 PError
<< "error: decoding not yet implemented" << endl
;
149 PError
<< "error: encoding not yet implemented" << endl
;
154 PINDEX frameCount
= 0;
159 RTP_DataFrame
yuvInFrame(sizeof(PluginCodec_Video_FrameHeader
) + (yuvIn
.GetWidth() * yuvOut
.GetHeight() * 3) / 2);
160 RTP_DataFrameList encodedFrames
, yuvOutFrame
;
162 PluginCodec_Video_FrameHeader
* header
= (PluginCodec_Video_FrameHeader
*)yuvInFrame
.GetPayloadPtr();
166 header
->width
= yuvIn
.GetWidth();
167 header
->height
= yuvIn
.GetHeight();
169 if (!yuvIn
.ReadFrame(OPAL_VIDEO_FRAME_DATA_PTR(header
))) {
173 encodedFrames
.Append(new RTP_DataFrame(100000));
174 if (!encoder
->ConvertFrames(yuvInFrame
, encodedFrames
)) {
175 PError
<< "error: encoder returned error" << endl
;
179 yuvOutFrame
.RemoveAll();
181 for (i
= 0; i
< encodedFrames
.GetSize(); ++i
) {
182 if (!decoder
->ConvertFrames(encodedFrames
[i
], yuvOutFrame
)) {
183 PError
<< "error: decoder returned error" << endl
;
186 if (yuvOutFrame
.GetSize() > 0)
189 if (i
!= encodedFrames
.GetSize()-1) {
190 PError
<< "warning: frame created from incomplete input frame list" << endl
;
193 PluginCodec_Video_FrameHeader
* headerOut
= (PluginCodec_Video_FrameHeader
*)yuvOutFrame
[0].GetPayloadPtr();
195 if (!yuvOut
.WriteFrame(OPAL_VIDEO_FRAME_DATA_PTR(headerOut
))) {
196 PError
<< "error: output file write failed" << endl
;
203 cout
<< frameCount
<< " frames transcoded" << endl
;