title: Qt: pass a lot of data between many threads with minimum delay
body: <p>My aim is to create a video player that uses encoded (and optionally encrypted) still images. My main thread creates the following three classes:</p>
  
  <p>player_class: image requests are sent out via a signal every 40-50ms.</p>
  
  <p>extract_frames_class: extract encoded and encrypted content from wrapper.</p>
  
  <p>handle_frames_class: the class creates an additional 30 decoding threads and stores them in an array. the class then receives the frame request and passes it on the the extract_frames_class. After getting the extracted data it checks which decoding thread is currently idle, and passes on the data to the decoder. as soon as the decoder is finished, the signal (containing the image) is sent via the handle_frames class back to the player.</p>
  
  <p>This approach works out fairly well. I get ~20 fps, which is ok. The goal being a steady 25. Unfortunately sending large QByteArrays (containing encoded data) and QImages seems to create additional delays. My new idea was the following:</p>
  
  <p>Why not create a class that containes all information that can/will be passed around among the threads, store an instance for every frame to be decoded in the player_class and send a reference or a pointer to the threads instead of passing the data itself?</p>
  
  <pre><code>class request: public QObject {
      Q_OBJECT
  public:
      int type; // 1 = request, 2 = response, 3 = kill processes
      QImage img; // decoded image
      QByteArray rawData; // extracted raw data of image to be decoded
      qint64 frameNr; // frame number in image sequence
      int decode_wait; // time to wait between decoding request.
      int decode_total = 1; // nr of images to decode
      int decode_time; // time took decoding images
      int decode_layer; // layer n of image to decode
  };
  </code></pre>
  
  <p>My class instance is created and sent out:</p>
  
  <pre><code>requests[i] =  new request();
  requests[i]-&gt;frameNr = decoding_frame;
  requests[i]-&gt;decode_layer = decode_layer;
  emit getFrames(requests[i]); // send out request
  </code></pre>
  
  <p>Here are my connect statements:</p>
  
  <pre><code>connect(player_class, SIGNAL(getFrames(request*)), extract_frames_class, SLOT(slotFrameExtractRequests(request*)));
  
  connect(extract_frames_class, SIGNAL(sendRawData(request*)), handle_frames_class, SLOT(slotRawData(request*)));
  
  connect(handle_frames_class, SIGNAL(sendImage(request*)), player_class, SLOT(receiveDecodedImage(request*)), Qt::DirectConnection);
  </code></pre>
  
  <p>As soon as the decoded data returns, the instance is deleted. The approach kind of works, but decoding slows down to around 1fps. Does someone know how come?</p>
  
  <p>Using the statement to pass custom classes according to qt documentation  <code>qRegisterMetaType&lt;request&gt;("request");</code> before creating the class instances in the main thread resulted in a compilation error.</p>
  
  <p>Tips on how to solve this issue are very much appreciated!</p>