egalite is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

Commit 59d90cc404fa30376ef3172fbd6a4e70a8c81b0a

User picture

testing timer

Files Affected

 
46a5dc0b3bbf9bdb954dfe3c1deb54555ab8b8a759d90cc404fa30376ef3172fbd6a4e70a8c81b0a
759
  bool removeFile (false);
759
  bool removeFile (false);
760
  XferInfo::XferKind kind (XferInfo::Xfer_None);
760
  XferInfo::XferKind kind (XferInfo::Xfer_None);
761
  XferInfo::XferDirection inout (XferInfo::Xfer_Out);
761
  XferInfo::XferDirection inout (XferInfo::Xfer_Out);
 
 
762
  qint64  duration (0);
762
  XferStateMap::iterator  stateIt = xferState.find(id);
763
  XferStateMap::iterator  stateIt = xferState.find(id);
763
  if (stateIt != xferState.end()) {
764
  if (stateIt != xferState.end()) {
764
    kind = stateIt->second.kind;
765
    kind = stateIt->second.kind;
765
    inout = stateIt->second.inout;
766
    inout = stateIt->second.inout;
766
    removeFile = stateIt->second.removeOnComplete;
767
    removeFile = stateIt->second.removeOnComplete;
 
 
768
    duration = stateIt->second.usecs;
767
  }
769
  }
768
  xferState.erase (id);
770
  xferState.erase (id);
769
  QFile *fp = xferFile[id];
771
  QFile *fp = xferFile[id];
770
  QString filename (tr("unknown file"));
772
  QString filename (tr("unknown file"));
 
 
773
  qDebug () << __PRETTY_FUNCTION__ << " file " << fp;
