MythTV  master
thumbfinder.cpp
Go to the documentation of this file.
1 /* -*- Mode: c++ -*-
2  * vim: set expandtab tabstop=4 shiftwidth=4:
3  *
4  * Original Project
5  * MythTV http://www.mythtv.org
6  *
7  * Copyright (c) 2004, 2005 John Pullan <john@pullan.org>
8  * Copyright (c) 2009, Janne Grunau <janne-mythtv@grunau.be>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
24  *
25  */
26 
27 // c++
28 #include <cerrno>
29 #include <cmath>
30 #include <cstdlib>
31 #include <iostream>
32 #include <sys/stat.h>
33 
34 // qt
35 #include <QApplication>
36 #include <QDomDocument>
37 #include <QFile>
38 #include <QDir>
39 #include <QPainter>
40 
41 // myth
42 #include <mythcontext.h>
43 #include <mythdbcon.h>
44 #include <programinfo.h>
45 #include <mythuihelper.h>
46 #include <mythmainwindow.h>
47 #include <mythdialogbox.h>
48 #include <mythdirs.h>
49 #include <mythmiscutil.h>
50 #include <mythuitext.h>
51 #include <mythuibutton.h>
52 #include <mythuiimage.h>
53 #include <mythuibuttonlist.h>
54 #include <mythimage.h>
55 #include <mythconfig.h>
56 
57 extern "C" {
58 #include "libavutil/imgutils.h"
59 }
60 
61 #ifndef INT64_C // Used in FFmpeg headers to define some constants
62 #define INT64_C(v) (v ## LL)
63 #endif
64 
65 // mytharchive
66 #include "thumbfinder.h"
67 
68 // the amount to seek before the required frame
69 #define PRE_SEEK_AMOUNT 50
70 
71 static const std::array<const SeekAmount,9> kSeekAmounts
72 {{
73  {"frame", -1},
74  {"1 second", 1},
75  {"5 seconds", 5},
76  {"10 seconds", 10},
77  {"30 seconds", 30},
78  {"1 minute", 60},
79  {"5 minutes", 300},
80  {"10 minutes", 600},
81  {"Cut Point", -2},
82 }};
83 
85  const QString &menuTheme)
86  :MythScreenType(parent, "ThumbFinder"),
87  m_archiveItem(archiveItem),
88  m_thumbCount(getChapterCount(menuTheme)),
89  m_thumbDir(createThumbDir())
90 {
91  // copy thumbList so we can abandon changes if required
92  m_thumbList.clear();
93  for (const auto *item : qAsConst(m_archiveItem->thumbList))
94  {
95  auto *thumb = new ThumbImage;
96  *thumb = *item;
97  m_thumbList.append(thumb);
98  }
99 }
100 
102 {
103  getThumbImages();
104 }
105 
107 {
108  while (!m_thumbList.isEmpty())
109  delete m_thumbList.takeFirst();
110  m_thumbList.clear();
111 
112  closeAVCodec();
113 }
114 
116 {
117  // Load the theme for this screen
118  bool foundtheme = LoadWindowFromXML("mythburn-ui.xml", "thumbfinder", this);
119  if (!foundtheme)
120  return false;
121 
122  bool err = false;
123  UIUtilE::Assign(this, m_frameImage, "frameimage", &err);
124  UIUtilE::Assign(this, m_positionImage, "positionimage", &err);
125  UIUtilE::Assign(this, m_imageGrid, "thumblist", &err);
126  UIUtilE::Assign(this, m_saveButton, "save_button", &err);
127  UIUtilE::Assign(this, m_cancelButton, "cancel_button", &err);
128  UIUtilE::Assign(this, m_frameButton, "frame_button", &err);
129  UIUtilE::Assign(this, m_seekAmountText, "seekamount", &err);
130  UIUtilE::Assign(this, m_currentPosText, "currentpos", &err);
131 
132  if (err)
133  {
134  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'mythburn'");
135  return false;
136  }
137 
140 
143 
145 
147 
148  BuildFocusList();
149 
151 
152  return true;
153 }
154 
155 bool ThumbFinder::keyPressEvent(QKeyEvent *event)
156 {
157  if (GetFocusWidget()->keyPressEvent(event))
158  return true;
159 
160  QStringList actions;
161  bool handled = GetMythMainWindow()->TranslateKeyPress("Archive", event, actions);
162 
163  for (int i = 0; i < actions.size() && !handled; i++)
164  {
165  QString action = actions[i];
166  handled = true;
167 
168  if (action == "MENU")
169  {
170  NextPrevWidgetFocus(true);
171  return true;
172  }
173 
174  if (action == "ESCAPE")
175  {
176  ShowMenu();
177  return true;
178  }
179 
180  if (action == "0" || action == "1" || action == "2" || action == "3" ||
181  action == "4" || action == "5" || action == "6" || action == "7" ||
182  action == "8" || action == "9")
183  {
185  int itemNo = m_imageGrid->GetCurrentPos();
186  ThumbImage *thumb = m_thumbList.at(itemNo);
187  if (thumb)
188  seekToFrame(thumb->frame);
189  return true;
190  }
191 
192  if (GetFocusWidget() == m_frameButton)
193  {
194  if (action == "UP")
195  {
196  changeSeekAmount(true);
197  }
198  else if (action == "DOWN")
199  {
200  changeSeekAmount(false);
201  }
202  else if (action == "LEFT")
203  {
204  seekBackward();
205  }
206  else if (action == "RIGHT")
207  {
208  seekForward();
209  }
210  else if (action == "SELECT")
211  {
212  updateThumb();
213  }
214  else
215  handled = false;
216  }
217  else
218  handled = false;
219  }
220 
221  if (!handled && MythScreenType::keyPressEvent(event))
222  handled = true;
223 
224  return handled;
225 }
226 
227 int ThumbFinder::getChapterCount(const QString &menuTheme)
228 {
229  QString filename = GetShareDir() + "mytharchive/themes/" +
230  menuTheme + "/theme.xml";
231  QDomDocument doc("mydocument");
232  QFile file(filename);
233 
234  if (!file.open(QIODevice::ReadOnly))
235  {
236  LOG(VB_GENERAL, LOG_ERR, "Failed to open theme file: " + filename);
237  return 0; //??
238  }
239  if (!doc.setContent(&file))
240  {
241  file.close();
242  LOG(VB_GENERAL, LOG_ERR, "Failed to parse theme file: " + filename);
243  return 0;
244  }
245  file.close();
246 
247  QDomNodeList chapterNodeList = doc.elementsByTagName("chapter");
248 
249  return chapterNodeList.count();
250 }
251 
253 {
255 
256  if (progInfo && m_archiveItem->hasCutlist)
257  progInfo->QueryCutList(m_deleteMap);
258  delete progInfo;
259 
260  if (m_deleteMap.isEmpty())
261  {
262  LOG(VB_GENERAL, LOG_ERR, "ThumbFinder::loadCutList: Got an empty delete map");
263  return;
264  }
265 
266  // if the first mark is a end mark then add the start mark at the beginning
267  frm_dir_map_t::const_iterator it = m_deleteMap.constBegin();
268  if (it.value() == MARK_CUT_END)
269  m_deleteMap.insert(0, MARK_CUT_START);
270 
271 
272  // if the last mark is a start mark then add the end mark at the end
273  it = m_deleteMap.constEnd();
274  --it;
275  if (it != m_deleteMap.constEnd())
276  {
277  if (it.value() == MARK_CUT_START)
279  }
280 }
281 
283 {
284  // copy the thumb details to the archiveItem
285  while (!m_archiveItem->thumbList.isEmpty())
286  delete m_archiveItem->thumbList.takeFirst();
287  m_archiveItem->thumbList.clear();
288 
289  for (const auto *item : qAsConst(m_thumbList))
290  {
291  auto *thumb = new ThumbImage;
292  *thumb = *item;
293  m_archiveItem->thumbList.append(thumb);
294  }
295 
296  Close();
297 }
298 
300 {
301  Close();
302 }
303 
305 {
306  int64_t pos = m_currentPTS - m_firstIFramePTS;
307  int64_t frame = pos / m_frameTime;
308 
309  if (m_currentPosText)
310  m_currentPosText->SetText(frameToTime(frame, true));
311 
312  updatePositionBar(frame);
313 }
314 
316 {
317  if (up)
318  {
319  m_currentSeek++;
320  if (m_currentSeek >= kSeekAmounts.size())
321  m_currentSeek = 0;
322  }
323  else
324  {
325  if (m_currentSeek == 0)
326  m_currentSeek = kSeekAmounts.size();
327  m_currentSeek--;
328  }
329 
331 }
332 
334 {
335  (void) item;
336 
337  int itemNo = m_imageGrid->GetCurrentPos();
338  ThumbImage *thumb = m_thumbList.at(itemNo);
339  if (thumb)
340  seekToFrame(thumb->frame);
341 }
342 
344 {
345  QString thumbDir = getTempDirectory() + "config/thumbs";
346 
347  // make sure the thumb directory exists
348  QDir dir(thumbDir);
349  if (!dir.exists())
350  {
351  dir.mkdir(thumbDir);
352  if( chmod(qPrintable(thumbDir), 0777) != 0 )
353  LOG(VB_GENERAL, LOG_ERR, "ThumbFinder: Failed to change permissions"
354  " on thumb directory: " + ENO);
355  }
356 
357  QString path;
358  for (int x = 1; dir.exists(); x++)
359  {
360  path = thumbDir + QString("/%1").arg(x);
361  dir.setPath(path);
362  }
363 
364  dir.mkdir(path);
365  if( chmod(qPrintable(path), 0777) != 0 )
366  LOG(VB_GENERAL, LOG_ERR, "ThumbFinder: Failed to change permissions on "
367  "thumb directory: %1" + ENO);
368 
369  return path;
370 }
371 
373 {
374  int itemNo = m_imageGrid->GetCurrentPos();
376 
377  ThumbImage *thumb = m_thumbList.at(itemNo);
378  if (!thumb)
379  return;
380 
381  // copy current frame image to the selected thumb image
382  QString imageFile = thumb->filename;
383  QFile dst(imageFile);
384  QFile src(m_frameFile);
385  copy(dst, src);
386 
387  item->SetImage(imageFile, "", true);
388 
389  // update the image grid item
390  int64_t pos = (int) ((m_currentPTS - m_startPTS) / m_frameTime);
391  thumb->frame = pos - m_offset;
392  if (itemNo != 0)
393  {
394  thumb->caption = frameToTime(thumb->frame);
395  item->SetText(thumb->caption);
396  }
397 
399 }
400 
401 QString ThumbFinder::frameToTime(int64_t frame, bool addFrame) const
402 {
403  int sec = (int) (frame / m_fps);
404  frame = frame - (int) (sec * m_fps);
405 
406  QString str = MythFormatTime(sec, "HH:mm:ss");
407  if (addFrame)
408  str += QString(".%1").arg(frame,10,2,QChar('0'));
409  return str;
410 }
411 
413 {
415  {
416  LOG(VB_GENERAL, LOG_ERR,
417  QString("ThumbFinder:: Failed to get file details for %1")
419  return false;
420  }
421 
423  return false;
424 
425  if (m_archiveItem->type == "Recording")
426  loadCutList();
427 
428  // calculate the file duration taking the cut list into account
430 
431  QString origFrameFile = m_frameFile;
432 
433  m_updateFrame = true;
434  getFrameImage();
435 
436  int chapterLen = 0;
437  if (m_thumbCount)
438  chapterLen = m_finalDuration / m_thumbCount;
439  else
440  chapterLen = m_finalDuration;
441 
442  m_updateFrame = false;
443 
444  // add title thumb
445  m_frameFile = m_thumbDir + "/title.jpg";
446  ThumbImage *thumb = nullptr;
447 
448  if (!m_thumbList.empty())
449  {
450  // use the thumb details in the thumbList if already available
451  thumb = m_thumbList.at(0);
452  }
453 
454  if (!thumb)
455  {
456  // no thumb available create a new one
457  thumb = new ThumbImage;
458  thumb->filename = m_frameFile;
459  thumb->frame = (int64_t) 0;
460  thumb->caption = "Title";
461  m_thumbList.append(thumb);
462  }
463  else
464  m_frameFile = thumb->filename;
465 
466  seekToFrame(thumb->frame);
467  getFrameImage();
468 
469  new MythUIButtonListItem(m_imageGrid, thumb->caption, thumb->filename);
470 
471  QCoreApplication::processEvents();
472 
473  for (int x = 1; x <= m_thumbCount; x++)
474  {
475  m_frameFile = m_thumbDir + QString("/chapter-%1.jpg").arg(x);
476 
477  thumb = nullptr;
478 
479  if (m_archiveItem->thumbList.size() > x)
480  {
481  // use the thumb details in the archiveItem if already available
482  thumb = m_archiveItem->thumbList.at(x);
483  }
484 
485  if (!thumb)
486  {
487  int chapter = chapterLen * (x - 1);
488  int hour = chapter / 3600;
489  int min = (chapter % 3600) / 60;
490  int sec = chapter % 60;
491  QString time = QString::asprintf("%02d:%02d:%02d", hour, min, sec);
492 
493  auto frame = (int64_t) (chapter * ceil(m_fps));
494 
495  // no thumb available create a new one
496  thumb = new ThumbImage;
497  thumb->filename = m_frameFile;
498  thumb->frame = frame;
499  thumb->caption = time;
500  m_thumbList.append(thumb);
501  }
502  else
503  m_frameFile = thumb->filename;
504 
505  seekToFrame(thumb->frame);
506  QCoreApplication::processEvents();
507  getFrameImage();
508  QCoreApplication::processEvents();
509  new MythUIButtonListItem(m_imageGrid, thumb->caption, thumb->filename);
510  QCoreApplication::processEvents();
511  }
512 
513  m_frameFile = origFrameFile;
514  seekToFrame(0);
515 
516  m_updateFrame = true;
517 
519 
521 
522  return true;
523 }
524 
525 bool ThumbFinder::initAVCodec(const QString &inFile)
526 {
527  // Open recording
528  LOG(VB_JOBQUEUE, LOG_INFO, QString("ThumbFinder: Opening '%1'")
529  .arg(inFile));
530 
531  if (!m_inputFC.Open(inFile))
532  {
533  LOG(VB_GENERAL, LOG_ERR, "ThumbFinder, Couldn't open input file" + ENO);
534  return false;
535  }
536 
537  // Getting stream information
538  int ret = avformat_find_stream_info(m_inputFC, nullptr);
539  if (ret < 0)
540  {
541  LOG(VB_GENERAL, LOG_ERR,
542  QString("Couldn't get stream info, error #%1").arg(ret));
543  return false;
544  }
545 
546  av_dump_format(m_inputFC, 0, qPrintable(inFile), 0);
547 
548  // find the first video stream
549  m_videostream = -1;
550 
551  for (uint i = 0; i < m_inputFC->nb_streams; i++)
552  {
553  AVStream *st = m_inputFC->streams[i];
554  if (m_inputFC->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
555  {
556  m_startTime = -1;
557  if (m_inputFC->streams[i]->start_time != (int) AV_NOPTS_VALUE)
558  m_startTime = m_inputFC->streams[i]->start_time;
559  else
560  {
561  LOG(VB_GENERAL, LOG_ERR,
562  "ThumbFinder: Failed to get start time");
563  return false;
564  }
565 
566  m_videostream = i;
567  m_frameWidth = st->codecpar->width;
568  m_frameHeight = st->codecpar->height;
569  if (st->r_frame_rate.den && st->r_frame_rate.num)
570  m_fps = av_q2d(st->r_frame_rate);
571  else
572  m_fps = 1/av_q2d(st->time_base);
573  break;
574  }
575  }
576 
577  if (m_videostream == -1)
578  {
579  LOG(VB_GENERAL, LOG_ERR, "Couldn't find a video stream");
580  return false;
581  }
582 
583  // get the codec context for the video stream
585  m_codecCtx->debug_mv = 0;
586  m_codecCtx->debug = 0;
587  m_codecCtx->workaround_bugs = 1;
588  m_codecCtx->lowres = 0;
589  m_codecCtx->idct_algo = FF_IDCT_AUTO;
590  m_codecCtx->skip_frame = AVDISCARD_DEFAULT;
591  m_codecCtx->skip_idct = AVDISCARD_DEFAULT;
592  m_codecCtx->skip_loop_filter = AVDISCARD_DEFAULT;
593  m_codecCtx->err_recognition = AV_EF_CAREFUL;
594  m_codecCtx->error_concealment = 3;
595 
596  // get decoder for video stream
597  m_codec = avcodec_find_decoder(m_codecCtx->codec_id);
598 
599  if (m_codec == nullptr)
600  {
601  LOG(VB_GENERAL, LOG_ERR,
602  "ThumbFinder: Couldn't find codec for video stream");
603  return false;
604  }
605 
606  // open codec
607  if (avcodec_open2(m_codecCtx, m_codec, nullptr) < 0)
608  {
609  LOG(VB_GENERAL, LOG_ERR,
610  "ThumbFinder: Couldn't open codec for video stream");
611  return false;
612  }
613 
614  // allocate temp buffer
615  int bufflen = m_frameWidth * m_frameHeight * 4;
616  m_outputbuf = new unsigned char[bufflen];
617  m_frameFile = getTempDirectory() + "work/frame.jpg";
618  return true;
619 }
620 
622 {
623  if (m_deleteMap.isEmpty() || !m_archiveItem->useCutlist)
624  return frameNumber;
625 
626  int diff = 0;
627  frm_dir_map_t::const_iterator it = m_deleteMap.constFind(frameNumber);
628 
629  for (it = m_deleteMap.constBegin(); it != m_deleteMap.constEnd(); ++it)
630  {
631  int start = it.key();
632 
633  ++it;
634  if (it == m_deleteMap.constEnd())
635  {
636  LOG(VB_GENERAL, LOG_ERR, "ThumbFinder: found a start cut but no cut end");
637  break;
638  }
639 
640  int end = it.key();
641 
642  if (start <= frameNumber + diff)
643  diff += end - start;
644  }
645 
646  m_offset = diff;
647  return frameNumber + diff;
648 }
649 
650 bool ThumbFinder::seekToFrame(int frame, bool checkPos)
651 {
652  // make sure the frame is not in a cut point
653  if (checkPos)
654  frame = checkFramePosition(frame);
655 
656  // seek to a position PRE_SEEK_AMOUNT frames before the required frame
657  int64_t timestamp = m_startTime + (frame * m_frameTime) -
659  int64_t requiredPTS = m_startPTS + (frame * m_frameTime);
660 
661  if (timestamp < m_startTime)
662  timestamp = m_startTime;
663 
664  if (av_seek_frame(m_inputFC, m_videostream, timestamp, AVSEEK_FLAG_ANY) < 0)
665  {
666  LOG(VB_GENERAL, LOG_ERR, "ThumbFinder::SeekToFrame: seek failed") ;
667  return false;
668  }
669 
670  avcodec_flush_buffers(m_codecCtx);
671  getFrameImage(true, requiredPTS);
672 
673  return true;
674 }
675 
677 {
678  int64_t currentFrame = (m_currentPTS - m_startPTS) / m_frameTime;
679 
680  int inc = kSeekAmounts[m_currentSeek].amount;
681 
682  if (inc == -1)
683  inc = 1;
684  else if (inc == -2)
685  {
686  int pos = 0;
687  frm_dir_map_t::const_iterator it;
688  for (it = m_deleteMap.constBegin(); it != m_deleteMap.constEnd(); ++it)
689  {
690  if (it.key() > (uint64_t)currentFrame)
691  {
692  pos = it.key();
693  break;
694  }
695  }
696  // seek to next cutpoint
697  m_offset = 0;
698  seekToFrame(pos, false);
699  return true;
700  }
701  else
702  inc = (int) (inc * ceil(m_fps));
703 
704  int64_t newFrame = currentFrame + inc - m_offset;
705  if (newFrame == currentFrame + 1)
706  getFrameImage(false);
707  else
708  seekToFrame(newFrame);
709 
710  return true;
711 }
712 
714 {
715  int64_t currentFrame = (m_currentPTS - m_startPTS) / m_frameTime;
716 
717  int inc = kSeekAmounts[m_currentSeek].amount;
718  if (inc == -1)
719  inc = -1;
720  else if (inc == -2)
721  {
722  // seek to previous cut point
723  frm_dir_map_t::const_iterator it;
724  int pos = 0;
725  for (it = m_deleteMap.constBegin(); it != m_deleteMap.constEnd(); ++it)
726  {
727  if (it.key() >= (uint64_t)currentFrame)
728  break;
729 
730  pos = it.key();
731  }
732 
733  // seek to next cutpoint
734  m_offset = 0;
735  seekToFrame(pos, false);
736  return true;
737  }
738  else
739  inc = (int) (-inc * ceil(m_fps));
740 
741  int64_t newFrame = currentFrame + inc - m_offset;
742  seekToFrame(newFrame);
743 
744  return true;
745 }
746 
747 bool ThumbFinder::getFrameImage(bool needKeyFrame, int64_t requiredPTS)
748 {
749  AVPacket pkt;
750  AVFrame orig;
751  AVFrame retbuf;
752  memset(&orig, 0, sizeof(AVFrame));
753  memset(&retbuf, 0, sizeof(AVFrame));
754 
755  av_init_packet(&pkt);
756 
757  bool frameFinished = false;
758  int frameCount = 0;
759  bool gotKeyFrame = false;
760 
761  while (av_read_frame(m_inputFC, &pkt) >= 0 && !frameFinished)
762  {
763  if (pkt.stream_index == m_videostream)
764  {
765  frameCount++;
766 
767  int keyFrame = pkt.flags & AV_PKT_FLAG_KEY;
768 
769  if (m_startPTS == -1 && pkt.dts != AV_NOPTS_VALUE)
770  {
771  m_startPTS = pkt.dts;
772  m_frameTime = pkt.duration;
773  }
774 
775  if (keyFrame)
776  gotKeyFrame = true;
777 
778  if (!gotKeyFrame && needKeyFrame)
779  {
780  av_packet_unref(&pkt);
781  continue;
782  }
783 
784  if (m_firstIFramePTS == -1)
785  m_firstIFramePTS = pkt.dts;
786 
787  av_frame_unref(m_frame);
788  frameFinished = false;
789  int ret = avcodec_receive_frame(m_codecCtx, m_frame);
790  if (ret == 0)
791  frameFinished = true;
792  if (ret == 0 || ret == AVERROR(EAGAIN))
793  avcodec_send_packet(m_codecCtx, &pkt);
794  if (requiredPTS != -1 && pkt.dts != AV_NOPTS_VALUE && pkt.dts < requiredPTS)
795  frameFinished = false;
796 
797  m_currentPTS = pkt.dts;
798  }
799 
800  av_packet_unref(&pkt);
801  }
802 
803  if (frameFinished)
804  {
805  av_image_fill_arrays(retbuf.data, retbuf.linesize, m_outputbuf,
806  AV_PIX_FMT_RGB32, m_frameWidth, m_frameHeight, IMAGE_ALIGN);
807  AVFrame *tmp = m_frame;
809  m_copy.Copy(&retbuf, AV_PIX_FMT_RGB32, tmp, m_codecCtx->pix_fmt,
811 
813  QImage::Format_RGB32);
814 
815  QByteArray ffile = m_frameFile.toLocal8Bit();
816  if (!img.save(ffile.constData(), "JPEG"))
817  {
818  LOG(VB_GENERAL, LOG_ERR, "Failed to save thumb: " + m_frameFile);
819  }
820 
821  if (m_updateFrame)
822  {
823  MythImage *mimage =
825  mimage->Assign(img);
826  m_frameImage->SetImage(mimage);
827  mimage->DecrRef();
828  }
829 
831  }
832 
833  return true;
834 }
835 
837 {
838  delete[] m_outputbuf;
839 
840  // close the codec
841  if (m_inputFC.isOpen() && m_inputFC->streams)
843 
844  // close the video file
845  m_inputFC.Close();
846 }
847 
849 {
850  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
851  auto *menuPopup = new MythDialogBox(tr("Menu"), popupStack, "actionmenu");
852 
853  if (menuPopup->Create())
854  popupStack->AddScreen(menuPopup);
855 
856  menuPopup->SetReturnEvent(this, "action");
857 
858  menuPopup->AddButton(tr("Exit, Save Thumbnails"), SLOT(savePressed()));
859  menuPopup->AddButton(tr("Exit, Don't Save Thumbnails"), SLOT(cancelPressed()));
860 }
861 
863 {
864  if (!m_positionImage)
865  return;
866 
867  QSize size = m_positionImage->GetArea().size();
868  auto *pixmap = new QPixmap(size.width(), size.height());
869 
870  QPainter p(pixmap);
871  QBrush brush(Qt::green);
872 
873  p.setBrush(brush);
874  p.setPen(Qt::NoPen);
875  p.fillRect(0, 0, size.width(), size.height(), brush);
876 
877  frm_dir_map_t::const_iterator it;
878 
879  brush.setColor(Qt::red);
880 
881  for (it = m_deleteMap.constBegin(); it != m_deleteMap.constEnd(); ++it)
882  {
883  double startdelta = size.width();
884  if (it.key() != 0)
885  startdelta = (m_archiveItem->duration * m_fps) / it.key();
886 
887  ++it;
888  if (it == m_deleteMap.constEnd())
889  {
890  LOG(VB_GENERAL, LOG_ERR, "ThumbFinder: found a start cut but no cut end");
891  break;
892  }
893 
894  double enddelta = size.width();
895  if (it.key() != 0)
896  enddelta = (m_archiveItem->duration * m_fps) / it.key();
897 
898  int start = (int) (size.width() / startdelta);
899  int end = (int) (size.width() / enddelta);
900  p.fillRect(start - 1, 0, end - start, size.height(), brush);
901  }
902 
903  if (frame == 0)
904  frame = 1;
905  brush.setColor(Qt::yellow);
906  int pos = (int) (size.width() / ((m_archiveItem->duration * m_fps) / frame));
907  p.fillRect(pos, 0, 3, size.height(), brush);
908 
910  image->Assign(*pixmap);
911  m_positionImage->SetImage(image);
912 
913  p.end();
914  delete pixmap;
915 }
916 
918 {
919  if (m_archiveItem->type == "Recording")
920  {
922  {
923  frm_dir_map_t::const_iterator it;
924 
925  int cutLen = 0;
926 
927  for (it = m_deleteMap.constBegin(); it != m_deleteMap.constEnd(); ++it)
928  {
929  int start = it.key();
930 
931  ++it;
932  if (it == m_deleteMap.constEnd())
933  {
934  LOG(VB_GENERAL, LOG_ERR, "ThumbFinder: found a start cut but no cut end");
935  break;
936  }
937 
938  int end = it.key();
939  cutLen += end - start;
940  }
941  return m_archiveItem->duration - (int) (cutLen / m_fps);
942  }
943  }
944 
945  return m_archiveItem->duration;
946 }
MythUIButton::Clicked
void Clicked()
ThumbFinder::m_frameHeight
int m_frameHeight
Definition: thumbfinder.h:89
RemoteAVFormatContext::isOpen
bool isOpen() const
Definition: mytharchive/mytharchive/remoteavformatcontext.h:104
ArchiveItem::useCutlist
bool useCutlist
Definition: archiveutil.h:70
MythUIButtonList::GetItemCurrent
MythUIButtonListItem * GetItemCurrent() const
Definition: mythuibuttonlist.cpp:1590
ENO
#define ENO
This can be appended to the LOG args with "+".
Definition: mythlogging.h:72
ThumbFinder::getThumbImages
bool getThumbImages(void)
Definition: thumbfinder.cpp:412
ThumbFinder::cancelPressed
void cancelPressed(void)
Definition: thumbfinder.cpp:299
ThumbImage::caption
QString caption
Definition: archiveutil.h:45
mythuitext.h
copy
long long copy(QFile &dst, QFile &src, uint block_size)
Copies src file to dst file.
Definition: mythmiscutil.cpp:305
MythScreenType::NextPrevWidgetFocus
virtual bool NextPrevWidgetFocus(bool up_or_down)
Definition: mythscreentype.cpp:157
ThumbFinder::m_startPTS
int64_t m_startPTS
Definition: thumbfinder.h:93
ThumbFinder::updateCurrentPos
void updateCurrentPos(void)
Definition: thumbfinder.cpp:304
ThumbImage::filename
QString filename
Definition: archiveutil.h:46
MythCodecMap::GetCodecContext
AVCodecContext * GetCodecContext(const AVStream *Stream, const AVCodec *Codec=nullptr, bool NullCodec=false)
Definition: mythavutil.cpp:241
ThumbFinder::seekBackward
bool seekBackward()
Definition: thumbfinder.cpp:713
ThumbFinder::m_videostream
int m_videostream
Definition: thumbfinder.h:90
doc
QDomDocument doc("MYTHARCHIVEITEM")
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:402
MythMainWindow::TranslateKeyPress
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
Definition: mythmainwindow.cpp:1139
MARK_CUT_END
@ MARK_CUT_END
Definition: programtypes.h:55
MythPainter::GetFormatImage
MythImage * GetFormatImage()
Returns a blank reference counted image in the format required for the Draw functions for this painte...
Definition: mythpainter.cpp:540
MythUIButtonList::itemSelected
void itemSelected(MythUIButtonListItem *item)
MythAVUtil::DeinterlaceAVFrame
static void DeinterlaceAVFrame(AVFrame *Frame)
Deinterlace an AVFrame.
Definition: mythavutil.cpp:125
ThumbFinder::m_firstIFramePTS
int64_t m_firstIFramePTS
Definition: thumbfinder.h:95
mythdialogbox.h
MythScreenStack
Definition: mythscreenstack.h:16
arg
arg(title).arg(filename).arg(doDelete))
mythdbcon.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
ThumbFinder::m_archiveItem
ArchiveItem * m_archiveItem
Definition: thumbfinder.h:102
ArchiveItem::duration
int duration
Definition: archiveutil.h:62
build_compdb.file
file
Definition: build_compdb.py:55
mythdirs.h
RemoteAVFormatContext::Open
bool Open(const QString &filename)
Definition: mytharchive/mytharchive/remoteavformatcontext.h:29
MythMainWindow::GetPainter
MythPainter * GetPainter()
Definition: mythmainwindow.cpp:261
getTempDirectory
QString getTempDirectory(bool showError)
Definition: archiveutil.cpp:68
ThumbFinder::m_startTime
int64_t m_startTime
Definition: thumbfinder.h:92
ThumbFinder::m_frameFile
QString m_frameFile
Definition: thumbfinder.h:87
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &stackname)
Definition: mythmainwindow.cpp:326
mythuibuttonlist.h
ThumbFinder::calcFinalDuration
int calcFinalDuration(void)
Definition: thumbfinder.cpp:917
mythuiimage.h
ThumbFinder::m_offset
int m_offset
Definition: thumbfinder.h:100
tmp
static guint32 * tmp
Definition: goom_core.cpp:31
MythScreenType::GetFocusWidget
MythUIType * GetFocusWidget(void) const
Definition: mythscreentype.cpp:112
MythUIType::GetArea
virtual MythRect GetArea(void) const
If the object has a minimum area defined, return it, other wise return the default area.
Definition: mythuitype.cpp:870
MythUIButtonListItem::SetText
void SetText(const QString &text, const QString &name="", const QString &state="")
Definition: mythuibuttonlist.cpp:3264
ThumbFinder::m_currentSeek
size_t m_currentSeek
Definition: thumbfinder.h:91
ThumbFinder::changeSeekAmount
void changeSeekAmount(bool up)
Definition: thumbfinder.cpp:315
ThumbFinder::m_frameButton
MythUIButton * m_frameButton
Definition: thumbfinder.h:108
ThumbFinder::m_frameWidth
int m_frameWidth
Definition: thumbfinder.h:88
MythUIButtonListItem
Definition: mythuibuttonlist.h:28
AVFrame
struct AVFrame AVFrame
Definition: BorderDetector.h:15
ArchiveItem::type
QString type
Definition: archiveutil.h:53
ThumbFinder::Create
bool Create(void) override
Definition: thumbfinder.cpp:115
ThumbFinder::m_imageGrid
MythUIButtonList * m_imageGrid
Definition: thumbfinder.h:113
programinfo.h
ThumbFinder::Init
void Init(void) override
Used after calling Load() to assign data to widgets and other UI initilisation which is prohibited in...
Definition: thumbfinder.cpp:101
MythUIButtonList::GetCurrentPos
int GetCurrentPos() const
Definition: mythuibuttonlist.h:190
hardwareprofile.config.p
p
Definition: config.py:33
ThumbFinder::m_updateFrame
bool m_updateFrame
Definition: thumbfinder.h:97
MythScreenType::SetFocusWidget
bool SetFocusWidget(MythUIType *widget=nullptr)
Definition: mythscreentype.cpp:117
getFileDetails
bool getFileDetails(ArchiveItem *a)
Definition: archiveutil.cpp:221
MythDialogBox
Basic menu dialog, message and a list of options.
Definition: mythdialogbox.h:138
ThumbFinder::m_deleteMap
frm_dir_map_t m_deleteMap
Definition: thumbfinder.h:98
ThumbFinder::m_frame
MythAVFrame m_frame
Definition: thumbfinder.h:82
ThumbFinder::getFrameImage
bool getFrameImage(bool needKeyFrame=true, int64_t requiredPTS=-1)
Definition: thumbfinder.cpp:747
MythFormatTime
QString MythFormatTime(int secs, const QString &fmt)
Format a seconds time value.
Definition: mythmiscutil.cpp:1234
GetShareDir
QString GetShareDir(void)
Definition: mythdirs.cpp:222
ThumbFinder::m_saveButton
MythUIButton * m_saveButton
Definition: thumbfinder.h:109
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:222
ThumbImage::frame
qint64 frame
Definition: archiveutil.h:47
ProgramInfo::QueryCutList
bool QueryCutList(frm_dir_map_t &delMap, bool loadAutosave=false) const
Definition: programinfo.cpp:3287
MythImage::DecrRef
int DecrRef(void) override
Decrements reference count and deletes on 0.
Definition: mythimage.cpp:54
ThumbImage
Definition: archiveutil.h:44
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:637
MythCodecMap::FreeCodecContext
void FreeCodecContext(const AVStream *Stream)
Definition: mythavutil.cpp:289
ThumbFinder::initAVCodec
bool initAVCodec(const QString &inFile)
Definition: thumbfinder.cpp:525
thumbfinder.h
ThumbFinder::m_positionImage
MythUIImage * m_positionImage
Definition: thumbfinder.h:112
ThumbFinder::ShowMenu
void ShowMenu(void) override
Definition: thumbfinder.cpp:848
uint
unsigned int uint
Definition: compat.h:140
ThumbFinder::m_inputFC
RemoteAVFormatContext m_inputFC
Definition: thumbfinder.h:78
ThumbFinder::ThumbFinder
ThumbFinder(MythScreenStack *parent, ArchiveItem *archiveItem, const QString &menuTheme)
Definition: thumbfinder.cpp:84
ThumbFinder::checkFramePosition
int checkFramePosition(int frameNumber)
Definition: thumbfinder.cpp:621
ThumbFinder::m_cancelButton
MythUIButton * m_cancelButton
Definition: thumbfinder.h:110
getProgramInfoForFile
ProgramInfo * getProgramInfoForFile(const QString &inFile)
Definition: archiveutil.cpp:185
ThumbFinder::~ThumbFinder
~ThumbFinder() override
Definition: thumbfinder.cpp:106
ThumbFinder::createThumbDir
static QString createThumbDir(void)
Definition: thumbfinder.cpp:343
UIUtilDisp::Assign
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
ThumbFinder::loadCutList
void loadCutList(void)
Definition: thumbfinder.cpp:252
ThumbFinder::frameToTime
QString frameToTime(int64_t frame, bool addFrame=false) const
Definition: thumbfinder.cpp:401
RemoteAVFormatContext::Close
void Close()
Definition: mytharchive/mytharchive/remoteavformatcontext.h:89
ThumbFinder::m_thumbList
QList< ThumbImage * > m_thumbList
Definition: thumbfinder.h:104
mythuihelper.h
ArchiveItem::thumbList
QList< ThumbImage * > thumbList
Definition: archiveutil.h:72
MARK_CUT_START
@ MARK_CUT_START
Definition: programtypes.h:56
mythimage.h
ThumbFinder::m_thumbDir
QString m_thumbDir
Definition: thumbfinder.h:105
ThumbFinder::m_thumbCount
int m_thumbCount
Definition: thumbfinder.h:103
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:68
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:414
ThumbFinder::gridItemChanged
void gridItemChanged(MythUIButtonListItem *item)
Definition: thumbfinder.cpp:333
mythmiscutil.h
ThumbFinder::seekToFrame
bool seekToFrame(int frame, bool checkPos=true)
Definition: thumbfinder.cpp:650
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:692
MythUIButtonListItem::SetImage
void SetImage(MythImage *image, const QString &name="")
Sets an image directly, should only be used in special circumstances since it bypasses the cache.
Definition: mythuibuttonlist.cpp:3398
dir
QDir dir
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1174
MythImage
Definition: mythimage.h:37
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:134
mythcontext.h
ThumbFinder::m_frameImage
MythUIImage * m_frameImage
Definition: thumbfinder.h:111
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:105
ThumbFinder::updateThumb
void updateThumb(void)
Definition: thumbfinder.cpp:372
MythUIButtonList::SetItemCurrent
void SetItemCurrent(MythUIButtonListItem *item)
Definition: mythuibuttonlist.cpp:1557
build_compdb.action
action
Definition: build_compdb.py:9
ThumbFinder::savePressed
void savePressed(void)
Definition: thumbfinder.cpp:282
ArchiveItem::hasCutlist
bool hasCutlist
Definition: archiveutil.h:69
kSeekAmounts
static const std::array< const SeekAmount, 9 > kSeekAmounts
Definition: thumbfinder.cpp:72
MythUIImage::SetImage
void SetImage(MythImage *img)
Should not be used unless absolutely necessary since it bypasses the image caching and threaded loade...
Definition: mythuiimage.cpp:748
mythuibutton.h
ThumbFinder::m_finalDuration
int m_finalDuration
Definition: thumbfinder.h:99
ThumbFinder::m_frameTime
int m_frameTime
Definition: thumbfinder.h:96
ThumbFinder::m_codecMap
MythCodecMap m_codecMap
Definition: thumbfinder.h:80
ThumbFinder::m_codec
AVCodec * m_codec
Definition: thumbfinder.h:81
ArchiveItem
Definition: archiveutil.h:51
MythImage::Assign
void Assign(const QImage &img)
Definition: mythimage.cpp:79
MythAVCopy::Copy
int Copy(AVFrame *To, const MythVideoFrame *From, unsigned char *Buffer, AVPixelFormat Fmt=AV_PIX_FMT_YUV420P)
Initialise AVFrame and copy contents of VideoFrame frame into it, performing any required conversion.
Definition: mythavutil.cpp:220
ThumbFinder::m_fps
float m_fps
Definition: thumbfinder.h:85
ThumbFinder::m_copy
MythAVCopy m_copy
Definition: thumbfinder.h:83
ThumbFinder::closeAVCodec
void closeAVCodec()
Definition: thumbfinder.cpp:836
ThumbFinder::m_currentPosText
MythUIText * m_currentPosText
Definition: thumbfinder.h:115
ThumbFinder::updatePositionBar
void updatePositionBar(int64_t frame)
Definition: thumbfinder.cpp:862
ThumbFinder::m_outputbuf
unsigned char * m_outputbuf
Definition: thumbfinder.h:86
mythmainwindow.h
ThumbFinder::m_seekAmountText
MythUIText * m_seekAmountText
Definition: thumbfinder.h:114
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:49
MythUIType::SetRedraw
void SetRedraw(void)
Definition: mythuitype.cpp:294
ThumbFinder::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: thumbfinder.cpp:155
ThumbFinder::m_currentPTS
int64_t m_currentPTS
Definition: thumbfinder.h:94
PRE_SEEK_AMOUNT
#define PRE_SEEK_AMOUNT
Definition: thumbfinder.cpp:69
ArchiveItem::filename
QString filename
Definition: archiveutil.h:59
ThumbFinder::getChapterCount
static int getChapterCount(const QString &menuTheme)
Definition: thumbfinder.cpp:227
ThumbFinder::m_codecCtx
AVCodecContext * m_codecCtx
Definition: thumbfinder.h:79
ThumbFinder::seekForward
bool seekForward()
Definition: thumbfinder.cpp:676