打印
[i.MX]

IMX6QSABRE-SDP板卡 SDL2.0

[复制链接]
2244|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
aniwang|  楼主 | 2015-9-15 10:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在使用imx6qsabre-sdp板卡, 移植运行linux3.10.53内核。对应的开发环境是yocto-3.10.53. 自己手动交叉编译SDL2.0.3库和实例程序,手动编译SDL2.0.3库,配置如下:
./configure --host=arm-poky-linux-gnueabi --x-include=/opt/fsl-release-bsp/build-x11/tmp/sysroots/imx6qsabresd/usr/include/ --x-libraries=/opt/fsl-release-bsp/build-x11/tmp/sysroots/imx6qsabresd/usr/lib --with-x --enable-video-x11 --enable-x11-shared --enable-video-x11-xcursor --enable-video-x11-xinerama --enable-video-x11-xinput  --enable-video-x11-xrandr --enable-video-x11-scrnsaver --enable-video-x11-xshape --enable-video-x11-vm --enable-video-dummy --enable-video-opengl --enable-video-opengles --enable-libudev --enable-dbus --enable-input-tslib --enable-pthreads --enable-pthread-sem --disable-assembly --prefix=/opt/sdl-2.0.3-lib  
这样配置后,可以正常编译出库文件,并拷贝到目标机文件系统/usr/lib下。
实例程序源码如下:

#include <stdio.h>

//extern "C"
//{
//#include "SDL2/SDL.h"
#include <SDL2/SDL.h>

//};

//set '1' to choose a type of file to play
#define LOAD_BGRA    0
#define LOAD_RGB24   0
#define LOAD_BGR24   0
#define LOAD_YUV420P 1

//Bit per Pixel
#if LOAD_BGRA
const int bpp=32;
#elif LOAD_RGB24|LOAD_BGR24
const int bpp=24;
#elif LOAD_YUV420P
const int bpp=12;
#endif

int screen_w=500,screen_h=500;
const int pixel_w=352,pixel_h=288;

unsigned char buffer[352*288*24/8];
//BPP=32
unsigned char buffer_convert[352*288*4];

//Convert RGB24/BGR24 to RGB32/BGR32
//And change Endian if needed
void CONVERT_24to32(unsigned char *image_in,unsigned char *image_out,int w,int h)
{
        int i, j;

        for(i =0;i<h;i++)
                for(j=0;j<w;j++)
                {
                        //Big Endian or Small Endian?
                        //"ARGB" order:high bit -> low bit.
                        //ARGB Format Big Endian (low address save high MSB, here is A) in memory : A|R|G|B
                        //ARGB Format Little Endian (low address save low MSB, here is B) in memory : B|G|R|A
                        if(SDL_BYTEORDER==SDL_LIL_ENDIAN){
                                //Little Endian (x86): R|G|B --> B|G|R|A
                                image_out[(i*w+j)*4+0]=image_in[(i*w+j)*3+2];
                                image_out[(i*w+j)*4+1]=image_in[(i*w+j)*3+1];
                                image_out[(i*w+j)*4+2]=image_in[(i*w+j)*3];
                                image_out[(i*w+j)*4+3]='0';
                        }else{
                                //Big Endian: R|G|B --> A|R|G|B
                                image_out[(i*w+j)*4]='0';
                                memcpy(image_out+(i*w+j)*4+1,image_in+(i*w+j)*3,3);
                        }
                }
}


//Refresh Event
#define REFRESH_EVENT  (SDL_USEREVENT + 1)

int thread_exit=0;

int refresh_video(void *opaque){
        while (thread_exit==0) {
                SDL_Event event;
                event.type = REFRESH_EVENT;
                SDL_PushEvent(&event);
                SDL_Delay(40);
        }
        return 0;
}

