4
* Makes Blender accessible from TMPGenc directly using VFAPI (you can
7
* Copyright (c) 2006 Peter Schlaile
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
14
9
* This program is distributed in the hope that it will be useful,
15
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* Copyright (c) 2006 Peter Schlaile
22
* ***** END GPL LICENSE BLOCK *****
21
25
/** \file blender/blenkernel/intern/writeframeserver.c
29
* Makes Blender accessible from TMPGenc directly using VFAPI (you can
25
33
#ifdef WITH_FRAMESERVER
70
78
static int startup_socket_system(void)
73
return (WSAStartup(MAKEWORD(2,0),&wsa) == 0);
81
return (WSAStartup(MAKEWORD(2, 0), &wsa) == 0);
76
84
static void shutdown_socket_system(void)
105
int start_frameserver(struct Scene *scene, RenderData *UNUSED(rd), int rectx, int recty, ReportList *reports)
113
int BKE_frameserver_start(struct Scene *scene, RenderData *UNUSED(rd), int rectx, int recty, ReportList *reports)
107
115
struct sockaddr_in addr;
110
118
(void)scene; /* unused */
112
120
if (!startup_socket_system()) {
113
BKE_report(reports, RPT_ERROR, "Can't startup socket system");
121
BKE_report(reports, RPT_ERROR, "Cannot startup socket system");
117
125
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
118
126
shutdown_socket_system();
119
BKE_report(reports, RPT_ERROR, "Can't open socket");
127
BKE_report(reports, RPT_ERROR, "Cannot open socket");
123
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*) &arg, sizeof(arg));
131
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &arg, sizeof(arg));
125
133
addr.sin_family = AF_INET;
126
134
addr.sin_port = htons(U.frameserverport);
129
137
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
130
138
shutdown_socket_system();
131
BKE_report(reports, RPT_ERROR, "Can't bind to socket");
139
BKE_report(reports, RPT_ERROR, "Cannot bind to socket");
135
143
if (listen(sock, SOMAXCONN) < 0) {
136
144
shutdown_socket_system();
137
BKE_report(reports, RPT_ERROR, "Can't establish listen backlog");
145
BKE_report(reports, RPT_ERROR, "Cannot establish listen backlog");
187
static int safe_puts(char * s)
195
static int safe_puts(char *s)
189
197
return safe_write(s, strlen(s));
192
static int handle_request(RenderData *rd, char * req)
200
static int handle_request(RenderData *rd, char *req)
198
206
if (memcmp(req, "GET ", 4) != 0) {
225
"HTTP/1.1 200 OK\r\n"
226
"Content-Type: text/html\r\n"
233
"HTTP/1.1 200 OK\r\n"
234
"Content-Type: text/html\r\n"
245
253
if (strcmp(path, "/close.txt") == 0) {
246
254
safe_puts(good_bye);
247
G.afbreek = 1; /* Abort render */
255
G.is_break = TRUE; /* Abort render */
253
int frameserver_loop(RenderData *rd, ReportList *UNUSED(reports))
261
int BKE_frameserver_loop(RenderData *rd, ReportList *UNUSED(reports))
256
264
struct timeval tv;
257
struct sockaddr_in addr;
265
struct sockaddr_in addr;
259
267
#ifdef FREE_WINDOWS
300
rval = select(connsock + 1, &readfds, NULL, NULL, &tv);
308
rval = select(connsock + 1, &readfds, NULL, NULL, &tv);
325
333
static void serve_ppm(int *pixels, int rectx, int recty)
327
unsigned char* rendered_frame;
328
unsigned char* row = (unsigned char*) malloc(render_width * 3);
335
unsigned char *rendered_frame;
336
unsigned char *row = (unsigned char *) malloc(render_width * 3);
330
338
char header[1024];
333
"HTTP/1.1 200 OK\r\n"
334
"Content-Type: image/ppm\r\n"
335
"Connection: close\r\n"
338
"# Creator: blender frameserver v0.0.1\n"
341
"HTTP/1.1 200 OK\r\n"
342
"Content-Type: image/ppm\r\n"
343
"Connection: close\r\n"
346
"# Creator: blender frameserver v0.0.1\n"
343
351
safe_puts(header);
345
353
rendered_frame = (unsigned char *)pixels;
347
355
for (y = recty - 1; y >= 0; y--) {
348
unsigned char* target = row;
349
unsigned char* src = rendered_frame + rectx * 4 * y;
350
unsigned char* end = src + rectx * 4;
356
unsigned char *target = row;
357
unsigned char *src = rendered_frame + rectx * 4 * y;
358
unsigned char *end = src + rectx * 4;
351
359
while (src != end) {
352
360
target[2] = src[2];
353
361
target[1] = src[1];
359
safe_write((char*)row, 3 * rectx);
367
safe_write((char *)row, 3 * rectx);
362
370
closesocket(connsock);
366
int append_frameserver(RenderData *UNUSED(rd), int UNUSED(start_frame), int frame, int *pixels,
367
int rectx, int recty, ReportList *UNUSED(reports))
374
int BKE_frameserver_append(RenderData *UNUSED(rd), int UNUSED(start_frame), int frame, int *pixels,
375
int rectx, int recty, ReportList *UNUSED(reports))
369
377
fprintf(stderr, "Serving frame: %d\n", frame);