Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

frameworks-av: Commit

frameworks/av


Commit MetaInfo

Revision7808919e17e8c6ab9971efdd33227d5bd4f90a79 (tree)
Time2019-03-20 01:17:33
AuthorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

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.

Change Summary

Incremental Difference

--- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
@@ -2045,7 +2045,13 @@ void NuPlayer::updateVideoSize(
20452045 && sarWidth > 0 && sarHeight > 0) {
20462046 ALOGV("Sample aspect ratio %d : %d", sarWidth, sarHeight);
20472047
2048- displayWidth = (displayWidth * sarWidth) / sarHeight;
2048+ if (sarWidth == displayWidth) {
2049+ ALOGW("sarWidth(%d) is the same as displayWidth, assume it's Storage Aspect Ratio and skip it!", sarWidth);
2050+ } else if (sarHeight == displayHeight) {
2051+ ALOGW("sarHeight(%d) is the same as displayHeight, assume it's Storage Aspect Ratio and skip it!", sarHeight);
2052+ } else {
2053+ displayWidth = (displayWidth * sarWidth) / sarHeight;
2054+ }
20492055
20502056 ALOGV("display dimensions %d x %d", displayWidth, displayHeight);
20512057 } else {
Show on old repository browser