Welcome! Log In Create A New Profile

Advanced

MJPEG Stream Client

Posted by Kajos 
MJPEG Stream Client
January 25, 2011 04:11PM
Hello,
I'm currently working on a MJPEG stream client, however I could use some help. I'm new to C so I could have made some pointer etc errors, which glad to be pointed on.
EDIT: Now everything works, but i get a corrupted JPEG. Could it be because net_read gets packages with end of an image and a beginning of an image? Cause I'm not taking that into account atm..
BTW: I'm using the jpeglib from the Codemii tutorial.



Edited 3 time(s). Last edit at 01/26/2011 05:22PM by Kajos.
Re: MJPEG Stream Client
January 25, 2011 08:51PM
http://pastebin.com/RsTn84Tu

Edited. Now showing first frame of the MJPEG stream and had some more working as well, however its still slow and crashing after multiple frames.

EDIT: crashes because of memory out. Probably because of an overuse of unfreed variables.. (?) Not used to that, heil garbage collection



Edited 3 time(s). Last edit at 01/26/2011 10:24PM by Kajos.
Re: MJPEG Stream Client
January 26, 2011 12:14AM
I did a dump of my first bufferread, and I'm suspecting my wifi-connection is what is up :D Had trouble with updates as well.. So gonna try tomorrow in a new setup, will let know.
Re: MJPEG Stream Client
January 26, 2011 12:44AM
I'm trying to locate the start of the JPEG with a searchfunction:

char* findImage(const char * buf, int bytes_read) {
	char * p = buf;
	
	char find[2];
	find[0]=(char)0xFF;
	find[1]=(char)0xD8;

	int k = 0;
	while (p = memchr(buf, find[0],bytes_read) && k < bytes_read) {
		if (*++p == find[1]) {
			return --p;
		}
		k++;
	}
	return NULL;
}
However it does not do so :S
Re: MJPEG Stream Client
January 26, 2011 04:40AM
Here's your problem, what happens if *++p is not equal to find[1]. You increment k, then you check the same area of memory again in your memchr() function. Also, memchr is not the best function to use here. Try using memcmp. You can find the both characters in one function this way, instead or relying on some pointer magic. Try something like this:
char *p = buf;
while(k < bytes_read)}{
   if(memcmp(find,p,2) == 0){
      return p;
   } else {
       p++;
   }
   k++
}
return NULL;
I can't garentee that this code will be correct, but it should give you an idea.

Also, don't post four times in a row, the edit button is there for a reason.
Re: MJPEG Stream Client
January 26, 2011 10:40AM
Also use [pastebin.com] to post code, the code markup of the forum isn't that great.
Re: MJPEG Stream Client
January 26, 2011 05:29PM
Quote

You increment k, then you check the same area of memory again in your memchr() function. Also, memchr is not the best function to use here. Try using memcmp.
Thanks, did'nt see that one. Fixed it now. I guess it would always return null and therefor give me wrong readings? Shouldn't it cause an exception when trying to dump the image when it's pointing to null?



Edited 1 time(s). Last edit at 01/26/2011 05:31PM by Kajos.
Re: MJPEG Stream Client
January 26, 2011 10:54PM
that would depend on the rest of your code. If you are just reading and dumping what is at the location returned then it won't dump(I don't think), but that shouldn't matter, because you should check to see if your function returns null, and if it does you should try to fix the problem, and not try to go on with the program :)
Re: MJPEG Stream Client
January 27, 2011 08:45PM
I have the stream client working now, but if I turn up the frames from 5fps (640x480) to 10 fps or more it hangs and returns to HC. Any ideas?

320x240 at 20fps holds pretty steady as well...



Edited 1 time(s). Last edit at 01/27/2011 09:09PM by Kajos.
Sorry, only registered users may post in this forum.

Click here to login