2017-02-25 2 views
-1

私の現在のプロジェクトC++/Qtでは、ビデオをストリーミングするファイルサーバーを作ろうとしています。アプリからChromeに動画をストリーミングすることはできますが、他のプレーヤー(例:VLC)にストリーミングすることはできません。私は他の図書館を使ってみましたが、彼らは働いていますが、私の作品は動かないのです。 ヘッダーに問題があると思います。ここにヘッダがある -ビデオはChromeでストリーミングできますが、他のプレイヤーではストリームできません

HTTP/1.0 200 OK\r\n 
Content-Length: VIDEO-SIZE\r\n 
Content-Type: video/mp4\r\n\r\n 

私も(シーク機能を使用する)部分ビデオサポートのためのサポートを持っており、ここではそれはヘッダだある - 私はQtのC++でアプリケーションを開発しています

HTTP/1.0 200 OK\r\n 
Content-Length: VIDEO-SIZE\r\n 
Content-Type: video/mp4\r\n 
Content-Range: bytes RANGE/VIDEO-SIZE\r\n\r\n 

ネットワークライブラリは、コードは非常に簡単です。基本的には、上記のヘッダーを送信し、次にビデオを送信します。 CPPコードは以下のコード内でQDataStreamを使用しないでください(未丁度良いコード、ちょうど基本案)

QTcpSocket *clientConnection = server->nextPendingConnection(); 
connect(clientConnection, SIGNAL(disconnected()), 
    clientConnection, SLOT(deleteLater())); 
clientConnection->waitForReadyRead(); 

QMap<QString, QString> requestMap; 
while (!clientConnection->atEnd()) { 
    QString line(clientConnection->readLine()); 
    qDebug()<<line; 
    if (line.indexOf(":") <= 0 || line.isEmpty()) 
     continue; 
    line.replace("\r\n", ""); 
    QString key(line.left(line.indexOf(":"))), 
      value(line.mid(line.indexOf(":") + 2, line.length())); 
    requestMap.insert(key, value); 
    qDebug() << "KEY: " << key << " VALUE: " << value << "\n"; 
} 
img->open(QFile::ReadOnly); 
QByteArray block; 
QDataStream out(&block, QIODevice::WriteOnly); 
out.setVersion(QDataStream::Qt_5_8); 
QString header, imgsize(QString::number(img->size())); 
if(requestMap.contains("Range")){ 
    QString range = requestMap["Range"]; 
    range = range.mid(6, range.length()); // 'bytes=' is 6 chars 
    qint64 seek = range.left(range.indexOf("-")).toInt(); 
    if (range.endsWith("-")) 
     range.append(QString::number(img->size() - 1)); 
    header = "HTTP/1.0 206 PARTIAL CONTENT\r\n" 
      "Content-Length: "+imgsize+"\r\n" 
      "Content-Range: bytes "+range+"/"+imgsize + "\r\n" 
      "Content-Type: "+db.mimeTypeForFile(fileinfo).name()+"\r\n\r\n"; 
      img->seek(seek); 
} else header = "HTTP/1.0 200 OK\r\n" 
       "Content-Length: "+imgsize+"\r\n" 
       "Content-Type: "+db.mimeTypeForFile(fileinfo).name()+"\r\n\r\n"; 
out << header.toLatin1(); 
clientConnection->write(block); 
clientConnection->waitForBytesWritten(); 
block.resize(65536); 

while(!img->atEnd()) 
{ 
    qint64 read = img->read(block.data(), 65536); 
    clientConnection->write(block, read); 

} 
+0

で送信してください。 – FadedCoder

答えて

1

です。 QByteArrayを作成し、ヘッダーを追加してclientConnection->write()

関連する問題