Windows Mobile uses SDL for video display (with SDL Lib for mobile)

Source: Internet
Author: User

The SDL library and header files used have been uploaded to the http://download.csdn.net/source/1775400

 

SDL is an open-source cross-platform multimedia development kit. It is mainly used for fast conversion and display of video formats, as well as encapsulation of user interaction responses for various platforms, such as keyboard, mouse, mobile phone buttons, and touch screens, it is widely used in games and multimedia players. Currently, it supports windows, Linux, WinCE, Mac OS, and Symbian OS.

 

Generally, the output image of the video decoder is in yuv420 format, while the screen size is generally rgb42. Generally, the screen display on mobile is directly written to the screen through decode> yuv2rgb> scale> DirectDraw. Using SDL can accelerate this process and make it easier to respond to user operations such as full screen scaling.

 

The following describes how to use SDL to accelerate video display on mobile.

 

1. Pass the window handle of the Main Dialog box to the display class.

 

2. initialize SDL and set the video display mode.

 

Sdl_surface * screen;
Sdl_rect;
Sdl_overlay * BMP;

Bool initsdl ()

{

Char sdl_var [64];
Sprintf (sdl_var, "sdl_windowid = 0x % lx", m_hwnd );//Main Window handle
Sdl_putenv (sdl_var );

 

Char * myvalue = sdl_getenv ("sdl_windowid ");

Atexit (sdl_quit );

 

// Initialize SDL based on the decoded video size

Screen = sdl_setvideomode (imagewidth, imageheight, 0, sdl_anyformat | sdl_resizable | sdl_doublebuf | sdl_hwsurface); // note the flags parameter.
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. Draw pixels on the screen

 

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 is the struct that stores the decoded YUV data in FFMPEG.

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); // display the image to the screen

}

 

4. Event polling and key response

 

Void sdlevent ()
{

Sdl_event event;

While (sdl_pollevent (& event ))
{
Trace (L "======== SDL videoresize event start ");
Switch (event. type)
{
Case sdl_videoresize:
// Responds to image scaling events

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 );
If (BMP = NULL)
{
Trace (L "bm1 = NULL ");
Return;
}
Isqcif = true;
}
Else
{
Screen = sdl_setvideomode (image_primary_width, image_primary_height,
0, sdl_anyformat | sdl_resizable | sdl_doublebuf | sdl_hwsurface );
If (screen = NULL)
{
Trace (L "screen1 = NULL ");
Return;
}

BMP = sdl_createyuvoverlay (image_primary_width, image_primary_height,
Sdl_yv12_overlay, screen );
If (BMP = NULL)
{
Trace (L "bm1 = NULL ");
Return;
}

Isqcif = false;
}

Break;
}

 Case sdl_mousebuttondown:

// Responds to the touch screen Click Event
Break;
}
Case sdl_quit:
// Response to exit event
Break;
Default:
Break;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.