How to achieve minimum delay in rendering?

I tested how much millisecond it takes to render 1028*720 picture into the texture by below code. I got the result in milliseconds in between the values (47 to 75) .

Due to this , i get the latency, as i m trying to display 30 frames per second, which means maximum of 33.3 milliseconds is needed to render.

  1. Is it the right way of measuring the time frame?
  2. Any quirk i need to be aware of ?

Kindly Help me.

sTime = SDL_GetTicks ();
SDL_UpdateYUVTexture(bmp, NULL, nextFrame->data[0],  nextFrame->linesize[0], nextFrame->data[1], nextFrame->linesize[1],
                                                                                                nextFrame->data[2], nextFrame->linesize[2]);

SDL_RenderClear(renderer);

SDL_RenderCopy(renderer, bmp, NULL, NULL);
SDL_RenderPresent(renderer);
eTime = SDL_GetTicks ();
LOGE (" Time taken for Rendering… %ld ", eTime - sTime);

SDL_RenderPresent(renderer) might be waiting for Vsync, that’s probably why
the time is so high. Do all your game loop work before calling
SDL_RenderPresent(),
because it will block while waiting for Vsync. To test whether that is
indeed happening, measure the time taken by SDL_RenderPresent().

Pallav Nawani
IronCode Gaming Private Limited
Website: http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming
Mobile: 9997478768On Tue, Jun 3, 2014 at 5:12 PM, keestu wrote:

I tested how much millisecond it takes to render 1028*720 picture into
the texture by below code. I got the result in milliseconds in between the
values (47 to 75) .

Due to this , i get the latency, as i m trying to display 30 frames per
second, which means maximum of 33.3 milliseconds is needed to render.

  1. Is it the right way of measuring the time frame?
  2. Any quirk i need to be aware of ?

Kindly Help me.

sTime = SDL_GetTicks ();
SDL_UpdateYUVTexture(bmp, NULL, nextFrame->data[0],
nextFrame->linesize[0], nextFrame->data[1], nextFrame->linesize[1],
nextFrame->data[2], nextFrame->linesize[2]);

SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, bmp, NULL, NULL);
SDL_RenderPresent(renderer);
eTime = SDL_GetTicks ();
LOGE (" Time taken for Rendering… %ld ", eTime - sTime);


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks, and sure i will check with how much time it is been taken for RenderPresent alone.

What i m doing this: There is a global variable pFrame, which is getting populated with frame by thead, and pushes the event to display.
So, my main event loop is something like:

while (SDL_PollEvent (&event)) {

case DISPLAY_MY_FRAME:
/// Here i do
SDL_UpdateYUVTexture(bmp, NULL, pFrame->data[0], pFrame->linesize[0], pFrame->data[1], pFrame->linesize[1],
pFrame->data[2], pFrame->linesize[2]);

          SDL_RenderClear(renderer);
          SDL_RenderCopy(renderer, bmp, NULL, NULL);
          SDL_RenderPresent(renderer);
         eTime = SDL_GetTicks (); 
        LOGE (" Time taken for Rendering... %ld ", eTime - sTime); 

}

I checked the time taken for each API.

SDL_UpdateYUVTexture takes more milliseconds, whereas other APIs are mostly 0 to 1 ms.

Can u suggest where i can hook into?

Which platform are you working on? Windows? Android? iOS?

Why are you calling SDL_UpdateYUVTexture() every frame?
Are you rendering a video? If not, you can just call it once, outside
the rendering loop.

SDL_UpdateYUVTexture() can be a slow function, because the underlying
renderer may not support a YUV texture natively, and in that case
SDL_UpdateYUVTexture() has to do YUV -> RGB conversion in software, and
that can be slow.On 6/3/2014 6:20 PM, keestu wrote:

I checked the time taken for each API.

SDL_UpdateYUVTexture takes more milliseconds, whereas other APIs are
mostly 0 to 1 ms.

Can u suggest where i can hook into?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming

Hi Pallav,

It is in Android platform, and i am trying video streaming from RTSP server, To get this done, i use ffmpeg, and whenever i get a complete picture from ffmpeg, i update the texture SDL_UpdateYUVTexture ().

Do u mean Converting YUV to RGB brings down the rendering time? Also, i am not sure if SDL uses hardware acceleration?. If so how to find ?

In-built SDL Renderers on mobile platforms (OpenGLES1 & OpenGLES2) do not
support hardware accelerated YUV textures. It only supports RGB 32 Bit. So
this means SDL is converting YUV data to RBG internally. And that code is
written in C. So it might not be fast enough for your purposes.

