[smpeg] Fault with smpeg under MacOS X (possibly endian issue)
Chris Nystrom
cnystrom at gmail.com
Tue Oct 11 03:40:24 EDT 2005
This code used to work with Fedora Core 3. I upgraded to Fedora Core 4
and it no longer works. Audio is ok, but the video is very grainy. I
tired it on several different machines with the same result. Is anyone
else having this problem?
Thank you,
Chris
--
#include <stdlib.h>
#include <stdio.h>
//#include <unistd.h>
#include "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;
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;
}
--
E-Mail: Chris Nystrom <cnystrom at gmail.com>
Business: http://www.shaklee.net/austin
Blog: http://conversazione.blogspot.com/
AIM: nystromchris
More information about the smpeg
mailing list