Patch from Gabriel Hartmann for his GSoC UVC project. Coding style updates by myself. Thanks!
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42688 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -565,8 +565,15 @@ CamDevice::DataPumpThread()
|
|||||||
}
|
}
|
||||||
#ifdef SUPPORT_ISO
|
#ifdef SUPPORT_ISO
|
||||||
else if (SupportsIsochronous()) {
|
else if (SupportsIsochronous()) {
|
||||||
int numPacketDescriptors = 20;
|
int numPacketDescriptors = 16;
|
||||||
usb_iso_packet_descriptor packetDescriptors[numPacketDescriptors];
|
usb_iso_packet_descriptor packetDescriptors[numPacketDescriptors];
|
||||||
|
|
||||||
|
// Initialize packetDescriptor request lengths
|
||||||
|
for (int i = 0; i<numPacketDescriptors; i++)
|
||||||
|
packetDescriptors[i].request_length = 256;
|
||||||
|
|
||||||
|
int fullPackets = 0;
|
||||||
|
int totalPackets = 0;
|
||||||
while (fTransferEnabled) {
|
while (fTransferEnabled) {
|
||||||
ssize_t len = -1;
|
ssize_t len = -1;
|
||||||
BAutolock lock(fLocker);
|
BAutolock lock(fLocker);
|
||||||
@@ -575,7 +582,8 @@ CamDevice::DataPumpThread()
|
|||||||
if (!fIsoIn)
|
if (!fIsoIn)
|
||||||
break;
|
break;
|
||||||
#ifndef DEBUG_DISCARD_INPUT
|
#ifndef DEBUG_DISCARD_INPUT
|
||||||
len = fIsoIn->IsochronousTransfer(fBuffer, fBufferLen, packetDescriptors, numPacketDescriptors);
|
len = fIsoIn->IsochronousTransfer(fBuffer, fBufferLen, packetDescriptors,
|
||||||
|
numPacketDescriptors);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//PRINT((CH ": got %d bytes" CT, len));
|
//PRINT((CH ": got %d bytes" CT, len));
|
||||||
@@ -594,8 +602,16 @@ CamDevice::DataPumpThread()
|
|||||||
|
|
||||||
#ifndef DEBUG_DISCARD_DATA
|
#ifndef DEBUG_DISCARD_DATA
|
||||||
if (fDataInput) {
|
if (fDataInput) {
|
||||||
fDataInput->Write(fBuffer, len);
|
int fBufferIndex = 0;
|
||||||
// else drop
|
for (int i = 0; i < numPacketDescriptors; i++) {
|
||||||
|
int actual_length = ((usb_iso_packet_descriptor)
|
||||||
|
packetDescriptors[i]).actual_length;
|
||||||
|
if (actual_length > 0) {
|
||||||
|
fDataInput->Write(&fBuffer[fBufferIndex],
|
||||||
|
actual_length);
|
||||||
|
}
|
||||||
|
fBufferIndex += actual_length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//snooze(2000);
|
//snooze(2000);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ addonSources =
|
|||||||
QuickCamDevice.cpp
|
QuickCamDevice.cpp
|
||||||
SonixCamDevice.cpp
|
SonixCamDevice.cpp
|
||||||
NW80xCamDevice.cpp
|
NW80xCamDevice.cpp
|
||||||
# UVCCamDevice.cpp
|
# UVCCamDevice.cpp UVCDeframer.cpp
|
||||||
;
|
;
|
||||||
|
|
||||||
## colorspace transforms sources
|
## colorspace transforms sources
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright 2011, Gabriel Hartmann, gabriel.hartmann@gmail.com.
|
||||||
* Copyright 2011, Jérôme Duval, korli@users.berlios.de.
|
* Copyright 2011, Jérôme Duval, korli@users.berlios.de.
|
||||||
* Copyright 2009, Ithamar Adema, <ithamar.adema@team-embedded.nl>.
|
* Copyright 2009, Ithamar Adema, <ithamar.adema@team-embedded.nl>.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
@@ -24,6 +25,15 @@ public:
|
|||||||
uint32 &height);
|
uint32 &height);
|
||||||
virtual status_t AcceptVideoFrame(uint32 &width,
|
virtual status_t AcceptVideoFrame(uint32 &width,
|
||||||
uint32 &height);
|
uint32 &height);
|
||||||
|
virtual void AddParameters(BParameterGroup *group,
|
||||||
|
int32 &index);
|
||||||
|
virtual status_t GetParameterValue(int32 id,
|
||||||
|
bigtime_t *last_change, void *value,
|
||||||
|
size_t *size);
|
||||||
|
virtual status_t SetParameterValue(int32 id, bigtime_t when,
|
||||||
|
const void *value, size_t size);
|
||||||
|
virtual status_t FillFrameBuffer(BBuffer *buffer,
|
||||||
|
bigtime_t *stamp = NULL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _ParseVideoControl(
|
void _ParseVideoControl(
|
||||||
@@ -35,14 +45,52 @@ private:
|
|||||||
status_t _ProbeCommitFormat();
|
status_t _ProbeCommitFormat();
|
||||||
status_t _SelectBestAlternate();
|
status_t _SelectBestAlternate();
|
||||||
status_t _SelectIdleAlternate();
|
status_t _SelectIdleAlternate();
|
||||||
|
void _DecodeColor(unsigned char *dst,
|
||||||
|
unsigned char *src, int32 width,
|
||||||
|
int32 height);
|
||||||
|
|
||||||
|
float _AddParameter(BParameterGroup* group,
|
||||||
|
BParameterGroup** subgroup, int32 index,
|
||||||
|
uint16 wValue, const char* name);
|
||||||
|
int _AddAutoParameter(BParameterGroup* subgroup,
|
||||||
|
int32 index, uint16 wValue);
|
||||||
|
|
||||||
usbvc_interface_header_descriptor *fHeaderDescriptor;
|
usbvc_interface_header_descriptor *fHeaderDescriptor;
|
||||||
|
|
||||||
const BUSBEndpoint* fInterruptIn;
|
const BUSBEndpoint* fInterruptIn;
|
||||||
uint32 fControlIndex;
|
uint32 fControlIndex;
|
||||||
|
uint16 fControlRequestIndex;
|
||||||
uint32 fStreamingIndex;
|
uint32 fStreamingIndex;
|
||||||
|
uint32 fUncompressedFormatIndex;
|
||||||
|
uint32 fUncompressedFrameIndex;
|
||||||
|
uint32 fMJPEGFormatIndex;
|
||||||
|
uint32 fMJPEGFrameIndex;
|
||||||
uint32 fMaxVideoFrameSize;
|
uint32 fMaxVideoFrameSize;
|
||||||
uint32 fMaxPayloadTransferSize;
|
uint32 fMaxPayloadTransferSize;
|
||||||
|
|
||||||
|
BList fUncompressedFrames;
|
||||||
|
BList fMJPEGFrames;
|
||||||
|
|
||||||
|
float fBrightness;
|
||||||
|
float fContrast;
|
||||||
|
float fHue;
|
||||||
|
float fSaturation;
|
||||||
|
float fSharpness;
|
||||||
|
float fGamma;
|
||||||
|
float fWBTemp;
|
||||||
|
float fWBComponent;
|
||||||
|
float fBacklightCompensation;
|
||||||
|
float fGain;
|
||||||
|
|
||||||
|
bool fBinaryBacklightCompensation;
|
||||||
|
|
||||||
|
int fWBTempAuto;
|
||||||
|
int fWBCompAuto;
|
||||||
|
int fHueAuto;
|
||||||
|
int fBacklightCompensationBinary;
|
||||||
|
int fPowerlineFrequency;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Gabriel Hartmann, gabriel.hartmann@gmail.com.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "UVCDeframer.h"
|
||||||
|
|
||||||
|
#include "CamDebug.h"
|
||||||
|
#include "CamDevice.h"
|
||||||
|
|
||||||
|
#include <Autolock.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_TAG_LEN CAMDEFRAMER_MAX_TAG_LEN
|
||||||
|
#define MAXFRAMEBUF CAMDEFRAMER_MAX_QUEUED_FRAMES
|
||||||
|
|
||||||
|
|
||||||
|
UVCDeframer::UVCDeframer(CamDevice* device)
|
||||||
|
: CamDeframer(device),
|
||||||
|
fFrameCount(0),
|
||||||
|
fID(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UVCDeframer::~UVCDeframer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ssize_t
|
||||||
|
UVCDeframer::Write(const void* buffer, size_t size)
|
||||||
|
{
|
||||||
|
const uint8* buf = (const uint8*)buffer;
|
||||||
|
int payloadSize = size - buf[0]; // total length - header length
|
||||||
|
|
||||||
|
// This packet is just a header
|
||||||
|
if (size == buf[0])
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// Allocate frame
|
||||||
|
if (!fCurrentFrame) {
|
||||||
|
BAutolock l(fLocker);
|
||||||
|
if (fFrames.CountItems() < MAXFRAMEBUF)
|
||||||
|
fCurrentFrame = AllocFrame();
|
||||||
|
else {
|
||||||
|
printf("Dropped %ld bytes. Too many queued frames.)\n", size);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write payload to buffer
|
||||||
|
fInputBuffer.Write(&buf[buf[0]], payloadSize);
|
||||||
|
|
||||||
|
// If end of frame add frame to list of frames
|
||||||
|
if ((buf[1] & 2) || (buf[1] & 1) != fID) {
|
||||||
|
fID = buf[1] & 1;
|
||||||
|
fFrameCount++;
|
||||||
|
buf = (uint8*)fInputBuffer.Buffer();
|
||||||
|
fCurrentFrame->Write(buf, fInputBuffer.BufferLength());
|
||||||
|
fFrames.AddItem(fCurrentFrame);
|
||||||
|
release_sem(fFrameSem);
|
||||||
|
fCurrentFrame = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
UVCDeframer::_PrintBuffer(const void* buffer, size_t size)
|
||||||
|
{
|
||||||
|
uint8* b = (uint8*)buffer;
|
||||||
|
for (size_t i = 0; i < size; i++)
|
||||||
|
printf("0x%x\t", b[i]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Gabriel Hartmann, gabriel.hartmann@gmail.com.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _UVC_DEFRAMER_H
|
||||||
|
#define _UVC_DEFRAMER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "CamDeframer.h"
|
||||||
|
|
||||||
|
#include <USB3.h>
|
||||||
|
|
||||||
|
|
||||||
|
class UVCDeframer : public CamDeframer {
|
||||||
|
public:
|
||||||
|
UVCDeframer(CamDevice *device);
|
||||||
|
virtual ~UVCDeframer();
|
||||||
|
// BPositionIO interface
|
||||||
|
// write from usb transfers
|
||||||
|
virtual ssize_t Write(const void *buffer, size_t size);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _PrintBuffer(const void* buffer, size_t size);
|
||||||
|
|
||||||
|
int32 fFrameCount;
|
||||||
|
int32 fID;
|
||||||
|
BMallocIO fInputBuffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _UVC_DEFRAMER_H */
|
||||||
|
|
||||||
+1
-1
@@ -52,7 +52,7 @@ ClassName(int classNumber) {
|
|||||||
case 0xE0:
|
case 0xE0:
|
||||||
return "Wireless controller";
|
return "Wireless controller";
|
||||||
case 0xEF:
|
case 0xEF:
|
||||||
return "Miscelaneous";
|
return "Miscellaneous";
|
||||||
case 0xFE:
|
case 0xFE:
|
||||||
return "Application specific";
|
return "Application specific";
|
||||||
case 0xFF:
|
case 0xFF:
|
||||||
|
|||||||
Reference in New Issue
Block a user