added detection and loading of default inputs and outputs

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3303 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper 2003-05-24 20:33:52 +00:00
parent d8d1ef215b
commit c12232ddb5
2 changed files with 213 additions and 63 deletions

View File

@ -6,6 +6,7 @@
#include <MediaNode.h> #include <MediaNode.h>
#include <MediaRoster.h> #include <MediaRoster.h>
#include <string.h> #include <string.h>
#include <String.h>
#include "DefaultManager.h" #include "DefaultManager.h"
#include "debug.h" #include "debug.h"
@ -13,10 +14,16 @@
*/ */
DefaultManager::DefaultManager() DefaultManager::DefaultManager()
: fSystemTimeSource(-1), : fPhysicalVideoOut(-1),
fDefaultVideoOut(-1), fPhysicalVideoIn(-1),
fDefaultVideoIn(-1) fPhysicalAudioOut(-1),
fPhysicalAudioIn(-1),
fSystemTimeSource(-1),
fTimeSource(-1),
fAudioMixer(-1),
fPhysicalAudioOutInputID(0)
{ {
strcpy(fPhysicalAudioOutInputName, "default");
} }
DefaultManager::~DefaultManager() DefaultManager::~DefaultManager()
@ -66,28 +73,54 @@ DefaultManager::Set(node_type type, const media_node *node, const dormant_node_i
} }
status_t status_t
DefaultManager::Get(media_node_id *nodeid, char *input_name, int32 *input_id, node_type type) DefaultManager::Get(media_node_id *nodeid, char *input_name, int32 *inputid, node_type type)
{ {
switch (type) { switch (type) {
case VIDEO_INPUT: // output: nodeid case VIDEO_INPUT: // output: nodeid
*nodeid = fDefaultVideoOut; if (fPhysicalVideoIn == -1)
return *nodeid > 0 ? B_OK : B_ERROR; return B_ERROR;
*nodeid = fPhysicalVideoIn;
return B_OK;
case AUDIO_INPUT: // output: nodeid case AUDIO_INPUT: // output: nodeid
*nodeid = -999; if (fPhysicalAudioIn == -1)
return B_ERROR; return B_ERROR;
*nodeid = fPhysicalAudioIn;
return B_OK;
case VIDEO_OUTPUT: // output: nodeid case VIDEO_OUTPUT: // output: nodeid
*nodeid = fDefaultVideoIn; if (fPhysicalVideoOut == -1)
return *nodeid > 0 ? B_OK : B_ERROR; return B_ERROR;
*nodeid = fPhysicalVideoOut;
return B_OK;
case AUDIO_OUTPUT: // output: nodeid
if (fPhysicalAudioOut == -1)
return B_ERROR;
*nodeid = fPhysicalAudioOut;
return B_OK;
case AUDIO_OUTPUT_EX: // output: nodeid, input_name, input_id
if (fPhysicalAudioOut == -1)
return B_ERROR;
*nodeid = fPhysicalAudioOut;
*inputid = fPhysicalAudioOutInputID;
strcpy(input_name, fPhysicalAudioOutInputName);
return B_OK;
case AUDIO_MIXER: // output: nodeid case AUDIO_MIXER: // output: nodeid
case AUDIO_OUTPUT: // output: nodeid if (fAudioMixer == -1)
case AUDIO_OUTPUT_EX: // output: nodeid, input_name, input_id return B_ERROR;
*nodeid = -999; *nodeid = fAudioMixer;
return B_ERROR; return B_OK;
case TIME_SOURCE: case TIME_SOURCE:
if (fTimeSource != -1)
*nodeid = fTimeSource;
else
*nodeid = fSystemTimeSource;
return B_OK;
case SYSTEM_TIME_SOURCE: case SYSTEM_TIME_SOURCE:
*nodeid = fSystemTimeSource; *nodeid = fSystemTimeSource;
return B_OK; return B_OK;
@ -119,57 +152,161 @@ DefaultManager::rescan_thread(void *arg)
void void
DefaultManager::RescanThread() DefaultManager::RescanThread()
{ {
dormant_node_info info;
media_format output;
media_format input;
int32 count;
status_t rv;
printf("DefaultManager::RescanThread() enter\n"); printf("DefaultManager::RescanThread() enter\n");
// We do not search for the system time source,
// it should already exist
ASSERT(fSystemTimeSource != -1);
memset(&output, 0, sizeof(output)); if (fPhysicalVideoOut == -1)
output.type = B_MEDIA_RAW_VIDEO; FindPhysicalVideoOut();
count = 1; if (fPhysicalVideoIn == -1)
rv = BMediaRoster::Roster()->GetDormantNodes(&info, &count, NULL, &output); FindPhysicalVideoIn();
if (rv != B_OK || count != 1) { if (fPhysicalAudioOut == -1)
printf("Couldn't find default video output node\n"); FindPhysicalAudioOut();
fDefaultVideoOut = -1; if (fPhysicalAudioIn == -1)
} else { FindPhysicalAudioIn();
media_node node; if (fAudioMixer == -1)
rv = BMediaRoster::Roster()->InstantiateDormantNode(info, &node); FindAudioMixer();
if (rv != B_OK) { // The normal time source is searched for after the
printf("Couldn't instantiate default video output node\n"); // Physical Audio Out has been created.
fDefaultVideoOut = -1; if (fTimeSource == -1)
} else { FindTimeSource();
printf("Default video output created!\n");
fDefaultVideoOut = node.node;
}
}
memset(&input, 0, sizeof(input));
input.type = B_MEDIA_RAW_VIDEO;
count = 1;
rv = BMediaRoster::Roster()->GetDormantNodes(&info, &count, &input);
if (rv != B_OK || count != 1) {
printf("Couldn't find default video input node\n");
fDefaultVideoIn = -1;
} else {
media_node node;
rv = BMediaRoster::Roster()->InstantiateDormantNode(info, &node);
if (rv != B_OK) {
printf("Couldn't instantiate default video input node\n");
fDefaultVideoIn = -1;
} else {
printf("Default video input created!\n");
fDefaultVideoIn = node.node;
}
}
printf("DefaultManager::RescanThread() leave\n"); printf("DefaultManager::RescanThread() leave\n");
} }
void
DefaultManager::FindPhysicalVideoOut()
{
dormant_node_info info;
media_format input; /* a physical video output has a logical data input */
media_node node;
int32 count;
status_t rv;
memset(&input, 0, sizeof(input));
input.type = B_MEDIA_RAW_VIDEO;
count = 1;
rv = BMediaRoster::Roster()->GetDormantNodes(&info, &count, &input, NULL, NULL, B_BUFFER_CONSUMER | B_PHYSICAL_OUTPUT);
if (rv != B_OK || count != 1) {
printf("Couldn't find physical video output node\n");
return;
}
rv = BMediaRoster::Roster()->InstantiateDormantNode(info, &node, B_FLAVOR_IS_GLOBAL);
if (rv != B_OK) {
printf("Couldn't instantiate physical video output node\n");
} else {
printf("Default physical video output created!\n");
fPhysicalVideoOut = node.node;
}
}
void
DefaultManager::FindPhysicalVideoIn()
{
dormant_node_info info;
media_format output; /* a physical video input has a logical data output */
media_node node;
int32 count;
status_t rv;
memset(&output, 0, sizeof(output));
output.type = B_MEDIA_RAW_VIDEO;
count = 1;
rv = BMediaRoster::Roster()->GetDormantNodes(&info, &count, NULL, &output, NULL, B_BUFFER_PRODUCER | B_PHYSICAL_INPUT);
if (rv != B_OK || count != 1) {
printf("Couldn't find physical video input node\n");
return;
}
rv = BMediaRoster::Roster()->InstantiateDormantNode(info, &node, B_FLAVOR_IS_GLOBAL);
if (rv != B_OK) {
printf("Couldn't instantiate physical video input node\n");
} else {
printf("Default physical video input created!\n");
fPhysicalVideoIn = node.node;
}
}
void
DefaultManager::FindPhysicalAudioOut()
{
dormant_node_info info;
media_format input; /* a physical audio output has a logical data input */
media_node node;
int32 count;
status_t rv;
memset(&input, 0, sizeof(input));
input.type = B_MEDIA_RAW_AUDIO;
count = 1;
rv = BMediaRoster::Roster()->GetDormantNodes(&info, &count, &input, NULL, NULL, B_BUFFER_CONSUMER | B_PHYSICAL_OUTPUT);
if (rv != B_OK || count != 1) {
printf("Couldn't find physical audio output node\n");
return;
}
rv = BMediaRoster::Roster()->InstantiateDormantNode(info, &node, B_FLAVOR_IS_GLOBAL);
if (rv != B_OK) {
printf("Couldn't instantiate physical audio output node\n");
} else {
printf("Default physical audio output created!\n");
fPhysicalAudioOut = node.node;
}
}
void
DefaultManager::FindPhysicalAudioIn()
{
dormant_node_info info;
media_format output; /* a physical audio input has a logical data output */
media_node node;
int32 count;
status_t rv;
memset(&output, 0, sizeof(output));
output.type = B_MEDIA_RAW_AUDIO;
count = 1;
rv = BMediaRoster::Roster()->GetDormantNodes(&info, &count, NULL, &output, NULL, B_BUFFER_PRODUCER | B_PHYSICAL_INPUT);
if (rv != B_OK || count != 1) {
printf("Couldn't find physical audio input node\n");
return;
}
rv = BMediaRoster::Roster()->InstantiateDormantNode(info, &node, B_FLAVOR_IS_GLOBAL);
if (rv != B_OK) {
printf("Couldn't instantiate physical audio input node\n");
} else {
printf("Default physical audio input created!\n");
fPhysicalAudioIn = node.node;
}
}
void
DefaultManager::FindTimeSource()
{
}
void
DefaultManager::FindAudioMixer()
{
dormant_node_info info;
media_node node;
int32 count;
status_t rv;
count = 1;
rv = BMediaRoster::Roster()->GetDormantNodes(&info, &count, NULL, NULL, NULL, B_BUFFER_PRODUCER | B_BUFFER_CONSUMER | B_SYSTEM_MIXER);
if (rv != B_OK || count != 1) {
printf("Couldn't find audio mixer node\n");
return;
}
rv = BMediaRoster::Roster()->InstantiateDormantNode(info, &node, B_FLAVOR_IS_GLOBAL);
if (rv != B_OK) {
printf("Couldn't instantiate audio mixer node\n");
} else {
printf("Default audio mixer created!\n");
fAudioMixer = node.node;
}
}
void void
DefaultManager::Dump() DefaultManager::Dump()

View File

@ -23,13 +23,26 @@ public:
void Dump(); void Dump();
void CleanupTeam(team_id team); void CleanupTeam(team_id team);
private:
static int32 rescan_thread(void *arg); static int32 rescan_thread(void *arg);
void RescanThread(); void RescanThread();
void FindPhysicalVideoOut();
void FindPhysicalVideoIn();
void FindPhysicalAudioOut();
void FindPhysicalAudioIn();
void FindAudioMixer();
void FindTimeSource();
private: private:
media_node_id fPhysicalVideoOut;
media_node_id fPhysicalVideoIn;
media_node_id fPhysicalAudioOut;
media_node_id fPhysicalAudioIn;
media_node_id fSystemTimeSource; media_node_id fSystemTimeSource;
media_node_id fDefaultVideoOut; media_node_id fTimeSource;
media_node_id fDefaultVideoIn; media_node_id fAudioMixer;
int32 fPhysicalAudioOutInputID;
char fPhysicalAudioOutInputName[B_MEDIA_NAME_LENGTH];
}; };