@@ -2,21 +2,76 @@ extern "C"
22{
33#include " sound.h"
44}
5+ #include < MediaAddOn.h>
6+ #include < MediaNode.h>
57#include < MediaRoster.h>
8+ #include < ParameterWeb.h>
69
7- const char * ffDetectSound (FF_MAYBE_UNUSED FFlist* devices /* List of FFSoundDevice */ )
10+ const char * ffDetectSound (FFlist* devices /* List of FFSoundDevice */ )
811{
912 BMediaRoster* roster = BMediaRoster::Roster ();
1013 media_node mediaNode;
14+ live_node_info liveInfo;
15+ dormant_node_info dormantInfo;
16+ status_t status;
1117
12- roster->GetAudioOutput (&mediaNode);
18+ if (roster->GetAudioOutput (&mediaNode) != B_OK)
19+ return NULL ;
20+
21+ FFSoundDevice* device = (FFSoundDevice*)ffListAdd (devices);
22+ if (roster->GetDormantNodeFor (mediaNode, &dormantInfo) == B_OK)
23+ {
24+ ffStrbufInitS (&device->identifier , dormantInfo.name );
25+ }
26+ if (roster->GetLiveNodeInfo (mediaNode, &liveInfo) == B_OK)
27+ {
28+ ffStrbufInitS (&device->name , liveInfo.name );
29+ ffStrbufTrimRightSpace (&device->name );
30+ }
31+ ffStrbufInitF (&device->platformApi , " %s" , " MediaKit" );
32+ // We'll check the Mixer actually
33+ device->volume = (uint8_t ) 100 ;
34+ device->active = true ;
35+ device->main = true ;
36+
37+ roster->ReleaseNode (mediaNode);
38+
39+ media_node mixer;
40+ status = roster->GetAudioMixer (&mixer);
41+ if (status != B_OK)
42+ return NULL ;
1343
14- int32 mediaOutputCount = 0 ;
15- roster->GetAllOutputsFor (mediaNode, NULL , 0 , &mediaOutputCount);
16- if (mediaOutputCount == 0 )
44+ BParameterWeb *web;
45+ status = roster->GetParameterWebFor (mixer, &web);
46+ roster->ReleaseNode (mixer); // the web is all we need :-)
47+ if (status != B_OK)
1748 return NULL ;
1849
19- // TODO: Implement the rest of the function
50+ BContinuousParameter *gain = NULL ;
51+ BParameter *mute = NULL ;
52+ BParameter *parameter;
53+ for (int32 index = 0 ; (parameter = web->ParameterAt (index)) != NULL ; index++) {
54+ // assume the mute preceding master gain control
55+ if (!strcmp (parameter->Kind (), B_MUTE))
56+ mute = parameter;
57+
58+ if (!strcmp (parameter->Kind (), B_MASTER_GAIN)) {
59+ // Can not use dynamic_cast due to fno-rtti
60+ // gain = dynamic_cast<BContinuousParameter *>(parameter);
61+ gain = (BContinuousParameter *)(parameter);
62+ break ;
63+ }
64+ }
65+
66+ if (gain == NULL )
67+ return NULL ;
68+
69+ float volume = 0.0 ;
70+ bigtime_t when;
71+ size_t size = sizeof (volume);
72+ gain->GetValue (&volume, &size, &when);
73+
74+ device->volume = (uint8_t ) (100 * (volume - gain->MinValue ()) / (gain->MaxValue () - gain->MinValue ()));
2075
21- return " Not supported on this platform " ;
76+ return NULL ;
2277}
0 commit comments