📄 videoio.cxx
字号:
{
return PTrue;
}
PBoolean PVideoDevice::SetVideoFormat(VideoFormat videoFmt)
{
videoFormat = videoFmt;
return PTrue;
}
PVideoDevice::VideoFormat PVideoDevice::GetVideoFormat() const
{
return videoFormat;
}
int PVideoDevice::GetNumChannels()
{
return 1;
}
PBoolean PVideoDevice::SetChannel(int channelNum)
{
if (channelNum < 0) { // Seek out the first available channel
for (int c = 0; c < GetNumChannels(); c++) {
if (SetChannel(c))
return PTrue;
}
return PFalse;
}
if (channelNum >= GetNumChannels()) {
PTRACE(2, "PVidDev\tSetChannel number (" << channelNum << ") too large.");
return PFalse;
}
channelNumber = channelNum;
return PTrue;
}
int PVideoDevice::GetChannel() const
{
return channelNumber;
}
PBoolean PVideoDevice::SetColourFormatConverter(const PString & newColourFmt)
{
PVideoFrameInfo src = *this;
PVideoFrameInfo dst = *this;
PString colourFmt = newColourFmt; // make copy, just in case newColourFmt is reference to member colourFormat
if (converter != NULL) {
if (CanCaptureVideo()) {
if (converter->GetDstColourFormat() == colourFmt)
return PTrue;
}
else {
if (converter->GetSrcColourFormat() == colourFmt)
return PTrue;
}
converter->GetSrcFrameInfo(src);
converter->GetDstFrameInfo(dst);
delete converter;
converter = NULL;
}
if (!preferredColourFormat.IsEmpty()) {
PTRACE(4,"PVidDev\tSetColourFormatConverter, want " << colourFmt << " trying " << preferredColourFormat);
if (SetColourFormat(preferredColourFormat)) {
if (CanCaptureVideo()) {
PTRACE(4,"PVidDev\tSetColourFormatConverter set camera to native "<< preferredColourFormat);
if (preferredColourFormat != colourFmt)
src.SetColourFormat(preferredColourFormat);
}
else {
PTRACE(4,"PVidDev\tSetColourFormatConverter set renderer to "<< preferredColourFormat);
if (preferredColourFormat != colourFmt)
dst.SetColourFormat(preferredColourFormat);
}
if (nativeVerticalFlip || src.GetColourFormat() != dst.GetColourFormat()) {
converter = PColourConverter::Create(src, dst);
if (converter != NULL) {
converter->SetVFlipState(nativeVerticalFlip);
return PTrue;
}
}
}
}
if (SetColourFormat(colourFmt)) {
if (nativeVerticalFlip) {
src.SetColourFormat(colourFmt);
dst.SetColourFormat(colourFmt);
converter = PColourConverter::Create(src, dst);
if (PAssertNULL(converter) == NULL)
return PFalse;
converter->SetVFlipState(nativeVerticalFlip);
}
PTRACE(3, "PVidDev\tSetColourFormatConverter success for native " << colourFmt);
return PTrue;
}
/************************
Eventually, need something more sophisticated than this, but for the
moment pick the known colour formats that the device is very likely to
support and then look for a conversion routine from that to the
destination format.
What we really want is some sort of better heuristic that looks at
computational requirements of each converter and picks a pair of formats
that the hardware supports and uses the least CPU.
*/
PINDEX knownFormatIdx = 0;
while (knownFormatIdx < PARRAYSIZE(colourFormatBPPTab)) {
PString formatToTry = colourFormatBPPTab[knownFormatIdx].colourFormat;
PTRACE(4,"PVidDev\tSetColourFormatConverter, want " << colourFmt << " trying " << formatToTry);
if (SetColourFormat(formatToTry)) {
if (CanCaptureVideo()) {
PTRACE(4,"PVidDev\tSetColourFormatConverter set camera to "<< formatToTry);
src.SetColourFormat(formatToTry);
dst.SetColourFormat(colourFmt);
}
else {
PTRACE(4,"PVidDev\tSetColourFormatConverter set renderer to "<< formatToTry);
dst.SetColourFormat(formatToTry);
src.SetColourFormat(colourFmt);
}
converter = PColourConverter::Create(src, dst);
if (converter != NULL) {
// set converter properties that depend on this color format
PTRACE(3, "PVidDev\tSetColourFormatConverter succeeded for " << colourFmt << " and device using " << formatToTry);
converter->SetVFlipState(nativeVerticalFlip);
return PTrue;
}
}
knownFormatIdx++;
}
PTRACE(2, "PVidDev\tSetColourFormatConverter FAILED for " << colourFmt);
return PFalse;
}
PBoolean PVideoDevice::GetVFlipState()
{
if (converter != NULL)
return converter->GetVFlipState() ^ nativeVerticalFlip;
return nativeVerticalFlip;
}
PBoolean PVideoDevice::SetVFlipState(PBoolean newVFlip)
{
if (newVFlip && converter == NULL) {
converter = PColourConverter::Create(*this, *this);
if (PAssertNULL(converter) == NULL)
return PFalse;
}
if (converter != NULL)
converter->SetVFlipState(newVFlip ^ nativeVerticalFlip);
return PTrue;
}
PBoolean PVideoDevice::GetFrameSizeLimits(unsigned & minWidth,
unsigned & minHeight,
unsigned & maxWidth,
unsigned & maxHeight)
{
minWidth = minHeight = 1;
maxWidth = maxHeight = UINT_MAX;
return PFalse;
}
static struct {
unsigned asked_width, asked_height, device_width, device_height;
} framesizeTab[] = {
{ 704, 576, 640, 480 },
{ 640, 480, 704, 576 },
{ 640, 480, 352, 288 },
{ 352, 288, 704, 576 },
{ 352, 288, 640, 480 },
{ 352, 288, 352, 240 },
{ 352, 288, 320, 240 },
{ 352, 288, 176, 144 },
{ 352, 288, 1024, 576 }, /* High resolution need to be set at the end */
{ 352, 288, 1280, 960 },
{ 352, 240, 352, 288 },
{ 352, 240, 320, 240 },
{ 352, 240, 640, 480 },
{ 320, 240, 352, 288 },
{ 320, 240, 352, 240 },
{ 320, 240, 640, 480 },
{ 176, 144, 352, 288 },
{ 176, 144, 352, 240 },
{ 176, 144, 320, 240 },
{ 176, 144, 176, 120 },
{ 176, 144, 160, 120 },
{ 176, 144, 640, 480 },
{ 176, 144, 1024, 576 },
{ 176, 144, 1280, 960 }, /* High resolution need to be set at the end */
{ 176, 120, 352, 288 },
{ 176, 120, 352, 240 },
{ 176, 120, 320, 240 },
{ 176, 120, 176, 144 },
{ 176, 120, 160, 120 },
{ 176, 120, 640, 480 },
{ 160, 120, 352, 288 },
{ 160, 120, 352, 240 },
{ 160, 120, 320, 240 },
{ 160, 120, 176, 144 },
{ 160, 120, 176, 120 },
{ 160, 120, 640, 480 },
};
PBoolean PVideoDevice::SetFrameSizeConverter(unsigned width, unsigned height, ResizeMode resizeMode)
{
if (SetFrameSize(width, height)) {
if (nativeVerticalFlip && converter == NULL) {
converter = PColourConverter::Create(*this, *this);
if (PAssertNULL(converter) == NULL)
return PFalse;
}
if (converter != NULL) {
converter->SetFrameSize(frameWidth, frameHeight);
converter->SetVFlipState(nativeVerticalFlip);
}
return PTrue;
}
// Try and get the most compatible physical frame size to convert from/to
PINDEX i;
for (i = 0; i < PARRAYSIZE(framesizeTab); i++) {
if (framesizeTab[i].asked_width == width && framesizeTab[i].asked_height == height &&
SetFrameSize(framesizeTab[i].device_width, framesizeTab[i].device_height))
break;
}
if (i >= PARRAYSIZE(framesizeTab)) {
// Failed to find a resolution the device can do so far, so try
// using the maximum width and height it claims it can do.
unsigned minWidth, minHeight, maxWidth, maxHeight;
if (GetFrameSizeLimits(minWidth, minHeight, maxWidth, maxHeight))
SetFrameSize(maxWidth, maxHeight);
}
// Now create the converter ( if not already exist)
if (converter == NULL) {
PVideoFrameInfo src = *this;
PVideoFrameInfo dst = *this;
if (CanCaptureVideo())
dst.SetFrameSize(width, height);
else
src.SetFrameSize(width, height);
dst.SetResizeMode(resizeMode);
converter = PColourConverter::Create(src, dst);
if (converter == NULL) {
PTRACE(1, "PVidDev\tSetFrameSizeConverter Colour converter creation failed");
return PFalse;
}
}
else
{
if (CanCaptureVideo())
converter->SetDstFrameSize(width, height);
else
converter->SetSrcFrameSize(width, height);
converter->SetResizeMode(resizeMode);
}
PTRACE(3,"PVidDev\tColour converter used from " << converter->GetSrcFrameWidth() << 'x' << converter->GetSrcFrameHeight() << " [" << converter->GetSrcColourFormat() << "]" << " to " << converter->GetDstFrameWidth() << 'x' << converter->GetDstFrameHeight() << " [" << converter->GetDstColourFormat() << "]");
return PTrue;
}
PBoolean PVideoDevice::SetFrameSize(unsigned width, unsigned height)
{
#if PTRACING
unsigned oldWidth = frameWidth;
unsigned oldHeight = frameHeight;
#endif
unsigned minWidth, minHeight, maxWidth, maxHeight;
GetFrameSizeLimits(minWidth, minHeight, maxWidth, maxHeight);
if (width < minWidth)
frameWidth = minWidth;
else if (width > maxWidth)
frameWidth = maxWidth;
else
frameWidth = width;
if (height < minHeight)
frameHeight = minHeight;
else if (height > maxHeight)
frameHeight = maxHeight;
else
frameHeight = height;
if (converter != NULL) {
if (!converter->SetSrcFrameSize(width, height) ||
!converter->SetDstFrameSize(width, height)) {
PTRACE(1, "PVidDev\tSetFrameSize with converter failed with " << width << 'x' << height);
return PFalse;
}
}
PTRACE_IF(2, oldWidth != frameWidth || oldHeight != frameHeight,
"PVidDev\tSetFrameSize to " << frameWidth << 'x' << frameHeight);
return PTrue;
}
PBoolean PVideoDevice::GetFrameSize(unsigned & width, unsigned & height) const
{
// Channels get very upset at this not returning the output size.
return converter != NULL ? converter->GetDstFrameSize(width, height) : PVideoFrameInfo::GetFrameSize(width, height);
}
PINDEX PVideoDevice::GetMaxFrameBytesConverted(PINDEX rawFrameBytes) const
{
if (converter == NULL)
return rawFrameBytes;
PINDEX srcFrameBytes = converter->GetMaxSrcFrameBytes();
PINDEX dstFrameBytes = converter->GetMaxDstFrameBytes();
PINDEX convertedFrameBytes = PMAX(srcFrameBytes, dstFrameBytes);
return PMAX(rawFrameBytes, convertedFrameBytes);
}
int PVideoDevice::GetBrightness()
{
return frameBrightness;
}
PBoolean PVideoDevice::SetBrightness(unsigned newBrightness)
{
frameBrightness = newBrightness;
return PTrue;
}
int PVideoDevice::GetWhiteness()
{
return frameWhiteness;
}
PBoolean PVideoDevice::SetWhiteness(unsigned newWhiteness)
{
frameWhiteness = newWhiteness;
return PTrue;
}
int PVideoDevice::GetColour()
{
return frameColour;
}
PBoolean PVideoDevice::SetColour(unsigned newColour)
{
frameColour=newColour;
return PTrue;
}
int PVideoDevice::GetContrast()
{
return frameContrast;
}
PBoolean PVideoDevice::SetContrast(unsigned newContrast)
{
frameContrast=newContrast;
return PTrue;
}
int PVideoDevice::GetHue()
{
return frameHue;
}
PBoolean PVideoDevice::SetHue(unsigned newHue)
{
frameHue=newHue;
return PTrue;
}
PBoolean PVideoDevice::GetParameters (int *whiteness,
int *brightness,
int *colour,
int *contrast,
int *hue)
{
if (!IsOpen())
return PFalse;
*brightness = frameBrightness;
*colour = frameColour;
*contrast = frameContrast;
*hue = frameHue;
*whiteness = frameWhiteness;
return PTrue;
}
PBoolean PVideoDevice::SetVideoChannelFormat (int newNumber, VideoFormat newFormat)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -