¿Cómo crear un servidor de transmisión HTTP MJPEG con sockets QTcp-Server?

Quiero crear un servidor Http para enviar un flujo MJPEG. Ya puedo enviar una imagen pero no transmisión en vivo.

Lo que hice: creé un servidor TCP. Cuando un cliente se conecta, se crea un TCP-Socket. Luego implementé un SLOT ReadyRead que se ejecuta cuando el navegador envía la solicitud "GET" al servidor.

GET / HTTP/1.1
Host: 127.0.0.1:8889
User-Agent: Mozilla/5.0...

Luego ejecuto el siguiente código

QString inbound = m_Client->readAll();

QByteArray header = "HTTP/1.1 200 OK\r\n";
m_Client->write(header);

QByteArray ContentType = "Content-Type: image/jpeg\r\n\n";
m_Client->write(ContentType);

Mat first_img; //OPENCV Material
m_Stream->read(first_,img); // Read Image from Webcam
QImage img = Mat2QImage(first_img); // Convert to QImage
QByteArray ba; // QByteArray as Buffer for JPG Envoded QImage
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
img.save(&buffer, "JPG");
m_Client->write(ba); // Write The Encoded Image

m_Client->close();

Pensé en crear un bucle para repetir la parte de transmisión de imágenes, pero esto no funciona. El navegador sigue cargando y no pasa nada ...

while(1){
    Mat first_img; //OPENCV Material
    m_Stream->read(first_img); // Read Image from Webcam

    QImage img = Mat2QImage(first_img); // Convert to QImage
    QByteArray ba; // QByteArray as Buffer for JPG Envoded QImage
    QBuffer buffer(&ba);
    buffer.open(QIODevice::WriteOnly);
    img.save(&buffer, "JPG");

    m_Client->write(ba); // Write The Encoded Image

    QThread::usleep(500);
}

¿Qué me estoy perdiendo? ¿La codificación es incorrecta o la forma en que manejo la solicitud? ¿Quizás los tipos mimo?

Actualizar Eché un vistazo a
http://www.damonkohler.com/2010/10/mjpeg-streaming-protocol.html yhttps://en.wikipedia.org/wiki/Motion_JPEG e intenté implementar estos métodos pero sin ningún resultado ...

QString inbound = m_Client->readAll();

QByteArray ContentType = ("HTTP/1.0 200 OK\r\n" \
        "Server: YourServerName\r\n" \
        "Connection: close\r\n" \
        "Max-Age: 0\r\n" \
        "Expires: 0\r\n" \
        "Cache-Control: no-cache, private\r\n" \
        "Pragma: no-cache\r\n" \
        "Content-Type: multipart/x-mixed-replace; " \
        "boundary=--BoundaryString\r\n\r\n");
m_Client->write(ContentType);



while(1){
    Mat first_img; //OPENCV Material
    m_Stream->read(first_img); // Read Image from Webcam

    QImage img = Mat2QImage(first_img); // Convert to QImage
    QByteArray ba; // QByteArray as Buffer for JPG Envoded QImage
    QBuffer buffer(&ba);
    buffer.open(QIODevice::WriteOnly);
    img.save(&buffer, "JPG");

    QByteArray BoundaryString = ("--BoundaryString\r\n" \
                                 "Content-type: image/jpg\r\n\r\n");

    m_Client->write(BoundaryString);
    m_Client->write(ba); // Write The Encoded Image

    QThread::usleep(500);
}

m_Client->close();

Respuestas a la pregunta(1)

Su respuesta a la pregunta