summaryrefslogtreecommitdiff
path: root/omx
diff options
context:
space:
mode:
authorNikhil Mande <nikhil@ti.com>2009-10-28 19:04:48 -0500
committerJames Dong <jdong@google.com>2009-11-09 16:17:46 -0800
commit28bb1bbc618ee23e505399ec6f18549b1d67f9a3 (patch)
tree60d97a7fab64599c770749379175a08a2df5d82f /omx
parent3ef84bfac77eb508edac31e9b7ce695d9502cf07 (diff)
downloadomap3-28bb1bbc618ee23e505399ec6f18549b1d67f9a3.tar.gz
Fix in h264 output buffer size calculation
Previous buffer calculation was incorrect, for D1 it was 2.1 MB now it is 600 KB. The calculations are now based on H.264 annex A spec. The smaller size results in reducing cache flush latencies in the bridge improving performance. With this change D1 can now get up to ~29 FPS. Credit to Jeff Vanhoof for noticing the large buffer size. Originally from: https://partner.source.android.com/g/#change,1400
Diffstat (limited to 'omx')
-rw-r--r--omx/video/src/openmax_il/video_encode/src/OMX_VideoEnc_Utils.c35
-rw-r--r--omx/video/src/openmax_il/video_encode/src/OMX_VideoEncoder.c4
2 files changed, 28 insertions, 11 deletions
diff --git a/omx/video/src/openmax_il/video_encode/src/OMX_VideoEnc_Utils.c b/omx/video/src/openmax_il/video_encode/src/OMX_VideoEnc_Utils.c
index 54aaf9f..01741ab 100644
--- a/omx/video/src/openmax_il/video_encode/src/OMX_VideoEnc_Utils.c
+++ b/omx/video/src/openmax_il/video_encode/src/OMX_VideoEnc_Utils.c
@@ -4084,21 +4084,34 @@ void CalculateBufferSize(OMX_PARAM_PORTDEFINITIONTYPE* pCompPort, VIDENC_COMPONE
OMX_U32 GetMaxAVCBufferSize(OMX_U32 width, OMX_U32 height)
{
OMX_U32 MaxCPB;
+ OMX_U32 nMacroBlocks;
- if(width<=176 && height<= 144)
+ /* Calculate output buffer size based on max possible CPB for the resolution
+ Output bitrate may not be set yet, so only resolution is taken into account */
+
+ nMacroBlocks = (width * height) / 256;
+
+ /* Following values are set based on Annex A of AVC Standard */
+ if(nMacroBlocks <= 99) {
MaxCPB = 500;
- else if(width<=352 && height<= 288)
+ }
+ else if(nMacroBlocks <= 396) {
MaxCPB = 2000;
- else if(width<=352 && height<= 576)
- MaxCPB = 10000;
- else if(width<=720 && height<= 576)
- MaxCPB = 14000;
- else if(width<=1280 && height<= 720)
- MaxCPB = 62500;
+ }
+ else if(nMacroBlocks <= 792) {
+ MaxCPB = 4000;
+ }
+ else if(nMacroBlocks <= 1620) {
+ /* Note - Max bitrate in this case is assumed to max 4 Mbps to limit the buffer size
+ If bitrate in this particular case could be higher than 4 Mbps, increase MxCPB value */
+ MaxCPB = 4000;
+ }
else
- MaxCPB = 240000;
- /*150(bytes) = 1200(bits)/8 SN release notes*/
- return 150*MaxCPB;
+ MaxCPB = 14000;
+
+ /* MaxCPB are in units of 1200 bits i.e. 150 bytes */
+ /* Return buffer size in bytes*/
+ return (150 * MaxCPB);
}
OMX_ERRORTYPE AddStateTransition(VIDENC_COMPONENT_PRIVATE* pComponentPrivate) {
diff --git a/omx/video/src/openmax_il/video_encode/src/OMX_VideoEncoder.c b/omx/video/src/openmax_il/video_encode/src/OMX_VideoEncoder.c
index 3998db3..de69e70 100644
--- a/omx/video/src/openmax_il/video_encode/src/OMX_VideoEncoder.c
+++ b/omx/video/src/openmax_il/video_encode/src/OMX_VideoEncoder.c
@@ -618,6 +618,7 @@ sDynamicFormat = getenv("FORMAT");
/* Set the default value of the run-time Target Frame Rate to the create-time Frame Rate */
pComponentPrivate->nTargetFrameRate = pPortDef->format.video.xFramerate;
+ /* Calculate default input buffer size */
CalculateBufferSize(pPortDef, pComponentPrivate);
pComponentPrivate->nInBufferSize = 0;
@@ -683,6 +684,7 @@ sDynamicFormat = getenv("FORMAT");
/* Set the default value of the run-time Target Bit Rate to the create-time Bit Rate */
pComponentPrivate->nTargetBitRate = pPortDef->format.video.nBitrate;
+ /* Calculate default output buffer size */
CalculateBufferSize(pPortDef, pComponentPrivate);
pComponentPrivate->nOutBufferSize = 0;
@@ -1866,6 +1868,7 @@ static OMX_ERRORTYPE SetParameter (OMX_IN OMX_HANDLETYPE hComponent,
pComponentPrivate->dbg, OMX_TRACE4,
"Failed to copy parameter.\n");
}
+ /* Calculate input buffer size based on these port settings */
CalculateBufferSize(pCompPortIn->pPortDef, pComponentPrivate);
}
else if (pComponentParam->nPortIndex == pCompPortOut->pPortDef->nPortIndex)
@@ -1879,6 +1882,7 @@ static OMX_ERRORTYPE SetParameter (OMX_IN OMX_HANDLETYPE hComponent,
pComponentPrivate->dbg, OMX_TRACE4,
"Failed to copy parameter.\n");
}
+ /* Calculate output buffer size based on these port settings */
CalculateBufferSize(pCompPortOut->pPortDef, pComponentPrivate);
}
else