How to write SMPEG call back function

I have successfully written some small examples with SMPEG library. In all
these examples I used NULL as call-back function pointer in
SMPEG_setdisplay(…, screen, NULL, NULL) call.

The only examples of non-null call-back functions I can come across have one
line function body consisting of SDL_UpdateRect(screen, x, y, w, h);

I need some guidance as to how to write a non-trivial call back function,
and use it in SMPEG_setdisplay() call.

Any help is appreciated.

Hello Laeeq,

I wrote this callback function, maybe it is not whatever you are looking
for…but anyway, I post it here:

void UpdateMPEGFrame(SDL_Surface *buffer, Sint32 x, Sint32 y, Uint32 w,
Uint32 h)

{

// if there is a filter selected…

if(iFXVideo!=FXSCREEN_NULL) IScreenFX->RenderFX(buffer,screen,iFXVideo);

// dump to screen

SDL_Flip(screen);

// Increase frame counter

iCurrentFrame++;

}

bye> ----- Original Message -----

From: laeeq_m_khan@hotmail.com (Laeeq Khan)
To:
Sent: Sunday, July 24, 2005 3:32 AM
Subject: [SDL] How to write SMPEG call back function.

I have successfully written some small examples with SMPEG library. In all
these examples I used NULL as call-back function pointer in
SMPEG_setdisplay(…, screen, NULL, NULL) call.

The only examples of non-null call-back functions I can come across have
one line function body consisting of SDL_UpdateRect(screen, x, y, w, h);

I need some guidance as to how to write a non-trivial call back function,
and use it in SMPEG_setdisplay() call.

Any help is appreciated.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I have successfully written some small examples with SMPEG library. In all
these examples I used NULL as call-back function pointer in
SMPEG_setdisplay(…, screen, NULL, NULL) call.

The only examples of non-null call-back functions I can come across have
one line function body consisting of SDL_UpdateRect(screen, x, y, w, h);

I need some guidance as to how to write a non-trivial call back function,
and use it in SMPEG_setdisplay() call.

Any help is appreciated.

Hi Robert,

May be my question is much simpler than what you showed me. Basically I want to
write a SMPEG_setdisplay() call-back function, which displays the video play
back on an SDL_Surface OTHER THEN screen (monitor). And later I want the
call-back function, to blit that surface on screen, and update only the area
occupied by that surface, leaving rest of the screen untouched.

Can it be done?

Regards,
-Laeeq> ----- Original Message -----

From: “Laeeq Khan” <laeeq_m_khan hotmail.com>
To: <sdl libsdl.org>
Sent: Sunday, July 24, 2005 3:32 AM
Subject: [SDL] How to write SMPEG call back function.


SDL mailing list
SDL libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi again,

I think I understand whatever you want to do… do you want to play a video
mixing it with your stuff?
so, the solution that I know…will be:

…your loading mpeg code…

SMPEG_setdisplay(mpeg,sBackbuffer,NULL,UpdateMPEGFrame);
SMPEG_play(mpeg);

…your waiting to finish the video or whatever you want…

mpeg is the “handle” to opened mpeg. sBackbuffer will be a pointer to
created surface with the size of your video (if you dont do a scaled play).
And UpdateMPEGFrame() could be as folllow:

void UpdateMPEGFrame(SDL_Surface *buffer, Sint32 x, Sint32 y,Uint32 w,Uint32
h)
{
SDL_BlitSurface(buffer,NULL,screen,_YourRectWithDesiredDestinationCoordinates);
iCurrentFrame++; // if you want to know the current frame and only update
with it changes
}

If you have any other problems, please, let me know :slight_smile:

good luck!

bye
Rober> ----- Original Message -----

From: laeeq_m_khan@hotmail.com (Laeeq Khan)
To:
Sent: Monday, July 25, 2005 5:31 PM
Subject: [SDL] Re: How to write SMPEG call back function.

----- Original Message -----
From: “Laeeq Khan” <laeeq_m_khan hotmail.com>
To: <sdl libsdl.org>
Sent: Sunday, July 24, 2005 3:32 AM
Subject: [SDL] How to write SMPEG call back function.

I have successfully written some small examples with SMPEG library. In
all
these examples I used NULL as call-back function pointer in
SMPEG_setdisplay(…, screen, NULL, NULL) call.

