How to accelerate

Hello!
I have to program for a video system under linux
which gathers video data from CCD camera and displays.I
have completed the driver for gathering card. But because
I’m a newbie to video programming, I have some difficults.
The system needs display 25-50 frames per second.Each frame can be
10241024 or 512512 with 8 bits per pixel.The video data
are all grayscale.A friend introduced SDL to me.And I have
made a test.Everything is ok but the display speed.
Following are my main test codes:

SDL_Color colors[256];
for (i = 0; i < 256; i++) {
colors[i].r = colors[i].g = colors[i].b = i;
}

if (SDL_Init(SDL_INIT_VIDEO)==-1) {
   ...
}

screen = SDL_SetVideoMode(..., SDL_HWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN);

src = SDL_CreateRGBSurface(SDL_SWSURFACE,...);

result = SDL_SetColors(screen, colors, 0, 256);

result =  SDL_SetColors(src[0], colors, 0, 256);
int n = 0;
int speed = 0;
Uint32 stime = SDL_GetTicks();

while(n < 1000) {
	if (SDL_MUSTLOCK(src)) {
		if (SDL_LockSurface(src)<0)
			fexit();
	}

	...mydrawingfunction which draws a frame by pixel
	with two for loop
	
	if (SDL_MUSTLOCK(src))
		SDL_UnlockSurface(src);

	SDL_BlitSurface(src, NULL, screen, NULL);

	SDL_UpdateRect(screen, 0, 0, 0, 0);
	n = SDL_GetTicks() - stime;
	speed ++;
}

When displaying 512512 frames, the speed can only reach 26-32 frames per second.
The SDL_GetVideoInfo() tells the hw_available and blit_
are all false and no
video_mem.
I use a nvidia geforce2 mx video card and have installed the official drvier.And
mplayer runs fluently with this card.My system is RH 9.0 and I install SDL just
with ./configure --enable-nanox-share-memory --enable-nanox-direct-fb
and make/make install.
How can I get hardware acceleration for SDL?
Or should I change the codes to accelerate?
Any help is preciated.

The SDL_GetVideoInfo() tells the hw_available and blit_* are all false
and no
video_mem.

I have this same problem on Mac OS X. I don’t know the story for yours,
but its probably either uncoded or impossible with the given
environment.

In Mac OS X’s case, I am told, it is the latter. Hardware surfaces are
not possible because of the way the operating system is designed. I’m
just SOL. If it’s the same for you, you’ll never be able to get
framerates as high they would be with hardware surfaces.

How can I get hardware acceleration for SDL?
Or should I change the codes to accelerate?

See if anyone knows the status of SDL in your environment. Maybe HW
acceleration is possible. Either way, one can always benefit from
optimizing source code. It’s when developing on an older or limited
system (like no HW support) that slow code hurts most. Profile the
execution of your code to find where the slow spots are, and focus
optimization there. The drawing function is a likely candidate.

Hope that helps,
phip

SDL_Color colors[256];
for (i = 0; i < 256; i++) {
colors[i].r = colors[i].g = colors[i].b = i;
}

if (SDL_Init(SDL_INIT_VIDEO)==-1) {

}

screen = SDL_SetVideoMode(…, SDL_HWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN);

What is exactly the command you are using, show us what is hidden behind
this “…” :slight_smile: .

src = SDL_CreateRGBSurface(SDL_SWSURFACE,…);

result = SDL_SetColors(screen, colors, 0, 256);

result = SDL_SetColors(src[0], colors, 0, 256);
int n = 0;
int speed = 0;
Uint32 stime = SDL_GetTicks();

while(n < 1000) {
if (SDL_MUSTLOCK(src)) {
if (SDL_LockSurface(src)<0)
fexit();
}

  ...mydrawingfunction which draws a frame by pixel
  with two for loop
  
  if (SDL_MUSTLOCK(src))
  	SDL_UnlockSurface(src);

  SDL_BlitSurface(src, NULL, screen, NULL);

You should use the same format (bit depth …) for src and screen,
otherwise, SDL will convert src on the fly, which is a time consumming
operation. In your case, since you change src every frame you should
initialize the video mode so that it fits src format => no on the fly
convertion. So, you must start you X server in 8 bits.

Julien

wgkun at mailst.xjtu.edu.cn wrote:

Hello!
I have to program for a video system under linux
which gathers video data from CCD camera and displays.I
have completed the driver for gathering card. But because
I’m a newbie to video programming, I have some difficults.
The system needs display 25-50 frames per second.Each frame can be
10241024 or 512512 with 8 bits per pixel.The video data
are all grayscale.A friend introduced SDL to me.And I have
made a test.Everything is ok but the display speed.
Following are my main test codes:

Why not to draw directly to the video surface or make the video surface
a sw surface and let SDL_UpdateRects() do the blit?

I think that having a video surface that is a HW surface and blitting a
SW surface to it is always slower of both the previous solutions.

As pointed out is also a MUST that your full screen resolution is 8bit
depth as your source datas. Maybe to get this to work correcly on X you
should log as root and do export SDL_VIDEODRIVER=dga.

50fps should be quite easy to reach on 8bit depth 1024x1024 buffers on
non-prehistoric hardware, just make sure there are no conversions, 8 ->
16 and 8 -> 32 conversions are very expensive!

Bye,
Gabry