123 } |
123 } |
124 |
124 |
125 bool AudioOutput::setOutputDevice(int newDevice) |
125 bool AudioOutput::setOutputDevice(int newDevice) |
126 { |
126 { |
127 m_backend->logMessage(Q_FUNC_INFO + QString::number(newDevice), Backend::Info, this); |
127 m_backend->logMessage(Q_FUNC_INFO + QString::number(newDevice), Backend::Info, this); |
|
128 |
128 if (newDevice == m_device) |
129 if (newDevice == m_device) |
129 return true; |
130 return true; |
130 |
131 |
131 if (root()) { |
132 if (root()) { |
132 root()->saveState(); |
133 root()->saveState(); |
133 if (gst_element_set_state(root()->pipeline(), GST_STATE_READY) == GST_STATE_CHANGE_FAILURE) |
134 if (gst_element_set_state(root()->pipeline(), GST_STATE_READY) == GST_STATE_CHANGE_FAILURE) |
134 return false; |
135 return false; |
135 } |
136 } |
136 |
137 |
137 bool success = false; |
138 bool success = false; |
138 const QList<AudioDevice> deviceList = m_backend->deviceManager()->audioOutputDevices(); |
139 if (m_audioSink && newDevice >= 0) { |
139 int deviceIdx = -1; |
|
140 for (int i=0; i<deviceList.size(); i++) { |
|
141 if (deviceList.at(i).id == newDevice) { |
|
142 deviceIdx = i; |
|
143 break; |
|
144 } |
|
145 } |
|
146 |
|
147 if (m_audioSink && deviceIdx >= 0) { |
|
148 // Save previous state |
140 // Save previous state |
149 GstState oldState = GST_STATE(m_audioSink); |
141 GstState oldState = GST_STATE(m_audioSink); |
150 const QByteArray oldDeviceValue = GstHelper::property(m_audioSink, "device"); |
142 const QByteArray oldDeviceValue = GstHelper::property(m_audioSink, "device"); |
151 const QByteArray deviceId = deviceList.at(deviceIdx).gstId; |
143 const QByteArray deviceId = m_backend->deviceManager()->gstId(newDevice); |
152 m_device = newDevice; |
144 m_device = newDevice; |
153 |
145 |
154 // We test if the device can be opened by checking if it can go from NULL to READY state |
146 // We test if the device can be opened by checking if it can go from NULL to READY state |
155 gst_element_set_state(m_audioSink, GST_STATE_NULL); |
147 gst_element_set_state(m_audioSink, GST_STATE_NULL); |
156 success = GstHelper::setProperty(m_audioSink, "device", deviceId); |
148 success = GstHelper::setProperty(m_audioSink, "device", deviceId); |
168 m_backend->logMessage(Q_FUNC_INFO + |
160 m_backend->logMessage(Q_FUNC_INFO + |
169 QLatin1String(" Successfully changed device ") + |
161 QLatin1String(" Successfully changed device ") + |
170 deviceId, Backend::Info, this); |
162 deviceId, Backend::Info, this); |
171 } |
163 } |
172 |
164 |
173 // Note the stopped state should not really be neccessary, but seems to be required to |
165 // Note the stopped state should not really be necessary, but seems to be required to |
174 // properly reset after changing the audio state |
166 // properly reset after changing the audio state |
175 if (root()) { |
167 if (root()) { |
176 QMetaObject::invokeMethod(root(), "setState", Qt::QueuedConnection, Q_ARG(State, StoppedState)); |
168 QMetaObject::invokeMethod(root(), "setState", Qt::QueuedConnection, Q_ARG(State, StoppedState)); |
177 root()->resumeState(); |
169 root()->resumeState(); |
178 } |
170 } |