Skip to content

Commit

Permalink
Added FPS info to THEORAPLAY_YuvVideoItem.
Browse files Browse the repository at this point in the history
SDL player will now try to catch up if it's falling behind in video.
  • Loading branch information
icculus committed Jun 11, 2011
1 parent 738e5a8 commit 4191073
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/sdltheoraplay.c
Expand Up @@ -97,6 +97,7 @@ static void playfile(const char *fname)
SDL_Surface *screen = NULL;
SDL_Overlay *overlay = NULL;
SDL_Event event;
Uint32 framems = 0;
int initfailed = 0;
int quit = 0;

Expand Down Expand Up @@ -133,6 +134,7 @@ static void playfile(const char *fname)
// Set the video mode as soon as we know what it should be.
if (video)
{
framems = (video->fps == 0.0) ? 0 : ((Uint32) (1000.0 / video->fps));
screen = SDL_SetVideoMode(video->width, video->height, 0, 0);
if (!screen)
fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
Expand Down Expand Up @@ -181,7 +183,10 @@ static void playfile(const char *fname)
if (video && (video->playms <= now))
{
//printf("Play video frame (%u ms)!\n", video->playms);
if (SDL_LockYUVOverlay(overlay) == -1)
if ( framems && ((now - video->playms) >= framems) )
; // do nothing, skip this frame to catch up.

else if (SDL_LockYUVOverlay(overlay) == -1)
{
static int warned = 0;
if (!warned)
Expand Down
1 change: 1 addition & 0 deletions theoraplay.c
Expand Up @@ -321,6 +321,7 @@ static void WorkerThread(TheoraDecoder *ctx)
YuvVideoItem *item = (YuvVideoItem *) malloc(sizeof (YuvVideoItem));
if (item == NULL) goto cleanup;
item->playms = (fps == 0) ? 0.0 : (unsigned long) ((((double) videoframes) / fps) * 1000.0);
item->fps = fps;
item->width = w;
item->height = h;
item->yuv = (unsigned char *) malloc(w * h * 2);
Expand Down
1 change: 1 addition & 0 deletions theoraplay.h
Expand Up @@ -18,6 +18,7 @@ typedef struct THEORAPLAY_Decoder THEORAPLAY_Decoder;
typedef struct THEORAPLAY_YuvVideoItem
{
unsigned int playms;
double fps;
unsigned int width;
unsigned int height;
unsigned char *yuv;
Expand Down

0 comments on commit 4191073

Please sign in to comment.