1
/***************************************************************************
2
copyright : (C) 2001 by mean
3
email : fixounet@free.fr
4
***************************************************************************/
6
/***************************************************************************
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. *
13
***************************************************************************/
19
#define Ui_Dialog Ui_encodingDialog
20
#include "ui_encoding.h"
25
#include "ADM_assert.h"
26
#include "ADM_osSupport/ADM_misc.h"
27
#include "DIA_working.h"
28
#include "DIA_encoding.h"
29
#include "ADM_toolkit/toolkit.hxx"
30
#include "ADM_libraries/ADM_utilities/avidemutils.h"
32
extern void UI_purge(void);
34
class encodingWindow : public QDialog
42
void buttonPressed(void ) { printf("StopReq\n");stopReq=1;}
44
void priorityChanged(int priorityLevel)
49
ui.comboBoxPriority->disconnect(SIGNAL(currentIndexChanged(int)));
50
ui.comboBoxPriority->setCurrentIndex(2);
51
connect(ui.checkBoxShutdown, SIGNAL(currentIndexChanged(int)), this, SLOT(priorityChanged(int)));
53
GUI_Error_HIG(QT_TR_NOOP("Privileges Required"), QT_TR_NOOP( "Root privileges are required to perform this operation."));
59
setpriority(PRIO_PROCESS, 0, ADM_getNiceValue(priorityLevel));
62
void shutdownChanged(int state)
67
ui.checkBoxShutdown->disconnect(SIGNAL(stateChanged(int)));
68
ui.checkBoxShutdown->setCheckState(Qt::Unchecked);
69
connect(ui.checkBoxShutdown, SIGNAL(stateChanged(int)), this, SLOT(shutdownChanged(int)));
71
GUI_Error_HIG(QT_TR_NOOP("Privileges Required"), QT_TR_NOOP( "Root privileges are required to perform this operation."));
82
encodingWindow::encodingWindow() : QDialog()
87
//check for root privileges
90
// set priority to normal, regardless of preferences
91
ui.comboBoxPriority->setCurrentIndex(2);
95
connect(ui.checkBoxShutdown, SIGNAL(stateChanged(int)), this, SLOT(shutdownChanged(int)));
96
connect( (ui.pushButton),SIGNAL(pressed()),this,SLOT(buttonPressed()));
97
connect(ui.comboBoxPriority, SIGNAL(currentIndexChanged(int)), this, SLOT(priorityChanged(int)));
102
prefs->get(PRIORITY_ENCODING,&priority);
105
// check for root privileges
108
ui.comboBoxPriority->setCurrentIndex(priority);
111
ui.comboBoxPriority->setCurrentIndex(priority);
114
//*******************************************
115
#define WIDGET(x) (window->ui.x)
116
#define WRITEM(x,y) window->ui.x->setText(y)
117
#define WRITE(x) WRITEM(x,string)
118
/*************************************/
119
static char string[80];
120
static encodingWindow *window=NULL;
121
DIA_encoding::DIA_encoding( uint32_t fps1000 )
126
ADM_assert(window==NULL);
133
window=new encodingWindow();
135
_originalPriority=getpriority(PRIO_PROCESS, 0);
141
window->setModal(TRUE);
146
\fn setFps(uint32_t fps)
147
\brief Memorize fps, it will be used later for bitrate computation
150
void DIA_encoding::setFps(uint32_t fps)
152
_roundup=(uint32_t )floor( (fps+999)/1000);
154
ADM_assert(_roundup<MAX_BR_SLOT);
155
memset(_bitrate,0,sizeof(_bitrate));
163
printf("Stop request\n");
166
DIA_encoding::~DIA_encoding( )
168
bool shutdownRequired = (window->ui.checkBoxShutdown->checkState() == Qt::Checked);
170
setpriority(PRIO_PROCESS, 0, _originalPriority);
172
if(window) delete window;
175
if (shutdownRequired && !stopReq)
177
DIA_working *work=new DIA_working(QT_TR_NOOP("Shutting down"));
178
bool performShutdown=true;
180
for(int i = 0; i <= 30; i++)
189
performShutdown=false;
194
if (performShutdown && shutdown())
203
\fn setPhasis(const char *n)
204
\brief Display parameters as phasis
207
void DIA_encoding::setPhasis(const char *n)
210
WRITEM(labelPhasis,n);
214
\fn setAudioCodec(const char *n)
215
\brief Display parameters as audio codec
218
void DIA_encoding::setAudioCodec(const char *n)
221
WRITEM(labelAudCodec,n);
224
\fn setCodec(const char *n)
225
\brief Display parameters as video codec
228
void DIA_encoding::setCodec(const char *n)
231
WRITEM(labelVidCodec,n);
234
\fn setBitrate(uint32_t br,uint32_t globalbr)
235
\brief Display parameters as instantaneous bitrate and average bitrate
238
void DIA_encoding::setBitrate(uint32_t br,uint32_t globalbr)
241
snprintf(string,79,"%lu kB/s",br,globalbr);
242
WRITE(labelVidBitrate);
247
\brief Reset everything, used for 2pass
250
void DIA_encoding::reset(void)
258
\fn setContainer(const char *container)
259
\brief Display parameter as container field
262
void DIA_encoding::setContainer(const char *container)
265
WRITEM(labelContainer,container);
267
#define ETA_SAMPLE_PERIOD 60000 //Use last n millis to calculate ETA
268
#define GUI_UPDATE_RATE 500
270
\fn setFrame(uint32_t nb,uint32_t size, uint32_t quant,uint32_t total)
271
\brief Recompute and update everything concering video
274
void DIA_encoding::setFrame(uint32_t nb,uint32_t size, uint32_t quant,uint32_t total)
278
if(nb < _lastnb || _lastnb == 0) // restart ?
282
_lastTime=clock.getElapsedMS();
287
_nextUpdate = _lastTime + GUI_UPDATE_RATE;
288
_nextSampleStartTime=_lastTime + ETA_SAMPLE_PERIOD;
289
_nextSampleStartFrame=0;
292
_current=nb%_roundup;
293
_bitrate[_current].size=size;
294
_bitrate[_current].quant=quant;
298
\brief Recompute and update all fields, especially ETA
301
void DIA_encoding::updateUI(void)
307
// nb/total=timestart/totaltime -> total time =timestart*total/nb
314
tim=clock.getElapsedMS();
315
if(_lastTime > tim) return;
316
if( tim < _nextUpdate) return ;
317
_nextUpdate = tim+GUI_UPDATE_RATE;
319
snprintf(string,79,"%lu",_lastnb);
320
WIDGET(labelFrame)->setText(string);
322
snprintf(string,79,"%lu",_total);
323
WIDGET(labelTotalFrame)->setText(string);
325
snprintf(string,79,"%lu",_total);
326
WIDGET(labelTotalFrame)->setText(string);
328
// Average bitrate on the last second
329
uint32_t sum=0,aquant=0,gsum;
330
for(int i=0;i<_roundup;i++)
332
sum+=_bitrate[i].size;
333
aquant+=_bitrate[i].quant;
340
// Now compute global average bitrate
341
float whole=_videoSize,second;
350
gsum=(uint32_t)whole;
352
setBitrate(sum,gsum);
356
uint32_t deltaFrame, deltaTime;
357
deltaTime=tim-_lastTime;
358
deltaFrame=_lastnb-_lastFrame;
360
_fps_average =(float)( deltaFrame*1000.0F / deltaTime );
362
snprintf(string,79,"%.2f",_fps_average);
363
WIDGET(labelFps)->setText(string);
367
double framesLeft=(_total-_lastnb);
369
ms2time(tim,&hh,&mm,&ss);
370
snprintf(string,79,"%02d:%02d:%02d",hh,mm,ss);
371
WIDGET(labelElapsed)->setText(string);
373
WIDGET(labelETA)->setText(ms2timedisplay((uint32_t) floor(0.5 + deltaTime * framesLeft / deltaFrame)));
375
// Check if we should move on to the next sample period
376
if (tim >= _nextSampleStartTime + ETA_SAMPLE_PERIOD ) {
377
_lastTime=_nextSampleStartTime;
378
_lastFrame=_nextSampleStartFrame;
379
_nextSampleStartTime=tim;
380
_nextSampleStartFrame=0;
381
} else if (tim >= _nextSampleStartTime && _nextSampleStartFrame == 0 ) {
382
// Store current point for use later as the next sample period.
384
_nextSampleStartTime=tim;
385
_nextSampleStartFrame=_lastnb;
387
// update progress bar
390
WIDGET(progressBar)->setValue((int)f);
392
_totalSize=_audioSize+_videoSize;
393
setSize(_totalSize>>20);
394
setAudioSizeIn((_audioSize>>20));
395
setVideoSizeIn((_videoSize>>20));
400
\fn setQuantIn(int size)
401
\brief display parameter as quantizer
404
void DIA_encoding::setQuantIn(int size)
407
sprintf(string,"%lu",size);
412
\fn setSize(int size)
413
\brief display parameter as total size
416
void DIA_encoding::setSize(int size)
419
sprintf(string,"%lu MB",size);
420
WRITE(labelTotalSize);
424
\fn setAudioSizeIn(int size)
425
\brief display parameter as audio size
428
void DIA_encoding::setAudioSizeIn(int size)
431
sprintf(string,"%lu MB",size);
432
WRITE(labelAudioSize);
436
\fn setVideoSizeIn(int size)
437
\brief display parameter as video size
440
void DIA_encoding::setVideoSizeIn(int size)
443
sprintf(string,"%lu MB",size);
444
WRITE(labelVideoSize);
448
\fn setAudioSize( uint32_t size)
449
\brief set the total audio size as per parameter
452
void DIA_encoding::setAudioSize(uint32_t size)
458
\brief return 0 if the window was killed or cancel button press, 1 otherwisearchForward
460
uint8_t DIA_encoding::isAlive( void )
466
if(GUI_Alternate((char*)QT_TR_NOOP("The encoding is paused. Do you want to resume or abort?"),
467
(char*)QT_TR_NOOP("Resume"),(char*)QT_TR_NOOP("Abort")))
473
if(!stopReq) return 1;
478
//********************************************