1 /***************************************************************************
2 copyright : (C) 2001 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 #include "ADM_cpp.h"
15 #include <math.h>
16
17 #include "Q_props.h"
18 #include "avi_vars.h"
19 #include "ADM_edAudioTrackExternal.h"
20 #include "ADM_edAudioTrackFromVideo.h"
21 #include "ADM_vidMisc.h"
22 #include "ADM_toolkitQt.h"
23 #include "ADM_coreUtils.h"
24 #include <QClipboard>
25
26 static const char *yesno[2]={QT_TRANSLATE_NOOP("qprops","No"),QT_TRANSLATE_NOOP("qprops","Yes")};
27
propWindow(QWidget * parent)28 propWindow::propWindow(QWidget *parent) : QDialog(parent)
29 {
30 ui.setupUi(this);
31 uint32_t war,har;
32 uint32_t hh, mm, ss, ms;
33 #define MXL 80
34 char text[MXL];
35 const char *s;
36
37 text[0] = 0;
38 listOfValues.clear();
39 if (!avifileinfo)
40 return;
41
42 #define FILLTEXT(a,b,c) {snprintf(text,MXL,b,c); listOfValues.push_back(QString::fromUtf8(text)); ui.a->setText(QString::fromUtf8(text));}
43 #define FILLTEXT4(a,b,c,d) {snprintf(text,MXL,b,c,d); listOfValues.push_back(QString::fromUtf8(text)); ui.a->setText(QString::fromUtf8(text));}
44 #define FILLTEXT5(a,b,c,d,e) {snprintf(text,MXL,b,c,d,e); listOfValues.push_back(QString::fromUtf8(text)); ui.a->setText(QString::fromUtf8(text));}
45 #define SET_YES(a,b) ui.a->setText(QString::fromUtf8(yesno[b]))
46 #define FILLQT_TRANSLATE_NOOP(a,q) listOfValues.push_back(QString::fromUtf8(text)); ui.q->setText(QString::fromUtf8(text));
47
48 //------------------------------------
49
50 FILLTEXT(label4CC, "%s", fourCC::tostring(avifileinfo->fcc));
51
52 FILLTEXT4(labeImageSize,QT_TRANSLATE_NOOP("qprops","%" PRIu32" x %" PRIu32), avifileinfo->width,avifileinfo->height);
53
54 war=video_body->getPARWidth();
55 har=video_body->getPARHeight();
56 getAspectRatioFromAR(war,har, &s);
57 FILLTEXT5(LabelAspectRatio,QT_TRANSLATE_NOOP("qprops","%s (%u:%u)"), s,war,har);
58
59 FILLTEXT(labelFrameRate, QT_TRANSLATE_NOOP("qprops","%2.3f fps"), (float) avifileinfo->fps1000 / 1000.F);
60
61 uint64_t duration=video_body->getVideoDuration();
62 ms2time(duration/1000,&hh,&mm,&ss,&ms);
63 snprintf(text, MXL, QT_TRANSLATE_NOOP("qprops","%02d:%02d:%02d.%03d"), hh, mm, ss, ms);
64 listOfValues.push_back(text);
65 ui.labelVideoDuration->setText(text);
66
67 uint32_t extraLen;
68 uint8_t *extraData;
69 video_body->getExtraHeaderData(&extraLen,&extraData);
70 FILLTEXT(LabelExtraDataSize,"%02d",extraLen);
71
72 if(extraLen)
73 {
74 int capped=extraLen;
75 if(capped>10) capped=10;
76 QString string;
77 char smallx[10];
78 for(int i=0;i<capped;i++)
79 {
80 snprintf(smallx,4,"%02X ",extraData[i]);
81 string+=QString(smallx);
82 }
83 listOfValues.push_back(string);
84 ui.LabelExtraData->setText(string);
85 }else
86 ui.LabelExtraData->clear();
87
88 //------------------------------------
89 WAVHeader *wavinfo=NULL;
90 ADM_audioStream *st;
91 video_body->getDefaultAudioTrack(&st);
92 if(st)
93 wavinfo=st->getInfo();
94 if(wavinfo)
95 {
96 int nbActive=video_body->getNumberOfActiveAudioTracks();
97 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
98 QString titleAudio=QCoreApplication::translate("qprops","Audio (%n active track(s))",NULL,nbActive);
99 #else
100 QString titleAudio=QCoreApplication::translate("qprops","Audio (%n active track(s))",NULL,QCoreApplication::UnicodeUTF8,nbActive);
101 #endif
102 ui.groupBoxAudio->setTitle(titleAudio);
103 listOfValues.push_back(titleAudio);
104
105 snprintf(text, MXL, "%s", getStrFromAudioCodec(wavinfo->encoding));
106 FILLQT_TRANSLATE_NOOP("qprops",labelACodec);
107
108 uint32_t channels=wavinfo->channels;
109 uint32_t frequency=wavinfo->frequency;
110 duration=0;
111 EditableAudioTrack *ed=video_body->getDefaultEditableAudioTrack();
112 if(ed)
113 {
114 ADM_EDAUDIO_TRACK_TYPE type=ed->edTrack->getTrackType();
115 switch (type)
116 {
117 case ADM_EDAUDIO_FROM_VIDEO:
118 duration=ed->edTrack->castToTrackFromVideo()->getDurationInUs();
119 channels=ed->edTrack->castToTrackFromVideo()->getOutputChannels();
120 frequency=ed->edTrack->castToTrackFromVideo()->getOutputFrequency();
121 break;
122 case ADM_EDAUDIO_EXTERNAL:
123 duration=ed->edTrack->castToExternal()->getDurationInUs();
124 channels=ed->edTrack->castToExternal()->getOutputChannels();
125 frequency=ed->edTrack->castToExternal()->getOutputFrequency();
126 break;
127 default:break;
128 }
129 }
130
131 switch (channels)
132 {
133 case 1:
134 sprintf(text,"%s", QT_TRANSLATE_NOOP("qprops","Mono"));
135 break;
136 case 2:
137 sprintf(text,"%s", QT_TRANSLATE_NOOP("qprops","Stereo"));
138 break;
139 default:
140 sprintf(text, "%d",channels);
141 break;
142 }
143
144 FILLQT_TRANSLATE_NOOP("qprops",labelChannels);
145
146 FILLTEXT4(labelBitrate, QT_TRANSLATE_NOOP("qprops","%" PRIu32" Bps / %" PRIu32" kbps"), wavinfo->byterate, wavinfo->byterate * 8 / 1000);
147
148 FILLTEXT(labelVBR,"%s","n/a");
149
150 FILLTEXT(labelFrequency, QT_TRANSLATE_NOOP("qprops","%" PRIu32" Hz"), frequency);
151
152 ms2time(duration/1000,&hh,&mm,&ss,&ms);
153 sprintf(text, QT_TRANSLATE_NOOP("qprops","%02d:%02d:%02d.%03d"), hh, mm, ss, ms);
154 FILLQT_TRANSLATE_NOOP("qprops",labelAudioDuration);
155 ui.labelAudioDuration->setEnabled(!!duration);
156
157 // SET_YES(labelVBR,currentaudiostream->isVBR());
158 } else
159 {
160 ui.groupBoxAudio->setEnabled(false);
161 }
162
163 connect(ui.pushButton_c2c,SIGNAL(clicked()),this,SLOT(propsCopyToClipboard()));
164 }
165
166 #define ADDCATEGORY(a) props += QString("\n=====================================================\n")\
167 +QString::fromUtf8(a)\
168 +QString("\n=====================================================\n");
169 #define ADDNAMEVALUE(a,b) props += QString::fromUtf8(a)+QString("\t")+QString(b)+QString("\n");
170
171 /**
172 \fn propsCopyToClipboard
173 \brief Copy a list of property-value pairs to clipboard
174 */
propsCopyToClipboard(void)175 void propWindow::propsCopyToClipboard(void)
176 {
177 if(listOfValues.size()<6) // something went wrong and the list is not sufficiently populated
178 return;
179
180 QString props;
181 props = QString();
182
183 ADDCATEGORY(QT_TRANSLATE_NOOP("qprops","Video"))
184
185 ADDNAMEVALUE(QT_TRANSLATE_NOOP("qprops","Codec 4CC:\t"),listOfValues.at(0))
186
187 ADDNAMEVALUE(QT_TRANSLATE_NOOP("qprops","Image Size:\t"),listOfValues.at(1))
188
189 ADDNAMEVALUE(QT_TRANSLATE_NOOP("qprops","Aspect Ratio:\t"),listOfValues.at(2))
190
191 ADDNAMEVALUE(QT_TRANSLATE_NOOP("qprops","Frame Rate:\t"),listOfValues.at(3))
192
193 ADDNAMEVALUE(QT_TRANSLATE_NOOP("qprops","Total Duration:\t"),listOfValues.at(4))
194
195 ADDCATEGORY(QT_TRANSLATE_NOOP("qprops","Extra Video Properties"))
196
197 ADDNAMEVALUE(QT_TRANSLATE_NOOP("qprops","ExtraDataSize:\t"),listOfValues.at(5))
198
199 bool hasExtraData=false;
200 if((QString)listOfValues.at(5) != QString("00"))
201 {
202 hasExtraData=true;
203 ADDNAMEVALUE(QT_TRANSLATE_NOOP("qprops","Extra data:\t"),listOfValues.at(6))
204 }
205
206 QString aud;
207 if(listOfValues.size() == 13+hasExtraData)
208 aud=listOfValues.at(6+hasExtraData);
209 else
210 aud=QString::fromUtf8(QT_TRANSLATE_NOOP("qprops","Audio"));
211
212 ADDCATEGORY(aud.toUtf8().constData())
213
214 if(listOfValues.size() == 13+hasExtraData)
215 {
216 ADDNAMEVALUE(QT_TRANSLATE_NOOP("qprops","Codec:\t\t"),listOfValues.at(7+hasExtraData))
217
218 ADDNAMEVALUE(QT_TRANSLATE_NOOP("qprops","Channels:\t"),listOfValues.at(8+hasExtraData))
219
220 ADDNAMEVALUE(QT_TRANSLATE_NOOP("qprops","Bitrate:\t"),listOfValues.at(9+hasExtraData))
221
222 //ADDNAMEVALUE(QT_TRANSLATE_NOOP("qprops","Variable Bitrate"),listOfValues.at(10+hasExtraData))
223
224 ADDNAMEVALUE(QT_TRANSLATE_NOOP("qprops","Frequency:\t"),listOfValues.at(11+hasExtraData))
225
226 ADDNAMEVALUE(QT_TRANSLATE_NOOP("qprops","Total Duration:\t"),listOfValues.at(12+hasExtraData))
227 }else
228 {
229 props += QT_TRANSLATE_NOOP("qprops","No Audio");
230 }
231
232 QClipboard *clipboard = QApplication::clipboard();
233 clipboard->clear();
234 clipboard->setText(props);
235 }
236
237 /**
238 \fn DIA_properties
239 \brief Display dialog with file information (size, codec, duration etc....)
240 */
DIA_properties(void)241 void DIA_properties( void )
242 {
243 if (playing)
244 return;
245
246 if (!avifileinfo)
247 return;
248
249 propWindow propwindow(qtLastRegisteredDialog());
250 qtRegisterDialog(&propwindow);
251 propwindow.exec();
252 qtUnregisterDialog(&propwindow);
253 }
254 //********************************************
255 //EOF
256