771
  if (fp) {
774
  if (fp) {
772
    filename = fp->fileName();
775
    filename = fp->fileName();
 
 
776
    qDebug () << __PRETTY_FUNCTION__ 
 
 
777
              << " closing receive file "  << fp->fileName();
773
    fp->close();
778
    fp->close();
 
 
779
    qDebug () << "     file size after close " 
 
 
780
              << QFileInfo (filename).size ();
 
 
781
    qDebug () << "     file perms after close " 
 
 
782
              << QFileInfo (filename).permissions ();
774
    if (removeFile) {
783
    if (removeFile) {
775
      fp->remove ();
784
      fp->remove ();
776
    }
785
    }
...
 
...
 
795
    if (inout == XferInfo::Xfer_In) {
804
    if (inout == XferInfo::Xfer_In) {
796
#if DO_AUDIO
805
#if DO_AUDIO
797
      audio.FinishReceive ();
806
      audio.FinishReceive ();
798
#else
807
#endif
799
  #if DO_MOBI_AUDIO
808
#if DO_MOBI_AUDIO
800
      mobiAudio.FinishReceive ();
809
      mobiAudio.FinishReceive (filename, duration);
801
  #endif
 
 
802
#endif
810
#endif
803
    } else if (inout == XferInfo::Xfer_Out) {
811
    } else if (inout == XferInfo::Xfer_Out) {
804
      ui.samButton->setEnabled (qtAudioOk);
812
      ui.samButton->setEnabled (qtAudioOk);
...
 
...
 
891
    info.lastChunkAck = 0;
899
    info.lastChunkAck = 0;
892
    info.kind = XferInfo::Xfer_Audio;
900
    info.kind = XferInfo::Xfer_Audio;
893
    info.inout = XferInfo::Xfer_In;
901
    info.inout = XferInfo::Xfer_In;
 
 
902
    info.usecs = msg.Attribute("usecs").toLongLong();
894
#if DO_AUDIO
903
#if DO_AUDIO
895
    audio.StartReceive ();
904
    audio.StartReceive ();
896
    QFile * fp = audio.InFile ();
905
    QFile * fp = audio.InFile ();
46a5dc0b3bbf9bdb954dfe3c1deb54555ab8b8a759d90cc404fa30376ef3172fbd6a4e70a8c81b0a
67
 
67
 
68
  XferInfo ()
68
  XferInfo ()
69
    :removeOnComplete (false),
69
    :removeOnComplete (false),
70
     pipeline (1)
70
     pipeline (1),
 
 
71
     usecs (0)
71
    {}
72
    {}
72
  ~XferInfo() {}
73
  ~XferInfo() {}
73
 
74
 
...
 
...
 
79
  quint64         lastChunkAck;
80
  quint64         lastChunkAck;
80
  bool            removeOnComplete;
81
  bool            removeOnComplete;
81
  int             pipeline;
82
  int             pipeline;
 
 
83
  qint64          usecs;
82
};
84
};
83
 
85
 
84
class ChatContent : public QDialog 
86
class ChatContent : public QDialog 
46a5dc0b3bbf9bdb954dfe3c1deb54555ab8b8a759d90cc404fa30376ef3172fbd6a4e70a8c81b0a
40
   player (0),
40
   player (0),
41
   recTime (10.0),
41
   recTime (10.0),
42
   tick (0.0),
42
   tick (0.0),
43
   secsLeft (0.0),
43
   secsLeft (0.0)
44
   playLimitTimer (0)
 
 
45
{
44
{
46
  audioSource = new QAudioCaptureSource (this);
45
  audioSource = new QAudioCaptureSource (this);
47
  recorder = new QMediaRecorder (audioSource, this);
46
  recorder = new QMediaRecorder (audioSource, this);
48
  player = new QMediaPlayer (this);
47
  player = new QMediaPlayer (this);
49
  ui.setupUi (this);
48
  ui.setupUi (this);
50
  playLimitTimer = new QTimer (this);
 
 
51
  hide ();
49
  hide ();
52
  clock.start ();
50
  clock.start ();
53
  inStateText[0] = QString("Stopper");
51
  inStateText[0] = QString("Stopper");
...
 
...
 
181
void
179
void
182
MobiAudiMessage::StartPlay ()
180
MobiAudiMessage::StartPlay ()
183
{
181
{
184
  qDebug () << __PRETTY_FUNCTION__ << "Play audio message";
182
  qDebug () << __PRETTY_FUNCTION__ << "Play audio message " << inFile.fileName();
185
  if (player == 0) {
183
  if (player == 0) {
186
    return;
184
    return;
187
  }
185
  }
188
  player->setMedia (QMediaContent (QUrl::fromLocalFile (inFile.fileName())));
186
  if (playList.isEmpty()) {
 
 
187
    return;
 
 
188
  }
 
 
189
  PlayItem item = playList.takeFirst();
 
 
190
  if (item.filename.isEmpty() || item.duration < 1) {
 
 
191
    return;
 
 
192
  }
 
 
193
  qDebug () << "   readable ? " << QFileInfo (item.filename).isReadable();
 
 
194
  player->setMedia (QMediaContent (QUrl::fromLocalFile (item.filename)));
189
 
195
 
190
  emit PlayStarting ();
196
  emit PlayStarting ();
191
  player->setVolume (50);
197
  player->setVolume (50);
192
  player->setPosition (0);
198
  player->setPosition (0);
193
  player->play ();
199
  player->play ();
194
  qDebug () << "    playing " << player->media().canonicalUrl();
200
  qDebug () << __PRETTY_FUNCTION__ ;
 
 
201
  qDebug () << "    playing  " << player->media().canonicalUrl();
 
 
202
  qDebug () << "  have audio " << player->isAudioAvailable ();
 
 
203
  qDebug () << "    mime     " << player->media().canonicalResource().mimeType();
 
 
204
  qDebug () << "    codec    " << player->media().canonicalResource().audioCodec();
 
 
205
  qDebug () << "    bitrate  " << player->media().canonicalResource().audioBitRate();
 
 
206
  qDebug () << "    null ?   " << player->media().isNull();
195
  qDebug () << "    duration " << player->duration();
207
  qDebug () << "    duration " << player->duration();
 
 
208
  qDebug () << "    position " << player->position();
196
  qDebug () << "    err      " << player->errorString();
209
  qDebug () << "    err      " << player->errorString();
197
  int playtime = (player->duration() / 1000) + 1000;
210
  qDebug () << "    rate     " << player->playbackRate();
198
 // playLimitTimer->start (playtime);
211
  int playtime = item.duration;
199
  QTimer::singleShot (playtime, this, SLOT (StopPlay()));
212
  qDebug () << "    play tiemout set to " << playtime;
 
 
213
  QTimer::singleShot (playtime, this, SLOT (TimeoutPlay()));
200
}
214
}
201
 
215
 
202
void
216
void
...
 
...
 
206
  qDebug () << "               " << player->errorString();
220
  qDebug () << "               " << player->errorString();
207
}
221
}
208
 
222
 
209
#if 0
 
 
210
void
 
 
211
MobiAudiMessage::CheckPlayState ()
 
 
212
{
 
 
213
  static qint64  oldWork (0);
 
 
214
  if (player) {
 
 
215
    QAudio::State  state = player->state ();
 
 
216
    if (state == QAudio::IdleState) {
 
 
217
      StopPlay ();
 
 
218
    } else {
 
 
219
      qint64 workdone = player->processedUSecs ();
 
 
220
      if (workdone <= oldWork) {  // nothing done in 2 secs, shut it down
 
 
221
        StopPlay ();
 
 
222
        qDebug () << " forcing audio player stop";
 
 
223
      } else {
 
 
224
        oldWork = workdone;
 
 
225
      }
 
 
226
    }
 
 
227
  }
 
 
228
}
 
 
229
#endif
 
 
230
 
223
 
231
void
224
void
232
MobiAudiMessage::PlayerStateChanged (QMediaPlayer::State state)
225
MobiAudiMessage::PlayerStateChanged (QMediaPlayer::State state)
233
{
226
{
234
  qDebug () << __PRETTY_FUNCTION__ << " state " << state;
227
  qDebug () << __PRETTY_FUNCTION__ << " new state " << state;
 
 
228
  qDebug () << "    playing  " << player->media().canonicalUrl();
 
 
229
  qDebug () << "  have audio " << player->isAudioAvailable ();
 
 
230
  qDebug () << "    mime     " << player->media().canonicalResource().mimeType();
 
 
231
  qDebug () << "    codec    " << player->media().canonicalResource().audioCodec();
 
 
232
  qDebug () << "    bitrate  " << player->media().canonicalResource().audioBitRate();
 
 
233
  qDebug () << "    null ?   " << player->media().isNull();
 
 
234
  qDebug () << "    duration " << player->duration();
 
 
235
  qDebug () << "    position " << player->position();
 
 
236
  qDebug () << "    err      " << player->errorString();
 
 
237
  qDebug () << "    rate     " << player->playbackRate();
235
  switch (state) {
238
  switch (state) {
236
  case QMediaPlayer::PlayingState:
239
  case QMediaPlayer::PlayingState:
237
    break;
240
    break;
...
 
...
 
243
  }
246
  }
244
}
247
}
245
 
248
 
 
 
249
void
 
 
250
MobiAudiMessage::TimeoutPlay ()
 
 
251
{
 
 
252
  qDebug () << __PRETTY_FUNCTION__ ;
 
 
253
  if (player && player->state() != QMediaPlayer::StoppedState) {
 
 
254
    StopPlay();
 
 
255
  }
 
 
256
}
 
 
257
 
246
 
258
 
247
void
259
void
248
MobiAudiMessage::StopPlay ()
260
MobiAudiMessage::StopPlay ()
...
 
...
 
256
  }
268
  }
