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

fixes, cleanup

This commit is contained in:
krepa098 2014-10-16 15:37:48 +02:00
parent 6e61da68e4
commit bd07666275
6 changed files with 62 additions and 43 deletions

View File

@ -30,25 +30,25 @@ void NetVideoSource::pushFrame(VideoFrame frame)
void NetVideoSource::pushVPXFrame(vpx_image *image)
{
int dw = image->d_w;
int dh = image->d_h;
const int dw = image->d_w;
const int dh = image->d_h;
int bpl = image->stride[VPX_PLANE_Y];
int cxbpl = image->stride[VPX_PLANE_V];
const int bpl = image->stride[VPX_PLANE_Y];
const int cxbpl = image->stride[VPX_PLANE_V];
VideoFrame frame;
frame.frameData.resize(dw * dh * 3); //YUV 24bit
frame.resolution = QSize(dw, dh);
frame.format = VideoFrame::YUV;
uint8_t* yData = image->planes[VPX_PLANE_Y];
uint8_t* uData = image->planes[VPX_PLANE_V];
uint8_t* vData = image->planes[VPX_PLANE_U];
const uint8_t* yData = image->planes[VPX_PLANE_Y];
const uint8_t* uData = image->planes[VPX_PLANE_V];
const uint8_t* vData = image->planes[VPX_PLANE_U];
// convert from planar to packed
for (int x = 0; x < dw; x += 1)
for (int y = 0; y < dh; ++y)
{
for (int y = 0; y < dh; y += 1)
for (int x = 0; x < dw; ++x)
{
uint8_t Y = yData[x + y * bpl];
uint8_t U = uData[x/2 + y/2*cxbpl];
@ -57,7 +57,6 @@ void NetVideoSource::pushVPXFrame(vpx_image *image)
frame.frameData.data()[dw * 3 * y + x * 3 + 0] = Y;
frame.frameData.data()[dw * 3 * y + x * 3 + 1] = U;
frame.frameData.data()[dw * 3 * y + x * 3 + 2] = V;
}
}

View File

@ -84,36 +84,30 @@ vpx_image Camera::getLastVPXImage()
return img;
}
int w = currFrame.resolution.width();
int h = currFrame.resolution.height();
const int w = currFrame.resolution.width();
const int h = currFrame.resolution.height();
// I420 "It comprises an NxM Y plane followed by (N/2)x(M/2) V and U planes."
// http://fourcc.org/yuv.php#IYUV
vpx_img_alloc(&img, VPX_IMG_FMT_VPXI420, w, h, 1);
for (int x = 0; x < w; x += 2)
for (int y = 0; y < h; ++y)
{
for (int y = 0; y < h; y += 2)
for (int x = 0; x < w; ++x)
{
QRgb p1 = currFrame.getPixel(x, y);
QRgb p2 = currFrame.getPixel(x + 1, y);
QRgb p3 = currFrame.getPixel(x, y + 1);
QRgb p4 = currFrame.getPixel(x + 1, y + 1);
u_int8_t b = currFrame.frameData.data()[(x + y * w) * 3 + 0];
u_int8_t g = currFrame.frameData.data()[(x + y * w) * 3 + 1];
u_int8_t r = currFrame.frameData.data()[(x + y * w) * 3 + 2];
img.planes[VPX_PLANE_Y][x + y * w] = ((66 * qRed(p1) + 129 * qGreen(p1) + 25 * qBlue(p1)) >> 8) + 16;
img.planes[VPX_PLANE_Y][x + 1 + y * w] = ((66 * qRed(p2) + 129 * qGreen(p2) + 25 * qBlue(p2)) >> 8) + 16;
img.planes[VPX_PLANE_Y][x + (y + 1) * w] = ((66 * qRed(p3) + 129 * qGreen(p3) + 25 * qBlue(p3)) >> 8) + 16;
img.planes[VPX_PLANE_Y][x + 1 + (y + 1) * w] = ((66 * qRed(p4) + 129 * qGreen(p4) + 25 * qBlue(p4)) >> 8) + 16;
img.planes[VPX_PLANE_Y][x + y * img.stride[VPX_PLANE_Y]] = ((66 * r + 129 * g + 25 * b) >> 8) + 16;
if (!(x % 2) && !(y % 2))
{
// TODO: consider p1 to p4?
const int i = x / 2;
const int j = y / 2;
int i = x / 2;
int j = y / 2;
img.planes[VPX_PLANE_U][i + j * w / 2] = ((112 * qRed(p1) + -94 * qGreen(p1) + -18 * qBlue(p1)) >> 8) + 128;
img.planes[VPX_PLANE_V][i + j * w / 2] = ((-38 * qRed(p1) + -74 * qGreen(p1) + 112 * qBlue(p1)) >> 8) + 128;
img.planes[VPX_PLANE_U][i + j * img.stride[VPX_PLANE_U]] = ((112 * r + -94 * g + -18 * b) >> 8) + 128;
img.planes[VPX_PLANE_V][i + j * img.stride[VPX_PLANE_V]] = ((-38 * r + -74 * g + 112 * b) >> 8) + 128;
}
}
}

