From 789ed99ffdeae638e9191ca99272e536f36f6934 Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 29 Mar 2005 20:07:22 +0000 Subject: Added a lot of error detection stuff to the camera, player, encoder and decoder objects. --- src/player.cc | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'src/player.cc') diff --git a/src/player.cc b/src/player.cc index 85a961a..db5b108 100644 --- a/src/player.cc +++ b/src/player.cc @@ -31,6 +31,9 @@ Player::Player(Error *err, Queue *gqueue, pthread_mutex_t *gmutex) { + // No errors has ocurred... yet! + noErrors = true; + char errbuf[256]; errobj = err; @@ -42,28 +45,39 @@ Player::Player(Error *err, sem_init(&play_sem, 0, 1); if(SDL_Init(SDL_INIT_VIDEO) < 0) { - sprintf(errbuf, "Unable to init SDL: %s\n", SDL_GetError()); + sprintf(errbuf, "Unable to init SDL: %s.", SDL_GetError()); errobj->pushError(errbuf); + noErrors = false; return; } + screen = SDL_SetVideoMode(DISPLAYWIDTH, DISPLAYHEIGHT, - 16, - SDL_HWSURFACE|SDL_ANYFORMAT|SDL_HWACCEL); + 0, // 0 bpp means 'use current display depth' + SDL_HWSURFACE | SDL_ANYFORMAT | SDL_HWACCEL); + if(!screen) { - sprintf(errbuf, "Unable to set %dx%d video: %s\n", + sprintf(errbuf, "Unable to set %dx%d video: %s.", DISPLAYWIDTH, DISPLAYHEIGHT, SDL_GetError()); errobj->pushError(errbuf); + noErrors = false; return; } - overlay = SDL_CreateYUVOverlay(DISPLAYWIDTH, DISPLAYHEIGHT, SDL_IYUV_OVERLAY, screen); + overlay = SDL_CreateYUVOverlay(DISPLAYWIDTH, + DISPLAYHEIGHT, + SDL_IYUV_OVERLAY, screen); + if(!overlay) { + sprintf(errbuf, "Unable to create SDL overlay: %s.", SDL_GetError()); + errobj->pushError(errbuf); + noErrors = false; + return; + } } Player::~Player() { - if(overlay) - SDL_FreeYUVOverlay(overlay); + SDL_FreeYUVOverlay(overlay); SDL_Quit(); } @@ -76,8 +90,9 @@ void Player::player() int i; struct timespec ts; - // rect.x = 20; - // rect.y = 182; + if(!noErrors) return; // FIXME: Gracefully exit... + + // Setup the displayarea. rect.x = 0; rect.y = 0; rect.w = DISPLAYWIDTH; @@ -94,7 +109,7 @@ void Player::player() sem_wait(&play_sem); sem_post(&play_sem); - if(!SDL_WaitEvent(&event)) break; // FIXME: Gracefull exit... + if(!SDL_WaitEvent(&event)) break; // FIXME: Gracefully exit... switch(event.type) { case SDL_KEYDOWN: -- cgit v1.2.3