Skip to content

Commit

Permalink
Subtitles: Make the subtitle zoom factor into a live setting.
Browse files Browse the repository at this point in the history
OSDCC708TextZoom is removed from the frontend OSD setup screen and
added as a "live setting" to the Subtitles menu of the playback OSD.
This brings up an adjustment dialog similar to adjusting audio sync or
timestretch.

The menu item is only offered when subtitles are currently enabled.

For text and CEA-708 subtitles, adjustments take effect immediately.
For CEA-608, the adjustment takes effect only when the next caption is
displayed, due to the way the 608 reader is structured.

For now, only the Subtitles menu entry is provided, but if needed, it
would be practical to add a wider set of actions and keybindings to
match the implementation of audio sync and timestretch adjustment.
  • Loading branch information
stichnot committed May 17, 2012
1 parent 76ed2bc commit 0089f7d
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 16 deletions.
3 changes: 2 additions & 1 deletion mythtv/libs/libmythtv/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ enum OSDFunctionalType
kOSDFunctionalType_PictureAdjust,
kOSDFunctionalType_SmartForward,
kOSDFunctionalType_TimeStretchAdjust,
kOSDFunctionalType_AudioSyncAdjust
kOSDFunctionalType_AudioSyncAdjust,
kOSDFunctionalType_SubtitleZoomAdjust
};