View File

@ -228,7 +228,8 @@ void ChatForm::onAvStart(int FriendId, int CallId, bool video)
videoButton->setObjectName("red");
videoButton->style()->polish(videoButton);
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
netcam->show();
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
}
else
{
@ -256,7 +257,7 @@ void ChatForm::onAvCancel(int FriendId, int)
videoButton->style()->polish(videoButton);
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
netcam->setSource(nullptr);
netcam->hide();
}
@ -276,7 +277,7 @@ void ChatForm::onAvEnd(int FriendId, int)
videoButton->style()->polish(videoButton);
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
netcam->setSource(nullptr);
netcam->hide();
}
@ -306,7 +307,7 @@ void ChatForm::onAvRinging(int FriendId, int CallId, bool video)
}
}
void ChatForm::onAvStarting(int FriendId, int callId, bool video)
void ChatForm::onAvStarting(int FriendId, int CallId, bool video)
{
if (FriendId != f->friendId)
return;
@ -320,8 +321,8 @@ void ChatForm::onAvStarting(int FriendId, int callId, bool video)
videoButton->setObjectName("red");
videoButton->style()->polish(videoButton);
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
netcam->setSource(Core::getInstance()->getVideoSourceFromCall(callId));
netcam->show();
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
}
else
{
@ -351,6 +352,7 @@ void ChatForm::onAvEnding(int FriendId, int)
videoButton->disconnect();
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
netcam->hide();
}
@ -372,7 +374,7 @@ void ChatForm::onAvRequestTimeout(int FriendId, int)
videoButton->disconnect();
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
netcam->setSource(nullptr);
netcam->hide();
}
@ -394,19 +396,20 @@ void ChatForm::onAvPeerTimeout(int FriendId, int)
videoButton->disconnect();
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
netcam->setSource(nullptr);
netcam->hide();
}
void ChatForm::onAvMediaChange(int, int, bool video)
void ChatForm::onAvMediaChange(int FriendId, int CallId, bool video)
{
Q_UNUSED(FriendId)
if (video)
{
netcam->show();
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
}
else
{
netcam->setSource(nullptr);
netcam->hide();
}
}
@ -456,7 +459,7 @@ void ChatForm::onCancelCallTriggered()
videoButton->disconnect();
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
netcam->setSource(nullptr);
netcam->hide();
emit cancelCall(callId, f->friendId);
}

View File

@ -50,7 +50,7 @@ public slots:
void onAvCancel(int FriendId, int CallId);
void onAvEnd(int FriendId, int CallId);
void onAvRinging(int FriendId, int CallId, bool video);
void onAvStarting(int FriendId, int callId, bool video);
void onAvStarting(int FriendId, int CallId, bool video);
void onAvEnding(int FriendId, int CallId);
void onAvRequestTimeout(int FriendId, int CallId);
void onAvPeerTimeout(int FriendId, int CallId);

View File

@ -22,7 +22,7 @@
NetCamView::NetCamView(QWidget* parent)
: QWidget(parent)
, mainLayout{new QHBoxLayout()}
, mainLayout(new QHBoxLayout())
{
setLayout(mainLayout);
setWindowTitle("Tox video");
@ -33,7 +33,27 @@ NetCamView::NetCamView(QWidget* parent)
mainLayout->addWidget(videoSurface);
}
void NetCamView::show(VideoSource *source, const QString &title)
{
setSource(source);
setTitle(title);
QWidget::show();
}
void NetCamView::hide()
{
setSource(nullptr);
QWidget::hide();
}
void NetCamView::setSource(VideoSource *s)
{
videoSurface->setSource(s);
}
void NetCamView::setTitle(const QString &title)
{
setWindowTitle(title);
}

View File

@ -31,8 +31,11 @@ class NetCamView : public QWidget
public:
NetCamView(QWidget *parent=0);
public slots:
virtual void show(VideoSource* source, const QString& title);
virtual void hide();
void setSource(VideoSource* s);
void setTitle(const QString& title);
private:
QHBoxLayout* mainLayout;