Transferring a video file (.mp4) through Ethernet port.
-
@J-Hilk it is also created when the receiveVideo() is called .. it exists until the function returns ..
@Prakash08 no, it's on the heap and you actually never delete it, so it exists forever.
Maybe QVideoWidgets takes ownership of it? I would have to look that up
either way the core issue stays, you're trying to play data that is destroyed as soon as it's created
-
wrote on 16 Apr 2024, 07:20 last edited by
@J-Hilk the main issue is, "Error: failed to seek". this is the message i'm getting. what does this mean? how to solve this ? any idea ?
-
@J-Hilk the main issue is, "Error: failed to seek". this is the message i'm getting. what does this mean? how to solve this ? any idea ?
@Prakash08 said in Transferring a video file (.mp4) through Ethernet port.:
how to solve this ? any idea ?
Fix your code - 4 people told you what's wrong...
-
wrote on 16 Apr 2024, 07:33 last edited by
@Christian-Ehrlicher I'm sorry, I did not get where the issue is, can you please elaborate, which part of code should be modified ?
-
@Prakash08 said in Transferring a video file (.mp4) through Ethernet port.:
// Set the media content of the QMediaPlayer player->setMedia(QMediaContent(), &buffer);
player
is using&buffer
as its buffer. Compare the lifetimes ofplayer
andbuffer
.wrote on 16 Apr 2024, 07:34 last edited by JonB@Christian-Ehrlicher said in Transferring a video file (.mp4) through Ethernet port.:
QBuffer buffer(&received_data);
How long does this object live?
@JonB said in Transferring a video file (.mp4) through Ethernet port.:
player
is using&buffer
as its buffer. Compare the lifetimes ofplayer
andbuffer
. -
@ChrisW67 the video is 5 secs long. And how to give the condition in sender to code to disconnect the connection when its done sending data ..?
wrote on 16 Apr 2024, 08:15 last edited by@Prakash08 said in Transferring a video file (.mp4) through Ethernet port.:
And how to give the condition in sender to code to disconnect the connection when its done sending data ..?
When the sender runs out of file content, or send its entire in-memory buffer, then it should call close() on its socket. Exactly how that looks depends on your sender code.
-
@Prakash08 said in Transferring a video file (.mp4) through Ethernet port.:
And how to give the condition in sender to code to disconnect the connection when its done sending data ..?
When the sender runs out of file content, or send its entire in-memory buffer, then it should call close() on its socket. Exactly how that looks depends on your sender code.
wrote on 16 Apr 2024, 09:39 last edited by@ChrisW67 how to send its in-memory buffer ? And here is the sender code ..
void MainWindow::send_video() { qDebug()<<"Connected to Server:"<<socket->peerAddress()<<" on port:"<<socket->peerPort()<<" name:"<<socket->peerName(); // QFile file("C:/Users/Intel/Pictures/sunset.png"); // Replace with the actual video path QFile file("C:/Users/Intel/Desktop/video_2.mp4"); if (!file.open(QIODevice::ReadOnly)) { qDebug() << "Unable to open file:" << file.errorString(); return; } while (!file.atEnd()) { QByteArray imageData = file.readAll(); // Read data in chunks socket->write(imageData); // Send data to server qDebug()<<" video data .."; } // QByteArray imageData = file.read(16955); // Read data in chunks // socket->write(imageData); qDebug()<<" video data sent.."; file.close(); socket->disconnectFromHost(); }
-
@Christian-Ehrlicher said in Transferring a video file (.mp4) through Ethernet port.:
QBuffer buffer(&received_data);
How long does this object live?
@JonB said in Transferring a video file (.mp4) through Ethernet port.:
player
is using&buffer
as its buffer. Compare the lifetimes ofplayer
andbuffer
. -
@JonB In the provided code , the player and buffer objects are created locally within the receiveVideo() function scope. Their lifetime is limited to the duration of the function execution.
wrote on 16 Apr 2024, 11:18 last edited by@Prakash08
Sorry, but you're wrong. @Christian-Ehrlicher & I have both tried to point this out to you.First of all,
QMediaPlayer *player = new QMediaPlayer
is a pointer to an allocated object on the heap. That means it persists until somethingdelete
s it. The fact thatQMediaPlayer *player
is itself a local variable is neither here nor there, when it goes out of scope that does not destroy the object it points to. That is quite different fromQBuffer buffer(&received_data)
, which is a local stack variable, not a pointer to an object. That does get destroyed at the end of theif
.Secondly,
player->setMedia(QMediaContent(), &buffer)
means thatplayer
is using the stackbuffer
, so as soon as theif
exitsbuffer
is destroyed but theQMediaPlayer
is still using it as its buffer. When you goplayer->play()
at the end that only starts playing the video, it does not finish playing it. It carries on playing after the function exits. But it's reading from a buffer which has now been destroyed. Not good! Lucky it does not "crash". Your "Error:failed to seek" error may be from code trying to access it when it is no longer valid.This is all standard C++ stuff.
17/17