[Opalvoip-svn] SF.net SVN: opalvoip:[30074] ptlib/trunk
Brought to you by:
csoutheren,
rjongbloed
From: <rjo...@us...> - 2013-06-28 07:35:35
|
Revision: 30074 http://sourceforge.net/p/opalvoip/code/30074 Author: rjongbloed Date: 2013-06-28 07:35:29 +0000 (Fri, 28 Jun 2013) Log Message: ----------- Merged revision(s) 30067-30072 from opal/branches/v3_12: Implemented the partially done y4m (raw video) file support. Added "720p" and "1080p" synonyms for resolution strings. Modified Paths: -------------- ptlib/trunk/include/ptclib/pvidfile.h ptlib/trunk/src/ptclib/pvidfile.cxx ptlib/trunk/src/ptlib/common/videoio.cxx Property Changed: ---------------- ptlib/trunk/ Index: ptlib/trunk =================================================================== --- ptlib/trunk 2013-06-28 06:56:59 UTC (rev 30073) +++ ptlib/trunk 2013-06-28 07:35:29 UTC (rev 30074) Property changes on: ptlib/trunk ___________________________________________________________________ Modified: svn:mergeinfo ## -4,7 +4,7 ## /ptlib/branches/Sirius_B:24839,24844,24968,24982 /ptlib/branches/csoutheren/LalandeBranch1:23331-23333,23723 /ptlib/branches/v2_10:25177-29189 -/ptlib/branches/v2_12:28485-30065 +/ptlib/branches/v2_12:28485-30072 /ptlib/branches/v2_2:20746,20791,20827,22014,22942 /ptlib/branches/v2_4:21086,21094,21147,21160,21185,21281,21296,21305,21322,21337,21363,21467,21471-21472,21506,21508,21623,21695,21744,21746,21763,22241,22958,23045-23046,23061,23066,23712 /ptlib/branches/v2_6:22195,22243,22295,22304,22311,22317,22320,22356,22458,22509,22587,22601-22602,22611,22629,22633,22673,22681,22729,22731-22732,22736,22742,22848,22960,22992,23161,23163,23167,23169,23177,23239,23291,23298,23336,23429,23595,23823,23827,23873,24816 \ No newline at end of property Modified: ptlib/trunk/include/ptclib/pvidfile.h =================================================================== --- ptlib/trunk/include/ptclib/pvidfile.h 2013-06-28 06:56:59 UTC (rev 30073) +++ ptlib/trunk/include/ptclib/pvidfile.h 2013-06-28 07:35:29 UTC (rev 30074) @@ -101,6 +101,7 @@ bool m_fixedFrameRate; PINDEX m_frameBytes; off_t m_headerOffset; + off_t m_frameHeaderLen; PFile m_file; }; @@ -121,13 +122,11 @@ PFile::OpenOptions opts = PFile::ModeDefault // <code>OpenOptions</code> enum# for open operation. ); - virtual PBoolean SetPosition(off_t pos, PFile::FilePositionOrigin origin); virtual PBoolean WriteFrame(const void * frame); virtual PBoolean ReadFrame(void * frame); protected: bool m_y4mMode; - int m_currPos; }; PFACTORY_LOAD(PYUVFile); Modified: ptlib/trunk/src/ptclib/pvidfile.cxx =================================================================== --- ptlib/trunk/src/ptclib/pvidfile.cxx 2013-06-28 06:56:59 UTC (rev 30073) +++ ptlib/trunk/src/ptclib/pvidfile.cxx 2013-06-28 07:35:29 UTC (rev 30074) @@ -43,7 +43,9 @@ #include <ptclib/pvidfile.h> #include <ptlib/videoio.h> +#define PTraceModule() "VidFile" + /////////////////////////////////////////////////////////////////////////////// PVideoFile::PVideoFile() @@ -51,6 +53,7 @@ , m_fixedFrameRate(false) , m_frameBytes(CalculateFrameBytes()) , m_headerOffset(0) + , m_frameHeaderLen(0) { } @@ -63,7 +66,7 @@ bool PVideoFile::SetFrameSizeFromFilename(const PString & fn) { - static PRegularExpression res("_(sqcif|qcif|cif|cif4|cif16|[0-9]+x[0-9]+)[^a-z0-9]", + static PRegularExpression res("_(sqcif|qcif|cif|cif4|cif16|HD[0-9]+|[0-9]+p|[0-9]+x[0-9]+)[^a-z0-9]", PRegularExpression::Extended|PRegularExpression::IgnoreCase); PINDEX pos, len; if (!fn.FindRegEx(res, pos, len) || !Parse(fn.Mid(pos+1, len-2))) @@ -101,10 +104,10 @@ #if PTRACING if (m_file.GetErrorCode(PFile::LastReadError) != PFile::NoError) - PTRACE(2, "VidFile\tError reading file \"" << m_file.GetFilePath() + PTRACE(2, "Error reading file \"" << m_file.GetFilePath() << "\" - " << m_file.GetErrorText(PFile::LastReadError)); else - PTRACE(4, "VidFile\tEnd of file \"" << m_file.GetFilePath() << '"'); + PTRACE(4, "End of file \"" << m_file.GetFilePath() << '"'); #endif return false; @@ -114,26 +117,26 @@ off_t PVideoFile::GetLength() const { off_t len = m_file.GetLength(); - return len < m_headerOffset ? 0 : ((len - m_headerOffset)/m_frameBytes); + return len < m_headerOffset ? 0 : ((len - m_headerOffset)/(m_frameBytes+m_frameHeaderLen)); } PBoolean PVideoFile::SetLength(off_t len) { - return m_file.SetLength(len*m_frameBytes + m_headerOffset); + return m_file.SetLength(len*(m_frameBytes+m_frameHeaderLen) + m_headerOffset); } off_t PVideoFile::GetPosition() const { off_t pos = m_file.GetPosition(); - return pos < m_headerOffset ? 0 : ((pos - m_headerOffset)/m_frameBytes); + return pos < m_headerOffset ? 0 : ((pos - m_headerOffset)/(m_frameBytes+m_frameHeaderLen)); } PBoolean PVideoFile::SetPosition(off_t pos, PFile::FilePositionOrigin origin) { - pos *= m_frameBytes; + pos *= m_frameBytes+m_frameHeaderLen; if (origin == PFile::Start) pos += m_headerOffset; @@ -182,6 +185,18 @@ } +static PString ReadPrintable(PFile & file) +{ + PString str; + + int ch; + while ((ch = file.ReadChar()) >= ' ' && ch < 0x7f) + str += (char)ch; + + return str; +} + + PBoolean PYUVFile::Open(const PFilePath & name, PFile::OpenMode mode, PFile::OpenOptions opts) { SetFrameSizeFromFilename(name); @@ -194,45 +209,84 @@ m_fixedFrameSize = !m_y4mMode; if (m_y4mMode) { - PString info; - int ch; - for (;;) { - if ((ch = m_file.ReadChar()) < 0) - return false; - if (ch == '\n') - break; - info += (char)ch; + PString info = ReadPrintable(m_file); + + PStringArray params = info.Tokenise(" \t", false); // Really is juts a space, but be forgiving + if (params.IsEmpty() || params[0] != "YUV4MPEG2") { + PTRACE(2, "Invalid file format, does not start with YUV4MPEG2"); + return false; } - PTRACE(4, "VidFile\ty4m header \"" << info << "\""); - m_headerOffset = m_file.GetPosition(); - m_currPos = 0; - } - return true; -} + for (PINDEX i = 1; i < params.GetSize(); ++i) { + PString param = params[i].ToUpper(); + switch (param[0]) { + case 'W' : + frameWidth = param.Mid(1).AsUnsigned(); + m_fixedFrameSize = true; + break; + case 'H' : + frameHeight = param.Mid(1).AsUnsigned(); + m_fixedFrameSize = true; + break; -PBoolean PYUVFile::SetPosition(off_t pos, PFile::FilePositionOrigin origin) -{ - if (!m_y4mMode) - return PVideoFile::SetPosition(pos, origin); + case 'F' : + { + unsigned denom = param.Mid(param.Find(':')+1).AsUnsigned(); + frameRate = (param.Mid(1).AsUnsigned()+denom/2)/denom; + m_fixedFrameRate = true; + } + break; - if (origin != PFile::Start) - return false; + case 'I' : + if (param[1] != 'P') { + PTRACE(2, "Interlace modes are not supported"); + return false; + } + break; - if (pos == 0) { - m_file.SetPosition(m_headerOffset, origin); - m_currPos = 0; + case 'A' : + sarWidth = param.Mid(1).AsUnsigned(); + sarHeight = param.Mid(param.Find(':')+1).AsUnsigned(); + break; + + case 'C' : + if (param == "C420") + colourFormat = "YUV420P"; + else if (param == "C422") + colourFormat = "YUV422P"; + else { + PTRACE(2, "Interlace modes are not supported"); + return false; + } + break; + } + } + + PTRACE(4, "y4m \"" << info << '"'); + m_headerOffset = m_file.GetPosition(); + m_frameBytes = CalculateFrameBytes(); } - return (pos == m_currPos); + return true; } PBoolean PYUVFile::WriteFrame(const void * frame) { - if (m_y4mMode) - m_file.WriteChar('\n'); + if (m_y4mMode) { + if (m_file.GetPosition() > 0) + m_file.WriteString("FRAME\n"); + else { + m_file << "YUV4MPEG2 W" << frameWidth << " H" << frameHeight << " F" << frameRate << ":1 Ip"; + if (sarWidth > 0 && sarHeight > 0) + m_file << " A" << sarWidth << ':' << sarHeight; + if (colourFormat == "YUV422P") + m_file << " C422"; + m_file << endl; + m_headerOffset = m_file.GetPosition(); + } + } return m_file.Write(frame, m_frameBytes); } @@ -240,26 +294,19 @@ PBoolean PYUVFile::ReadFrame(void * frame) { - if (!m_y4mMode) - return PVideoFile::ReadFrame(frame); - - PString info; - int ch; - for (;;) { - if ((ch = m_file.ReadChar()) < 0) + if (m_y4mMode) { + PString info = ReadPrintable(m_file); + if (m_frameHeaderLen == 0) + m_frameHeaderLen = m_file.GetPosition() - m_headerOffset; + if (info.NumCompare("FRAME") != EqualTo) { + PTRACE(2, "Invalid frame header in y4m file"); return false; - if (ch == '\n') - break; - info += (char)ch; + } + PTRACE(6, "y4m \"" << info << '"'); + PTRACE(4, "VidFile\ty4m frame \"" << info << '"'); } - PTRACE(4, "VidFile\ty4m frame \"" << info << '"'); - if (!PVideoFile::ReadFrame(frame)) - return false; - - ++m_currPos; - - return true; + return PVideoFile::ReadFrame(frame); } Modified: ptlib/trunk/src/ptlib/common/videoio.cxx =================================================================== --- ptlib/trunk/src/ptlib/common/videoio.cxx 2013-06-28 06:56:59 UTC (rev 30073) +++ ptlib/trunk/src/ptlib/common/videoio.cxx 2013-06-28 07:35:29 UTC (rev 30074) @@ -442,8 +442,10 @@ { "HD480", PVideoDevice::HD480Width, PVideoDevice::HD480Height }, { "HDTVP", PVideoDevice::HD720Width, PVideoDevice::HD720Height }, { "HD720", PVideoDevice::HD720Width, PVideoDevice::HD720Height }, + { "720p", PVideoDevice::HD720Width, PVideoDevice::HD720Height }, { "HDTVI", PVideoDevice::HD1080Width,PVideoDevice::HD1080Height}, { "HD1080", PVideoDevice::HD1080Width,PVideoDevice::HD1080Height}, + { "1080p", PVideoDevice::HD1080Width,PVideoDevice::HD1080Height}, { "CGA", 320, 240 }, { "VGA", 640, 480 }, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |