|
|
我用SDL写了一个播放YUV序列的程序,可是运行后窗口一直是黑的,什么都没有,哪位大侠知道是什么原因吗?
谢谢
程序如下:
[PHP]#include <SDL.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#define W 176
#define H 144
#define FILENAME "foreman.qcif"
int
main()
{
SDL_Surface *screen;
SDL_Overlay* overlay;
SDL_Rect overlayrect;
int imgsize_y = W * H;
int imgsize_uv = W * H / 4;
int fd;
int i;
char *pic;
int framesz = imgsize_y + 2 * imgsize_uv;
if ((fd = open(FILENAME, O_RDONLY)) < 0) {
perror("open");
exit(1);
}
pic = malloc(framesz);
if (NULL == pic) {
fprintf(stderr, "memory allocation error occured.\n");
exit(1);
}
/* Initialize the SDL library */
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
"Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
}
/* Clean up on exit */
atexit(SDL_Quit);
/*
* Initialize the display in a 640x480 8-bit palettized mode,
* requesting a software surface
*/
screen = SDL_SetVideoMode(W, H, 0, SDL_SWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n",
SDL_GetError());
exit(1);
}
overlay = SDL_CreateYUVOverlay(W, H, SDL_YV12_OVERLAY, screen);
if (!overlay) {
fprintf(stderr, "Couldn't create overlay: %s\n", SDL_GetError());
exit(1);
}
printf("Created %dx%dx%d %s %s overlay\n",overlay->w,overlay->h,overlay->planes,
overlay->hw_overlay?"hardware":"software",
overlay->format==SDL_YV12_OVERLAY?"YV12":
overlay->format==SDL_IYUV_OVERLAY?"IYUV":
overlay->format==SDL_YUY2_OVERLAY?"YUY2":
overlay->format==SDL_UYVY_OVERLAY?"UYVY":
overlay->format==SDL_YVYU_OVERLAY?"YVYU":
"Unknown");
for(i=0; i<overlay->planes; i++) {
printf("plane %d: pitch=%d\n", i, overlay->pitches);
}
overlayrect.x=0;
overlayrect.y=0;
overlayrect.w=W;
overlayrect.h=H;
i = 0;
while (read(fd, pic, framesz) == framesz) {
fprintf(stderr, "Frame: %d\n", ++i);
SDL_LockSurface(screen);
SDL_LockYUVOverlay(overlay);
memcpy(overlay->pixels[0], pic, imgsize_y);
memcpy(overlay->pixels[1], pic + imgsize_y, imgsize_uv);
memcpy(overlay->pixels[2], pic + imgsize_y + imgsize_uv, imgsize_uv);
SDL_UnlockYUVOverlay(overlay);
SDL_UnlockSurface(screen);
SDL_DisplayYUVOverlay(overlay, &overlayrect);
SDL_Delay(200);
}
SDL_FreeYUVOverlay(overlay);
free(pic);
close(fd);
return 0;
}
[/PHP] |
|