Add a sub to the client/server test and fix an exposed bug.
[dcpomatic.git] / src / lib / server.cc
index 28236e3e04804e39ccab9b5167e7d2de7101f193..d40325db0055b7350c8bb04e8df5ca2f25a9200f 100644 (file)
@@ -33,6 +33,7 @@
 #include "image.h"
 #include "dcp_video_frame.h"
 #include "config.h"
+#include "subtitle.h"
 
 using namespace std;
 using namespace boost;
@@ -72,62 +73,73 @@ Server::Server (Log* log)
 int
 Server::process (shared_ptr<Socket> socket)
 {
-       char buffer[128];
+       char buffer[256];
        socket->read_indefinite ((uint8_t *) buffer, sizeof (buffer), 30);
        socket->consume (strlen (buffer) + 1);
        
        stringstream s (buffer);
-       
+
        string command;
        s >> command;
        if (command != "encode") {
                return -1;
        }
-       
+
        Size in_size;
        int pixel_format_int;
        Size out_size;
        int padding;
+       int subtitle_offset;
+       int subtitle_scale;
        string scaler_id;
        int frame;
        float frames_per_second;
        string post_process;
        int colour_lut_index;
        int j2k_bandwidth;
+       Position subtitle_position;
+       Size subtitle_size;
        
        s >> in_size.width >> in_size.height
          >> pixel_format_int
          >> out_size.width >> out_size.height
          >> padding
+         >> subtitle_offset
+         >> subtitle_scale
          >> scaler_id
          >> frame
          >> frames_per_second
          >> post_process
          >> colour_lut_index
-         >> j2k_bandwidth;
-       
+         >> j2k_bandwidth
+         >> subtitle_position.x >> subtitle_position.y
+         >> subtitle_size.width >> subtitle_size.height;
+
        PixelFormat pixel_format = (PixelFormat) pixel_format_int;
        Scaler const * scaler = Scaler::from_id (scaler_id);
        if (post_process == "none") {
                post_process = "";
        }
        
-       shared_ptr<SimpleImage> image (new SimpleImage (pixel_format, in_size));
-       
-       for (int i = 0; i < image->components(); ++i) {
-               int line_size;
-               s >> line_size;
-               image->set_line_size (i, line_size);
-       }
-       
-       for (int i = 0; i < image->components(); ++i) {
-               socket->read_definite_and_consume (image->data()[i], image->line_size()[i] * image->lines(i), 30);
+       shared_ptr<Image> image (new AlignedImage (pixel_format, in_size));
+
+       image->read_from_socket (socket);
+
+       shared_ptr<Subtitle> sub;
+       if (subtitle_position.x != -1) {
+               shared_ptr<Image> subtitle_image (new AlignedImage (PIX_FMT_RGBA, subtitle_size));
+               subtitle_image->read_from_socket (socket);
+               sub.reset (new Subtitle (subtitle_position, subtitle_image));
        }
+
+       DCPVideoFrame dcp_video_frame (
+               image, sub, out_size, padding, subtitle_offset, subtitle_scale,
+               scaler, frame, frames_per_second, post_process, colour_lut_index, j2k_bandwidth, _log
+               );
        
-       DCPVideoFrame dcp_video_frame (image, out_size, padding, scaler, frame, frames_per_second, post_process, colour_lut_index, j2k_bandwidth, _log);
        shared_ptr<EncodedData> encoded = dcp_video_frame.encode_locally ();
        encoded->send (socket);
-       
+
        return frame;
 }