A (failed) attempt to play two videos with SMPEG

Here is an attempt to play two mpeg clips simultaneously on screen on two
disjoint regions of screen.

The problem is the first clip plays fine, but the second one flickers real bad.

Basically, this program plays two videos on two separate surfaces, and blitting
those surfaces on separate regions of screen. I am using separate SMPEG
call back functions in SMPEG_setdisplay() to accomplish this.

Please let me know if you see anything wrong with this program. Is there any
other way, two video clips can be displayed simultaneously on the screen?

Regards,
Laeeq Khan---------------------

#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <smpeg/smpeg.h>

SDL_Surface *screen;
SDL_Rect dst;
SDL_Rect dst_2;
SMPEG *mpeg;
SMPEG *mpeg_2;
SMPEG_Info info;
SMPEG_Info info_2;

SDL_Surface *surf_1;
SDL_Surface *surf_2;
Uint32 rmask, gmask, bmask, amask;

void updateMPEGFrame(SDL_Surface *buffer, Sint32 x, Sint32 y,
Uint32 w, Uint32 h)
{
SDL_BlitSurface(buffer, NULL, screen, &dst);
//SDL_Flip(screen);
SDL_UpdateRect(screen, dst.x, dst.y, dst.w, dst.h);
}

void updateMPEGFrame_2(SDL_Surface *buffer, Sint32 x, Sint32 y,
Uint32 w, Uint32 h)
{
SDL_BlitSurface(buffer, NULL, screen, &dst_2);
//SDL_Flip(screen);
SDL_UpdateRect(screen, dst_2.x, dst_2.y, dst_2.w, dst_2.h);
}

int main( int argc, char* argv[] )
{
SDL_Surface *sTemp;

if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0)
{
printf("%s:%u SDL initialization error\n", FILE, LINE);
return 1;
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(640, 480, 0, 0);
if(screen == NULL)
{
printf("%s:%u Unable to set video mode\n", FILE, LINE);
return 1;
}

dst.x = dst.y = 0;
dst.w = 160;
dst.h = 128;

dst_2.x = 0;
dst_2.y = 140;
dst_2.w = 352;
dst_2.h = 240;

// Create surface,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff0000ff;
#endif

sTemp = SDL_CreateRGBSurface(SDL_SWSURFACE, 640, 480, 32,
rmask, gmask, bmask, amask);
if(sTemp == NULL)
{
printf("%s:%u Failed to create RGB surface\n", FILE, LINE);
return 1;
}
else
printf("%s:%u RGB surface created\n", FILE, LINE);

surf_1=SDL_DisplayFormat(sTemp);
SDL_FreeSurface(sTemp);
//--------- 2 --------
sTemp = SDL_CreateRGBSurface(SDL_SWSURFACE, 640, 480, 32,
rmask, gmask, bmask, amask);
if(sTemp == NULL)
{
printf("%s:%u Failed to create RGB surface\n", FILE, LINE);
return 1;
}
else
printf("%s:%u RGB surface created\n", FILE, LINE);

surf_2=SDL_DisplayFormat(sTemp);
SDL_FreeSurface(sTemp);

//--------------- 1 --------------

mpeg = SMPEG_new("/home/laeeq/mpg_files/mm.mpg", &info, 1);
if(info.has_video)
printf(“w = %d, h = %d\n”, info.width, info.height);
else
{
printf("%s:%u no video found\n", FILE, LINE);
return 1;
}

// SMPEG_setdisplay(mpeg, screen, NULL, NULL);
SMPEG_setdisplay(mpeg, surf_1, NULL, updateMPEGFrame);
SMPEG_scaleXY(mpeg, 160, 128);
SMPEG_play(mpeg);

// ----------- 2 ----------------

mpeg_2 = SMPEG_new("/home/laeeq/mpg_files/billG.mpg", &info_2, 1);
if(info_2.has_video)
printf(“w = %d, h = %d\n”, info_2.width, info_2.height);
else
{
printf("%s:%u no video found\n", FILE, LINE);
return 1;
}
SMPEG_move(mpeg_2, 100, 140);
SMPEG_scaleXY(mpeg_2, 352, 240);
SMPEG_setdisplay(mpeg_2, surf_2, NULL, updateMPEGFrame_2);
SMPEG_play(mpeg_2);

SDL_Delay(5000);

SMPEG_delete(mpeg);
SMPEG_delete(mpeg_2);
SDL_Quit();
return 0;
}