Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix, refactor, cleanup and simplify taking screenshots.

- remove the ScreenShot jumppoint (it's an action not a jumppoint)
- 'promote' the TV Playback SCREENSHOT action to a Global action.
- consolidate the screenshot grabbing into several simple, reusable
methods in MythMainWindow. Grabbing always uses png and default quality
settings and only the size of the resulting screenshot can be set. The
ScreenShotPath setting is always used.
- convert both the network control code and frontend http interface to
use events to signal taking of a screenshot (using a customised
MythEventMessage with any size settings embedded in the extradata).
- intercept screenshot events in MythMainWindow and MythScreenType for
the main UI and in TV for media playback.
- Only VDPAU video playback doesn't grab the screen as expected (it
grabs the chromakey layer i.e. black) so I've added some custom code for
VDPAU.
- remove the existing TV screenshot code. It was hanging the frontend
and didn't actually grab what was on screen.

All told, the user should get a consistent screengrab 'experience' and
it should show what is on screen, whether in the main UI or watching
video (including OSD, visualisations etc. Only tested on linux but works
with XVideo, OpenGL and VDPAU).

N.B. There is a small change to the Network Control API as setting the
screenshot path is no longer supported.
  • Loading branch information...
commit fa9f32bd29bfb26445ea88ba35a3042e4d43955a 1 parent fad355b
Mark Kendall authored
7 mythtv/libs/libmythtv/mythplayer.cpp
View
@@ -3851,6 +3851,13 @@ bool MythPlayer::IsEmbedding(void)
return false;
}
+bool MythPlayer::GetScreenShot(int width, int height)
+{
+ if (videoOutput)
+ return videoOutput->GetScreenShot(width, height);
+ return false;
+}
+
bool MythPlayer::HasTVChainNext(void) const
{
return player_ctx->tvchain && player_ctx->tvchain->HasNext();
1  mythtv/libs/libmythtv/mythplayer.h
View
@@ -188,6 +188,7 @@ class MTV_PUBLIC MythPlayer
bool IsMuted(void) { return audio.IsMuted(); }
bool UsingNullVideo(void) const { return using_null_videoout; }
bool HasTVChainNext(void) const;
+ bool GetScreenShot(int width = 0, int height = 0);
// Non-const gets
VideoOutput *getVideoOutput(void) { return videoOutput; }
1  mythtv/libs/libmythtv/tv_actions.h
View
@@ -36,7 +36,6 @@
#define ACTION_JUMPTODVDCHAPTERMENU "JUMPTODVDCHAPTERMENU"
#define ACTION_JUMPTODVDTITLEMENU "JUMPTODVDTITLEMENU"
-#define ACTION_SCREENSHOT "SCREENSHOT"
#define ACTION_EXITSHOWNOPROMPTS "EXITSHOWNOPROMPTS"
/* Interactive Television keys */
81 mythtv/libs/libmythtv/tv_play.cpp
View
@@ -688,9 +688,6 @@ void TV::InitKeys(void)
REG_KEY("TV Playback", ACTION_EXITSHOWNOPROMPTS,
QT_TRANSLATE_NOOP("MythControls", "Exit Show without any prompts"),
"");
- REG_KEY("TV Playback", ACTION_SCREENSHOT,
- QT_TRANSLATE_NOOP("MythControls", "Save screenshot of current "
- "video frame"), "");
/* Interactive Television keys */
REG_KEY("TV Playback", ACTION_MENURED, QT_TRANSLATE_NOOP("MythControls",
@@ -3843,16 +3840,18 @@ bool TV::ActiveHandleAction(PlayerContext *ctx,
sigMonMode = !sigMonMode;
}
}
- else if (has_action(ACTION_SCREENSHOT, actions) && !isDVD)
+ else if (has_action(ACTION_SCREENSHOT, actions))
{
- long long caploc = -1;
ctx->LockDeletePlayer(__FILE__, __LINE__);
- if (ctx->player)
- caploc = ctx->player->GetFramesPlayed();
+ if (ctx->player && ctx->player->GetScreenShot())
+ {
+ // VideoOutput has saved screenshot
+ }
+ else
+ {
+ GetMythMainWindow()->ScreenShot();
+ }
ctx->UnlockDeletePlayer(__FILE__, __LINE__);
-
- if (caploc >= 0)
- ScreenShot(ctx, caploc);
}
else if (has_action(ACTION_EXITSHOWNOPROMPTS, actions))
{
@@ -8052,7 +8051,22 @@ void TV::customEvent(QEvent *e)
// TODO Go through these and make sure they make sense...
QStringList tokens = message.split(" ", QString::SkipEmptyParts);
- if (message.left(14) == "DONE_RECORDING")
+ if (message == ACTION_SCREENSHOT)
+ {
+ PlayerContext *mctx = GetPlayerWriteLock(0, __FILE__, __LINE__);
+ bool extra = me->ExtraDataCount() == 2;
+ int width = extra ? me->ExtraData(0).toInt() : 0;
+ int height = extra ? me->ExtraData(1).toInt() : 0;
+ if (mctx && mctx->player && mctx->player->GetScreenShot(width, height))
+ {
+ }
+ else
+ {
+ GetMythMainWindow()->ScreenShot(width, height);
+ }
+ ReturnPlayerLock(mctx);
+ }
+ else if (message.left(14) == "DONE_RECORDING")
{
int seconds = 0;
long long frames = 0;
@@ -11076,51 +11090,6 @@ void TV::ITVRestart(PlayerContext *ctx, bool isLive)
ctx->UnlockDeletePlayer(__FILE__, __LINE__);
}
-/* \fn TV::ScreenShot(PlayerContext*, long long)
- * \brief Creates an image of a particular frame from the current
- * playbackinfo recording.
- */
-bool TV::ScreenShot(PlayerContext *ctx, long long frameNumber)
-{
- QDir d;
- QString confdir = GetConfDir();
- if (!d.mkpath(confdir))
- {
- QString msg = tr("Screen Shot") + " " + tr("Error");
- SetOSDMessage(ctx, msg);
- return false;
- }
-
- ctx->LockPlayingInfo(__FILE__, __LINE__);
- if (!ctx->playingInfo)
- {
- VERBOSE(VB_IMPORTANT, LOC_ERR +
- "ScreenShot called with NULL playingInfo");
- ctx->UnlockPlayingInfo(__FILE__, __LINE__);
- return false;
- }
-
- QString outFile =
- QString("%1/%2_%3_%4.png")
- .arg(confdir).arg(ctx->playingInfo->GetChanID())
- .arg(ctx->playingInfo->GetRecordingStartTime(MythDate))
- .arg(frameNumber);
-
- PreviewGenerator *previewgen = new PreviewGenerator(
- ctx->playingInfo, QString(), PreviewGenerator::kLocalAndRemote);
- ctx->UnlockPlayingInfo(__FILE__, __LINE__);
-
- previewgen->SetPreviewTimeAsFrameNumber(frameNumber);
- previewgen->SetOutputSize(QSize(-1,-1));
- previewgen->SetOutputFilename(outFile);
- bool ok = previewgen->Run();
- previewgen->deleteLater();
-
- QString msg = tr("Screen Shot") + " " + ((ok) ? tr("OK") : tr("Error"));
- SetOSDMessage(ctx, msg);
- return ok;
-}
-
/* \fn TV::DVDJumpBack(PlayerContext*)
\brief jump to the previous dvd title or chapter
*/
2  mythtv/libs/libmythtv/tv_play.h
View
@@ -612,8 +612,6 @@ class MTV_PUBLIC TV : public QObject
void ITVRestart(PlayerContext*, bool isLive);
- bool ScreenShot(PlayerContext*, long long frameNumber);
-
// DVD methods
void DVDJumpBack(PlayerContext*);
void DVDJumpForward(PlayerContext*);
7 mythtv/libs/libmythtv/videoout_vdpau.cpp
View
@@ -1216,3 +1216,10 @@ void VideoOutputVDPAU::ParseOptions(void)
}
}
}
+
+bool VideoOutputVDPAU::GetScreenShot(int width, int height)
+{
+ if (m_render)
+ return m_render->GetScreenShot(width, height);
+ return false;
+}
1  mythtv/libs/libmythtv/videoout_vdpau.h
View
@@ -62,6 +62,7 @@ class VideoOutputVDPAU : public VideoOutput
virtual bool hasHWAcceleration(void) const
{ return codec_is_vdpau(video_codec_id); }
virtual MythPainter* GetOSDPainter(void) { return (MythPainter*)m_osd_painter; }
+ virtual bool GetScreenShot(int width = 0, int height = 0);
virtual bool CanVisualise(AudioPlayer *audio, MythRender *render)
{ return VideoOutput::CanVisualise(audio, m_render); }
1  mythtv/libs/libmythtv/videooutbase.h
View
@@ -240,6 +240,7 @@ class VideoOutput
virtual QString GetOSDRenderer(void) const;
virtual MythPainter *GetOSDPainter(void) { return (MythPainter*)osd_painter; }
+ virtual bool GetScreenShot(int width = 0, int height = 0) { return false; }
QString GetFilters(void) const;
/// \brief translates caption/dvd button rectangle into 'screen' space
135 mythtv/libs/libmythui/mythmainwindow.cpp
View
@@ -485,10 +485,6 @@ MythMainWindow::MythMainWindow(const bool useDB)
d->repaintRegion = QRegion(QRect(0,0,0,0));
d->m_drawEnabled = true;
-
- connect(this, SIGNAL(signalRemoteScreenShot(QString,int,int)),
- this, SLOT(doRemoteScreenShot(QString,int,int)),
- Qt::BlockingQueuedConnection);
}
MythMainWindow::~MythMainWindow()
@@ -754,105 +750,49 @@ void MythMainWindow::closeEvent(QCloseEvent *e)
QWidget::closeEvent(e);
}
-bool MythMainWindow::screenShot(QString fname, int x, int y,
- int x2, int y2, int w, int h)
+void MythMainWindow::GrabWindow(QImage &image)
{
- bool ret = false;
-
- QString extension = fname.section('.', -1, -1);
- if (extension == "jpg")
- extension = "JPEG";
- else
- extension = "PNG";
-
- VERBOSE(VB_GENERAL, "MythMainWindow::screenShot saving winId " +
- QString("%1 to %2 (%3 x %4) [ %5/%6 - %7/%8] type %9")
- .arg((long)QApplication::desktop()->winId())
- .arg(fname)
- .arg(w).arg(h)
- .arg(x).arg(y)
- .arg(x2).arg(y2)
- .arg(extension));
-
- QPixmap p;
- p = QPixmap::grabWindow( QApplication::desktop()->winId(), x, y, x2, y2);
-
- QImage img = p.toImage();
-
- if ( w == 0 )
- w = img.width();
-
- if ( h == 0 )
- h = img.height();
-
- VERBOSE(VB_GENERAL, QString("Scaling to %1 x %2 from %3 x %4")
- .arg(w)
- .arg(h)
- .arg(img.width())
- .arg(img.height()));
-
- img = img.scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation);
-
- if (img.save(fname, extension.toAscii(), 100))
- {
- VERBOSE(VB_GENERAL, "MythMainWindow::screenShot succeeded");
- ret = true;
- }
+ WId winid;
+ QWidget *active = QApplication::activeWindow();
+ if (active)
+ winid = active->winId();
else
- {
- VERBOSE(VB_GENERAL, "MythMainWindow::screenShot Failed!");
- ret = false;
- }
+ winid = QApplication::desktop()->winId();
- return ret;
+ QPixmap p = QPixmap::grabWindow(winid);
+ image = p.toImage();
}
-bool MythMainWindow::screenShot(int x, int y, int x2, int y2)
+bool MythMainWindow::SaveScreenShot(const QImage &image)
{
- QString fPath = GetMythDB()->GetSetting("ScreenShotPath","/tmp/");
- QString fName = QString("/%1/myth-screenshot-%2.png")
- .arg(fPath)
- .arg(QDateTime::currentDateTime()
- .toString("yyyy-MM-ddThh-mm-ss.zzz"));
+ QString fpath = GetMythDB()->GetSetting("ScreenShotPath", "/tmp");
+ QString fname = QString("%1/myth-screenshot-%2.png").arg(fpath)
+ .arg(QDateTime::currentDateTime().toString("yyyy-MM-ddThh-mm-ss.zzz"));
- return screenShot(fName, x, y, x2, y2, 0, 0);
-}
+ VERBOSE(VB_GENERAL,QString("Saving screenshot to %1 (%2x%3)")
+ .arg(fname).arg(image.width()).arg(image.height()));
-bool MythMainWindow::screenShot(QString fname, int w, int h)
-{
- QWidget *active = QApplication::activeWindow();
- if (active)
+ if (image.save(fname))
{
- QRect sLoc = active->geometry();
- return screenShot(fname, sLoc.left(),sLoc.top(),
- sLoc.width(), sLoc.height(), w, h);
+ VERBOSE(VB_GENERAL, "MythMainWindow::screenShot succeeded");
+ return true;
}
- return false;
-}
-void MythMainWindow::remoteScreenShot(QString fname, int w, int h)
-{
- // This will be running from the MythFEXML handler, primarily
- // Since QPixmap must be running in the GUI thread, we need to cross
- // threads here.
- emit signalRemoteScreenShot(fname, w, h);
+ VERBOSE(VB_GENERAL, "MythMainWindow::screenShot Failed!");
+ return false;
}
-void MythMainWindow::doRemoteScreenShot(QString fname, int w, int h)
+bool MythMainWindow::ScreenShot(int w, int h)
{
- // This will be running in the GUI thread
- screenShot(fname, w, h);
-}
+ QImage img;
+ GrabWindow(img);
+ if (w <= 0)
+ w = img.width();
+ if (h <= 0)
+ h = img.height();
-bool MythMainWindow::screenShot(void)
-{
- QWidget *active = QApplication::activeWindow();
- if (active)
- {
- QRect sLoc = active->geometry();
- return screenShot(sLoc.left(),sLoc.top(), sLoc.width(), sLoc.height());
- }
- return false;
+ img = img.scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ return SaveScreenShot(img);
}
bool MythMainWindow::event(QEvent *e)
@@ -1071,6 +1011,8 @@ void MythMainWindow::InitKeys()
"Delete"), "D");
RegisterKey("Global", "EDIT", QT_TRANSLATE_NOOP("MythControls",
"Edit"), "E");
+ RegisterKey("Global", ACTION_SCREENSHOT, QT_TRANSLATE_NOOP("MythControls",
+ "Save screenshot"), "");
RegisterKey("Global", "PAGEUP", QT_TRANSLATE_NOOP("MythControls",
"Page Up"), "PgUp");
@@ -1762,9 +1704,7 @@ void MythMainWindow::RegisterJump(const QString &destination,
void MythMainWindow::JumpTo(const QString& destination, bool pop)
{
- if (destination == "ScreenShot")
- screenShot();
- else if (d->destinationMap.count(destination) > 0 && d->exitmenucallback == NULL)
+ if (d->destinationMap.count(destination) > 0 && d->exitmenucallback == NULL)
{
d->exitingtomain = true;
d->popwindows = pop;
@@ -2242,6 +2182,19 @@ void MythMainWindow::customEvent(QEvent *ce)
message.mid(tokens[0].length() +
tokens[1].length() + 2));
}
+ else if (message.startsWith(ACTION_SCREENSHOT))
+ {
+ if (me->ExtraDataCount() == 2)
+ {
+ int width = me->ExtraData(0).toInt();
+ int height = me->ExtraData(1).toInt();
+ ScreenShot(width, height);
+ }
+ else
+ {
+ ScreenShot();
+ }
+ }
}
else if ((MythEvent::Type)(ce->type()) == MythEvent::MythUserMessage)
{
12 mythtv/libs/libmythui/mythmainwindow.h
View
@@ -91,11 +91,9 @@ class MUI_PUBLIC MythMainWindow : public QWidget
QWidget *GetPaintWindow();
MythRender *GetRenderDevice();
- bool screenShot(QString fname, int x, int y, int x2, int y2, int w, int h);
- bool screenShot(int x, int y, int x2, int y2);
- bool screenShot(QString fname, int w, int h);
- bool screenShot(void);
- void remoteScreenShot(QString fname, int w, int h);
+ void GrabWindow(QImage &image);
+ bool SaveScreenShot(const QImage &image);
+ bool ScreenShot(int w = 0, int h = 0);
void AllowInput(bool allow);
@@ -128,10 +126,6 @@ class MUI_PUBLIC MythMainWindow : public QWidget
protected slots:
void animate();
- void doRemoteScreenShot(QString fname, int w, int h);
-
- signals:
- void signalRemoteScreenShot(QString fname, int w, int h);
protected:
MythMainWindow(const bool useDB = true);
55 mythtv/libs/libmythui/mythrender_vdpau.cpp
View
@@ -4,6 +4,7 @@
#include <QThread>
#include "mythverbose.h"
+#include "mythmainwindow.h"
#include "mythrender_vdpau.h"
// NB this may be API dependant
@@ -474,6 +475,54 @@ void MythRenderVDPAU::MoveResizeWin(QRect &rect)
m_display->MoveResizeWin(m_window, rect);
}
+bool MythRenderVDPAU::GetScreenShot(int width, int height)
+{
+ LOCK_RENDER
+ CHECK_STATUS(false)
+
+ if (m_surface >= (uint)m_surfaces.size())
+ return false;
+
+ VdpRGBAFormat fmt;
+ uint32_t w, h;
+ VdpOutputSurface surface = m_outputSurfaces[m_surfaces[m_surface]].m_id;
+ INIT_ST
+ vdp_st = vdp_output_surface_get_parameters(surface, &fmt, &w, &h);
+ CHECK_ST
+
+ if (!ok || fmt != VDP_RGBA_FORMAT_B8G8R8A8 || w <= 0 || h <= 0)
+ return false;
+
+ int size = w * h * 4;
+ unsigned char* buffer = new unsigned char[size];
+ void* const data[1] = { buffer };
+ const uint32_t pitches[1] = { w * 4 };
+ vdp_st = vdp_output_surface_get_bits_native(surface, NULL, data, pitches);
+ CHECK_ST
+
+ if (!ok)
+ {
+ delete [] buffer;
+ return false;
+ }
+
+ bool success = false;
+ QImage img(buffer, w, h, QImage::Format_RGB32);
+ MythMainWindow *window = GetMythMainWindow();
+ if (window)
+ {
+ if (width <= 0)
+ width = img.width();
+ if (height <= 0)
+ height = img.height();
+
+ img = img.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ success = window->SaveScreenShot(img);
+ }
+ delete [] buffer;
+ return success;
+}
+
void MythRenderVDPAU::CheckOutputSurfaces(void)
{
LOCK_RENDER
@@ -1423,6 +1472,10 @@ bool MythRenderVDPAU::GetProcs(void)
GET_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY, vdp_output_surface_destroy);
GET_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_BITMAP_SURFACE,
vdp_output_surface_render_bitmap_surface);
+ GET_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_GET_PARAMETERS,
+ vdp_output_surface_get_parameters);
+ GET_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_GET_BITS_NATIVE,
+ vdp_output_surface_get_bits_native);
GET_PROC(VDP_FUNC_ID_VIDEO_MIXER_CREATE, vdp_video_mixer_create);
GET_PROC(VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES,
vdp_video_mixer_set_feature_enables);
@@ -1649,6 +1702,8 @@ void MythRenderVDPAU::ResetProcs(void)
vdp_output_surface_create = NULL;
vdp_output_surface_destroy = NULL;
vdp_output_surface_render_bitmap_surface = NULL;
+ vdp_output_surface_get_parameters = NULL;
+ vdp_output_surface_get_bits_native = NULL;
vdp_video_mixer_create = NULL;
vdp_video_mixer_set_feature_enables = NULL;
vdp_video_mixer_destroy = NULL;
3  mythtv/libs/libmythui/mythrender_vdpau.h
View
@@ -73,6 +73,7 @@ class MUI_PUBLIC MythRenderVDPAU : public MythRender
void DrawDisplayRect(const QRect &rect, bool use_colorkey = false);
void MoveResizeWin(QRect &rect);
void CheckOutputSurfaces(void);
+ bool GetScreenShot(int width = 0, int height = 0);
uint CreateOutputSurface(const QSize &size,
VdpRGBAFormat fmt = VDP_RGBA_FORMAT_B8G8R8A8,
@@ -190,6 +191,8 @@ class MUI_PUBLIC MythRenderVDPAU : public MythRender
VdpOutputSurfaceCreate *vdp_output_surface_create;
VdpOutputSurfaceDestroy *vdp_output_surface_destroy;
VdpOutputSurfaceRenderBitmapSurface *vdp_output_surface_render_bitmap_surface;
+ VdpOutputSurfaceGetParameters *vdp_output_surface_get_parameters;
+ VdpOutputSurfaceGetBitsNative *vdp_output_surface_get_bits_native;
VdpVideoMixerCreate *vdp_video_mixer_create;
VdpVideoMixerSetFeatureEnables *vdp_video_mixer_set_feature_enables;
VdpVideoMixerDestroy *vdp_video_mixer_destroy;
4 mythtv/libs/libmythui/mythscreentype.cpp
View
@@ -446,6 +446,10 @@ bool MythScreenType::keyPressEvent(QKeyEvent *event)
QCoreApplication::postEvent(
GetMythMainWindow()->GetSystemEventHandler(), me.clone());
}
+ else if (action == ACTION_SCREENSHOT)
+ {
+ GetMythMainWindow()->ScreenShot();
+ }
else
handled = false;
}
2  mythtv/libs/libmythui/mythuiactions.h
View
@@ -18,4 +18,6 @@
#define ACTION_LEFT "LEFT"
#define ACTION_RIGHT "RIGHT"
+#define ACTION_SCREENSHOT "SCREENSHOT"
+
#endif // MYTHUI_ACTIONS_H
8 mythtv/programs/mythfrontend/main.cpp
View
@@ -923,11 +923,6 @@ static void reloadTheme_void(void)
exit(err);
}
-static void getScreenShot(void)
-{
- (void) GetMythMainWindow()->screenShot();
-}
-
static void setDebugShowBorders(void)
{
MythPainter *p = GetMythPainter();
@@ -978,9 +973,6 @@ static void InitJumpPoints(void)
REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "Previously Recorded"),
"", "", startPrevious);
- REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "ScreenShot"),
- "", "", getScreenShot, false);
-
REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "Toggle Show Widget Borders"),
"", "", setDebugShowBorders, false);
REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "Toggle Show Widget Names"),
34 mythtv/programs/mythfrontend/mythfexml.cpp
View
@@ -132,35 +132,25 @@ bool MythFEXML::ProcessRequest( HttpWorkerThread *pThread, HTTPRequest *pRequest
void MythFEXML::GetScreenShot(HTTPRequest *pRequest)
{
- pRequest->m_eResponseType = ResponseTypeFile;
+ pRequest->m_eResponseType = ResponseTypeHTML;
// Optional Parameters
-
int nWidth = pRequest->m_mapParams[ "width" ].toInt();
int nHeight = pRequest->m_mapParams[ "height" ].toInt();
- QString sFormat = pRequest->m_mapParams[ "format" ].toLower();
-
- if (sFormat.isEmpty())
- {
- sFormat = "png";
- }
-
- if (sFormat != "jpg" && sFormat != "png" && sFormat != "gif") {
- VERBOSE(VB_GENERAL, QString("Invalid screen shot format: %1")
- .arg(sFormat));
- return;
- }
- VERBOSE(VB_GENERAL, QString("Screen shot requested - %1") .arg(sFormat));
-
- QString sFileName = QString("/%1/myth-screenshot-XML.%2")
- .arg(gCoreContext->GetSetting("ScreenShotPath","/tmp/"))
- .arg(sFormat);
+ VERBOSE(VB_GENERAL, QString("Screen shot requested (%1x%2)")
+ .arg(nWidth).arg(nHeight));
MythMainWindow *window = GetMythMainWindow();
- emit window->remoteScreenShot(sFileName, nWidth, nHeight);
-
- pRequest->m_sFileName = sFileName;
+ QStringList args;
+ if (nWidth && nHeight)
+ {
+ args << QString::number(nWidth);
+ args << QString::number(nHeight);
+ }
+ MythEvent* me = new MythEvent(MythEvent::MythEventMessage,
+ ACTION_SCREENSHOT, args);
+ qApp->postEvent(window, me);
}
void MythFEXML::SendMessage(HTTPRequest *pRequest)
89 mythtv/programs/mythfrontend/networkcontrol.cpp
View
@@ -1168,8 +1168,7 @@ QString NetworkControl::processHelp(NetworkCommand *nc)
{
helpText +=
"screenshot - Takes a screenshot and saves it as screenshot.png\r\n"
- "screenshot FILENAME - Saves the screenshot as FILENAME\r\n"
- "screenshot FILENAME WxH - Saves the screenshot as a WxH size image\r\n";
+ "screenshot WxH - Saves the screenshot as a WxH size image\r\n";
}
else if (command == "exit")
{
@@ -1498,92 +1497,30 @@ QString NetworkControl::listChannels(const uint start, const uint limit) const
QString NetworkControl::saveScreenshot(NetworkCommand *nc)
{
- QString outFile = GetConfDir() + "/screenshot.png";
int width = 0;
int height = 0;
- QString location = GetMythUI()->GetCurrentLocation();
-
- if (location != "Playback")
+ if (nc->getArgCount() == 2)
{
- if (nc->getArgCount() >= 2)
- outFile = nc->getArg(1);
-
- if (nc->getArgCount() >= 3)
+ QStringList size = nc->getArg(1).split('x');
+ if (size.size() == 2)
{
- QStringList size = nc->getArg(2).split('x');
width = size[0].toInt();
height = size[1].toInt();
}
-
- MythMainWindow *window = GetMythMainWindow();
- emit window->remoteScreenShot(outFile, width, height);
- return "OK";
}
- QString result;
- int64_t frameNumber = 150;
-
- gotAnswer = false;
- QString message = QString("NETWORK_CONTROL QUERY POSITION");
- MythEvent me(message);
- gCoreContext->dispatch(me);
-
- QTime timer;
- timer.start();
- while (timer.elapsed() < 2000 && !gotAnswer)
- usleep(10000);
-
- if (gotAnswer)
+ MythMainWindow *window = GetMythMainWindow();
+ QStringList args;
+ if (width && height)
{
- QStringList results = answer.simplified().split(" ");
- if (results.size() < 8)
- return "ERROR: Invalid network control command";
-
- uint chanid = results[5].toUInt();
- QDateTime recstartts = myth_dt_from_string(results[6]);
- ProgramInfo pginfo(chanid, recstartts);
- if (!pginfo.GetChanID())
- return "ERROR: Unable to find program info for current program";
-
- if (nc->getArgCount() >= 4)
- outFile = nc->getArg(3);
-
- if (nc->getArgCount() >= 5)
- {
- QStringList size = nc->getArg(4).split('x');
- width = size[0].toInt();
- height = size[1].toInt();
- }
- else
- {
- width = -1;
- height = -1;
- }
-
- frameNumber = results[7].toLongLong();
-
- PreviewGenerator *previewgen = new PreviewGenerator(
- &pginfo, QString(), PreviewGenerator::kForceLocal);
- previewgen->SetPreviewTimeAsFrameNumber(frameNumber);
- previewgen->SetOutputFilename(outFile);
- previewgen->SetOutputSize(QSize(width, height));
- bool ok = previewgen->Run();
- previewgen->deleteLater();
-
- QString str = "ERROR: Unable to generate screenshot, check logs";
- if (ok)
- {
- str = QString("OK %1x%2")
- .arg((width > 0) ? width : 64).arg((height > 0) ? height : 64);
- }
-
- return str;
+ args << QString::number(width);
+ args << QString::number(height);
}
- else
- return "ERROR: Timed out waiting for reply from player";
-
- return "ERROR: Unknown reason";
+ MythEvent* me = new MythEvent(MythEvent::MythEventMessage,
+ ACTION_SCREENSHOT, args);
+ qApp->postEvent(window, me);
+ return "OK";
}
QString NetworkCommand::getFrom(int arg)
Please sign in to comment.
Something went wrong with that request. Please try again.