Use media_format pixel_width/height_aspect as it was meant to be used. This
avoids rounding issues (1440x1080 -> 1920x1080 instead of 1921x1080). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31477 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -359,26 +359,26 @@ Controller::PlayerActivated(bool active)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Controller::GetSize(int *width, int *height, float* widthToHeightRatio)
|
Controller::GetSize(int *width, int *height, int* widthAspect,
|
||||||
|
int* heightAspect)
|
||||||
{
|
{
|
||||||
BAutolock _(this);
|
BAutolock _(this);
|
||||||
|
|
||||||
if (fVideoTrackSupplier) {
|
if (fVideoTrackSupplier) {
|
||||||
media_format format = fVideoTrackSupplier->Format();
|
media_format format = fVideoTrackSupplier->Format();
|
||||||
// TODO: take aspect ratio into account!
|
|
||||||
*height = format.u.raw_video.display.line_count;
|
*height = format.u.raw_video.display.line_count;
|
||||||
*width = format.u.raw_video.display.line_width;
|
*width = format.u.raw_video.display.line_width;
|
||||||
if (widthToHeightRatio != NULL) {
|
if (widthAspect != NULL)
|
||||||
printf("pixel_width_aspect: %d\n", format.u.raw_video.pixel_width_aspect);
|
*widthAspect = format.u.raw_video.pixel_width_aspect;
|
||||||
printf("pixel_height_aspect: %d\n", format.u.raw_video.pixel_height_aspect);
|
if (heightAspect != NULL)
|
||||||
*widthToHeightRatio = (float)format.u.raw_video.pixel_width_aspect
|
*heightAspect = format.u.raw_video.pixel_height_aspect;
|
||||||
/ format.u.raw_video.pixel_height_aspect;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
*height = 0;
|
*height = 0;
|
||||||
*width = 0;
|
*width = 0;
|
||||||
if (widthToHeightRatio != NULL)
|
if (widthAspect != NULL)
|
||||||
*widthToHeightRatio = 0.0f;
|
*widthAspect = 1;
|
||||||
|
if (heightAspect != NULL)
|
||||||
|
*heightAspect = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,8 @@ public:
|
|||||||
void PlayerActivated(bool active);
|
void PlayerActivated(bool active);
|
||||||
|
|
||||||
void GetSize(int *width, int *height,
|
void GetSize(int *width, int *height,
|
||||||
float* widthToHeightRatio = NULL);
|
int* widthAspect = NULL,
|
||||||
|
int* heightAspect = NULL);
|
||||||
|
|
||||||
int AudioTrackCount();
|
int AudioTrackCount();
|
||||||
int VideoTrackCount();
|
int VideoTrackCount();
|
||||||
|
|||||||
@@ -116,8 +116,8 @@ MainWin::MainWin()
|
|||||||
fNoInterface(false),
|
fNoInterface(false),
|
||||||
fSourceWidth(-1),
|
fSourceWidth(-1),
|
||||||
fSourceHeight(-1),
|
fSourceHeight(-1),
|
||||||
fWidthScale(1.0),
|
fWidthAspect(0),
|
||||||
fHeightScale(1.0),
|
fHeightAspect(0),
|
||||||
fMouseDownTracking(false),
|
fMouseDownTracking(false),
|
||||||
fGlobalSettingsListener(this)
|
fGlobalSettingsListener(this)
|
||||||
{
|
{
|
||||||
@@ -592,31 +592,38 @@ MainWin::MessageReceived(BMessage *msg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case M_ASPECT_100000_1:
|
case M_ASPECT_100000_1:
|
||||||
VideoFormatChange(fSourceWidth, fSourceHeight, 1.0);
|
VideoFormatChange(fSourceWidth, fSourceHeight,
|
||||||
|
fSourceWidth, fSourceHeight);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case M_ASPECT_106666_1:
|
case M_ASPECT_106666_1:
|
||||||
VideoFormatChange(fSourceWidth, fSourceHeight, 1.06666);
|
VideoFormatChange(fSourceWidth, fSourceHeight,
|
||||||
|
lround(1.06666 * fSourceWidth), fSourceHeight);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case M_ASPECT_109091_1:
|
case M_ASPECT_109091_1:
|
||||||
VideoFormatChange(fSourceWidth, fSourceHeight, 1.09091);
|
VideoFormatChange(fSourceWidth, fSourceHeight,
|
||||||
|
lround(1.09091 * fSourceWidth), fSourceHeight);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case M_ASPECT_141176_1:
|
case M_ASPECT_141176_1:
|
||||||
VideoFormatChange(fSourceWidth, fSourceHeight, 1.41176);
|
VideoFormatChange(fSourceWidth, fSourceHeight,
|
||||||
|
lround(1.41176 * fSourceWidth), fSourceHeight);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case M_ASPECT_720_576:
|
case M_ASPECT_720_576:
|
||||||
VideoFormatChange(720, 576, 1.06666);
|
VideoFormatChange(720, 576,
|
||||||
|
lround(1.06666 * fSourceWidth), fSourceHeight);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case M_ASPECT_704_576:
|
case M_ASPECT_704_576:
|
||||||
VideoFormatChange(704, 576, 1.09091);
|
VideoFormatChange(704, 576,
|
||||||
|
lround(1.09091 * fSourceWidth), fSourceHeight);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case M_ASPECT_544_576:
|
case M_ASPECT_544_576:
|
||||||
VideoFormatChange(544, 576, 1.41176);
|
VideoFormatChange(544, 576,
|
||||||
|
lround(1.41176 * fSourceWidth), fSourceHeight);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case M_SET_PLAYLIST_POSITION:
|
case M_SET_PLAYLIST_POSITION:
|
||||||
@@ -776,17 +783,18 @@ MainWin::ShowPlaylistWindow()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MainWin::VideoFormatChange(int width, int height, float widthToHeightRatio)
|
MainWin::VideoFormatChange(int width, int height, int widthAspect,
|
||||||
|
int heightAspect)
|
||||||
{
|
{
|
||||||
// called when video format or aspect ratio changes
|
// called when video format or aspect ratio changes
|
||||||
|
|
||||||
printf("VideoFormatChange enter: width %d, height %d, "
|
printf("VideoFormatChange enter: width %d, height %d, "
|
||||||
"widthToHeightRatio %.6f\n", width, height, widthToHeightRatio);
|
"aspect ratio: %d:%d\n", width, height, widthAspect, heightAspect);
|
||||||
|
|
||||||
fSourceWidth = width;
|
fSourceWidth = width;
|
||||||
fSourceHeight = height;
|
fSourceHeight = height;
|
||||||
fWidthScale = widthToHeightRatio;
|
fWidthAspect = widthAspect;
|
||||||
fHeightScale = 1.0f;
|
fHeightAspect = heightAspect;
|
||||||
|
|
||||||
FrameResized(Bounds().Width(), Bounds().Height());
|
FrameResized(Bounds().Width(), Bounds().Height());
|
||||||
|
|
||||||
@@ -829,13 +837,13 @@ MainWin::_SetupWindow()
|
|||||||
int previousSourceWidth = fSourceWidth;
|
int previousSourceWidth = fSourceWidth;
|
||||||
int previousSourceHeight = fSourceHeight;
|
int previousSourceHeight = fSourceHeight;
|
||||||
if (fHasVideo) {
|
if (fHasVideo) {
|
||||||
fController->GetSize(&fSourceWidth, &fSourceHeight, &fWidthScale);
|
fController->GetSize(&fSourceWidth, &fSourceHeight,
|
||||||
fHeightScale = 1.0;
|
&fWidthAspect, &fHeightAspect);
|
||||||
} else {
|
} else {
|
||||||
fSourceWidth = 0;
|
fSourceWidth = 0;
|
||||||
fSourceHeight = 0;
|
fSourceHeight = 0;
|
||||||
fWidthScale = 1.0;
|
fWidthAspect = 1;
|
||||||
fHeightScale = 1.0;
|
fHeightAspect = 1;
|
||||||
}
|
}
|
||||||
_UpdateControlsEnabledStatus();
|
_UpdateControlsEnabledStatus();
|
||||||
|
|
||||||
@@ -1018,6 +1026,26 @@ MainWin::_GetMinimumWindowSize(int& width, int& height) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MainWin::_GetUnscaledVideoSize(int& videoWidth, int& videoHeight) const
|
||||||
|
{
|
||||||
|
if (fWidthAspect != 0 && fHeightAspect != 0) {
|
||||||
|
videoWidth = fSourceHeight / fHeightAspect * fWidthAspect;
|
||||||
|
videoHeight = fSourceWidth / fWidthAspect * fHeightAspect;
|
||||||
|
// Use the scaling which produces an enlarged view.
|
||||||
|
if (videoWidth > fSourceWidth) {
|
||||||
|
// Enlarge width
|
||||||
|
videoHeight = fSourceHeight;
|
||||||
|
} else {
|
||||||
|
// Enlarge height
|
||||||
|
videoWidth = fSourceWidth;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
videoWidth = fSourceWidth;
|
||||||
|
videoHeight = fSourceHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MainWin::_SetWindowSizeLimits()
|
MainWin::_SetWindowSizeLimits()
|
||||||
{
|
{
|
||||||
@@ -1033,13 +1061,14 @@ void
|
|||||||
MainWin::_ResizeWindow(int percent)
|
MainWin::_ResizeWindow(int percent)
|
||||||
{
|
{
|
||||||
// Get required window size
|
// Get required window size
|
||||||
int videoWidth = lround(fSourceWidth * fWidthScale);
|
int videoWidth;
|
||||||
int videoHeight = lround(fSourceHeight * fHeightScale);
|
int videoHeight;
|
||||||
|
_GetUnscaledVideoSize(videoWidth, videoHeight);
|
||||||
|
|
||||||
videoWidth = (videoWidth * percent) / 100;
|
videoWidth = (videoWidth * percent) / 100;
|
||||||
videoHeight = (videoHeight * percent) / 100;
|
videoHeight = (videoHeight * percent) / 100;
|
||||||
|
|
||||||
// Calculate and set the initial window size
|
// Calculate and set the minimum window size
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
_GetMinimumWindowSize(width, height);
|
_GetMinimumWindowSize(width, height);
|
||||||
@@ -1060,8 +1089,11 @@ MainWin::_ResizeVideoView(int x, int y, int width, int height)
|
|||||||
if (fKeepAspectRatio) {
|
if (fKeepAspectRatio) {
|
||||||
// Keep aspect ratio, place video view inside
|
// Keep aspect ratio, place video view inside
|
||||||
// the background area (may create black bars).
|
// the background area (may create black bars).
|
||||||
float scaledWidth = fSourceWidth * fWidthScale;
|
int videoWidth;
|
||||||
float scaledHeight = fSourceHeight * fHeightScale;
|
int videoHeight;
|
||||||
|
_GetUnscaledVideoSize(videoWidth, videoHeight);
|
||||||
|
float scaledWidth = videoWidth;
|
||||||
|
float scaledHeight = videoHeight;
|
||||||
float factor = min_c(width / scaledWidth, height / scaledHeight);
|
float factor = min_c(width / scaledWidth, height / scaledHeight);
|
||||||
int renderWidth = lround(scaledWidth * factor);
|
int renderWidth = lround(scaledWidth * factor);
|
||||||
int renderHeight = lround(scaledHeight * factor);
|
int renderHeight = lround(scaledHeight * factor);
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public:
|
|||||||
void ShowSettingsWindow();
|
void ShowSettingsWindow();
|
||||||
|
|
||||||
void VideoFormatChange(int width, int height,
|
void VideoFormatChange(int width, int height,
|
||||||
float widthToHeightRatio);
|
int widthAspect, int heightAspect);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _RefsReceived(BMessage* message);
|
void _RefsReceived(BMessage* message);
|
||||||
@@ -73,6 +73,8 @@ private:
|
|||||||
void _GetMinimumWindowSize(int& width,
|
void _GetMinimumWindowSize(int& width,
|
||||||
int& height) const;
|
int& height) const;
|
||||||
void _SetWindowSizeLimits();
|
void _SetWindowSizeLimits();
|
||||||
|
void _GetUnscaledVideoSize(int& videoWidth,
|
||||||
|
int& videoHeight) const;
|
||||||
void _ResizeWindow(int percent);
|
void _ResizeWindow(int percent);
|
||||||
void _ResizeVideoView(int x, int y, int width,
|
void _ResizeVideoView(int x, int y, int width,
|
||||||
int height);
|
int height);
|
||||||
@@ -132,8 +134,8 @@ private:
|
|||||||
volatile bool fNoInterface;
|
volatile bool fNoInterface;
|
||||||
int fSourceWidth;
|
int fSourceWidth;
|
||||||
int fSourceHeight;
|
int fSourceHeight;
|
||||||
float fWidthScale;
|
int fWidthAspect;
|
||||||
float fHeightScale;
|
int fHeightAspect;
|
||||||
int fMenuBarWidth;
|
int fMenuBarWidth;
|
||||||
int fMenuBarHeight;
|
int fMenuBarHeight;
|
||||||
int fControlsHeight;
|
int fControlsHeight;
|
||||||
|
|||||||
Reference in New Issue
Block a user