The only examples of non-null call-back functions I can come across
have
one line function body consisting of SDL_UpdateRect(screen, x, y, w,
h);

I need some guidance as to how to write a non-trivial call back
function,
and use it in SMPEG_setdisplay() call.

Any help is appreciated.

Hi Robert,

May be my question is much simpler than what you showed me. Basically I
want to
write a SMPEG_setdisplay() call-back function, which displays the video
play
back on an SDL_Surface OTHER THEN screen (monitor). And later I want the
call-back function, to blit that surface on screen, and update only the
area
occupied by that surface, leaving rest of the screen untouched.

Can it be done?

Regards,
-Laeeq


SDL mailing list
SDL libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Roberto Prieto <dm2 mi.madritel.es> writes:

Hi again,

I think I understand whatever you want to do… do you want to play a video
mixing it with your stuff?
so, the solution that I know…will be:

…your loading mpeg code…

SMPEG_setdisplay(mpeg,sBackbuffer,NULL,UpdateMPEGFrame);
SMPEG_play(mpeg);

…your waiting to finish the video or whatever you want…

mpeg is the “handle” to opened mpeg. sBackbuffer will be a pointer to
created surface with the size of your video (if you dont do a scaled play).
And UpdateMPEGFrame() could be as folllow:

void UpdateMPEGFrame(SDL_Surface *buffer, Sint32 x, Sint32 y,Uint32 w,Uint32
h)
{
SDL_BlitSurface
(buffer,NULL,screen,_YourRectWithDesiredDestinationCoordinates);> iCurrentFrame++; // if you want to know the current frame and only update
with it changes
}

If you have any other problems, please, let me know :slight_smile:

good luck!

bye
Rober

----- Original Message -----
From: “Laeeq Khan” <Laeeq_M_Khan hotmail.com>
To: <sdl libsdl.org>
Sent: Monday, July 25, 2005 5:31 PM
Subject: [SDL] Re: How to write SMPEG call back function.

----- Original Message -----
From: “Laeeq Khan” <laeeq_m_khan hotmail.com>
To: <sdl libsdl.org>
Sent: Sunday, July 24, 2005 3:32 AM
Subject: [SDL] How to write SMPEG call back function.

I have successfully written some small examples with SMPEG library. In
all
these examples I used NULL as call-back function pointer in
SMPEG_setdisplay(…, screen, NULL, NULL) call.

The only examples of non-null call-back functions I can come across
have
one line function body consisting of SDL_UpdateRect(screen, x, y, w,
h);

I need some guidance as to how to write a non-trivial call back
function,
and use it in SMPEG_setdisplay() call.

Any help is appreciated.

Hi Robert,

May be my question is much simpler than what you showed me. Basically I
want to
write a SMPEG_setdisplay() call-back function, which displays the video
play
back on an SDL_Surface OTHER THEN screen (monitor). And later I want the
call-back function, to blit that surface on screen, and update only the
area
occupied by that surface, leaving rest of the screen untouched.

Can it be done?

Regards,
-Laeeq


SDL mailing list
SDL libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi Robert,

I think I incorporated the technique you described, but all I am getting is a
blank screen. Do you think, I am doing something wrong in my use of call-back
function in SMPEG_setdisplay().

Regards,
-Laeeq

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

SDL_Surface *screen;
SDL_Rect dst;
SMPEG *mpeg;
SMPEG_Info info;

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

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

int main()
{
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 = 640;
dst.h = 400;

// 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

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

mpeg = SMPEG_new("/home/laeeq/mpg_files/coin_fall.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_play(mpeg);
SDL_Delay(5*1000);
SMPEG_delete(mpeg);
SDL_Quit();
return 0;
}


Hello Laeeq,

I have seen your code and basically you need to do a call to
SDL_Flip(screen).

I have modified your code and now, this works!. SDL_Flip(screen) is on SMPEG
callback, it only dumps to screen when a frame change. Also, I have included
a SDL_DisplayFormat(), you have to use it ALWAYS after SDL_SetVideoMode()
when you load/create a surface, you believe me, it avoids you a lot of
headaches :).

well, if you have any other problems, let me know :). I would to see you
final software.

Cheers!

