doxygen: blender/blenkernel tagged.
[blender.git] / source / blender / blenkernel / intern / writeframeserver.c
index 0780cd0dc483649459fbd9fa2763377ba80fad3d..2239f6d31474eaf471cee200980e81a82dee16f3 100644 (file)
@@ -1,4 +1,9 @@
+/** \file blender/blenkernel/intern/writeframeserver.c
+ *  \ingroup bke
+ */
 /*
+ * $Id$
+ *
  * Frameserver
  * Makes Blender accessible from TMPGenc directly using VFAPI (you can
  * use firefox too ;-)
 
 #include <stdlib.h>
 
-#include "MEM_guardedalloc.h"
-#include "BLI_blenlib.h"
 #include "DNA_userdef_types.h"
 
-#include "BKE_global.h"
+#include "BLI_utildefines.h"
 
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
+#include "BKE_writeframeserver.h"
+#include "BKE_global.h"
+#include "BKE_report.h"
 
 #include "DNA_scene_types.h"
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 static int sock;
 static int connsock;
 static int write_ppm;
@@ -66,89 +66,88 @@ static int render_height;
 
 
 #if defined(_WIN32)
-static int startup_socket_system()
+static int startup_socket_system(void)
 {
        WSADATA wsa;
        return (WSAStartup(MAKEWORD(2,0),&wsa) == 0);
 }
 
-static void shutdown_socket_system()
+static void shutdown_socket_system(void)
 {
        WSACleanup();
 }
-static int select_was_interrupted_by_signal()
+static int select_was_interrupted_by_signal(void)
 {
        return (WSAGetLastError() == WSAEINTR);
 }
 #else
-static int startup_socket_system()
+static int startup_socket_system(void)
 {
        return 1;
 }
 
-static void shutdown_socket_system()
+static void shutdown_socket_system(void)
 {
 }
 
-static int select_was_interrupted_by_signal()
+static int select_was_interrupted_by_signal(void)
 {
        return (errno == EINTR);
 }
 
-static int closesocket(int fd) 
+static int closesocket(int fd)
 {
        return close(fd);
 }
 #endif
 
-void start_frameserver(struct Scene *scene, RenderData *rd, int rectx, int recty)
+int start_frameserver(struct Scene *scene, RenderData *UNUSED(rd), int rectx, int recty, ReportList *reports)
 {
-        struct sockaddr_in      addr;
+       struct sockaddr_in addr;
        int arg = 1;
+       
+       (void)scene; /* unused */
 
        if (!startup_socket_system()) {
-               G.afbreek = 1;
-               //XXX error("Can't startup socket system");
-               return;
+               BKE_report(reports, RPT_ERROR, "Can't startup socket system");
+               return 0;
        }
 
        if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
                shutdown_socket_system();
-               G.afbreek = 1; /* Abort render */
-               //XXX error("Can't open socket");
-               return;
-        }
+               BKE_report(reports, RPT_ERROR, "Can't open socket");
+               return 0;
+       }
 
-       setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
-                   (char*) &arg, sizeof(arg));
+       setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*) &arg, sizeof(arg));
 
        addr.sin_family = AF_INET;
-        addr.sin_port = htons(U.frameserverport);
-        addr.sin_addr.s_addr = INADDR_ANY;
+       addr.sin_port = htons(U.frameserverport);
+       addr.sin_addr.s_addr = INADDR_ANY;
 
        if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
                shutdown_socket_system();
-               G.afbreek = 1; /* Abort render */
-               //XXX error("Can't bind to socket");
-               return;
-        }
+               BKE_report(reports, RPT_ERROR, "Can't bind to socket");
+               return 0;
+       }
 
-        if (listen(sock, SOMAXCONN) < 0) {
+       if (listen(sock, SOMAXCONN) < 0) {
                shutdown_socket_system();
-               G.afbreek = 1; /* Abort render */
-               //XXX error("Can't establish listen backlog");
-               return;
-        }
+               BKE_report(reports, RPT_ERROR, "Can't establish listen backlog");
+               return 0;
+       }
        connsock = -1;
 
        render_width = rectx;
        render_height = recty;
+
+       return 1;
 }
 