257
  busyReceive = false;
269
  busyReceive = false;
258
  emit PlayFinished ();
270
  emit PlayFinished ();
259
  playLimitTimer->stop ();
 
 
260
  qDebug () << __PRETTY_FUNCTION__ << " done playing audio message";
271
  qDebug () << __PRETTY_FUNCTION__ << " done playing audio message";
261
}
272
}
262
 
273
 
...
 
...
 
283
}
294
}
284
 
295
 
285
void
296
void
286
MobiAudiMessage::FinishReceive ()
297
MobiAudiMessage::FinishReceive (const QString & filename, qint64 duration)
287
{
298
{
288
  StartPlay ();
299
  qDebug () << __PRETTY_FUNCTION__ << filename << duration;
 
 
300
  playList.append (PlayItem (filename, duration));
 
 
301
  QTimer::singleShot (100, this, SLOT (StartPlay ()));
289
}
302
}
290
 
303
 
291
QString
304
QString
46a5dc0b3bbf9bdb954dfe3c1deb54555ab8b8a759d90cc404fa30376ef3172fbd6a4e70a8c81b0a
61
  bool  BusyReceive () { return busyReceive; }
61
  bool  BusyReceive () { return busyReceive; }
62
 
62
 
63
  void  Record (const QPoint & where, const QSize & size);