Possible Solutions:

  1. Most mobile platforms should offer Hardware Accelerated YUV textures.
    You could edit SDL’s OpenGL ES1/ES2 video renderer to add support for
    accelerated YUV.
  2. Get a smaller sized video frame from the server (512x384) and convert
    it, then upscale it when blitting to the renderer.
  3. Switch to JAVA. Maybe android has an API to do what you are doing. In
    that case you wouldn’t need to use SDL at all.

Pallav Nawani
IronCode Gaming Private Limited
Website: http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming
Mobile: 9997478768On Wed, Jun 4, 2014 at 12:10 PM, keestu wrote:

Hi Pallav,

It is in Android platform, and i am trying video streaming from RTSP
server, To get this done, i use ffmpeg, and whenever i get a complete
picture from ffmpeg, i update the texture SDL_UpdateYUVTexture ().

Do u mean Converting YUV to RGB brings down the rendering time? Also, i am
not sure if SDL uses hardware acceleration?. If so how to find ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks for the reply. If i understand correctly your statement, then “Converting YUV to RGB” enables using Hardware acceleration?, If not how about using OpenGL in SDL?

SDL is already using OpenGL.

Pallav Nawani
IronCode Gaming Private Limited
Website: http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming
Mobile: 9997478768On Wed, Jun 4, 2014 at 12:41 PM, keestu wrote:

Thanks for the reply. If i understand correctly your statement, then
"Converting YUV to RGB" enables using Hardware acceleration?, If not how
about using OpenGL in SDL?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

What you can do is to find a YUV to RGB implementation in ARM Assembly
Language. That will reduce the time taken in YUV->RGB conversion.

Pallav Nawani
IronCode Gaming Private Limited
Website: http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming
Mobile: 9997478768On Wed, Jun 4, 2014 at 12:10 PM, keestu wrote:

Hi Pallav,

It is in Android platform, and i am trying video streaming from RTSP
server, To get this done, i use ffmpeg, and whenever i get a complete
picture from ffmpeg, i update the texture SDL_UpdateYUVTexture ().

Do u mean Converting YUV to RGB brings down the rendering time? Also, i am
not sure if SDL uses hardware acceleration?. If so how to find ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Ok, FFmpeg provides converting yuv to RGB format. If i convert the same then , does SDL uses “hardware acceleration”?

In the “Migration Guide to 2.0” it is mentioned [ https://wiki.libsdl.org/Introduction ]

" Acceleration is supported using OpenGL and Direct3D, and there is a software fallback "

That’s why i got confused, if if render in android, how to confirm it uses software fallback or hardware rendering?

On Android, the YUV to RGB conversion is using a software fallback written
in plain C.

It does not matter if you are using the OpenGL ES or software renderer, the
conversion itself is done in software.

2014-06-04 9:31 GMT+02:00 keestu :> In the “Migration Guide to 2.0” it is mentioned [

https://wiki.libsdl.org/Introduction ]

" Acceleration is supported using OpenGL and Direct3D, and there is a
software fallback "

That’s why i got confused, if if render in android, how to confirm it uses
software fallback or hardware rendering?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

The GLES 2 renderer isn’t using a YUV->RGB conversion shader on the GPU?
Does anyone know why not?

Jonny DOn Wed, Jun 4, 2014 at 5:26 AM, Stefanos A. wrote:

On Android, the YUV to RGB conversion is using a software fallback written
in plain C.

It does not matter if you are using the OpenGL ES or software renderer,
the conversion itself is done in software.

2014-06-04 9:31 GMT+02:00 keestu :

In the “Migration Guide to 2.0” it is mentioned [
https://wiki.libsdl.org/Introduction ]

" Acceleration is supported using OpenGL and Direct3D, and there is a
software fallback "

That’s why i got confused, if if render in android, how to confirm it
uses software fallback or hardware rendering?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Most likely because no one bothered writing one?

2014-06-04 10:35 GMT-03:00 Jonathan Dearborn :> The GLES 2 renderer isn’t using a YUV->RGB conversion shader on the GPU?

Does anyone know why not?

Jonny D

On Wed, Jun 4, 2014 at 5:26 AM, Stefanos A. wrote:

On Android, the YUV to RGB conversion is using a software fallback
written in plain C.

It does not matter if you are using the OpenGL ES or software renderer,
the conversion itself is done in software.

2014-06-04 9:31 GMT+02:00 keestu :

In the “Migration Guide to 2.0” it is mentioned [
https://wiki.libsdl.org/Introduction ]

" Acceleration is supported using OpenGL and Direct3D, and there is a
software fallback "

That’s why i got confused, if if render in android, how to confirm it
uses software fallback or hardware rendering?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.