提交 0c5a946b 编写于 作者: Z Zhang Rui

Player: fix sample aspect ratio

上级 4be513e4
......@@ -37,6 +37,8 @@ public abstract class AbstractMediaPlayer {
protected static final int MEDIA_ERROR = 100;
protected static final int MEDIA_INFO = 200;
protected static final int MEDIA_SET_VIDEO_SAR = 10001;
public static final int MEDIA_INFO_UNKNOWN = 1;
public static final int MEDIA_INFO_STARTED_AS_NEXT = 2;
public static final int MEDIA_INFO_VIDEO_RENDERING_START = 3;
......@@ -114,7 +116,7 @@ public abstract class AbstractMediaPlayer {
public interface OnVideoSizeChangedListener {
public void onVideoSizeChanged(AbstractMediaPlayer mp, int width,
int height);
int height, int sar_num, int sar_den);
}
public interface OnErrorListener {
......@@ -195,10 +197,11 @@ public abstract class AbstractMediaPlayer {
}
protected static final void notifyOnVideoSizeChanged(
AbstractMediaPlayer mp, int width, int height) {
AbstractMediaPlayer mp, int width, int height, int sarNum,
int sarDen) {
if (mp != null && mp.mOnVideoSizeChangedListener != null)
mp.mOnVideoSizeChangedListener
.onVideoSizeChanged(mp, width, height);
mp.mOnVideoSizeChangedListener.onVideoSizeChanged(mp, width,
height, sarNum, sarDen);
}
protected static final boolean notifyOnError(AbstractMediaPlayer mp,
......
......@@ -172,7 +172,8 @@ public final class AndroidMediaPlayer extends AbstractMediaPlayer {
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
notifyOnVideoSizeChanged(mWeakMediaPlayer.get(), width, height);
notifyOnVideoSizeChanged(mWeakMediaPlayer.get(), width, height, 1,
1);
}
@Override
......
......@@ -62,6 +62,8 @@ public final class IjkMediaPlayer extends AbstractMediaPlayer {
private int mVideoWidth;
private int mVideoHeight;
private int mVideoSarNum;
private int mVideoSarDen;
/**
* Default constructor. Consider using one of the create() methods for
......@@ -375,7 +377,9 @@ public final class IjkMediaPlayer extends AbstractMediaPlayer {
case MEDIA_SET_VIDEO_SIZE:
mIjkMediaPlayer.mVideoWidth = msg.arg1;
mIjkMediaPlayer.mVideoHeight = msg.arg2;
notifyOnVideoSizeChanged(mIjkMediaPlayer, msg.arg1, msg.arg2);
notifyOnVideoSizeChanged(mIjkMediaPlayer, msg.arg1, msg.arg2,
mIjkMediaPlayer.mVideoSarNum,
mIjkMediaPlayer.mVideoSarDen);
return;
case MEDIA_ERROR:
......@@ -400,6 +404,14 @@ public final class IjkMediaPlayer extends AbstractMediaPlayer {
case MEDIA_NOP: // interface test message - ignore
break;
case MEDIA_SET_VIDEO_SAR:
mIjkMediaPlayer.mVideoSarNum = msg.arg1;
mIjkMediaPlayer.mVideoSarDen = msg.arg2;
notifyOnVideoSizeChanged(mIjkMediaPlayer, msg.arg1, msg.arg2,
mIjkMediaPlayer.mVideoSarNum,
mIjkMediaPlayer.mVideoSarDen);
break;
default:
DebugLog.e(TAG, "Unknown message type " + msg.what);
return;
......
......@@ -90,6 +90,8 @@ public class VideoView extends SurfaceView implements
private AbstractMediaPlayer mMediaPlayer = null;
private int mVideoWidth;
private int mVideoHeight;
private int mVideoSarNum;
private int mVideoSarDen;
private int mSurfaceWidth;
private int mSurfaceHeight;
private MediaController mMediaController;
......@@ -145,8 +147,12 @@ public class VideoView extends SurfaceView implements
DisplayMetrics disp = mContext.getResources().getDisplayMetrics();
int windowWidth = disp.widthPixels, windowHeight = disp.heightPixels;
float windowRatio = windowWidth / (float) windowHeight;
int sarNum = mVideoSarNum;
int sarDen = mVideoSarDen;
if (mVideoHeight > 0 && mVideoWidth > 0) {
float videoRatio = ((float) (mVideoWidth)) / mVideoHeight;
if (sarNum > 0 && sarDen > 0)
videoRatio = videoRatio * sarNum / sarDen;
mSurfaceHeight = mVideoHeight;
mSurfaceWidth = mVideoWidth;
......@@ -171,10 +177,10 @@ public class VideoView extends SurfaceView implements
// getHolder().setFormat(ImageFormat.YV12);
DebugLog.dfmt(
TAG,
"VIDEO: %dx%dx%f, Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f",
mVideoWidth, mVideoHeight, videoRatio, mSurfaceWidth,
mSurfaceHeight, lp.width, lp.height, windowWidth,
windowHeight, windowRatio);
"VIDEO: %dx%dx%f[SAR:%d:%d], Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f",
mVideoWidth, mVideoHeight, videoRatio, mVideoSarNum,
mVideoSarDen, mSurfaceWidth, mSurfaceHeight, lp.width,
lp.height, windowWidth, windowHeight, windowRatio);
mVideoLayout = layout;
}
}
......@@ -183,6 +189,8 @@ public class VideoView extends SurfaceView implements
mContext = ctx;
mVideoWidth = 0;
mVideoHeight = 0;
mVideoSarNum = 0;
mVideoSarDen = 0;
getHolder().addCallback(mSHCallback);
setFocusable(true);
setFocusableInTouchMode(true);
......@@ -289,10 +297,12 @@ public class VideoView extends SurfaceView implements
OnVideoSizeChangedListener mSizeChangedListener = new OnVideoSizeChangedListener() {
public void onVideoSizeChanged(AbstractMediaPlayer mp, int width,
int height) {
int height, int sarNum, int sarDen) {
DebugLog.dfmt(TAG, "onVideoSizeChanged: (%dx%d)", width, height);
mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight();
mVideoSarNum = sarNum;
mVideoSarDen = sarDen;
if (mVideoWidth != 0 && mVideoHeight != 0)
setVideoLayout(mVideoLayout);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册