~ubuntu-branches/ubuntu/saucy/blender/saucy-proposed

« back to all changes in this revision

Viewing changes to source/blender/blenkernel/intern/writeframeserver.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *
3
 
 * Frameserver
4
 
 * Makes Blender accessible from TMPGenc directly using VFAPI (you can
5
 
 * use firefox too ;-)
6
 
 *
7
 
 * Copyright (c) 2006 Peter Schlaile
8
 
 *
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 *****
 
3
 *
 
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.
13
8
 *
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.
18
13
 *
 
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.
 
17
 *
 
18
 * Copyright (c) 2006 Peter Schlaile
 
19
 *
 
20
 * Contributor(s):
 
21
 *
 
22
 * ***** END GPL LICENSE BLOCK *****
19
23
 */
20
24
 
21
25
/** \file blender/blenkernel/intern/writeframeserver.c
22
26
 *  \ingroup bke
 
27
 *
 
28
 * Frameserver
 
29
 * Makes Blender accessible from TMPGenc directly using VFAPI (you can
 
30
 * use firefox too ;-)
23
31
 */
24
32
 
25
33
#ifdef WITH_FRAMESERVER
70
78
static int startup_socket_system(void)
71
79
{
72
80
        WSADATA wsa;
73
 
        return (WSAStartup(MAKEWORD(2,0),&wsa) == 0);
 
81
        return (WSAStartup(MAKEWORD(2, 0), &wsa) == 0);
74
82
}
75
83
 
76
84
static void shutdown_socket_system(void)
102
110
}
103
111
#endif
104
112
 
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)
106
114
{
107
115
        struct sockaddr_in addr;
108
116
        int arg = 1;
110
118
        (void)scene; /* unused */
111
119
 
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");
114
122
                return 0;
115
123
        }
116
124
 
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");
120
128
                return 0;
121
129
        }
122
130
 
123
 
        setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*) &arg, sizeof(arg));
 
131
        setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &arg, sizeof(arg));
124
132
 
125
133
        addr.sin_family = AF_INET;
126
134
        addr.sin_port = htons(U.frameserverport);
128
136
 
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");
132
140
                return 0;
133
141
        }
134
142
 
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");
138
146
                return 0;
139
147
        }
140
148
        connsock = -1;
169
177
"<body><pre>\n"
170
178
"Render stopped. Goodbye</pre></body></html>";
171
179
 
172
 
static int safe_write(char * s, int tosend)
 
180
static int safe_write(char *s, int tosend)
173
181
{
174
182
        int total = tosend;
175
183
        do {
184
192
        return total;
185
193
}
186
194
 
187
 
static int safe_puts(char * s)
 
195
static int safe_puts(char *s)
188
196
{
189
197
        return safe_write(s, strlen(s));
190
198
}
191
199
 
192
 
static int handle_request(RenderData *rd, char * req)
 
200
static int handle_request(RenderData *rd, char *req)
193
201
{
194
 
        char * p;
195
 
        char * path;
 
202
        char *p;
 
203
        char *path;
196
204
        int pathlen;
197
205
 
198
206
        if (memcmp(req, "GET ", 4) != 0) {
222
230
                char buf[4096];
223
231
 
224
232
                sprintf(buf,
225
 
                        "HTTP/1.1 200 OK\r\n"
226
 
                        "Content-Type: text/html\r\n"
227
 
                        "\r\n"
228
 
                        "start %d\n"
229
 
                        "end %d\n"
230
 
                        "width %d\n"
231
 
                        "height %d\n"
232
 
                        "rate %d\n"
233
 
                        "ratescale %d\n",
234
 
                        rd->sfra,
235
 
                        rd->efra,
236
 
                        render_width,
237
 
                        render_height,
238
 
                        rd->frs_sec,
239
 
                        1
240
 
                        );
 
233
                        "HTTP/1.1 200 OK\r\n"
 
234
                        "Content-Type: text/html\r\n"
 
235
                        "\r\n"
 
236
                        "start %d\n"
 
237
                        "end %d\n"
 
238
                        "width %d\n"
 
239
                        "height %d\n"
 
240
                        "rate %d\n"
 
241
                        "ratescale %d\n",
 
242
                        rd->sfra,
 
243
                        rd->efra,
 
244
                        render_width,
 
245
                        render_height,
 
246
                        rd->frs_sec,
 
247
                        1
 
248
                        );
241
249
 
242
250
                safe_puts(buf);
243
251
                return -1;
244
252
        }
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 */
248
256
                return -1;
249
257
        }
250
258
        return -1;
251
259
}
252
260
 
253
 
int frameserver_loop(RenderData *rd, ReportList *UNUSED(reports))
 
261
int BKE_frameserver_loop(RenderData *rd, ReportList *UNUSED(reports))
254
262
{
255
263
        fd_set readfds;
256
264
        struct timeval tv;
257
 
        struct sockaddr_in      addr;
 
265
        struct sockaddr_in addr;
258
266
        int len, rval;
259
267
#ifdef FREE_WINDOWS
260
268
        int socklen;
297
305
                tv.tv_sec = 10;
298
306
                tv.tv_usec = 0;
299
307
 
300
 
                        rval = select(connsock + 1, &readfds, NULL, NULL, &tv);
 
308
                rval = select(connsock + 1, &readfds, NULL, NULL, &tv);
301
309
                if (rval > 0) {
302
310
                        break;
303
311
                }
324
332
 
325
333
static void serve_ppm(int *pixels, int rectx, int recty)
326
334
{
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);
329
337
        int y;
330
338
        char header[1024];
331
339
 
332
340
        sprintf(header,
333
 
                "HTTP/1.1 200 OK\r\n"
334
 
                "Content-Type: image/ppm\r\n"
335
 
                "Connection: close\r\n"
336
 
                "\r\n"
337
 
                "P6\n"
338
 
                "# Creator: blender frameserver v0.0.1\n"
339
 
                "%d %d\n"
340
 
                "255\n",
341
 
                rectx, recty);
 
341
                "HTTP/1.1 200 OK\r\n"
 
342
                "Content-Type: image/ppm\r\n"
 
343
                "Connection: close\r\n"
 
344
                "\r\n"
 
345
                "P6\n"
 
346
                "# Creator: blender frameserver v0.0.1\n"
 
347
                "%d %d\n"
 
348
                "255\n",
 
349
                rectx, recty);
342
350
 
343
351
        safe_puts(header);
344
352
 
345
353
        rendered_frame = (unsigned char *)pixels;
346
354
 
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];
356
364
                        target += 3;
357
365
                        src += 4;
358
366
                }
359
 
                safe_write((char*)row, 3 * rectx);
 
367
                safe_write((char *)row, 3 * rectx);
360
368
        }
361
369
        free(row);
362
370
        closesocket(connsock);
363
371
        connsock = -1;
364
372
}
365
373
 
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))
368
376
{
369
377
        fprintf(stderr, "Serving frame: %d\n", frame);
370
378
        if (write_ppm) {
375
383
                connsock = -1;
376
384
        }
377
385
 
378
 
        return 0;
 
386
        return 1;
379
387
}
380
388
 
381
 
void end_frameserver(void)
 
389
void BKE_frameserver_end(void)
382
390
{
383
391
        if (connsock != -1) {
384
392
                closesocket(connsock);