still working on video
This commit is contained in:
parent
252d462309
commit
0fc3c02a52
@ -435,36 +435,32 @@ private slots:
|
|||||||
if (!m_camera_timer) {
|
if (!m_camera_timer) {
|
||||||
m_camera_timer = new QTimer(this);
|
m_camera_timer = new QTimer(this);
|
||||||
connect(m_camera_timer, &QTimer::timeout, this, [this]() {
|
connect(m_camera_timer, &QTimer::timeout, this, [this]() {
|
||||||
// Create a test video frame showing camera is active
|
// Create a simple animated test pattern
|
||||||
QPixmap pixmap(640, 480);
|
QPixmap pixmap(640, 480);
|
||||||
pixmap.fill(Qt::black);
|
pixmap.fill(Qt::black);
|
||||||
|
|
||||||
// Draw a simple pattern to show camera is working
|
|
||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
painter.fillRect(pixmap.rect(), QColor(30, 30, 30));
|
painter.fillRect(pixmap.rect(), QColor(20, 20, 40));
|
||||||
painter.setPen(QPen(Qt::green, 2));
|
painter.setPen(QPen(Qt::green, 2));
|
||||||
painter.drawRect(10, 10, pixmap.width()-20, pixmap.height()-20);
|
painter.drawRect(10, 10, pixmap.width()-20, pixmap.height()-20);
|
||||||
painter.setPen(QPen(Qt::white));
|
painter.setPen(QPen(Qt::white));
|
||||||
painter.setFont(QFont("Arial", 16));
|
painter.setFont(QFont("Arial", 14));
|
||||||
painter.drawText(pixmap.rect(), Qt::AlignCenter,
|
|
||||||
QString("Camera: %1\n[%2]").arg(camera_info_label->text()).arg(
|
int frame_num = (++m_frame_counter) / 10;
|
||||||
QTime::currentTime().toString("hh:mm:ss")));
|
QString text = QString("● Camera Active\n%1\n[%2]")
|
||||||
|
.arg(camera_info_label->text())
|
||||||
|
.arg(QTime::currentTime().toString("hh:mm:ss"));
|
||||||
|
painter.drawText(pixmap.rect(), Qt::AlignCenter, text);
|
||||||
painter.end();
|
painter.end();
|
||||||
|
|
||||||
local_video_label->setPixmap(pixmap);
|
local_video_label->setPixmap(pixmap);
|
||||||
|
|
||||||
// Send frame data to server
|
// Send simple video frame notification (not actual video data)
|
||||||
if (socket && socket->state() == QSslSocket::ConnectedState) {
|
if (socket && socket->state() == QSslSocket::ConnectedState && frame_num % 3 == 0) {
|
||||||
// Encode pixmap as base64 and send as VIDEO_FRAME message
|
socket->write("FRAME_UPDATE\n");
|
||||||
QByteArray buffer;
|
|
||||||
QDataStream stream(&buffer, QIODevice::WriteOnly);
|
|
||||||
stream << pixmap.toImage();
|
|
||||||
QString frame_data = QString::fromUtf8(buffer.toBase64());
|
|
||||||
QString msg = QString("VIDEO_FRAME:%1\n").arg(frame_data);
|
|
||||||
socket->write(msg.toUtf8());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
m_camera_timer->start(100); // 10 FPS for video frames
|
m_camera_timer->start(100); // 10 FPS for animation
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socket->state() == QSslSocket::ConnectedState) {
|
if (socket->state() == QSslSocket::ConnectedState) {
|
||||||
@ -556,26 +552,22 @@ private slots:
|
|||||||
add_remote_user(username, false);
|
add_remote_user(username, false);
|
||||||
chat_display->append("[System] " + username + " disabled their camera");
|
chat_display->append("[System] " + username + " disabled their camera");
|
||||||
} else if (message.startsWith("VIDEO_FRAME:")) {
|
} else if (message.startsWith("VIDEO_FRAME:")) {
|
||||||
// Parse video frame message: VIDEO_FRAME:username:data
|
// Video frame data - placeholder for actual video
|
||||||
int second_colon = message.indexOf(':', 12);
|
// For now, just confirm video is being sent
|
||||||
if (second_colon > 12) {
|
} else if (message.startsWith("FRAME_UPDATE")) {
|
||||||
QString username = message.mid(12, second_colon - 12);
|
// Animate remote user video feeds
|
||||||
QString frame_data = message.mid(second_colon + 1);
|
for (auto &pair : remote_users) {
|
||||||
|
VideoFeedWidget *widget = pair.second;
|
||||||
// Decode base64 image data
|
// Create animated test pattern
|
||||||
QByteArray buffer = QByteArray::fromBase64(frame_data.toUtf8());
|
QPixmap pixmap(320, 240);
|
||||||
if (!buffer.isEmpty()) {
|
pixmap.fill(QColor(40, 40, 60));
|
||||||
QDataStream stream(&buffer, QIODevice::ReadOnly);
|
QPainter p(&pixmap);
|
||||||
QImage image;
|
p.setPen(QPen(Qt::cyan, 1));
|
||||||
stream >> image;
|
for (int i = 0; i < 10; i++) {
|
||||||
|
p.drawRect(5 + i*2, 5 + i*2, pixmap.width()-10-i*4, pixmap.height()-10-i*4);
|
||||||
if (!image.isNull()) {
|
|
||||||
QPixmap pixmap = QPixmap::fromImage(image);
|
|
||||||
if (remote_users.find(username) != remote_users.end()) {
|
|
||||||
remote_users[username]->update_video_frame(pixmap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
p.end();
|
||||||
|
widget->update_video_frame(pixmap);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Regular chat message
|
// Regular chat message
|
||||||
@ -679,6 +671,7 @@ private:
|
|||||||
// Camera
|
// Camera
|
||||||
QCamera *m_camera;
|
QCamera *m_camera;
|
||||||
QTimer *m_camera_timer;
|
QTimer *m_camera_timer;
|
||||||
|
int m_frame_counter = 0;
|
||||||
|
|
||||||
// Connection
|
// Connection
|
||||||
QSslSocket *socket;
|
QSslSocket *socket;
|
||||||
|
|||||||
@ -165,6 +165,10 @@ void handle_client(SSL *ssl, int client_socket) {
|
|||||||
std::cout << "User " << nickname << " disabled camera" << std::endl;
|
std::cout << "User " << nickname << " disabled camera" << std::endl;
|
||||||
std::string broadcast_msg = "USER_CAMERA_OFF:" + nickname + "\n";
|
std::string broadcast_msg = "USER_CAMERA_OFF:" + nickname + "\n";
|
||||||
broadcast_message(broadcast_msg, ssl);
|
broadcast_message(broadcast_msg, ssl);
|
||||||
|
} else if (msg_str.find("FRAME_UPDATE") != std::string::npos) {
|
||||||
|
// Forward frame update notification to all clients
|
||||||
|
std::string broadcast_msg = "FRAME_UPDATE\n";
|
||||||
|
broadcast_message(broadcast_msg, ssl);
|
||||||
} else if (msg_str.find("VIDEO_FRAME:") != std::string::npos) {
|
} else if (msg_str.find("VIDEO_FRAME:") != std::string::npos) {
|
||||||
// Forward video frames with username prefix
|
// Forward video frames with username prefix
|
||||||
std::string broadcast_msg = "VIDEO_FRAME:" + nickname + ":" + msg_str.substr(12) + "\n";
|
std::string broadcast_msg = "VIDEO_FRAME:" + nickname + ":" + msg_str.substr(12) + "\n";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user