diff --git a/src/apps/mediaplayer/Controller.cpp b/src/apps/mediaplayer/Controller.cpp index 9ea8db9519..eb6a0295a6 100644 --- a/src/apps/mediaplayer/Controller.cpp +++ b/src/apps/mediaplayer/Controller.cpp @@ -359,26 +359,26 @@ Controller::PlayerActivated(bool active) void -Controller::GetSize(int *width, int *height, float* widthToHeightRatio) +Controller::GetSize(int *width, int *height, int* widthAspect, + int* heightAspect) { BAutolock _(this); if (fVideoTrackSupplier) { media_format format = fVideoTrackSupplier->Format(); - // TODO: take aspect ratio into account! *height = format.u.raw_video.display.line_count; *width = format.u.raw_video.display.line_width; - if (widthToHeightRatio != NULL) { -printf("pixel_width_aspect: %d\n", format.u.raw_video.pixel_width_aspect); -printf("pixel_height_aspect: %d\n", format.u.raw_video.pixel_height_aspect); - *widthToHeightRatio = (float)format.u.raw_video.pixel_width_aspect - / format.u.raw_video.pixel_height_aspect; - } + if (widthAspect != NULL) + *widthAspect = format.u.raw_video.pixel_width_aspect; + if (heightAspect != NULL) + *heightAspect = format.u.raw_video.pixel_height_aspect; } else { *height = 0; *width = 0; - if (widthToHeightRatio != NULL) - *widthToHeightRatio = 0.0f; + if (widthAspect != NULL) + *widthAspect = 1; + if (heightAspect != NULL) + *heightAspect = 1; } } diff --git a/src/apps/mediaplayer/Controller.h b/src/apps/mediaplayer/Controller.h index 460ff014e7..593f5df5f2 100644 --- a/src/apps/mediaplayer/Controller.h +++ b/src/apps/mediaplayer/Controller.h @@ -86,7 +86,8 @@ public: void PlayerActivated(bool active); void GetSize(int *width, int *height, - float* widthToHeightRatio = NULL); + int* widthAspect = NULL, + int* heightAspect = NULL); int AudioTrackCount(); int VideoTrackCount(); diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index 422e60d5de..7d3abbdf2d 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -116,8 +116,8 @@ MainWin::MainWin() fNoInterface(false), fSourceWidth(-1), fSourceHeight(-1), - fWidthScale(1.0), - fHeightScale(1.0), + fWidthAspect(0), + fHeightAspect(0), fMouseDownTracking(false), fGlobalSettingsListener(this) { @@ -592,31 +592,38 @@ MainWin::MessageReceived(BMessage *msg) break; case M_ASPECT_100000_1: - VideoFormatChange(fSourceWidth, fSourceHeight, 1.0); + VideoFormatChange(fSourceWidth, fSourceHeight, + fSourceWidth, fSourceHeight); break; case M_ASPECT_106666_1: - VideoFormatChange(fSourceWidth, fSourceHeight, 1.06666); + VideoFormatChange(fSourceWidth, fSourceHeight, + lround(1.06666 * fSourceWidth), fSourceHeight); break; case M_ASPECT_109091_1: - VideoFormatChange(fSourceWidth, fSourceHeight, 1.09091); + VideoFormatChange(fSourceWidth, fSourceHeight, + lround(1.09091 * fSourceWidth), fSourceHeight); break; case M_ASPECT_141176_1: - VideoFormatChange(fSourceWidth, fSourceHeight, 1.41176); + VideoFormatChange(fSourceWidth, fSourceHeight, + lround(1.41176 * fSourceWidth), fSourceHeight); break; case M_ASPECT_720_576: - VideoFormatChange(720, 576, 1.06666); + VideoFormatChange(720, 576, + lround(1.06666 * fSourceWidth), fSourceHeight); break; case M_ASPECT_704_576: - VideoFormatChange(704, 576, 1.09091); + VideoFormatChange(704, 576, + lround(1.09091 * fSourceWidth), fSourceHeight); break; case M_ASPECT_544_576: - VideoFormatChange(544, 576, 1.41176); + VideoFormatChange(544, 576, + lround(1.41176 * fSourceWidth), fSourceHeight); break; case M_SET_PLAYLIST_POSITION: @@ -776,17 +783,18 @@ MainWin::ShowPlaylistWindow() 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 printf("VideoFormatChange enter: width %d, height %d, " - "widthToHeightRatio %.6f\n", width, height, widthToHeightRatio); + "aspect ratio: %d:%d\n", width, height, widthAspect, heightAspect); fSourceWidth = width; fSourceHeight = height; - fWidthScale = widthToHeightRatio; - fHeightScale = 1.0f; + fWidthAspect = widthAspect; + fHeightAspect = heightAspect; FrameResized(Bounds().Width(), Bounds().Height()); @@ -829,13 +837,13 @@ MainWin::_SetupWindow() int previousSourceWidth = fSourceWidth; int previousSourceHeight = fSourceHeight; if (fHasVideo) { - fController->GetSize(&fSourceWidth, &fSourceHeight, &fWidthScale); - fHeightScale = 1.0; + fController->GetSize(&fSourceWidth, &fSourceHeight, + &fWidthAspect, &fHeightAspect); } else { fSourceWidth = 0; fSourceHeight = 0; - fWidthScale = 1.0; - fHeightScale = 1.0; + fWidthAspect = 1; + fHeightAspect = 1; } _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 MainWin::_SetWindowSizeLimits() { @@ -1033,13 +1061,14 @@ void MainWin::_ResizeWindow(int percent) { // Get required window size - int videoWidth = lround(fSourceWidth * fWidthScale); - int videoHeight = lround(fSourceHeight * fHeightScale); + int videoWidth; + int videoHeight; + _GetUnscaledVideoSize(videoWidth, videoHeight); videoWidth = (videoWidth * percent) / 100; videoHeight = (videoHeight * percent) / 100; - // Calculate and set the initial window size + // Calculate and set the minimum window size int width; int height; _GetMinimumWindowSize(width, height); @@ -1060,8 +1089,11 @@ MainWin::_ResizeVideoView(int x, int y, int width, int height) if (fKeepAspectRatio) { // Keep aspect ratio, place video view inside // the background area (may create black bars). - float scaledWidth = fSourceWidth * fWidthScale; - float scaledHeight = fSourceHeight * fHeightScale; + int videoWidth; + int videoHeight; + _GetUnscaledVideoSize(videoWidth, videoHeight); + float scaledWidth = videoWidth; + float scaledHeight = videoHeight; float factor = min_c(width / scaledWidth, height / scaledHeight); int renderWidth = lround(scaledWidth * factor); int renderHeight = lround(scaledHeight * factor); diff --git a/src/apps/mediaplayer/MainWin.h b/src/apps/mediaplayer/MainWin.h index c5ae2231cf..5a6e4713a6 100644 --- a/src/apps/mediaplayer/MainWin.h +++ b/src/apps/mediaplayer/MainWin.h @@ -59,7 +59,7 @@ public: void ShowSettingsWindow(); void VideoFormatChange(int width, int height, - float widthToHeightRatio); + int widthAspect, int heightAspect); private: void _RefsReceived(BMessage* message); @@ -73,6 +73,8 @@ private: void _GetMinimumWindowSize(int& width, int& height) const; void _SetWindowSizeLimits(); + void _GetUnscaledVideoSize(int& videoWidth, + int& videoHeight) const; void _ResizeWindow(int percent); void _ResizeVideoView(int x, int y, int width, int height); @@ -132,8 +134,8 @@ private: volatile bool fNoInterface; int fSourceWidth; int fSourceHeight; - float fWidthScale; - float fHeightScale; + int fWidthAspect; + int fHeightAspect; int fMenuBarWidth; int fMenuBarHeight; int fControlsHeight;