src/3rdparty/phonon/mmf/abstractaudioeffect.cpp
branchRCL_3
changeset 4 3b1da2848fc7
parent 3 41300fa6a67c
child 8 3f74d0d4af4c
equal deleted inserted replaced
3:41300fa6a67c 4:3b1da2848fc7
    17 */
    17 */
    18 
    18 
    19 #include "mediaobject.h"
    19 #include "mediaobject.h"
    20 
    20 
    21 #include "abstractaudioeffect.h"
    21 #include "abstractaudioeffect.h"
       
    22 #include "audioplayer.h"
       
    23 #include "mmf_videoplayer.h"
    22 
    24 
    23 QT_BEGIN_NAMESPACE
    25 QT_BEGIN_NAMESPACE
    24 
    26 
    25 using namespace Phonon;
    27 using namespace Phonon;
    26 using namespace Phonon::MMF;
    28 using namespace Phonon::MMF;
    32 /*! \namespace Phonon::MMF
    34 /*! \namespace Phonon::MMF
    33   \internal
    35   \internal
    34 */
    36 */
    35 
    37 
    36 AbstractAudioEffect::AbstractAudioEffect(QObject *parent,
    38 AbstractAudioEffect::AbstractAudioEffect(QObject *parent,
    37                                          const QList<EffectParameter> &params) : MediaNode::MediaNode(parent)
    39                                          const QList<EffectParameter> &params)
    38                                                                                , m_params(params)
    40     :   MediaNode(parent)
       
    41     ,   m_params(params)
       
    42     ,   m_player(0)
    39 {
    43 {
       
    44 
    40 }
    45 }
    41 
    46 
    42 bool AbstractAudioEffect::disconnectMediaNode(MediaNode *target)
    47 QList<Phonon::EffectParameter> AbstractAudioEffect::parameters() const
    43 {
    48 {
    44     MediaNode::disconnectMediaNode(target);
    49     // Convert from QList<MMF::EffectParameter> to QList<Phonon::EffectParameter>
    45     m_effect.reset();
    50     QList<Phonon::EffectParameter> result;
    46     return true;
    51     EffectParameter param;
       
    52     foreach (param, m_params)
       
    53         result += param;
       
    54     return result;
    47 }
    55 }
    48 
    56 
    49 QList<EffectParameter> AbstractAudioEffect::parameters() const
    57 QVariant AbstractAudioEffect::parameterValue(const Phonon::EffectParameter &queriedParam) const
    50 {
       
    51     return m_params;
       
    52 }
       
    53 
       
    54 QVariant AbstractAudioEffect::parameterValue(const EffectParameter &queriedParam) const
       
    55 {
    58 {
    56     const QVariant &val = m_values.value(queriedParam.id());
    59     const QVariant &val = m_values.value(queriedParam.id());
    57 
    60 
    58     if (val.isNull())
    61     if (val.isNull())
    59         return queriedParam.defaultValue();
    62         return queriedParam.defaultValue();
    60     else
    63     else
    61         return val;
    64         return val;
    62 }
    65 }
    63 
    66 
    64 bool AbstractAudioEffect::activateOnMediaObject(MediaObject *mo)
    67 void AbstractAudioEffect::setParameterValue(const Phonon::EffectParameter &param,
    65 {
       
    66     AudioPlayer *const ap = qobject_cast<AudioPlayer *>(mo->abstractPlayer());
       
    67 
       
    68     if (ap)
       
    69         return activateOn(ap->player());
       
    70     else
       
    71         return true;
       
    72 }
       
    73 
       
    74 void AbstractAudioEffect::setParameterValue(const EffectParameter &param,
       
    75                                             const QVariant &newValue)
    68                                             const QVariant &newValue)
    76 {
    69 {
    77     m_values.insert(param.id(), newValue);
    70     m_values.insert(param.id(), newValue);
    78     parameterChanged(param.id(), newValue);
    71 
       
    72     if (m_effect.data()) {
       
    73         const EffectParameter& internalParam = internalParameter(param.id());
       
    74         int err = parameterChanged(internalParam, newValue);
       
    75         // TODO: handle audio effect errors
       
    76         Q_UNUSED(err);
       
    77     }
    79 }
    78 }
       
    79 
       
    80 void AbstractAudioEffect::abstractPlayerChanged(AbstractPlayer *player)
       
    81 {
       
    82     m_player = qobject_cast<AbstractMediaPlayer *>(player);
       
    83     m_effect.reset();
       
    84 }
       
    85 
       
    86 void AbstractAudioEffect::stateChanged(Phonon::State newState,
       
    87                                        Phonon::State oldState)
       
    88 {
       
    89     if (Phonon::LoadingState == oldState
       
    90         && Phonon::LoadingState != newState)
       
    91         createEffect();
       
    92 }
       
    93 
       
    94 void AbstractAudioEffect::connectMediaObject(MediaObject *mediaObject)
       
    95 {
       
    96     Q_ASSERT_X(!m_player, Q_FUNC_INFO, "Player already connected");
       
    97     Q_ASSERT_X(!m_effect.data(), Q_FUNC_INFO, "Effect already created");
       
    98 
       
    99     abstractPlayerChanged(mediaObject->abstractPlayer());
       
   100 
       
   101     connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
       
   102             SLOT(stateChanged(Phonon::State, Phonon::State)));
       
   103 
       
   104     connect(mediaObject, SIGNAL(abstractPlayerChanged(AbstractPlayer *)),
       
   105             SLOT(abstractPlayerChanged(AbstractPlayer *)));
       
   106 
       
   107     if (mediaObject->state() != Phonon::LoadingState)
       
   108         createEffect();
       
   109 }
       
   110 
       
   111 void AbstractAudioEffect::disconnectMediaObject(MediaObject *mediaObject)
       
   112 {
       
   113     mediaObject->disconnect(this);
       
   114     abstractPlayerChanged(0);
       
   115 }
       
   116 
       
   117 void AbstractAudioEffect::setEnabled(bool enabled)
       
   118 {
       
   119     TInt err = KErrNone;
       
   120 
       
   121     if (enabled)
       
   122         // TODO: handle audio effect errors
       
   123         TRAP(err, m_effect->EnableL())
       
   124     else
       
   125         // TODO: handle audio effect errors
       
   126         TRAP(err, m_effect->DisableL())
       
   127 
       
   128     Q_UNUSED(err);
       
   129 }
       
   130 
       
   131 void AbstractAudioEffect::createEffect()
       
   132 {
       
   133     Q_ASSERT_X(m_player, Q_FUNC_INFO, "Invalid media player pointer");
       
   134 
       
   135     if (AudioPlayer *audioPlayer = qobject_cast<AudioPlayer *>(m_player)) {
       
   136         createEffect(audioPlayer->nativePlayer());
       
   137     }
       
   138 
       
   139     if (m_effect.data()) {
       
   140         EffectParameter param;
       
   141 	int err = 0;
       
   142         foreach (param, m_params) {
       
   143             const QVariant value = parameterValue(param);
       
   144             err = parameterChanged(param, value);
       
   145         }
       
   146 	Q_UNUSED(err)
       
   147     }
       
   148 }
       
   149 
       
   150 const MMF::EffectParameter& AbstractAudioEffect::internalParameter(int id) const
       
   151 {
       
   152     const EffectParameter *result = 0;
       
   153     for (int i=0; i<m_params.count() && !result; ++i) {
       
   154         if (m_params[i].id() == id)
       
   155             result = &m_params[i];
       
   156     }
       
   157     Q_ASSERT_X(result, Q_FUNC_INFO, "Parameter not found");
       
   158     return *result;
       
   159 }
       
   160 
       
   161 int AbstractAudioEffect::parameterChanged(const EffectParameter &param,
       
   162             const QVariant &value)
       
   163 {
       
   164     int err = 0;
       
   165 
       
   166     switch (param.id()) {
       
   167     case ParameterEnable:
       
   168         setEnabled(value.toBool());
       
   169         break;
       
   170     default:
       
   171         {
       
   172         const EffectParameter& internalParam = internalParameter(param.id());
       
   173         err = effectParameterChanged(internalParam, value);
       
   174         }
       
   175         break;
       
   176     }
       
   177 
       
   178     if (!err)
       
   179         TRAP(err, m_effect->ApplyL());
       
   180 
       
   181     return err;
       
   182 }
       
   183 
       
   184 int AbstractAudioEffect::effectParameterChanged(
       
   185     const EffectParameter &param, const QVariant &value)
       
   186 {
       
   187     // Default implementation
       
   188     Q_ASSERT_X(false, Q_FUNC_INFO, "Effect has no parameters");
       
   189     return 0;
       
   190 }
       
   191 
    80 
   192 
    81 QT_END_NAMESPACE
   193 QT_END_NAMESPACE
    82 
   194