Skip to content

Commit 140fbad

Browse files
committed
Added new AudioDeviceInfo struct, and populate a vector of them on QtPlayer initialization. This allows a user to overwrite the preferred audio device by using the setting PLAYBACK_AUDIO_DEVICE_NAME.
1 parent bf620f8 commit 140fbad

File tree

9 files changed

+97
-10
lines changed

9 files changed

+97
-10
lines changed

include/AudioDeviceInfo.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @file
3+
* @brief Header file for Audio Device Info struct
4+
* @author Jonathan Thomas <[email protected]>
5+
*
6+
* @section LICENSE
7+
*
8+
* Copyright (c) 2008-2014 OpenShot Studios, LLC
9+
* <http://www.openshotstudios.com/>. This file is part of
10+
* OpenShot Library (libopenshot), an open-source project dedicated to
11+
* delivering high quality video editing and animation solutions to the
12+
* world. For more information visit <http://www.openshot.org/>.
13+
*
14+
* OpenShot Library (libopenshot) is free software: you can redistribute it
15+
* and/or modify it under the terms of the GNU Lesser General Public License
16+
* as published by the Free Software Foundation, either version 3 of the
17+
* License, or (at your option) any later version.
18+
*
19+
* OpenShot Library (libopenshot) is distributed in the hope that it will be
20+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
* GNU Lesser General Public License for more details.
23+
*
24+
* You should have received a copy of the GNU Lesser General Public License
25+
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
26+
*/
27+
28+
#ifndef OPENSHOT_AUDIODEVICEINFO_H
29+
#define OPENSHOT_AUDIODEVICEINFO_H
30+
31+
32+
/**
33+
* @brief This struct hold information about Audio Devices
34+
*
35+
* The type and name of the audio device.
36+
*/
37+
struct AudioDeviceInfo
38+
{
39+
string name;
40+
string type;
41+
};
42+
43+
#endif

include/Qt/AudioPlaybackThread.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "../ReaderBase.h"
3333
#include "../RendererBase.h"
3434
#include "../AudioReaderSource.h"
35+
#include "../AudioDeviceInfo.h"
36+
#include "../Settings.h"
3537

3638
namespace openshot
3739
{
@@ -66,8 +68,11 @@ namespace openshot
6668
/// Error found during JUCE initialise method
6769
string initialise_error;
6870

69-
/// Create or get an instance of this singleton (invoke the class with this method)
70-
static AudioDeviceManagerSingleton * Instance(int numChannels);
71+
/// List of valid audio device names
72+
vector<AudioDeviceInfo> audio_device_names;
73+
74+
/// Override with no channels and no preferred audio device
75+
static AudioDeviceManagerSingleton * Instance();
7176

7277
/// Public device manager property
7378
AudioDeviceManager audioDeviceManager;
@@ -126,7 +131,10 @@ namespace openshot
126131
int getSpeed() const { if (source) return source->getSpeed(); else return 1; }
127132

128133
/// Get Audio Error (if any)
129-
string getError() { return AudioDeviceManagerSingleton::Instance(numChannels)->initialise_error; }
134+
string getError() { return AudioDeviceManagerSingleton::Instance()->initialise_error; }
135+
136+
/// Get Audio Device Names (if any)
137+
vector<AudioDeviceInfo> getAudioDeviceNames() { return AudioDeviceManagerSingleton::Instance()->audio_device_names; };
130138

131139
friend class PlayerPrivate;
132140
friend class QtPlayer;

include/QtPlayer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ namespace openshot
6262
/// Get Error (if any)
6363
string GetError();
6464

65+
/// Get Audio Devices from JUCE
66+
vector<AudioDeviceInfo> GetAudioDeviceNames();
67+
6568
/// Play the video
6669
void Play();
6770

include/Settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ namespace openshot {
109109
/// Which GPU to use to encode (0 is the first)
110110
int HW_EN_DEVICE_SET = 0;
111111

112+
/// The audio device name to use during playback
113+
string PLAYBACK_AUDIO_DEVICE_NAME = "";
114+
112115
/// Create or get an instance of this logger singleton (invoke the class with this method)
113116
static Settings * Instance();
114117
};

src/Qt/AudioPlaybackThread.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace openshot
3535
AudioDeviceManagerSingleton *AudioDeviceManagerSingleton::m_pInstance = NULL;
3636

3737
// Create or Get an instance of the device manager singleton
38-
AudioDeviceManagerSingleton *AudioDeviceManagerSingleton::Instance(int numChannels)
38+
AudioDeviceManagerSingleton *AudioDeviceManagerSingleton::Instance()
3939
{
4040
if (!m_pInstance) {
4141
// Create the actual instance of device manager only once
@@ -44,16 +44,31 @@ namespace openshot
4444
// Initialize audio device only 1 time
4545
String error = m_pInstance->audioDeviceManager.initialise (
4646
0, /* number of input channels */
47-
numChannels, /* number of output channels */
47+
2, /* number of output channels */
4848
0, /* no XML settings.. */
49-
true /* select default device on failure */);
49+
true, /* select default device on failure */
50+
Settings::Instance()->PLAYBACK_AUDIO_DEVICE_NAME /* preferredDefaultDeviceName */);
5051

5152
// Persist any errors detected
5253
if (error.isNotEmpty()) {
5354
m_pInstance->initialise_error = error.toStdString();
5455
} else {
5556
m_pInstance->initialise_error = "";
5657
}
58+
59+
// Get all audio device names
60+
for (int i = 0; i < m_pInstance->audioDeviceManager.getAvailableDeviceTypes().size(); ++i)
61+
{
62+
const AudioIODeviceType* t = m_pInstance->audioDeviceManager.getAvailableDeviceTypes()[i];
63+
const StringArray deviceNames = t->getDeviceNames ();
64+
65+
for (int j = 0; j < deviceNames.size (); ++j )
66+
{
67+
const String deviceName = deviceNames[j];
68+
AudioDeviceInfo deviceInfo = {deviceName.toStdString(), t->getTypeName().toStdString()};
69+
m_pInstance->audio_device_names.push_back(deviceInfo);
70+
}
71+
}
5772
}
5873

5974
return m_pInstance;
@@ -149,7 +164,7 @@ namespace openshot
149164

150165
// Start new audio device (or get existing one)
151166
// Add callback
152-
AudioDeviceManagerSingleton::Instance(numChannels)->audioDeviceManager.addAudioCallback(&player);
167+
AudioDeviceManagerSingleton::Instance()->audioDeviceManager.addAudioCallback(&player);
153168

154169
// Create TimeSliceThread for audio buffering
155170
time_thread.startThread();
@@ -182,7 +197,7 @@ namespace openshot
182197
transport.setSource(NULL);
183198

184199
player.setSource(NULL);
185-
AudioDeviceManagerSingleton::Instance(0)->audioDeviceManager.removeAudioCallback(&player);
200+
AudioDeviceManagerSingleton::Instance()->audioDeviceManager.removeAudioCallback(&player);
186201

187202
// Remove source
188203
delete source;

src/QtPlayer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ QtPlayer::~QtPlayer()
5656
void QtPlayer::CloseAudioDevice()
5757
{
5858
// Close audio device (only do this once, when all audio playback is finished)
59-
AudioDeviceManagerSingleton::Instance(0)->CloseAudioDevice();
59+
AudioDeviceManagerSingleton::Instance()->CloseAudioDevice();
6060
}
6161

6262
// Return any error string during initialization
@@ -69,6 +69,15 @@ string QtPlayer::GetError() {
6969
}
7070
}
7171

72+
/// Get Audio Devices from JUCE
73+
vector<AudioDeviceInfo> QtPlayer::GetAudioDeviceNames() {
74+
if (reader && threads_started) {
75+
return p->audioPlayback->getAudioDeviceNames();
76+
} else {
77+
return vector<AudioDeviceInfo>();
78+
}
79+
}
80+
7281
void QtPlayer::SetSource(const std::string &source)
7382
{
7483
FFmpegReader *ffreader = new FFmpegReader(source);

src/Settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Settings *Settings::Instance()
5151
m_pInstance->DE_LIMIT_WIDTH_MAX = 1950;
5252
m_pInstance->HW_DE_DEVICE_SET = 0;
5353
m_pInstance->HW_EN_DEVICE_SET = 0;
54-
54+
m_pInstance->PLAYBACK_AUDIO_DEVICE_NAME = "";
5555
}
5656

5757
return m_pInstance;

src/bindings/python/openshot.i

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
#include "../../../include/Settings.h"
8888
#include "../../../include/Timeline.h"
8989
#include "../../../include/ZmqLogger.h"
90+
#include "../../../include/AudioDeviceInfo.h"
9091

9192
%}
9293

@@ -154,6 +155,7 @@
154155
%include "../../../include/Settings.h"
155156
%include "../../../include/Timeline.h"
156157
%include "../../../include/ZmqLogger.h"
158+
%include "../../../include/AudioDeviceInfo.h"
157159

158160
#ifdef USE_IMAGEMAGICK
159161
%include "../../../include/ImageReader.h"
@@ -187,4 +189,5 @@ namespace std {
187189
%template(FieldVector) vector<Field>;
188190
%template(MappedFrameVector) vector<MappedFrame>;
189191
%template(MappedMetadata) map<string, string>;
192+
%template(AudioDeviceInfoVector) vector<AudioDeviceInfo>;
190193
}

src/bindings/ruby/openshot.i

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ namespace std {
9191
#include "../../../include/Settings.h"
9292
#include "../../../include/Timeline.h"
9393
#include "../../../include/ZmqLogger.h"
94+
#include "../../../include/AudioDeviceInfo.h"
9495

9596
%}
9697

@@ -147,6 +148,7 @@ namespace std {
147148
%include "../../../include/Settings.h"
148149
%include "../../../include/Timeline.h"
149150
%include "../../../include/ZmqLogger.h"
151+
%include "../../../include/AudioDeviceInfo.h"
150152

151153
#ifdef USE_IMAGEMAGICK
152154
%include "../../../include/ImageReader.h"
@@ -181,4 +183,5 @@ namespace std {
181183
%template(FieldVector) vector<Field>;
182184
%template(MappedFrameVector) vector<MappedFrame>;
183185
%template(MappedMetadata) map<string, string>;
186+
%template(AudioDeviceInfoVector) vector<AudioDeviceInfo>;
184187
}

0 commit comments

Comments
 (0)