Finish implementation of AVDecoder and the old implementation based on
MediaInfo is removed. Removed old broadcast class.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include "avdecoder.h"
|
#include "avdecoder.h"
|
||||||
|
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
|
#include <QFile>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
AVDecoder::AVDecoder() :
|
AVDecoder::AVDecoder() :
|
||||||
@@ -8,9 +9,22 @@ AVDecoder::AVDecoder() :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AVDecoder::~AVDecoder()
|
||||||
|
{
|
||||||
|
if(pFormatCtx) {
|
||||||
|
avformat_close_input(&pFormatCtx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AVDecoder::init()
|
||||||
|
{
|
||||||
|
av_register_all();
|
||||||
|
}
|
||||||
|
|
||||||
bool AVDecoder::open(const QString filename)
|
bool AVDecoder::open(const QString filename)
|
||||||
{
|
{
|
||||||
if(avformat_open_input(&pFormatCtx, filename.toStdString().c_str(), NULL, NULL) != 0) {
|
|
||||||
|
if(avformat_open_input(&pFormatCtx, QFile::encodeName(filename).constData(), NULL, NULL) != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +59,7 @@ void AVDecoder::getAudioMetadata(metadata_t &metadata)
|
|||||||
metadata.data.music.title = strdup("");
|
metadata.data.music.title = strdup("");
|
||||||
}
|
}
|
||||||
|
|
||||||
av_dict_free(&file_metadata);
|
metadata.data.music.tracks->data.track_audio.bitrate = pFormatCtx->bit_rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AVDecoder::getVideoMetadata(metadata_t &metadata)
|
void AVDecoder::getVideoMetadata(metadata_t &metadata)
|
||||||
@@ -68,10 +82,33 @@ void AVDecoder::getVideoMetadata(metadata_t &metadata)
|
|||||||
if((entry = av_dict_get(file_metadata, "title", NULL, 0)) != NULL) {
|
if((entry = av_dict_get(file_metadata, "title", NULL, 0)) != NULL) {
|
||||||
metadata.data.video.title = strdup(entry->value);
|
metadata.data.video.title = strdup(entry->value);
|
||||||
} else {
|
} else {
|
||||||
metadata.data.video.title = strdup("");
|
metadata.data.video.title = metadata.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
av_dict_free(&file_metadata);
|
metadata.data.video.tracks->data.track_video.duration = pFormatCtx->duration / 1000;
|
||||||
|
metadata.data.video.tracks->data.track_video.bitrate = pFormatCtx->bit_rate;
|
||||||
|
|
||||||
|
int stream_index;
|
||||||
|
AVCodec *codec = NULL;
|
||||||
|
|
||||||
|
if((stream_index = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, &codec, 0)) >= 0) {
|
||||||
|
AVCodecContext *pCodecCtx = pFormatCtx->streams[stream_index]->codec;
|
||||||
|
metadata.data.video.tracks->data.track_video.width = pCodecCtx->width;
|
||||||
|
metadata.data.video.tracks->data.track_video.height = pCodecCtx->height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AVDecoder::getPictureMetadata(metadata_t &metadata)
|
||||||
|
{
|
||||||
|
int stream_index;
|
||||||
|
AVCodec *codec = NULL;
|
||||||
|
|
||||||
|
if((stream_index = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, &codec, 0)) >= 0) {
|
||||||
|
AVCodecContext *pCodecCtx = pFormatCtx->streams[stream_index]->codec;
|
||||||
|
metadata.data.photo.tracks->data.track_photo.width = pCodecCtx->width;
|
||||||
|
metadata.data.photo.tracks->data.track_photo.height = pCodecCtx->height;
|
||||||
|
}
|
||||||
|
metadata.data.photo.title = strdup(metadata.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray AVDecoder::getAudioThumbnail(int width, int height)
|
QByteArray AVDecoder::getAudioThumbnail(int width, int height)
|
||||||
@@ -93,20 +130,6 @@ QByteArray AVDecoder::getAudioThumbnail(int width, int height)
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AVDecoder::AVFrameToQImage(AVFrame &frame, QImage &image, int width, int height)
|
|
||||||
{
|
|
||||||
quint8 *src = frame.data[0];
|
|
||||||
|
|
||||||
for (int y = 0; y < height; y++) {
|
|
||||||
QRgb *scanLine = (QRgb *)image.scanLine(y);
|
|
||||||
|
|
||||||
for (int x = 0; x < width; x++) {
|
|
||||||
scanLine[x] = qRgb(src[3*x], src[3*x+1], src[3*x+2]);
|
|
||||||
}
|
|
||||||
src += frame.linesize[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AVFrame *AVDecoder::getDecodedFrame(AVCodecContext *pCodecCtx, int stream_index)
|
AVFrame *AVDecoder::getDecodedFrame(AVCodecContext *pCodecCtx, int stream_index)
|
||||||
{
|
{
|
||||||
AVFrame *pFrame = avcodec_alloc_frame();
|
AVFrame *pFrame = avcodec_alloc_frame();
|
||||||
@@ -134,6 +157,7 @@ QByteArray AVDecoder::getVideoThumbnail(int width, int height)
|
|||||||
QByteArray data;
|
QByteArray data;
|
||||||
int stream_index;
|
int stream_index;
|
||||||
AVFrame *pFrame;
|
AVFrame *pFrame;
|
||||||
|
AVDictionary *opts = NULL;
|
||||||
AVCodec *codec = NULL;
|
AVCodec *codec = NULL;
|
||||||
AVCodecContext *pCodecCtx = NULL;
|
AVCodecContext *pCodecCtx = NULL;
|
||||||
|
|
||||||
@@ -145,12 +169,15 @@ QByteArray AVDecoder::getVideoThumbnail(int width, int height)
|
|||||||
|
|
||||||
pCodecCtx = pFormatCtx->streams[stream_index]->codec;
|
pCodecCtx = pFormatCtx->streams[stream_index]->codec;
|
||||||
|
|
||||||
if(avcodec_open2(pCodecCtx, codec, NULL) < 0) {
|
if(avcodec_open2(pCodecCtx, codec, &opts) < 0) {
|
||||||
avcodec_close(pCodecCtx);
|
avcodec_close(pCodecCtx);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(av_seek_frame(pFormatCtx, stream_index, pFormatCtx->duration * percentage / 100, 0) < 0) {
|
qint64 seek_pos = pFormatCtx->duration * percentage / (AV_TIME_BASE * 100);
|
||||||
|
qint64 frame = av_rescale(seek_pos,pFormatCtx->streams[stream_index]->time_base.den, pFormatCtx->streams[stream_index]->time_base.num);
|
||||||
|
|
||||||
|
if(avformat_seek_file(pFormatCtx, stream_index, 0, frame, frame, AVSEEK_FLAG_FRAME) < 0) {
|
||||||
avcodec_close(pCodecCtx);
|
avcodec_close(pCodecCtx);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -163,7 +190,7 @@ QByteArray AVDecoder::getVideoThumbnail(int width, int height)
|
|||||||
AVFrame *pFrameRGB = avcodec_alloc_frame();
|
AVFrame *pFrameRGB = avcodec_alloc_frame();
|
||||||
|
|
||||||
int numBytes = avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
|
int numBytes = avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
|
||||||
uint8_t *buffer = (uint8_t *)av_malloc(numBytes * sizeof(uint8_t));
|
uint8_t *buffer = (uint8_t *)av_malloc(numBytes);
|
||||||
|
|
||||||
avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
|
avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
|
||||||
|
|
||||||
@@ -174,17 +201,20 @@ QByteArray AVDecoder::getVideoThumbnail(int width, int height)
|
|||||||
pCodecCtx->width,
|
pCodecCtx->width,
|
||||||
pCodecCtx->height,
|
pCodecCtx->height,
|
||||||
PIX_FMT_RGB24,
|
PIX_FMT_RGB24,
|
||||||
SWS_BILINEAR,
|
SWS_BICUBIC,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
QImage img(pCodecCtx->width, pCodecCtx->height, QImage::Format_RGB32);
|
if(!sws_ctx) {
|
||||||
|
avcodec_close(pCodecCtx);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
sws_scale(
|
sws_scale(
|
||||||
sws_ctx,
|
sws_ctx,
|
||||||
(uint8_t const * const *)pFrame->data,
|
pFrame->data,
|
||||||
pFrame->linesize,
|
pFrame->linesize,
|
||||||
0,
|
0,
|
||||||
pCodecCtx->height,
|
pCodecCtx->height,
|
||||||
@@ -192,11 +222,15 @@ QByteArray AVDecoder::getVideoThumbnail(int width, int height)
|
|||||||
pFrameRGB->linesize
|
pFrameRGB->linesize
|
||||||
);
|
);
|
||||||
|
|
||||||
AVFrameToQImage(*pFrame, img, pCodecCtx->width, pCodecCtx->height);
|
QImage image(pCodecCtx->width, pCodecCtx->height, QImage::Format_RGB888);
|
||||||
|
|
||||||
|
for(int y = 0, height = pCodecCtx->height, width = pCodecCtx->width; y < height; y++){
|
||||||
|
memcpy(image.scanLine(y), pFrameRGB->data[0] + y * pFrameRGB->linesize[0], width * 3);
|
||||||
|
}
|
||||||
|
|
||||||
QBuffer imgbuffer(&data);
|
QBuffer imgbuffer(&data);
|
||||||
imgbuffer.open(QIODevice::WriteOnly);
|
imgbuffer.open(QIODevice::WriteOnly);
|
||||||
QImage result = img.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
QImage result = image.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||||
result.save(&imgbuffer, "JPEG");
|
result.save(&imgbuffer, "JPEG");
|
||||||
|
|
||||||
av_free(buffer);
|
av_free(buffer);
|
||||||
@@ -211,4 +245,5 @@ QByteArray AVDecoder::getVideoThumbnail(int width, int height)
|
|||||||
void AVDecoder::close()
|
void AVDecoder::close()
|
||||||
{
|
{
|
||||||
avformat_close_input(&pFormatCtx);
|
avformat_close_input(&pFormatCtx);
|
||||||
|
pFormatCtx = NULL;
|
||||||
}
|
}
|
||||||
|
@@ -15,13 +15,17 @@ class AVDecoder
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AVDecoder();
|
AVDecoder();
|
||||||
|
~AVDecoder();
|
||||||
bool open(const QString filename);
|
bool open(const QString filename);
|
||||||
QByteArray getAudioThumbnail(int width, int height);
|
QByteArray getAudioThumbnail(int width, int height);
|
||||||
QByteArray getVideoThumbnail(int width, int height);
|
QByteArray getVideoThumbnail(int width, int height);
|
||||||
|
void getPictureMetadata(metadata_t &metadata);
|
||||||
void getAudioMetadata(metadata_t &metadata);
|
void getAudioMetadata(metadata_t &metadata);
|
||||||
void getVideoMetadata(metadata_t &metadata);
|
void getVideoMetadata(metadata_t &metadata);
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
|
static void init();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void AVFrameToQImage(AVFrame &frame, QImage &image, int width, int height);
|
void AVFrameToQImage(AVFrame &frame, QImage &image, int width, int height);
|
||||||
AVFrame *getDecodedFrame(AVCodecContext *pCodecCtx, int stream_index);
|
AVFrame *getDecodedFrame(AVCodecContext *pCodecCtx, int stream_index);
|
||||||
|
@@ -48,7 +48,7 @@ CmaBroadcast::CmaBroadcast(QObject *parent) :
|
|||||||
// generate a GUID if doesn't exist yet in settings
|
// generate a GUID if doesn't exist yet in settings
|
||||||
uuid = settings.value("guid").toString();
|
uuid = settings.value("guid").toString();
|
||||||
if(uuid.isEmpty()) {
|
if(uuid.isEmpty()) {
|
||||||
uuid = QUuid::createUuid().toString();
|
uuid = QUuid::createUuid().toString().mid(1,36);
|
||||||
settings.setValue("guid", uuid);
|
settings.setValue("guid", uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ void CmaBroadcast::readPendingDatagrams()
|
|||||||
|
|
||||||
if(datagram.contains(broadcast_query)) {
|
if(datagram.contains(broadcast_query)) {
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
socket->writeDatagram(reply.toUtf8(), sender, senderPort);
|
socket->writeDatagram(reply, sender, senderPort);
|
||||||
} else {
|
} else {
|
||||||
qWarning("Unknown request: %.*s\n", datagram.length(), datagram.constData());
|
qWarning("Unknown request: %.*s\n", datagram.length(), datagram.constData());
|
||||||
}
|
}
|
||||||
@@ -83,19 +83,23 @@ void CmaBroadcast::readPendingDatagrams()
|
|||||||
void CmaBroadcast::setAvailable()
|
void CmaBroadcast::setAvailable()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
reply = broadcast_reply
|
reply.clear();
|
||||||
|
reply.insert(0, broadcast_reply
|
||||||
.arg(broadcast_ok, uuid, "win", hostname)
|
.arg(broadcast_ok, uuid, "win", hostname)
|
||||||
.arg(VITAMTP_PROTOCOL_MAX_VERSION, 8, 10, QChar('0'))
|
.arg(VITAMTP_PROTOCOL_MAX_VERSION, 8, 10, QChar('0'))
|
||||||
.arg(QCMA_REQUEST_PORT)
|
.arg(QCMA_REQUEST_PORT)
|
||||||
.arg(VITAMTP_WIRELESS_MAX_VERSION, 8, 10, QChar('0'));
|
.arg(VITAMTP_WIRELESS_MAX_VERSION, 8, 10, QChar('0')));
|
||||||
|
reply.append('\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmaBroadcast::setUnavailable()
|
void CmaBroadcast::setUnavailable()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
reply = broadcast_reply
|
reply.clear();
|
||||||
|
reply.insert(0, broadcast_reply
|
||||||
.arg(broadcast_unavailable, uuid, "win", hostname)
|
.arg(broadcast_unavailable, uuid, "win", hostname)
|
||||||
.arg(VITAMTP_PROTOCOL_MAX_VERSION, 8, 10, QChar('0'))
|
.arg(VITAMTP_PROTOCOL_MAX_VERSION, 8, 10, QChar('0'))
|
||||||
.arg(QCMA_REQUEST_PORT)
|
.arg(QCMA_REQUEST_PORT)
|
||||||
.arg(VITAMTP_WIRELESS_MAX_VERSION, 8, 10, QChar('0'));
|
.arg(VITAMTP_WIRELESS_MAX_VERSION, 8, 10, QChar('0')));
|
||||||
|
reply.append('\0');
|
||||||
}
|
}
|
||||||
|
@@ -37,7 +37,7 @@ private:
|
|||||||
|
|
||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
QString uuid;
|
QString uuid;
|
||||||
QString reply;
|
QByteArray reply;
|
||||||
QString hostname;
|
QString hostname;
|
||||||
QUdpSocket *socket;
|
QUdpSocket *socket;
|
||||||
static const QString broadcast_reply;
|
static const QString broadcast_reply;
|
||||||
|
@@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
#include "cmaclient.h"
|
#include "cmaclient.h"
|
||||||
#include "capability.h"
|
#include "capability.h"
|
||||||
|
#include "avdecoder.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "wirelessworker.h"
|
|
||||||
|
|
||||||
#include "QApplication"
|
#include "QApplication"
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
@@ -34,17 +34,37 @@
|
|||||||
#include <MediaInfo/File__Analyse_Automatic.h>
|
#include <MediaInfo/File__Analyse_Automatic.h>
|
||||||
|
|
||||||
metadata_t CmaClient::g_thumbmeta = {0, 0, 0, NULL, NULL, 0, 0, 0, Thumbnail, {{18, 144, 80, 0, 1, 1.0f, 2}}, NULL};
|
metadata_t CmaClient::g_thumbmeta = {0, 0, 0, NULL, NULL, 0, 0, 0, Thumbnail, {{18, 144, 80, 0, 1, 1.0f, 2}}, NULL};
|
||||||
|
CmaClient *CmaClient::this_object = NULL;
|
||||||
|
|
||||||
CmaClient::CmaClient(QObject *parent) :
|
CmaClient::CmaClient(QObject *parent) :
|
||||||
BaseWorker(parent)
|
BaseWorker(parent)
|
||||||
{
|
{
|
||||||
|
this_object = this;
|
||||||
|
AVDecoder::init();
|
||||||
|
}
|
||||||
|
|
||||||
|
int CmaClient::deviceRegistered(const char *deviceid)
|
||||||
|
{
|
||||||
|
qDebug("Got connection request from %s", deviceid);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CmaClient::generatePin(wireless_vita_info_t *info, int *p_err)
|
||||||
|
{
|
||||||
|
qDebug("Registration request from %s (MAC: %s)", info->name, info->mac_addr);
|
||||||
|
int pin = qrand() % 100000000;
|
||||||
|
qDebug("Your registration PIN for %s is: %08d", info->name, pin);
|
||||||
|
*p_err = 0;
|
||||||
|
emit this_object->receivedPin(pin);
|
||||||
|
return pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
vita_device_t *CmaClient::getDeviceConnection()
|
vita_device_t *CmaClient::getDeviceConnection()
|
||||||
{
|
{
|
||||||
int num_tries = 0;
|
int num_tries = 0;
|
||||||
vita_device_t *vita;
|
vita_device_t *vita;
|
||||||
typedef BroadcastSignal BS;
|
wireless_host_info_t host;
|
||||||
|
host.port = QCMA_REQUEST_PORT;
|
||||||
|
|
||||||
while(active) {
|
while(active) {
|
||||||
vita = VitaMTP_Get_First_USB_Vita();
|
vita = VitaMTP_Get_First_USB_Vita();
|
||||||
@@ -52,7 +72,7 @@ vita_device_t *CmaClient::getDeviceConnection()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
qDebug("No Vita detected via USB, attempt %i", ++num_tries);
|
qDebug("No Vita detected via USB, attempt %i", ++num_tries);
|
||||||
vita = VitaMTP_Get_First_Wireless_Vita(&BS::info, 0, 2, BS::deviceRegistered, BS::generatePin);
|
vita = VitaMTP_Get_First_Wireless_Vita(&host, 0, 0, CmaClient::deviceRegistered, CmaClient::generatePin);
|
||||||
if(vita || !active) {
|
if(vita || !active) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -69,12 +69,16 @@ private:
|
|||||||
void vitaEventSendNPAccountInfo(vita_event_t *event, int eventId);
|
void vitaEventSendNPAccountInfo(vita_event_t *event, int eventId);
|
||||||
void vitaEventRequestTerminate(vita_event_t *event, int eventId);
|
void vitaEventRequestTerminate(vita_event_t *event, int eventId);
|
||||||
|
|
||||||
|
static int deviceRegistered(const char *deviceid);
|
||||||
|
static int generatePin(wireless_vita_info_t *info, int *p_err);
|
||||||
|
|
||||||
QWaitCondition waitCondition;
|
QWaitCondition waitCondition;
|
||||||
CmaBroadcast broadcast;
|
CmaBroadcast broadcast;
|
||||||
vita_device_t *device;
|
vita_device_t *device;
|
||||||
volatile bool active;
|
volatile bool active;
|
||||||
volatile bool connected;
|
volatile bool connected;
|
||||||
static metadata_t g_thumbmeta;
|
static metadata_t g_thumbmeta;
|
||||||
|
static CmaClient *this_object;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void receivedPin(int);
|
void receivedPin(int);
|
||||||
|
@@ -19,15 +19,13 @@
|
|||||||
|
|
||||||
#include "cmaobject.h"
|
#include "cmaobject.h"
|
||||||
#include "sforeader.h"
|
#include "sforeader.h"
|
||||||
|
#include "avdecoder.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <MediaInfo/MediaInfo.h>
|
|
||||||
#include <MediaInfo/File__Analyse_Automatic.h>
|
|
||||||
|
|
||||||
int CMAObject::ohfi_count = OHFI_OFFSET;
|
int CMAObject::ohfi_count = OHFI_OFFSET;
|
||||||
|
|
||||||
CMAObject::CMAObject(CMAObject *obj_parent) :
|
CMAObject::CMAObject(CMAObject *obj_parent) :
|
||||||
@@ -84,21 +82,9 @@ void CMAObject::loadSfoMetadata(const QString &path)
|
|||||||
|
|
||||||
void CMAObject::loadMusicMetadata(const QString &path)
|
void CMAObject::loadMusicMetadata(const QString &path)
|
||||||
{
|
{
|
||||||
MediaInfoLib::MediaInfo media;
|
AVDecoder decoder;
|
||||||
if(media.Open(path.toStdWString())) {
|
if(decoder.open(path)) {
|
||||||
QString data;
|
decoder.getAudioMetadata(metadata);
|
||||||
data = QString::fromStdWString(media.Get(MediaInfoLib::Stream_General, 0, MediaInfoLib::General_Album));
|
|
||||||
metadata.data.music.album = strdup(!data.isEmpty() ? data.toUtf8().data() : (parent->metadata.name ? parent->metadata.name : ""));
|
|
||||||
data = QString::fromStdWString(media.Get(MediaInfoLib::Stream_General, 0, MediaInfoLib::General_Performer));
|
|
||||||
metadata.data.music.artist = strdup(data.toUtf8().data());
|
|
||||||
data = QString::fromStdWString(media.Get(MediaInfoLib::Stream_General, 0, MediaInfoLib::General_Title));
|
|
||||||
metadata.data.music.title = strdup(!data.isEmpty() ? data.toUtf8().data() : metadata.name);
|
|
||||||
data = QString::fromStdWString(media.Get(MediaInfoLib::Stream_Audio, 0, MediaInfoLib::Audio_BitRate));
|
|
||||||
bool ok;
|
|
||||||
int bitrate = data.toInt(&ok);
|
|
||||||
if(ok) {
|
|
||||||
metadata.data.music.tracks->data.track_audio.bitrate = bitrate;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
metadata.data.music.album = strdup(parent->metadata.name ? parent->metadata.name : "");
|
metadata.data.music.album = strdup(parent->metadata.name ? parent->metadata.name : "");
|
||||||
metadata.data.music.artist = strdup("");
|
metadata.data.music.artist = strdup("");
|
||||||
@@ -108,36 +94,9 @@ void CMAObject::loadMusicMetadata(const QString &path)
|
|||||||
|
|
||||||
void CMAObject::loadVideoMetadata(const QString &path)
|
void CMAObject::loadVideoMetadata(const QString &path)
|
||||||
{
|
{
|
||||||
MediaInfoLib::MediaInfo media;
|
AVDecoder decoder;
|
||||||
if(media.Open(path.toStdWString())) {
|
if(decoder.open(path)) {
|
||||||
bool ok;
|
decoder.getVideoMetadata(metadata);
|
||||||
QString data;
|
|
||||||
data = QString::fromStdWString(media.Get(MediaInfoLib::Stream_General, 0, MediaInfoLib::General_Title));
|
|
||||||
metadata.data.video.title = strdup(!data.isEmpty() ? data.toUtf8().data() : metadata.name);
|
|
||||||
data = QString::fromStdWString(media.Get(MediaInfoLib::Stream_General, 0, MediaInfoLib::General_Comment));
|
|
||||||
metadata.data.video.explanation = strdup(data.toUtf8().data());
|
|
||||||
data = QString::fromStdWString(media.Get(MediaInfoLib::Stream_General, 0, MediaInfoLib::General_Copyright));
|
|
||||||
metadata.data.video.copyright = strdup(data.toUtf8().data());
|
|
||||||
data = QString::fromStdWString(media.Get(MediaInfoLib::Stream_Video, 0, MediaInfoLib::Video_BitRate));
|
|
||||||
int bitrate = data.toInt(&ok);
|
|
||||||
if(ok) {
|
|
||||||
metadata.data.video.tracks->data.track_video.bitrate = bitrate;
|
|
||||||
}
|
|
||||||
data = QString::fromStdWString(media.Get(MediaInfoLib::Stream_Video, 0, MediaInfoLib::Video_Duration));
|
|
||||||
int duration = data.toInt(&ok);
|
|
||||||
if(ok) {
|
|
||||||
metadata.data.video.tracks->data.track_video.duration = duration;
|
|
||||||
}
|
|
||||||
data = QString::fromStdWString(media.Get(MediaInfoLib::Stream_Video, 0, MediaInfoLib::Video_Width));
|
|
||||||
int width = data.toInt(&ok);
|
|
||||||
if(ok) {
|
|
||||||
metadata.data.video.tracks->data.track_video.width = width;
|
|
||||||
}
|
|
||||||
data = QString::fromStdWString(media.Get(MediaInfoLib::Stream_Video, 0, MediaInfoLib::Video_Height));
|
|
||||||
int height = data.toInt(&ok);
|
|
||||||
if(ok) {
|
|
||||||
metadata.data.video.tracks->data.track_video.height = height;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
metadata.data.video.title = strdup(metadata.name);
|
metadata.data.video.title = strdup(metadata.name);
|
||||||
metadata.data.video.explanation = strdup("");
|
metadata.data.video.explanation = strdup("");
|
||||||
@@ -147,21 +106,9 @@ void CMAObject::loadVideoMetadata(const QString &path)
|
|||||||
|
|
||||||
void CMAObject::loadPhotoMetadata(const QString &path)
|
void CMAObject::loadPhotoMetadata(const QString &path)
|
||||||
{
|
{
|
||||||
MediaInfoLib::MediaInfo media;
|
AVDecoder decoder;
|
||||||
if(media.Open(path.toStdWString())) {
|
if(decoder.open(path)) {
|
||||||
bool ok;
|
decoder.getPictureMetadata(metadata);
|
||||||
QString data;
|
|
||||||
data = QString::fromStdWString(media.Get(MediaInfoLib::Stream_General, 0, MediaInfoLib::General_Title));
|
|
||||||
metadata.data.photo.title = strdup(!data.isEmpty() ? data.toUtf8().data() : metadata.name);
|
|
||||||
data = QString::fromStdWString(media.Get(MediaInfoLib::Stream_Image, 0, MediaInfoLib::Image_Height));
|
|
||||||
int height = data.toInt(&ok);
|
|
||||||
if(ok) {
|
|
||||||
metadata.data.photo.tracks->data.track_photo.height = height;
|
|
||||||
}
|
|
||||||
int width = data.toInt(&ok);
|
|
||||||
if(ok) {
|
|
||||||
metadata.data.photo.tracks->data.track_photo.width = width;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
metadata.data.photo.title = strdup(metadata.name);
|
metadata.data.photo.title = strdup(metadata.name);
|
||||||
}
|
}
|
||||||
|
7
qcma.pro
7
qcma.pro
@@ -14,7 +14,6 @@ TARGET = qcma
|
|||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
wirelessworker.cpp \
|
|
||||||
capability.cpp \
|
capability.cpp \
|
||||||
database.cpp \
|
database.cpp \
|
||||||
cmaobject.cpp \
|
cmaobject.cpp \
|
||||||
@@ -30,7 +29,6 @@ SOURCES += main.cpp \
|
|||||||
avdecoder.cpp
|
avdecoder.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
wirelessworker.h \
|
|
||||||
capability.h \
|
capability.h \
|
||||||
database.h \
|
database.h \
|
||||||
cmaobject.h \
|
cmaobject.h \
|
||||||
@@ -46,7 +44,7 @@ HEADERS += \
|
|||||||
avdecoder.h
|
avdecoder.h
|
||||||
|
|
||||||
CONFIG += link_pkgconfig
|
CONFIG += link_pkgconfig
|
||||||
PKGCONFIG += libvitamtp libmediainfo libavformat libavcodec libavutil libswscale
|
PKGCONFIG += libvitamtp libavformat libavcodec libavutil libswscale
|
||||||
|
|
||||||
QMAKE_CXXFLAGS += -Wno-write-strings -Wall
|
QMAKE_CXXFLAGS += -Wno-write-strings -Wall
|
||||||
|
|
||||||
@@ -55,7 +53,8 @@ RESOURCES += \
|
|||||||
|
|
||||||
OTHER_FILES += \
|
OTHER_FILES += \
|
||||||
resources/psp2-updatelist.xml \
|
resources/psp2-updatelist.xml \
|
||||||
resources/psv_icon.png
|
resources/psv_icon.png \
|
||||||
|
README.md
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
configwidget.ui
|
configwidget.ui
|
||||||
|
29
utils.cpp
29
utils.cpp
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "avdecoder.h"
|
||||||
|
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -30,9 +31,6 @@
|
|||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <MediaInfo/MediaInfo.h>
|
|
||||||
#include <MediaInfo/File__Analyse_Automatic.h>
|
|
||||||
|
|
||||||
bool getDiskSpace(const QString &dir, quint64 *free, quint64 *total)
|
bool getDiskSpace(const QString &dir, quint64 *free, quint64 *total)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
@@ -139,24 +137,21 @@ QByteArray getThumbnail(const QString &path, DataType type, metadata_t *metadata
|
|||||||
// TODO: try to load an album cover from one of the audio files.
|
// TODO: try to load an album cover from one of the audio files.
|
||||||
data = findFolderAlbumArt(path, metadata);
|
data = findFolderAlbumArt(path, metadata);
|
||||||
} else {
|
} else {
|
||||||
MediaInfoLib::MediaInfo media;
|
AVDecoder decoder;
|
||||||
|
|
||||||
if(media.Open(path.toStdWString())) {
|
if(decoder.open(path)) {
|
||||||
QString base64 = QString::fromStdWString(media.Get(MediaInfoLib::Stream_General, 0, MediaInfoLib::General_Cover_Data));
|
data = decoder.getAudioThumbnail(256, 256);
|
||||||
QImage img;
|
metadata->data.thumbnail.width = 256;
|
||||||
|
metadata->data.thumbnail.height = 256;
|
||||||
if(base64.size() > 0 && img.loadFromData(QByteArray::fromBase64(base64.toUtf8()))) {
|
|
||||||
QBuffer buffer(&data);
|
|
||||||
buffer.open(QIODevice::WriteOnly);
|
|
||||||
// use smooth transformation for the ambum art since is important to display correctly
|
|
||||||
QImage result = img.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
||||||
result.save(&buffer, "JPEG");
|
|
||||||
metadata->data.thumbnail.width = result.width();
|
|
||||||
metadata->data.thumbnail.height = result.height();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if(MASK_SET(type, Video)) {
|
||||||
|
AVDecoder decoder;
|
||||||
|
if(decoder.open(path)) {
|
||||||
|
data = decoder.getVideoThumbnail(256, 256);
|
||||||
|
metadata->data.thumbnail.width = 256;
|
||||||
|
metadata->data.thumbnail.height = 256;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO: implement thumbnails for videos
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* QCMA: Cross-platform content manager assistant for the PS Vita
|
|
||||||
*
|
|
||||||
* Copyright (C) 2013 Codestation
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "wirelessworker.h"
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
#include <QTime>
|
|
||||||
#include <QHostInfo>
|
|
||||||
|
|
||||||
#define QCMA_REQUEST_PORT 9309
|
|
||||||
|
|
||||||
wireless_host_info_t BroadcastSignal::info = {"00000000-0000-0000-0000-000000000000", "win", NULL, QCMA_REQUEST_PORT};
|
|
||||||
|
|
||||||
BroadcastSignal *BroadcastSignal::this_object = NULL;
|
|
||||||
|
|
||||||
BroadcastSignal::BroadcastSignal(QObject *parent) :
|
|
||||||
BaseWorker(parent)
|
|
||||||
{
|
|
||||||
qsrand(QTime::currentTime().msec());
|
|
||||||
this_object = this;
|
|
||||||
started = false;
|
|
||||||
strcpy(hostname, QHostInfo::localHostName().toStdString().c_str());
|
|
||||||
BroadcastSignal::info.name = hostname;
|
|
||||||
}
|
|
||||||
|
|
||||||
BroadcastSignal::~BroadcastSignal()
|
|
||||||
{
|
|
||||||
VitaMTP_Stop_Broadcast();
|
|
||||||
}
|
|
||||||
|
|
||||||
int BroadcastSignal::deviceRegistered(const char *deviceid)
|
|
||||||
{
|
|
||||||
qDebug("Got connection request from %s", deviceid);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int BroadcastSignal::generatePin(wireless_vita_info_t *info, int *p_err)
|
|
||||||
{
|
|
||||||
qDebug("Registration request from %s (MAC: %s)", info->name, info->mac_addr);
|
|
||||||
int pin = qrand() % 100000000;
|
|
||||||
qDebug("Your registration PIN for %s is: %08d", info->name, pin);
|
|
||||||
*p_err = 0;
|
|
||||||
emit this_object->receivedPin(pin);
|
|
||||||
return pin;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadcastSignal::process()
|
|
||||||
{
|
|
||||||
qDebug() <<"Broadcast thread ID: "<< QThread::currentThreadId();
|
|
||||||
qDebug("Starting CMA wireless broadcast...");
|
|
||||||
|
|
||||||
started = true;
|
|
||||||
if(VitaMTP_Broadcast_Host(&info, 0) < 0) {
|
|
||||||
qCritical( "An error occured during broadcast. Exiting.");
|
|
||||||
} else {
|
|
||||||
qDebug("Broadcast ended.");
|
|
||||||
}
|
|
||||||
qDebug("Broadcast thread end.");
|
|
||||||
emit finished();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadcastSignal::stopBroadcast()
|
|
||||||
{
|
|
||||||
qDebug("Stopping broadcast");
|
|
||||||
VitaMTP_Stop_Broadcast();
|
|
||||||
started = false;
|
|
||||||
}
|
|
@@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* QCMA: Cross-platform content manager assistant for the PS Vita
|
|
||||||
*
|
|
||||||
* Copyright (C) 2013 Codestation
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef WIRELESSWORKER_H
|
|
||||||
#define WIRELESSWORKER_H
|
|
||||||
|
|
||||||
#include "baseworker.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QSemaphore>
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include <vitamtp.h>
|
|
||||||
}
|
|
||||||
|
|
||||||
class BroadcastSignal : public BaseWorker
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit BroadcastSignal(QObject *parent = 0);
|
|
||||||
~BroadcastSignal();
|
|
||||||
|
|
||||||
static int deviceRegistered(const char *deviceid);
|
|
||||||
static int generatePin(wireless_vita_info_t *info, int *p_err);
|
|
||||||
bool isRunning() { return started; }
|
|
||||||
|
|
||||||
static wireless_host_info_t info;
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
volatile bool started;
|
|
||||||
char hostname[256];
|
|
||||||
//used to emit a signal from a static method
|
|
||||||
static BroadcastSignal *this_object;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void receivedPin(int);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void stopBroadcast();
|
|
||||||
|
|
||||||
protected slots:
|
|
||||||
void process();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // WIRELESSWORKER_H
|
|
Reference in New Issue
Block a user