Send PTP_RC_GeneralError when cancelling object transfers.

Moved back uint64 to unsigned long to avoid variable truncation with the vitamtp library.
Astyle format dds.cpp.
This commit is contained in:
codestation
2014-01-07 18:33:21 -04:30
parent 5fb47de3da
commit 019d2a03a4
6 changed files with 90 additions and 75 deletions

View File

@@ -62,6 +62,7 @@ void CmaClient::connectUsb()
do { do {
if((vita = VitaMTP_Get_First_USB_Vita()) != NULL) { if((vita = VitaMTP_Get_First_USB_Vita()) != NULL) {
qDebug("Starting new USB connection");
processNewConnection(vita); processNewConnection(vita);
} else { } else {
//TODO: replace this with an event-driven setup //TODO: replace this with an event-driven setup
@@ -93,6 +94,7 @@ void CmaClient::connectWireless()
do { do {
if((vita = VitaMTP_Get_First_Wireless_Vita(&host, 0, CC::deviceRegistered, CC::generatePin, CC::registrationComplete)) != NULL) { if((vita = VitaMTP_Get_First_Wireless_Vita(&host, 0, CC::deviceRegistered, CC::generatePin, CC::registrationComplete)) != NULL) {
qDebug("Starting new wireless connection");
processNewConnection(vita); processNewConnection(vita);
} else { } else {
mutex.lock(); mutex.lock();

View File

@@ -446,6 +446,9 @@ void CmaEvent::vitaEventSendObject(vita_event_t *event, int eventId)
quint16 ret = VitaMTP_SendObject_Callback(device, &parentHandle, &handle, &object->metadata, &CmaEvent::readCallback); quint16 ret = VitaMTP_SendObject_Callback(device, &parentHandle, &handle, &object->metadata, &CmaEvent::readCallback);
if(ret != PTP_RC_OK) { if(ret != PTP_RC_OK) {
qWarning("Sending of %s failed. Code: %04X", object->metadata.name, ret); qWarning("Sending of %s failed. Code: %04X", object->metadata.name, ret);
if(ret == PTP_ERROR_CANCEL) {
VitaMTP_ReportResult(device, eventId, PTP_RC_GeneralError);
}
m_file->close(); m_file->close();
delete m_file; delete m_file;
return; return;
@@ -945,23 +948,26 @@ void CmaEvent::vitaEventCheckExistance(vita_event_t *event, int eventId)
VitaMTP_ReportResult(device, eventId, PTP_RC_OK); VitaMTP_ReportResult(device, eventId, PTP_RC_OK);
} }
int CmaEvent::readCallback(unsigned char *data, int64_t wantlen, int64_t *gotlen) int CmaEvent::readCallback(unsigned char *data, unsigned long wantlen, unsigned long *gotlen)
{ {
*gotlen = m_file->read((char *)data, wantlen); int ret = m_file->read((char *)data, wantlen);
if(*gotlen == -1) { if(ret != -1) {
return -1; *gotlen = ret;
ret = PTP_RC_OK;
} }
return PTP_RC_OK; return ret;
} }
int CmaEvent::writeCallback(const unsigned char *data, int64_t size, int64_t *written) int CmaEvent::writeCallback(const unsigned char *data, unsigned long size, unsigned long *written)
{ {
int ret = m_file->write((const char *)data, size); int ret = m_file->write((const char *)data, size);
if(ret != -1) { if(ret != -1) {
*written = ret; *written = ret;
ret = PTP_RC_OK; ret = PTP_RC_OK;
} }
return ret; return ret;
} }

View File

@@ -63,9 +63,8 @@ private:
void vitaEventSendObjectMetadataItems(vita_event_t *event, int eventId); void vitaEventSendObjectMetadataItems(vita_event_t *event, int eventId);
void vitaEventSendNPAccountInfo(vita_event_t *event, int eventId); void vitaEventSendNPAccountInfo(vita_event_t *event, int eventId);
static int readCallback(unsigned char *data, int64_t wantlen, int64_t *gotlen); static int readCallback(unsigned char *data, unsigned long wantlen, unsigned long *gotlen);
static int writeCallback(const unsigned char *data, int64_t size, int64_t *written); static int writeCallback(const unsigned char *data, unsigned long size, unsigned long *written);
static int readHTTPCallback(unsigned char *data, int64_t wantlen, int64_t *gotlen);
void processEvent(); void processEvent();
bool isActive(); bool isActive();

View File

@@ -49,13 +49,11 @@ typedef quint8 uchar;
#define VERTICAL 2 #define VERTICAL 2
#define CUBE_LAYOUT HORIZONTAL #define CUBE_LAYOUT HORIZONTAL
struct Color8888 struct Color8888 {
{
uchar r, g, b, a; uchar r, g, b, a;
}; };
union Color565 union Color565 {
{
struct { struct {
ushort b : 5; ushort b : 5;
ushort g : 6; ushort g : 6;
@@ -234,8 +232,7 @@ static DDSType GetType( const DDSHeader & header )
case 32: case 32:
return DDS_A8R8G8B8; return DDS_A8R8G8B8;
} }
} } else {
else {
switch( header.pf.bitcount ) { switch( header.pf.bitcount ) {
case 16: case 16:
return DDS_R5G6B5; return DDS_R5G6B5;
@@ -243,8 +240,7 @@ static DDSType GetType( const DDSHeader & header )
return DDS_R8G8B8; return DDS_R8G8B8;
} }
} }
} } else if( header.pf.flags & DDPF_FOURCC ) {
else if( header.pf.flags & DDPF_FOURCC ) {
switch( header.pf.fourcc ) { switch( header.pf.fourcc ) {
case FOURCC_DXT1: case FOURCC_DXT1:
return DDS_DXT1; return DDS_DXT1;
@@ -388,14 +384,12 @@ static QDataStream & operator>> ( QDataStream & s, Color565 & c )
} }
struct BlockDXT struct BlockDXT {
{
Color565 col0; Color565 col0;
Color565 col1; Color565 col1;
uchar row[4]; uchar row[4];
void GetColors( Color8888 color_array[4] ) void GetColors( Color8888 color_array[4] ) {
{
color_array[0].r = (col0.c.r << 3) | (col0.c.r >> 2); color_array[0].r = (col0.c.r << 3) | (col0.c.r >> 2);
color_array[0].g = (col0.c.g << 2) | (col0.c.g >> 4); color_array[0].g = (col0.c.g << 2) | (col0.c.g >> 4);
color_array[0].b = (col0.c.b << 3) | (col0.c.b >> 2); color_array[0].b = (col0.c.b << 3) | (col0.c.b >> 2);
@@ -417,8 +411,7 @@ struct BlockDXT
color_array[3].g = (2 * color_array[1].g + color_array[0].g) / 3; color_array[3].g = (2 * color_array[1].g + color_array[0].g) / 3;
color_array[3].b = (2 * color_array[1].b + color_array[0].b) / 3; color_array[3].b = (2 * color_array[1].b + color_array[0].b) / 3;
color_array[3].a = 0xFF; color_array[3].a = 0xFF;
} } else {
else {
// Three-color block: derive the other color. // Three-color block: derive the other color.
color_array[2].r = (color_array[0].r + color_array[1].r) / 2; color_array[2].r = (color_array[0].r + color_array[1].r) / 2;
color_array[2].g = (color_array[0].g + color_array[1].g) / 2; color_array[2].g = (color_array[0].g + color_array[1].g) / 2;
@@ -454,14 +447,12 @@ struct BlockDXTAlphaLinear {
uchar alpha1; uchar alpha1;
uchar bits[6]; uchar bits[6];
void GetAlphas( uchar alpha_array[8] ) void GetAlphas( uchar alpha_array[8] ) {
{
alpha_array[0] = alpha0; alpha_array[0] = alpha0;
alpha_array[1] = alpha1; alpha_array[1] = alpha1;
// 8-alpha or 6-alpha block? // 8-alpha or 6-alpha block?
if( alpha_array[0] > alpha_array[1] ) if( alpha_array[0] > alpha_array[1] ) {
{
// 8-alpha block: derive the other 6 alphas. // 8-alpha block: derive the other 6 alphas.
// 000 = alpha_0, 001 = alpha_1, others are interpolated // 000 = alpha_0, 001 = alpha_1, others are interpolated
@@ -471,9 +462,7 @@ struct BlockDXTAlphaLinear {
alpha_array[5] = ( 3 * alpha0 + 4 * alpha1) / 7; // Bit code 101 alpha_array[5] = ( 3 * alpha0 + 4 * alpha1) / 7; // Bit code 101
alpha_array[6] = ( 2 * alpha0 + 5 * alpha1) / 7; // Bit code 110 alpha_array[6] = ( 2 * alpha0 + 5 * alpha1) / 7; // Bit code 110
alpha_array[7] = ( alpha0 + 6 * alpha1) / 7; // Bit code 111 alpha_array[7] = ( alpha0 + 6 * alpha1) / 7; // Bit code 111
} } else {
else
{
// 6-alpha block: derive the other alphas. // 6-alpha block: derive the other alphas.
// 000 = alpha_0, 001 = alpha_1, others are interpolated // 000 = alpha_0, 001 = alpha_1, others are interpolated
@@ -486,27 +475,40 @@ struct BlockDXTAlphaLinear {
} }
} }
void GetBits( uchar bit_array[16] ) void GetBits( uchar bit_array[16] ) {
{
// Split 24 packed bits into 8 bytes, 3 bits at a time. // Split 24 packed bits into 8 bytes, 3 bits at a time.
uint b = bits[0] | bits[1] << 8 | bits[2] << 16; uint b = bits[0] | bits[1] << 8 | bits[2] << 16;
bit_array[0] = uchar(b & 0x07); b >>= 3; bit_array[0] = uchar(b & 0x07);
bit_array[1] = uchar(b & 0x07); b >>= 3; b >>= 3;
bit_array[2] = uchar(b & 0x07); b >>= 3; bit_array[1] = uchar(b & 0x07);
bit_array[3] = uchar(b & 0x07); b >>= 3; b >>= 3;
bit_array[4] = uchar(b & 0x07); b >>= 3; bit_array[2] = uchar(b & 0x07);
bit_array[5] = uchar(b & 0x07); b >>= 3; b >>= 3;
bit_array[6] = uchar(b & 0x07); b >>= 3; bit_array[3] = uchar(b & 0x07);
b >>= 3;
bit_array[4] = uchar(b & 0x07);
b >>= 3;
bit_array[5] = uchar(b & 0x07);
b >>= 3;
bit_array[6] = uchar(b & 0x07);
b >>= 3;
bit_array[7] = uchar(b & 0x07); bit_array[7] = uchar(b & 0x07);
b = bits[3] | bits[4] << 8 | bits[5] << 16; b = bits[3] | bits[4] << 8 | bits[5] << 16;
bit_array[8] = uchar(b & 0x07); b >>= 3; bit_array[8] = uchar(b & 0x07);
bit_array[9] = uchar(b & 0x07); b >>= 3; b >>= 3;
bit_array[10] = uchar(b & 0x07); b >>= 3; bit_array[9] = uchar(b & 0x07);
bit_array[11] = uchar(b & 0x07); b >>= 3; b >>= 3;
bit_array[12] = uchar(b & 0x07); b >>= 3; bit_array[10] = uchar(b & 0x07);
bit_array[13] = uchar(b & 0x07); b >>= 3; b >>= 3;
bit_array[14] = uchar(b & 0x07); b >>= 3; bit_array[11] = uchar(b & 0x07);
b >>= 3;
bit_array[12] = uchar(b & 0x07);
b >>= 3;
bit_array[13] = uchar(b & 0x07);
b >>= 3;
bit_array[14] = uchar(b & 0x07);
b >>= 3;
bit_array[15] = uchar(b & 0x07); bit_array[15] = uchar(b & 0x07);
} }
}; };
@@ -603,7 +605,9 @@ static bool LoadDXT3( QDataStream & s, const DDSHeader & header, QImage & img )
static bool LoadDXT2( QDataStream & s, const DDSHeader & header, QImage & img ) static bool LoadDXT2( QDataStream & s, const DDSHeader & header, QImage & img )
{ {
if( !LoadDXT3(s, header, img) ) return false; if( !LoadDXT3(s, header, img) ) {
return false;
}
//UndoPremultiplyAlpha(img); //UndoPremultiplyAlpha(img);
return true; return true;
} }
@@ -658,7 +662,9 @@ static bool LoadDXT5( QDataStream & s, const DDSHeader & header, QImage & img )
} }
static bool LoadDXT4( QDataStream & s, const DDSHeader & header, QImage & img ) static bool LoadDXT4( QDataStream & s, const DDSHeader & header, QImage & img )
{ {
if( !LoadDXT5(s, header, img) ) return false; if( !LoadDXT5(s, header, img) ) {
return false;
}
//UndoPremultiplyAlpha(img); //UndoPremultiplyAlpha(img);
return true; return true;
} }
@@ -771,7 +777,8 @@ static bool LoadATI2( QDataStream & s, const DDSHeader & header, QImage & img )
typedef bool (* TextureLoader)( QDataStream & s, const DDSHeader & header, QImage & img ); typedef bool (* TextureLoader)( QDataStream & s, const DDSHeader & header, QImage & img );
// Get an appropriate texture loader for the given type. // Get an appropriate texture loader for the given type.
static TextureLoader GetTextureLoader( DDSType type ) { static TextureLoader GetTextureLoader( DDSType type )
{
switch( type ) { switch( type ) {
case DDS_A8R8G8B8: case DDS_A8R8G8B8:
return LoadA8R8G8B8; return LoadA8R8G8B8;
@@ -826,7 +833,8 @@ static bool LoadTexture( QDataStream & s, const DDSHeader & header, QImage & img
} }
static int FaceOffset( const DDSHeader & header ) { static int FaceOffset( const DDSHeader & header )
{
DDSType type = GetType( header ); DDSType type = GetType( header );
@@ -843,8 +851,7 @@ static int FaceOffset( const DDSHeader & header ) {
w >>= 1; w >>= 1;
h >>= 1; h >>= 1;
} while( --mipmap ); } while( --mipmap );
} } else {
else {
int multiplier = header.pf.bitcount / 8; int multiplier = header.pf.bitcount / 8;
do { do {
int face_size = w * h * multiplier; int face_size = w * h * multiplier;
@@ -956,8 +963,9 @@ bool canReadDDS(QIODevice *device)
qint64 readBytes = device->read(head, sizeof(head)); qint64 readBytes = device->read(head, sizeof(head));
if (readBytes != sizeof(head)) { if (readBytes != sizeof(head)) {
if (device->isSequential()) { if (device->isSequential()) {
while (readBytes > 0) while (readBytes > 0) {
device->ungetChar(head[readBytes-- - 1]); device->ungetChar(head[readBytes-- - 1]);
}
} else { } else {
device->seek(oldPos); device->seek(oldPos);
} }
@@ -965,8 +973,9 @@ bool canReadDDS(QIODevice *device)
} }
if (device->isSequential()) { if (device->isSequential()) {
while (readBytes > 0) while (readBytes > 0) {
device->ungetChar(head[readBytes-- - 1]); device->ungetChar(head[readBytes-- - 1]);
}
} else { } else {
device->seek(oldPos); device->seek(oldPos);
} }
@@ -1018,8 +1027,7 @@ bool loadDDS(const QString &filename, QImage *image)
if( IsCubeMap( header ) ) { if( IsCubeMap( header ) ) {
result = LoadCubeMap( s, header, *image ); result = LoadCubeMap( s, header, *image );
} } else {
else {
result = LoadTexture( s, header, *image ); result = LoadTexture( s, header, *image );
} }

View File

@@ -30,8 +30,8 @@ QMutex HTTPDownloader::dataAvailable;
QMutex HTTPDownloader::dataRead; QMutex HTTPDownloader::dataRead;
char *HTTPDownloader::buffer = NULL; char *HTTPDownloader::buffer = NULL;
qint64 HTTPDownloader::bufferSize = 0; unsigned long HTTPDownloader::bufferSize = 0;
qint64 HTTPDownloader::downloadLeft = 0; unsigned long HTTPDownloader::downloadLeft = 0;
HTTPDownloader::HTTPDownloader(const QString &url, QObject *parent) : HTTPDownloader::HTTPDownloader(const QString &url, QObject *parent) :
QObject(parent), remote_url(url), firstRead(true) QObject(parent), remote_url(url), firstRead(true)
@@ -111,7 +111,7 @@ void HTTPDownloader::readyRead()
dataRead.unlock(); dataRead.unlock();
} }
int HTTPDownloader::readCallback(unsigned char *data, int64_t wantlen, int64_t *gotlen) int HTTPDownloader::readCallback(unsigned char *data, unsigned long wantlen, unsigned long *gotlen)
{ {
if(!dataAvailable.tryLock(30000)) { if(!dataAvailable.tryLock(30000)) {
qWarning("Connection timeout while receiving data from network, aborting"); qWarning("Connection timeout while receiving data from network, aborting");

View File

@@ -40,7 +40,7 @@ signals:
public slots: public slots:
void downloadFile(); void downloadFile();
static int readCallback(unsigned char *data, int64_t wantlen, int64_t *gotlen); static int readCallback(unsigned char *data, unsigned long wantlen, unsigned long *gotlen);
void metadataChanged(); void metadataChanged();
void readyRead(); void readyRead();
void error(QNetworkReply::NetworkError); void error(QNetworkReply::NetworkError);
@@ -58,8 +58,8 @@ private:
volatile static qint64 m_contentLength; volatile static qint64 m_contentLength;
static char *buffer; static char *buffer;
static qint64 bufferSize; static unsigned long bufferSize;
static qint64 downloadLeft; static unsigned long downloadLeft;
}; };
#endif // HTTPDOWNLOADER_H #endif // HTTPDOWNLOADER_H