Skip to content

Commit b853c39

Browse files
committed
Support aspect ratio changes in stream
1 parent 211b7a6 commit b853c39

File tree

2 files changed

+80
-44
lines changed

2 files changed

+80
-44
lines changed

OMXCore.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,11 @@ OMX_ERRORTYPE COMXCoreComponent::DecoderEventHandler(
16691669
CLog::Log(LOGDEBUG, "%s::%s %s - OMX_EventPortSettingsChanged(output)\n", CLASSNAME, __func__, ctx->GetName().c_str());
16701670
#endif
16711671
break;
1672+
case OMX_EventParamOrConfigChanged:
1673+
#if defined(OMX_DEBUG_EVENTHANDLER)
1674+
CLog::Log(LOGDEBUG, "%s::%s %s - OMX_EventParamOrConfigChanged(output)\n", CLASSNAME, __func__, ctx->GetName().c_str());
1675+
#endif
1676+
break;
16721677
#if defined(OMX_DEBUG_EVENTHANDLER)
16731678
case OMX_EventMark:
16741679
CLog::Log(LOGDEBUG, "%s::%s %s - OMX_EventMark\n", CLASSNAME, __func__, ctx->GetName().c_str());

OMXVideo.cpp

Lines changed: 75 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,10 @@ bool COMXVideo::PortSettingsChanged()
136136
{
137137
OMX_ERRORTYPE omx_err = OMX_ErrorNone;
138138
std::string componentName = "";
139-
float par = m_pixel_aspect;
140139

141140
if (m_settings_changed)
142141
{
143-
SetVideoRect(m_src_rect, m_dst_rect);
144142
m_omx_decoder.DisablePort(m_omx_decoder.GetOutputPort(), true);
145-
m_omx_decoder.EnablePort(m_omx_decoder.GetOutputPort(), true);
146-
return true;
147143
}
148144

149145
OMX_PARAM_PORTDEFINITIONTYPE port_image;
@@ -152,7 +148,26 @@ bool COMXVideo::PortSettingsChanged()
152148
omx_err = m_omx_decoder.GetParameter(OMX_IndexParamPortDefinition, &port_image);
153149
if(omx_err != OMX_ErrorNone)
154150
{
155-
CLog::Log(LOGERROR, "%s::%s - error m_omx_decoder.GetParameter(OMX_IndexParamPortDefinition) omx_err(0x%08x)\n", CLASSNAME, __func__, omx_err);
151+
CLog::Log(LOGERROR, "%s::%s - error m_omx_decoder.GetParameter(OMX_IndexParamPortDefinition) omx_err(0x%08x)", CLASSNAME, __func__, omx_err);
152+
}
153+
154+
OMX_CONFIG_POINTTYPE pixel_aspect;
155+
OMX_INIT_STRUCTURE(pixel_aspect);
156+
pixel_aspect.nPortIndex = m_omx_decoder.GetOutputPort();
157+
omx_err = m_omx_decoder.GetParameter(OMX_IndexParamBrcmPixelAspectRatio, &pixel_aspect);
158+
if(omx_err != OMX_ErrorNone)
159+
{
160+
CLog::Log(LOGERROR, "%s::%s - error m_omx_decoder.GetParameter(OMX_IndexParamBrcmPixelAspectRatio) omx_err(0x%08x)", CLASSNAME, __func__, omx_err);
161+
}
162+
163+
if (pixel_aspect.nX && pixel_aspect.nY)
164+
m_pixel_aspect = (float)pixel_aspect.nX / (float)pixel_aspect.nY;
165+
166+
if (m_settings_changed)
167+
{
168+
SetVideoRect(m_src_rect, m_dst_rect);
169+
m_omx_decoder.EnablePort(m_omx_decoder.GetOutputPort(), true);
170+
return true;
156171
}
157172

158173
OMX_CONFIG_INTERLACETYPE interlace;
@@ -227,27 +242,6 @@ bool COMXVideo::PortSettingsChanged()
227242
}
228243
}
229244

