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
{
protected:
@@ -252,6 +255,7 @@ private:
friend class _BMediaRosterP;
friend class MNodeManager;
friend class BBufferProducer; // for getting _mNodeID
friend class BPrivate::media::TimeSourceObject;
// Deprecated in 4.1
int32 IncrementChangeTag();
@@ -318,7 +322,7 @@ virtual status_t _Reserved_MediaNode_15(void *);
int32 _mChangeCount; // deprecated
int32 _mChangeCountReserved; // deprecated
uint64 fKinds;
media_node_id fTimeSourceID;
media_node_id _unused;
BBufferProducer * fProducerThis;
BBufferConsumer * fConsumerThis;
-1
View File
@@ -23,7 +23,6 @@ struct command_data;
// BMessage based data exchange with the media_server
status_t SendToServer(BMessage *msg);
//status_t QueryServer(BMessage *request, BMessage *reply);
// Raw data based data exchange with the media_server
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
+58 -17
View File
@@ -24,15 +24,18 @@ BMessenger *MediaServerMessenger;
static port_id MediaServerPort;
static port_id MediaAddonServerPort;
void find_media_server_port();
void find_media_addon_server_port();
class initit
{
public:
initit()
{
MediaServerMessenger = new BMessenger(NEW_MEDIA_SERVER_SIGNATURE);
MediaServerPort = find_port("media_server port");
MediaAddonServerPort = find_port("media_addon_server port");
find_media_server_port();
find_media_addon_server_port();
thread_info info;
get_thread_info(find_thread(NULL), &info);
team = info.team;
@@ -45,6 +48,25 @@ public:
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
request_data::SendReply(status_t result, reply_data *reply, int replysize) const
{
@@ -64,17 +86,6 @@ status_t SendToServer(BMessage *msg)
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
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;
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));
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;
}
@@ -119,10 +145,25 @@ status_t QueryPort(port_id requestport, int32 msgcode, request_data *request, in
request->reply_port = _PortPool->GetPort();
rv = write_port_etc(requestport, msgcode, request, requestsize, B_RELATIVE_TIMEOUT, TIMEOUT);
if (rv != B_OK) {
FATAL("QueryPort: write_port failed, port %ld, error %#lx (%s)\n", requestport, rv, strerror(rv));
_PortPool->PutPort(request->reply_port);
return rv;
if (requestport == MediaServerPort) {
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);
+4 -3
View File
@@ -42,20 +42,21 @@ SharedLibrary media :
TimeSource.cpp
# Internal Functionality
BufferIdCache.cpp
DataExchange.cpp
PortPool.cpp
DormantNodeManager.cpp
Notifications.cpp
PortPool.cpp
SystemTimeSource.cpp
BufferIdCache.cpp
SharedBufferList.cpp
TrackReader.cpp
TimedEventQueuePrivate.cpp
TimeSourceObject.cpp
TimeSourceObjectManager.cpp
SoundPlayNode.cpp
ChannelMixer.cpp
SampleConverter.cpp
SamplingrateConverter.cpp
VolumeControl.cpp
# Old (R3) Media Kit
OldAudioModule.cpp
+59 -16
View File
@@ -186,8 +186,27 @@ BTimeSource *
BMediaNode::TimeSource() const
{
CALLED();
if (fTimeSource == 0)
const_cast<BMediaNode *>(this)->fTimeSource = new _SysTimeSource;
if (fTimeSource != 0)
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;
}
@@ -432,22 +451,28 @@ BMediaNode::Preroll()
BMediaNode::SetTimeSource(BTimeSource *time_source)
{
CALLED();
return;// XXX
// this is a hook function, and
// may be overriden by derived classes.
// the functionality here is only to
// support those people that don't
// use the roster to set a time source
if (time_source == fTimeSource)
if (time_source == NULL || time_source == fTimeSource)
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;
}
if (fTimeSource)
fTimeSource->Release();
fTimeSource = dynamic_cast<BTimeSource *>(time_source->Acquire());
fTimeSourceID = fTimeSource->ID();
fTimeSource = newsource;
}
/*************************************************************
@@ -505,15 +530,33 @@ BMediaNode::HandleMessage(int32 message,
case NODE_SET_TIMESOURCE:
{
printf("NODE_SET_TIMESOURCE enter\n");
const node_set_timesource_command *command = static_cast<const node_set_timesource_command *>(data);
bool first = (fTimeSourceID == 0);
if (fTimeSource)
BMediaRoster *roster;
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();
fTimeSourceID = command->timesource_id;
fTimeSource = 0; // XXX create timesource object here
fTimeSource = new _SysTimeSource;
if (!first)
fTimeSource = newsource;
SetTimeSource(fTimeSource);
} else {
fTimeSource = newsource;
}
printf("NODE_SET_TIMESOURCE leave\n");
return B_OK;
}
@@ -749,7 +792,7 @@ BMediaNode::_InitObject(const char *name, media_node_id id, uint64 kinds)
_mChangeCount = 0; // deprecated
_mChangeCountReserved = 0; // deprecated
fKinds = kinds;
fTimeSourceID = -1;
// fTimeSourceID = -1;
fProducerThis = 0;
fConsumerThis = 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));
}
BTimeSource *
BMediaRoster::MakeTimeSourceFor(const media_node & for_node)
{
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
#include <OS.h>
//#include <MediaRoster.h>
#include <stdio.h>
#include <MediaRoster.h>
#include "SystemTimeSource.h"
_SysTimeSource::_SysTimeSource() :
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
+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