c++ - Playback custom stream with QMediaPlayer -


i searched thoroughly find answer problem no other post has been helpful far. developing application in qt need playback video stream received through custom protocol. found myself trying in every possible way feed these packets in qmediaplayer no success. idea write incoming packets in qbuffer , read them qmediaplayer. follows trial:

/// videoplayer.h class videoplayer : public qwidget { public slots:     void play();     void handlepacket(qbytearray);     [...]  private:     qmediaplayer mediaplayer;     qbuffer      buffer; };  /// videoplayer.cpp videoplayer::videoplayer(qwidget *parent) : qwidget(parent) , mediaplayer(0, (qmediaplayer::streamplayback)) {     buffer.open(qbuffer::readwrite); }  void videoplayer::handlepacket(qbytearray packet) {     buffer.buffer().append(packet); }  void videoplayer::play() {     mediaplayer.setmedia(qmediacontent(), &buffer);     mediaplayer.play(); } 

with above qmediaplayer plays data in buffer @ moment of calling mediaplayer.setmedia(qmediacontent(), &buffer) seems ignore new packets appended buffer. may because accessing internal qbytearray directly (i checked qiodevice::readyread signal emitted , is)? found no way make qmediaplayer play new incoming data other calling setmedia again. there way notify qmediaplayer media length has changed?

is there easier way make this? thought writing own qiodevice or somehow integrate packet receiver in qt framework provide custom stream qmediacontent?

are there other libraries or methods allow me accomplish task?

i using qt 5.4. in advance help.

my answer not real answer, sharing experience , research results. focused on audio part of stream.

i'm working kind of same issue. have custom protocol contains 1 encoded image , 1 encoded audio portion within 1 incoming [from network] data frame. need handle image , audio separately:

  • decode image , send raw rgb data process display (lol nevermind)
  • play audio portion whatever way

main: i can use qt library. because libvlc [which use right these things] buffering audio/video , didn't found way disable , play stream in real-time. should note incoming stream video camera need play real-time possible.

during quick research, i've found way plays something:

// init method {     // ...     mplayer = new qmediaplayer(this, qmediaplayer::streamplayback);     mbuffer = new qbuffer(this);     mbuffer->open(qiodevice::readwrite);     // ... }  // trying play audio portion void mycoolplayer::handleframeaudio(const qbytearray &audioblob) {     mbuffer->seek(0);     mbuffer->write(audioblob);     mbuffer->seek(0);     mplayer->setmedia(qmediacontent(), mbuffer);     mplayer->play(); } 

this plays distorted sound @ least plays something.

also, if have audio/video decoder, can use:

  • qpainter::drawimage draw decoded rgb image data on empty widget
  • qaudiooutput plays decoded pcm audio data

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -