Multithread program screen freeze

Hi, all

I used SDL in my v4l program with SDL_mixer, SDL_timer, SDL_thread. I create a SDL thread to grab video stream from bt878 by v4l2 and bitblt, update the video to screen, a timer loop bitblt and update to screen 10 times a second too. sometime the screen froze but the mp3 music still play. The program cannot quit. Can somebody help me? thanks

my code:

timer loop:-------------------------------------------------
static Uint32 timer_loop(Uint32 interval)
{
SDL_BlitSurface(t_surface, 0, core_screen, &t_rect);
SDL_UpdateRects(core_screen, 1, &t_rect);
return 100;
}

thread loop:

static int vidcap_thread(void* data)
{
int i;
struct v4l2_buffer buf;
enum v4l2_buf_type type;

while(1) {
	memset(&buf, 0 ,sizeof(buf));
	buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	buf.memory = V4L2_MEMORY_MMAP;
	buf.field =	V4L2_FIELD_ANY;

	if (ioctl(cap_fd, VIDIOC_DQBUF, &buf)==-1) {
		if (errno==EAGAIN) continue;
		break;
	}

	if (buf.index<MAX_BUFF) {
		SDL_BlitSurface(cap_surface[buf.index] , &cap_rect, core_screen, &screen_rect);
		SDL_UpdateRects(core_screen, 1, &screen_rect);
	}

	if (ioctl (cap_fd, VIDIOC_QBUF, &buf)==-1) break;
}//end while

//fail
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
ioctl (cap_fd, VIDIOC_STREAMOFF, &type);

for (i=0;i<MAX_BUFF;i++) {
	SDL_FreeSurface(cap_surface[i]);
	munmap (cap_buff[i].addr, cap_buff[i].size);
}

cap_living = 0;

return 0;

}

sorry for my pool english

SDL documents that its video functions are not (in general) thread
safe, and on some platforms must be called from the main thread. You
might want to look into a producer/consumer model using the SDL_Event
system to facilitate inter-thread communications.On Wed, Dec 23, 2009 at 3:20 PM, antzhi wrote:

Hi, all

I used SDL in my v4l program with SDL_mixer, SDL_timer, SDL_thread. I create
a SDL thread to grab video stream from bt878 by v4l2 and bitblt, update the
video to screen, a timer loop bitblt and update to screen 10 times a second
too. sometime the screen froze but the mp3 music still play. The program
cannot quit. Can somebody help me? thanks

Thank you, I add a mutex to fix this problem, all is ok

Brian Barrett wrote:> SDL documents that its video functions are not (in general) thread

safe, and on some platforms must be called from the main thread. You
might want to look into a producer/consumer model using the SDL_Event
system to facilitate inter-thread communications.

On Wed, Dec 23, 2009 at 3:20 PM, antzhi <@antzhi> wrote:

Hi, all

I used SDL in my v4l program with SDL_mixer, SDL_timer, SDL_thread. I create
a SDL thread to grab video stream from bt878 by v4l2 and bitblt, update the
video to screen, a timer loop bitblt and update to screen 10 times a second
too. sometime the screen froze but the mp3 music still play. The program
cannot quit. Can somebody help me? thanks


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Strictly speaking, SDL does not support blitting to the screen from
different threads, regardless of the presence of mutexes. If you want your
application to be portable, you will need a more robust solution.On Wed, Dec 23, 2009 at 8:24 PM, antzhi wrote:

Thank you, I add a mutex to fix this problem, all is ok

yes, maybe i need a “blit” thread to do all blitting

Brian Barrett wrote:> Strictly speaking, SDL does not support blitting to the screen from different threads, regardless of the presence of mutexes. If you want your application to be portable, you will need a more robust solution.

On Wed, Dec 23, 2009 at 8:24 PM, antzhi <@antzhi (@antzhi)> wrote:

  Thank you, I add a mutex to fix this problem, all is ok