style clean up

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35114 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2010-01-17 12:51:31 +00:00
parent 8aad948744
commit d3bb2b9543
+84 -37
View File
@@ -65,10 +65,12 @@ DefaultManager::DefaultManager()
fEndHeader[2] = 0x00000002; fEndHeader[2] = 0x00000002;
} }
DefaultManager::~DefaultManager() DefaultManager::~DefaultManager()
{ {
} }
// this is called by the media_server *before* any add-ons have been loaded // this is called by the media_server *before* any add-ons have been loaded
status_t status_t
DefaultManager::LoadState() DefaultManager::LoadState()
@@ -110,6 +112,7 @@ DefaultManager::LoadState()
return B_OK; return B_OK;
} }
status_t status_t
DefaultManager::SaveState(NodeManager *node_manager) DefaultManager::SaveState(NodeManager *node_manager)
{ {
@@ -126,8 +129,10 @@ DefaultManager::SaveState(NodeManager *node_manager)
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE); BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
uint32 default_types[] = {kMsgTypeVideoIn, kMsgTypeVideoOut, kMsgTypeAudioIn, kMsgTypeAudioOut}; uint32 default_types[] = {kMsgTypeVideoIn, kMsgTypeVideoOut,
uint32 media_node_ids[] = {fPhysicalVideoIn, fPhysicalVideoOut, fPhysicalAudioIn, fPhysicalAudioOut}; kMsgTypeAudioIn, kMsgTypeAudioOut};
uint32 media_node_ids[] = {fPhysicalVideoIn, fPhysicalVideoOut,
fPhysicalAudioIn, fPhysicalAudioOut};
for (uint32 i=0; i<sizeof(default_types)/sizeof(default_types[0]); i++) { for (uint32 i=0; i<sizeof(default_types)/sizeof(default_types[0]); i++) {
BMessage *settings = new BMessage(); BMessage *settings = new BMessage();
settings->AddInt32(kDefaultManagerType, default_types[i]); settings->AddInt32(kDefaultManagerType, default_types[i]);
@@ -147,7 +152,8 @@ DefaultManager::SaveState(NodeManager *node_manager)
BPath path(&ref); BPath path(&ref);
settings->AddInt32(kDefaultManagerAddon, info.addon); settings->AddInt32(kDefaultManagerAddon, info.addon);
settings->AddInt32(kDefaultManagerFlavorId, info.flavor_id); settings->AddInt32(kDefaultManagerFlavorId, info.flavor_id);
settings->AddInt32(kDefaultManagerInput, default_types[i] == kMsgTypeAudioOut ? fPhysicalAudioOutInputID : 0); settings->AddInt32(kDefaultManagerInput,
default_types[i] == kMsgTypeAudioOut ? fPhysicalAudioOutInputID : 0);
settings->AddString(kDefaultManagerFlavorName, info.name); settings->AddString(kDefaultManagerFlavorName, info.name);
settings->AddString(kDefaultManagerPath, path.Path()); settings->AddString(kDefaultManagerPath, path.Path());
@@ -164,7 +170,8 @@ DefaultManager::SaveState(NodeManager *node_manager)
for (int32 i = 0; i < category_count; i++) { for (int32 i = 0; i < category_count; i++) {
BMessage *settings = (BMessage *)list.ItemAt(i); BMessage *settings = (BMessage *)list.ItemAt(i);
uint32 default_type; uint32 default_type;
if (settings->FindInt32(kDefaultManagerType, (int32*)&default_type) < B_OK) if (settings->FindInt32(kDefaultManagerType,
(int32*)&default_type) < B_OK)
return B_ERROR; return B_ERROR;
if (file.Write(&kMsgHeader, sizeof(uint32)) < (int32)sizeof(uint32)) if (file.Write(&kMsgHeader, sizeof(uint32)) < (int32)sizeof(uint32))
return B_ERROR; return B_ERROR;
@@ -180,11 +187,14 @@ DefaultManager::SaveState(NodeManager *node_manager)
return B_OK; return B_OK;
} }
status_t status_t
DefaultManager::Set(media_node_id node_id, const char *input_name, int32 input_id, node_type type) DefaultManager::Set(media_node_id node_id, const char *input_name,
int32 input_id, node_type type)
{ {
CALLED(); CALLED();
TRACE("DefaultManager::Set type : %i, node : %li, input : %li\n", type, node_id, input_id); TRACE("DefaultManager::Set type : %i, node : %li, input : %li\n", type,
node_id, input_id);
switch (type) { switch (type) {
case VIDEO_INPUT: case VIDEO_INPUT:
fPhysicalVideoIn = node_id; fPhysicalVideoIn = node_id;
@@ -200,12 +210,14 @@ DefaultManager::Set(media_node_id node_id, const char *input_name, int32 input_i
case AUDIO_OUTPUT: case AUDIO_OUTPUT:
fPhysicalAudioOut = node_id; fPhysicalAudioOut = node_id;
fPhysicalAudioOutInputID = input_id; fPhysicalAudioOutInputID = input_id;
strcpy(fPhysicalAudioOutInputName, input_name ? input_name : "<null>"); strcpy(fPhysicalAudioOutInputName,
input_name ? input_name : "<null>");
return B_OK; return B_OK;
case TIME_SOURCE: case TIME_SOURCE:
return B_ERROR; return B_ERROR;
case SYSTEM_TIME_SOURCE: //called by the media_server's ServerApp::StartSystemTimeSource() // called by the media_server's ServerApp::StartSystemTimeSource()
case SYSTEM_TIME_SOURCE:
{ {
ASSERT(fSystemTimeSource == -1); ASSERT(fSystemTimeSource == -1);
fSystemTimeSource = node_id; fSystemTimeSource = node_id;
@@ -214,14 +226,17 @@ DefaultManager::Set(media_node_id node_id, const char *input_name, int32 input_i
default: default:
{ {
ERROR("DefaultManager::Set Error: called with unknown type %d\n", type); ERROR("DefaultManager::Set Error: called with unknown type %d\n",
type);
return B_ERROR; return B_ERROR;
} }
} }
} }
status_t status_t
DefaultManager::Get(media_node_id *nodeid, char *input_name, int32 *inputid, node_type type) DefaultManager::Get(media_node_id *nodeid, char *input_name, int32 *inputid,
node_type type)
{ {
CALLED(); CALLED();
switch (type) { switch (type) {
@@ -276,21 +291,26 @@ DefaultManager::Get(media_node_id *nodeid, char *input_name, int32 *inputid, nod
default: default:
{ {
ERROR("DefaultManager::Get Error: called with unknown type %d\n", type); ERROR("DefaultManager::Get Error: called with unknown type %d\n",
type);
return B_ERROR; return B_ERROR;
} }
} }
} }
// this is called by the media_server *after* the initial add-on loading has been done
// this is called by the media_server *after* the initial add-on loading
// has been done
status_t status_t
DefaultManager::Rescan() DefaultManager::Rescan()
{ {
thread_id fThreadId = spawn_thread(rescan_thread, "rescan defaults", 8, this); thread_id fThreadId = spawn_thread(rescan_thread, "rescan defaults",
B_NORMAL_PRIORITY - 2, this);
resume_thread(fThreadId); resume_thread(fThreadId);
return B_OK; return B_OK;
} }
int32 int32
DefaultManager::rescan_thread(void *arg) DefaultManager::rescan_thread(void *arg)
{ {
@@ -298,6 +318,7 @@ DefaultManager::rescan_thread(void *arg)
return 0; return 0;
} }
void void
DefaultManager::RescanThread() DefaultManager::RescanThread()
{ {
@@ -308,17 +329,23 @@ DefaultManager::RescanThread()
ASSERT(fSystemTimeSource != -1); ASSERT(fSystemTimeSource != -1);
if (fPhysicalVideoOut == -1) { if (fPhysicalVideoOut == -1) {
FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false, B_MEDIA_RAW_VIDEO); FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false,
FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false, B_MEDIA_ENCODED_VIDEO); B_MEDIA_RAW_VIDEO);
FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false,
B_MEDIA_ENCODED_VIDEO);
} }
if (fPhysicalVideoIn == -1) { if (fPhysicalVideoIn == -1) {
FindPhysical(&fPhysicalVideoIn, kMsgTypeVideoIn, true, B_MEDIA_RAW_VIDEO); FindPhysical(&fPhysicalVideoIn, kMsgTypeVideoIn, true,
FindPhysical(&fPhysicalVideoIn, kMsgTypeVideoIn, true, B_MEDIA_ENCODED_VIDEO); B_MEDIA_RAW_VIDEO);
FindPhysical(&fPhysicalVideoIn, kMsgTypeVideoIn, true,
B_MEDIA_ENCODED_VIDEO);
} }
if (fPhysicalAudioOut == -1) if (fPhysicalAudioOut == -1)
FindPhysical(&fPhysicalAudioOut, kMsgTypeAudioOut, false, B_MEDIA_RAW_AUDIO); FindPhysical(&fPhysicalAudioOut, kMsgTypeAudioOut, false,
B_MEDIA_RAW_AUDIO);
if (fPhysicalAudioIn == -1) if (fPhysicalAudioIn == -1)
FindPhysical(&fPhysicalAudioIn, kMsgTypeAudioIn, true, B_MEDIA_RAW_AUDIO); FindPhysical(&fPhysicalAudioIn, kMsgTypeAudioIn, true,
B_MEDIA_RAW_AUDIO);
if (fAudioMixer == -1) if (fAudioMixer == -1)
FindAudioMixer(); FindAudioMixer();
@@ -360,7 +387,8 @@ DefaultManager::FindPhysical(volatile media_node_id *id, uint32 default_type,
for(int32 i=0; i<fMsgList.CountItems(); i++) { for(int32 i=0; i<fMsgList.CountItems(); i++) {
msg = (BMessage *)fMsgList.ItemAt(i); msg = (BMessage *)fMsgList.ItemAt(i);
int32 msgType; int32 msgType;
if(msg->FindInt32(kDefaultManagerType, &msgType)==B_OK && ((uint32)msgType == default_type)) { if(msg->FindInt32(kDefaultManagerType, &msgType) == B_OK
&& ((uint32)msgType == default_type)) {
const char *name = NULL; const char *name = NULL;
const char *path = NULL; const char *path = NULL;
msg->FindInt32(kDefaultManagerAddon, &msgDninfo.addon); msg->FindInt32(kDefaultManagerAddon, &msgDninfo.addon);
@@ -381,9 +409,11 @@ DefaultManager::FindPhysical(volatile media_node_id *id, uint32 default_type,
count = MAX_NODE_INFOS; count = MAX_NODE_INFOS;
rv = BMediaRoster::Roster()->GetLiveNodes(&info[0], &count, rv = BMediaRoster::Roster()->GetLiveNodes(&info[0], &count,
isInput ? NULL : &format, isInput ? &format : NULL, NULL, isInput ? NULL : &format, isInput ? &format : NULL, NULL,
isInput ? B_BUFFER_PRODUCER | B_PHYSICAL_INPUT : B_BUFFER_CONSUMER | B_PHYSICAL_OUTPUT); isInput ? B_BUFFER_PRODUCER | B_PHYSICAL_INPUT
: B_BUFFER_CONSUMER | B_PHYSICAL_OUTPUT);
if (rv != B_OK || count < 1) { if (rv != B_OK || count < 1) {
ERROR("Couldn't find physical %s %s node\n", isAudio ? "audio" : "video", isInput ? "input" : "output"); ERROR("Couldn't find physical %s %s node\n",
isAudio ? "audio" : "video", isInput ? "input" : "output");
return; return;
} }
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
@@ -397,7 +427,8 @@ DefaultManager::FindPhysical(volatile media_node_id *id, uint32 default_type,
*id = info[i].node.node; *id = info[i].node.node;
continue; continue;
} }
if (0 == strcmp(info[i].name, "DV Input")) // skip the Firewire audio driver // skip the Firewire audio driver
if (0 == strcmp(info[i].name, "DV Input"))
continue; continue;
} else { } else {
if (0 == strcmp(info[i].name, "None Out")) { if (0 == strcmp(info[i].name, "None Out")) {
@@ -407,7 +438,8 @@ DefaultManager::FindPhysical(volatile media_node_id *id, uint32 default_type,
fPhysicalAudioOutInputID = input_id; fPhysicalAudioOutInputID = input_id;
continue; continue;
} }
if (0 == strcmp(info[i].name, "DV Output")) // skip the Firewire audio driver // skip the Firewire audio driver
if (0 == strcmp(info[i].name, "DV Output"))
continue; continue;
} }
} }
@@ -453,10 +485,12 @@ DefaultManager::FindTimeSource()
*/ */
if (fPhysicalAudioOut != -1) { if (fPhysicalAudioOut != -1) {
media_node clone; media_node clone;
if (B_OK == BMediaRoster::Roster()->GetNodeFor(fPhysicalAudioOut, &clone)) { if (B_OK == BMediaRoster::Roster()->GetNodeFor(fPhysicalAudioOut,
&clone)) {
if (clone.kind & B_TIME_SOURCE) { if (clone.kind & B_TIME_SOURCE) {
fTimeSource = clone.node; fTimeSource = clone.node;
BMediaRoster::Roster()->StartTimeSource(clone, system_time() + 1000); BMediaRoster::Roster()->StartTimeSource(clone,
system_time() + 1000);
BMediaRoster::Roster()->ReleaseNode(clone); BMediaRoster::Roster()->ReleaseNode(clone);
printf("Default DAC timesource created!\n"); printf("Default DAC timesource created!\n");
return; return;
@@ -474,20 +508,25 @@ DefaultManager::FindTimeSource()
memset(&input, 0, sizeof(input)); memset(&input, 0, sizeof(input));
input.type = B_MEDIA_RAW_AUDIO; input.type = B_MEDIA_RAW_AUDIO;
count = MAX_NODE_INFOS; count = MAX_NODE_INFOS;
rv = BMediaRoster::Roster()->GetLiveNodes(&info[0], &count, &input, NULL, NULL, B_TIME_SOURCE | B_PHYSICAL_OUTPUT); rv = BMediaRoster::Roster()->GetLiveNodes(&info[0], &count, &input, NULL, NULL,
B_TIME_SOURCE | B_PHYSICAL_OUTPUT);
if (rv == B_OK && count >= 1) { if (rv == B_OK && count >= 1) {
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
printf("info[%d].name %s\n", i, info[i].name); printf("info[%d].name %s\n", i, info[i].name);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
// The BeOS R5 None Out node pretend to be a physical time source, that is pretty dumb // The BeOS R5 None Out node pretend to be a physical time source,
if (0 == strcmp(info[i].name, "None Out")) // skip the Null audio driver // that is pretty dumb
// skip the Null audio driver
if (0 == strcmp(info[i].name, "None Out"))
continue; continue;
if (0 != strstr(info[i].name, "DV Output")) // skip the Firewire audio driver // skip the Firewire audio driver
if (0 != strstr(info[i].name, "DV Output"))
continue; continue;
printf("Default DAC timesource \"%s\" created!\n", info[i].name); printf("Default DAC timesource \"%s\" created!\n", info[i].name);
fTimeSource = info[i].node.node; fTimeSource = info[i].node.node;
BMediaRoster::Roster()->StartTimeSource(info[i].node, system_time() + 1000); BMediaRoster::Roster()->StartTimeSource(info[i].node,
system_time() + 1000);
return; return;
} }
} else { } else {
@@ -498,6 +537,7 @@ DefaultManager::FindTimeSource()
*/ */
} }
void void
DefaultManager::FindAudioMixer() DefaultManager::FindAudioMixer()
{ {
@@ -506,7 +546,8 @@ DefaultManager::FindAudioMixer()
status_t rv; status_t rv;
count = 1; count = 1;
rv = BMediaRoster::Roster()->GetLiveNodes(&info, &count, NULL, NULL, NULL, B_BUFFER_PRODUCER | B_BUFFER_CONSUMER | B_SYSTEM_MIXER); rv = BMediaRoster::Roster()->GetLiveNodes(&info, &count, NULL, NULL, NULL,
B_BUFFER_PRODUCER | B_BUFFER_CONSUMER | B_SYSTEM_MIXER);
if (rv != B_OK || count != 1) { if (rv != B_OK || count != 1) {
printf("Couldn't find audio mixer node\n"); printf("Couldn't find audio mixer node\n");
return; return;
@@ -515,6 +556,7 @@ DefaultManager::FindAudioMixer()
printf("Default audio mixer node created\n"); printf("Default audio mixer node created\n");
} }
status_t status_t
DefaultManager::ConnectMixerToOutput() DefaultManager::ConnectMixerToOutput()
{ {
@@ -537,7 +579,8 @@ DefaultManager::ConnectMixerToOutput()
rv = roster->GetNodeFor(fPhysicalAudioOut, &soundcard); rv = roster->GetNodeFor(fPhysicalAudioOut, &soundcard);
if (rv != B_OK) { if (rv != B_OK) {
printf("DefaultManager: failed to find soundcard (physical audio output)\n"); printf("DefaultManager: failed to find soundcard (physical audio "
"output)\n");
return B_ERROR; return B_ERROR;
} }
@@ -551,14 +594,16 @@ DefaultManager::ConnectMixerToOutput()
// we now have the mixer and soundcard nodes, // we now have the mixer and soundcard nodes,
// find a free input/output and connect them // find a free input/output and connect them
rv = roster->GetFreeOutputsFor(mixer, &output, 1, &count, B_MEDIA_RAW_AUDIO); rv = roster->GetFreeOutputsFor(mixer, &output, 1, &count,
B_MEDIA_RAW_AUDIO);
if (rv != B_OK || count != 1) { if (rv != B_OK || count != 1) {
printf("DefaultManager: can't find free mixer output\n"); printf("DefaultManager: can't find free mixer output\n");
rv = B_ERROR; rv = B_ERROR;
goto finish; goto finish;
} }
rv = roster->GetFreeInputsFor(soundcard, inputs, MAX_INPUT_INFOS, &count, B_MEDIA_RAW_AUDIO); rv = roster->GetFreeInputsFor(soundcard, inputs, MAX_INPUT_INFOS, &count,
B_MEDIA_RAW_AUDIO);
if (rv != B_OK || count < 1) { if (rv != B_OK || count < 1) {
printf("DefaultManager: can't find free soundcard inputs\n"); printf("DefaultManager: can't find free soundcard inputs\n");
rv = B_ERROR; rv = B_ERROR;
@@ -625,7 +670,8 @@ DefaultManager::ConnectMixerToOutput()
break; break;
} }
rv = roster->Connect(output.source, input.destination, &format, &newoutput, &newinput); rv = roster->Connect(output.source, input.destination, &format,
&newoutput, &newinput);
if (rv == B_OK) if (rv == B_OK)
break; break;
} }
@@ -656,13 +702,14 @@ finish:
return rv; return rv;
} }
void void
DefaultManager::Dump() DefaultManager::Dump()
{ {
} }
void void
DefaultManager::CleanupTeam(team_id team) DefaultManager::CleanupTeam(team_id team)
{ {
} }