31 if(urlstr == NULL)
return -1;
42 if(
sock == NULL)
return -1;
51 printf(
"rlWebcam::ERROR sock==NULL\n");
55 const char *cptr =
getFrame(timeout);
63 unsigned char buffer[1024*1024];
67 printf(
"rlWebcam::ERROR sock==NULL\n");
77 printf(
"rlWebcam::ERROR sock->isConnected() == 0\n");
85 if(
sock->
readStr(line,(
int)
sizeof(line)-1,timeout) < 1)
return NULL;
86 if(
debug) printf(
"getFrame:: Header:%s",line);
87 if(strncmp(line,
"Content-Length:",15) == 0)
break;
91 sscanf(line,
"Content-Length: %d", &len);
92 if(
debug) printf(
"getFrame:: len=%d\n",len);
93 if(len > (
int) (
sizeof(buffer) - 1))
return NULL;
95 if(requestOnly)
return NULL;
99 if(
sock->
read(&c1,1,timeout) < 1)
return NULL;
100 if(
debug) printf(
"%02x ", c1);
103 if(
sock->
read(&c2,1,timeout) < 1)
return NULL;
104 if(
debug) printf(
"%02x ", c2);
107 if(
debug) printf(
"\nrlWebcam::Found startOfImage\n");
116 printf(
"rlWebcam::ERROR you forgot to set filename\n");
122 printf(
"rlWebcam::ERROR could not write file %s\n",
filename.
text());
131 len =
sock->
read(&buffer[2],len-2,timeout);
133 if(len < 1)
return NULL;
136 fwrite(buffer, ind, 1, fout);
172 printf(
"rlWebcam::ERROR sock==NULL\n");
182 printf(
"rlWebcam::ERROR sock->isConnected() == 0\n");
190 if(
sock->
readStr(line,(
int)
sizeof(line)-1,timeout) < 1)
return -1;
191 if(
debug) printf(
"getFrameBuffer:: Header:%s",line);
192 if(strncmp(line,
"Content-Length:",15) == 0)
break;
196 sscanf(line,
"Content-Length: %d", &len);
197 if(
debug) printf(
"getFrameBuffer:: len=%d\n",len);
202 if(
sock->
read(&c1,1,timeout) < 1)
return -3;
203 if(
debug) printf(
"%02x ", c1);
206 if(
sock->
read(&c2,1,timeout) < 1)
return -4;
207 if(
debug) printf(
"%02x ", c2);
210 if(
debug) printf(
"\nrlWebcam::Found startOfImage\n");
219 len =
sock->
read(&buffer[2],len-2,timeout);
221 if(len < 1)
return -5;
266 printf(
"rlWebcam::wrong url syntax in %s\n",
url.
text());
267 printf(
"url syntax: http://host:port/path_to_webcam_cgi_script\n");
274 if(cptr != NULL) *cptr =
'\0';
276 if(cptr != NULL) *cptr =
'\0';
286 printf(
"rlWebcam::wrong url syntax in %s\n",
url.
text());
287 printf(
"url syntax: http://host:port/path_to_webcam_cgi_script\n");
294 if(cptr != NULL) *cptr =
'\0';
296 if(cptr != NULL) sscanf(cptr,
":%d", &port);
297 if(
debug) printf(
"rlWebcam:port=%d\n", port);
305 printf(
"rlWebcam::wrong url syntax in %s\n",
url.
text());
306 printf(
"url syntax: http://host:port/path_to_webcam_cgi_script\n");
313 if(cptr == NULL)
return "";
315 if(
debug) printf(
"rlWebcam:path=%s\n", cptr);
int setUrl(const char *url)
int startsWith(const char *startstr)
int getFrameBuffer(unsigned char *buffer, int maxbuffer, int timeout=3000)
int readStr(char *buf, int len, int timeout=0)
int read(void *buf, int len, int timeout=0)
const char * getSnapshot(int timeout=3000)
int setText(const char *text)
const char * getFrame(int timeout=3000, int requestOnly=0)
int printf(const char *format,...)