-static char index_page[] 
-= 
-"HTTP/1.1 200 OK\n"
-"Content-Type: text/html\n\n"
+static char index_page[] =
+"HTTP/1.1 200 OK\r\n"
+"Content-Type: text/html\r\n"
+"\r\n"
 "<html><head><title>Blender Frameserver</title></head>\n"
 "<body><pre>\n"
 "<H2>Blender Frameserver</H2>\n"
@@ -161,9 +160,10 @@ static char index_page[]
 "\n"
 "</pre></body></html>\n";
 
-static char good_bye[]
-= "HTTP/1.1 200 OK\n"
-"Content-Type: text/html\n\n"
+static char good_bye[] =
+"HTTP/1.1 200 OK\r\n"
+"Content-Type: text/html\r\n"
+"\r\n"
 "<html><head><title>Blender Frameserver</title></head>\n"
 "<body><pre>\n"
 "Render stopped. Goodbye</pre></body></html>";
@@ -206,7 +206,7 @@ static int handle_request(RenderData *rd, char * req)
        *p = 0;
 
        if (strcmp(path, "/index.html") == 0
-           || strcmp(path, "/") == 0) {
+               || strcmp(path, "/") == 0) {
                safe_puts(index_page);
                return -1;
        }
@@ -221,13 +221,14 @@ static int handle_request(RenderData *rd, char * req)
        if (strcmp(path, "/info.txt") == 0) {
                char buf[4096];
 
-               sprintf(buf, 
-                       "HTTP/1.1 200 OK\n"
-                       "Content-Type: text/html\n\n"
+               sprintf(buf,
+                       "HTTP/1.1 200 OK\r\n"
+                       "Content-Type: text/html\r\n"
+                       "\r\n"
                        "start %d\n"
                        "end %d\n"
                        "width %d\n"
-                       "height %d\n" 
+                       "height %d\n"
                        "rate %d\n"
                        "ratescale %d\n",
                        rd->sfra,
@@ -249,7 +250,7 @@ static int handle_request(RenderData *rd, char * req)
        return -1;
 }
 
-int frameserver_loop(RenderData *rd)
+int frameserver_loop(RenderData *rd, ReportList *UNUSED(reports))
 {
        fd_set readfds;
        struct timeval tv;
@@ -292,7 +293,7 @@ int frameserver_loop(RenderData *rd)
                tv.tv_sec = 10;
                tv.tv_usec = 0;
 
-               rval = select(connsock + 1, &readfds, NULL, NULL, &tv);
+                       rval = select(connsock + 1, &readfds, NULL, NULL, &tv);
                if (rval > 0) {
                        break;
                } else if (rval == 0) {
@@ -322,10 +323,11 @@ static void serve_ppm(int *pixels, int rectx, int recty)
        int y;
        char header[1024];
 
-       sprintf(header, 
-               "HTTP/1.1 200 OK\n"
-               "Content-Type: image/ppm\n"
-               "Connection: close\n\n"
+       sprintf(header,
+               "HTTP/1.1 200 OK\r\n"
+               "Content-Type: image/ppm\r\n"
+               "Connection: close\r\n"
+               "\r\n"
                "P6\n"
                "# Creator: blender frameserver v0.0.1\n"
                "%d %d\n"
@@ -348,14 +350,14 @@ static void serve_ppm(int *pixels, int rectx, int recty)
                        target += 3;
                        src += 4;
                }
-               safe_write((char*)row, 3 * rectx); 
+               safe_write((char*)row, 3 * rectx);
        }
        free(row);
        closesocket(connsock);
        connsock = -1;
 }
 
-void append_frameserver(RenderData *rd, int frame, int *pixels, int rectx, int recty)
+int append_frameserver(RenderData *UNUSED(rd), int frame, int *pixels, int rectx, int recty, ReportList *UNUSED(reports))
 {
        fprintf(stderr, "Serving frame: %d\n", frame);
        if (write_ppm) {
@@ -365,9 +367,11 @@ void append_frameserver(RenderData *rd, int frame, int *pixels, int rectx, int r
                closesocket(connsock);
                connsock = -1;
        }
+
+       return 0;
 }
 
-void end_frameserver()
+void end_frameserver(void)
 {
        if (connsock != -1) {
                closesocket(connsock);