#include <stdlib.h>
#include <stdio.h>
//#include <unistd.h>
#include “sdl/SDL.h”
#include “sdl/smpeg.h”

SDL_Surface *screen;
SDL_Rect dst;
SMPEG *mpeg;
SMPEG_Info info;

SDL_Surface *surf_1;
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);
}

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 = 640;
dst.h = 400;

// 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, 400, 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);

mpeg = SMPEG_new(“1.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_play(mpeg);
int done=0;
while(!done && ((SMPEG_status(mpeg)==SMPEG_PLAYING)))
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
if(event.key.keysym.sym==SDLK_ESCAPE) done=1;
break;
case SDL_QUIT:
done=1;
break;
default:
break;
}
}
SDL_Delay(200);
}
SMPEG_delete(mpeg);
SDL_Quit();
return 0;
}> ----- Original Message -----

From: laeeq_m_khan@hotmail.com (Laeeq Khan)
To:
Sent: Wednesday, July 27, 2005 9:33 PM
Subject: [SDL] Re: How to write SMPEG call back function.

Roberto Prieto <dm2 mi.madritel.es> writes:

Hi again,

I think I understand whatever you want to do… do you want to play a
video
mixing it with your stuff?
so, the solution that I know…will be:

…your loading mpeg code…

SMPEG_setdisplay(mpeg,sBackbuffer,NULL,UpdateMPEGFrame);
SMPEG_play(mpeg);

…your waiting to finish the video or whatever you want…

mpeg is the “handle” to opened mpeg. sBackbuffer will be a pointer to
created surface with the size of your video (if you dont do a scaled
play).
And UpdateMPEGFrame() could be as folllow:

void UpdateMPEGFrame(SDL_Surface *buffer, Sint32 x, Sint32 y,Uint32
w,Uint32
h)
{
SDL_BlitSurface
(buffer,NULL,screen,_YourRectWithDesiredDestinationCoordinates);
iCurrentFrame++; // if you want to know the current frame and only update
with it changes
}

If you have any other problems, please, let me know :slight_smile:

good luck!

bye
Rober

----- Original Message -----
From: “Laeeq Khan” <Laeeq_M_Khan hotmail.com>
To: <sdl libsdl.org>
Sent: Monday, July 25, 2005 5:31 PM
Subject: [SDL] Re: How to write SMPEG call back function.

----- Original Message -----
From: “Laeeq Khan” <laeeq_m_khan hotmail.com>
To: <sdl libsdl.org>
Sent: Sunday, July 24, 2005 3:32 AM
Subject: [SDL] How to write SMPEG call back function.

I have successfully written some small examples with SMPEG library.
In
all
these examples I used NULL as call-back function pointer in
SMPEG_setdisplay(…, screen, NULL, NULL) call.

The only examples of non-null call-back functions I can come across
have
one line function body consisting of SDL_UpdateRect(screen, x, y, w,
h);

I need some guidance as to how to write a non-trivial call back
function,
and use it in SMPEG_setdisplay() call.

Any help is appreciated.

Hi Robert,

May be my question is much simpler than what you showed me. Basically I
want to
write a SMPEG_setdisplay() call-back function, which displays the video
play
back on an SDL_Surface OTHER THEN screen (monitor). And later I want
the
call-back function, to blit that surface on screen, and update only the
area
occupied by that surface, leaving rest of the screen untouched.

Can it be done?

Regards,
-Laeeq


SDL mailing list
SDL libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi Robert,

I think I incorporated the technique you described, but all I am getting
is a
blank screen. Do you think, I am doing something wrong in my use of
call-back
function in SMPEG_setdisplay().

Regards,
-Laeeq

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

SDL_Surface *screen;
SDL_Rect dst;
SMPEG *mpeg;
SMPEG_Info info;

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

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

int main()
{
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 = 640;
dst.h = 400;

// 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

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

mpeg = SMPEG_new("/home/laeeq/mpg_files/coin_fall.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_play(mpeg);
SDL_Delay(5*1000);
SMPEG_delete(mpeg);
SDL_Quit();
return 0;
}



SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi Robert,

Your program indeed works, thank you very much. Now I will use this technique
to play two videos simultaneously on the screen, I will let you know how it
goes.

Regards,
Laeeq