mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fixes, cleanup
This commit is contained in:
parent
6e61da68e4
commit
bd07666275
|
@ -30,25 +30,25 @@ void NetVideoSource::pushFrame(VideoFrame frame)
|
||||||
|
|
||||||
void NetVideoSource::pushVPXFrame(vpx_image *image)
|
void NetVideoSource::pushVPXFrame(vpx_image *image)
|
||||||
{
|
{
|
||||||
int dw = image->d_w;
|
const int dw = image->d_w;
|
||||||
int dh = image->d_h;
|
const int dh = image->d_h;
|
||||||
|
|
||||||
int bpl = image->stride[VPX_PLANE_Y];
|
const int bpl = image->stride[VPX_PLANE_Y];
|
||||||
int cxbpl = image->stride[VPX_PLANE_V];
|
const int cxbpl = image->stride[VPX_PLANE_V];
|
||||||
|
|
||||||
VideoFrame frame;
|
VideoFrame frame;
|
||||||
frame.frameData.resize(dw * dh * 3); //YUV 24bit
|
frame.frameData.resize(dw * dh * 3); //YUV 24bit
|
||||||
frame.resolution = QSize(dw, dh);
|
frame.resolution = QSize(dw, dh);
|
||||||
frame.format = VideoFrame::YUV;
|
frame.format = VideoFrame::YUV;
|
||||||
|
|
||||||
uint8_t* yData = image->planes[VPX_PLANE_Y];
|
const uint8_t* yData = image->planes[VPX_PLANE_Y];
|
||||||
uint8_t* uData = image->planes[VPX_PLANE_V];
|
const uint8_t* uData = image->planes[VPX_PLANE_V];
|
||||||
uint8_t* vData = image->planes[VPX_PLANE_U];
|
const uint8_t* vData = image->planes[VPX_PLANE_U];
|
||||||
|
|
||||||
// convert from planar to packed
|
// 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 Y = yData[x + y * bpl];
|
||||||
uint8_t U = uData[x/2 + y/2*cxbpl];
|
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 + 0] = Y;
|
||||||
frame.frameData.data()[dw * 3 * y + x * 3 + 1] = U;
|
frame.frameData.data()[dw * 3 * y + x * 3 + 1] = U;
|
||||||
frame.frameData.data()[dw * 3 * y + x * 3 + 2] = V;
|
frame.frameData.data()[dw * 3 * y + x * 3 + 2] = V;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,36 +84,30 @@ vpx_image Camera::getLastVPXImage()
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
int w = currFrame.resolution.width();
|
const int w = currFrame.resolution.width();
|
||||||
int h = currFrame.resolution.height();
|
const int h = currFrame.resolution.height();
|
||||||
|
|
||||||
// I420 "It comprises an NxM Y plane followed by (N/2)x(M/2) V and U planes."
|
// I420 "It comprises an NxM Y plane followed by (N/2)x(M/2) V and U planes."
|
||||||
// http://fourcc.org/yuv.php#IYUV
|
// http://fourcc.org/yuv.php#IYUV
|
||||||
vpx_img_alloc(&img, VPX_IMG_FMT_VPXI420, w, h, 1);
|
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);
|
u_int8_t b = currFrame.frameData.data()[(x + y * w) * 3 + 0];
|
||||||
QRgb p2 = currFrame.getPixel(x + 1, y);
|
u_int8_t g = currFrame.frameData.data()[(x + y * w) * 3 + 1];
|
||||||
QRgb p3 = currFrame.getPixel(x, y + 1);
|
u_int8_t r = currFrame.frameData.data()[(x + y * w) * 3 + 2];
|
||||||
QRgb p4 = currFrame.getPixel(x + 1, y + 1);
|
|
||||||
|
|
||||||
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 + y * img.stride[VPX_PLANE_Y]] = ((66 * r + 129 * g + 25 * b) >> 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;
|
|
||||||
|
|
||||||
if (!(x % 2) && !(y % 2))
|
if (!(x % 2) && !(y % 2))
|
||||||
{
|
{
|
||||||
// TODO: consider p1 to p4?
|
const int i = x / 2;
|
||||||
|
const int j = y / 2;
|
||||||
|
|
||||||
int i = x / 2;
|
img.planes[VPX_PLANE_U][i + j * img.stride[VPX_PLANE_U]] = ((112 * r + -94 * g + -18 * b) >> 8) + 128;
|
||||||
int j = y / 2;
|
img.planes[VPX_PLANE_V][i + j * img.stride[VPX_PLANE_V]] = ((-38 * r + -74 * g + 112 * b) >> 8) + 128;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,7 +228,8 @@ void ChatForm::onAvStart(int FriendId, int CallId, bool video)
|
||||||
videoButton->setObjectName("red");
|
videoButton->setObjectName("red");
|
||||||
videoButton->style()->polish(videoButton);
|
videoButton->style()->polish(videoButton);
|
||||||
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
|
||||||
netcam->show();
|
|
||||||
|
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -256,7 +257,7 @@ void ChatForm::onAvCancel(int FriendId, int)
|
||||||
videoButton->style()->polish(videoButton);
|
videoButton->style()->polish(videoButton);
|
||||||
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
||||||
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
||||||
netcam->setSource(nullptr);
|
|
||||||
netcam->hide();
|
netcam->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +277,7 @@ void ChatForm::onAvEnd(int FriendId, int)
|
||||||
videoButton->style()->polish(videoButton);
|
videoButton->style()->polish(videoButton);
|
||||||
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
||||||
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
||||||
netcam->setSource(nullptr);
|
|
||||||
netcam->hide();
|
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)
|
if (FriendId != f->friendId)
|
||||||
return;
|
return;
|
||||||
|
@ -320,8 +321,8 @@ void ChatForm::onAvStarting(int FriendId, int callId, bool video)
|
||||||
videoButton->setObjectName("red");
|
videoButton->setObjectName("red");
|
||||||
videoButton->style()->polish(videoButton);
|
videoButton->style()->polish(videoButton);
|
||||||
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
|
||||||
netcam->setSource(Core::getInstance()->getVideoSourceFromCall(callId));
|
|
||||||
netcam->show();
|
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -351,6 +352,7 @@ void ChatForm::onAvEnding(int FriendId, int)
|
||||||
videoButton->disconnect();
|
videoButton->disconnect();
|
||||||
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
||||||
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
||||||
|
|
||||||
netcam->hide();
|
netcam->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,7 +374,7 @@ void ChatForm::onAvRequestTimeout(int FriendId, int)
|
||||||
videoButton->disconnect();
|
videoButton->disconnect();
|
||||||
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
||||||
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
||||||
netcam->setSource(nullptr);
|
|
||||||
netcam->hide();
|
netcam->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,19 +396,20 @@ void ChatForm::onAvPeerTimeout(int FriendId, int)
|
||||||
videoButton->disconnect();
|
videoButton->disconnect();
|
||||||
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
||||||
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
||||||
netcam->setSource(nullptr);
|
|
||||||
netcam->hide();
|
netcam->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onAvMediaChange(int, int, bool video)
|
void ChatForm::onAvMediaChange(int FriendId, int CallId, bool video)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(FriendId)
|
||||||
|
|
||||||
if (video)
|
if (video)
|
||||||
{
|
{
|
||||||
netcam->show();
|
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
netcam->setSource(nullptr);
|
|
||||||
netcam->hide();
|
netcam->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -456,7 +459,7 @@ void ChatForm::onCancelCallTriggered()
|
||||||
videoButton->disconnect();
|
videoButton->disconnect();
|
||||||
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
||||||
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
||||||
netcam->setSource(nullptr);
|
|
||||||
netcam->hide();
|
netcam->hide();
|
||||||
emit cancelCall(callId, f->friendId);
|
emit cancelCall(callId, f->friendId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public slots:
|
||||||
void onAvCancel(int FriendId, int CallId);
|
void onAvCancel(int FriendId, int CallId);
|
||||||
void onAvEnd(int FriendId, int CallId);
|
void onAvEnd(int FriendId, int CallId);
|
||||||
void onAvRinging(int FriendId, int CallId, bool video);
|
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 onAvEnding(int FriendId, int CallId);
|
||||||
void onAvRequestTimeout(int FriendId, int CallId);
|
void onAvRequestTimeout(int FriendId, int CallId);
|
||||||
void onAvPeerTimeout(int FriendId, int CallId);
|
void onAvPeerTimeout(int FriendId, int CallId);
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
NetCamView::NetCamView(QWidget* parent)
|
NetCamView::NetCamView(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, mainLayout{new QHBoxLayout()}
|
, mainLayout(new QHBoxLayout())
|
||||||
{
|
{
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
setWindowTitle("Tox video");
|
setWindowTitle("Tox video");
|
||||||
|
@ -33,7 +33,27 @@ NetCamView::NetCamView(QWidget* parent)
|
||||||
mainLayout->addWidget(videoSurface);
|
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)
|
void NetCamView::setSource(VideoSource *s)
|
||||||
{
|
{
|
||||||
videoSurface->setSource(s);
|
videoSurface->setSource(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetCamView::setTitle(const QString &title)
|
||||||
|
{
|
||||||
|
setWindowTitle(title);
|
||||||
|
}
|
||||||
|
|
|
@ -31,8 +31,11 @@ class NetCamView : public QWidget
|
||||||
public:
|
public:
|
||||||
NetCamView(QWidget *parent=0);
|
NetCamView(QWidget *parent=0);
|
||||||
|
|
||||||
public slots:
|
virtual void show(VideoSource* source, const QString& title);
|
||||||
|
virtual void hide();
|
||||||
|
|
||||||
void setSource(VideoSource* s);
|
void setSource(VideoSource* s);
|
||||||
|
void setTitle(const QString& title);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHBoxLayout* mainLayout;
|
QHBoxLayout* mainLayout;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user