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