1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Fix video sending

This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-07-12 12:50:40 +02:00
parent 2af720877f
commit 457a54d591
5 changed files with 24 additions and 12 deletions

View File

@ -33,10 +33,14 @@ const QString Core::CONFIG_FILE_NAME = "data";
QList<ToxFile> Core::fileSendQueue;
QList<ToxFile> Core::fileRecvQueue;
ToxCall Core::calls[TOXAV_MAX_CALLS];
const int Core::videobufsize{TOXAV_MAX_VIDEO_WIDTH * TOXAV_MAX_VIDEO_HEIGHT * 4};
uint8_t* Core::videobuf;
Core::Core(Camera* cam, QThread *coreThread) :
tox(nullptr), camera(cam)
{
videobuf = new uint8_t[videobufsize];
toxTimer = new QTimer(this);
toxTimer->setSingleShot(true);
//saveTimer = new QTimer(this);
@ -70,6 +74,12 @@ Core::~Core()
toxav_kill(toxav);
tox_kill(tox);
}
if (videobuf)
{
delete[] videobuf;
videobuf=nullptr;
}
}
void Core::start()
@ -1171,8 +1181,8 @@ void Core::prepareCall(int friendId, int callId, ToxAv* toxav, bool videoEnabled
calls[callId].callId = callId;
calls[callId].friendId = friendId;
calls[callId].codecSettings = av_DefaultSettings;
calls[callId].codecSettings.max_video_width = TOXAV_VIDEO_WIDTH;
calls[callId].codecSettings.max_video_height = TOXAV_VIDEO_HEIGHT;
calls[callId].codecSettings.max_video_width = TOXAV_MAX_VIDEO_WIDTH;
calls[callId].codecSettings.max_video_height = TOXAV_MAX_VIDEO_HEIGHT;
calls[callId].videoEnabled = videoEnabled;
toxav_prepare_transmission(toxav, callId, &calls[callId].codecSettings, videoEnabled);
@ -1316,15 +1326,14 @@ void Core::sendCallVideo(int callId)
if (!calls[callId].active || !calls[callId].videoEnabled)
return;
static const int bufsize = TOXAV_MAX_VIDEO_WIDTH * TOXAV_MAX_VIDEO_HEIGHT * 4;
static uint8_t* videobuf = new uint8_t[bufsize];
vpx_image frame = camera->getLastVPXImage();
if (frame.w && frame.h)
{
int result;
if((result = toxav_prepare_video_frame(toxav, callId, videobuf, bufsize, &frame)) < 0)
if((result = toxav_prepare_video_frame(toxav, callId, videobuf, videobufsize, &frame)) < 0)
{
qDebug() << QString("Core: toxav_prepare_video_frame: error %1").arg(result);
vpx_img_free(&frame);
calls[callId].sendVideoTimer->start();
return;
}
@ -1332,9 +1341,7 @@ void Core::sendCallVideo(int callId)
if((result = toxav_send_video(toxav, callId, (uint8_t*)videobuf, result)) < 0)
qDebug() << QString("Core: toxav_send_video error: %1").arg(result);
emit Widget::getInstance()->getCore()->videoFrameReceived(frame);
vpx_img_free(&frame);
}
else
qDebug("Core::sendCallVideo: Invalid frame (bad camera ?)");

4
core.h
View File

@ -44,8 +44,6 @@
// TODO: Put that in the settings
#define TOXAV_MAX_VIDEO_WIDTH 1600
#define TOXAV_MAX_VIDEO_HEIGHT 1200
#define TOXAV_VIDEO_WIDTH 640
#define TOXAV_VIDEO_HEIGHT 480
class Camera;
@ -289,6 +287,8 @@ private:
static ToxCall calls[TOXAV_MAX_CALLS];
static const QString CONFIG_FILE_NAME;
static const int videobufsize;
static uint8_t* videobuf;
};
#endif // CORE_HPP

View File

@ -231,6 +231,7 @@ QImage Camera::getLastImage()
vpx_image Camera::getLastVPXImage()
{
vpx_image img;
img.w = img.h = 0;
if (!lastFrame.isValid())
return img;
if (!lastFrame.map(QAbstractVideoBuffer::ReadOnly))

View File

@ -32,6 +32,10 @@ NetCamView::NetCamView(QWidget* parent)
void NetCamView::updateDisplay(vpx_image frame)
{
int w = frame.d_w, h = frame.d_h;
if (!frame.w || !frame.h || !w || !h)
return;
int bpl = frame.stride[VPX_PLANE_Y], cxbpl = frame.stride[VPX_PLANE_V];
QImage img(w, h, QImage::Format_RGB32);
@ -55,6 +59,6 @@ void NetCamView::updateDisplay(vpx_image frame)
}
}
lastFrame = img;
vpx_img_free(&frame);
displayLabel->setPixmap(QPixmap::fromImage(img));
}

View File

@ -22,7 +22,7 @@
VideoSurface::VideoSurface()
: QAbstractVideoSurface()
{
vpx_img_alloc(&input, VPX_IMG_FMT_YV12, TOXAV_VIDEO_WIDTH, TOXAV_VIDEO_HEIGHT, 1);
vpx_img_alloc(&input, VPX_IMG_FMT_YV12, TOXAV_MAX_VIDEO_WIDTH, TOXAV_MAX_VIDEO_HEIGHT, 1);
}
bool VideoSurface::start(const QVideoSurfaceFormat &format)