# How to achieve minimum delay in rendering?

**URL:** <https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720>\
**Category:** SDL Development\
**Created:** [June 3, 2014, 11:42am UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720 "2014-06-03T11:42:35Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![keestu](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/k/839c29/32.png) [@keestu](https://discourse.libsdl.org/u/keestu)\
**Post date:** [June 3, 2014, 11:42am UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/1 "2014-06-03T11:42:35Z")

</div>

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);

---

<div class="post-metadata">

**Author:** ![Pallav\_Nawani](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/pallav_nawani/32/237_2.png) [@Pallav\_Nawani](https://discourse.libsdl.org/u/Pallav_Nawani)\
**Post date:** [June 3, 2014, 11:57am UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/2 "2014-06-03T11:57:08Z")

</div>

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](http://www.ironcode.com)  
Twitter: [x.com](http://twitter.com/Ironcode_Gaming)  
Facebook: [Ironcode Gaming](http://www.facebook.com/Ironcode.Gaming)  
Mobile: _9997478768_On 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)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![keestu](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/k/839c29/32.png) [@keestu](https://discourse.libsdl.org/u/keestu)\
**Post date:** [June 3, 2014, 12:35pm UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/3 "2014-06-03T12:35:41Z")

</div>

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); 

```

}

---

<div class="post-metadata">

**Author:** ![keestu](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/k/839c29/32.png) [@keestu](https://discourse.libsdl.org/u/keestu)\
**Post date:** [June 3, 2014, 12:50pm UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/4 "2014-06-03T12:50:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Pallav\_Nawani](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/pallav_nawani/32/237_2.png) [@Pallav\_Nawani](https://discourse.libsdl.org/u/Pallav_Nawani)\
**Post date:** [June 4, 2014, 6:03am UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/5 "2014-06-04T06:03:01Z")

</div>

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)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

–  
_Pallav Nawani_  
_Game Designer/CEO_

> **[Ironcode Gaming](https://ironcode.com/)**
>
> Founded in 2004 Ironcode is an independent developer and publisher of quality games. Here at Ironcode we develop and produce original games and also provide end

Twitter: [x.com](http://twitter.com/Ironcode_Gaming)  
Facebook: [Ironcode Gaming](http://www.facebook.com/Ironcode.Gaming)

---

<div class="post-metadata">

**Author:** ![keestu](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/k/839c29/32.png) [@keestu](https://discourse.libsdl.org/u/keestu)\
**Post date:** [June 4, 2014, 6:40am UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/6 "2014-06-04T06:40:11Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Pallav\_Nawani](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/pallav_nawani/32/237_2.png) [@Pallav\_Nawani](https://discourse.libsdl.org/u/Pallav_Nawani)\
**Post date:** [June 4, 2014, 6:54am UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/7 "2014-06-04T06:54:51Z")

</div>

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](http://www.ironcode.com)  
Twitter: [x.com](http://twitter.com/Ironcode_Gaming)  
Facebook: [Ironcode Gaming](http://www.facebook.com/Ironcode.Gaming)  
Mobile: _9997478768_On 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)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![keestu](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/k/839c29/32.png) [@keestu](https://discourse.libsdl.org/u/keestu)\
**Post date:** [June 4, 2014, 7:11am UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/8 "2014-06-04T07:11:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Pallav\_Nawani](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/pallav_nawani/32/237_2.png) [@Pallav\_Nawani](https://discourse.libsdl.org/u/Pallav_Nawani)\
**Post date:** [June 4, 2014, 7:17am UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/9 "2014-06-04T07:17:17Z")

</div>

SDL is already using OpenGL.

_Pallav Nawani_  
_IronCode Gaming Private Limited_  
Website: [http://www.ironcode.com](http://www.ironcode.com)  
Twitter: [x.com](http://twitter.com/Ironcode_Gaming)  
Facebook: [Ironcode Gaming](http://www.facebook.com/Ironcode.Gaming)  
Mobile: _9997478768_On 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)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Pallav\_Nawani](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/pallav_nawani/32/237_2.png) [@Pallav\_Nawani](https://discourse.libsdl.org/u/Pallav_Nawani)\
**Post date:** [June 4, 2014, 7:18am UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/10 "2014-06-04T07:18:28Z")

</div>

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](http://www.ironcode.com)  
Twitter: [x.com](http://twitter.com/Ironcode_Gaming)  
Facebook: [Ironcode Gaming](http://www.facebook.com/Ironcode.Gaming)  
Mobile: _9997478768_On 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)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![keestu](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/k/839c29/32.png) [@keestu](https://discourse.libsdl.org/u/keestu)\
**Post date:** [June 4, 2014, 7:29am UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/11 "2014-06-04T07:29:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![keestu](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/k/839c29/32.png) [@keestu](https://discourse.libsdl.org/u/keestu)\
**Post date:** [June 4, 2014, 7:31am UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/12 "2014-06-04T07:31:28Z")

</div>

In the “Migration Guide to 2.0” it is mentioned [[https://wiki.libsdl.org/Introduction](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?

---

<div class="post-metadata">

**Author:** ![Stefanos\_A](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/f0a364/32.png) [@Stefanos\_A](https://discourse.libsdl.org/u/Stefanos_A)\
**Post date:** [June 4, 2014, 9:26am UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/13 "2014-06-04T09:26:57Z")

</div>

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](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)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![JonnyD](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/jonnyd/32/1604_2.png) [@JonnyD](https://discourse.libsdl.org/u/JonnyD)\
**Post date:** [June 4, 2014, 1:35pm UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/14 "2014-06-04T13:35:41Z")

</div>

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](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)  
> > [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Gabriel\_Jacobo](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/gabriel_jacobo/32/1968_2.png) [@Gabriel\_Jacobo](https://discourse.libsdl.org/u/Gabriel_Jacobo)\
**Post date:** [June 4, 2014, 1:39pm UTC](https://discourse.libsdl.org/t/how-to-achieve-minimum-delay-in-rendering/20720/15 "2014-06-04T13:39:33Z")

</div>

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](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)  
> > > [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> > 
> > * * *
> > 
> > SDL mailing list  
> > SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> > [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

–  
Gabriel.