230-
// only set aspect when we have a aspect and display doesn't match the aspect
231-
if(par != 0.0f && fabs(par - 1.0f) > 0.01f)
232-
{
233-
OMX_CONFIG_DISPLAYREGIONTYPE configDisplay;
234-
OMX_INIT_STRUCTURE(configDisplay);
235-
configDisplay.nPortIndex = m_omx_render.GetInputPort();
236-
237-
AVRational aspect;
238-
aspect = av_d2q(par, 100);
239-
configDisplay.set = OMX_DISPLAY_SET_PIXEL;
240-
configDisplay.pixel_x = aspect.num;
241-
configDisplay.pixel_y = aspect.den;
242-
printf("Aspect : num %d den %d pixel aspect %f\n", aspect.num, aspect.den, par);
243-
omx_err = m_omx_render.SetConfig(OMX_IndexConfigDisplayRegion, &configDisplay);
244-
if(omx_err != OMX_ErrorNone)
245-
{
246-
CLog::Log(LOGERROR, "COMXVideo::Open error OMX_IndexConfigDisplayRegion omx_err(0x%08x)\n", omx_err);
247-
return false;
248-
}
249-
}
250-
251245
if(m_deinterlace)
252246
{
253247
m_omx_tunnel_decoder.Initialize(&m_omx_decoder, m_omx_decoder.GetOutputPort(), &m_omx_image_fx, m_omx_image_fx.GetInputPort());
@@ -523,6 +517,20 @@ bool COMXVideo::Open(COMXStreamInfo &hints, OMXClock *clock, const CRect &DestRe
523517
return false;
524518
}
525519

520+
// request portsettingschanged on aspect ratio change
521+
OMX_CONFIG_REQUESTCALLBACKTYPE notifications;
522+
OMX_INIT_STRUCTURE(notifications);
523+
notifications.nPortIndex = m_omx_decoder.GetOutputPort();
524+
notifications.nIndex = OMX_IndexParamBrcmPixelAspectRatio;
525+
notifications.bEnable = OMX_TRUE;
526+
527+
omx_err = m_omx_decoder.SetParameter((OMX_INDEXTYPE)OMX_IndexConfigRequestCallback, &notifications);
528+
if (omx_err != OMX_ErrorNone)
529+
{
530+
CLog::Log(LOGERROR, "COMXVideo::Open OMX_IndexConfigRequestCallback error (0%08x)\n", omx_err);
531+
return false;
532+
}
533+
526534
OMX_PARAM_BRCMVIDEODECODEERRORCONCEALMENTTYPE concanParam;
527535
OMX_INIT_STRUCTURE(concanParam);
528536
concanParam.bStartWithValidFrame = OMX_FALSE;
@@ -959,6 +967,14 @@ int COMXVideo::Decode(uint8_t *pData, int iSize, double dts, double pts)
959967
CLog::Log(LOGERROR, "%s::%s - error PortSettingsChanged omx_err(0x%08x)\n", CLASSNAME, __func__, omx_err);
960968
}
961969
}
970+
omx_err = m_omx_decoder.WaitForEvent(OMX_EventParamOrConfigChanged, 0);
971+
if (omx_err == OMX_ErrorNone)
972+
{
973+
if(!PortSettingsChanged())
974+
{
975+
CLog::Log(LOGERROR, "%s::%s - error PortSettingsChanged (EventParamOrConfigChanged) omx_err(0x%08x)\n", CLASSNAME, __func__, omx_err);
976+
}
977+
}
962978
}
963979
return true;
964980
}
@@ -980,32 +996,47 @@ void COMXVideo::Reset(void)
980996
///////////////////////////////////////////////////////////////////////////////////////////
981997
void COMXVideo::SetVideoRect(const CRect& SrcRect, const CRect& DestRect)
982998
{
983-
if (!m_settings_changed || DestRect.x2 <= DestRect.x1 || DestRect.y2 <= DestRect.y1)
999+
if ( !m_settings_changed || !((DestRect.x2 > DestRect.x1 && DestRect.y2 > DestRect.y1) || m_pixel_aspect != 0.0f) )
9841000
return;
9851001

1002+
OMX_ERRORTYPE omx_err;
9861003
OMX_CONFIG_DISPLAYREGIONTYPE configDisplay;
987-
9881004
OMX_INIT_STRUCTURE(configDisplay);
9891005
configDisplay.nPortIndex = m_omx_render.GetInputPort();
990-
configDisplay.fullscreen = OMX_FALSE;
991-
configDisplay.noaspect = OMX_TRUE;
992-
993-
configDisplay.set = (OMX_DISPLAYSETTYPE)(OMX_DISPLAY_SET_DEST_RECT|OMX_DISPLAY_SET_SRC_RECT|OMX_DISPLAY_SET_FULLSCREEN|OMX_DISPLAY_SET_NOASPECT);
994-
configDisplay.dest_rect.x_offset = (int)(DestRect.x1+0.5f);
995-
configDisplay.dest_rect.y_offset = (int)(DestRect.y1+0.5f);
996-
configDisplay.dest_rect.width = (int)(DestRect.Width()+0.5f);
997-
configDisplay.dest_rect.height = (int)(DestRect.Height()+0.5f);
9981006

999-
configDisplay.src_rect.x_offset = (int)(SrcRect.x1+0.5f);
1000-
configDisplay.src_rect.y_offset = (int)(SrcRect.y1+0.5f);
1001-
configDisplay.src_rect.width = (int)(SrcRect.Width()+0.5f);
1002-
configDisplay.src_rect.height = (int)(SrcRect.Height()+0.5f);
1003-
1004-
m_omx_render.SetConfig(OMX_IndexConfigDisplayRegion, &configDisplay);
1007+
// configured dest_rect takes precedence
1008+
if (DestRect.x2 > DestRect.x1 && DestRect.y2 > DestRect.y1)
1009+
{
1010+
configDisplay.fullscreen = OMX_FALSE;
1011+
configDisplay.noaspect = OMX_TRUE;
1012+
1013+
configDisplay.set = (OMX_DISPLAYSETTYPE)(OMX_DISPLAY_SET_DEST_RECT|OMX_DISPLAY_SET_SRC_RECT|OMX_DISPLAY_SET_FULLSCREEN|OMX_DISPLAY_SET_NOASPECT);
1014+
configDisplay.dest_rect.x_offset = (int)(DestRect.x1+0.5f);
1015+
configDisplay.dest_rect.y_offset = (int)(DestRect.y1+0.5f);
1016+
configDisplay.dest_rect.width = (int)(DestRect.Width()+0.5f);
1017+
configDisplay.dest_rect.height = (int)(DestRect.Height()+0.5f);
1018+
1019+
configDisplay.src_rect.x_offset = (int)(SrcRect.x1+0.5f);
1020+
configDisplay.src_rect.y_offset = (int)(SrcRect.y1+0.5f);
1021+
configDisplay.src_rect.width = (int)(SrcRect.Width()+0.5f);
1022+
configDisplay.src_rect.height = (int)(SrcRect.Height()+0.5f);
1023+
}
1024+
else /* if (m_pixel_aspect != 0.0f) */
1025+
{
1026+
AVRational aspect = av_d2q(m_pixel_aspect, 100);
1027+
configDisplay.set = OMX_DISPLAY_SET_PIXEL;
1028+
configDisplay.pixel_x = aspect.num;
1029+
configDisplay.pixel_y = aspect.den;
1030+
}
1031+
omx_err = m_omx_render.SetConfig(OMX_IndexConfigDisplayRegion, &configDisplay);
1032+
if(omx_err != OMX_ErrorNone)
1033+
{
1034+
CLog::Log(LOGERROR, "COMXVideo::Open error OMX_IndexConfigDisplayRegion omx_err(0x%08x)\n", omx_err);
1035+
}
10051036

1006-
printf("dest_rect.x_offset %d dest_rect.y_offset %d dest_rect.width %d dest_rect.height %d\n",
1037+
printf("dest_rect.x_offset %d dest_rect.y_offset %d dest_rect.width %d dest_rect.height %d, pixel_aspect %.2f\n",
10071038
configDisplay.dest_rect.x_offset, configDisplay.dest_rect.y_offset,
1008-
configDisplay.dest_rect.width, configDisplay.dest_rect.height);
1039+
configDisplay.dest_rect.width, configDisplay.dest_rect.height, m_pixel_aspect);
10091040
}
10101041

10111042
int COMXVideo::GetInputBufferSize()

0 commit comments

Comments
 (0)