added OSS DSP support for GstreamerPlayer
This commit is contained in:
parent
e8b6c8d7e8
commit
eea04b3886
3 changed files with 126 additions and 9 deletions
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.4 $
|
||||
Version : $Revision: 1.5 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/GstreamerPlayer.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -109,9 +109,7 @@ GstreamerPlayer :: initialize(void) throw (std::exception)
|
|||
g_signal_connect(pipeline, "error", G_CALLBACK(errorHandler), this);
|
||||
g_signal_connect(pipeline, "state-change", G_CALLBACK(stateChange), this);
|
||||
|
||||
audiosink = gst_element_factory_make("alsasink", "alsasink");
|
||||
setAudioDevice(audioDevice);
|
||||
gst_bin_add(GST_BIN(pipeline), audiosink);
|
||||
|
||||
// set up other variables
|
||||
initialized = true;
|
||||
|
@ -441,9 +439,46 @@ bool
|
|||
GstreamerPlayer :: setAudioDevice(const std::string &deviceName)
|
||||
throw ()
|
||||
{
|
||||
// TODO: support OSS as well
|
||||
if (deviceName.size() > 0) {
|
||||
g_object_set(G_OBJECT(audiosink), "device", deviceName.c_str(), NULL);
|
||||
bool oss = deviceName.find("/dev") == 0;
|
||||
bool relink = false;
|
||||
|
||||
if (deviceName.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (audiosink) {
|
||||
bool oldOss = g_strrstr(gst_element_get_name(audiosink), "osssink");
|
||||
relink = oss && !oldOss;
|
||||
}
|
||||
|
||||
if (relink && audiosink) {
|
||||
if (decoder) {
|
||||
gst_element_unlink(decoder, audiosink);
|
||||
}
|
||||
gst_bin_remove(GST_BIN(pipeline), audiosink);
|
||||
// FIXME: why unref here? remove should unref already
|
||||
g_object_unref(G_OBJECT(audiosink));
|
||||
audiosink = 0;
|
||||
}
|
||||
|
||||
if (!audiosink) {
|
||||
audiosink = oss
|
||||
? gst_element_factory_make("osssink", "osssink")
|
||||
: gst_element_factory_make("alsasink", "alsasink");
|
||||
relink = true;
|
||||
}
|
||||
if (!audiosink) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// it's the same property, "device" for both alsasink and osssink
|
||||
g_object_set(G_OBJECT(audiosink), "device", deviceName.c_str(), NULL);
|
||||
|
||||
if (relink) {
|
||||
if (decoder) {
|
||||
gst_element_link(decoder, audiosink);
|
||||
}
|
||||
gst_bin_add(GST_BIN(pipeline), audiosink);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.5 $
|
||||
Version : $Revision: 1.6 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/GstreamerPlayerTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -153,6 +153,79 @@ GstreamerPlayerTest :: simplePlayTest(void)
|
|||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Check if the setDevice() function works are advertized.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
GstreamerPlayerTest :: setDeviceTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
Ptr<time_duration>::Ref sleepT(new time_duration(microseconds(10)));
|
||||
Ptr<time_duration>::Ref playlength;
|
||||
|
||||
player->initialize();
|
||||
|
||||
// check on an ALSA device
|
||||
CPPUNIT_ASSERT(player->setAudioDevice("plughw:0,0"));
|
||||
try {
|
||||
player->open("file:var/test-short.mp3");
|
||||
} catch (std::invalid_argument &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(!player->isPlaying());
|
||||
player->start();
|
||||
CPPUNIT_ASSERT(player->isPlaying());
|
||||
while (player->isPlaying()) {
|
||||
TimeConversion::sleep(sleepT);
|
||||
}
|
||||
playlength = player->getPlaylength();
|
||||
CPPUNIT_ASSERT(playlength.get());
|
||||
CPPUNIT_ASSERT(playlength->seconds() == 2);
|
||||
CPPUNIT_ASSERT(!player->isPlaying());
|
||||
|
||||
// check on an OSS DSP device
|
||||
CPPUNIT_ASSERT(player->setAudioDevice("/dev/dsp"));
|
||||
try {
|
||||
player->open("file:var/test-short.mp3");
|
||||
} catch (std::invalid_argument &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(!player->isPlaying());
|
||||
player->start();
|
||||
CPPUNIT_ASSERT(player->isPlaying());
|
||||
while (player->isPlaying()) {
|
||||
TimeConversion::sleep(sleepT);
|
||||
}
|
||||
playlength = player->getPlaylength();
|
||||
CPPUNIT_ASSERT(playlength.get());
|
||||
CPPUNIT_ASSERT(playlength->seconds() == 2);
|
||||
CPPUNIT_ASSERT(!player->isPlaying());
|
||||
|
||||
// check changing from ALSA to OSS after opening
|
||||
CPPUNIT_ASSERT(player->setAudioDevice("plughw:0,0"));
|
||||
try {
|
||||
player->open("file:var/test-short.mp3");
|
||||
} catch (std::invalid_argument &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(player->setAudioDevice("/dev/dsp"));
|
||||
CPPUNIT_ASSERT(!player->isPlaying());
|
||||
player->start();
|
||||
CPPUNIT_ASSERT(player->isPlaying());
|
||||
while (player->isPlaying()) {
|
||||
TimeConversion::sleep(sleepT);
|
||||
}
|
||||
playlength = player->getPlaylength();
|
||||
CPPUNIT_ASSERT(playlength.get());
|
||||
CPPUNIT_ASSERT(playlength->seconds() == 2);
|
||||
CPPUNIT_ASSERT(!player->isPlaying());
|
||||
|
||||
|
||||
player->close();
|
||||
player->deInitialize();
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Play a simple SMIL file
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.6 $
|
||||
Version : $Revision: 1.7 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/GstreamerPlayerTest.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -58,7 +58,7 @@ namespace PlaylistExecutor {
|
|||
* Unit test for the GstreamerPlayer class.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.6 $
|
||||
* @version $Revision: 1.7 $
|
||||
* @see GstreamerPlayer
|
||||
*/
|
||||
class GstreamerPlayerTest : public CPPUNIT_NS::TestFixture
|
||||
|
@ -66,6 +66,7 @@ class GstreamerPlayerTest : public CPPUNIT_NS::TestFixture
|
|||
CPPUNIT_TEST_SUITE(GstreamerPlayerTest);
|
||||
CPPUNIT_TEST(firstTest);
|
||||
CPPUNIT_TEST(simplePlayTest);
|
||||
CPPUNIT_TEST(setDeviceTest);
|
||||
CPPUNIT_TEST(simpleSmilTest);
|
||||
CPPUNIT_TEST(secondSmilTest);
|
||||
CPPUNIT_TEST(animatedSmilTest);
|
||||
|
@ -111,6 +112,14 @@ class GstreamerPlayerTest : public CPPUNIT_NS::TestFixture
|
|||
void
|
||||
simplePlayTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
/**
|
||||
* Test the setDevice() function, with ALSA and OSS devices.
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
setDeviceTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
/**
|
||||
* Play a simple SMIL file.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue