frameworks/av
Révision | b13fd4a3a09429c7eacf720c5efd40f5f36c06e9 (tree) |
---|---|
l'heure | 2020-04-14 22:49:59 |
Auteur | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
nuplayer: skip bad SAR values
Historically there are two definitions of SAR:
1. Storage Aspect Ratio
2. Sample Aspect Ratio
The first one is used in MPEG2 terminology, while the second is used
in MPEG4-AVC terminology.
The MPEG2 terminology actually means the real frame dimension (w:h),
while the MPEG4-AVC terminology means the shape of individual pixels.
It's called PAR (Pixel Aspect Ratio) in MPEG2 terminology.
Android apparently uses the second definition as comments in the code.
However, some video files include SAR tags in MPEG2 terminology sense.
For example,
08-14 18:13:45.212 2841 4769 I NuPlayer: int32_t width = 856
08-14 18:13:45.212 2841 4769 I NuPlayer: int32_t height = 480
08-14 18:13:45.212 2841 4769 I NuPlayer: int32_t sar-width = 852
08-14 18:13:45.212 2841 4769 I NuPlayer: int32_t sar-height = 480
That makes Android calculate the DAR (Display Aspect Ratio)
incorrectly, where DAR = FAR (Frame Aspect Ratio) x SAR.
As a result the video is stretched strangely.
To workaround it, skip the SAR tags if they look like the
Storage Aspect Ratio.
@@ -2066,7 +2066,13 @@ void NuPlayer::updateVideoSize( | ||
2066 | 2066 | && sarWidth > 0 && sarHeight > 0) { |
2067 | 2067 | ALOGV("Sample aspect ratio %d : %d", sarWidth, sarHeight); |
2068 | 2068 | |
2069 | - displayWidth = (displayWidth * sarWidth) / sarHeight; | |
2069 | + if (sarWidth == displayWidth) { | |
2070 | + ALOGW("sarWidth(%d) is the same as displayWidth, assume it's Storage Aspect Ratio and skip it!", sarWidth); | |
2071 | + } else if (sarHeight == displayHeight) { | |
2072 | + ALOGW("sarHeight(%d) is the same as displayHeight, assume it's Storage Aspect Ratio and skip it!", sarHeight); | |
2073 | + } else { | |
2074 | + displayWidth = (displayWidth * sarWidth) / sarHeight; | |
2075 | + } | |
2070 | 2076 | |
2071 | 2077 | ALOGV("display dimensions %d x %d", displayWidth, displayHeight); |
2072 | 2078 | } else { |