1 /***************************************************************************
2 copyright : (C) 2006 by mean
3 email : fixounet@free.fr
4 ***************************************************************************/
5
6 /***************************************************************************
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 ***************************************************************************///
14
15 #include "ADM_default.h"
16 #include "ADM_coreVideoFilter.h"
17 #define ADM_FLY_INTERNAL
18 #include "DIA_flyDialogQt4.h"
19 #include "ADM_assert.h"
20 #include <QtCore/QEvent>
21 #include <QtCore/QCoreApplication>
22 #include <QGraphicsView>
23 #include <QPushButton>
24 #include <QRadioButton>
25 #include <QHBoxLayout>
26 #include <QApplication>
27 #include "ADM_toolkitQt.h"
28 #include "ADM_vidMisc.h"
29 extern "C" {
30 #include "libavcodec/avcodec.h"
31 }
32 /**
33 */
34 class flyControl
35 {
36 public:
flyControl(QHBoxLayout * horizontalLayout_4)37 flyControl(QHBoxLayout *horizontalLayout_4)
38 {
39
40 pushButton_back1mn = new QPushButton();
41 pushButton_back1mn->setObjectName(QString("pushButton_back1mn"));
42 pushButton_back1mn->setAutoRepeat(true);
43 pushButton_back1mn->setAutoRepeatDelay(1000);
44
45 horizontalLayout_4->addWidget(pushButton_back1mn);
46
47 pushButton_play = new QPushButton();
48 pushButton_play->setObjectName(QString("pushButton_play"));
49 pushButton_play->setCheckable(true);
50
51 horizontalLayout_4->addWidget(pushButton_play);
52
53 pushButton_next = new QPushButton();
54 pushButton_next->setObjectName(QString("pushButton_next"));
55 pushButton_next->setAutoRepeat(true);
56 pushButton_next->setAutoRepeatDelay(1000);
57
58 horizontalLayout_4->addWidget(pushButton_next);
59
60 pushButton_fwd1mn = new QPushButton();
61 pushButton_fwd1mn->setObjectName(QString("pushButton_fwd1mn"));
62 pushButton_fwd1mn->setAutoRepeat(true);
63 pushButton_fwd1mn->setAutoRepeatDelay(1000);
64
65 horizontalLayout_4->addWidget(pushButton_fwd1mn);
66 //
67 labelTime=new QLabel();
68 labelTime->setText("00:00:00.000 / 00:00:00.000");
69 horizontalLayout_4->addWidget(labelTime);
70 //
71 QSpacerItem *horizontalSpacer_4 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
72 horizontalLayout_4->addItem(horizontalSpacer_4);
73
74 pushButton_back1mn->setToolTip(QApplication::translate("seekablePreviewDialog", "Back one minute", 0));
75 pushButton_back1mn->setText(QApplication::translate("seekablePreviewDialog", "<<", 0));
76 pushButton_play->setText(QApplication::translate("seekablePreviewDialog", "Play", 0));
77 pushButton_next->setToolTip(QApplication::translate("seekablePreviewDialog", "Next image", 0));
78 pushButton_next->setText(QApplication::translate("seekablePreviewDialog", ">", 0));
79 pushButton_fwd1mn->setText(QApplication::translate("seekablePreviewDialog", ">>", 0));
80 pushButton_fwd1mn->setToolTip(QApplication::translate("seekablePreviewDialog", "Forward one minute", 0));
81 }
disableButtons()82 void disableButtons()
83 {
84 pushButton_back1mn->setEnabled(false);
85 pushButton_fwd1mn->setEnabled(false);
86 pushButton_next->setEnabled(false);
87 }
enableButtons()88 void enableButtons()
89 {
90 pushButton_back1mn->setEnabled(true);
91 pushButton_fwd1mn->setEnabled(true);
92 pushButton_next->setEnabled(true);
93 }
94 public:
95 QPushButton *pushButton_back1mn;
96 QPushButton *pushButton_play;
97 QPushButton *pushButton_next;
98 QPushButton *pushButton_fwd1mn;
99 QLabel *labelTime;
100 };
101
102 /**
103 \fn updateZoom
104 */
updateZoom(void)105 void ADM_flyDialog::updateZoom(void)
106 {
107 _rgbByteBufferDisplay.clean();
108 _rgbByteBufferDisplay.setSize(_zoomW * _zoomH * 4);
109 resetScaler();
110 }
111 /**
112 *
113 * @return
114 */
disableZoom()115 bool ADM_flyDialog::disableZoom()
116 {
117 _resizeMethod = RESIZE_NONE;
118 recomputeSize();
119 return true;
120 }
enableZoom(void)121 bool ADM_flyDialog::enableZoom(void)
122 {
123 _resizeMethod = RESIZE_AUTO;
124 recomputeSize();
125 return true;
126 }
127 /**
128 \fn recomputeSize
129 \brief recompute zoom factor
130 */
131
recomputeSize(void)132 void ADM_flyDialog::recomputeSize(void)
133 {
134 if(this->_resizeMethod==RESIZE_NONE)
135 {
136 _zoom = 1;
137 _zoomW = _w;
138 _zoomH = _h;
139 updateZoom();
140 postInit (true);
141 sliderChanged();
142 return;
143 }
144
145 float new_zoom = calcZoomFactor();
146
147 ResizeMethod new_resizeMethod;
148 uint32_t new_zoomW;
149 uint32_t new_zoomH;
150
151 new_zoomW = uint32_t (_w * new_zoom);
152 new_zoomH = uint32_t (_h * new_zoom);
153
154 if ( new_zoom == _zoom && new_zoomW == _zoomW && new_zoomH == _zoomH)
155 return;
156
157 if ( new_zoomH < 30 || new_zoomW < 30)
158 {
159 ADM_info ("Resisting zoom size change from %dx%d (zoom %.5f) to %dx%d (zoom %.5f)\n",
160 _zoomW, _zoomH, _zoom, new_zoomW, new_zoomH, new_zoom);
161 return;
162 }
163
164 ADM_info ("Fixing zoom size from %dx%d (zoom %.5f) to correct %dx%d (zoom %.5f)\n",
165 _zoomW, _zoomH, _zoom, new_zoomW, new_zoomH, new_zoom);
166 _zoom = new_zoom;
167 _zoomW = new_zoomW;
168 _zoomH = new_zoomH;
169 updateZoom();
170 postInit (true);
171 sliderChanged();
172 }
173
174 /**
175 \fn cleanup
176 \brief deallocate
177 */
cleanup(void)178 uint8_t ADM_flyDialog::cleanup(void)
179 {
180 #define DEL1(x) if(x) {delete [] x;x=NULL;}
181 #define DEL2(x) if(x) {delete x;x=NULL;}
182 DEL2(_yuvBuffer);
183 _rgbByteBufferDisplay.clean();
184 if(_control)
185 {
186 delete _control;
187 _control=NULL;
188 }
189 return 1;
190 }
191 /**
192 \fn ~ADM_flyDialog
193 \brief destructor
194 */
~ADM_flyDialog(void)195 ADM_flyDialog::~ADM_flyDialog(void)
196 {
197 cleanup();
198 }
199
200 /**
201 \fn goToTime
202 */
goToTime(uint64_t tme)203 bool ADM_flyDialog::goToTime(uint64_t tme)
204 {
205 _in->goToTime(tme);
206 return nextImageInternal();
207 }
208
209 /**
210 \fn sliderChanged
211 \brief callback to handle image changes
212 */
sliderChanged(void)213 uint8_t ADM_flyDialog::sliderChanged(void)
214 {
215 uint32_t fn= sliderGet();
216 uint32_t frameNumber;
217 uint32_t len,flags;
218
219 ADM_assert(_yuvBuffer);
220 ADM_assert(_in);
221
222
223 double time;
224 time=fn;
225 time/=ADM_FLY_SLIDER_MAX;
226 time*=_in->getInfo()->totalDuration;
227 return goToTime(time);
228
229 }
230 /**
231 \fn toRgbColor
232 */
toRgbColor(void)233 ADM_colorspace ADM_flyDialog::toRgbColor(void)
234 {
235 if(isRgbInverted()) return ADM_COLOR_BGR32A;
236 return ADM_COLOR_RGB32A;
237 }
238 /**
239 *
240 * @param frame
241 * @return
242 */
addControl(QHBoxLayout * horizontalLayout_4)243 bool ADM_flyDialog::addControl(QHBoxLayout *horizontalLayout_4)
244 {
245 _parent->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
246 _control=new flyControl(horizontalLayout_4);
247 QObject::connect(_control->pushButton_next ,SIGNAL(clicked()),this,SLOT(nextImage()));
248 QObject::connect(_control->pushButton_back1mn ,SIGNAL(clicked()),this,SLOT(backOneMinute()));
249 QObject::connect(_control->pushButton_fwd1mn ,SIGNAL(clicked()),this,SLOT(fwdOneMinute()));
250 QObject::connect(_control->pushButton_play ,SIGNAL(toggled(bool )),this,SLOT(play(bool)));
251
252 return true;
253 }
254
255 /**
256 \fn sameImage
257 */
sameImage(void)258 bool ADM_flyDialog::sameImage(void)
259 {
260 process();
261 return display(_rgbByteBufferDisplay.at(0));
262 }
getCurrentPts()263 uint64_t ADM_flyDialog::getCurrentPts()
264 {
265 return lastPts;
266 }
267 /**
268 \fn nextImageInternal
269 */
nextImageInternal(void)270 bool ADM_flyDialog::nextImageInternal(void)
271 {
272 uint32_t frameNumber;
273 if(!_in->getNextFrame(&frameNumber,_yuvBuffer))
274 {
275 ADM_warning("[FlyDialog] Cannot get frame %u\n",frameNumber);
276 return 0;
277 }
278 lastPts=_yuvBuffer->Pts;
279 setCurrentPts(lastPts);
280 uint64_t duration=_in->getInfo()->totalDuration;
281 QString time=QString(ADM_us2plain(lastPts)) + QString(" / ") + QString(ADM_us2plain(duration));
282 if(_control)
283 _control->labelTime->setText(time);
284 // Process...
285 process();
286 return display(_rgbByteBufferDisplay.at(0));
287 }
288
289 /**
290 \fn nextImage
291 */
nextImage(void)292 bool ADM_flyDialog::nextImage(void)
293 {
294 ADM_QSlider *slide=(ADM_QSlider *)_slider;
295 ADM_assert(slide);
296 bool oldState=slide->blockSignals(true);
297 bool r=nextImageInternal();
298 if(r)
299 updateSlider();
300 slide->blockSignals(oldState);
301 return r;
302 }
303
304 /**
305 *
306 * @return
307 */
initializeSize()308 bool ADM_flyDialog::initializeSize()
309 {
310 _canvas->resize(1,1);
311 QSize qsize= _canvas->parentWidget()->parentWidget()->size();
312 //_usedWidth = qsize.width();
313 // Normally there is nothing interesting left and right, we can use a hardcoded value
314 _usedWidth=64;
315 _usedHeight= 32+qsize.height(); // keep a border margin
316
317 if (_resizeMethod != RESIZE_NONE)
318 {
319 _zoom = calcZoomFactor();
320 if (_zoom == 1)
321 {
322 _resizeMethod = RESIZE_NONE;
323 }
324 }
325 if (_resizeMethod == RESIZE_NONE)
326 {
327 _zoom = 1;
328 _zoomW = _w;
329 _zoomH = _h;
330 } else
331 {
332 _zoomW = uint32_t(_w * _zoom);
333 _zoomH = uint32_t(_h * _zoom);
334 }
335
336 ADM_info("xAutoZoom : base size= %d x %d\n",_usedWidth,_usedHeight);
337 return true;
338 }
339 /**
340 * \brief Calculate the zoom ratio required to fit the whole image on the screen.
341 * @param imageWidth
342 * @param imageHeight
343 * @return
344 */
calcZoomToBeDisplayable(uint32_t imageWidth,uint32_t imageHeight)345 float ADM_flyDialog::calcZoomToBeDisplayable( uint32_t imageWidth, uint32_t imageHeight)
346 {
347 uint32_t screenWidth, screenHeight;
348 QWidget *topWindow=_canvas->parentWidget()->parentWidget();
349 UI_getPhysicalScreenSize(topWindow, &screenWidth, &screenHeight);
350
351 // Usable width/height
352 int usableWidth =(int)screenWidth -_usedWidth;
353 int usableHeight=(int)screenHeight-_usedHeight;
354
355 if(usableWidth<160) usableWidth=160;
356 if(usableHeight<160) usableHeight=160;
357
358
359 float widthRatio = (float)usableWidth / (float)imageWidth;
360 float heightRatio = (float)usableHeight / (float)imageHeight;
361
362 ADM_info("autoZoom : Raw w=%f h=%f\n",widthRatio,heightRatio);
363
364 float r= (widthRatio < heightRatio ? widthRatio : heightRatio);
365 return r;
366
367 }
368
369 //************************************
370 // Implement the specific part
371 // i.e. yuv processing or RGB processing
372 //************************************
ADM_flyDialogYuv(QDialog * parent,uint32_t width,uint32_t height,ADM_coreVideoFilter * in,ADM_QCanvas * canvas,ADM_QSlider * slider,ResizeMethod resizeMethod)373 ADM_flyDialogYuv::ADM_flyDialogYuv(QDialog *parent,uint32_t width, uint32_t height, ADM_coreVideoFilter *in,
374 ADM_QCanvas *canvas, ADM_QSlider *slider,
375 ResizeMethod resizeMethod) : ADM_flyDialog(parent,width,height,in,canvas,slider,resizeMethod)
376 {
377 _control=NULL;
378 _yuvBufferOut=new ADMImageDefault(_w,_h);
379 yuvToRgb=NULL;
380 initializeSize();
381 updateZoom();
382 postInit(false);
383 _nextRdv=0;
384 }
resetScaler(void)385 void ADM_flyDialogYuv::resetScaler(void)
386 {
387 if(yuvToRgb)
388 {
389 delete yuvToRgb;
390 yuvToRgb=NULL;
391 }
392
393 yuvToRgb=new ADMColorScalerFull(ADM_CS_BICUBIC,
394 _w,
395 _h,
396 _zoomW,
397 _zoomH,
398 ADM_COLOR_YV12,toRgbColor());
399 }
400 /**
401 *
402 */
~ADM_flyDialogYuv()403 ADM_flyDialogYuv::~ADM_flyDialogYuv()
404 {
405 if(yuvToRgb)
406 {
407 delete yuvToRgb;
408 yuvToRgb=NULL;
409 }
410 if(_yuvBufferOut) delete _yuvBufferOut;
411 _yuvBufferOut=NULL;
412 if(_control)
413 {
414 delete _control;
415 _control=NULL;
416 }
417 }
process(void)418 bool ADM_flyDialogYuv::process(void)
419 {
420 processYuv(_yuvBuffer,_yuvBufferOut);
421 yuvToRgb->convertImage(_yuvBufferOut,_rgbByteBufferDisplay.at(0));
422 return true;
423 }
424 //*****************************************
ADM_flyDialogRgb(QDialog * parent,uint32_t width,uint32_t height,ADM_coreVideoFilter * in,ADM_QCanvas * canvas,ADM_QSlider * slider,ResizeMethod resizeMethod)425 ADM_flyDialogRgb::ADM_flyDialogRgb(QDialog *parent,uint32_t width, uint32_t height, ADM_coreVideoFilter *in,
426 ADM_QCanvas *canvas, ADM_QSlider *slider,
427 ResizeMethod resizeMethod) : ADM_flyDialog(parent,width,height,in,canvas,slider,resizeMethod)
428 {
429 uint32_t size=_w*_h*4;
430 _rgbByteBuffer.setSize(size);
431 _rgbByteBufferOut.setSize(size);
432 yuv2rgb =new ADMColorScalerSimple(_w,_h,ADM_COLOR_YV12,
433 toRgbColor());
434 rgb2rgb=NULL;
435 initializeSize();
436 updateZoom();
437 postInit(false);
438
439 }
resetScaler(void)440 void ADM_flyDialogRgb::resetScaler(void)
441 {
442 if(rgb2rgb) delete rgb2rgb;
443 rgb2rgb=new ADMColorScalerFull(ADM_CS_BICUBIC,
444 _w,
445 _h,
446 _zoomW,
447 _zoomH,
448 ADM_COLOR_RGB32A,ADM_COLOR_RGB32A);
449 }
450 /**
451 *
452 */
~ADM_flyDialogRgb()453 ADM_flyDialogRgb::~ADM_flyDialogRgb()
454 {
455 _rgbByteBuffer.clean();
456 _rgbByteBufferOut.clean();
457 if(rgb2rgb) delete rgb2rgb;
458 if(yuv2rgb) delete yuv2rgb;
459 rgb2rgb=NULL;
460 yuv2rgb=NULL;
461
462 }
process(void)463 bool ADM_flyDialogRgb::process(void)
464 {
465 yuv2rgb->convertImage(_yuvBuffer,_rgbByteBuffer.at(0));
466 if (_resizeMethod != RESIZE_NONE)
467 {
468 processRgb(_rgbByteBuffer.at(0),_rgbByteBufferOut.at(0));
469 rgb2rgb->convert(_rgbByteBufferOut.at(0), _rgbByteBufferDisplay.at(0));
470 }else
471 {
472 processRgb(_rgbByteBuffer.at(0),_rgbByteBufferDisplay.at(0));
473 }
474 return true;
475 }
476
477
478
479
480 /**
481 \fn FlyDialogEventFilter
482 \brief
483 */
484
FlyDialogEventFilter(ADM_flyDialog * flyDialog)485 FlyDialogEventFilter::FlyDialogEventFilter(ADM_flyDialog *flyDialog)
486 {
487 recomputed = false;
488 this->flyDialog = flyDialog;
489 }
490 /**
491 \fn eventFilter
492 \brief
493 */
494
eventFilter(QObject * obj,QEvent * event)495 bool FlyDialogEventFilter::eventFilter(QObject *obj, QEvent *event)
496 {
497 if (event->type() == QEvent::Show && !recomputed)
498 {
499 recomputed = true;
500 QWidget* parent = (QWidget*)obj;
501 uint32_t screenWidth, screenHeight;
502
503 UI_getPhysicalScreenSize(parent, &screenWidth, &screenHeight);
504 flyDialog->recomputeSize();
505 QCoreApplication::processEvents();
506 parent->move((((int)screenWidth) - parent->frameSize().width()) / 2, (((int)screenHeight) - parent->frameSize().height()) / 2);
507 }
508
509 return QObject::eventFilter(obj, event);
510 }
511 /**
512 \fn ADM_flyDialog
513 \brief
514 */
515
ADM_flyDialog(QDialog * parent,uint32_t width,uint32_t height,ADM_coreVideoFilter * in,ADM_QCanvas * canvas,ADM_QSlider * slider,ResizeMethod resizeMethod)516 ADM_flyDialog::ADM_flyDialog(QDialog *parent ,uint32_t width, uint32_t height, ADM_coreVideoFilter *in,
517 ADM_QCanvas *canvas, ADM_QSlider *slider, ResizeMethod resizeMethod)
518 {
519 ADM_assert(canvas);
520 {
521 ADM_assert(in);
522 slider->setMaximum(ADM_FLY_SLIDER_MAX);
523 }
524 _parent=parent;
525 _w = width;
526 _h = height;
527 _in = in;
528 _slider = slider;
529 _canvas = canvas;
530 _cookie = NULL;
531 _computedZoom=0;
532 _resizeMethod = resizeMethod;
533 _zoomChangeCount = 0;
534 _yuvBuffer=new ADMImageDefault(_w,_h);
535 _usedWidth= _usedHeight=0;
536 lastPts=0;
537
538 QGraphicsScene *sc=new QGraphicsScene(this);
539 sc->setBackgroundBrush(QBrush(Qt::darkGray, Qt::SolidPattern));
540 qobject_cast<QGraphicsView*>(_canvas->parentWidget())->setScene(sc);
541 qobject_cast<QFrame*>(_canvas->parentWidget())->setFrameStyle(QFrame::NoFrame);
542
543 connect(&timer,SIGNAL(timeout()),this,SLOT(timeout()));
544 timer.setSingleShot(true);
545
546 int incrementUs=getUnderlyingFilter()->getInfo()->frameIncrement;
547
548 incrementUs=(incrementUs+501)/1000; // us => ms
549 if(incrementUs<10) incrementUs=10;
550 _frameIncrement=incrementUs;
551 timer.setInterval(_frameIncrement);
552
553 ADM_info("Interval = %d ms\n",incrementUs);
554 timer.stop();
555
556 }
557 /**
558 \fn postInit
559 \brief
560 */
561
postInit(uint8_t reInit)562 void ADM_flyDialog::postInit(uint8_t reInit)
563 {
564 QWidget *graphicsView = ((ADM_QCanvas*)_canvas)->parentWidget();
565 ADM_QSlider *slider=(ADM_QSlider *)_slider;
566
567 if (reInit)
568 {
569 FlyDialogEventFilter *eventFilter = new FlyDialogEventFilter(this);
570
571 if (slider)
572 slider->setMaximum(ADM_FLY_SLIDER_MAX);
573
574 graphicsView->parentWidget()->installEventFilter(eventFilter);
575 }
576
577 ((ADM_QCanvas*)_canvas)->changeSize(_zoomW, _zoomH);
578 graphicsView->setMinimumSize(_zoomW, _zoomH);
579 }
580
581 /**
582 \fn adjustCanvasPosition
583 \brief center canvas within the viewport (graphicsView)
584 */
adjustCanvasPosition(void)585 void ADM_flyDialog::adjustCanvasPosition(void)
586 {
587 uint32_t graphicsViewWidth = _canvas->parentWidget()->width();
588 uint32_t graphicsViewHeight = _canvas->parentWidget()->height();
589 uint32_t canvasWidth = _canvas->width();
590 uint32_t canvasHeight = _canvas->height();
591 int h = 0;
592 int v = 0;
593 if(graphicsViewWidth > canvasWidth)
594 h = (graphicsViewWidth - canvasWidth)/2;
595 if(graphicsViewHeight > canvasHeight)
596 v = (graphicsViewHeight - canvasHeight)/2;
597 if(h||v)
598 _canvas->move(h,v);
599 }
600
601 /**
602 \fn fitCanvasIntoView
603 */
fitCanvasIntoView(uint32_t width,uint32_t height)604 void ADM_flyDialog::fitCanvasIntoView(uint32_t width, uint32_t height)
605 {
606 double ar = (double)_w / _h;
607 double viewAr = (double)width / height;
608
609 if(viewAr != ar)
610 {
611 uint32_t tmpZoomW = 0;
612 uint32_t tmpZoomH = 0;
613 if(viewAr > ar)
614 {
615 tmpZoomW = (uint32_t)((double)height * ar);
616 tmpZoomH = height;
617 }else
618 {
619 tmpZoomW = width;
620 tmpZoomH = (uint32_t)((double)width / ar);
621 }
622 _resizeMethod = RESIZE_AUTO;
623 _zoomW = tmpZoomW&0xfffffffe;
624 _zoomH = tmpZoomH&0xfffffffe;
625 _zoom = (float)_zoomW / _w;
626 updateZoom();
627 _canvas->changeSize(_zoomW, _zoomH);
628 sameImage();
629 }
630 }
631
632 /**
633 \fn calcZoomFactor
634 \brief
635 */
calcZoomFactor(void)636 float ADM_flyDialog::calcZoomFactor(void)
637 {
638 #define APPROXIMATE 20.
639 if(_computedZoom) return _computedZoom;
640 double zoom;
641 zoom=calcZoomToBeDisplayable(_w, _h);
642 // Find the closest integer
643 // zoom it ?
644 if((zoom)>1)
645 {
646 _computedZoom=1.; // never upscale automatically
647 return _computedZoom;
648 }
649 double invertZoom=1/zoom;
650 _computedZoom=APPROXIMATE/floor((1+APPROXIMATE*(invertZoom)));
651 ADM_info("AutoZoom 1/%f\n",(float)(1./_computedZoom));
652 return _computedZoom;
653
654 }
655 /**
656 \fn display
657 \brief
658 */
659
display(uint8_t * rgbData)660 uint8_t ADM_flyDialog::display(uint8_t *rgbData)
661 {
662 ADM_QCanvas *view=(ADM_QCanvas *)_canvas;
663 ADM_assert(view);
664 view->dataBuffer=rgbData;
665 if(!rgbData)
666 {
667 ADM_info("flyDialog: No rgbuffer ??\n");
668 }
669 view->repaint();
670 return 1;
671 }
672 /**
673 \fn sliderGet
674 \brief
675 */
676
sliderGet(void)677 uint32_t ADM_flyDialog::sliderGet(void)
678 {
679 ADM_QSlider *slide=(ADM_QSlider *)_slider;
680 ADM_assert(slide);
681 return slide->value();
682
683 }
684 /**
685 \fn sliderSet
686 \brief
687 */
688
sliderSet(uint32_t value)689 uint8_t ADM_flyDialog::sliderSet(uint32_t value)
690 {
691 ADM_QSlider *slide=(ADM_QSlider *)_slider;
692 ADM_assert(slide);
693 if(value>ADM_FLY_SLIDER_MAX) value=ADM_FLY_SLIDER_MAX;
694 slide->setValue(value);
695 return 1;
696 }
697
698 /**
699 \fn updateSlider
700 \brief
701 */
updateSlider(void)702 void ADM_flyDialog::updateSlider(void)
703 {
704 ADM_assert(_in);
705 uint64_t dur=_in->getInfo()->totalDuration;
706 uint64_t pts=getCurrentPts();
707 double pos;
708 pos=pts;
709 pos/=dur;
710 pos*=ADM_FLY_SLIDER_MAX;
711 pos+=0.5; // round up
712 sliderSet((uint32_t)pos);
713 }
714
715 /**
716 \fn isRgbInverted
717 \brief
718 */
isRgbInverted(void)719 bool ADM_flyDialog::isRgbInverted(void)
720 {
721 return 0;
722 }
723
724
725 /**
726 *
727 */
728 #define JUMP_LENGTH (60LL*1000LL*1000LL)
729
backOneMinute(void)730 void ADM_flyDialog::backOneMinute(void)
731 {
732 uint64_t pts=getCurrentPts();
733 if(pts<JUMP_LENGTH) pts=0;
734 else pts-=JUMP_LENGTH;
735 goToTime(pts);
736 updateSlider();
737 }
738 /**
739 *
740 */
fwdOneMinute(void)741 void ADM_flyDialog::fwdOneMinute(void)
742 {
743 uint64_t pts=getCurrentPts();
744 pts+=JUMP_LENGTH;
745 goToTime(pts);
746 updateSlider();
747 }
748 /**
749 *
750 */
play(bool state)751 void ADM_flyDialog::play(bool state)
752 {
753 ADM_QSlider *slide=(ADM_QSlider *)_slider;
754 ADM_assert(slide);
755 if(state)
756 {
757 _control->disableButtons();
758 slide->setEnabled(false);
759 _clock.reset();
760 timer.setInterval(_frameIncrement);
761 _nextRdv=_frameIncrement;
762 timer.start();
763 }else
764 {
765 timer.stop();
766 _control->enableButtons();
767 slide->setEnabled(true);
768 }
769
770 }
771
772 /**
773 \fn timeout
774 \brief play filtered video
775 */
timeout()776 void ADM_flyDialog::timeout()
777 {
778 bool r=nextImage();
779 uint64_t duration=_in->getInfo()->totalDuration;
780 QString time=QString(ADM_us2plain(_yuvBuffer->Pts)) + QString(" / ") + QString(ADM_us2plain(duration));
781 _control->labelTime->setText(time);
782 if(r)
783 {
784 int now=_clock.getElapsedMS();
785 //printf("Now = %d, next Rdv=%d, delta =%d\n",now,_nextRdv,_nextRdv-now);
786 _nextRdv+=_frameIncrement;
787 if(_nextRdv<=now) timer.setInterval(1);
788 else timer.setInterval(_nextRdv-now);
789 timer.start();
790 }
791 else
792 {
793 _control->pushButton_play->setChecked(false);
794 }
795 }
796
797
798 //******************************
799 //EOF
800
801