int main(int argc, char* argv[])
{
        if(SDL_Init(SDL_INIT_VIDEO)) {  
                printf( "Could not initialize SDL - %s\n", SDL_GetError());
                return -1;
        }

        SDL_Window *screen;
        //SDL 2.0 Support for multiple windows
        screen = SDL_CreateWindow("Simplest Video Play SDL2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
                screen_w, screen_h,SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
        if(!screen) {  
                printf("SDL: could not create window - exiting:%s\n",SDL_GetError());  
                return -1;
        }
        SDL_Renderer* sdlRenderer = SDL_CreateRenderer(screen, -1, 0);  

        Uint32 pixformat=0;
#if LOAD_BGRA
        //Note: ARGB8888 in "Little Endian" system stores as B|G|R|A
        pixformat= SDL_PIXELFORMAT_ARGB8888;  
#elif LOAD_RGB24
        pixformat= SDL_PIXELFORMAT_RGB888;  
#elif LOAD_BGR24
        pixformat= SDL_PIXELFORMAT_BGR888;  
#elif LOAD_YUV420P
        //IYUV: Y + U + V  (3 planes)
        //YV12: Y + V + U  (3 planes)
        pixformat= SDL_PIXELFORMAT_IYUV;  
#endif

        SDL_Texture* sdlTexture = SDL_CreateTexture(sdlRenderer,pixformat, SDL_TEXTUREACCESS_STREAMING,pixel_w,pixel_h);



        FILE *fp=NULL;
#if LOAD_BGRA
        fp=fopen("test_bgra_320x180.rgb","rb+");
#elif LOAD_RGB24
        fp=fopen("../test_rgb24_320x180.rgb","rb+");
#elif LOAD_BGR24
        fp=fopen("../test_bgr24_320x180.rgb","rb+");
#elif LOAD_YUV420P
        fp=fopen("/unit_tests/akiyo_cif.yuv","rb+");
#endif
        if(fp==NULL){
                printf("cannot open this file\n");
                return -1;
        }

        SDL_Rect sdlRect;  

        SDL_Thread *refresh_thread = SDL_CreateThread(refresh_video,NULL,NULL);
        SDL_Event event;
        while(1){
                //Wait
                SDL_WaitEvent(&event);
                if(event.type==REFRESH_EVENT){
                        if (fread(buffer, 1, pixel_w*pixel_h*bpp/8, fp) != pixel_w*pixel_h*bpp/8){
                                // Loop
                                fseek(fp, 0, SEEK_SET);
                                fread(buffer, 1, pixel_w*pixel_h*bpp/8, fp);
                        }

#if LOAD_BGRA
                        //We don't need to change Endian
                        //Because input BGRA pixel data(B|G|R|A) is same as ARGB8888 in Little Endian (B|G|R|A)
                        SDL_UpdateTexture( sdlTexture, NULL, buffer, pixel_w*4);  
#elif LOAD_RGB24|LOAD_BGR24
                        //change 24bit to 32 bit
                        //and in Windows we need to change Endian
                        CONVERT_24to32(buffer,buffer_convert,pixel_w,pixel_h);
                        SDL_UpdateTexture( sdlTexture, NULL, buffer_convert, pixel_w*4);  
#elif LOAD_YUV420P
                        SDL_UpdateTexture( sdlTexture, NULL, buffer, pixel_w);  
#endif
                        //FIX: If window is resize
                        sdlRect.x = 0;  
                        sdlRect.y = 0;  
                        sdlRect.w = screen_w;  
                        sdlRect.h = screen_h;  
                       
                        SDL_RenderClear( sdlRenderer );   
                        SDL_RenderCopy( sdlRenderer, sdlTexture, NULL, &sdlRect);  
                        SDL_RenderPresent( sdlRenderer );  
                        //Delay 40ms
                        SDL_Delay(40);
                       
                }else if(event.type==SDL_WINDOWEVENT){
                        //If Resize
                        SDL_GetWindowSize(screen,&screen_w,&screen_h);
                }else if(event.type==SDL_QUIT){
                        break;
                }
        }

        return 0;
}


编译:arm-poky-linux-gnueabi-gcc -o sdl2play sdl2play.c -lSDL2
实例程序编译成功,无错误和警告。
目标机上运行实例出现如下问题:
root@imx6qsabresd:/unit_tests#./sdl2play
libGL error: UNIX signal already caught! libGL error: UNIX signal already caught!

相关帖子

沙发
quray1985| | 2015-9-15 11:31 | 只看该作者
楼主这个板子是做什么的啊

使用特权

评论回复
板凳
aniwang|  楼主 | 2015-9-15 14:04 | 只看该作者
主要做可视VOIP设备的。

使用特权

评论回复
地板
aniwang|  楼主 | 2015-9-15 14:07 | 只看该作者
可知道这个问题如何解决?或是我配置SDL2.0.3库有问题? 或有没有在IMX6上做个SDL2.0库显示视频的?

使用特权

评论回复
5
mini1986| | 2015-9-15 16:35 | 只看该作者
关注一下,高端产品啊......

使用特权

评论回复
6
ss1976| | 2017-7-22 14:43 | 只看该作者
你的设备有回声吗?如果有,怎么消除的呢?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

4

帖子

0

粉丝