最近下载了V1.3的SDL源程序,并且编译成了so库,但是通过android模拟器使用SDL的库函数显示YUV视频数据时却出现了黑屏现象,无法正常显示视频,不知道是不是编译的SDL库有问题导致的?
有没有成功移植到android平台的SDL库呢?或者有没其他的方法能够将底层的音视频流通过模拟器播放显示呢?请各位帮帮忙!谢谢了!
------解决方案--------------------
sdl是开源的跨平台多媒体开发包, 主要用在快速的视频格式转换和显示,以及封装了键盘/鼠标/手机按键/触屏等各个平台的用户交互响应,广泛应用在游戏,多媒体播放器等应用中。目前支持windows,linux, wince,mac os,非正式地支持symbian os。
一般视频解码器输出图像的是yuv420格式,而屏幕显示大都是rgb42规格。 mobile上画面显示一般经由decode>>yuv2rgb>>scale>>directDraw直接写屏。 采用SDL可以加速这一过程,且更方便响应全屏缩放等用户操作。
下面介绍mobile上用sdl来加速显示视频的全过程。
1. 把主对话框的窗口句柄传给显示类。
2. 初始化sdl,设置显示视频模式
SDL_Surface *screen;
SDL_Rect sdl_rect;
SDL_Overlay *bmp;
bool InitSdl()
{
char sdl_var[64];
sprintf(sdl_var, "SDL_WINDOWID=0x%lx", m_hWnd);//主窗口句柄
SDL_putenv(sdl_var);
char *myvalue = SDL_getenv("SDL_WINDOWID");
atexit(SDL_Quit);
//根据解码后的视频尺寸来初始化sdl
screen = SDL_SetVideoMode(ImageWidth, ImageHeight, 0,SDL_ANYFORMAT|SDL_RESIZABLE|SDL_DOUBLEBUF|SDL_HWSURFACE);//注意用到的参数flags
if(!screen)
{
TRACE(L"error SDL SetVideoMode!");
return false;
}
bmp = SDL_CreateYUVOverlay(ImageWidth, ImageHeight, ,SDL_YV12_OVERLAY,screen);
if(!bmp)
{
TRACE(L"error SDL CreateYUVOverlay!");
return false;
}
return TRUE;
}
3. 在屏幕上绘制像素
void SdlDisplayFrame()
{
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];
//pFrame是ffmpeg存放解码后yuv数据的struct
img_convert(&pict, PIX_FMT_YUV420P, (AVPicture *)pFrame, pContext->pix_fmt, iImage_Width, iImage_Height);
SDL_LockSurface(screen);
SDL_LockYUVOverlay(bmp);
{
sdl_rect.x = 0;
sdl_rect.y = 0;
sdl_rect.w = m_width; //pContext->width;
sdl_rect.h = m_height; //pContext->height;
}
SDL_UnlockYUVOverlay(bmp);
SDL_UnlockSurface(screen);
SDL_DisplayYUVOverlay(bmp, &sdl_rect);//显示图片到屏幕
}
4. 事件轮询和按键响应
void SdlEvent()
{
SDL_Event event;
while ( SDL_PollEvent(&event))
{
TRACE(L"========SDL VIDEORESIZE EVENT START");
switch (event.type)
{
case SDL_VIDEORESIZE:
// 响应图像缩放事件
if (m_iImage_Width == Image_Primary_Width && m_iImage_Height == Image_Primary_Height)
{
TRACE(L"event.resize.w = %d",event.resize.w);
TRACE(L"event.resize.h = %d",event.resize.h);
m_width = event.resize.w;
m_height = event.resize.h;
SDL_FreeYUVOverlay(bmp);
bmp = NULL;
SDL_FreeSurface(screen);
screen = NULL;
if (!IsQcif)
{
m_height = m_height * 2;
m_width = m_width * 2;
screen = SDL_SetVideoMode(MobileFullScreenWidth,MobileFullScreenHeight,
0,SDL_ANYFORMAT|SDL_RESIZABLE|SDL_DOUBLEBUF|SDL_HWSURFACE);
if (screen == NULL)
{
TRACE(L"screen= NULL");
return;
}
bmp = SDL_CreateYUVOverlay(MobileFullScreenWidth,MobileFullScreenHeight,
SDL_YV12_OVERLAY,screen);