Classified ads
ringtoneplayer.h
Go to the documentation of this file.
1 /* -*-C++-*- -*-coding: utf-8-unix;-*-
2  Classified Ads is Copyright (c) Antti J√§rvinen 2013-2016.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  Classified Ads is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with Classified Ads; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #ifndef RINGTONE_PLAYER_H
22 #define RINGTONE_PLAYER_H
23 
24 #include <QByteArray>
25 #include <QAudioOutput>
26 #include <QIODevice>
27 #include <QTimer>
28 #include <opus/opus.h> // for data types
29 #include "../net/voicecallengine.h" // for MCallStatusObserver
30 #include "../mcontroller.h"
31 #include "../datamodel/model.h"
32 
33 class QFile ;
34 class QMutex ;
35 
42 class RingtonePlayer : public QIODevice,
44  Q_OBJECT
45 
46 public:
53  RingtonePlayer(Model& aModel,
54  MController& aController ) ;
55  ~RingtonePlayer() ;
59  void timerEvent(QTimerEvent *event);
64  virtual void callStatusChanged(quint32 aCallId,
66 
67 // next methods inherited from QIODevice:
68 public:
69  virtual qint64 bytesAvailable () const {
70  return iAudioBuffer.size() + QIODevice::bytesAvailable();
71  }
72 protected:
84  virtual qint64 writeData ( const char * data, qint64 maxSize ) ;
95  virtual qint64 readData ( char * data, qint64 maxSize ) ;
99  virtual bool open ( OpenMode mode ) ;
100  /*
101  * method for opening QIODevice: tells that this is no random-access
102  * device.
103  *
104  * @return true always
105  */
106  virtual bool isSequential () const {
107  return true ; // is not random-access,
108  }
109 signals:
113  void error(int aError,
114  const QString& aExplanation) ;
115 
116 public slots:
120  virtual void finishedPlaying ( QAudio::State aState );
121 
125  virtual void notify() ;
129  void stop() ;
130 private: // methods
134  void initInput() ;
135 private: // members
136  QAudioFormat iFormat;
137  QAudioOutput* iAudioOutput ;
138  QByteArray iAudioBuffer ;
139  bool iNeedsToRun ;
140  QFile* iRingtoneFile ;
141  int iTimerId ;
142  OpusDecoder* iDecoder ;
143  QByteArray iDecodedData ;
144  QMutex* iMutex ;
147 } ;
148 #endif
MController & iController
Definition: ringtoneplayer.h:146
virtual bool open(OpenMode mode)
void error(int aError, const QString &aExplanation)
QByteArray iDecodedData
Definition: ringtoneplayer.h:143
bool iNeedsToRun
Definition: ringtoneplayer.h:139
Model & iModel
Definition: ringtoneplayer.h:145
virtual bool isSequential() const
Definition: ringtoneplayer.h:106
Class for alerting user in case of incoming call.
Definition: ringtoneplayer.h:42
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:43
M of the MVC pattern. Handles permanent storage.
Definition: model.h:48
OpusDecoder * iDecoder
Definition: ringtoneplayer.h:142
Definition: mvoicecallengine.h:52
QMutex * iMutex
Definition: ringtoneplayer.h:144
CallState
Definition: mvoicecallengine.h:38
virtual void notify()
virtual qint64 readData(char *data, qint64 maxSize)
RingtonePlayer(Model &aModel, MController &aController)
QAudioOutput * iAudioOutput
Definition: ringtoneplayer.h:137
virtual qint64 writeData(const char *data, qint64 maxSize)
QFile * iRingtoneFile
Definition: ringtoneplayer.h:140
virtual void finishedPlaying(QAudio::State aState)
int iTimerId
Definition: ringtoneplayer.h:141
QAudioFormat iFormat
Definition: ringtoneplayer.h:136
void timerEvent(QTimerEvent *event)
virtual qint64 bytesAvailable() const
Definition: ringtoneplayer.h:69
QByteArray iAudioBuffer
Definition: ringtoneplayer.h:138
virtual void callStatusChanged(quint32 aCallId, VoiceCallEngine::CallState aState)