1

我已经成功地交叉编译了 android 平台的 sdl 库,现在我想在 android 屏幕中显示我的 sdl 表单,如 SDL_Surface 和 SDL_Rect 。这怎么可能?

这是我的第一次尝试

  SDLRenderer::SDLRenderer    () :
         bmp            (NULL),
         screen         (NULL),
         imgConvertCtx  (NULL),
         isInit         (false),
         quitKeyPressed (false)
  {
  }
  SDLRenderer::~SDLRenderer   ()
  {
  }

  bool    SDLRenderer::init                   (int width, int height)
  {       LOGI("sdlrenderer init");
this->screen = SDL_SetVideoMode(width, height, 0, 0);

  if(!screen){
    LOGI("!screen");
    return false;
  }

this->bmp = SDL_CreateYUVOverlay(width, height, SDL_YV12_OVERLAY, this->screen);

LOGI("SDL_CreateYUVOverlay passed");

return true;
}
bool    SDLRenderer::processEvents          ()
{
 SDL_Event sdlEvent;
 while(SDL_PollEvent(&sdlEvent))
 {
     switch(sdlEvent.type)
     {
         case SDL_KEYDOWN:
             if(sdlEvent.key.keysym.sym == SDLK_ESCAPE)
                 this->quitKeyPressed = true;
             break;
         case SDL_QUIT: this->quitKeyPressed = true; break;
     } 
 }

 return true;
}
bool    SDLRenderer::isQuitKeyPressed       ()
{
return this->quitKeyPressed;
}
void    SDLRenderer::onVideoDataAvailable   (const uint8_t **data,         videoFrameProperties* props)
{LOGI("sdlrenderer data availabe");
   if(!this->isInit){
    this->isInit = this->init(props->width, props->height);
    LOGI("sdlrenderer data availabe calling render init"); 
   }
   LOGI("before     SDL_LockYUVOverlay(bmp);"); 

SDL_LockYUVOverlay(bmp);
LOGI("after     SDL_LockYUVOverlay(bmp);"); 

AVPicture pict;
LOGI("after    AVPicture pict;"); 

pict.data[0] = bmp->pixels[0];
pict.data[1] = bmp->pixels[2];
pict.data[2] = bmp->pixels[1];

pict.linesize[0] = bmp->pitches[0];
pict.linesize[1] = bmp->pitches[2];
pict.linesize[2] = bmp->pitches[1];
  LOGI("after     creating avpicture"); 

// Convert the image into YUV format that SDL uses
if(imgConvertCtx == NULL)
{
    int w = props->width;
    int h = props->height;

    imgConvertCtx = sws_getContext(props->width, props->height, (PixelFormat)props-     >pxlFmt, w, h, PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);

    if(imgConvertCtx == NULL)
    { LOGI("imgConvertCtx == NULL"); 

        fprintf(stderr, "Cannot initialize the conversion context!\n");
        exit(1);
    }
}

sws_scale(imgConvertCtx, data, props->linesize, 0, props->height, pict.data,   pict.linesize);
 LOGI("calling SDL_UnlockYUVOverlay(bmp);"); 

SDL_UnlockYUVOverlay(bmp);

rect.x = 0;
rect.y = 0;
rect.w = props->width;
rect.h = props->height;
LOGI("sdlrenderer displaying");
SDL_DisplayYUVOverlay(bmp, &rect);
}

有我的主要

int main(int argc, char *argv[])
{
    SDLRenderer     *renderer = new SDLRenderer();
    DASHReceiver    *receiver = new DASHReceiver(30); 

    receiver->Init("http://www----custom url here");

    LibavDecoder *decoder = new LibavDecoder(receiver);

    decoder->attachVideoObserver(renderer);
    decoder->setFrameRate(24);
    decoder->init();

    bool eos = false;

    while(!renderer->isQuitKeyPressed() && !eos)
  {
      eos = !decoder->decode();
      renderer->processEvents();
   }

   decoder->stop();

return 0;
  }

提前致谢!

4

2 回答 2

1

据我所知,您正在尝试移植 bitmovin 开源破折号播放器。我已经这样做了,一旦将 SDL 移植到 android,该软件的所有其他部分都可以正常工作。我的代码与您完全相同,这部分运行良好确保在 java 部分中定义表面尝试使用 SDLActivity google 并使用此处提供的 java 代码然后仔细查看此处http://lists。 libsdl.org/pipermail/sdl-libsdl.org/2011-July/081481.html对java代码做一些小的修改

    // The Unimplemented OpenGL ES API notices *always* indicate you have
    // the incorrect context version, which has to be fixed in SDLActivity.java .
    int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
    int contextAttrs[] = new int[]{
                      EGL_CONTEXT_CLIENT_VERSION, majorVersion,
                      EGL10.EGL_NONE
                       };
     EGLContext ctx = egl.eglCreateContext(dpy, config,EGL10.EGL_NO_CONTEXT, contextAttrs);
     if (ctx == EGL10.EGL_NO_CONTEXT) {
          Log.e("SDL", "Couldn't create context");
          return false;
     }

    /*
    EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null);
    if (ctx == EGL10.EGL_NO_CONTEXT) {
        Log.e("SDL", "Couldn't create context");
        return false;
    }
    */
于 2013-05-22T14:03:24.363 回答
1

You are missing an SDL_Flip or an SDL_UpdateRect to be called on your main SDL_surface, which will update it on the screen.

于 2013-04-16T17:35:41.353 回答