繁体   English   中英

在android中使用sdl

[英]using sdl in android

我已经成功为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;
  }

提前致谢!

你缺少一个SDL_FlipSDL_UpdateRect被叫做你的主要SDL_surface,这将更新它在屏幕上。

据我所知,您正在尝试移植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;
    }
    */

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM