BMediaNode: Improve readability

* Style fixes.
* Remove pervasive comments.
* Cleanup.
This commit is contained in:
Dario Casalinuovo
2015-07-11 15:36:00 +02:00
parent 1f5588ed21
commit 2e60efdafe
+263 -287
View File
@@ -27,21 +27,24 @@
* THE SOFTWARE. * THE SOFTWARE.
* *
*/ */
//#define DEBUG 7
#include <MediaRoster.h>
#include <MediaNode.h>
#include <TimeSource.h>
#include <BufferConsumer.h> #include <BufferConsumer.h>
#include <BufferProducer.h> #include <BufferProducer.h>
#include <Controllable.h> #include <Controllable.h>
#include <FileInterface.h> #include <FileInterface.h>
#include <MediaRoster.h>
#include <MediaNode.h>
#include <TimeSource.h>
#include <string.h> #include <string.h>
#include "DataExchange.h"
#include "debug.h" #include "debug.h"
#include "MediaMisc.h" #include "MediaMisc.h"
#include "MediaRosterEx.h" #include "MediaRosterEx.h"
#include "DataExchange.h"
#include "ServerInterface.h"
#include "Notifications.h" #include "Notifications.h"
#include "ServerInterface.h"
#include "TimeSourceObject.h" #include "TimeSourceObject.h"
#include "TimeSourceObjectManager.h" #include "TimeSourceObjectManager.h"
@@ -56,93 +59,75 @@ using std::nothrow_t;
#define TRACE(x...) #define TRACE(x...)
#endif #endif
// Don't rename this one, it's used and exported for binary compatibility
// don't rename this one, it's used and exported for binary compatibility
int32 BMediaNode::_m_changeTag = 0; int32 BMediaNode::_m_changeTag = 0;
/************************************************************* // media_node
* media_node
*************************************************************/ media_node media_node::null;
// final & verified
media_node::media_node() media_node::media_node()
: node(-1), :
node(-1),
port(-1), port(-1),
kind(0) kind(0)
{ {
} }
// final & verified
media_node::~media_node() media_node::~media_node()
{ {
} }
/************************************************************* // media_input
* static media_node variables
*************************************************************/
// final & verified
media_node media_node::null;
/*************************************************************
* media_input
*************************************************************/
// final
media_input::media_input() media_input::media_input()
{ {
name[0] = '\0'; name[0] = '\0';
} }
// final
media_input::~media_input() media_input::~media_input()
{ {
} }
/************************************************************* // media_output
* media_output
*************************************************************/
// final
media_output::media_output() media_output::media_output()
{ {
name[0] = '\0'; name[0] = '\0';
} }
// final
media_output::~media_output() media_output::~media_output()
{ {
} }
/************************************************************* // live_node_info
* live_node_info
*************************************************************/
// final & verified
live_node_info::live_node_info() live_node_info::live_node_info()
: hint_point(0.0f, 0.0f) :
hint_point(0.0f, 0.0f)
{ {
name[0] = '\0'; name[0] = '\0';
} }
// final & verified
live_node_info::~live_node_info() live_node_info::~live_node_info()
{ {
} }
/************************************************************* // BMediaNode
* protected BMediaNode
*************************************************************/
/* virtual */
BMediaNode::~BMediaNode() BMediaNode::~BMediaNode()
{ {
CALLED(); CALLED();
// BeBook: UnregisterNode() unregisters a node from the Media Server. It's called automatically // BeBook: UnregisterNode() unregisters a node from the Media Server.
// BeBook: by the BMediaNode destructor, but it might be convenient to call it sometime before // It's called automatically by the BMediaNode destructor, but it might
// BeBook: you delete your node instance, depending on your implementation and circumstances. // be convenient to call it sometime before you delete your node instance,
// depending on your implementation and circumstances.
// first we remove the time source // First we remove the time source
if (fTimeSource) { if (fTimeSource) {
fTimeSource->RemoveMe(this); fTimeSource->RemoveMe(this);
fTimeSource->Release(); fTimeSource->Release();
@@ -151,17 +136,13 @@ BMediaNode::~BMediaNode()
// Attention! We do not delete their control ports, since they are only a // Attention! We do not delete their control ports, since they are only a
// shadow object, and the real one still exists // shadow object, and the real one still exists
if (0 == (fKinds & NODE_KIND_SHADOW_TIMESOURCE)) { if ((fKinds & NODE_KIND_SHADOW_TIMESOURCE) == 0) {
if (fControlPort > 0) if (fControlPort > 0)
delete_port(fControlPort); delete_port(fControlPort);
} else { } else
TRACE("BMediaNode::~BMediaNode: shadow timesource, not unregistering\n"); TRACE("BMediaNode::~BMediaNode: shadow timesource, not unregistering\n");
} }
}
/*************************************************************
* public BMediaNode
*************************************************************/
BMediaNode* BMediaNode*
BMediaNode::Acquire() BMediaNode::Acquire()
@@ -219,7 +200,9 @@ BMediaNode::Node() const
CALLED(); CALLED();
media_node temp; media_node temp;
temp.node = ID(); temp.node = ID();
temp.port = ControlPort(); // we *must* call ControlPort(), some derived nodes use it to start the port read thread! // We *must* call ControlPort(), some derived nodes
// use it to start the port read thread!
temp.port = ControlPort();
temp.kind = Kinds(); temp.kind = Kinds();
return temp; return temp;
} }
@@ -238,7 +221,7 @@ BMediaNode::TimeSource() const
{ {
PRINT(7, "CALLED BMediaNode::TimeSource()\n"); PRINT(7, "CALLED BMediaNode::TimeSource()\n");
// return the currently assigned time source // Return the currently assigned time source
if (fTimeSource != 0) if (fTimeSource != 0)
return fTimeSource; return fTimeSource;
@@ -250,11 +233,9 @@ BMediaNode::TimeSource() const
// can use GetSystemTimeSource // can use GetSystemTimeSource
BMediaNode* self = const_cast<BMediaNode*>(this); BMediaNode* self = const_cast<BMediaNode*>(this);
// if (fTimeSourceID == NODE_SYSTEM_TIMESOURCE_ID) { self->fTimeSource = MediaRosterEx(
// self->fTimeSource = _TimeSourceObjectManager->GetSystemTimeSource(); BMediaRoster::Roster())->MakeTimeSourceObject(fTimeSourceID);
// } else {
self->fTimeSource = MediaRosterEx(BMediaRoster::Roster())->MakeTimeSourceObject(fTimeSourceID);
// }
ASSERT(fTimeSource == self->fTimeSource); ASSERT(fTimeSource == self->fTimeSource);
if (fTimeSource == 0) { if (fTimeSource == 0) {
@@ -270,7 +251,7 @@ BMediaNode::TimeSource() const
} }
/* virtual */ port_id port_id
BMediaNode::ControlPort() const BMediaNode::ControlPort() const
{ {
PRINT(7, "CALLED BMediaNode::ControlPort()\n"); PRINT(7, "CALLED BMediaNode::ControlPort()\n");
@@ -278,17 +259,12 @@ BMediaNode::ControlPort() const
} }
/*************************************************************
* protected BMediaNode
*************************************************************/
status_t status_t
BMediaNode::ReportError(node_error what, BMediaNode::ReportError(node_error what, const BMessage* info)
const BMessage *info)
{ {
CALLED(); CALLED();
// sanity check the what value // Sanity check the what value
switch (what) { switch (what) {
case BMediaNode::B_NODE_FAILED_START: case BMediaNode::B_NODE_FAILED_START:
case BMediaNode::B_NODE_FAILED_STOP: case BMediaNode::B_NODE_FAILED_STOP:
@@ -314,15 +290,15 @@ status_t
BMediaNode::NodeStopped(bigtime_t whenPerformance) BMediaNode::NodeStopped(bigtime_t whenPerformance)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
// called by derived classes when they have // Called by derived classes when they have
// finished handling a stop request. // finished handling a stop request.
// notify anyone who is listening for stop notifications! // Notify anyone who is listening for stop notifications!
BPrivate::media::notifications::NodeStopped(Node(), whenPerformance); BPrivate::media::notifications::NodeStopped(Node(), whenPerformance);
// XXX If your node is a BBufferProducer, downstream consumers // NOTE: If your node is a BBufferProducer, downstream consumers
// XXX will be notified that your node stopped (automatically, no less) // will be notified that your node stopped (automatically, no less) through
// XXX through the BBufferConsumer::ProducerDataStatus(B_PRODUCER_STOPPED) call. // the BBufferConsumer::ProducerDataStatus(B_PRODUCER_STOPPED) call.
return B_OK; return B_OK;
} }
@@ -334,9 +310,7 @@ BMediaNode::NodeStopped(bigtime_t whenPerformance)
* value. * value.
*/ */
void void
BMediaNode::TimerExpired(bigtime_t notifyPoint, BMediaNode::TimerExpired(bigtime_t notifyPoint, int32 cookie, status_t error)
int32 cookie,
status_t error)
{ {
CALLED(); CALLED();
if (write_port((port_id)cookie, 0, &error, sizeof(error)) < 0) { if (write_port((port_id)cookie, 0, &error, sizeof(error)) < 0) {
@@ -346,7 +320,6 @@ BMediaNode::TimerExpired(bigtime_t notifyPoint,
} }
/* explicit */
BMediaNode::BMediaNode(const char* name) BMediaNode::BMediaNode(const char* name)
{ {
TRACE("BMediaNode::BMediaNode: name '%s'\n", name); TRACE("BMediaNode::BMediaNode: name '%s'\n", name);
@@ -355,8 +328,7 @@ BMediaNode::BMediaNode(const char *name)
status_t status_t
BMediaNode::WaitForMessage(bigtime_t waitUntil, BMediaNode::WaitForMessage(bigtime_t waitUntil, uint32 flags,
uint32 flags,
void* _reserved_) void* _reserved_)
{ {
TRACE("entering: BMediaNode::WaitForMessage()\n"); TRACE("entering: BMediaNode::WaitForMessage()\n");
@@ -364,8 +336,8 @@ BMediaNode::WaitForMessage(bigtime_t waitUntil,
// This function waits until either real time specified by // This function waits until either real time specified by
// waitUntil or a message is received on the control port. // waitUntil or a message is received on the control port.
// The flags are currently unused and should be 0. // The flags are currently unused and should be 0.
// Note: about 16 KByte stack used
char data[B_MEDIA_MESSAGE_SIZE]; // about 16 KByte stack used char data[B_MEDIA_MESSAGE_SIZE];
int32 message; int32 message;
ssize_t size; ssize_t size;
while (true) { while (true) {
@@ -390,10 +362,12 @@ BMediaNode::WaitForMessage(bigtime_t waitUntil,
TRACE("BMediaNode::WaitForMessage request is: %#lx, node %ld, this %p\n", TRACE("BMediaNode::WaitForMessage request is: %#lx, node %ld, this %p\n",
message, fNodeID, this); message, fNodeID, this);
if (message == GENERAL_PURPOSE_WAKEUP) return B_OK; // no action needed if (message == GENERAL_PURPOSE_WAKEUP)
return B_OK;
if (message > NODE_MESSAGE_START && message < NODE_MESSAGE_END) { if (message > NODE_MESSAGE_START && message < NODE_MESSAGE_END) {
TRACE("BMediaNode::WaitForMessage calling BMediaNode\n"); TRACE("BMediaNode::WaitForMessage calling BMediaNode\n");
if (B_OK == BMediaNode::HandleMessage(message, data, size)) if (B_OK == BMediaNode::HandleMessage(message, data, size))
return B_OK; return B_OK;
} }
@@ -401,8 +375,10 @@ BMediaNode::WaitForMessage(bigtime_t waitUntil,
if (message > PRODUCER_MESSAGE_START && message < PRODUCER_MESSAGE_END) { if (message > PRODUCER_MESSAGE_START && message < PRODUCER_MESSAGE_END) {
if (!fProducerThis) if (!fProducerThis)
fProducerThis = dynamic_cast<BBufferProducer*>(this); fProducerThis = dynamic_cast<BBufferProducer*>(this);
TRACE("BMediaNode::WaitForMessage calling BBufferProducer %p\n", TRACE("BMediaNode::WaitForMessage calling BBufferProducer %p\n",
fProducerThis); fProducerThis);
if (fProducerThis && fProducerThis->BBufferProducer::HandleMessage( if (fProducerThis && fProducerThis->BBufferProducer::HandleMessage(
message, data, size) == B_OK) { message, data, size) == B_OK) {
return B_OK; return B_OK;
@@ -412,8 +388,10 @@ BMediaNode::WaitForMessage(bigtime_t waitUntil,
if (message > CONSUMER_MESSAGE_START && message < CONSUMER_MESSAGE_END) { if (message > CONSUMER_MESSAGE_START && message < CONSUMER_MESSAGE_END) {
if (!fConsumerThis) if (!fConsumerThis)
fConsumerThis = dynamic_cast<BBufferConsumer*>(this); fConsumerThis = dynamic_cast<BBufferConsumer*>(this);
TRACE("BMediaNode::WaitForMessage calling BBufferConsumer %p\n", TRACE("BMediaNode::WaitForMessage calling BBufferConsumer %p\n",
fConsumerThis); fConsumerThis);
if (fConsumerThis && fConsumerThis->BBufferConsumer::HandleMessage( if (fConsumerThis && fConsumerThis->BBufferConsumer::HandleMessage(
message, data, size) == B_OK) { message, data, size) == B_OK) {
return B_OK; return B_OK;
@@ -424,8 +402,10 @@ BMediaNode::WaitForMessage(bigtime_t waitUntil,
&& message < FILEINTERFACE_MESSAGE_END) { && message < FILEINTERFACE_MESSAGE_END) {
if (!fFileInterfaceThis) if (!fFileInterfaceThis)
fFileInterfaceThis = dynamic_cast<BFileInterface*>(this); fFileInterfaceThis = dynamic_cast<BFileInterface*>(this);
TRACE("BMediaNode::WaitForMessage calling BFileInterface %p\n", TRACE("BMediaNode::WaitForMessage calling BFileInterface %p\n",
fFileInterfaceThis); fFileInterfaceThis);
if (fFileInterfaceThis if (fFileInterfaceThis
&& fFileInterfaceThis->BFileInterface::HandleMessage( && fFileInterfaceThis->BFileInterface::HandleMessage(
message, data, size) == B_OK) { message, data, size) == B_OK) {
@@ -437,8 +417,10 @@ BMediaNode::WaitForMessage(bigtime_t waitUntil,
&& message < CONTROLLABLE_MESSAGE_END) { && message < CONTROLLABLE_MESSAGE_END) {
if (!fControllableThis) if (!fControllableThis)
fControllableThis = dynamic_cast<BControllable*>(this); fControllableThis = dynamic_cast<BControllable*>(this);
TRACE("BMediaNode::WaitForMessage calling BControllable %p\n", TRACE("BMediaNode::WaitForMessage calling BControllable %p\n",
fControllableThis); fControllableThis);
if (fControllableThis if (fControllableThis
&& fControllableThis->BControllable::HandleMessage( && fControllableThis->BControllable::HandleMessage(
message, data, size) == B_OK) { message, data, size) == B_OK) {
@@ -450,8 +432,10 @@ BMediaNode::WaitForMessage(bigtime_t waitUntil,
&& message < TIMESOURCE_MESSAGE_END) { && message < TIMESOURCE_MESSAGE_END) {
if (!fTimeSourceThis) if (!fTimeSourceThis)
fTimeSourceThis = dynamic_cast<BTimeSource*>(this); fTimeSourceThis = dynamic_cast<BTimeSource*>(this);
TRACE("BMediaNode::WaitForMessage calling BTimeSource %p\n", TRACE("BMediaNode::WaitForMessage calling BTimeSource %p\n",
fTimeSourceThis); fTimeSourceThis);
if (fTimeSourceThis && fTimeSourceThis->BTimeSource::HandleMessage( if (fTimeSourceThis && fTimeSourceThis->BTimeSource::HandleMessage(
message, data, size) == B_OK) { message, data, size) == B_OK) {
return B_OK; return B_OK;
@@ -459,7 +443,7 @@ BMediaNode::WaitForMessage(bigtime_t waitUntil,
} }
TRACE("BMediaNode::WaitForMessage calling default HandleMessage\n"); TRACE("BMediaNode::WaitForMessage calling default HandleMessage\n");
if (B_OK == HandleMessage(message, data, size)) if (HandleMessage(message, data, size) == B_OK)
return B_OK; return B_OK;
HandleBadMessage(message, data, size); HandleBadMessage(message, data, size);
@@ -468,7 +452,7 @@ BMediaNode::WaitForMessage(bigtime_t waitUntil,
} }
/* virtual */ void void
BMediaNode::Start(bigtime_t performance_time) BMediaNode::Start(bigtime_t performance_time)
{ {
CALLED(); CALLED();
@@ -482,9 +466,8 @@ BMediaNode::Start(bigtime_t performance_time)
} }
/* virtual */ void void
BMediaNode::Stop(bigtime_t performance_time, BMediaNode::Stop(bigtime_t performance_time, bool immediate)
bool immediate)
{ {
CALLED(); CALLED();
// This hook function is called when a node is stopped // This hook function is called when a node is stopped
@@ -497,9 +480,8 @@ BMediaNode::Stop(bigtime_t performance_time,
} }
/* virtual */ void void
BMediaNode::Seek(bigtime_t media_time, BMediaNode::Seek(bigtime_t media_time, bigtime_t performance_time)
bigtime_t performance_time)
{ {
CALLED(); CALLED();
// This hook function is called when a node is asked // This hook function is called when a node is asked
@@ -513,31 +495,30 @@ BMediaNode::Seek(bigtime_t media_time,
} }
/* virtual */ void void
BMediaNode::SetRunMode(run_mode mode) BMediaNode::SetRunMode(run_mode mode)
{ {
CALLED(); CALLED();
// this is a hook function, and // This is a hook function, and
// may be overriden by derived classes. // may be overriden by derived classes.
// the functionality here is only to // The functionality here is only to
// support those people that don't // support those people that don't
// use the roster to set the run mode // use the roster to set the run mode
fRunMode = mode; fRunMode = mode;
} }
/* virtual */ void void
BMediaNode::TimeWarp(bigtime_t at_real_time, BMediaNode::TimeWarp(bigtime_t at_real_time, bigtime_t to_performance_time)
bigtime_t to_performance_time)
{ {
CALLED(); CALLED();
// May be overriden by derived classes. // May be overriden by derived classes.
} }
/* virtual */ void void
BMediaNode::Preroll() BMediaNode::Preroll()
{ {
CALLED(); CALLED();
@@ -545,34 +526,32 @@ BMediaNode::Preroll()
} }
/* virtual */ void void
BMediaNode::SetTimeSource(BTimeSource* time_source) BMediaNode::SetTimeSource(BTimeSource* time_source)
{ {
CALLED(); CALLED();
// this is a hook function, and // This is a hook function, and
// may be overriden by derived classes. // may be overriden by derived classes.
if (time_source == NULL || time_source == fTimeSource) if (time_source == NULL || time_source == fTimeSource)
return; return;
// we just trip into debugger, code that tries to do this is broken. // We just trip into debugger, code that tries to do this is broken.
debugger("BMediaNode::SetTimeSource() can't be used to set a timesource, use BMediaRoster::SetTimeSourceFor()!\n"); debugger("BMediaNode::SetTimeSource() can't be used to set a timesource, "
"use BMediaRoster::SetTimeSourceFor()!\n");
} }
/*************************************************************
* public BMediaNode
*************************************************************/
/* virtual */ status_t status_t
BMediaNode::HandleMessage(int32 message, BMediaNode::HandleMessage(int32 message, const void* data, size_t size)
const void *data,
size_t size)
{ {
TRACE("BMediaNode::HandleMessage %#lx, node %ld\n", message, fNodeID); TRACE("BMediaNode::HandleMessage %#lx, node %ld\n", message, fNodeID);
switch (message) { switch (message) {
case NODE_FINAL_RELEASE: case NODE_FINAL_RELEASE:
{ {
// const node_final_release_command *command = static_cast<const node_final_release_command *>(data); TRACE("BMediaNode::HandleMessage NODE_FINAL_RELEASE, this %p\n",
this);
// This is called by the media server to delete the object // This is called by the media server to delete the object
// after is has been released by all nodes that are using it. // after is has been released by all nodes that are using it.
// We forward the function to the BMediaRoster, since the // We forward the function to the BMediaRoster, since the
@@ -580,18 +559,16 @@ BMediaNode::HandleMessage(int32 message,
// outermost destructor that will exit the thread that is // outermost destructor that will exit the thread that is
// reading messages from the port (this thread contex) will // reading messages from the port (this thread contex) will
// quit, and ~BMediaNode destructor won't be called ever. // quit, and ~BMediaNode destructor won't be called ever.
TRACE("BMediaNode::HandleMessage NODE_FINAL_RELEASE, this %p\n", this);
BMessage msg(NODE_FINAL_RELEASE); BMessage msg(NODE_FINAL_RELEASE);
msg.AddPointer("node", this); msg.AddPointer("node", this);
BMediaRoster::Roster()->PostMessage(&msg); BMediaRoster::Roster()->PostMessage(&msg);
return B_OK; return B_OK;
} }
case NODE_START: case NODE_START:
{ {
const node_start_command *command = static_cast<const node_start_command *>(data); const node_start_command* command
= static_cast<const node_start_command*>(data);
TRACE("BMediaNode::HandleMessage NODE_START, node %ld\n", fNodeID); TRACE("BMediaNode::HandleMessage NODE_START, node %ld\n", fNodeID);
Start(command->performance_time); Start(command->performance_time);
return B_OK; return B_OK;
@@ -599,7 +576,8 @@ BMediaNode::HandleMessage(int32 message,
case NODE_STOP: case NODE_STOP:
{ {
const node_stop_command *command = static_cast<const node_stop_command *>(data); const node_stop_command* command
= static_cast<const node_stop_command*>(data);
TRACE("BMediaNode::HandleMessage NODE_STOP, node %ld\n", fNodeID); TRACE("BMediaNode::HandleMessage NODE_STOP, node %ld\n", fNodeID);
Stop(command->performance_time, command->immediate); Stop(command->performance_time, command->immediate);
return B_OK; return B_OK;
@@ -607,7 +585,8 @@ BMediaNode::HandleMessage(int32 message,
case NODE_SEEK: case NODE_SEEK:
{ {
const node_seek_command *command = static_cast<const node_seek_command *>(data); const node_seek_command* command
= static_cast<const node_seek_command*>(data);
TRACE("BMediaNode::HandleMessage NODE_SEEK, node %ld\n", fNodeID); TRACE("BMediaNode::HandleMessage NODE_SEEK, node %ld\n", fNodeID);
Seek(command->media_time, command->performance_time); Seek(command->media_time, command->performance_time);
return B_OK; return B_OK;
@@ -615,9 +594,11 @@ BMediaNode::HandleMessage(int32 message,
case NODE_SET_RUN_MODE: case NODE_SET_RUN_MODE:
{ {
const node_set_run_mode_command *command = static_cast<const node_set_run_mode_command *>(data); const node_set_run_mode_command* command
TRACE("BMediaNode::HandleMessage NODE_SET_RUN_MODE, node %ld\n", fNodeID); = static_cast<const node_set_run_mode_command*>(data);
// when changing this, also change PRODUCER_SET_RUN_MODE_DELAY TRACE("BMediaNode::HandleMessage NODE_SET_RUN_MODE,"
" node %ld\n", fNodeID);
// Need to change PRODUCER_SET_RUN_MODE_DELAY
fRunMode = command->mode; fRunMode = command->mode;
SetRunMode(fRunMode); SetRunMode(fRunMode);
return B_OK; return B_OK;
@@ -625,15 +606,18 @@ BMediaNode::HandleMessage(int32 message,
case NODE_TIME_WARP: case NODE_TIME_WARP:
{ {
const node_time_warp_command *command = static_cast<const node_time_warp_command *>(data); const node_time_warp_command* command
TRACE("BMediaNode::HandleMessage NODE_TIME_WARP, node %ld\n", fNodeID); = static_cast<const node_time_warp_command*>(data);
TRACE("BMediaNode::HandleMessage NODE_TIME_WARP,"
" node %ld\n", fNodeID);
TimeWarp(command->at_real_time, command->to_performance_time); TimeWarp(command->at_real_time, command->to_performance_time);
return B_OK; return B_OK;
} }
case NODE_PREROLL: case NODE_PREROLL:
{ {
TRACE("BMediaNode::HandleMessage NODE_PREROLL, node %ld\n", fNodeID); TRACE("BMediaNode::HandleMessage NODE_PREROLL, "
" node %ld\n", fNodeID);
Preroll(); Preroll();
return B_OK; return B_OK;
} }
@@ -677,37 +661,44 @@ BMediaNode::HandleMessage(int32 message,
case NODE_SET_TIMESOURCE: case NODE_SET_TIMESOURCE:
{ {
const node_set_timesource_command *command = static_cast<const node_set_timesource_command *>(data); const node_set_timesource_command* command
= static_cast<const node_set_timesource_command*>(data);
TRACE("BMediaNode::HandleMessage NODE_SET_TIMESOURCE, node %ld, timesource %ld enter\n", fNodeID, command->timesource_id); TRACE("BMediaNode::HandleMessage NODE_SET_TIMESOURCE,"
" node %ld, timesource %ld enter\n",
fNodeID, command->timesource_id);
fTimeSourceID = command->timesource_id; fTimeSourceID = command->timesource_id;
if (fTimeSource) { if (fTimeSource) {
// as this node already had a timesource, we need // As this node already had a timesource, to remove this node
// we need to remove this node from time source control // from time source control
fTimeSource->RemoveMe(this); fTimeSource->RemoveMe(this);
// Then release the time source // Release the time source
fTimeSource->Release(); fTimeSource->Release();
// force next call to TimeSource() to create a new object // Force next call to TimeSource() to create a new object
fTimeSource = 0; fTimeSource = 0;
} }
// create new time source object // Create new time source object and call the SetTimeSource
// hook function to notify any derived class
fTimeSource = TimeSource(); fTimeSource = TimeSource();
// and call the SetTimeSource hook function to notify
// any derived class
SetTimeSource(fTimeSource); SetTimeSource(fTimeSource);
TRACE("BMediaNode::HandleMessage NODE_SET_TIMESOURCE, node %ld, timesource %ld leave\n", fNodeID, command->timesource_id); TRACE("BMediaNode::HandleMessage NODE_SET_TIMESOURCE, node %ld,"
"timesource %ld leave\n", fNodeID, command->timesource_id);
return B_OK; return B_OK;
} }
case NODE_GET_TIMESOURCE: case NODE_GET_TIMESOURCE:
{ {
const node_get_timesource_request *request = static_cast<const node_get_timesource_request *>(data); const node_get_timesource_request* request
TRACE("BMediaNode::HandleMessage NODE_GET_TIMESOURCE, node %ld\n", fNodeID); = static_cast<const node_get_timesource_request*>(data);
TRACE("BMediaNode::HandleMessage NODE_GET_TIMESOURCE,"
" node %ld\n", fNodeID);
node_get_timesource_reply reply; node_get_timesource_reply reply;
reply.timesource_id = fTimeSourceID; reply.timesource_id = fTimeSourceID;
request->SendReply(B_OK, &reply, sizeof(reply)); request->SendReply(B_OK, &reply, sizeof(reply));
@@ -716,32 +707,35 @@ BMediaNode::HandleMessage(int32 message,
case NODE_REQUEST_COMPLETED: case NODE_REQUEST_COMPLETED:
{ {
const node_request_completed_command *command = static_cast<const node_request_completed_command *>(data); const node_request_completed_command* command
TRACE("BMediaNode::HandleMessage NODE_REQUEST_COMPLETED, node %ld\n", fNodeID); = static_cast<const node_request_completed_command*>(data);
TRACE("BMediaNode::HandleMessage NODE_REQUEST_COMPLETED,"
" node %ld\n", fNodeID);
RequestCompleted(command->info); RequestCompleted(command->info);
return B_OK; return B_OK;
} }
}; default:
return B_ERROR;
}
return B_ERROR; return B_ERROR;
} }
void void
BMediaNode::HandleBadMessage(int32 code, BMediaNode::HandleBadMessage(int32 code, const void* buffer, size_t size)
const void *buffer,
size_t size)
{ {
CALLED(); CALLED();
TRACE("BMediaNode::HandleBadMessage: code %#08lx, buffer %p, size %ld\n", code, buffer, size); TRACE("BMediaNode::HandleBadMessage: code %#08lx, buffer %p, size %ld\n",
code, buffer, size);
if (code < NODE_MESSAGE_START || code > TIMESOURCE_MESSAGE_END) { if (code < NODE_MESSAGE_START || code > TIMESOURCE_MESSAGE_END) {
ERROR("BMediaNode::HandleBadMessage: unknown code!\n"); ERROR("BMediaNode::HandleBadMessage: unknown code!\n");
} else { } else {
/* All messages targeted to nodes should be handled here, // All messages targeted to nodes should be handled here,
* messages targetted to the wrong node should be handled // messages targetted to the wrong node should be handled
* by returning an error, not by stalling the sender. // by returning an error, not by stalling the sender.
*/
const request_data* request = static_cast<const request_data* >(buffer); const request_data* request = static_cast<const request_data* >(buffer);
reply_data reply; reply_data reply;
request->SendReply(B_ERROR, &reply, sizeof(reply)); request->SendReply(B_ERROR, &reply, sizeof(reply));
@@ -753,7 +747,6 @@ void
BMediaNode::AddNodeKind(uint64 kind) BMediaNode::AddNodeKind(uint64 kind)
{ {
TRACE("BMediaNode::AddNodeKind: node %ld, this %p\n", fNodeID, this); TRACE("BMediaNode::AddNodeKind: node %ld, this %p\n", fNodeID, this);
fKinds |= kind; fKinds |= kind;
} }
@@ -765,14 +758,15 @@ BMediaNode::operator new(size_t size)
return ::operator new(size); return ::operator new(size);
} }
void* void*
BMediaNode::operator new(size_t size, BMediaNode::operator new(size_t size, const nothrow_t&) throw()
const nothrow_t &) throw()
{ {
CALLED(); CALLED();
return ::operator new(size, nothrow); return ::operator new(size, nothrow);
} }
void void
BMediaNode::operator delete(void* ptr) BMediaNode::operator delete(void* ptr)
{ {
@@ -780,19 +774,16 @@ BMediaNode::operator delete(void *ptr)
::operator delete(ptr); ::operator delete(ptr);
} }
void void
BMediaNode::operator delete(void * ptr, BMediaNode::operator delete(void* ptr, const nothrow_t&) throw()
const nothrow_t &) throw()
{ {
CALLED(); CALLED();
::operator delete(ptr, nothrow); ::operator delete(ptr, nothrow);
} }
/*************************************************************
* protected BMediaNode
*************************************************************/
/* virtual */ status_t status_t
BMediaNode::RequestCompleted(const media_request_info& info) BMediaNode::RequestCompleted(const media_request_info& info)
{ {
CALLED(); CALLED();
@@ -807,9 +798,127 @@ BMediaNode::RequestCompleted(const media_request_info &info)
return B_OK; return B_OK;
} }
/*************************************************************
* private BMediaNode status_t
*************************************************************/ BMediaNode::DeleteHook(BMediaNode* node)
{
CALLED();
// Attention! We do not unregister TimeSourceObject nodes,
// since they are only a shadow object, and the real one still exists
if ((fKinds & NODE_KIND_SHADOW_TIMESOURCE) == 0)
BMediaRoster::Roster()->UnregisterNode(this);
delete this; // delete "this" or "node", both are the same
return B_OK;
}
void
BMediaNode::NodeRegistered()
{
CALLED();
// The Media Server calls this hook function after the node has been registered.
// May be overriden by derived classes.
}
status_t
BMediaNode::GetNodeAttributes(media_node_attribute* outAttributes,
size_t inMaxCount)
{
UNIMPLEMENTED();
return B_ERROR;
}
status_t
BMediaNode::AddTimer(bigtime_t at_performance_time, int32 cookie)
{
CALLED();
return B_ERROR;
}
status_t BMediaNode::_Reserved_MediaNode_0(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_1(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_2(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_3(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_4(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_5(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_6(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_7(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_8(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_9(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_10(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_11(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_12(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_13(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_14(void*) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_15(void*) { return B_ERROR; }
/*
private unimplemented
BMediaNode::BMediaNode()
BMediaNode::BMediaNode(const BMediaNode &clone)
BMediaNode &BMediaNode::operator=(const BMediaNode &clone)
*/
void
BMediaNode::_InitObject(const char* name, media_node_id id, uint64 kinds)
{
TRACE("BMediaNode::_InitObject: nodeid %ld, this %p\n", id, this);
fNodeID = id;
fRefCount = 1;
fName[0] = 0;
if (name)
strlcpy(fName, name, B_MEDIA_NAME_LENGTH);
fRunMode = B_INCREASE_LATENCY;
fKinds = kinds;
fProducerThis = 0;
fConsumerThis = 0;
fFileInterfaceThis = 0;
fControllableThis = 0;
fTimeSourceThis = 0;
// Create control port
fControlPort = create_port(64, fName);
// Nodes are assigned the system time source by default
fTimeSourceID = NODE_SYSTEM_TIMESOURCE_ID;
// We can't create the timesource object here, because
// every timesource is a BMediaNode, which would result
// in infinite recursions
fTimeSource = NULL;
}
BMediaNode::BMediaNode(const char* name, media_node_id id, uint32 kinds)
{
TRACE("BMediaNode::BMediaNode: name '%s', nodeid %ld, kinds %#lx\n",
name, id, kinds);
_InitObject(name, id, kinds);
}
int32
BMediaNode::NewChangeTag()
{
CALLED();
// Change tags have been used in BeOS R4 to match up
// format change requests between producer and consumer,
// This has changed starting with R4.5
// now "change tags" are used with the following functions:
// BMediaNode::RequestCompleted()
// BBufferConsumer::RequestFormatChange()
// BBufferConsumer::SetOutputBuffersFor()
// BBufferConsumer::SetOutputEnabled()
// BBufferConsumer::SetVideoClippingFor()
return atomic_add(&BMediaNode::_m_changeTag,1);
}
// BeOS R4 deprecated API
int32 int32
BMediaNode::IncrementChangeTag() BMediaNode::IncrementChangeTag()
@@ -860,136 +969,3 @@ BMediaNode::ApplyChangeTag(int32 previously_reserved)
// not supported, only for binary compatibility // not supported, only for binary compatibility
return B_OK; return B_OK;
} }
/*************************************************************
* protected BMediaNode
*************************************************************/
/* virtual */ status_t
BMediaNode::DeleteHook(BMediaNode *node)
{
CALLED();
// Attention! We do not unregister TimeSourceObject nodes,
// since they are only a shadow object, and the real one still exists
if ((fKinds & NODE_KIND_SHADOW_TIMESOURCE) == 0)
BMediaRoster::Roster()->UnregisterNode(this);
delete this; // delete "this" or "node", both are the same
return B_OK;
}
/* virtual */ void
BMediaNode::NodeRegistered()
{
CALLED();
// The Media Server calls this hook function after the node has been registered.
// May be overriden by derived classes.
}
/*************************************************************
* public BMediaNode
*************************************************************/
/* virtual */ status_t
BMediaNode::GetNodeAttributes(media_node_attribute *outAttributes,
size_t inMaxCount)
{
UNIMPLEMENTED();
return B_ERROR;
}
/* virtual */ status_t
BMediaNode::AddTimer(bigtime_t at_performance_time,
int32 cookie)
{
CALLED();
return B_ERROR;
}
status_t BMediaNode::_Reserved_MediaNode_0(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_1(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_2(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_3(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_4(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_5(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_6(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_7(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_8(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_9(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_10(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_11(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_12(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_13(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_14(void *) { return B_ERROR; }
status_t BMediaNode::_Reserved_MediaNode_15(void *) { return B_ERROR; }
/*
private unimplemented
BMediaNode::BMediaNode()
BMediaNode::BMediaNode(const BMediaNode &clone)
BMediaNode &BMediaNode::operator=(const BMediaNode &clone)
*/
void
BMediaNode::_InitObject(const char *name, media_node_id id, uint64 kinds)
{
TRACE("BMediaNode::_InitObject: nodeid %ld, this %p\n", id, this);
fNodeID = id;
fRefCount = 1;
fName[0] = 0;
if (name)
strlcpy(fName, name, B_MEDIA_NAME_LENGTH);
fRunMode = B_INCREASE_LATENCY;
fKinds = kinds;
fProducerThis = 0;
fConsumerThis = 0;
fFileInterfaceThis = 0;
fControllableThis = 0;
fTimeSourceThis = 0;
// create control port
fControlPort = create_port(64, fName);
// nodes are assigned the system time source by default
fTimeSourceID = NODE_SYSTEM_TIMESOURCE_ID;
// We can't create the timesource object here, because
// every timesource is a BMediaNode, which would result
// in infinite recursions
fTimeSource = NULL;
}
BMediaNode::BMediaNode(const char *name,
media_node_id id,
uint32 kinds)
{
TRACE("BMediaNode::BMediaNode: name '%s', nodeid %ld, kinds %#lx\n", name, id, kinds);
_InitObject(name, id, kinds);
}
/*************************************************************
* protected BMediaNode
*************************************************************/
/* static */ int32
BMediaNode::NewChangeTag()
{
CALLED();
// change tags have been used in BeOS R4 to match up
// format change requests between producer and consumer,
// This has changed starting with R4.5
// now "change tags" are used with
// BMediaNode::RequestCompleted()
// and
// BBufferConsumer::RequestFormatChange()
// BBufferConsumer::SetOutputBuffersFor()
// BBufferConsumer::SetOutputEnabled()
// BBufferConsumer::SetVideoClippingFor()
return atomic_add(&BMediaNode::_m_changeTag,1);
}