enum OSDTimeout
Expand Down
12 changes: 8 additions & 4 deletions mythtv/libs/libmythtv/subtitlescreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ SubtitleScreen::SubtitleScreen(MythPlayer *player, const char * name,
m_player(player), m_subreader(NULL), m_608reader(NULL),
m_708reader(NULL), m_safeArea(QRect()),
m_removeHTML(QRegExp("</?.+>")), m_subtitleType(kDisplayNone),
m_textFontZoom(100), m_refreshArea(false),
m_textFontZoom(100), m_textFontZoomPrev(100), m_refreshArea(false),
m_fontStretch(fontStretch),
m_format(new SubtitleFormat)
{
Expand Down Expand Up @@ -614,12 +614,14 @@ bool SubtitleScreen::Create(void)
if (!m_708reader)
LOG(VB_GENERAL, LOG_WARNING, LOC + "Failed to get CEA-708 reader.");
m_textFontZoom = gCoreContext->GetNumSetting("OSDCC708TextZoom", 100);
m_textFontZoomPrev = m_textFontZoom;

return true;
}

void SubtitleScreen::Pulse(void)
{
m_textFontZoom = gCoreContext->GetNumSetting("OSDCC708TextZoom", 100);
ExpireSubtitles();

DisplayAVSubtitles(); // allow forced subtitles to work
Expand All @@ -636,6 +638,7 @@ void SubtitleScreen::Pulse(void)
OptimiseDisplayedArea();
MythScreenType::Pulse();
m_refreshArea = false;
m_textFontZoomPrev = m_textFontZoom;
}

void SubtitleScreen::ClearAllSubtitles(void)
Expand Down Expand Up @@ -867,7 +870,7 @@ void SubtitleScreen::DisplayTextSubtitles(void)
if (!m_player || !m_subreader)
return;

bool changed = false;
bool changed = (m_textFontZoom != m_textFontZoomPrev);
VideoOutput *vo = m_player->GetVideoOutput();
if (!vo)
return;
Expand Down Expand Up @@ -1099,7 +1102,7 @@ void SubtitleScreen::DisplayCC608Subtitles(void)
if (!m_608reader)
return;

bool changed = false;
bool changed = (m_textFontZoom != m_textFontZoomPrev);

if (!m_player || !m_player->GetVideoOutput())
return;
Expand Down Expand Up @@ -1145,7 +1148,8 @@ void SubtitleScreen::DisplayCC708Subtitles(void)
video_aspect = m_player->GetVideoAspect();
QRect oldsafe = m_safeArea;
m_safeArea = m_player->GetVideoOutput()->GetSafeRect();
changed = (oldsafe != m_safeArea);
changed = (oldsafe != m_safeArea ||
m_textFontZoom != m_textFontZoomPrev);
if (changed)
{
for (uint i = 0; i < 8; i++)
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythtv/subtitlescreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class SubtitleScreen : public MythScreenType
QHash<MythUIType*, long long> m_expireTimes;
int m_fontSize;
int m_textFontZoom; // valid for 708 & text subs
int m_textFontZoomPrev;
bool m_refreshArea;
QHash<int,QList<MythUIType*> > m_708imageCache;
int m_fontStretch;
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythtv/tv_actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#define ACTION_DISABLEEXTTEXT "DISABLEEXTTEXT"
#define ACTION_ENABLEEXTTEXT "ENABLEEXTTEXT"
#define ACTION_TOGGLEEXTTEXT "TOGGLETEXT"
#define ACTION_TOGGLESUBTITLEZOOM "TOGGLESUBZOOM"

/* Interactive Television keys */
#define ACTION_MENURED "MENURED"
Expand Down
64 changes: 64 additions & 0 deletions mythtv/libs/libmythtv/tv_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ TV::TV(void)
wantsToQuit(true),
stretchAdjustment(false),
audiosyncAdjustment(false),
subtitleZoomAdjustment(false),
editmode(false), zoomMode(false),
sigMonMode(false),
endOfRecording(false),
Expand Down Expand Up @@ -1414,6 +1415,7 @@ TVState TV::GetState(int player_idx) const
return ret;
}

// XXX what about subtitlezoom?
void TV::GetStatus(void)
{
QVariantMap status;
Expand Down Expand Up @@ -3806,6 +3808,7 @@ bool TV::ProcessKeypress(PlayerContext *actx, QKeyEvent *e)
handled = handled || PictureAttributeHandleAction(actx, actions);
handled = handled || TimeStretchHandleAction(actx, actions);
handled = handled || AudioSyncHandleAction(actx, actions);
handled = handled || SubtitleZoomHandleAction(actx, actions);
handled = handled || DiscMenuHandleAction(actx, actions);
handled = handled || ActiveHandleAction(
actx, actions, isDVD, isMenuOrStill);
Expand Down Expand Up @@ -4036,6 +4039,30 @@ bool TV::AudioSyncHandleAction(PlayerContext *ctx,
return handled;
}

bool TV::SubtitleZoomHandleAction(PlayerContext *ctx,
const QStringList &actions)
{
if (!subtitleZoomAdjustment)
return false;

bool handled = true;

if (has_action(ACTION_LEFT, actions))
ChangeSubtitleZoom(ctx, -1);
else if (has_action(ACTION_RIGHT, actions))
ChangeSubtitleZoom(ctx, 1);
else if (has_action(ACTION_UP, actions))
ChangeSubtitleZoom(ctx, -10);
else if (has_action(ACTION_DOWN, actions))
ChangeSubtitleZoom(ctx, 10);
else if (has_action(ACTION_TOGGLESUBTITLEZOOM, actions))
ClearOSD(ctx);
else
handled = false;

return handled;
}

bool TV::DiscMenuHandleAction(PlayerContext *ctx, const QStringList &actions)
{
int64_t pts = 0;
Expand Down Expand Up @@ -4407,6 +4434,8 @@ bool TV::ToggleHandleAction(PlayerContext *ctx,
ToggleAdjustFill(ctx);
else if (has_action(ACTION_TOGGELAUDIOSYNC, actions))
ChangeAudioSync(ctx, 0); // just display
else if (has_action(ACTION_TOGGLESUBTITLEZOOM, actions))
ChangeSubtitleZoom(ctx, 0); // just display
else if (has_action(ACTION_TOGGLEVISUALISATION, actions))
EnableVisualisation(ctx, false, true /*toggle*/);
else if (has_action(ACTION_ENABLEVISUALISATION, actions))
Expand Down Expand Up @@ -8374,6 +8403,33 @@ void TV::EnableUpmix(PlayerContext *ctx, bool enable, bool toggle)
SetOSDMessage(ctx, enabled ? tr("Upmixer On") : tr("Upmixer Off"));
}

void TV::ChangeSubtitleZoom(PlayerContext *ctx, int dir)
{
ctx->LockDeletePlayer(__FILE__, __LINE__);
if (!ctx->player)
{
ctx->UnlockDeletePlayer(__FILE__, __LINE__);
return;
}

subtitleZoomAdjustment = true;
bool showing = ctx->player->GetCaptionsEnabled();
int newval = gCoreContext->GetNumSetting("OSDCC708TextZoom", 100) + dir;
newval = max(50, newval);
newval = min(200, newval);
ctx->UnlockDeletePlayer(__FILE__, __LINE__);

if (showing && !browsehelper->IsBrowsing())
{
UpdateOSDStatus(ctx, tr("Adjust Subtitle Zoom"), tr("Subtitle Zoom"),
QString::number(newval),
kOSDFunctionalType_SubtitleZoomAdjust,
"%", newval * 1000 / 200, 0, 0, kOSDTimeout_Long);
SetUpdateOSDPosition(false);
gCoreContext->SaveSetting("OSDCC708TextZoom", newval);
}
}

// dir in 10ms jumps
void TV::ChangeAudioSync(PlayerContext *ctx, int dir, int newsync)
{
Expand Down Expand Up @@ -9251,6 +9307,9 @@ void TV::HandleOSDClosed(int osdType)
case kOSDFunctionalType_AudioSyncAdjust:
audiosyncAdjustment = false;
break;
case kOSDFunctionalType_SubtitleZoomAdjust:
subtitleZoomAdjustment = false;
break;
case kOSDFunctionalType_Default:
break;
}
Expand Down Expand Up @@ -10172,6 +10231,8 @@ void TV::OSDDialogEvent(int result, QString text, QString action)
}
else if (action.left(15) == ACTION_TOGGELAUDIOSYNC)
ChangeAudioSync(actx, 0);
else if (action == ACTION_TOGGLESUBTITLEZOOM)
ChangeSubtitleZoom(actx, 0);
else if (action == ACTION_TOGGLEVISUALISATION)
EnableVisualisation(actx, false, true /*toggle*/);
else if (action == ACTION_ENABLEVISUALISATION)
Expand Down Expand Up @@ -10879,6 +10940,9 @@ void TV::FillOSDMenuSubtitles(const PlayerContext *ctx, OSD *osd,
}
if (!ttm_tracks.empty())
osd->DialogAddButton(tr("Toggle Teletext Menu"), "TOGGLETTM");
if (enabled)
osd->DialogAddButton(tr("Adjust Subtitle Zoom"),
ACTION_TOGGLESUBTITLEZOOM);
}
else if (category == "AVSUBTITLES")
{
Expand Down
6 changes: 6 additions & 0 deletions mythtv/libs/libmythtv/tv_play.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ class MTV_PUBLIC TV : public QObject
void UpdateOSDAskAllowDialog(PlayerContext*);
void SetUpdateOSDPosition(bool set_it);

// Captions/subtitles
bool SubtitleZoomHandleAction(PlayerContext *ctx,
const QStringList &actions);
void ChangeSubtitleZoom(PlayerContext *ctx, int dir);

// PxP handling
bool CreatePBP(PlayerContext *lctx, const ProgramInfo *info);
bool CreatePIP(PlayerContext *lctx, const ProgramInfo *info);
Expand Down Expand Up @@ -666,6 +671,7 @@ class MTV_PUBLIC TV : public QObject
mutable bool wantsToQuit;
bool stretchAdjustment; ///< True if time stretch is turned on
bool audiosyncAdjustment; ///< True if audiosync is turned on
bool subtitleZoomAdjustment; ///< True if subtitle zoom is turned on
bool editmode; ///< Are we in video editing mode
bool zoomMode;
bool sigMonMode; ///< Are we in signal monitoring mode?
Expand Down
11 changes: 0 additions & 11 deletions mythtv/programs/mythfrontend/globalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,16 +1323,6 @@ static HostComboBox MUNUSED *DecodeVBIFormat()
return gc;
}

static HostSpinBox *OSDCC708TextZoomPercentage(void)
{
HostSpinBox *gs = new HostSpinBox("OSDCC708TextZoom", 50, 200, 5);
gs->setLabel(QObject::tr("Subtitle text zoom percentage"));
gs->setValue(100);
gs->setHelpText(QObject::tr("Use this to enlarge or shrink text based subtitles."));

return gs;
}

static HostComboBox *SubtitleCodec()
{
HostComboBox *gc = new HostComboBox("SubtitleCodec");
Expand Down Expand Up @@ -3400,7 +3390,6 @@ OSDSettings::OSDSettings()
osd->addChild(PersistentBrowseMode());
osd->addChild(BrowseAllTuners());
osd->addChild(DefaultCCMode());
osd->addChild(OSDCC708TextZoomPercentage());
osd->addChild(SubtitleCodec());
addChild(osd);

Expand Down

0 comments on commit 0089f7d

Please sign in to comment.