63
  void  Record (const QPoint & where, const QSize & size);
64
  void  StartPlay ();
 
 
65
  int   Size ();
64
  int   Size ();
66
 
65
 
67
  void  SetInLength (qint64 usecs) { playUSecs = usecs; }
66
  void  SetInLength (qint64 usecs) { playUSecs = usecs; }
...
 
...
 
69
public slots:
68
public slots:
70
 
69
 
71
  void StopRecording ();
70
  void StopRecording ();
72
  void FinishReceive ();
71
  void FinishReceive (const QString & filename, qint64 duration);
73
  void StopPlay ();
 
 
74
 
72
 
75
private slots:
73
private slots:
76
 
74
 
...
 
...
 
78
  void PlayerStateChanged (QMediaPlayer::State state);
76
  void PlayerStateChanged (QMediaPlayer::State state);
79
  void RecorderError  (QMediaRecorder::Error error);
77
  void RecorderError  (QMediaRecorder::Error error);
80
  void PlayerError  (QMediaPlayer::Error error);
78
  void PlayerError  (QMediaPlayer::Error error);
 
 
79
  void StartPlay ();
 
 
80
  void StopPlay ();
 
 
81
  void TimeoutPlay ();
81
 
82
 
82
signals:
83
signals:
83
 
84
 
...
 
...
 
87
 
88
 
88
private:
89
private:
89
 
90
 
 
 
91
  class PlayItem {
 
 
92
  public:
 
 
93
    PlayItem ()
 
 
94
      :filename(QString()), duration(0)
 
 
95
    {}
 
 
96
    PlayItem (const QString & name, qint64 len)
 
 
97
      :filename (name), duration (len)
 
 
98
    {}
 
 
99
 
 
 
100
    QString  filename;
 
 
101
    qint64   duration;
 
 
102
  };
 
 
103
 
90
  void       StartCount (double maxtime);
104
  void       StartCount (double maxtime);
91
  QString    Tempname ();
105
  QString    Tempname ();
92
 
106
 
...
 
...
 
105
  double         recTime;
119
  double         recTime;
106
  double         tick;
120
  double         tick;
107
  double         secsLeft;
121
  double         secsLeft;
108
  QTimer        *playLimitTimer;
 
 
109
  qint64         playUSecs;
122
  qint64         playUSecs;
110
  bool           busyReceive;
123
  bool           busyReceive;
111
  QTime          clock;
124
  QTime          clock;
112
  QString        inStateText[4];
125
  QString        inStateText[4];
113
 
126
 
 
 
127
  QList<PlayItem>  playList;
 
 
128
 
114
  Ui_CountDownDisplay ui;
129
  Ui_CountDownDisplay ui;
115
} ;
130
} ;
116
 
131