4
* Copyright (c) 2006 Peter Schlaile
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
25
#define VF_STREAM_VIDEO 0x00000001
26
#define VF_STREAM_AUDIO 0x00000002
27
#define VF_OK 0x00000000
28
#define VF_ERROR 0x80004005
34
DWORD dwSupportStreamType;
35
char cPluginInfo[256];
37
} VF_PluginInfo,*LPVF_PluginInfo;
39
typedef DWORD VF_FileHandle,*LPVF_FileHandle;
44
} VF_FileInfo,*LPVF_FileInfo;
55
} VF_StreamInfo_Video,*LPVF_StreamInfo_Video;
64
DWORD dwBitsPerSample;
66
} VF_StreamInfo_Audio,*LPVF_StreamInfo_Audio;
74
} VF_ReadData_Video,*LPVF_ReadData_Video;
80
DWORD dwReadedSampleCount;
83
} VF_ReadData_Audio,*LPVF_ReadData_Audio;
87
HRESULT (__stdcall *OpenFile)(
88
char *lpFileName, LPVF_FileHandle lpFileHandle );
89
HRESULT (__stdcall *CloseFile)( VF_FileHandle hFileHandle );
90
HRESULT (__stdcall *GetFileInfo)( VF_FileHandle hFileHandle,
91
LPVF_FileInfo lpFileInfo );
92
HRESULT (__stdcall *GetStreamInfo)( VF_FileHandle hFileHandle,
93
DWORD dwStream,void *lpStreamInfo );
94
HRESULT (__stdcall *ReadData)( VF_FileHandle hFileHandle,
95
DWORD dwStream,void *lpData );
96
} VF_PluginFunc,*LPVF_PluginFunc;
98
__declspec(dllexport) HRESULT vfGetPluginInfo(
99
LPVF_PluginInfo lpPluginInfo )
101
if (!lpPluginInfo || lpPluginInfo->dwSize != sizeof(VF_PluginInfo)) {
105
lpPluginInfo->dwAPIVersion = 1;
106
lpPluginInfo->dwVersion = 1;
107
lpPluginInfo->dwSupportStreamType = VF_STREAM_VIDEO;
108
strcpy(lpPluginInfo->cPluginInfo, "Blender Frameserver");
109
strcpy(lpPluginInfo->cFileType,
110
"Blender Frame-URL-File (*.blu)|*.blu");
115
static unsigned long getipaddress(const char * ipaddr)
117
struct hostent *host;
120
if (((ip = inet_addr(ipaddr)) == INADDR_NONE)
121
&& strcmp(ipaddr, "255.255.255.255") != 0) {
122
if ((host = gethostbyname(ipaddr)) != NULL) {
123
memcpy(&ip, host->h_addr, sizeof(ip));
130
static void my_send(SOCKET sock, char * str)
132
send(sock, str, strlen(str), 0);
135
static int my_recv(SOCKET sock, char * line, int maxlen)
141
got = recv(sock, line, toget, 0);
151
static int my_gets(SOCKET sock, char * line, int maxlen)
155
while (((last_rval = my_recv(sock, line, 1)) == 1) && maxlen > 0) {
168
typedef struct conndesc_ {
169
struct sockaddr_in addr;
180
HRESULT __stdcall VF_OpenFileFunc_Blen(
181
char *lpFileName, LPVF_FileHandle lpFileHandle )
189
struct sockaddr_in addr;
193
while (*p && *p != '.') p++;
195
if (strcmp(p, "blu") != 0) {
199
fp = fopen(lpFileName, "r");
208
while (*p && *p != ':') p++;
216
addr.sin_family = AF_INET;
217
addr.sin_port = htons(port);
218
addr.sin_addr.s_addr = getipaddress(host);
220
s_in = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
225
if (connect(s_in, (struct sockaddr*) &addr,
231
rval = (conndesc*) malloc(sizeof(conndesc));
235
my_send(s_in, "GET /info.txt HTTP/1.0\n\n");
241
if (my_gets(s_in, buf, 250) <= 0) {
247
while (*val && *val != ' ') val++;
252
if (strcmp(key, "width") == 0) {
253
rval->width = atoi(val);
254
} else if (strcmp(key, "height") == 0) {
255
rval->height = atoi(val);
256
} else if (strcmp(key, "start") == 0) {
257
rval->start = atoi(val);
258
} else if (strcmp(key, "end") == 0) {
259
rval->end = atoi(val);
260
} else if (strcmp(key, "rate") == 0) {
261
rval->rate = atoi(val);
262
} else if (strcmp(key, "ratescale") == 0) {
263
rval->ratescale = atoi(val);
270
*lpFileHandle = (VF_FileHandle) rval;
275
HRESULT __stdcall VF_CloseFileFunc_Blen(
276
VF_FileHandle hFileHandle )
278
free((conndesc*) hFileHandle);
283
HRESULT __stdcall VF_GetFileInfoFunc_Blen(
284
VF_FileHandle hFileHandle,
285
LPVF_FileInfo lpFileInfo )
287
conndesc * c = (conndesc*) hFileHandle;
292
if (lpFileInfo->dwSize != sizeof(VF_FileInfo)) {
296
lpFileInfo->dwHasStreams = VF_STREAM_VIDEO;
301
HRESULT __stdcall VF_GetStreamInfoFunc_Blen(
302
VF_FileHandle hFileHandle,
303
DWORD dwStream,void *lpStreamInfo )
305
conndesc * c = (conndesc*) hFileHandle;
307
LPVF_StreamInfo_Video v = (LPVF_StreamInfo_Video) lpStreamInfo;
309
if (c == 0 || dwStream != VF_STREAM_VIDEO || v == 0) {
313
v->dwLengthL = c->end - c->start;
315
v->dwScale = c->ratescale;
317
v->dwWidth = c->width;
318
v->dwHeight = c->height;
324
HRESULT __stdcall VF_ReadDataFunc_Blen(
325
VF_FileHandle hFileHandle,
326
DWORD dwStream,void *lpData )
335
unsigned char * framebuf;
337
conndesc * c = (conndesc*) hFileHandle;
338
LPVF_ReadData_Video v = (LPVF_ReadData_Video) lpData;
340
if (c == 0 || dwStream != VF_STREAM_VIDEO || v == 0) {
344
s_in = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
349
if (connect(s_in, (struct sockaddr*) &c->addr,
350
sizeof(c->addr)) < 0) {
354
sprintf(req, "GET /images/ppm/%d.ppm HTTP/1.0\n\n",
355
(int) (v->dwFrameNumberL) + c->start);
360
if (my_gets(s_in, buf, 256) <= 0) {
363
} while (strcmp(buf, "P6\n") != 0);
366
rval = my_gets(s_in, buf, 256);
367
} while ( (buf[0] == '#' || buf[0] == '\n') && rval >= 0);
369
if (sscanf(buf, "%d %d\n", &width, &height) != 2) {
373
if (width != c->width || height != c->height) {
377
my_gets(s_in, buf, 256); /* 255 */
379
framebuf = (unsigned char*) v->lpData;
381
for (y = 0; y < height; y++) {
382
unsigned char * p = framebuf + v->lPitch * y;
383
unsigned char * e = p + width * 3;
385
my_recv(s_in, (char*) p, width * 3);
387
unsigned char tmp = p[2];
401
__declspec(dllexport) HRESULT vfGetPluginFunc(
402
LPVF_PluginFunc lpPluginFunc )
404
if (!lpPluginFunc || lpPluginFunc->dwSize != sizeof(VF_PluginFunc)) {
408
lpPluginFunc->OpenFile = VF_OpenFileFunc_Blen;
409
lpPluginFunc->CloseFile = VF_CloseFileFunc_Blen;
410
lpPluginFunc->GetFileInfo = VF_GetFileInfoFunc_Blen;
411
lpPluginFunc->GetStreamInfo = VF_GetStreamInfoFunc_Blen;
412
lpPluginFunc->ReadData = VF_ReadDataFunc_Blen;
4
* Copyright (c) 2006 Peter Schlaile
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
25
#define VF_STREAM_VIDEO 0x00000001
26
#define VF_STREAM_AUDIO 0x00000002
27
#define VF_OK 0x00000000
28
#define VF_ERROR 0x80004005
34
DWORD dwSupportStreamType;
35
char cPluginInfo[256];
37
} VF_PluginInfo,*LPVF_PluginInfo;
39
typedef DWORD VF_FileHandle,*LPVF_FileHandle;
44
} VF_FileInfo,*LPVF_FileInfo;
55
} VF_StreamInfo_Video,*LPVF_StreamInfo_Video;
64
DWORD dwBitsPerSample;
66
} VF_StreamInfo_Audio,*LPVF_StreamInfo_Audio;
74
} VF_ReadData_Video,*LPVF_ReadData_Video;
80
DWORD dwReadedSampleCount;
83
} VF_ReadData_Audio,*LPVF_ReadData_Audio;
87
HRESULT (__stdcall *OpenFile)(
88
char *lpFileName, LPVF_FileHandle lpFileHandle );
89
HRESULT (__stdcall *CloseFile)( VF_FileHandle hFileHandle );
90
HRESULT (__stdcall *GetFileInfo)( VF_FileHandle hFileHandle,
91
LPVF_FileInfo lpFileInfo );
92
HRESULT (__stdcall *GetStreamInfo)( VF_FileHandle hFileHandle,
93
DWORD dwStream,void *lpStreamInfo );
94
HRESULT (__stdcall *ReadData)( VF_FileHandle hFileHandle,
95
DWORD dwStream,void *lpData );
96
} VF_PluginFunc,*LPVF_PluginFunc;
98
__declspec(dllexport) HRESULT vfGetPluginInfo(
99
LPVF_PluginInfo lpPluginInfo )
101
if (!lpPluginInfo || lpPluginInfo->dwSize != sizeof(VF_PluginInfo)) {
105
lpPluginInfo->dwAPIVersion = 1;
106
lpPluginInfo->dwVersion = 1;
107
lpPluginInfo->dwSupportStreamType = VF_STREAM_VIDEO;
108
strcpy(lpPluginInfo->cPluginInfo, "Blender Frameserver");
109
strcpy(lpPluginInfo->cFileType,
110
"Blender Frame-URL-File (*.blu)|*.blu");
115
static unsigned long getipaddress(const char * ipaddr)
117
struct hostent *host;
120
if (((ip = inet_addr(ipaddr)) == INADDR_NONE)
121
&& strcmp(ipaddr, "255.255.255.255") != 0) {
122
if ((host = gethostbyname(ipaddr)) != NULL) {
123
memcpy(&ip, host->h_addr, sizeof(ip));
130
static void my_send(SOCKET sock, char * str)
132
send(sock, str, strlen(str), 0);
135
static int my_recv(SOCKET sock, char * line, int maxlen)
141
got = recv(sock, line, toget, 0);
151
static int my_gets(SOCKET sock, char * line, int maxlen)
155
while (((last_rval = my_recv(sock, line, 1)) == 1) && maxlen > 0) {
168
typedef struct conndesc_ {
169
struct sockaddr_in addr;
180
HRESULT __stdcall VF_OpenFileFunc_Blen(
181
char *lpFileName, LPVF_FileHandle lpFileHandle )
189
struct sockaddr_in addr;
193
while (*p && *p != '.') p++;
195
if (strcmp(p, "blu") != 0) {
199
fp = fopen(lpFileName, "r");
208
while (*p && *p != ':') p++;
216
addr.sin_family = AF_INET;
217
addr.sin_port = htons(port);
218
addr.sin_addr.s_addr = getipaddress(host);
220
s_in = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
225
if (connect(s_in, (struct sockaddr*) &addr,
231
rval = (conndesc*) malloc(sizeof(conndesc));
235
my_send(s_in, "GET /info.txt HTTP/1.0\n\n");
241
if (my_gets(s_in, buf, 250) <= 0) {
247
while (*val && *val != ' ') val++;
252
if (strcmp(key, "width") == 0) {
253
rval->width = atoi(val);
254
} else if (strcmp(key, "height") == 0) {
255
rval->height = atoi(val);
256
} else if (strcmp(key, "start") == 0) {
257
rval->start = atoi(val);
258
} else if (strcmp(key, "end") == 0) {
259
rval->end = atoi(val);
260
} else if (strcmp(key, "rate") == 0) {
261
rval->rate = atoi(val);
262
} else if (strcmp(key, "ratescale") == 0) {
263
rval->ratescale = atoi(val);
270
*lpFileHandle = (VF_FileHandle) rval;
275
HRESULT __stdcall VF_CloseFileFunc_Blen(
276
VF_FileHandle hFileHandle )
278
free((conndesc*) hFileHandle);
283
HRESULT __stdcall VF_GetFileInfoFunc_Blen(
284
VF_FileHandle hFileHandle,
285
LPVF_FileInfo lpFileInfo )
287
conndesc * c = (conndesc*) hFileHandle;
292
if (lpFileInfo->dwSize != sizeof(VF_FileInfo)) {
296
lpFileInfo->dwHasStreams = VF_STREAM_VIDEO;
301
HRESULT __stdcall VF_GetStreamInfoFunc_Blen(
302
VF_FileHandle hFileHandle,
303
DWORD dwStream,void *lpStreamInfo )
305
conndesc * c = (conndesc*) hFileHandle;
307
LPVF_StreamInfo_Video v = (LPVF_StreamInfo_Video) lpStreamInfo;
309
if (c == 0 || dwStream != VF_STREAM_VIDEO || v == 0) {
313
v->dwLengthL = c->end - c->start;
315
v->dwScale = c->ratescale;
317
v->dwWidth = c->width;
318
v->dwHeight = c->height;
324
HRESULT __stdcall VF_ReadDataFunc_Blen(
325
VF_FileHandle hFileHandle,
326
DWORD dwStream,void *lpData )
335
unsigned char * framebuf;
337
conndesc * c = (conndesc*) hFileHandle;
338
LPVF_ReadData_Video v = (LPVF_ReadData_Video) lpData;
340
if (c == 0 || dwStream != VF_STREAM_VIDEO || v == 0) {
344
s_in = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
349
if (connect(s_in, (struct sockaddr*) &c->addr,
350
sizeof(c->addr)) < 0) {
354
sprintf(req, "GET /images/ppm/%d.ppm HTTP/1.0\n\n",
355
(int) (v->dwFrameNumberL) + c->start);
360
if (my_gets(s_in, buf, 256) <= 0) {
363
} while (strcmp(buf, "P6\n") != 0);
366
rval = my_gets(s_in, buf, 256);
367
} while ( (buf[0] == '#' || buf[0] == '\n') && rval >= 0);
369
if (sscanf(buf, "%d %d\n", &width, &height) != 2) {
373
if (width != c->width || height != c->height) {
377
my_gets(s_in, buf, 256); /* 255 */
379
framebuf = (unsigned char*) v->lpData;
381
for (y = 0; y < height; y++) {
382
unsigned char * p = framebuf + v->lPitch * y;
383
unsigned char * e = p + width * 3;
385
my_recv(s_in, (char*) p, width * 3);
387
unsigned char tmp = p[2];
401
__declspec(dllexport) HRESULT vfGetPluginFunc(
402
LPVF_PluginFunc lpPluginFunc )
404
if (!lpPluginFunc || lpPluginFunc->dwSize != sizeof(VF_PluginFunc)) {
408
lpPluginFunc->OpenFile = VF_OpenFileFunc_Blen;
409
lpPluginFunc->CloseFile = VF_CloseFileFunc_Blen;
410
lpPluginFunc->GetFileInfo = VF_GetFileInfoFunc_Blen;
411
lpPluginFunc->GetStreamInfo = VF_GetStreamInfoFunc_Blen;
412
lpPluginFunc->ReadData = VF_ReadDataFunc_Blen;