more time source function...

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2353 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper
2003-01-03 01:51:22 +00:00
parent 50808915da
commit 287f7492c3
13 changed files with 243 additions and 85 deletions
+5 -1
View File
@@ -111,6 +111,9 @@ struct media_node_attribute
}; };
namespace BPrivate { namespace media { class TimeSourceObject; } }
class BMediaNode class BMediaNode
{ {
protected: protected:
@@ -252,6 +255,7 @@ private:
friend class _BMediaRosterP; friend class _BMediaRosterP;
friend class MNodeManager; friend class MNodeManager;
friend class BBufferProducer; // for getting _mNodeID friend class BBufferProducer; // for getting _mNodeID
friend class BPrivate::media::TimeSourceObject;
// Deprecated in 4.1 // Deprecated in 4.1
int32 IncrementChangeTag(); int32 IncrementChangeTag();
@@ -318,7 +322,7 @@ virtual status_t _Reserved_MediaNode_15(void *);
int32 _mChangeCount; // deprecated int32 _mChangeCount; // deprecated
int32 _mChangeCountReserved; // deprecated int32 _mChangeCountReserved; // deprecated
uint64 fKinds; uint64 fKinds;
media_node_id fTimeSourceID; media_node_id _unused;
BBufferProducer * fProducerThis; BBufferProducer * fProducerThis;
BBufferConsumer * fConsumerThis; BBufferConsumer * fConsumerThis;
-1
View File
@@ -23,7 +23,6 @@ struct command_data;
// BMessage based data exchange with the media_server // BMessage based data exchange with the media_server
status_t SendToServer(BMessage *msg); status_t SendToServer(BMessage *msg);
//status_t QueryServer(BMessage *request, BMessage *reply);
// Raw data based data exchange with the media_server // Raw data based data exchange with the media_server
status_t SendToServer(int32 msgcode, command_data *msg, int size); status_t SendToServer(int32 msgcode, command_data *msg, int size);
-17
View File
@@ -1,17 +0,0 @@
#ifndef _VOLUME_CONTROL_
#define _VOLUME_CONTROL_
/***********************************************************************
* AUTHOR: Marcus Overhagen
* FILE: VolumeControl.h
* DESCR: transitional private volume control functions
***********************************************************************/
namespace MediaKitPrivate {
status_t GetMasterVolume(float *left, float *right);
status_t SetMasterVolume(float left, float right);
} //namespace MediaKitPrivate
#endif
+57 -16
View File
@@ -24,14 +24,17 @@ BMessenger *MediaServerMessenger;
static port_id MediaServerPort; static port_id MediaServerPort;
static port_id MediaAddonServerPort; static port_id MediaAddonServerPort;
void find_media_server_port();
void find_media_addon_server_port();
class initit class initit
{ {
public: public:
initit() initit()
{ {
MediaServerMessenger = new BMessenger(NEW_MEDIA_SERVER_SIGNATURE); MediaServerMessenger = new BMessenger(NEW_MEDIA_SERVER_SIGNATURE);
MediaServerPort = find_port("media_server port"); find_media_server_port();
MediaAddonServerPort = find_port("media_addon_server port"); find_media_addon_server_port();
thread_info info; thread_info info;
get_thread_info(find_thread(NULL), &info); get_thread_info(find_thread(NULL), &info);
@@ -45,6 +48,25 @@ public:
initit _initit; initit _initit;
void find_media_server_port()
{
MediaServerPort = find_port("media_server port");
if (MediaServerPort < 0) {
FATAL("couldn't find MediaServerPort\n");
MediaServerPort = -666; // make this a unique number
}
}
void find_media_addon_server_port()
{
MediaAddonServerPort = find_port("media_addon_server port");
if (MediaAddonServerPort < 0) {
FATAL("couldn't find MediaAddonServerPort\n");
MediaAddonServerPort = -555; // make this a unique number
}
}
status_t status_t
request_data::SendReply(status_t result, reply_data *reply, int replysize) const request_data::SendReply(status_t result, reply_data *reply, int replysize) const
{ {
@@ -64,17 +86,6 @@ status_t SendToServer(BMessage *msg)
return rv; return rv;
} }
/*
status_t QueryServer(BMessage *request, BMessage *reply)
{
status_t rv;
rv = MediaServerMessenger->SendMessage(request, reply, TIMEOUT, TIMEOUT);
if (rv != B_OK)
FATAL("QueryServer: SendMessage failed\n");
return rv;
}
*/
// Raw data based data exchange with the media_server // Raw data based data exchange with the media_server
status_t SendToServer(int32 msgcode, command_data *msg, int size) status_t SendToServer(int32 msgcode, command_data *msg, int size)
{ {
@@ -105,8 +116,23 @@ status_t SendToPort(port_id sendport, int32 msgcode, command_data *msg, int size
{ {
status_t rv; status_t rv;
rv = write_port_etc(sendport, msgcode, msg, size, B_RELATIVE_TIMEOUT, TIMEOUT); rv = write_port_etc(sendport, msgcode, msg, size, B_RELATIVE_TIMEOUT, TIMEOUT);
if (rv != B_OK) if (rv != B_OK) {
FATAL("SendToPort: write_port failed, port %ld, error %#lx (%s)\n", sendport, rv, strerror(rv)); FATAL("SendToPort: write_port failed, port %ld, error %#lx (%s)\n", sendport, rv, strerror(rv));
if (sendport == MediaServerPort) {
find_media_server_port();
sendport = MediaServerPort;
} else if (sendport == MediaAddonServerPort) {
find_media_addon_server_port();
sendport = MediaAddonServerPort;
} else {
return rv;
}
rv = write_port_etc(sendport, msgcode, msg, size, B_RELATIVE_TIMEOUT, TIMEOUT);
if (rv != B_OK) {
FATAL("SendToPort: retrying write_port failed, port %ld, error %#lx (%s)\n", sendport, rv, strerror(rv));
return rv;
}
}
return B_OK; return B_OK;
} }
@@ -119,10 +145,25 @@ status_t QueryPort(port_id requestport, int32 msgcode, request_data *request, in
request->reply_port = _PortPool->GetPort(); request->reply_port = _PortPool->GetPort();
rv = write_port_etc(requestport, msgcode, request, requestsize, B_RELATIVE_TIMEOUT, TIMEOUT); rv = write_port_etc(requestport, msgcode, request, requestsize, B_RELATIVE_TIMEOUT, TIMEOUT);
if (rv != B_OK) { if (rv != B_OK) {
FATAL("QueryPort: write_port failed, port %ld, error %#lx (%s)\n", requestport, rv, strerror(rv)); FATAL("QueryPort: write_port failed, port %ld, error %#lx (%s)\n", requestport, rv, strerror(rv));
_PortPool->PutPort(request->reply_port); if (requestport == MediaServerPort) {
return rv; find_media_server_port();
requestport = MediaServerPort;
} else if (requestport == MediaAddonServerPort) {
find_media_addon_server_port();
requestport = MediaAddonServerPort;
} else {
_PortPool->PutPort(request->reply_port);
return rv;
}
rv = write_port_etc(requestport, msgcode, request, requestsize, B_RELATIVE_TIMEOUT, TIMEOUT);
if (rv != B_OK) {
FATAL("QueryPort: retrying write_port failed, port %ld, error %#lx (%s)\n", requestport, rv, strerror(rv));
_PortPool->PutPort(request->reply_port);
return rv;
}
} }
rv = read_port_etc(request->reply_port, &code, reply, replysize, B_RELATIVE_TIMEOUT, TIMEOUT); rv = read_port_etc(request->reply_port, &code, reply, replysize, B_RELATIVE_TIMEOUT, TIMEOUT);
+4 -3
View File
@@ -42,20 +42,21 @@ SharedLibrary media :
TimeSource.cpp TimeSource.cpp
# Internal Functionality # Internal Functionality
BufferIdCache.cpp
DataExchange.cpp DataExchange.cpp
PortPool.cpp
DormantNodeManager.cpp DormantNodeManager.cpp
Notifications.cpp Notifications.cpp
PortPool.cpp
SystemTimeSource.cpp SystemTimeSource.cpp
BufferIdCache.cpp
SharedBufferList.cpp SharedBufferList.cpp
TrackReader.cpp TrackReader.cpp
TimedEventQueuePrivate.cpp TimedEventQueuePrivate.cpp
TimeSourceObject.cpp
TimeSourceObjectManager.cpp
SoundPlayNode.cpp SoundPlayNode.cpp
ChannelMixer.cpp ChannelMixer.cpp
SampleConverter.cpp SampleConverter.cpp
SamplingrateConverter.cpp SamplingrateConverter.cpp
VolumeControl.cpp
# Old (R3) Media Kit # Old (R3) Media Kit
OldAudioModule.cpp OldAudioModule.cpp
+58 -15
View File
@@ -186,8 +186,27 @@ BTimeSource *
BMediaNode::TimeSource() const BMediaNode::TimeSource() const
{ {
CALLED(); CALLED();
if (fTimeSource == 0) if (fTimeSource != 0)
const_cast<BMediaNode *>(this)->fTimeSource = new _SysTimeSource; return fTimeSource;
BMediaNode *self = const_cast<BMediaNode *>(this);
BMediaRoster *roster = BMediaRoster::Roster();
status_t rv;
media_node clone;
rv = roster->GetSystemTimeSource(&clone);
if (rv != B_OK) {
FATAL("BMediaNode::TimeSource: Error, GetSystemTimeSource failed\n");
return NULL;
}
self->fTimeSource = roster->MakeTimeSourceFor(clone);
if (fTimeSource == 0) {
FATAL("BMediaNode::TimeSource: Error, MakeTimeSourceFor failed\n");
}
rv = roster->ReleaseNode(clone);
if (fTimeSource == 0) {
FATAL("BMediaNode::TimeSource: Error, ReleaseNode failed\n");
}
return fTimeSource; return fTimeSource;
} }
@@ -432,22 +451,28 @@ BMediaNode::Preroll()
BMediaNode::SetTimeSource(BTimeSource *time_source) BMediaNode::SetTimeSource(BTimeSource *time_source)
{ {
CALLED(); CALLED();
return;// XXX
// 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 a time source // use the roster to set a time source
if (time_source == fTimeSource) if (time_source == NULL || time_source == fTimeSource)
return; return;
if (time_source == NULL) FATAL("BMediaNode::SetTimeSource used to set a time source for this node\n");
// some stupid code to do a stupid thing that should not be done
BMediaNode *newnode = time_source->Acquire();
BTimeSource *newsource = dynamic_cast<BTimeSource *>(newnode);
if (newsource == NULL) {
FATAL("BMediaNode::SetTimeSource can't dynamic_cast into timesource\n");
newnode->Release();
return; return;
}
if (fTimeSource) if (fTimeSource)
fTimeSource->Release(); fTimeSource->Release();
fTimeSource = dynamic_cast<BTimeSource *>(time_source->Acquire()); fTimeSource = newsource;
fTimeSourceID = fTimeSource->ID();
} }
/************************************************************* /*************************************************************
@@ -505,15 +530,33 @@ BMediaNode::HandleMessage(int32 message,
case NODE_SET_TIMESOURCE: case NODE_SET_TIMESOURCE:
{ {
printf("NODE_SET_TIMESOURCE enter\n");
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);
bool first = (fTimeSourceID == 0); BMediaRoster *roster;
if (fTimeSource) BTimeSource *newsource;
media_node clone;
status_t rv;
roster = BMediaRoster::Roster();
rv = roster->GetNodeFor(command->timesource_id, &clone);
if (rv != B_OK) {
FATAL("NODE_SET_TIMESOURCE: Error, GetNodeFor failed\n");
return B_OK;
}
newsource = roster->MakeTimeSourceFor(clone);
if (newsource == 0) {
FATAL("NODE_SET_TIMESOURCE: Error, MakeTimeSourceFor failed\n");
roster->ReleaseNode(clone);
return B_OK;
}
roster->ReleaseNode(clone);
if (fTimeSource) {
fTimeSource->Release(); fTimeSource->Release();
fTimeSourceID = command->timesource_id; fTimeSource = newsource;
fTimeSource = 0; // XXX create timesource object here
fTimeSource = new _SysTimeSource;
if (!first)
SetTimeSource(fTimeSource); SetTimeSource(fTimeSource);
} else {
fTimeSource = newsource;
}
printf("NODE_SET_TIMESOURCE leave\n");
return B_OK; return B_OK;
} }
@@ -749,7 +792,7 @@ BMediaNode::_InitObject(const char *name, media_node_id id, uint64 kinds)
_mChangeCount = 0; // deprecated _mChangeCount = 0; // deprecated
_mChangeCountReserved = 0; // deprecated _mChangeCountReserved = 0; // deprecated
fKinds = kinds; fKinds = kinds;
fTimeSourceID = -1; // fTimeSourceID = -1;
fProducerThis = 0; fProducerThis = 0;
fConsumerThis = 0; fConsumerThis = 0;
fFileInterfaceThis = 0; fFileInterfaceThis = 0;
+10 -2
View File
@@ -434,12 +434,20 @@ BMediaRoster::ReleaseNode(const media_node & node)
return QueryServer(SERVER_RELEASE_NODE, &request, sizeof(request), &reply, sizeof(reply)); return QueryServer(SERVER_RELEASE_NODE, &request, sizeof(request), &reply, sizeof(reply));
} }
BTimeSource * BTimeSource *
BMediaRoster::MakeTimeSourceFor(const media_node & for_node) BMediaRoster::MakeTimeSourceFor(const media_node & for_node)
{ {
BROKEN(); BROKEN();
return new _SysTimeSource(); // XXX fix this
printf("BMediaRoster::MakeTimeSourceFor enter, node %ld, port %ld, kind %#lx\n", for_node.node, for_node.port, for_node.kind);
static BTimeSource *source = 0;
if (source == 0)
source = new _SysTimeSource();
printf("BMediaRoster::MakeTimeSourceFor leave, node %ld, port %ld, kind %#lx\n", source->Node().node, source->Node().port, source->Node().kind);
return dynamic_cast<BTimeSource *>(source->Acquire());
} }
+5 -2
View File
@@ -8,13 +8,16 @@
// XXX This works only as long a BTimeSource is only supporting realtime // XXX This works only as long a BTimeSource is only supporting realtime
#include <OS.h> #include <OS.h>
//#include <MediaRoster.h> #include <stdio.h>
#include <MediaRoster.h>
#include "SystemTimeSource.h" #include "SystemTimeSource.h"
_SysTimeSource::_SysTimeSource() : _SysTimeSource::_SysTimeSource() :
BMediaNode("system time source") BMediaNode("system time source")
{ {
// BMediaRoster::Roster()->RegisterNode(this); // XXX printf("_SysTimeSource::_SysTimeSource enter\n");
BMediaRoster::Roster()->RegisterNode(this); // XXX
printf("_SysTimeSource::_SysTimeSource leave\n");
} }
/* virtual */ status_t /* virtual */ status_t
+45
View File
@@ -0,0 +1,45 @@
/***********************************************************************
* Copyright (c) 2002 Marcus Overhagen. All Rights Reserved.
* This file may be used under the terms of the OpenBeOS License.
*
* The object returned by BMediaRoster's
* BTimeSource * MakeTimeSourceFor(const media_node & for_node);
*
***********************************************************************/
#include <OS.h>
#include <stdio.h>
#include <MediaRoster.h>
#include "TimeSourceObject.h"
TimeSourceObject::TimeSourceObject(const media_node &node) :
BMediaNode("some timesource object")
{
printf("TimeSourceObject::TimeSourceObject enter\n");
delete_port(fControlPort);
fControlPort = -666;
printf("TimeSourceObject::TimeSourceObject leave\n");
}
/* virtual */ status_t
TimeSourceObject::SnoozeUntil(
bigtime_t performance_time,
bigtime_t with_latency,
bool retry_signals)
{
return B_ERROR;
}
/* virtual */ status_t
TimeSourceObject::TimeSourceOp(
const time_source_op_info & op,
void * _reserved)
{
return B_OK;
}
/* virtual */ BMediaAddOn*
TimeSourceObject::AddOn(int32 * internal_id) const
{
return NULL;
}
+37
View File
@@ -0,0 +1,37 @@
/***********************************************************************
* Copyright (c) 2002 Marcus Overhagen. All Rights Reserved.
* This file may be used under the terms of the OpenBeOS License.
*
* The object returned by BMediaRoster's
* BTimeSource * MakeTimeSourceFor(const media_node & for_node);
*
***********************************************************************/
#ifndef _TIME_SOURCE_OBJECT_H_
#define _TIME_SOURCE_OBJECT_H_
#include <TimeSource.h>
namespace BPrivate { namespace media {
class TimeSourceObject : public BTimeSource
{
public:
TimeSourceObject(const media_node &node);
virtual status_t SnoozeUntil(
bigtime_t performance_time,
bigtime_t with_latency = 0,
bool retry_signals = false);
protected:
virtual status_t TimeSourceOp(
const time_source_op_info & op,
void * _reserved);
virtual BMediaAddOn* AddOn(
int32 * internal_id) const;
};
} } using namespace BPrivate::media;
#endif
@@ -0,0 +1,11 @@
/***********************************************************************
* Copyright (c) 2002 Marcus Overhagen. All Rights Reserved.
* This file may be used under the terms of the MIT License.
*
***********************************************************************/
#include <OS.h>
#include <stdio.h>
#include <MediaRoster.h>
#include "TimeSourceObjectManager.h"
+9
View File
@@ -0,0 +1,9 @@
/***********************************************************************
* Copyright (c) 2002 Marcus Overhagen. All Rights Reserved.
* This file may be used under the terms of the MIT License.
*
***********************************************************************/
#ifndef _TIME_SOURCE_OBJECT_MANAGER_H_
#define _TIME_SOURCE_OBJECT_MANAGER_H_
#endif
-26
View File
@@ -1,26 +0,0 @@
/***********************************************************************
* AUTHOR: Marcus Overhagen
* FILE: VolumeControl.cpp
* DESCR: transitional private volume control functions
***********************************************************************/
#include <Message.h>
#include <Messenger.h>
#include "debug.h"
#include "VolumeControl.h"
#include "ServerInterface.h"
namespace MediaKitPrivate {
status_t GetMasterVolume(float *left, float *right)
{
return B_OK;
}
status_t SetMasterVolume(float left, float right)
{
return B_OK;
}
} //namespace MediaKitPrivate