Sorry for this large commit in advance; it's not really possible to divide this

into smaller parts:

media_addon_server:
* Removed (broken) use of (broken and inefficient) home-brewn Map, and List
  classes. This also fixes a crash on shutdown when used with the malloc_debug
  implementation. It's using stl::vector, and stl::map now instead.

_shared_buffer_list:
* Renamed _shared_buffer_list to SharedBufferList, and put it into the BPrivate
  namespace. Also, made a class out of it.
* Separated shared buffer list creation from cloning.
* Enlarged maximum number of buffers to something that is not that evil, but
  actually uses the space it has (ie. is a useful multiple of
  shared_buffer_info that fills a multiple of B_PAGE_SIZE as much as possible).
* No longer drops into the debugger if the
* The list that is currently used is very inefficient for the features it
  provides though (no change there).

_buffer_id_cache:
* Renamed to BufferCache, and put it into the private namespace
* It now deletes its buffers on deletion; since the BBufferConsumer will be
  gone, too, at this point, there is little chance that there are still buffers
  in use.
* Also, it's now using std::map instead of the (see above) Map class.

BBuffer:
* Got rid of the fBufferID member.

Misc.:
* Got rid of the global "team" variable; the media kit is now using the
  private app kit's current_team() now.
* Added a lot of missing error checks (mostly memory allocations).
* Renamed fields like "flavorid" to flavor_id, renamed "dfi_*" fields to
  something more detailed.
* Moved ServerInterface.h from src/servers/media/ to headers/private/media.
* Notifications.h was not self contained.
* Added missing licenses.
* Lots of cleanups, and coding style fixes.

What this doesn't fix:
* Bug #4954 which started all this (this comes next, though)
* Deinitialization is broken, as the PortPool is uninitialized too early, and
  still used afterwards.
* The strange add-on monitoring code in the media_addon_server


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34500 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-12-05 11:11:28 +00:00
parent 04c71a2f1d
commit 9dec231042
31 changed files with 1767 additions and 1548 deletions
+8 -6
View File
@@ -9,7 +9,10 @@
#include <MediaDefs.h> #include <MediaDefs.h>
struct _shared_buffer_list; namespace BPrivate {
class BufferCache;
class SharedBufferList;
}
struct buffer_clone_info { struct buffer_clone_info {
@@ -54,8 +57,8 @@ public:
size_t Size(); size_t Size();
private: private:
friend struct _buffer_id_cache; friend class BPrivate::BufferCache;
friend struct _shared_buffer_list; friend class BPrivate::SharedBufferList;
friend class BMediaRoster; friend class BMediaRoster;
friend class BBufferProducer; friend class BBufferProducer;
friend class BBufferConsumer; friend class BBufferConsumer;
@@ -73,15 +76,14 @@ private:
void SetHeader(const media_header* header); void SetHeader(const media_header* header);
media_header fMediaHeader; media_header fMediaHeader;
_shared_buffer_list* fBufferList; BPrivate::SharedBufferList* fBufferList;
area_id fArea; area_id fArea;
void* fData; void* fData;
size_t fOffset; size_t fOffset;
size_t fSize; size_t fSize;
media_buffer_id fBufferID;
int32 fFlags; int32 fFlags;
uint32 _reserved[11]; uint32 _reserved[12];
}; };
+2 -2
View File
@@ -13,9 +13,9 @@
class BBuffer; class BBuffer;
class BBufferGroup; class BBufferGroup;
class BRegion; class BRegion;
class _buffer_id_cache;
namespace BPrivate { namespace BPrivate {
class BufferCache;
namespace media { namespace media {
class BMediaRosterEx; class BMediaRosterEx;
} }
@@ -147,7 +147,7 @@ private:
private: private:
media_type fConsumerType; media_type fConsumerType;
_buffer_id_cache* fBufferCache; BPrivate::BufferCache* fBufferCache;
BBufferGroup* fDeleteBufferGroup; BBufferGroup* fDeleteBufferGroup;
uint32 _reserved[14]; uint32 _reserved[14];
}; };
+5 -3
View File
@@ -10,7 +10,9 @@
class BBuffer; class BBuffer;
struct _shared_buffer_list; namespace BPrivate {
struct SharedBufferList;
}
class BBufferGroup { class BBufferGroup {
@@ -53,12 +55,12 @@ private:
status_t _Init(); status_t _Init();
private: private:
friend struct _shared_buffer_list; friend struct BPrivate::SharedBufferList;
status_t fInitError; status_t fInitError;
status_t fRequestError; status_t fRequestError;
int32 fBufferCount; int32 fBufferCount;
_shared_buffer_list* fBufferList; BPrivate::SharedBufferList* fBufferList;
sem_id fReclaimSem; sem_id fReclaimSem;
uint32 _reserved[9]; uint32 _reserved[9];
+15 -15
View File
@@ -286,8 +286,8 @@ enum {
}; };
struct addonserver_instantiate_dormant_node_request : request_data { struct addonserver_instantiate_dormant_node_request : request_data {
media_addon_id addonid; media_addon_id addon_id;
int32 flavorid; int32 flavor_id;
team_id creator_team; team_id creator_team;
}; };
@@ -605,8 +605,8 @@ struct server_set_node_creator_reply : reply_data {
}; };
struct server_change_addon_flavor_instances_count_request : request_data { struct server_change_addon_flavor_instances_count_request : request_data {
media_addon_id addonid; media_addon_id addon_id;
int32 flavorid; int32 flavor_id;
int32 delta; // must be +1 or -1 int32 delta; // must be +1 or -1
team_id team; team_id team;
}; };
@@ -624,17 +624,17 @@ struct server_register_node_request : request_data {
}; };
struct server_register_node_reply : reply_data { struct server_register_node_reply : reply_data {
media_node_id nodeid; media_node_id node_id;
}; };
struct server_unregister_node_request : request_data { struct server_unregister_node_request : request_data {
media_node_id nodeid; media_node_id node_id;
team_id team; team_id team;
}; };
struct server_unregister_node_reply : reply_data { struct server_unregister_node_reply : reply_data {
media_addon_id addonid; media_addon_id addon_id;
int32 flavorid; int32 flavor_id;
}; };
struct server_get_live_node_info_request : request_data { struct server_get_live_node_info_request : request_data {
@@ -669,11 +669,11 @@ struct server_node_id_for_request : request_data {
}; };
struct server_node_id_for_reply : reply_data { struct server_node_id_for_reply : reply_data {
media_node_id nodeid; media_node_id node_id;
}; };
struct server_get_node_for_request : request_data { struct server_get_node_for_request : request_data {
media_node_id nodeid; media_node_id node_id;
team_id team; team_id team;
}; };
@@ -713,7 +713,7 @@ struct server_rescan_defaults_command : command_data {
}; };
struct addonserver_rescan_mediaaddon_flavors_command : command_data { struct addonserver_rescan_mediaaddon_flavors_command : command_data {
media_addon_id addonid; media_addon_id addon_id;
}; };
struct addonserver_rescan_finished_notify_command : command_data { struct addonserver_rescan_finished_notify_command : command_data {
@@ -724,15 +724,15 @@ struct server_register_mediaaddon_request : request_data {
}; };
struct server_register_mediaaddon_reply : reply_data { struct server_register_mediaaddon_reply : reply_data {
media_addon_id addonid; media_addon_id addon_id;
}; };
struct server_unregister_mediaaddon_command : command_data { struct server_unregister_mediaaddon_command : command_data {
media_addon_id addonid; media_addon_id addon_id;
}; };
struct server_get_mediaaddon_ref_request : request_data { struct server_get_mediaaddon_ref_request : request_data {
media_addon_id addonid; media_addon_id addon_id;
}; };
struct server_get_mediaaddon_ref_reply : reply_data { struct server_get_mediaaddon_ref_reply : reply_data {
@@ -757,7 +757,7 @@ struct server_register_buffer_reply : reply_data {
struct server_unregister_buffer_command : command_data { struct server_unregister_buffer_command : command_data {
team_id team; team_id team;
media_buffer_id bufferid; media_buffer_id buffer_id;
}; };
struct server_rewindtypes_request : request_data { struct server_rewindtypes_request : request_data {
+13 -10
View File
@@ -1,11 +1,14 @@
/* /*
* Copyright 2002, Marcus Overhagen. All rights reserved. * Copyright 2002, Marcus Overhagen. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _NOTIFICATIONS_H #ifndef _NOTIFICATIONS_H
#define _NOTIFICATIONS_H #define _NOTIFICATIONS_H
#include <MediaNode.h>
namespace BPrivate { namespace BPrivate {
namespace media { namespace media {
namespace notifications { namespace notifications {
@@ -15,7 +18,7 @@ namespace notifications {
* The notifications marked with "N" are only send when the * The notifications marked with "N" are only send when the
* media_node specific BMediaRoster::StartWatching() is used * media_node specific BMediaRoster::StartWatching() is used
* and the notification belongs to the watched node. * and the notification belongs to the watched node.
* *
* In addition, anyone watching a specific node will also receive * In addition, anyone watching a specific node will also receive
* error notifications generated by BMediaNode::ReportError() * error notifications generated by BMediaNode::ReportError()
* *
@@ -35,13 +38,13 @@ namespace notifications {
* B_MEDIA_NODE_STOPPED N "node", "when" * B_MEDIA_NODE_STOPPED N "node", "when"
* B_MEDIA_FLAVORS_CHANGED "be:addon_id", "be:new_count", "be:gone_count" * B_MEDIA_FLAVORS_CHANGED "be:addon_id", "be:new_count", "be:gone_count"
*/ */
// used for BMediaRoster::StartWatching() parameter validation // used for BMediaRoster::StartWatching() parameter validation
bool IsValidNotificationRequest(bool node_specific, int32 notification); bool IsValidNotificationRequest(bool node_specific, int32 notification);
// called by BMediaRoster::StartWatching() // called by BMediaRoster::StartWatching()
status_t Register(const BMessenger &notifyHandler, const media_node &node, int32 notification); status_t Register(const BMessenger &notifyHandler, const media_node &node, int32 notification);
// called by BMediaRoster::StopWatching() // called by BMediaRoster::StopWatching()
status_t Unregister(const BMessenger &notifyHandler, const media_node &node, int32 notification); status_t Unregister(const BMessenger &notifyHandler, const media_node &node, int32 notification);
@@ -54,20 +57,20 @@ namespace notifications {
void ConnectionBroken(const media_source &source, const media_destination &destination); void ConnectionBroken(const media_source &source, const media_destination &destination);
void BuffersCreated(area_info *areas, int32 count); void BuffersCreated(area_info *areas, int32 count);
void BuffersDeleted(const media_buffer_id *ids, int32 count); void BuffersDeleted(const media_buffer_id *ids, int32 count);
// called by BMediaNode::NodeStopped() // called by BMediaNode::NodeStopped()
void NodeStopped(const media_node &node, bigtime_t when); void NodeStopped(const media_node &node, bigtime_t when);
// called by BControllable::BroadcastChangedParameter() // called by BControllable::BroadcastChangedParameter()
status_t ParameterChanged(const media_node &node, int32 parameterid); status_t ParameterChanged(const media_node &node, int32 parameterid);
// called by BControllable::SetParameterWeb() // called by BControllable::SetParameterWeb()
void WebChanged(const media_node &node); void WebChanged(const media_node &node);
// called by BControllable::BroadcastNewParameterValue() // called by BControllable::BroadcastNewParameterValue()
status_t NewParameterValue(const media_node &node, int32 parameterid, bigtime_t when, const void *param, size_t paramsize); status_t NewParameterValue(const media_node &node, int32 parameterid, bigtime_t when, const void *param, size_t paramsize);
// called by the media_addon_server AFTER a flavor change has been // called by the media_addon_server AFTER a flavor change has been
// handled. NOT CALLED by BMediaAddOn::NotifyFlavorChange() // handled. NOT CALLED by BMediaAddOn::NotifyFlavorChange()
void FlavorsChanged(media_addon_id addonid, int32 newcount, int32 gonecount); void FlavorsChanged(media_addon_id addonid, int32 newcount, int32 gonecount);
+10 -12
View File
@@ -1,30 +1,28 @@
/*********************************************************************** /*
* Copyright (c) 2002 Marcus Overhagen. All Rights Reserved. * Copyright 2002, Marcus Overhagen. All Rights Reserved.
* This file may be used under the terms of the OpenBeOS License. * Distributed under the terms of the MIT License.
* */
* A pool of kernel ports
***********************************************************************/
#ifndef _POOL_PORT_H_ #ifndef _POOL_PORT_H_
#define _POOL_PORT_H_ #define _POOL_PORT_H_
class PortPool
{ class PortPool {
public: public:
PortPool(); PortPool();
~PortPool(); ~PortPool();
port_id GetPort(); port_id GetPort();
void PutPort(port_id port); void PutPort(port_id port);
private: private:
void Lock(); void Lock();
void Unlock(); void Unlock();
struct PortInfo struct PortInfo {
{
port_id port; port_id port;
bool used; bool used;
}; };
PortInfo * pool; PortInfo * pool;
int count; int count;
int maxcount; int maxcount;
+72
View File
@@ -0,0 +1,72 @@
/*
* Copyright 2002, Marcus Overhagen. All Rights Reserved.
* Copyright 2009, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _SERVER_INTERFACE_H_
#define _SERVER_INTERFACE_H_
#include <Entry.h>
#include <MediaDefs.h>
#include <MediaNode.h>
#include <MediaAddOn.h>
enum {
ADDONSERVER_INSTANTIATE_DORMANT_NODE,
SERVER_REGISTER_MEDIAADDON,
SERVER_UNREGISTER_MEDIAADDON,
SERVER_GET_MEDIAADDON_REF,
SERVER_REGISTER_DORMANT_NODE,
SERVER_GET_DORMANT_NODES,
SERVER_GET_DORMANT_FLAVOR_INFO,
END
};
struct xfer_server_get_dormant_flavor_info {
media_addon_id addon;
int32 flavor_id;
port_id reply_port;
};
struct xfer_server_get_dormant_flavor_info_reply {
status_t result;
type_code type; // the flatten type_code
size_t flattened_size;
char flattened_data[1];
// a flattened dormant_flavor_info, flattened_size large
};
struct xfer_server_get_dormant_nodes {
int32 max_count;
bool has_input;
media_format input_format;
bool has_output;
media_format output_format;
bool has_name;
char name[B_MEDIA_NAME_LENGTH + 1]; // 1 for a trailing "*"
uint64 require_kinds;
uint64 deny_kinds;
port_id reply_port;
};
struct xfer_server_get_dormant_nodes_reply {
status_t result;
int32 count;
// if count > 0, a second reply containing count dormant_node_infos
// is send
};
struct xfer_server_register_dormant_node {
media_addon_id purge_id;
// if > 0, server must first remove all dormant_flavor_infos
// belonging to that id
type_code type; // the flatten type_code
size_t flattened_size;
char flattened_data[1];
// a flattened dormant_flavor_info, flattened_size large
};
#endif // _SERVER_INTERFACE_H_
+54 -41
View File
@@ -1,53 +1,66 @@
/*********************************************************************** /*
* Copyright (c) 2002 Marcus Overhagen. All Rights Reserved. * Copyright 2009, Axel Dörfler, [email protected].
* This file may be used under the terms of the OpenBeOS License. * Copyright 2002, Marcus Overhagen. All Rights Reserved.
* * Distributed under the terms of the MIT License.
* Used for BBufferGroup and BBuffer management across teams */
***********************************************************************/
#ifndef _SHARED_BUFFER_LIST_H_ #ifndef _SHARED_BUFFER_LIST_H_
#define _SHARED_BUFFER_LIST_H_ #define _SHARED_BUFFER_LIST_H_
#include <Buffer.h> #include <Buffer.h>
// created in the media server, cloned into
// each BBufferGroup (visible in all address spaces / teams) namespace BPrivate {
struct _shared_buffer_list
{
struct _shared_buffer_info class SharedBufferList {
{ public:
media_buffer_id id; static area_id Create(SharedBufferList** _list);
BBuffer * buffer; static SharedBufferList* Get(area_id area);
bool reclaimed;
// the reclaim_sem belonging to the BBufferGroup of this BBuffer void Put();
// also used as a unique identifier of the group void DeleteGroupAndPut(sem_id groupReclaimSem);
sem_id reclaim_sem;
status_t Lock();
status_t Unlock();
status_t AddBuffer(sem_id groupReclaimSem,
BBuffer* buffer);
status_t RequestBuffer(sem_id groupReclaimSem,
int32 buffersInGroup, size_t size,
media_buffer_id wantID, BBuffer** _buffer,
bigtime_t timeout);
status_t RecycleBuffer(BBuffer* buffer);
status_t GetBufferList(sem_id groupReclaimSem,
int32 bufferCount, BBuffer** buffers);
private:
struct _shared_buffer_info {
media_buffer_id id;
BBuffer* buffer;
bool reclaimed;
// The reclaim_sem belonging to the BBufferGroup of this BBuffer
// is also used as a unique identifier of the group
sem_id reclaim_sem;
}; };
enum { MAX_BUFFER = 666 }; // this fixed limit is probably very evil
sem_id locker_sem; enum { kMaxBuffers = 2047 };
int32 locker_atom; // 16 bytes per buffer, 8 pages in total (one entry less for the list)
// always only the first "buffercount" entries in the "info" array are used
int32 buffercount;
_shared_buffer_info info[MAX_BUFFER];
status_t AddBuffer(sem_id group_reclaim_sem, BBuffer *buffer); status_t _Init();
status_t RequestBuffer(sem_id group_reclaim_sem, int32 buffers_in_group, size_t size, media_buffer_id wantID, BBuffer **buffer, bigtime_t timeout); void _RequestBufferInOtherGroups(
status_t GetBufferList(sem_id group_reclaim_sem, int32 buf_count, BBuffer **out_buffers); sem_id groupReclaimSem, media_buffer_id id);
status_t RecycleBuffer(BBuffer *buffer);
status_t Init();
static _shared_buffer_list *Clone(area_id id = -1); private:
void Terminate(sem_id group_reclaim_sem); sem_id fSemaphore;
void Unmap(); vint32 fAtom;
status_t Lock(); _shared_buffer_info fInfos[kMaxBuffers];
status_t Unlock(); int32 fCount;
// used by RequestBuffer, call this one with the list locked!
void RequestBufferInOtherGroups(sem_id group_reclaim_sem, media_buffer_id id);
}; };
#endif
} // namespace BPrivate
#endif // _SHARED_BUFFER_LIST_H_
+37 -36
View File
@@ -1,3 +1,8 @@
/*
* Copyright 2009, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*/
/* /*
* Copyright (c) 2002, 2003 Marcus Overhagen <[email protected]> * Copyright (c) 2002, 2003 Marcus Overhagen <[email protected]>
* *
@@ -24,12 +29,12 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*
*/ */
#include <Buffer.h> #include <Buffer.h>
#include <AppMisc.h>
#include <MediaDefs.h> #include <MediaDefs.h>
#include "debug.h" #include "debug.h"
@@ -37,9 +42,6 @@
#include "SharedBufferList.h" #include "SharedBufferList.h"
namespace BPrivate { namespace media {
extern team_id team;
} }
using namespace BPrivate::media; using namespace BPrivate::media;
@@ -49,11 +51,11 @@ using namespace BPrivate::media;
buffer_clone_info::buffer_clone_info() buffer_clone_info::buffer_clone_info()
{ {
CALLED(); CALLED();
buffer = 0; buffer = 0;
area = 0; area = 0;
offset = 0; offset = 0;
size = 0; size = 0;
flags = 0; flags = 0;
} }
@@ -122,11 +124,11 @@ BBuffer::CloneInfo() const
CALLED(); CALLED();
buffer_clone_info info; buffer_clone_info info;
info.buffer = fBufferID; info.buffer = fMediaHeader.buffer;
info.area = fArea; info.area = fArea;
info.offset = fOffset; info.offset = fOffset;
info.size = fSize; info.size = fSize;
info.flags = fFlags; info.flags = fFlags;
return info; return info;
} }
@@ -137,7 +139,6 @@ BBuffer::ID()
{ {
CALLED(); CALLED();
return fMediaHeader.buffer; return fMediaHeader.buffer;
//return fBufferID;
} }
@@ -181,20 +182,21 @@ BBuffer::Size()
} }
// #pragma mark - private BBuffer // #pragma mark - private BBuffer
BBuffer::BBuffer(const buffer_clone_info& info) BBuffer::BBuffer(const buffer_clone_info& info)
: :
// must all be NULL/0 if not correct initialized // must all be NULL/0 if not correctly initialized
fBufferList(NULL), fBufferList(NULL),
fData(NULL), fData(NULL),
fSize(0), fSize(0)
fBufferID(0)
// must be 0 if not registered
{ {
CALLED(); CALLED();
fMediaHeader.buffer = 0;
// must be 0 if not registered
// special case for BSmallBuffer // special case for BSmallBuffer
if (info.area == 0 && info.buffer == 0) if (info.area == 0 && info.buffer == 0)
return; return;
@@ -208,7 +210,7 @@ BBuffer::BBuffer(const buffer_clone_info& info)
return; return;
} }
fBufferList = _shared_buffer_list::Clone(areaReply.area); fBufferList = BPrivate::SharedBufferList::Get(areaReply.area);
if (fBufferList == NULL) { if (fBufferList == NULL) {
ERROR("BBuffer::BBuffer: _shared_buffer_list::Clone() failed\n"); ERROR("BBuffer::BBuffer: _shared_buffer_list::Clone() failed\n");
return; return;
@@ -217,7 +219,7 @@ BBuffer::BBuffer(const buffer_clone_info& info)
server_register_buffer_request request; server_register_buffer_request request;
server_register_buffer_reply reply; server_register_buffer_reply reply;
request.team = team; request.team = BPrivate::current_team();
request.info = info; request.info = info;
// ask media_server to register this buffer, // ask media_server to register this buffer,
@@ -241,10 +243,11 @@ BBuffer::BBuffer(const buffer_clone_info& info)
// the response from media server contains enough information // the response from media server contains enough information
// to clone the memory for this buffer // to clone the memory for this buffer
fBufferID = reply.info.buffer;
fSize = reply.info.size; fSize = reply.info.size;
fFlags = reply.info.flags; fFlags = reply.info.flags;
fOffset = reply.info.offset; fOffset = reply.info.offset;
fMediaHeader.size_used = 0;
fMediaHeader.buffer = reply.info.buffer;
fArea = clone_area("a cloned BBuffer", &fData, B_ANY_ADDRESS, fArea = clone_area("a cloned BBuffer", &fData, B_ANY_ADDRESS,
B_READ_AREA | B_WRITE_AREA, reply.info.area); B_READ_AREA | B_WRITE_AREA, reply.info.area);
@@ -256,28 +259,26 @@ BBuffer::BBuffer(const buffer_clone_info& info)
} }
fData = (char*)fData + fOffset; fData = (char*)fData + fOffset;
fMediaHeader.size_used = 0;
fMediaHeader.buffer = fBufferID;
} }
BBuffer::~BBuffer() BBuffer::~BBuffer()
{ {
CALLED(); CALLED();
// unmap the BufferList // unmap the BufferList
if (fBufferList != NULL) if (fBufferList != NULL)
fBufferList->Unmap(); fBufferList->Put();
// unmap the Data // unmap the Data
if (fData != NULL) { if (fData != NULL) {
delete_area(fArea); delete_area(fArea);
// ask media_server to unregister the buffer // Ask media_server to unregister the buffer when the last clone of
// when the last clone of this buffer is gone, // this buffer is gone, media_server will also remove its cached area.
// media_server will also remove it's cached area
server_unregister_buffer_command cmd; server_unregister_buffer_command cmd;
cmd.team = team; cmd.team = BPrivate::current_team();
cmd.bufferid = fBufferID; cmd.buffer_id = fMediaHeader.buffer;
SendToServer(SERVER_UNREGISTER_BUFFER, &cmd, sizeof(cmd)); SendToServer(SERVER_UNREGISTER_BUFFER, &cmd, sizeof(cmd));
} }
} }
@@ -287,14 +288,14 @@ void
BBuffer::SetHeader(const media_header* header) BBuffer::SetHeader(const media_header* header)
{ {
CALLED(); CALLED();
ASSERT(header->buffer == fMediaHeader.buffer);
if (header->buffer != fMediaHeader.buffer)
debugger("oops");
fMediaHeader = *header; fMediaHeader = *header;
// TODO: why can't we do this without crash? what's wrong?
// fMediaHeader.buffer = fBufferID;
} }
// #pragma mark - public BSmallBuffer // #pragma mark - public BSmallBuffer
static const buffer_clone_info sSmallBufferInfo; static const buffer_clone_info sSmallBufferInfo;
+59
View File
@@ -0,0 +1,59 @@
/*
* Copyright 2009, Axel Dörfler, [email protected].
* Copyright 2002, Marcus Overhagen. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
//! A cache for BBuffers to be received by BBufferConsumer::BufferReceived().
#include "BufferCache.h"
#include <Buffer.h>
#include "debug.h"
namespace BPrivate {
BufferCache::BufferCache()
{
}
BufferCache::~BufferCache()
{
for (BufferMap::iterator iterator = fMap.begin(); iterator != fMap.end();
iterator++) {
delete iterator->second;
}
}
BBuffer*
BufferCache::GetBuffer(media_buffer_id id)
{
BufferMap::iterator found = fMap.find(id);
if (found != fMap.end())
return found->second;
buffer_clone_info info;
info.buffer = id;
BBuffer* buffer = new(std::nothrow) BBuffer(info);
if (buffer == NULL)
return NULL;
try {
fMap.insert(std::make_pair(id, buffer));
} catch (std::bad_alloc& exception) {
delete buffer;
return NULL;
}
return buffer;
}
} // namespace BPrivate
+38
View File
@@ -0,0 +1,38 @@
/*
* Copyright 2009, Axel Dörfler, [email protected].
* Copyright 2002, Marcus Overhagen. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _BUFFER_CACHE_H_
#define _BUFFER_CACHE_H_
#include <map>
#include <MediaDefs.h>
class BBuffer;
namespace BPrivate {
class BufferCache {
public:
BufferCache();
~BufferCache();
BBuffer* GetBuffer(media_buffer_id id);
private:
typedef std::map<media_buffer_id, BBuffer*> BufferMap;
BufferMap fMap;
};
} // namespace BPrivate
#endif // _BUFFER_CACHE_H_
+170 -172
View File
@@ -24,37 +24,35 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*
*/ */
#include "BufferCache.h"
#include <BufferConsumer.h> #include <BufferConsumer.h>
#include <stdlib.h>
#include <BufferProducer.h> #include <BufferProducer.h>
#include <BufferGroup.h> #include <BufferGroup.h>
#include <Buffer.h> #include <Buffer.h>
#include <TimeSource.h> //for debugging #include <TimeSource.h>
#include <stdlib.h>
#include "debug.h" #include <debug.h>
#include "MediaMisc.h" #include <MediaMisc.h>
#include "DataExchange.h" #include <DataExchange.h>
#include "BufferIdCache.h"
/*************************************************************
* protected BBufferConsumer
*************************************************************/
/* virtual */
BBufferConsumer::~BBufferConsumer() BBufferConsumer::~BBufferConsumer()
{ {
CALLED(); CALLED();
delete fBufferCache; delete fBufferCache;
if (fDeleteBufferGroup) delete fDeleteBufferGroup;
delete fDeleteBufferGroup;
} }
/************************************************************* // #pragma mark - public BBufferConsumer
* public BBufferConsumer
*************************************************************/
media_type media_type
BBufferConsumer::ConsumerType() BBufferConsumer::ConsumerType()
@@ -64,97 +62,97 @@ BBufferConsumer::ConsumerType()
} }
/* static */ status_t /*static*/ status_t
BBufferConsumer::RegionToClipData(const BRegion *region, BBufferConsumer::RegionToClipData(const BRegion* region, int32* _format,
int32 *format, int32 *_size, void* data)
int32 *ioSize,
void *data)
{ {
CALLED(); CALLED();
status_t rv;
int count;
count = *ioSize / sizeof(int16); int count = *_size / sizeof(int16);
rv = BBufferProducer::clip_region_to_shorts(region, static_cast<int16 *>(data), count, &count); status_t status = BBufferProducer::clip_region_to_shorts(region,
*ioSize = count * sizeof(int16); static_cast<int16 *>(data), count, &count);
*format = BBufferProducer::B_CLIP_SHORT_RUNS;
*_size = count * sizeof(int16);
return rv; *_format = BBufferProducer::B_CLIP_SHORT_RUNS;
return status;
} }
/*************************************************************
* protected BBufferConsumer
*************************************************************/
/* explicit */ // #pragma mark - protected BBufferConsumer
BBufferConsumer::BBufferConsumer(media_type consumer_type) :
BBufferConsumer::BBufferConsumer(media_type consumerType)
:
BMediaNode("called by BBufferConsumer"), BMediaNode("called by BBufferConsumer"),
fConsumerType(consumer_type), fConsumerType(consumerType),
fBufferCache(new _buffer_id_cache), fBufferCache(new BPrivate::BufferCache),
fDeleteBufferGroup(0) fDeleteBufferGroup(0)
{ {
CALLED(); CALLED();
AddNodeKind(B_BUFFER_CONSUMER); AddNodeKind(B_BUFFER_CONSUMER);
} }
/* static */ void /*static*/ void
BBufferConsumer::NotifyLateProducer(const media_source &what_source, BBufferConsumer::NotifyLateProducer(const media_source& whatSource,
bigtime_t how_much, bigtime_t howMuch, bigtime_t performanceTime)
bigtime_t performance_time)
{ {
CALLED(); CALLED();
if (IS_INVALID_SOURCE(what_source)) if (IS_INVALID_SOURCE(whatSource))
return; return;
producer_late_notice_received_command command; producer_late_notice_received_command command;
command.source = what_source; command.source = whatSource;
command.how_much = how_much; command.how_much = howMuch;
command.performance_time = performance_time; command.performance_time = performanceTime;
SendToPort(what_source.port, PRODUCER_LATE_NOTICE_RECEIVED, &command, sizeof(command)); SendToPort(whatSource.port, PRODUCER_LATE_NOTICE_RECEIVED, &command,
sizeof(command));
} }
status_t status_t
BBufferConsumer::SetVideoClippingFor(const media_source &output, BBufferConsumer::SetVideoClippingFor(const media_source& output,
const media_destination &destination, const media_destination& destination, const int16* shorts, int32 shortCount,
const int16 *shorts, const media_video_display_info& display, void* userData, int32* _changeTag,
int32 short_count, void *_reserved_)
const media_video_display_info &display,
void *user_data,
int32 *change_tag,
void *_reserved_)
{ {
CALLED(); CALLED();
if (IS_INVALID_SOURCE(output)) if (IS_INVALID_SOURCE(output))
return B_MEDIA_BAD_SOURCE; return B_MEDIA_BAD_SOURCE;
if (IS_INVALID_DESTINATION(destination)) if (IS_INVALID_DESTINATION(destination))
return B_MEDIA_BAD_DESTINATION; return B_MEDIA_BAD_DESTINATION;
if (short_count > int(B_MEDIA_MESSAGE_SIZE - sizeof(producer_video_clipping_changed_command)) / 2) if (shortCount > int(B_MEDIA_MESSAGE_SIZE
debugger("BBufferConsumer::SetVideoClippingFor short_count too large (8000 limit)\n"); - sizeof(producer_video_clipping_changed_command)) / 2) {
debugger("BBufferConsumer::SetVideoClippingFor short_count too large "
producer_video_clipping_changed_command *command; "(8000 limit)\n");
size_t size; }
status_t rv;
producer_video_clipping_changed_command* command;
size_t size = sizeof(producer_video_clipping_changed_command)
+ shortCount * sizeof(short);
command
= static_cast<producer_video_clipping_changed_command*>(malloc(size));
if (command == NULL)
return B_NO_MEMORY;
size = sizeof(producer_video_clipping_changed_command) + short_count * sizeof(short);
command = static_cast<producer_video_clipping_changed_command *>(malloc(size));
command->source = output; command->source = output;
command->destination = destination; command->destination = destination;
command->display = display; command->display = display;
command->user_data = user_data; command->user_data = userData;
command->change_tag = NewChangeTag(); command->change_tag = NewChangeTag();
command->short_count = short_count; command->short_count = shortCount;
memcpy(command->shorts, shorts, short_count * sizeof(short)); memcpy(command->shorts, shorts, shortCount * sizeof(short));
if (change_tag != NULL) if (_changeTag != NULL)
*change_tag = command->change_tag; *_changeTag = command->change_tag;
rv = SendToPort(output.port, PRODUCER_VIDEO_CLIPPING_CHANGED, command, size); status_t status = SendToPort(output.port, PRODUCER_VIDEO_CLIPPING_CHANGED,
command, size);
free(command); free(command);
return rv; return status;
} }
@@ -173,7 +171,7 @@ BBufferConsumer::SetOutputEnabled(const media_source &source,
return B_MEDIA_BAD_DESTINATION; return B_MEDIA_BAD_DESTINATION;
producer_enable_output_command command; producer_enable_output_command command;
command.source = source; command.source = source;
command.destination = destination; command.destination = destination;
command.enabled = enabled; command.enabled = enabled;
@@ -181,7 +179,7 @@ BBufferConsumer::SetOutputEnabled(const media_source &source,
command.change_tag = NewChangeTag(); command.change_tag = NewChangeTag();
if (change_tag != NULL) if (change_tag != NULL)
*change_tag = command.change_tag; *change_tag = command.change_tag;
return SendToPort(source.port, PRODUCER_ENABLE_OUTPUT, &command, sizeof(command)); return SendToPort(source.port, PRODUCER_ENABLE_OUTPUT, &command, sizeof(command));
} }
@@ -201,7 +199,7 @@ BBufferConsumer::RequestFormatChange(const media_source &source,
return B_MEDIA_BAD_DESTINATION; return B_MEDIA_BAD_DESTINATION;
producer_format_change_requested_command command; producer_format_change_requested_command command;
command.source = source; command.source = source;
command.destination = destination; command.destination = destination;
command.format = to_format; command.format = to_format;
@@ -209,7 +207,7 @@ BBufferConsumer::RequestFormatChange(const media_source &source,
command.change_tag = NewChangeTag(); command.change_tag = NewChangeTag();
if (change_tag != NULL) if (change_tag != NULL)
*change_tag = command.change_tag; *change_tag = command.change_tag;
return SendToPort(source.port, PRODUCER_FORMAT_CHANGE_REQUESTED, &command, sizeof(command)); return SendToPort(source.port, PRODUCER_FORMAT_CHANGE_REQUESTED, &command, sizeof(command));
} }
@@ -224,46 +222,41 @@ BBufferConsumer::RequestAdditionalBuffer(const media_source &source,
return B_MEDIA_BAD_SOURCE; return B_MEDIA_BAD_SOURCE;
producer_additional_buffer_requested_command command; producer_additional_buffer_requested_command command;
command.source = source; command.source = source;
command.prev_buffer = prev_buffer->ID(); command.prev_buffer = prev_buffer->ID();
command.prev_time = 0; command.prev_time = 0;
command.has_seek_tag = false; command.has_seek_tag = false;
//command.prev_tag = //command.prev_tag =
return SendToPort(source.port, PRODUCER_ADDITIONAL_BUFFER_REQUESTED, &command, sizeof(command)); return SendToPort(source.port, PRODUCER_ADDITIONAL_BUFFER_REQUESTED, &command, sizeof(command));
} }
status_t status_t
BBufferConsumer::RequestAdditionalBuffer(const media_source &source, BBufferConsumer::RequestAdditionalBuffer(const media_source& source,
bigtime_t start_time, bigtime_t startTime, void *_reserved)
void *_reserved)
{ {
CALLED(); CALLED();
if (IS_INVALID_SOURCE(source)) if (IS_INVALID_SOURCE(source))
return B_MEDIA_BAD_SOURCE; return B_MEDIA_BAD_SOURCE;
producer_additional_buffer_requested_command command; producer_additional_buffer_requested_command command;
command.source = source; command.source = source;
command.prev_buffer = 0; command.prev_buffer = 0;
command.prev_time = start_time; command.prev_time = startTime;
command.has_seek_tag = false; command.has_seek_tag = false;
//command.prev_tag =
return SendToPort(source.port, PRODUCER_ADDITIONAL_BUFFER_REQUESTED,
return SendToPort(source.port, PRODUCER_ADDITIONAL_BUFFER_REQUESTED, &command, sizeof(command)); &command, sizeof(command));
} }
status_t status_t
BBufferConsumer::SetOutputBuffersFor(const media_source &source, BBufferConsumer::SetOutputBuffersFor(const media_source &source,
const media_destination &destination, const media_destination &destination, BBufferGroup *group, void *user_data,
BBufferGroup *group, int32 *change_tag, bool will_reclaim, void *_reserved_)
void *user_data,
int32 *change_tag,
bool will_reclaim,
void *_reserved_)
{ {
CALLED(); CALLED();
@@ -271,10 +264,10 @@ BBufferConsumer::SetOutputBuffersFor(const media_source &source,
return B_MEDIA_BAD_SOURCE; return B_MEDIA_BAD_SOURCE;
if (IS_INVALID_DESTINATION(destination)) if (IS_INVALID_DESTINATION(destination))
return B_MEDIA_BAD_DESTINATION; return B_MEDIA_BAD_DESTINATION;
producer_set_buffer_group_command *command; producer_set_buffer_group_command *command;
BBuffer **buffers; BBuffer **buffers;
int32 buffer_count; int32 buffer_count;
size_t size; size_t size;
status_t rv; status_t rv;
@@ -284,8 +277,8 @@ BBufferConsumer::SetOutputBuffersFor(const media_source &source,
if (B_OK != group->CountBuffers(&buffer_count)) if (B_OK != group->CountBuffers(&buffer_count))
return B_ERROR; return B_ERROR;
} }
if (buffer_count != 0) { if (buffer_count != 0) {
buffers = new BBuffer * [buffer_count]; buffers = new BBuffer * [buffer_count];
if (B_OK != group->GetBufferList(buffer_count, buffers)) { if (B_OK != group->GetBufferList(buffer_count, buffers)) {
delete [] buffers; delete [] buffers;
@@ -309,11 +302,11 @@ BBufferConsumer::SetOutputBuffersFor(const media_source &source,
if (change_tag != NULL) if (change_tag != NULL)
*change_tag = command->change_tag; *change_tag = command->change_tag;
rv = SendToPort(source.port, PRODUCER_SET_BUFFER_GROUP, command, size); rv = SendToPort(source.port, PRODUCER_SET_BUFFER_GROUP, command, size);
free(command); free(command);
if (rv == B_OK) { if (rv == B_OK) {
if (fDeleteBufferGroup) // XXX will leak memory if port write failed if (fDeleteBufferGroup) // XXX will leak memory if port write failed
delete fDeleteBufferGroup; delete fDeleteBufferGroup;
fDeleteBufferGroup = will_reclaim ? NULL : group; fDeleteBufferGroup = will_reclaim ? NULL : group;
@@ -323,10 +316,8 @@ BBufferConsumer::SetOutputBuffersFor(const media_source &source,
status_t status_t
BBufferConsumer::SendLatencyChange(const media_source &source, BBufferConsumer::SendLatencyChange(const media_source& source,
const media_destination &destination, const media_destination& destination, bigtime_t newLatency, uint32 flags)
bigtime_t my_new_latency,
uint32 flags)
{ {
CALLED(); CALLED();
if (IS_INVALID_SOURCE(source)) if (IS_INVALID_SOURCE(source))
@@ -335,37 +326,36 @@ BBufferConsumer::SendLatencyChange(const media_source &source,
return B_MEDIA_BAD_DESTINATION; return B_MEDIA_BAD_DESTINATION;
producer_latency_changed_command command; producer_latency_changed_command command;
command.source = source; command.source = source;
command.destination = destination; command.destination = destination;
command.latency = my_new_latency; command.latency = newLatency;
command.flags = flags; command.flags = flags;
TRACE("###### BBufferConsumer::SendLatencyChange: latency from %ld/%ld to %ld/%ld changed to %Ld\n", TRACE("###### BBufferConsumer::SendLatencyChange: latency from %ld/%ld to "
source.port, source.id, destination.port, destination.id, my_new_latency); "%ld/%ld changed to %Ld\n", source.port, source.id, destination.port,
destination.id, newLatency);
return SendToPort(source.port, PRODUCER_LATENCY_CHANGED, &command, sizeof(command));
return SendToPort(source.port, PRODUCER_LATENCY_CHANGED, &command,
sizeof(command));
} }
/*************************************************************
* protected BBufferConsumer
*************************************************************/
/* virtual */ status_t status_t
BBufferConsumer::HandleMessage(int32 message, BBufferConsumer::HandleMessage(int32 message, const void* data, size_t size)
const void *data,
size_t size)
{ {
PRINT(4, "BBufferConsumer::HandleMessage %#lx, node %ld\n", message, ID()); PRINT(4, "BBufferConsumer::HandleMessage %#lx, node %ld\n", message, ID());
status_t rv; status_t rv;
switch (message) { switch (message) {
case CONSUMER_ACCEPT_FORMAT: case CONSUMER_ACCEPT_FORMAT:
{ {
const consumer_accept_format_request *request = static_cast<const consumer_accept_format_request *>(data); const consumer_accept_format_request* request
= static_cast<const consumer_accept_format_request*>(data);
consumer_accept_format_reply reply; consumer_accept_format_reply reply;
reply.format = request->format; reply.format = request->format;
rv = AcceptFormat(request->dest, &reply.format); status_t status = AcceptFormat(request->dest, &reply.format);
request->SendReply(rv, &reply, sizeof(reply)); request->SendReply(status, &reply, sizeof(reply));
return B_OK; return B_OK;
} }
@@ -390,12 +380,17 @@ BBufferConsumer::HandleMessage(int32 message,
case CONSUMER_BUFFER_RECEIVED: case CONSUMER_BUFFER_RECEIVED:
{ {
const consumer_buffer_received_command *command = static_cast<const consumer_buffer_received_command *>(data); const consumer_buffer_received_command* command
BBuffer *buffer; = static_cast<const consumer_buffer_received_command*>(data);
buffer = fBufferCache->GetBuffer(command->buffer);
BBuffer* buffer = fBufferCache->GetBuffer(command->buffer);
buffer->SetHeader(&command->header); buffer->SetHeader(&command->header);
PRINT(4, "calling BBufferConsumer::BufferReceived buffer %ld at perf %Ld and TimeSource()->Now() is %Ld\n", buffer->Header()->buffer, buffer->Header()->start_time, TimeSource()->Now());
//printf("BBufferConsumer::BufferReceived node %2ld, buffer %2ld, start_time %12Ld with lateness %6Ld\n", ID(), buffer->Header()->buffer, buffer->Header()->start_time, TimeSource()->Now() - buffer->Header()->start_time); PRINT(4, "calling BBufferConsumer::BufferReceived buffer %ld at "
"perf %Ld and TimeSource()->Now() is %Ld\n",
buffer->Header()->buffer, buffer->Header()->start_time,
TimeSource()->Now());
BufferReceived(buffer); BufferReceived(buffer);
return B_OK; return B_OK;
} }
@@ -425,7 +420,7 @@ BBufferConsumer::HandleMessage(int32 message,
request->SendReply(rv, &reply, sizeof(reply)); request->SendReply(rv, &reply, sizeof(reply));
return B_OK; return B_OK;
} }
case CONSUMER_DISCONNECTED: case CONSUMER_DISCONNECTED:
{ {
const consumer_disconnected_request *request = static_cast<const consumer_disconnected_request *>(data); const consumer_disconnected_request *request = static_cast<const consumer_disconnected_request *>(data);
@@ -464,8 +459,7 @@ BBufferConsumer::HandleMessage(int32 message,
request->SendReply(rv, &reply, sizeof(reply)); request->SendReply(rv, &reply, sizeof(reply));
return B_OK; return B_OK;
} }
}
};
return B_ERROR; return B_ERROR;
} }
@@ -482,9 +476,9 @@ BBufferConsumer::SeekTagRequested(const media_destination &destination,
return B_ERROR; return B_ERROR;
} }
/*************************************************************
* private BBufferConsumer // #pragma mark - private BBufferConsumer
*************************************************************/
/* /*
not implemented: not implemented:
@@ -493,7 +487,9 @@ BBufferConsumer::BBufferConsumer(const BBufferConsumer &clone)
BBufferConsumer & BBufferConsumer::operator=(const BBufferConsumer &clone) BBufferConsumer & BBufferConsumer::operator=(const BBufferConsumer &clone)
*/ */
/* deprecated function for R4 */
/*! Deprecated function for BeOS R4.
*/
/* static */ status_t /* static */ status_t
BBufferConsumer::SetVideoClippingFor(const media_source &output, BBufferConsumer::SetVideoClippingFor(const media_source &output,
const int16 *shorts, const int16 *shorts,
@@ -506,7 +502,7 @@ BBufferConsumer::SetVideoClippingFor(const media_source &output,
return B_MEDIA_BAD_SOURCE; return B_MEDIA_BAD_SOURCE;
if (short_count > int(B_MEDIA_MESSAGE_SIZE - sizeof(producer_video_clipping_changed_command)) / 2) if (short_count > int(B_MEDIA_MESSAGE_SIZE - sizeof(producer_video_clipping_changed_command)) / 2)
debugger("BBufferConsumer::SetVideoClippingFor short_count too large (8000 limit)\n"); debugger("BBufferConsumer::SetVideoClippingFor short_count too large (8000 limit)\n");
producer_video_clipping_changed_command *command; producer_video_clipping_changed_command *command;
size_t size; size_t size;
status_t rv; status_t rv;
@@ -522,19 +518,19 @@ BBufferConsumer::SetVideoClippingFor(const media_source &output,
memcpy(command->shorts, shorts, short_count * sizeof(short)); memcpy(command->shorts, shorts, short_count * sizeof(short));
if (change_tag != NULL) if (change_tag != NULL)
*change_tag = command->change_tag; *change_tag = command->change_tag;
rv = SendToPort(output.port, PRODUCER_VIDEO_CLIPPING_CHANGED, command, size); rv = SendToPort(output.port, PRODUCER_VIDEO_CLIPPING_CHANGED, command, size);
free(command); free(command);
return rv; return rv;
} }
/* deprecated function for R4 */ /*! Deprecated function for BeOS R4.
/* static */ status_t */
BBufferConsumer::RequestFormatChange(const media_source &source, /*static*/ status_t
const media_destination &destination, BBufferConsumer::RequestFormatChange(const media_source& source,
media_format *in_to_format, const media_destination& destination, media_format* format,
int32 *change_tag) int32* _changeTag)
{ {
CALLED(); CALLED();
if (IS_INVALID_SOURCE(source)) if (IS_INVALID_SOURCE(source))
@@ -543,57 +539,59 @@ BBufferConsumer::RequestFormatChange(const media_source &source,
return B_MEDIA_BAD_DESTINATION; return B_MEDIA_BAD_DESTINATION;
producer_format_change_requested_command command; producer_format_change_requested_command command;
command.source = source; command.source = source;
command.destination = destination; command.destination = destination;
command.format = *in_to_format; command.format = *format;
command.user_data = 0; command.user_data = 0;
command.change_tag = NewChangeTag(); command.change_tag = NewChangeTag();
if (change_tag != NULL) if (_changeTag != NULL)
*change_tag = command.change_tag; *_changeTag = command.change_tag;
return SendToPort(source.port, PRODUCER_FORMAT_CHANGE_REQUESTED, &command, sizeof(command)); return SendToPort(source.port, PRODUCER_FORMAT_CHANGE_REQUESTED, &command,
sizeof(command));
} }
/* deprecated function for R4 */ /*! Deprecated function for BeOS R4.
/* static */ status_t */
BBufferConsumer::SetOutputEnabled(const media_source &source, /*static*/ status_t
bool enabled, BBufferConsumer::SetOutputEnabled(const media_source& source, bool enabled,
int32 *change_tag) int32* _changeTag)
{ {
CALLED(); CALLED();
if (IS_INVALID_SOURCE(source)) if (IS_INVALID_SOURCE(source))
return B_MEDIA_BAD_SOURCE; return B_MEDIA_BAD_SOURCE;
producer_enable_output_command command; producer_enable_output_command command;
command.source = source; command.source = source;
command.destination = media_destination::null; command.destination = media_destination::null;
command.enabled = enabled; command.enabled = enabled;
command.user_data = 0; command.user_data = 0;
command.change_tag = NewChangeTag(); command.change_tag = NewChangeTag();
if (change_tag != NULL) if (_changeTag != NULL)
*change_tag = command.change_tag; *_changeTag = command.change_tag;
return SendToPort(source.port, PRODUCER_ENABLE_OUTPUT, &command, sizeof(command)); return SendToPort(source.port, PRODUCER_ENABLE_OUTPUT, &command,
sizeof(command));
} }
status_t BBufferConsumer::_Reserved_BufferConsumer_0(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_0(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_1(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_1(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_2(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_2(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_3(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_3(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_4(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_4(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_5(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_5(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_6(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_6(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_7(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_7(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_8(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_8(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_9(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_9(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_10(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_10(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_11(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_11(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_12(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_12(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_13(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_13(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_14(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_14(void*) { return B_ERROR; }
status_t BBufferConsumer::_Reserved_BufferConsumer_15(void *) { return B_ERROR; } status_t BBufferConsumer::_Reserved_BufferConsumer_15(void*) { return B_ERROR; }
+26 -26
View File
@@ -43,9 +43,9 @@ BBufferGroup::BBufferGroup(size_t size, int32 count, uint32 placement,
CALLED(); CALLED();
if (_Init() != B_OK) if (_Init() != B_OK)
return; return;
// This one is easy. We need to create "count" BBuffers, // This one is easy. We need to create "count" BBuffers,
// each one "size" bytes large. They all go into one // each one "size" bytes large. They all go into one
// area, with "placement" and "lock" attributes. // area, with "placement" and "lock" attributes.
// The BBuffers created will clone the area, and // The BBuffers created will clone the area, and
// then we delete our area. This way BBuffers are // then we delete our area. This way BBuffers are
@@ -57,7 +57,7 @@ BBufferGroup::BBufferGroup(size_t size, int32 count, uint32 placement,
"&& placement != B_ANY_KERNEL_ADDRESS (0x%08lx)\n", placement); "&& placement != B_ANY_KERNEL_ADDRESS (0x%08lx)\n", placement);
placement = B_ANY_ADDRESS; placement = B_ANY_ADDRESS;
} }
// first we roundup for a better placement in memory // first we roundup for a better placement in memory
size_t allocSize = (size + 63) & ~63; size_t allocSize = (size + 63) & ~63;
@@ -76,7 +76,7 @@ BBufferGroup::BBufferGroup(size_t size, int32 count, uint32 placement,
buffer_clone_info info; buffer_clone_info info;
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
info.area = bufferArea; info.area = bufferArea;
info.offset = i * allocSize; info.offset = i * allocSize;
info.size = size; info.size = size;
@@ -95,7 +95,7 @@ BBufferGroup::BBufferGroup()
CALLED(); CALLED();
if (_Init() != B_OK) if (_Init() != B_OK)
return; return;
// this one simply creates an empty BBufferGroup // this one simply creates an empty BBufferGroup
} }
@@ -105,16 +105,16 @@ BBufferGroup::BBufferGroup(int32 count, const media_buffer_id* buffers)
CALLED(); CALLED();
if (_Init() != B_OK) if (_Init() != B_OK)
return; return;
// TODO: we need to make sure that a media_buffer_id is only added // TODO: we need to make sure that a media_buffer_id is only added
// once to each group // once to each group
// this one creates "BBuffer"s from "media_buffer_id"s passed // this one creates "BBuffer"s from "media_buffer_id"s passed
// by the application. // by the application.
buffer_clone_info info; buffer_clone_info info;
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
info.buffer = buffers[i]; info.buffer = buffers[i];
fInitError = AddBuffer(info); fInitError = AddBuffer(info);
@@ -127,8 +127,8 @@ BBufferGroup::BBufferGroup(int32 count, const media_buffer_id* buffers)
BBufferGroup::~BBufferGroup() BBufferGroup::~BBufferGroup()
{ {
CALLED(); CALLED();
if (fBufferList) if (fBufferList != NULL)
fBufferList->Terminate(fReclaimSem); fBufferList->DeleteGroupAndPut(fReclaimSem);
delete_sem(fReclaimSem); delete_sem(fReclaimSem);
} }
@@ -188,7 +188,7 @@ BBufferGroup::RequestBuffer(size_t size, bigtime_t timeout)
if (size <= 0) if (size <= 0)
return NULL; return NULL;
BBuffer *buffer; BBuffer *buffer;
status_t status; status_t status;
@@ -207,7 +207,7 @@ BBufferGroup::RequestBuffer(BBuffer* buffer, bigtime_t timeout)
CALLED(); CALLED();
if (fInitError != B_OK) if (fInitError != B_OK)
return B_NO_INIT; return B_NO_INIT;
if (buffer == NULL) if (buffer == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -215,7 +215,7 @@ BBufferGroup::RequestBuffer(BBuffer* buffer, bigtime_t timeout)
status = fBufferList->RequestBuffer(fReclaimSem, fBufferCount, 0, 0, status = fBufferList->RequestBuffer(fReclaimSem, fBufferCount, 0, 0,
&buffer, timeout); &buffer, timeout);
fRequestError = status; fRequestError = status;
return status; return status;
} }
@@ -249,7 +249,7 @@ BBufferGroup::GetBufferList(int32 bufferCount, BBuffer** _buffers)
CALLED(); CALLED();
if (fInitError != B_OK) if (fInitError != B_OK)
return B_NO_INIT; return B_NO_INIT;
if (bufferCount <= 0 || bufferCount > fBufferCount) if (bufferCount <= 0 || bufferCount > fBufferCount)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -264,7 +264,7 @@ BBufferGroup::WaitForBuffers()
if (fInitError != B_OK) if (fInitError != B_OK)
return B_NO_INIT; return B_NO_INIT;
// TODO: this function is not really useful anyway, and will // TODO: this function is not really useful anyway, and will
// not work exactly as documented, but it is close enough // not work exactly as documented, but it is close enough
if (fBufferCount < 0) if (fBufferCount < 0)
@@ -281,7 +281,7 @@ BBufferGroup::WaitForBuffers()
; ;
if (status != B_OK) if (status != B_OK)
return status; return status;
// we need to release the "fReclaimSem" now, else we would block // we need to release the "fReclaimSem" now, else we would block
// requesting of new buffers // requesting of new buffers
@@ -297,7 +297,7 @@ BBufferGroup::ReclaimAllBuffers()
return B_NO_INIT; return B_NO_INIT;
// because additional BBuffers might get added to this group betweeen // because additional BBuffers might get added to this group betweeen
// acquire and release // acquire and release
int32 count = fBufferCount; int32 count = fBufferCount;
if (count < 0) if (count < 0)
@@ -313,10 +313,10 @@ BBufferGroup::ReclaimAllBuffers()
do { do {
status = acquire_sem_etc(fReclaimSem, count, 0, 0); status = acquire_sem_etc(fReclaimSem, count, 0, 0);
} while (status == B_INTERRUPTED); } while (status == B_INTERRUPTED);
if (status != B_OK) if (status != B_OK)
return status; return status;
// we need to release the "fReclaimSem" now, else we would block // we need to release the "fReclaimSem" now, else we would block
// requesting of new buffers // requesting of new buffers
@@ -333,7 +333,7 @@ BBufferGroup::AddBuffersTo(BMessage* message, const char* name, bool needLock)
CALLED(); CALLED();
if (fInitError != B_OK) if (fInitError != B_OK)
return B_NO_INIT; return B_NO_INIT;
// BeOS R4 legacy API. Implemented as a wrapper around GetBufferList // BeOS R4 legacy API. Implemented as a wrapper around GetBufferList
// "needLock" is ignored, GetBufferList will do locking // "needLock" is ignored, GetBufferList will do locking
@@ -342,17 +342,17 @@ BBufferGroup::AddBuffersTo(BMessage* message, const char* name, bool needLock)
if (name == NULL || strlen(name) == 0) if (name == NULL || strlen(name) == 0)
return B_BAD_VALUE; return B_BAD_VALUE;
BBuffer** buffers; BBuffer** buffers;
int32 count; int32 count;
count = fBufferCount; count = fBufferCount;
buffers = new BBuffer * [count]; buffers = new BBuffer * [count];
status_t status = GetBufferList(count, buffers); status_t status = GetBufferList(count, buffers);
if (status != B_OK) if (status != B_OK)
goto end; goto end;
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
status = message->AddInt32(name, int32(buffers[i]->ID())); status = message->AddInt32(name, int32(buffers[i]->ID()));
if (status != B_OK) if (status != B_OK)
@@ -377,7 +377,7 @@ status_t
BBufferGroup::_Init() BBufferGroup::_Init()
{ {
CALLED(); CALLED();
// some defaults in case we drop out early // some defaults in case we drop out early
fBufferList = 0; fBufferList = 0;
fInitError = B_ERROR; fInitError = B_ERROR;
@@ -404,9 +404,9 @@ BBufferGroup::_Init()
return fInitError; return fInitError;
} }
fBufferList = _shared_buffer_list::Clone(areaReply.area); fBufferList = BPrivate::SharedBufferList::Get(areaReply.area);
if (fBufferList == NULL) { if (fBufferList == NULL) {
ERROR("BBufferGroup::InitBufferGroup: _shared_buffer_list::Clone " ERROR("BBufferGroup::InitBufferGroup: SharedBufferList::Get() "
"failed\n"); "failed\n");
fInitError = B_ERROR; fInitError = B_ERROR;
return fInitError; return fInitError;
-45
View File
@@ -1,45 +0,0 @@
/***********************************************************************
* Copyright (c) 2002 Marcus Overhagen. All Rights Reserved.
* This file may be used under the terms of the OpenBeOS License.
*
* A cache for BBuffers to be received by
* BBufferConsumer::BufferReceived()
***********************************************************************/
#include <Buffer.h>
#include "BufferIdCache.h"
#include "debug.h"
// XXX we are not allowed to delete BBuffer objects when they are not recycled
_buffer_id_cache::_buffer_id_cache()
{
}
_buffer_id_cache::~_buffer_id_cache()
{
// XXX deleting buffers here is not save, too
/*
fMap.Rewind();
BBuffer **buffer;
while (fMap.GetNext(&buffer)) {
fMap.RemoveCurrent();
delete *buffer;
}
*/
}
BBuffer *
_buffer_id_cache::GetBuffer(media_buffer_id id)
{
BBuffer **buffer;
if (fMap.Get(id, &buffer))
return *buffer;
buffer_clone_info ci;
ci.buffer = id;
BBuffer *buf = new BBuffer(ci);
fMap.Insert(id, buf);
return buf;
}
-25
View File
@@ -1,25 +0,0 @@
/***********************************************************************
* Copyright (c) 2002 Marcus Overhagen. All Rights Reserved.
* This file may be used under the terms of the OpenBeOS License.
*
* A cache for BBuffers to be received by
* BBufferConsumer::BufferReceived()
***********************************************************************/
#ifndef _BUFFER_ID_CACHE_H_
#define _BUFFER_ID_CACHE_H_
#include "TMap.h"
class _buffer_id_cache
{
public:
_buffer_id_cache();
~_buffer_id_cache();
BBuffer *GetBuffer(media_buffer_id id);
private:
Map<media_buffer_id, BBuffer *> fMap;
};
#endif
+43 -32
View File
@@ -1,52 +1,54 @@
/* /*
* Copyright 2002-2007, Marcus Overhagen. All rights reserved. * Copyright 2002-2007, Marcus Overhagen. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include <OS.h>
#include <Messenger.h> #include <DataExchange.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <Messenger.h>
#include <OS.h>
#include "debug.h" #include "debug.h"
#include "PortPool.h" #include "PortPool.h"
#include "MediaMisc.h" #include "MediaMisc.h"
#include "DataExchange.h"
#include "ServerInterface.h" #include "ServerInterface.h"
#define TIMEOUT 15000000 // 15 seconds timeout! #define TIMEOUT 15000000 // 15 seconds timeout!
namespace BPrivate { namespace BPrivate {
namespace media { namespace media {
team_id team;
namespace dataexchange { namespace dataexchange {
BMessenger *MediaServerMessenger;
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_server_port();
void find_media_addon_server_port(); void find_media_addon_server_port();
static BMessenger * GetMediaServerMessenger() { static BMessenger*
static BMessenger * messenger = new BMessenger(B_MEDIA_SERVER_SIGNATURE); GetMediaServerMessenger()
{
static BMessenger* messenger = new BMessenger(B_MEDIA_SERVER_SIGNATURE);
return MediaServerMessenger = messenger; return MediaServerMessenger = messenger;
} }
class initit class initit {
{
public: public:
initit() initit()
{ {
MediaServerMessenger = 0; MediaServerMessenger = 0;
find_media_server_port(); find_media_server_port();
find_media_addon_server_port(); find_media_addon_server_port();
thread_info info;
get_thread_info(find_thread(NULL), &info);
team = info.team;
} }
~initit() ~initit()
{ {
delete MediaServerMessenger; delete MediaServerMessenger;
@@ -55,7 +57,8 @@ public:
initit _initit; initit _initit;
void find_media_server_port() void
find_media_server_port()
{ {
MediaServerPort = find_port(MEDIA_SERVER_PORT_NAME); MediaServerPort = find_port(MEDIA_SERVER_PORT_NAME);
if (MediaServerPort < 0) { if (MediaServerPort < 0) {
@@ -64,7 +67,9 @@ void find_media_server_port()
} }
} }
void find_media_addon_server_port()
void
find_media_addon_server_port()
{ {
MediaAddonServerPort = find_port(MEDIA_ADDON_SERVER_PORT_NAME); MediaAddonServerPort = find_port(MEDIA_ADDON_SERVER_PORT_NAME);
if (MediaAddonServerPort < 0) { if (MediaAddonServerPort < 0) {
@@ -84,7 +89,8 @@ request_data::SendReply(status_t result, reply_data *reply, int replysize) const
// 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 rv; status_t rv;
rv = GetMediaServerMessenger()->SendMessage(msg, static_cast<BHandler *>(NULL), TIMEOUT); rv = GetMediaServerMessenger()->SendMessage(msg, static_cast<BHandler *>(NULL), TIMEOUT);
@@ -96,7 +102,7 @@ status_t SendToServer(BMessage *msg)
} }
status_t status_t
QueryServer(BMessage &request, BMessage &reply) QueryServer(BMessage &request, BMessage &reply)
{ {
status_t status = GetMediaServerMessenger()->SendMessage(&request, &reply, TIMEOUT, TIMEOUT); status_t status = GetMediaServerMessenger()->SendMessage(&request, &reply, TIMEOUT, TIMEOUT);
@@ -110,32 +116,37 @@ 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)
{ {
return SendToPort(MediaServerPort, msgcode, msg, size); return SendToPort(MediaServerPort, msgcode, msg, size);
} }
status_t QueryServer(int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize) status_t
QueryServer(int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize)
{ {
return QueryPort(MediaServerPort, msgcode, request, requestsize, reply, replysize); return QueryPort(MediaServerPort, msgcode, request, requestsize, reply, replysize);
} }
// Raw data based data exchange with the media_addon_server // Raw data based data exchange with the media_addon_server
status_t SendToAddonServer(int32 msgcode, command_data *msg, int size) status_t
SendToAddonServer(int32 msgcode, command_data *msg, int size)
{ {
return SendToPort(MediaAddonServerPort, msgcode, msg, size); return SendToPort(MediaAddonServerPort, msgcode, msg, size);
} }
status_t QueryAddonServer(int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize) status_t
QueryAddonServer(int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize)
{ {
return QueryPort(MediaAddonServerPort, msgcode, request, requestsize, reply, replysize); return QueryPort(MediaAddonServerPort, msgcode, request, requestsize, reply, replysize);
} }
// Raw data based data exchange with the media_server // Raw data based data exchange with the media_server
status_t SendToPort(port_id sendport, int32 msgcode, command_data *msg, int size) status_t
SendToPort(port_id sendport, int32 msgcode, command_data *msg, int size)
{ {
status_t rv; status_t rv;
@@ -162,7 +173,8 @@ status_t SendToPort(port_id sendport, int32 msgcode, command_data *msg, int size
} }
status_t QueryPort(port_id requestport, int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize) status_t
QueryPort(port_id requestport, int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize)
{ {
status_t rv; status_t rv;
int32 code; int32 code;
@@ -170,7 +182,7 @@ 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) {
ERROR("QueryPort: write_port failed, msgcode 0x%lx, port %ld, error %#lx (%s)\n", msgcode, requestport, rv, strerror(rv)); ERROR("QueryPort: write_port failed, msgcode 0x%lx, port %ld, error %#lx (%s)\n", msgcode, requestport, rv, strerror(rv));
if (rv == B_BAD_PORT_ID && requestport == MediaServerPort) { if (rv == B_BAD_PORT_ID && requestport == MediaServerPort) {
@@ -198,11 +210,10 @@ status_t QueryPort(port_id requestport, int32 msgcode, request_data *request, in
if (rv < B_OK) { if (rv < B_OK) {
ERROR("QueryPort: read_port failed, msgcode 0x%lx, port %ld, error %#lx (%s)\n", msgcode, request->reply_port, rv, strerror(rv)); ERROR("QueryPort: read_port failed, msgcode 0x%lx, port %ld, error %#lx (%s)\n", msgcode, request->reply_port, rv, strerror(rv));
} }
return (rv < B_OK) ? rv : reply->result; return (rv < B_OK) ? rv : reply->result;
} }
}; // dataexchange } // dataexchange
}; // media } // media
}; // BPrivate } // BPrivate
+22 -21
View File
@@ -34,10 +34,10 @@
* *
* Dormant media nodes can be instantiated on demand. The reside on harddisk in the * Dormant media nodes can be instantiated on demand. The reside on harddisk in the
* directories /boot/beos/system/add-ons/media and /boot/home/config/add-ons/media * directories /boot/beos/system/add-ons/media and /boot/home/config/add-ons/media
* Multiple media nodes can be included in one file, they can be accessed using the * Multiple media nodes can be included in one file, they can be accessed using the
* BMediaAddOn that each file implements. * BMediaAddOn that each file implements.
* The BMediaAddOn allows getting a list of supported flavors. Each flavor represents * The BMediaAddOn allows getting a list of supported flavors. Each flavor represents
* a media node. * a media node.
* The media_addon_server does the initial scanning of files and getting the list * The media_addon_server does the initial scanning of files and getting the list
* of supported flavors. It uses the flavor_info to do this, and reports the list * of supported flavors. It uses the flavor_info to do this, and reports the list
* of flavors to the media_server packed into individual dormant_media_node * of flavors to the media_server packed into individual dormant_media_node
@@ -80,7 +80,7 @@ DormantNodeManager::~DormantNodeManager()
ERROR("Forcing unload of add-on id %ld with usecount %ld\n", info->addon->AddonID(), info->usecount); ERROR("Forcing unload of add-on id %ld with usecount %ld\n", info->addon->AddonID(), info->usecount);
UnloadAddon(info->addon, info->image); UnloadAddon(info->addon, info->image);
} }
delete fAddonmap; delete fAddonmap;
} }
@@ -108,14 +108,14 @@ BMediaAddOn *
DormantNodeManager::GetAddon(media_addon_id id) DormantNodeManager::GetAddon(media_addon_id id)
{ {
BMediaAddOn *addon; BMediaAddOn *addon;
TRACE("DormantNodeManager::GetAddon, id %ld\n",id); TRACE("DormantNodeManager::GetAddon, id %ld\n",id);
// first try to use a already loaded add-on // first try to use a already loaded add-on
addon = TryGetAddon(id); addon = TryGetAddon(id);
if (addon) if (addon)
return addon; return addon;
// Be careful, we avoid locking here! // Be careful, we avoid locking here!
// ok, it's not loaded, try to get the path // ok, it's not loaded, try to get the path
@@ -124,7 +124,7 @@ DormantNodeManager::GetAddon(media_addon_id id)
ERROR("DormantNodeManager::GetAddon: can't find path for add-on %ld\n",id); ERROR("DormantNodeManager::GetAddon: can't find path for add-on %ld\n",id);
return NULL; return NULL;
} }
// try to load it // try to load it
BMediaAddOn *newaddon; BMediaAddOn *newaddon;
image_id image; image_id image;
@@ -132,7 +132,7 @@ DormantNodeManager::GetAddon(media_addon_id id)
ERROR("DormantNodeManager::GetAddon: can't load add-on %ld from path %s\n",id, path.Path()); ERROR("DormantNodeManager::GetAddon: can't load add-on %ld from path %s\n",id, path.Path());
return NULL; return NULL;
} }
// ok, we successfully loaded it. Now lock and insert it into the map, // ok, we successfully loaded it. Now lock and insert it into the map,
// or unload it if the map already contains one that was loaded by another // or unload it if the map already contains one that was loaded by another
// thread at the same time // thread at the same time
@@ -162,7 +162,7 @@ DormantNodeManager::PutAddonDelayed(media_addon_id id)
// We must make sure that the media-add-on stays in memory // We must make sure that the media-add-on stays in memory
// a couple of seconds longer. // a couple of seconds longer.
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
void void
@@ -174,7 +174,7 @@ DormantNodeManager::PutAddon(media_addon_id id)
bool unload; bool unload;
TRACE("DormantNodeManager::PutAddon, id %ld\n",id); TRACE("DormantNodeManager::PutAddon, id %ld\n",id);
fLock->Lock(); fLock->Lock();
if (!fAddonmap->Get(id, &info)) { if (!fAddonmap->Get(id, &info)) {
ERROR("DormantNodeManager::PutAddon: failed to find add-on %ld\n",id); ERROR("DormantNodeManager::PutAddon: failed to find add-on %ld\n",id);
@@ -204,9 +204,9 @@ DormantNodeManager::RegisterAddon(const char *path)
status_t rv; status_t rv;
int32 code; int32 code;
entry_ref tempref; entry_ref tempref;
TRACE("DormantNodeManager::RegisterAddon, path %s\n",path); TRACE("DormantNodeManager::RegisterAddon, path %s\n",path);
rv = get_ref_for_path(path, &tempref); rv = get_ref_for_path(path, &tempref);
if (rv != B_OK) { if (rv != B_OK) {
ERROR("DormantNodeManager::RegisterAddon failed, couldn't get ref for path %s\n",path); ERROR("DormantNodeManager::RegisterAddon failed, couldn't get ref for path %s\n",path);
@@ -232,9 +232,10 @@ DormantNodeManager::RegisterAddon(const char *path)
return 0; return 0;
} }
TRACE("DormantNodeManager::RegisterAddon finished with id %ld\n",reply.addonid); TRACE("DormantNodeManager::RegisterAddon finished with id %ld\n",
reply.addon_id);
return reply.addonid; return reply.addon_id;
} }
// For use by media_addon_server only // For use by media_addon_server only
@@ -250,7 +251,7 @@ DormantNodeManager::UnregisterAddon(media_addon_id id)
port = find_port(MEDIA_SERVER_PORT_NAME); port = find_port(MEDIA_SERVER_PORT_NAME);
if (port <= B_OK) if (port <= B_OK)
return; return;
msg.addonid = id; msg.addon_id = id;
write_port(port, SERVER_UNREGISTER_MEDIAADDON, &msg, sizeof(msg)); write_port(port, SERVER_UNREGISTER_MEDIAADDON, &msg, sizeof(msg));
} }
@@ -267,7 +268,7 @@ DormantNodeManager::FindAddonPath(BPath *path, media_addon_id id)
port = find_port(MEDIA_SERVER_PORT_NAME); port = find_port(MEDIA_SERVER_PORT_NAME);
if (port <= B_OK) if (port <= B_OK)
return B_ERROR; return B_ERROR;
msg.addonid = id; msg.addon_id = id;
msg.reply_port = _PortPool->GetPort(); msg.reply_port = _PortPool->GetPort();
rv = write_port(port, SERVER_GET_MEDIAADDON_REF, &msg, sizeof(msg)); rv = write_port(port, SERVER_GET_MEDIAADDON_REF, &msg, sizeof(msg));
if (rv != B_OK) { if (rv != B_OK) {
@@ -291,33 +292,33 @@ DormantNodeManager::LoadAddon(BMediaAddOn **newaddon, image_id *newimage, const
BMediaAddOn *addon; BMediaAddOn *addon;
image_id image; image_id image;
status_t rv; status_t rv;
image = load_add_on(path); image = load_add_on(path);
if (image < B_OK) { if (image < B_OK) {
ERROR("DormantNodeManager::LoadAddon: loading failed, error %lx (%s), path %s\n", image, strerror(image), path); ERROR("DormantNodeManager::LoadAddon: loading failed, error %lx (%s), path %s\n", image, strerror(image), path);
return B_ERROR; return B_ERROR;
} }
rv = get_image_symbol(image, "make_media_addon", B_SYMBOL_TYPE_TEXT, (void**)&make_addon); rv = get_image_symbol(image, "make_media_addon", B_SYMBOL_TYPE_TEXT, (void**)&make_addon);
if (rv < B_OK) { if (rv < B_OK) {
ERROR("DormantNodeManager::LoadAddon: loading failed, function not found, error %lx (%s)\n", rv, strerror(rv)); ERROR("DormantNodeManager::LoadAddon: loading failed, function not found, error %lx (%s)\n", rv, strerror(rv));
unload_add_on(image); unload_add_on(image);
return B_ERROR; return B_ERROR;
} }
addon = make_addon(image); addon = make_addon(image);
if (addon == 0) { if (addon == 0) {
ERROR("DormantNodeManager::LoadAddon: creating BMediaAddOn failed\n"); ERROR("DormantNodeManager::LoadAddon: creating BMediaAddOn failed\n");
unload_add_on(image); unload_add_on(image);
return B_ERROR; return B_ERROR;
} }
ASSERT(addon->ImageID() == image); // this should be true for a well behaving add-on ASSERT(addon->ImageID() == image); // this should be true for a well behaving add-on
// everything ok // everything ok
*newaddon = addon; *newaddon = addon;
*newimage = image; *newimage = image;
// we are a friend class of BMediaAddOn and initialize these member variables // we are a friend class of BMediaAddOn and initialize these member variables
addon->fAddon = id; addon->fAddon = id;
addon->fImage = image; addon->fImage = image;
+2 -7
View File
@@ -7,17 +7,12 @@ if $(TARGET_PLATFORM) != haiku {
# We need the public media headers also when not compiling for Haiku. # We need the public media headers also when not compiling for Haiku.
} }
UsePrivateHeaders media shared ; UsePrivateHeaders app media shared ;
if $(CHECK_MALLOC) { if $(CHECK_MALLOC) {
SubDirC++Flags -D_NO_INLINE_ASM -fcheck-memory-usage ; SubDirC++Flags -D_NO_INLINE_ASM -fcheck-memory-usage ;
} }
# That's ugly. The header (ServerInterface.h) should reside in
# headers/private/media.
SubDirHdrs [ FDirName $(HAIKU_TOP) src servers media ] ;
SubDirSysHdrs $(SUBDIR) ; # for the Old*.h headers
SharedLibrary libmedia.so : SharedLibrary libmedia.so :
# Private Media Kit # Private Media Kit
!missing_symbols.cpp !missing_symbols.cpp
@@ -52,7 +47,7 @@ SharedLibrary libmedia.so :
TimeSource.cpp TimeSource.cpp
# Internal Functionality # Internal Functionality
BufferIdCache.cpp BufferCache.cpp
DataExchange.cpp DataExchange.cpp
DefaultMediaTheme.cpp DefaultMediaTheme.cpp
DormantNodeManager.cpp DormantNodeManager.cpp
+12 -12
View File
@@ -104,7 +104,7 @@ dormant_flavor_info::dormant_flavor_info()
} }
/* virtual */ /* virtual */
dormant_flavor_info::~dormant_flavor_info() dormant_flavor_info::~dormant_flavor_info()
{ {
delete [] name; delete [] name;
@@ -182,7 +182,7 @@ dormant_flavor_info::operator=(const flavor_info &clone)
// initialize node_info with default values from dormant_node_info constructor // initialize node_info with default values from dormant_node_info constructor
dormant_node_info defaultValues; dormant_node_info defaultValues;
node_info = defaultValues; node_info = defaultValues;
return *this; return *this;
} }
@@ -284,7 +284,7 @@ dormant_flavor_info::Flatten(void *buffer,
if (size < FlattenedSize()) if (size < FlattenedSize())
return B_ERROR; return B_ERROR;
char *buf = (char *)buffer; char *buf = (char *)buffer;
int32 nameLength = name ? (int32)strlen(name) : -1; int32 nameLength = name ? (int32)strlen(name) : -1;
int32 infoLength = info ? (int32)strlen(info) : -1; int32 infoLength = info ? (int32)strlen(info) : -1;
int32 inFormatCount = 0; int32 inFormatCount = 0;
@@ -362,7 +362,7 @@ dormant_flavor_info::Unflatten(type_code c,
if (size < 8) if (size < 8)
return B_ERROR; return B_ERROR;
const char *buf = (const char *)buffer; const char *buf = (const char *)buffer;
int32 nameLength; int32 nameLength;
int32 infoLength; int32 infoLength;
@@ -409,7 +409,7 @@ dormant_flavor_info::Unflatten(type_code c,
} }
int32 count; int32 count;
kinds = *(uint64*)buf; buf += sizeof(uint64); kinds = *(uint64*)buf; buf += sizeof(uint64);
flavor_flags = *(uint32*)buf; buf += sizeof(uint32); flavor_flags = *(uint32*)buf; buf += sizeof(uint32);
internal_id = *(int32*)buf; buf += sizeof(int32); internal_id = *(int32*)buf; buf += sizeof(int32);
@@ -423,12 +423,12 @@ dormant_flavor_info::Unflatten(type_code c,
if (!in_formats) if (!in_formats)
return B_NO_MEMORY; return B_NO_MEMORY;
// XXX FIXME! we should not!!! make flat copies of media_format // XXX FIXME! we should not!!! make flat copies of media_format
memcpy(const_cast<media_format *>(in_formats), buf, count * sizeof(media_format)); memcpy(const_cast<media_format *>(in_formats), buf, count * sizeof(media_format));
in_format_count = count; in_format_count = count;
} }
buf += count * sizeof(media_format); // XXX not save buf += count * sizeof(media_format); // XXX not save
} }
count = *(int32*)buf; buf += sizeof(int32); count = *(int32*)buf; buf += sizeof(int32);
out_format_flags = *(uint32*)buf; buf += sizeof(uint32); out_format_flags = *(uint32*)buf; buf += sizeof(uint32);
@@ -438,14 +438,14 @@ dormant_flavor_info::Unflatten(type_code c,
if (!out_formats) if (!out_formats)
return B_NO_MEMORY; return B_NO_MEMORY;
// XXX FIXME! we should not!!! make flat copies of media_format // XXX FIXME! we should not!!! make flat copies of media_format
memcpy(const_cast<media_format *>(out_formats), buf, count * sizeof(media_format)); memcpy(const_cast<media_format *>(out_formats), buf, count * sizeof(media_format));
out_format_count = count; out_format_count = count;
} }
buf += count * sizeof(media_format); // XXX not save buf += count * sizeof(media_format); // XXX not save
} }
node_info = *(dormant_node_info*)buf; buf += sizeof(dormant_node_info); node_info = *(dormant_node_info*)buf; buf += sizeof(dormant_node_info);
return B_OK; return B_OK;
} }
@@ -453,7 +453,7 @@ dormant_flavor_info::Unflatten(type_code c,
* public BMediaAddOn * public BMediaAddOn
*************************************************************/ *************************************************************/
/* explicit */ /* explicit */
BMediaAddOn::BMediaAddOn(image_id image) : BMediaAddOn::BMediaAddOn(image_id image) :
fImage(image), fImage(image),
fAddon(0) fAddon(0)
@@ -462,7 +462,7 @@ BMediaAddOn::BMediaAddOn(image_id image) :
} }
/* virtual */ /* virtual */
BMediaAddOn::~BMediaAddOn() BMediaAddOn::~BMediaAddOn()
{ {
CALLED(); CALLED();
@@ -617,7 +617,7 @@ BMediaAddOn::NotifyFlavorChange()
return B_ERROR; return B_ERROR;
addonserver_rescan_mediaaddon_flavors_command command; addonserver_rescan_mediaaddon_flavors_command command;
command.addonid = fAddon; command.addon_id = fAddon;
return SendToAddonServer(ADDONSERVER_RESCAN_MEDIAADDON_FLAVORS, &command, sizeof(command)); return SendToAddonServer(ADDONSERVER_RESCAN_MEDIAADDON_FLAVORS, &command, sizeof(command));
} }
+125 -125
View File
@@ -31,7 +31,6 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*
*/ */
@@ -39,7 +38,7 @@
char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002-2006 Marcus " char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002-2006 Marcus "
"Overhagen <[email protected]>"; "Overhagen <[email protected]>";
//#define DEBUG 7
#include <MediaRoster.h> #include <MediaRoster.h>
#include <new> #include <new>
@@ -56,6 +55,8 @@ char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002-2006 Marcus "
#include <String.h> #include <String.h>
#include <TimeSource.h> #include <TimeSource.h>
#include <AppMisc.h>
#include "debug.h" #include "debug.h"
#include "MediaRosterEx.h" #include "MediaRosterEx.h"
#include "MediaMisc.h" #include "MediaMisc.h"
@@ -68,39 +69,43 @@ char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002-2006 Marcus "
namespace BPrivate { namespace media { namespace BPrivate { namespace media {
// the BMediaRoster destructor is private, // the BMediaRoster destructor is private,
// but _DefaultDeleter is a friend class of // but _DefaultDeleter is a friend class of
// the BMediaRoster an thus can delete it // the BMediaRoster an thus can delete it
class DefaultDeleter class DefaultDeleter {
public:
~DefaultDeleter()
{ {
public: if (BMediaRoster::sDefaultInstance != NULL) {
~DefaultDeleter() BMediaRoster::sDefaultInstance->Lock();
{ BMediaRoster::sDefaultInstance->Quit();
if (BMediaRoster::sDefaultInstance) {
BMediaRoster::sDefaultInstance->Lock();
BMediaRoster::sDefaultInstance->Quit();
}
} }
}; }
};
} // namespace media
} // namespace BPrivate
} } // BPrivate::media
using namespace BPrivate::media; using namespace BPrivate::media;
// DefaultDeleter will delete the BMediaRoster object in it's destructor. // DefaultDeleter will delete the BMediaRoster object in it's destructor.
DefaultDeleter _deleter; DefaultDeleter _deleter;
BMediaRosterEx::BMediaRosterEx(status_t* _error) BMediaRosterEx::BMediaRosterEx(status_t* _error)
: BMediaRoster() :
BMediaRoster()
{ {
status_t rv;
// register this application with the media server // register this application with the media server
server_register_app_request request; server_register_app_request request;
server_register_app_reply reply; server_register_app_reply reply;
request.team = team; request.team = BPrivate::current_team();
request.messenger = BMessenger(NULL, this); request.messenger = BMessenger(NULL, this);
rv = QueryServer(SERVER_REGISTER_APP, &request, sizeof(request), &reply,
sizeof(reply)); status_t status = QueryServer(SERVER_REGISTER_APP, &request,
if (rv != B_OK) sizeof(request), &reply, sizeof(reply));
if (status != B_OK)
*_error = B_MEDIA_SYSTEM_FAILURE; *_error = B_MEDIA_SYSTEM_FAILURE;
else else
*_error = B_OK; *_error = B_OK;
@@ -110,11 +115,9 @@ BMediaRosterEx::BMediaRosterEx(status_t* _error)
status_t status_t
BMediaRosterEx::SaveNodeConfiguration(BMediaNode* node) BMediaRosterEx::SaveNodeConfiguration(BMediaNode* node)
{ {
BMediaAddOn *addon; int32 flavorID;
media_addon_id addonid; BMediaAddOn* addon = node->AddOn(&flavorID);
int32 flavorid; if (addon == NULL) {
addon = node->AddOn(&flavorid);
if (!addon) {
// NOTE: This node could have been created by an application, // NOTE: This node could have been created by an application,
// it does not mean there is an error. // it does not mean there is an error.
// TODO: this check incorrectly triggers on BeOS R5 BT848 node // TODO: this check incorrectly triggers on BeOS R5 BT848 node
@@ -122,54 +125,55 @@ BMediaRosterEx::SaveNodeConfiguration(BMediaNode* node)
"from BMediaAddOn!\n", node->ID()); "from BMediaAddOn!\n", node->ID());
return B_ERROR; return B_ERROR;
} }
addonid = addon->AddonID();
media_addon_id addonID = addon->AddonID();
// TODO: fix this // TODO: fix this
printf("### BMediaRosterEx::SaveNodeConfiguration should save addon-id " printf("### BMediaRosterEx::SaveNodeConfiguration should save addon-id "
"%ld, flavor-id %ld config NOW!\n", addonid, flavorid); "%ld, flavor-id %ld config NOW!\n", addonID, flavorID);
return B_OK; return B_OK;
} }
status_t status_t
BMediaRosterEx::LoadNodeConfiguration(media_addon_id addonid, int32 flavorid, BMediaRosterEx::LoadNodeConfiguration(media_addon_id addonID, int32 flavorID,
BMessage *out_msg) BMessage *_msg)
{ {
// TODO: fix this // TODO: fix this
out_msg->MakeEmpty(); // to be fully R5 compliant _msg->MakeEmpty(); // to be fully R5 compliant
printf("### BMediaRosterEx::LoadNodeConfiguration should load addon-id " printf("### BMediaRosterEx::LoadNodeConfiguration should load addon-id "
"%ld, flavor-id %ld config NOW!\n", addonid, flavorid); "%ld, flavor-id %ld config NOW!\n", addonID, flavorID);
return B_OK; return B_OK;
} }
status_t status_t
BMediaRosterEx::IncrementAddonFlavorInstancesCount(media_addon_id addonid, BMediaRosterEx::IncrementAddonFlavorInstancesCount(media_addon_id addonID,
int32 flavorid) int32 flavorID)
{ {
server_change_addon_flavor_instances_count_request request; server_change_addon_flavor_instances_count_request request;
server_change_addon_flavor_instances_count_reply reply; server_change_addon_flavor_instances_count_reply reply;
request.addonid = addonid; request.addon_id = addonID;
request.flavorid = flavorid; request.flavor_id = flavorID;
request.delta = 1; request.delta = 1;
request.team = team; request.team = BPrivate::current_team();
return QueryServer(SERVER_CHANGE_ADDON_FLAVOR_INSTANCES_COUNT, &request, return QueryServer(SERVER_CHANGE_ADDON_FLAVOR_INSTANCES_COUNT, &request,
sizeof(request), &reply, sizeof(reply)); sizeof(request), &reply, sizeof(reply));
} }
status_t status_t
BMediaRosterEx::DecrementAddonFlavorInstancesCount(media_addon_id addonid, BMediaRosterEx::DecrementAddonFlavorInstancesCount(media_addon_id addonID,
int32 flavorid) int32 flavorID)
{ {
server_change_addon_flavor_instances_count_request request; server_change_addon_flavor_instances_count_request request;
server_change_addon_flavor_instances_count_reply reply; server_change_addon_flavor_instances_count_reply reply;
request.addonid = addonid; request.addon_id = addonID;
request.flavorid = flavorid; request.flavor_id = flavorID;
request.delta = -1; request.delta = -1;
request.team = team; request.team = BPrivate::current_team();
return QueryServer(SERVER_CHANGE_ADDON_FLAVOR_INSTANCES_COUNT, &request, return QueryServer(SERVER_CHANGE_ADDON_FLAVOR_INSTANCES_COUNT, &request,
sizeof(request), &reply, sizeof(reply)); sizeof(request), &reply, sizeof(reply));
} }
@@ -200,7 +204,7 @@ BMediaRosterEx::GetNode(node_type type, media_node* out_node,
status_t rv; status_t rv;
request.type = type; request.type = type;
request.team = team; request.team = BPrivate::current_team();
rv = QueryServer(SERVER_GET_NODE, &request, sizeof(request), &reply, rv = QueryServer(SERVER_GET_NODE, &request, sizeof(request), &reply,
sizeof(reply)); sizeof(reply));
if (rv != B_OK) if (rv != B_OK)
@@ -565,7 +569,7 @@ BMediaRoster::GetAudioOutput(media_node* _node, int32* _inputID,
_inputName); _inputName);
} }
status_t status_t
BMediaRoster::GetTimeSource(media_node* _node) BMediaRoster::GetTimeSource(media_node* _node)
{ {
@@ -673,8 +677,8 @@ BMediaRoster::GetNodeFor(media_node_id node, media_node* clone)
server_get_node_for_reply reply; server_get_node_for_reply reply;
status_t rv; status_t rv;
request.nodeid = node; request.node_id = node;
request.team = team; request.team = BPrivate::current_team();
rv = QueryServer(SERVER_GET_NODE_FOR, &request, sizeof(request), &reply, rv = QueryServer(SERVER_GET_NODE_FOR, &request, sizeof(request), &reply,
sizeof(reply)); sizeof(reply));
@@ -720,7 +724,7 @@ BMediaRoster::ReleaseNode(const media_node& node)
if (node.kind & NODE_KIND_NO_REFCOUNTING) { if (node.kind & NODE_KIND_NO_REFCOUNTING) {
printf("BMediaRoster::ReleaseNode, trying to release reference " printf("BMediaRoster::ReleaseNode, trying to release reference "
"counting disabled timesource, node %ld, port %ld, team %ld\n", "counting disabled timesource, node %ld, port %ld, team %ld\n",
node.node, node.port, team); node.node, node.port, BPrivate::current_team());
return B_OK; return B_OK;
} }
@@ -729,16 +733,16 @@ BMediaRoster::ReleaseNode(const media_node& node)
status_t rv; status_t rv;
request.node = node; request.node = node;
request.team = team; request.team = BPrivate::current_team();
TRACE("BMediaRoster::ReleaseNode, node %ld, port %ld, team %ld\n", TRACE("BMediaRoster::ReleaseNode, node %ld, port %ld, team %ld\n",
node.node, node.port, team); node.node, node.port, BPrivate::current_team());
rv = QueryServer(SERVER_RELEASE_NODE, &request, sizeof(request), &reply, rv = QueryServer(SERVER_RELEASE_NODE, &request, sizeof(request), &reply,
sizeof(reply)); sizeof(reply));
if (rv != B_OK) { if (rv != B_OK) {
ERROR("BMediaRoster::ReleaseNode FAILED, node %ld, port %ld, team " ERROR("BMediaRoster::ReleaseNode FAILED, node %ld, port %ld, team "
"%ld!\n", node.node, node.port, team); "%ld!\n", node.node, node.port, BPrivate::current_team());
} }
return rv; return rv;
} }
@@ -1159,7 +1163,7 @@ BMediaRoster::StopNode(const media_node& node, bigtime_t atPerformanceTime,
return SendToPort(node.port, NODE_STOP, &command, sizeof(command)); return SendToPort(node.port, NODE_STOP, &command, sizeof(command));
} }
status_t status_t
BMediaRoster::SeekNode(const media_node& node, bigtime_t toMediaTime, BMediaRoster::SeekNode(const media_node& node, bigtime_t toMediaTime,
bigtime_t atPerformanceTime) bigtime_t atPerformanceTime)
@@ -1213,7 +1217,7 @@ BMediaRoster::StartTimeSource(const media_node& node, bigtime_t atRealTime)
return write_port(node.port, TIMESOURCE_OP, &msg, sizeof(msg)); return write_port(node.port, TIMESOURCE_OP, &msg, sizeof(msg));
} }
status_t status_t
BMediaRoster::StopTimeSource(const media_node& node, bigtime_t atRealTime, BMediaRoster::StopTimeSource(const media_node& node, bigtime_t atRealTime,
bool immediate) bool immediate)
@@ -1250,7 +1254,7 @@ BMediaRoster::StopTimeSource(const media_node& node, bigtime_t atRealTime,
return write_port(node.port, TIMESOURCE_OP, &msg, sizeof(msg)); return write_port(node.port, TIMESOURCE_OP, &msg, sizeof(msg));
} }
status_t status_t
BMediaRoster::SeekTimeSource(const media_node& node, BMediaRoster::SeekTimeSource(const media_node& node,
bigtime_t toPerformanceTime, bigtime_t atRealTime) bigtime_t toPerformanceTime, bigtime_t atRealTime)
@@ -1312,7 +1316,7 @@ BMediaRoster::SetRunModeNode(const media_node& node, BMediaNode::run_mode mode)
return write_port(node.port, NODE_SET_RUN_MODE, &msg, sizeof(msg)); return write_port(node.port, NODE_SET_RUN_MODE, &msg, sizeof(msg));
} }
status_t status_t
BMediaRoster::PrerollNode(const media_node& node) BMediaRoster::PrerollNode(const media_node& node)
{ {
@@ -1880,8 +1884,8 @@ BMediaRoster::RegisterNode(BMediaNode* node)
status_t status_t
BMediaRosterEx::RegisterNode(BMediaNode* node, media_addon_id addonid, BMediaRosterEx::RegisterNode(BMediaNode* node, media_addon_id addonID,
int32 flavorid) int32 flavorID)
{ {
CALLED(); CALLED();
if (node == NULL) if (node == NULL)
@@ -1890,27 +1894,24 @@ BMediaRosterEx::RegisterNode(BMediaNode* node, media_addon_id addonid,
// some sanity check // some sanity check
// I'm not sure if the media kit warrants to call BMediaNode::AddOn() here. // I'm not sure if the media kit warrants to call BMediaNode::AddOn() here.
// Perhaps we don't need it. // Perhaps we don't need it.
{ DEBUG_ONLY(
BMediaAddOn *addon; int32 testFlavorID;
int32 addon_flavor_id; BMediaAddOn* addon = node->AddOn(&testFlavorID);
media_addon_id addon_id;
addon_flavor_id = 0; ASSERT(addonID == addon != NULL ? addon->AddonID() : -1);
addon = node->AddOn(&addon_flavor_id); ASSERT(flavorID == testFlavorID);
addon_id = addon ? addon->AddonID() : -1; );
ASSERT(addonid == addon_id);
ASSERT(flavorid == addon_flavor_id);
}
status_t rv; status_t rv;
server_register_node_request request; server_register_node_request request;
server_register_node_reply reply; server_register_node_reply reply;
request.addon_id = addonid; request.addon_id = addonID;
request.addon_flavor_id = flavorid; request.addon_flavor_id = flavorID;
strcpy(request.name, node->Name()); strcpy(request.name, node->Name());
request.kinds = node->Kinds(); request.kinds = node->Kinds();
request.port = node->ControlPort(); request.port = node->ControlPort();
request.team = team; request.team = BPrivate::current_team();
TRACE("BMediaRoster::RegisterNode: sending SERVER_REGISTER_NODE: port " TRACE("BMediaRoster::RegisterNode: sending SERVER_REGISTER_NODE: port "
"%ld, kinds 0x%Lx, team %ld, name '%s'\n", request.port, request.kinds, "%ld, kinds 0x%Lx, team %ld, name '%s'\n", request.port, request.kinds,
@@ -1928,9 +1929,9 @@ BMediaRosterEx::RegisterNode(BMediaNode* node, media_addon_id addonid,
"finished\n"); "finished\n");
// we are a friend class of BMediaNode and initialize this member variable // we are a friend class of BMediaNode and initialize this member variable
node->fNodeID = reply.nodeid; node->fNodeID = reply.node_id;
ASSERT(reply.nodeid == node->Node().node); ASSERT(reply.node_id == node->Node().node);
ASSERT(reply.nodeid == node->ID()); ASSERT(reply.node_id == node->ID());
// call the callback // call the callback
node->NodeRegistered(); node->NodeRegistered();
@@ -1964,19 +1965,18 @@ BMediaRosterEx::RegisterNode(BMediaNode* node, media_addon_id addonid,
PublishOutputs(node->Node(), &list); PublishOutputs(node->Node(), &list);
} }
} }
if (node->Kinds() & B_BUFFER_CONSUMER) { if ((node->Kinds() & B_BUFFER_CONSUMER) != 0) {
BBufferConsumer *bc; BBufferConsumer* consumer = dynamic_cast<BBufferConsumer*>(node);
bc = dynamic_cast<BBufferConsumer *>(node); if (consumer != NULL) {
if (bc) {
List<media_input> list; List<media_input> list;
if (B_OK == GetAllInputs(bc, &list)) if (GetAllInputs(consumer, &list) == B_OK)
PublishInputs(node->Node(), &list); PublishInputs(node->Node(), &list);
} }
} }
TRACE("BMediaRoster::RegisterNode: sending NodesCreated\n"); TRACE("BMediaRoster::RegisterNode: sending NodesCreated\n");
BPrivate::media::notifications::NodesCreated(&reply.nodeid, 1); BPrivate::media::notifications::NodesCreated(&reply.node_id, 1);
TRACE("BMediaRoster::RegisterNode: finished\n"); TRACE("BMediaRoster::RegisterNode: finished\n");
@@ -2005,7 +2005,7 @@ BMediaRoster::UnregisterNode(BMediaNode* node)
if (node->fKinds & NODE_KIND_NO_REFCOUNTING) { if (node->fKinds & NODE_KIND_NO_REFCOUNTING) {
TRACE("BMediaRoster::UnregisterNode, trying to unregister reference " TRACE("BMediaRoster::UnregisterNode, trying to unregister reference "
"counting disabled timesource, node %ld, port %ld, team %ld\n", "counting disabled timesource, node %ld, port %ld, team %ld\n",
node->ID(), node->ControlPort(), team); node->ID(), node->ControlPort(), BPrivate::current_team());
return B_OK; return B_OK;
} }
if (node->ID() == NODE_UNREGISTERED_ID) { if (node->ID() == NODE_UNREGISTERED_ID) {
@@ -2030,11 +2030,11 @@ BMediaRoster::UnregisterNode(BMediaNode* node)
server_unregister_node_reply reply; server_unregister_node_reply reply;
status_t rv; status_t rv;
request.nodeid = node->ID(); request.node_id = node->ID();
request.team = team; request.team = BPrivate::current_team();
// send a notification // send a notification
BPrivate::media::notifications::NodesDeleted(&request.nodeid, 1); BPrivate::media::notifications::NodesDeleted(&request.node_id, 1);
rv = QueryServer(SERVER_UNREGISTER_NODE, &request, sizeof(request), &reply, rv = QueryServer(SERVER_UNREGISTER_NODE, &request, sizeof(request), &reply,
sizeof(reply)); sizeof(reply));
@@ -2044,17 +2044,17 @@ BMediaRoster::UnregisterNode(BMediaNode* node)
return rv; return rv;
} }
if (reply.addonid != -1) { if (reply.addon_id != -1) {
// Small problem here, we can't use DormantNodeManager::PutAddon(), as // Small problem here, we can't use DormantNodeManager::PutAddon(), as
// UnregisterNode() is called by a dormant node itself (by the // UnregisterNode() is called by a dormant node itself (by the
// destructor). // destructor).
// The add-on that contains the node needs to remain in memory until the // The add-on that contains the node needs to remain in memory until the
// destructor execution is finished. // destructor execution is finished.
// DormantNodeManager::PutAddonDelayed() will delay unloading. // DormantNodeManager::PutAddonDelayed() will delay unloading.
_DormantNodeManager->PutAddonDelayed(reply.addonid); _DormantNodeManager->PutAddonDelayed(reply.addon_id);
rv = MediaRosterEx(this)->DecrementAddonFlavorInstancesCount( rv = MediaRosterEx(this)->DecrementAddonFlavorInstancesCount(
reply.addonid, reply.flavorid); reply.addon_id, reply.flavor_id);
if (rv != B_OK) { if (rv != B_OK) {
ERROR("BMediaRoster::UnregisterNode: " ERROR("BMediaRoster::UnregisterNode: "
"DecrementAddonFlavorInstancesCount() failed\n"); "DecrementAddonFlavorInstancesCount() failed\n");
@@ -2275,16 +2275,16 @@ BMediaRoster::GetDormantNodes(dormant_node_info* _info, int32* _count,
if (port <= B_OK) if (port <= B_OK)
return B_ERROR; return B_ERROR;
msg.maxcount = *_count; msg.max_count = *_count;
msg.has_input = hasInput != NULL; msg.has_input = hasInput != NULL;
if (hasInput != NULL) { if (hasInput != NULL) {
// TODO: we should not make a flat copy of media_format // TODO: we should not make a flat copy of media_format
msg.inputformat = *hasInput; msg.input_format = *hasInput;
} }
msg.has_output = hasOutput != NULL; msg.has_output = hasOutput != NULL;
if (hasOutput != NULL) { if (hasOutput != NULL) {
// TODO: we should not make a flat copy of media_format // TODO: we should not make a flat copy of media_format
msg.outputformat = *hasOutput; msg.output_format = *hasOutput;
} }
msg.has_name = name != NULL; msg.has_name = name != NULL;
@@ -2459,7 +2459,7 @@ BMediaRosterEx::InstantiateDormantNode(media_addon_id addonID, int32 flavorID,
TRACE("BMediaRosterEx::InstantiateDormantNode: addon-id %ld, flavor_id " TRACE("BMediaRosterEx::InstantiateDormantNode: addon-id %ld, flavor_id "
"%ld instanciated as node %ld, port %ld in team %ld\n", addonID, "%ld instanciated as node %ld, port %ld in team %ld\n", addonID,
flavorID, _node->node, _node->port, team); flavorID, _node->node, _node->port, BPrivate::current_team());
return B_OK; return B_OK;
} }
@@ -2548,9 +2548,9 @@ BMediaRoster::InstantiateDormantNode(const dormant_node_info& info,
addonserver_instantiate_dormant_node_request request; addonserver_instantiate_dormant_node_request request;
addonserver_instantiate_dormant_node_reply reply; addonserver_instantiate_dormant_node_reply reply;
request.addonid = info.addon; request.addon_id = info.addon;
request.flavorid = info.flavor_id; request.flavor_id = info.flavor_id;
request.creator_team = team; request.creator_team = BPrivate::current_team();
// creator team is allowed to also release global nodes // creator team is allowed to also release global nodes
rv = QueryAddonServer(ADDONSERVER_INSTANTIATE_DORMANT_NODE, &request, rv = QueryAddonServer(ADDONSERVER_INSTANTIATE_DORMANT_NODE, &request,
sizeof(request), &reply, sizeof(reply)); sizeof(request), &reply, sizeof(reply));
@@ -2568,7 +2568,7 @@ BMediaRoster::InstantiateDormantNode(const dormant_node_info& info,
return B_OK; return B_OK;
} }
status_t status_t
BMediaRoster::InstantiateDormantNode(const dormant_node_info& info, BMediaRoster::InstantiateDormantNode(const dormant_node_info& info,
media_node* _node) media_node* _node)
@@ -2611,44 +2611,44 @@ BMediaRosterEx::GetDormantFlavorInfo(media_addon_id addonID, int32 flavorID,
if (_flavor == NULL) if (_flavor == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
xfer_server_get_dormant_flavor_info msg; port_id port = find_port(MEDIA_SERVER_PORT_NAME);
xfer_server_get_dormant_flavor_info_reply *reply; if (port < 0)
port_id port;
status_t rv;
int32 code;
port = find_port(MEDIA_SERVER_PORT_NAME);
if (port < B_OK)
return B_ERROR; return B_ERROR;
reply = (xfer_server_get_dormant_flavor_info_reply*)malloc(16000); xfer_server_get_dormant_flavor_info_reply* reply
= (xfer_server_get_dormant_flavor_info_reply*)malloc(16300);
if (reply == NULL) if (reply == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
xfer_server_get_dormant_flavor_info msg;
msg.addon = addonID; msg.addon = addonID;
msg.flavor_id = flavorID; msg.flavor_id = flavorID;
msg.reply_port = _PortPool->GetPort(); msg.reply_port = _PortPool->GetPort();
rv = write_port(port, SERVER_GET_DORMANT_FLAVOR_INFO, &msg, sizeof(msg)); status_t status = write_port(port, SERVER_GET_DORMANT_FLAVOR_INFO, &msg,
if (rv != B_OK) { sizeof(msg));
if (status != B_OK) {
free(reply); free(reply);
_PortPool->PutPort(msg.reply_port); _PortPool->PutPort(msg.reply_port);
return rv; return status;
} }
rv = read_port(msg.reply_port, &code, reply, 16000);
int32 code;
status = read_port(msg.reply_port, &code, reply, 16000);
_PortPool->PutPort(msg.reply_port); _PortPool->PutPort(msg.reply_port);
if (rv < B_OK) { if (status < B_OK) {
free(reply); free(reply);
return rv; return status;
} }
if (reply->result == B_OK) if (reply->result == B_OK) {
rv = _flavor->Unflatten(reply->dfi_type, &reply->dfi, reply->dfi_size); status = _flavor->Unflatten(reply->type, &reply->flattened_data,
else reply->flattened_size);
rv = reply->result; } else
status = reply->result;
free(reply); free(reply);
return rv; return status;
} }
@@ -2855,20 +2855,20 @@ BMediaRoster::SniffRef(const entry_ref& file, uint64 requireNodeKinds,
return B_BAD_VALUE; return B_BAD_VALUE;
BMimeType aMimeType; BMimeType aMimeType;
dormant_node_info nodes[30]; dormant_node_info nodes[30];
int32 count = 30; int32 count = 30;
int32 highestCapability = -1; int32 highestCapability = -1;
float capability; float capability;
media_node node; media_node node;
// Get all dormant nodes using GetDormantNodes // Get all dormant nodes using GetDormantNodes
if (GetDormantNodes(nodes, &count, NULL, NULL, NULL, requireNodeKinds | B_FILE_INTERFACE, 0) == B_OK) { if (GetDormantNodes(nodes, &count, NULL, NULL, NULL, requireNodeKinds | B_FILE_INTERFACE, 0) == B_OK) {
// Call SniffRefFor on each node that matches requireNodeKinds // Call SniffRefFor on each node that matches requireNodeKinds
for (int32 i=0;i<count;i++) { for (int32 i=0;i<count;i++) {
if (InstantiateDormantNode(nodes[i], &node) == B_OK) { if (InstantiateDormantNode(nodes[i], &node) == B_OK) {
if (SniffRefFor(node, file, &aMimeType, &capability) == B_OK) { if (SniffRefFor(node, file, &aMimeType, &capability) == B_OK) {
// find the first node that has 100% capability // find the first node that has 100% capability
TRACE("%s has a %f%% chance of playing file\n",nodes[i].name, capability * 100.0); TRACE("%s has a %f%% chance of playing file\n",nodes[i].name, capability * 100.0);
@@ -2880,22 +2880,22 @@ BMediaRoster::SniffRef(const entry_ref& file, uint64 requireNodeKinds,
ReleaseNode(node); ReleaseNode(node);
} }
} }
if (highestCapability != -1) { if (highestCapability != -1) {
*_node = nodes[highestCapability]; *_node = nodes[highestCapability];
TRACE("BMediaRoster::SniffRef: found a node %s addon-id %ld, flavor_id %ld\n", TRACE("BMediaRoster::SniffRef: found a node %s addon-id %ld, flavor_id %ld\n",
nodes[highestCapability].name, nodes[highestCapability].addon, nodes[highestCapability].flavor_id); nodes[highestCapability].name, nodes[highestCapability].addon, nodes[highestCapability].flavor_id);
if (mimeType != NULL) { if (mimeType != NULL) {
//*mimeType = aMimeType; -- need a copy constructor //*mimeType = aMimeType; -- need a copy constructor
} }
return B_OK; return B_OK;
} }
} }
return B_ERROR; return B_ERROR;
} }
@@ -3028,7 +3028,7 @@ BMediaRoster::NodeIDFor(port_id port)
return -1; return -1;
} }
return reply.nodeid; return reply.node_id;
} }
@@ -3118,7 +3118,7 @@ BMediaRoster::AudioBufferSizeFor(int32 channelCount, uint32 sampleFormat,
return bufferSize; return bufferSize;
} }
/*! Use MediaFlags to inquire about specific features of the Media Kit. /*! Use MediaFlags to inquire about specific features of the Media Kit.
Returns < 0 for "not present", positive size for output data size. Returns < 0 for "not present", positive size for output data size.
0 means that the capability is present, but no data about it. 0 means that the capability is present, but no data about it.
@@ -3202,7 +3202,7 @@ BMediaRoster::~BMediaRoster()
// unregister this application with the media server // unregister this application with the media server
server_unregister_app_request request; server_unregister_app_request request;
server_unregister_app_reply reply; server_unregister_app_reply reply;
request.team = team; request.team = BPrivate::current_team();
QueryServer(SERVER_UNREGISTER_APP, &request, sizeof(request), &reply, QueryServer(SERVER_UNREGISTER_APP, &request, sizeof(request), &reply,
sizeof(reply)); sizeof(reply));
+76 -48
View File
@@ -24,78 +24,90 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*
*/ */
/* This is a interface class for media kit notifications.
* It is private to the media kit which uses it to pass /*! This is a interface class for media kit notifications.
* notifications up to the media_server which will broadcast It is private to the media kit which uses it to pass notifications up to
* them. the media_server which will broadcast them.
*/ */
/* XXX The BeBook, MediaDefs.h and the BeOS R5 do list
* XXX different strings for the message data fields of // TODO: The BeBook, MediaDefs.h and the BeOS R5 do list
* XXX the notification messages. // different strings for the message data fields of
*/ // the notification messages.
#include "Notifications.h"
#include <Messenger.h> #include <Messenger.h>
#include <MediaNode.h> #include <MediaNode.h>
#include <AppMisc.h>
#include "debug.h" #include "debug.h"
#include "DataExchange.h" #include "DataExchange.h"
#include "Notifications.h"
namespace BPrivate { namespace BPrivate {
namespace media { namespace media {
extern team_id team;
namespace notifications { namespace notifications {
status_t status_t
Register(const BMessenger &notifyHandler, const media_node &node, int32 notification) Register(const BMessenger& notifyHandler, const media_node& node,
int32 notification)
{ {
CALLED(); CALLED();
BMessage msg(MEDIA_SERVER_REQUEST_NOTIFICATIONS); BMessage msg(MEDIA_SERVER_REQUEST_NOTIFICATIONS);
msg.AddInt32(NOTIFICATION_PARAM_WHAT, notification); msg.AddInt32(NOTIFICATION_PARAM_WHAT, notification);
msg.AddInt32(NOTIFICATION_PARAM_TEAM, team); msg.AddInt32(NOTIFICATION_PARAM_TEAM, BPrivate::current_team());
msg.AddMessenger(NOTIFICATION_PARAM_MESSENGER, notifyHandler); msg.AddMessenger(NOTIFICATION_PARAM_MESSENGER, notifyHandler);
msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); msg.AddData("node", B_RAW_TYPE, &node, sizeof(node));
return BPrivate::media::dataexchange::SendToServer(&msg); return BPrivate::media::dataexchange::SendToServer(&msg);
} }
status_t status_t
Unregister(const BMessenger &notifyHandler, const media_node &node, int32 notification) Unregister(const BMessenger& notifyHandler, const media_node& node,
int32 notification)
{ {
CALLED(); CALLED();
BMessage msg(MEDIA_SERVER_CANCEL_NOTIFICATIONS); BMessage msg(MEDIA_SERVER_CANCEL_NOTIFICATIONS);
msg.AddInt32(NOTIFICATION_PARAM_WHAT, notification); msg.AddInt32(NOTIFICATION_PARAM_WHAT, notification);
msg.AddInt32(NOTIFICATION_PARAM_TEAM, team); msg.AddInt32(NOTIFICATION_PARAM_TEAM, BPrivate::current_team());
msg.AddMessenger(NOTIFICATION_PARAM_MESSENGER, notifyHandler); msg.AddMessenger(NOTIFICATION_PARAM_MESSENGER, notifyHandler);
msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); msg.AddData("node", B_RAW_TYPE, &node, sizeof(node));
return BPrivate::media::dataexchange::SendToServer(&msg); return BPrivate::media::dataexchange::SendToServer(&msg);
} }
/*! Transmits the error code specified by \a what to anyone who's receiving
notifications from this node. If \a info isn't \c NULL, it's used as a
model message for the error notification message.
The message field "be:node_id" will contain the node ID.
*/
status_t status_t
ReportError(const media_node &node, BMediaNode::node_error what, const BMessage * info) ReportError(const media_node& node, BMediaNode::node_error what,
const BMessage* info)
{ {
/* Transmits the error code specified by whichError to anyone that's receiving notifications from
* this node. If info isn't NULL, it's used as a model message for the error notification message.
* The message field "be:node_id" will contain the node ID.
*/
CALLED(); CALLED();
BMessage msg; BMessage msg;
if (info) if (info != NULL)
msg = *info; msg = *info;
msg.what = MEDIA_SERVER_SEND_NOTIFICATIONS; msg.what = MEDIA_SERVER_SEND_NOTIFICATIONS;
msg.AddInt32(NOTIFICATION_PARAM_WHAT, what); msg.AddInt32(NOTIFICATION_PARAM_WHAT, what);
msg.AddInt32("be:node_id", node.node); msg.AddInt32("be:node_id", node.node);
msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); msg.AddData("node", B_RAW_TYPE, &node, sizeof(node));
return BPrivate::media::dataexchange::SendToServer(&msg); return BPrivate::media::dataexchange::SendToServer(&msg);
} }
void void
NodesCreated(const media_node_id *ids, int32 count) NodesCreated(const media_node_id* ids, int32 count)
{ {
CALLED(); CALLED();
BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS);
@@ -103,12 +115,13 @@ NodesCreated(const media_node_id *ids, int32 count)
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
msg.AddInt32("media_node_id", ids[i]); msg.AddInt32("media_node_id", ids[i]);
} }
BPrivate::media::dataexchange::SendToServer(&msg); BPrivate::media::dataexchange::SendToServer(&msg);
} }
void void
NodesDeleted(const media_node_id *ids, int32 count) NodesDeleted(const media_node_id* ids, int32 count)
{ {
CALLED(); CALLED();
BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS);
@@ -116,12 +129,14 @@ NodesDeleted(const media_node_id *ids, int32 count)
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
msg.AddInt32("media_node_id", ids[i]); msg.AddInt32("media_node_id", ids[i]);
} }
BPrivate::media::dataexchange::SendToServer(&msg); BPrivate::media::dataexchange::SendToServer(&msg);
} }
void void
ConnectionMade(const media_input &input, const media_output &output, const media_format &format) ConnectionMade(const media_input& input, const media_output& output,
const media_format& format)
{ {
CALLED(); CALLED();
BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS);
@@ -129,24 +144,27 @@ ConnectionMade(const media_input &input, const media_output &output, const media
msg.AddData("input", B_RAW_TYPE, &input, sizeof(input)); msg.AddData("input", B_RAW_TYPE, &input, sizeof(input));
msg.AddData("output", B_RAW_TYPE, &output, sizeof(output)); msg.AddData("output", B_RAW_TYPE, &output, sizeof(output));
msg.AddData("format", B_RAW_TYPE, &format, sizeof(format)); msg.AddData("format", B_RAW_TYPE, &format, sizeof(format));
BPrivate::media::dataexchange::SendToServer(&msg); BPrivate::media::dataexchange::SendToServer(&msg);
} }
void void
ConnectionBroken(const media_source &source, const media_destination &destination) ConnectionBroken(const media_source& source,
const media_destination& destination)
{ {
CALLED(); CALLED();
BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS);
msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_CONNECTION_BROKEN); msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_CONNECTION_BROKEN);
msg.AddData("source", B_RAW_TYPE, &source, sizeof(source)); msg.AddData("source", B_RAW_TYPE, &source, sizeof(source));
msg.AddData("destination", B_RAW_TYPE, &destination, sizeof(destination)); msg.AddData("destination", B_RAW_TYPE, &destination, sizeof(destination));
BPrivate::media::dataexchange::SendToServer(&msg); BPrivate::media::dataexchange::SendToServer(&msg);
} }
void void
BuffersCreated(area_info *areas, int32 count) BuffersCreated(area_info* areas, int32 count)
{ {
CALLED(); CALLED();
BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS);
@@ -154,12 +172,13 @@ BuffersCreated(area_info *areas, int32 count)
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
msg.AddData("clone_info", B_RAW_TYPE, &areas[i], sizeof(area_info)); msg.AddData("clone_info", B_RAW_TYPE, &areas[i], sizeof(area_info));
} }
BPrivate::media::dataexchange::SendToServer(&msg); BPrivate::media::dataexchange::SendToServer(&msg);
} }
void void
BuffersDeleted(const media_buffer_id *ids, int32 count) BuffersDeleted(const media_buffer_id* ids, int32 count)
{ {
CALLED(); CALLED();
BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS);
@@ -167,12 +186,14 @@ BuffersDeleted(const media_buffer_id *ids, int32 count)
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
msg.AddInt32("media_buffer_id", ids[i]); msg.AddInt32("media_buffer_id", ids[i]);
} }
BPrivate::media::dataexchange::SendToServer(&msg); BPrivate::media::dataexchange::SendToServer(&msg);
} }
void void
FormatChanged(const media_source &source, const media_destination &destination, const media_format &format) FormatChanged(const media_source& source, const media_destination& destination,
const media_format& format)
{ {
CALLED(); CALLED();
BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS);
@@ -180,74 +201,81 @@ FormatChanged(const media_source &source, const media_destination &destination,
msg.AddData("source", B_RAW_TYPE, &source, sizeof(source)); msg.AddData("source", B_RAW_TYPE, &source, sizeof(source));
msg.AddData("destination", B_RAW_TYPE, &destination, sizeof(destination)); msg.AddData("destination", B_RAW_TYPE, &destination, sizeof(destination));
msg.AddData("format", B_RAW_TYPE, &format, sizeof(format)); msg.AddData("format", B_RAW_TYPE, &format, sizeof(format));
BPrivate::media::dataexchange::SendToServer(&msg); BPrivate::media::dataexchange::SendToServer(&msg);
} }
status_t status_t
ParameterChanged(const media_node &node, int32 parameterid) ParameterChanged(const media_node& node, int32 parameterID)
{ {
CALLED(); CALLED();
BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS);
msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_PARAMETER_CHANGED); msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_PARAMETER_CHANGED);
msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); msg.AddData("node", B_RAW_TYPE, &node, sizeof(node));
msg.AddInt32("parameter", parameterid); msg.AddInt32("parameter", parameterID);
return BPrivate::media::dataexchange::SendToServer(&msg); return BPrivate::media::dataexchange::SendToServer(&msg);
} }
void void
WebChanged(const media_node &node) WebChanged(const media_node& node)
{ {
CALLED(); CALLED();
BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS);
msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_WEB_CHANGED); msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_WEB_CHANGED);
msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); msg.AddData("node", B_RAW_TYPE, &node, sizeof(node));
BPrivate::media::dataexchange::SendToServer(&msg); BPrivate::media::dataexchange::SendToServer(&msg);
} }
status_t status_t
NewParameterValue(const media_node &node, int32 parameterid, bigtime_t when, const void *param, size_t paramsize) NewParameterValue(const media_node& node, int32 parameterID, bigtime_t when,
const void* param, size_t paramsize)
{ {
CALLED(); CALLED();
BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS);
msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_NEW_PARAMETER_VALUE); msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_NEW_PARAMETER_VALUE);
msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); msg.AddData("node", B_RAW_TYPE, &node, sizeof(node));
msg.AddInt32("parameter", parameterid); msg.AddInt32("parameter", parameterID);
msg.AddInt64("when", when); msg.AddInt64("when", when);
msg.AddData("value", B_RAW_TYPE, param, paramsize); msg.AddData("value", B_RAW_TYPE, param, paramsize);
return BPrivate::media::dataexchange::SendToServer(&msg); return BPrivate::media::dataexchange::SendToServer(&msg);
} }
void void
FlavorsChanged(media_addon_id addonid, int32 newcount, int32 gonecount) FlavorsChanged(media_addon_id addOnID, int32 newCount, int32 goneCount)
{ {
CALLED(); CALLED();
BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS);
msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_FLAVORS_CHANGED); msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_FLAVORS_CHANGED);
msg.AddInt32("be:addon_id", addonid); msg.AddInt32("be:addon_id", addOnID);
msg.AddInt32("be:new_count", newcount); msg.AddInt32("be:new_count", newCount);
msg.AddInt32("be:gone_count", gonecount); msg.AddInt32("be:gone_count", goneCount);
BPrivate::media::dataexchange::SendToServer(&msg); BPrivate::media::dataexchange::SendToServer(&msg);
} }
void void
NodeStopped(const media_node &node, bigtime_t when) NodeStopped(const media_node& node, bigtime_t when)
{ {
CALLED(); CALLED();
BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS);
msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_NODE_STOPPED); msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_NODE_STOPPED);
msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); msg.AddData("node", B_RAW_TYPE, &node, sizeof(node));
msg.AddInt64("when", when); msg.AddInt64("when", when);
BPrivate::media::dataexchange::SendToServer(&msg); BPrivate::media::dataexchange::SendToServer(&msg);
} }
// XXX missing: B_MEDIA_TRANSPORT_STATE /* "state", "location", "realtime" */ // TODO: missing: B_MEDIA_TRANSPORT_STATE: "state", "location", "realtime"
// XXX missing: B_MEDIA_DEFAULT_CHANGED /* "default", "node" */ // TODO: missing: B_MEDIA_DEFAULT_CHANGED: "default", "node"
bool bool
@@ -266,7 +294,7 @@ IsValidNotificationRequest(bool node_specific, int32 notification)
case B_MEDIA_DEFAULT_CHANGED: case B_MEDIA_DEFAULT_CHANGED:
case B_MEDIA_FLAVORS_CHANGED: case B_MEDIA_FLAVORS_CHANGED:
return true; return true;
// only valid for node specific watching // only valid for node specific watching
case B_MEDIA_PARAMETER_CHANGED: case B_MEDIA_PARAMETER_CHANGED:
case B_MEDIA_FORMAT_CHANGED: case B_MEDIA_FORMAT_CHANGED:
@@ -274,13 +302,13 @@ IsValidNotificationRequest(bool node_specific, int32 notification)
case B_MEDIA_NEW_PARAMETER_VALUE: case B_MEDIA_NEW_PARAMETER_VALUE:
case B_MEDIA_NODE_STOPPED: case B_MEDIA_NODE_STOPPED:
return node_specific; return node_specific;
// everything else is invalid // everything else is invalid
default: default:
return false; return false;
} }
} }
}; // namespace notifications } // namespace notifications
}; // namespace media } // namespace media
}; // namespace BPrivate } // namespace BPrivate
+262 -201
View File
@@ -1,213 +1,241 @@
/*********************************************************************** /*
* Copyright (c) 2002 Marcus Overhagen. All Rights Reserved. * Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
* This file may be used under the terms of the OpenBeOS License. * Copyright 2002, Marcus Overhagen. All Rights Reserved.
* * Distributed under the terms of the MIT License.
* Used for BBufferGroup and BBuffer management across teams */
***********************************************************************/
#include <Buffer.h>
/*! Used for BBufferGroup and BBuffer management across teams.
Created in the media server, cloned into each BBufferGroup (visible in
all address spaces).
*/
// TODO: don't use a simple list!
#include <SharedBufferList.h>
#include <string.h> #include <string.h>
#include "SharedBufferList.h"
#include <Buffer.h>
#include "debug.h" #include "debug.h"
status_t namespace BPrivate {
_shared_buffer_list::Init()
/*static*/ area_id
SharedBufferList::Create(SharedBufferList** _list)
{ {
CALLED(); CALLED();
locker_atom = 0;
locker_sem = create_sem(0,"shared buffer list lock");
if (locker_sem < B_OK)
return (status_t) locker_sem;
for (int i = 0; i < MAX_BUFFER; i++) { size_t size = (sizeof(SharedBufferList) + (B_PAGE_SIZE - 1))
info[i].id = -1; & ~(B_PAGE_SIZE - 1);
info[i].buffer = 0; SharedBufferList* list;
info[i].reclaim_sem = 0;
info[i].reclaimed = false; area_id area = create_area("shared buffer list", (void**)&list,
B_ANY_ADDRESS, size, B_LAZY_LOCK, B_READ_AREA | B_WRITE_AREA);
if (area < 0)
return area;
status_t status = list->_Init();
if (status != B_OK) {
delete_area(area);
return status;
} }
return B_OK;
return area;
} }
_shared_buffer_list *
_shared_buffer_list::Clone(area_id id) /*static*/ SharedBufferList*
SharedBufferList::Get(area_id id)
{ {
CALLED(); CALLED();
// if id == -1, we are in the media_server team, // TODO: map this only once per team!
// and create the initial list, else we clone it
_shared_buffer_list *adr; SharedBufferList* list;
status_t status; area_id area = clone_area("shared buffer list clone", (void**)&list,
B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, id);
if (id == -1) { if (area < 0) {
size_t size = ((sizeof(_shared_buffer_list)) + (B_PAGE_SIZE - 1)) & ~(B_PAGE_SIZE - 1); ERROR("SharedBufferList::Clone() clone area: %ld err = %s\n", id,
status = create_area("shared buffer list",(void **)&adr,B_ANY_ADDRESS,size,B_LAZY_LOCK,B_READ_AREA | B_WRITE_AREA); strerror(area));
if (status >= B_OK) { return NULL;
status = adr->Init();
if (status != B_OK)
delete_area(area_for(adr));
}
} else {
status = clone_area("shared buffer list clone", (void **)&adr, B_ANY_ADDRESS, B_READ_AREA|B_WRITE_AREA, id);
if (status < B_OK) {
ERROR("_shared_buffer_list::Clone() clone area: %ld err = %s\n", id, strerror(status));
}
} }
return (status < B_OK) ? NULL : adr; return list;
} }
void void
_shared_buffer_list::Unmap() SharedBufferList::Put()
{ {
CALLED(); CALLED();
// unmap the memory used by this struct
// XXX is this save? area_id area = area_for(this);
area_id id; if (area >= 0)
id = area_for(this); delete_area(area);
if (id >= B_OK)
delete_area(id);
} }
/*! Deletes all BBuffers of the group specified by \a groupReclaimSem, then
unmaps the list from memory.
*/
void void
_shared_buffer_list::Terminate(sem_id group_reclaim_sem) SharedBufferList::DeleteGroupAndPut(sem_id groupReclaimSem)
{ {
CALLED(); CALLED();
// delete all BBuffers of this group, then unmap from memory if (Lock() == B_OK) {
for (int32 i = 0; i < fCount; i++) {
if (fInfos[i].reclaim_sem == groupReclaimSem) {
// delete the associated buffer
delete fInfos[i].buffer;
if (Lock() != B_OK) { // better not try to access the list unlocked // Decrement buffer count by one, and fill the gap
// but at least try to unmap the memory // in the list with its last entry
Unmap(); fCount--;
return; if (fCount > 0)
} fInfos[i--] = fInfos[fCount];
for (int32 i = 0; i < buffercount; i++) {
if (info[i].reclaim_sem == group_reclaim_sem) {
// delete the associated buffer
delete info[i].buffer;
// decrement buffer count by one
buffercount--;
// fill the gap in the list with the last entry
if (buffercount > 0) {
info[i] = info[buffercount];
i--; // make sure we check this entry again
} }
} }
Unlock();
} }
Unlock(); Put();
Unmap();
} }
status_t status_t
_shared_buffer_list::Lock() SharedBufferList::Lock()
{ {
if (atomic_add(&locker_atom, 1) > 0) { if (atomic_add(&fAtom, 1) > 0) {
status_t status; status_t status;
while (B_INTERRUPTED == (status = acquire_sem(locker_sem))) do {
; status = acquire_sem(fSemaphore);
return status; // will only return != B_OK if the media_server crashed or quit } while (status == B_INTERRUPTED);
return status;
} }
return B_OK; return B_OK;
} }
status_t status_t
_shared_buffer_list::Unlock() SharedBufferList::Unlock()
{ {
if (atomic_add(&locker_atom, -1) > 1) if (atomic_add(&fAtom, -1) > 1)
return release_sem(locker_sem); // will only return != B_OK if the media_server crashed or quit return release_sem(fSemaphore);
return B_OK; return B_OK;
} }
status_t status_t
_shared_buffer_list::AddBuffer(sem_id group_reclaim_sem, BBuffer *buffer) SharedBufferList::AddBuffer(sem_id groupReclaimSem, BBuffer* buffer)
{ {
CALLED(); CALLED();
if (buffer == NULL) if (buffer == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
if (Lock() != B_OK) status_t status = Lock();
return B_ERROR; if (status != B_OK)
return status;
if (buffercount == MAX_BUFFER) {
if (fCount == kMaxBuffers) {
Unlock(); Unlock();
debugger("we are doomed"); return B_MEDIA_TOO_MANY_BUFFERS;
return B_ERROR;
} }
info[buffercount].id = buffer->ID(); fInfos[fCount].id = buffer->ID();
info[buffercount].buffer = buffer; fInfos[fCount].buffer = buffer;
info[buffercount].reclaim_sem = group_reclaim_sem; fInfos[fCount].reclaim_sem = groupReclaimSem;
info[buffercount].reclaimed = true; fInfos[fCount].reclaimed = true;
buffercount++; fCount++;
status_t status1 = release_sem_etc(group_reclaim_sem,1,B_DO_NOT_RESCHEDULE); status = release_sem_etc(groupReclaimSem, 1, B_DO_NOT_RESCHEDULE);
status_t status2 = Unlock(); if (status != B_OK)
return status;
return (status1 == B_OK && status2 == B_OK) ? B_OK : B_ERROR; return Unlock();
} }
status_t
_shared_buffer_list::RequestBuffer(sem_id group_reclaim_sem, int32 buffers_in_group, size_t size, media_buffer_id wantID, BBuffer **buffer, bigtime_t timeout) status_t
SharedBufferList::RequestBuffer(sem_id groupReclaimSem, int32 buffersInGroup,
size_t size, media_buffer_id wantID, BBuffer** _buffer, bigtime_t timeout)
{ {
CALLED(); CALLED();
// we always search for a buffer from the group indicated by group_reclaim_sem first // We always search for a buffer from the group indicated by groupReclaimSem
// if "size" != 0, we search for a buffer that is "size" bytes or larger // first.
// if "wantID" != 0, we search for a buffer with this id // If "size" != 0, we search for a buffer that is "size" bytes or larger.
// if "*buffer" != NULL, we search for a buffer at this address // If "wantID" != 0, we search for a buffer with this ID.
// if we found a buffer, we also need to mark it in all other groups as requested // If "*_buffer" != NULL, we search for a buffer at this address.
// and also once need to acquire the reclaim_sem of the other groups //
// If we found a buffer, we also need to mark it in all other groups as
status_t status; // requested and also once need to acquire the reclaim_sem of the other
uint32 acquire_flags; // groups
int32 count;
uint32 acquireFlags;
if (timeout <= 0) { if (timeout <= 0) {
timeout = 0; timeout = 0;
acquire_flags = B_RELATIVE_TIMEOUT; acquireFlags = B_RELATIVE_TIMEOUT;
} else if (timeout != B_INFINITE_TIMEOUT) { } else if (timeout == B_INFINITE_TIMEOUT) {
timeout += system_time(); acquireFlags = B_RELATIVE_TIMEOUT;
acquire_flags = B_ABSOLUTE_TIMEOUT;
} else { } else {
//timeout is B_INFINITE_TIMEOUT timeout += system_time();
acquire_flags = B_RELATIVE_TIMEOUT; acquireFlags = B_ABSOLUTE_TIMEOUT;
} }
// with each itaration we request one more buffer, since we need to skip the buffers that don't fit the request // With each itaration we request one more buffer, since we need to skip
count = 1; // the buffers that don't fit the request
int32 count = 1;
do { do {
while (B_INTERRUPTED == (status = acquire_sem_etc(group_reclaim_sem, count, acquire_flags, timeout))) status_t status;
; do {
status = acquire_sem_etc(groupReclaimSem, count, acquireFlags,
timeout);
} while (status == B_INTERRUPTED);
if (status != B_OK) if (status != B_OK)
return status; return status;
// try to exit savely if the lock fails // try to exit savely if the lock fails
if (Lock() != B_OK) { status = Lock();
ERROR("_shared_buffer_list:: RequestBuffer: Lock failed\n"); if (status != B_OK) {
release_sem_etc(group_reclaim_sem, count, 0); ERROR("SharedBufferList:: RequestBuffer: Lock failed: %s\n",
strerror(status));
release_sem_etc(groupReclaimSem, count, 0);
return B_ERROR; return B_ERROR;
} }
for (int32 i = 0; i < buffercount; i++) { for (int32 i = 0; i < fCount; i++) {
// we need a BBuffer from the group, and it must be marked as reclaimed // We need a BBuffer from the group, and it must be marked as
if (info[i].reclaim_sem == group_reclaim_sem && info[i].reclaimed) { // reclaimed
if ( if (fInfos[i].reclaim_sem == groupReclaimSem
(size != 0 && size <= info[i].buffer->SizeAvailable()) || && fInfos[i].reclaimed) {
(*buffer != 0 && info[i].buffer == *buffer) || if ((size != 0 && size <= fInfos[i].buffer->SizeAvailable())
(wantID != 0 && info[i].id == wantID) || (*_buffer != 0 && fInfos[i].buffer == *_buffer)
) { || (wantID != 0 && fInfos[i].id == wantID)) {
// we found a buffer // we found a buffer
info[i].reclaimed = false; fInfos[i].reclaimed = false;
*buffer = info[i].buffer; *_buffer = fInfos[i].buffer;
// if we requested more than one buffer, release the rest // if we requested more than one buffer, release the rest
if (count > 1) if (count > 1) {
release_sem_etc(group_reclaim_sem, count - 1, B_DO_NOT_RESCHEDULE); release_sem_etc(groupReclaimSem, count - 1,
B_DO_NOT_RESCHEDULE);
// and mark all buffers with the same ID as requested in all other buffer groups }
RequestBufferInOtherGroups(group_reclaim_sem, info[i].buffer->ID());
// And mark all buffers with the same ID as requested in
// all other buffer groups
_RequestBufferInOtherGroups(groupReclaimSem,
fInfos[i].buffer->ID());
Unlock(); Unlock();
return B_OK; return B_OK;
@@ -215,107 +243,140 @@ _shared_buffer_list::RequestBuffer(sem_id group_reclaim_sem, int32 buffers_in_gr
} }
} }
release_sem_etc(group_reclaim_sem, count, B_DO_NOT_RESCHEDULE); release_sem_etc(groupReclaimSem, count, B_DO_NOT_RESCHEDULE);
if (Unlock() != B_OK) { if (Unlock() != B_OK) {
ERROR("_shared_buffer_list:: RequestBuffer: unlock failed\n"); ERROR("SharedBufferList:: RequestBuffer: unlock failed\n");
return B_ERROR; return B_ERROR;
} }
// prepare to request one more buffer next time // prepare to request one more buffer next time
count++; count++;
} while (count <= buffers_in_group); } while (count <= buffersInGroup);
ERROR("_shared_buffer_list:: RequestBuffer: no buffer found\n"); ERROR("SharedBufferList:: RequestBuffer: no buffer found\n");
return B_ERROR; return B_ERROR;
} }
void
_shared_buffer_list::RequestBufferInOtherGroups(sem_id group_reclaim_sem, media_buffer_id id)
{
for (int32 i = 0; i < buffercount; i++) {
// find buffers with same id, but belonging to other groups
if (info[i].id == id && info[i].reclaim_sem != group_reclaim_sem) {
// and mark them as requested
// XXX this can deadlock if BBuffers with same media_buffer_id
// XXX exist in more than one BBufferGroup, and RequestBuffer()
// XXX is called on both groups (which should not be done).
status_t status;
while (B_INTERRUPTED == (status = acquire_sem(info[i].reclaim_sem)))
;
// try to skip entries that belong to crashed teams
if (status != B_OK)
continue;
if (info[i].reclaimed == false) {
ERROR("_shared_buffer_list:: RequestBufferInOtherGroups BBuffer %p, id = %ld not reclaimed while requesting\n", info[i].buffer, id);
continue;
}
info[i].reclaimed = false;
}
}
}
status_t status_t
_shared_buffer_list::RecycleBuffer(BBuffer *buffer) SharedBufferList::RecycleBuffer(BBuffer* buffer)
{ {
CALLED(); CALLED();
int reclaimed_count; media_buffer_id id = buffer->ID();
// media_buffer_id id = buffer->ID();
media_buffer_id id = buffer->fBufferID;
if (Lock() != B_OK) if (Lock() != B_OK)
return B_ERROR; return B_ERROR;
reclaimed_count = 0; int32 reclaimedCount = 0;
for (int32 i = 0; i < buffercount; i++) {
for (int32 i = 0; i < fCount; i++) {
// find the buffer id, and reclaim it in all groups it belongs to // find the buffer id, and reclaim it in all groups it belongs to
if (info[i].id == id) { if (fInfos[i].id == id) {
reclaimed_count++; reclaimedCount++;
if (info[i].reclaimed) { if (fInfos[i].reclaimed) {
ERROR("_shared_buffer_list::RecycleBuffer, BBuffer %p, id = %ld already reclaimed\n", buffer, id); ERROR("SharedBufferList::RecycleBuffer, BBuffer %p, id = %ld "
"already reclaimed\n", buffer, id);
DEBUG_ONLY(debugger("buffer already reclaimed")); DEBUG_ONLY(debugger("buffer already reclaimed"));
continue; continue;
} }
info[i].reclaimed = true; fInfos[i].reclaimed = true;
release_sem_etc(info[i].reclaim_sem, 1, B_DO_NOT_RESCHEDULE); release_sem_etc(fInfos[i].reclaim_sem, 1, B_DO_NOT_RESCHEDULE);
} }
} }
if (Unlock() != B_OK) if (Unlock() != B_OK)
return B_ERROR; return B_ERROR;
if (reclaimed_count == 0) { if (reclaimedCount == 0) {
ERROR("shared_buffer_list::RecycleBuffer, BBuffer %p, id = %ld NOT reclaimed\n", buffer, id); ERROR("shared_buffer_list::RecycleBuffer, BBuffer %p, id = %ld NOT "
"reclaimed\n", buffer, id);
return B_ERROR; return B_ERROR;
} }
return B_OK; return B_OK;
} }
status_t
_shared_buffer_list::GetBufferList(sem_id group_reclaim_sem, int32 buf_count, BBuffer **out_buffers) /*! Returns exactly \a bufferCount buffers from the group specified via its
\a groupReclaimSem if successful.
*/
status_t
SharedBufferList::GetBufferList(sem_id groupReclaimSem, int32 bufferCount,
BBuffer** buffers)
{ {
CALLED(); CALLED();
int32 found;
found = 0;
if (Lock() != B_OK) if (Lock() != B_OK)
return B_ERROR; return B_ERROR;
for (int32 i = 0; i < buffercount; i++) int32 found = 0;
if (info[i].reclaim_sem == group_reclaim_sem) {
out_buffers[found++] = info[i].buffer; for (int32 i = 0; i < fCount; i++)
if (found == buf_count) if (fInfos[i].reclaim_sem == groupReclaimSem) {
buffers[found++] = fInfos[i].buffer;
if (found == bufferCount)
break; break;
} }
if (Unlock() != B_OK) if (Unlock() != B_OK)
return B_ERROR; return B_ERROR;
return (found == buf_count) ? B_OK : B_ERROR; return found == bufferCount ? B_OK : B_ERROR;
} }
status_t
SharedBufferList::_Init()
{
CALLED();
fSemaphore = create_sem(0, "shared buffer list lock");
if (fSemaphore < 0)
return fSemaphore;
fAtom = 0;
for (int32 i = 0; i < kMaxBuffers; i++) {
fInfos[i].id = -1;
}
return B_OK;
}
/*! Used by RequestBuffer, call this one with the list locked!
*/
void
SharedBufferList::_RequestBufferInOtherGroups(sem_id groupReclaimSem,
media_buffer_id id)
{
for (int32 i = 0; i < fCount; i++) {
// find buffers with same id, but belonging to other groups
if (fInfos[i].id == id && fInfos[i].reclaim_sem != groupReclaimSem) {
// and mark them as requested
// TODO: this can deadlock if BBuffers with same media_buffer_id
// exist in more than one BBufferGroup, and RequestBuffer()
// is called on both groups (which should not be done).
status_t status;
do {
status = acquire_sem(fInfos[i].reclaim_sem);
} while (status == B_INTERRUPTED);
// try to skip entries that belong to crashed teams
if (status != B_OK)
continue;
if (fInfos[i].reclaimed == false) {
ERROR("SharedBufferList:: RequestBufferInOtherGroups BBuffer "
"%p, id = %ld not reclaimed while requesting\n",
fInfos[i].buffer, id);
continue;
}
fInfos[i].reclaimed = false;
}
}
}
} // namespace BPrivate
+46 -31
View File
@@ -1,4 +1,4 @@
/* /*
* Copyright 2002, Marcus Overhagen. All rights reserved. * Copyright 2002, Marcus Overhagen. All rights reserved.
* Copyright 2009, Axel Dörfler, axeld@pinc-software.de. * Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
@@ -15,28 +15,30 @@
BufferManager::BufferManager() BufferManager::BufferManager()
: :
fSharedBufferList(_shared_buffer_list::Clone()), fSharedBufferList(NULL),
fSharedBufferListArea(-1),
fNextBufferID(1), fNextBufferID(1),
fLocker("buffer manager locker") fLocker("buffer manager locker")
{ {
fSharedBufferListID = area_for(fSharedBufferList); fSharedBufferListArea
= BPrivate::SharedBufferList::Create(&fSharedBufferList);
} }
BufferManager::~BufferManager() BufferManager::~BufferManager()
{ {
fSharedBufferList->Unmap(); fSharedBufferList->Put();
} }
area_id area_id
BufferManager::SharedBufferListID() BufferManager::SharedBufferListArea()
{ {
return fSharedBufferListID; return fSharedBufferListArea;
} }
status_t status_t
BufferManager::RegisterBuffer(team_id team, media_buffer_id bufferID, BufferManager::RegisterBuffer(team_id team, media_buffer_id bufferID,
size_t* _size, int32* _flags, size_t* _offset, area_id* _area) size_t* _size, int32* _flags, size_t* _offset, area_id* _area)
{ {
@@ -55,7 +57,7 @@ BufferManager::RegisterBuffer(team_id team, media_buffer_id bufferID,
*_area = info->area; *_area = info->area;
*_offset = info->offset; *_offset = info->offset;
*_size = info->size, *_size = info->size,
*_flags = info->flags; *_flags = info->flags;
return B_OK; return B_OK;
@@ -69,7 +71,7 @@ BufferManager::RegisterBuffer(team_id team, size_t size, int32 flags,
BAutolock lock(fLocker); BAutolock lock(fLocker);
TRACE("RegisterBuffer team = %ld, area = %ld, offset = %ld, size = %ld\n", TRACE("RegisterBuffer team = %ld, area = %ld, offset = %ld, size = %ld\n",
team, area, offset, size); team, area, offset, size);
area_id clonedArea = _CloneArea(area); area_id clonedArea = _CloneArea(area);
if (clonedArea < 0) { if (clonedArea < 0) {
ERROR("RegisterBuffer: failed to clone buffer! error = %#lx, team = " ERROR("RegisterBuffer: failed to clone buffer! error = %#lx, team = "
@@ -84,14 +86,19 @@ BufferManager::RegisterBuffer(team_id team, size_t size, int32 flags,
info.offset = offset; info.offset = offset;
info.size = size; info.size = size;
info.flags = flags; info.flags = flags;
info.teams.insert(team);
*_bufferID = info.id; try {
info.teams.insert(team);
fBufferInfoMap.Put(info.id, info); if (fBufferInfoMap.Put(info.id, info) != B_OK)
throw std::bad_alloc();
} catch (std::bad_alloc& exception) {
_ReleaseClonedArea(clonedArea);
return B_NO_MEMORY;
}
TRACE("RegisterBuffer: done, bufferID = %ld\n", info.id); TRACE("RegisterBuffer: done, bufferID = %ld\n", info.id);
*_bufferID = info.id;
return B_OK; return B_OK;
} }
@@ -100,12 +107,12 @@ status_t
BufferManager::UnregisterBuffer(team_id team, media_buffer_id bufferID) BufferManager::UnregisterBuffer(team_id team, media_buffer_id bufferID)
{ {
BAutolock lock(fLocker); BAutolock lock(fLocker);
TRACE("UnregisterBuffer: team = %ld, bufferid = %ld\n", team, bufferID); TRACE("UnregisterBuffer: team = %ld, bufferID = %ld\n", team, bufferID);
buffer_info* info; buffer_info* info;
if (!fBufferInfoMap.Get(bufferID, info)) { if (!fBufferInfoMap.Get(bufferID, info)) {
ERROR("UnregisterBuffer: failed to unregister buffer! team = %ld, " ERROR("UnregisterBuffer: failed to unregister buffer! team = %ld, "
"bufferid = %ld\n", team, bufferID); "bufferID = %ld\n", team, bufferID);
return B_ERROR; return B_ERROR;
} }
@@ -114,7 +121,7 @@ BufferManager::UnregisterBuffer(team_id team, media_buffer_id bufferID)
"bufferID = %ld\n", team, bufferID); "bufferID = %ld\n", team, bufferID);
return B_ERROR; return B_ERROR;
} }
info->teams.erase(team); info->teams.erase(team);
TRACE("UnregisterBuffer: team = %ld removed from bufferID = %ld\n", team, TRACE("UnregisterBuffer: team = %ld removed from bufferID = %ld\n", team,
@@ -146,7 +153,7 @@ BufferManager::CleanupTeam(team_id team)
if (entry.value.teams.empty()) { if (entry.value.teams.empty()) {
PRINT(1, "BufferManager::CleanupTeam: removing buffer id %ld that " PRINT(1, "BufferManager::CleanupTeam: removing buffer id %ld that "
"has no teams\n", entry.key); "has no teams\n", entry.key.GetHashCode());
_ReleaseClonedArea(entry.value.area); _ReleaseClonedArea(entry.value.area);
iterator.Remove(); iterator.Remove();
} }
@@ -182,14 +189,16 @@ BufferManager::Dump()
area_id area_id
BufferManager::_CloneArea(area_id area) BufferManager::_CloneArea(area_id area)
{ {
clone_info* info; {
if (fCloneInfoMap.Get(area, info)) { clone_info* info;
// we have already cloned this particular area if (fCloneInfoMap.Get(area, info)) {
TRACE("BufferManager::_CloneArea() area %ld has already been cloned " // we have already cloned this particular area
"(id %ld)\n", area, info->clone); TRACE("BufferManager::_CloneArea() area %ld has already been "
"cloned (id %ld)\n", area, info->clone);
info->ref_count++; info->ref_count++;
return info->clone; return info->clone;
}
} }
void* address; void* address;
@@ -199,16 +208,22 @@ BufferManager::_CloneArea(area_id area)
TRACE("BufferManager::_CloneArea() cloned area %ld, clone id %ld\n", TRACE("BufferManager::_CloneArea() cloned area %ld, clone id %ld\n",
area, clonedArea); area, clonedArea);
if (clonedArea >= 0) { if (clonedArea < 0)
clone_info info; return clonedArea;
info.clone = clonedArea;
info.ref_count = 1;
fCloneInfoMap.Put(area, info); clone_info info;
fSourceInfoMap.Put(clonedArea, area); info.clone = clonedArea;
info.ref_count = 1;
if (fCloneInfoMap.Put(area, info) == B_OK) {
if (fSourceInfoMap.Put(clonedArea, area) == B_OK)
return clonedArea;
fCloneInfoMap.Remove(area);
} }
return clonedArea; delete_area(clonedArea);
return B_NO_MEMORY;
} }
+11 -9
View File
@@ -1,4 +1,4 @@
/* /*
* Copyright 2002, Marcus Overhagen. All rights reserved. * Copyright 2002, Marcus Overhagen. All rights reserved.
* Copyright 2009, Axel Dörfler, axeld@pinc-software.de. * Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
@@ -13,16 +13,18 @@
#include <HashMap.h> #include <HashMap.h>
struct _shared_buffer_list; namespace BPrivate {
class SharedBufferList;
}
class BufferManager { class BufferManager {
public: public:
BufferManager(); BufferManager();
~BufferManager(); ~BufferManager();
area_id SharedBufferListID(); area_id SharedBufferListArea();
status_t RegisterBuffer(team_id team, status_t RegisterBuffer(team_id team,
media_buffer_id bufferID, size_t* _size, media_buffer_id bufferID, size_t* _size,
int32* _flags, size_t* _offset, area_id* _area); int32* _flags, size_t* _offset, area_id* _area);
@@ -56,7 +58,7 @@ private:
int32 flags; int32 flags;
std::set<team_id> teams; std::set<team_id> teams;
}; };
template<typename Type> struct id_hash { template<typename Type> struct id_hash {
id_hash() id_hash()
: :
@@ -84,7 +86,7 @@ private:
{ {
return fID; return fID;
} }
id_hash& operator=(const id_hash& other) id_hash& operator=(const id_hash& other)
{ {
fID = other.fID; fID = other.fID;
@@ -99,8 +101,8 @@ private:
typedef HashMap<id_hash<area_id>, clone_info> CloneInfoMap; typedef HashMap<id_hash<area_id>, clone_info> CloneInfoMap;
typedef HashMap<id_hash<area_id>, area_id> SourceInfoMap; typedef HashMap<id_hash<area_id>, area_id> SourceInfoMap;
_shared_buffer_list* fSharedBufferList; BPrivate::SharedBufferList* fSharedBufferList;
area_id fSharedBufferListID; area_id fSharedBufferListArea;
media_buffer_id fNextBufferID; media_buffer_id fNextBufferID;
BLocker fLocker; BLocker fLocker;
BufferInfoMap fBufferInfoMap; BufferInfoMap fBufferInfoMap;
+40 -36
View File
@@ -1,7 +1,11 @@
/* /*
* Copyright 2002, 2003 Marcus Overhagen, Jérôme Duval. All rights reserved. * Copyright 2002, 2003 Marcus Overhagen, Jérôme Duval. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include "DefaultManager.h"
#include <Application.h> #include <Application.h>
#include <Directory.h> #include <Directory.h>
#include <File.h> #include <File.h>
@@ -12,7 +16,7 @@
#include <Path.h> #include <Path.h>
#include <TimeSource.h> #include <TimeSource.h>
#include <string.h> #include <string.h>
#include "DefaultManager.h"
#include "DormantNodeManager.h" #include "DormantNodeManager.h"
#include "NodeManager.h" #include "NodeManager.h"
#include "debug.h" #include "debug.h"
@@ -74,12 +78,12 @@ DefaultManager::LoadState()
BPath path; BPath path;
if((err = find_directory(B_USER_SETTINGS_DIRECTORY, &path))!=B_OK) if((err = find_directory(B_USER_SETTINGS_DIRECTORY, &path))!=B_OK)
return err; return err;
path.Append(kDefaultManagerSettingsDirectory); path.Append(kDefaultManagerSettingsDirectory);
path.Append(kDefaultManagerSettingsFile); path.Append(kDefaultManagerSettingsFile);
BFile file(path.Path(), B_READ_ONLY); BFile file(path.Path(), B_READ_ONLY);
uint32 category_count; uint32 category_count;
if (file.Read(fBeginHeader, sizeof(uint32)*3) < (int32)sizeof(uint32)*3) if (file.Read(fBeginHeader, sizeof(uint32)*3) < (int32)sizeof(uint32)*3)
return B_ERROR; return B_ERROR;
@@ -119,20 +123,20 @@ DefaultManager::SaveState(NodeManager *node_manager)
if ((err = create_directory(path.Path(), 0755)) != B_OK) if ((err = create_directory(path.Path(), 0755)) != B_OK)
return err; return err;
path.Append(kDefaultManagerSettingsFile); path.Append(kDefaultManagerSettingsFile);
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, kMsgTypeAudioIn, kMsgTypeAudioOut};
uint32 media_node_ids[] = {fPhysicalVideoIn, fPhysicalVideoOut, fPhysicalAudioIn, fPhysicalAudioOut}; 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]);
// we call the node manager to have more infos about nodes // we call the node manager to have more infos about nodes
dormant_node_info info; dormant_node_info info;
media_node node; media_node node;
entry_ref ref; entry_ref ref;
if (node_manager->GetCloneForId(&node, media_node_ids[i], be_app->Team()) != B_OK) if (node_manager->GetCloneForID(&node, media_node_ids[i], be_app->Team()) != B_OK)
continue; continue;
if (node_manager->GetDormantNodeInfo(&info, node) != B_OK) if (node_manager->GetDormantNodeInfo(&info, node) != B_OK)
continue; continue;
@@ -147,17 +151,17 @@ DefaultManager::SaveState(NodeManager *node_manager)
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());
list.AddItem(settings); list.AddItem(settings);
TRACE("message %s added\n", info.name); TRACE("message %s added\n", info.name);
} }
if (file.Write(fBeginHeader, sizeof(uint32)*3) < (int32)sizeof(uint32)*3) if (file.Write(fBeginHeader, sizeof(uint32)*3) < (int32)sizeof(uint32)*3)
return B_ERROR; return B_ERROR;
int32 category_count = list.CountItems(); int32 category_count = list.CountItems();
if (file.Write(&category_count, sizeof(uint32)) < (int32)sizeof(uint32)) if (file.Write(&category_count, sizeof(uint32)) < (int32)sizeof(uint32))
return B_ERROR; return B_ERROR;
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;
@@ -173,7 +177,7 @@ DefaultManager::SaveState(NodeManager *node_manager)
} }
if (file.Write(fEndHeader, sizeof(uint32)*3) < (int32)sizeof(uint32)*3) if (file.Write(fEndHeader, sizeof(uint32)*3) < (int32)sizeof(uint32)*3)
return B_ERROR; return B_ERROR;
return B_OK; return B_OK;
} }
@@ -201,14 +205,14 @@ DefaultManager::Set(media_node_id node_id, const char *input_name, int32 input_i
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() case SYSTEM_TIME_SOURCE: //called by the media_server's ServerApp::StartSystemTimeSource()
{ {
ASSERT(fSystemTimeSource == -1); ASSERT(fSystemTimeSource == -1);
fSystemTimeSource = node_id; fSystemTimeSource = node_id;
return B_OK; return B_OK;
} }
default: default:
{ {
ERROR("DefaultManager::Set Error: called with unknown type %d\n", type); ERROR("DefaultManager::Set Error: called with unknown type %d\n", type);
@@ -233,7 +237,7 @@ DefaultManager::Get(media_node_id *nodeid, char *input_name, int32 *inputid, nod
return B_NAME_NOT_FOUND; return B_NAME_NOT_FOUND;
*nodeid = fPhysicalAudioIn; *nodeid = fPhysicalAudioIn;
return B_OK; return B_OK;
case VIDEO_OUTPUT: // output: nodeid case VIDEO_OUTPUT: // output: nodeid
if (fPhysicalVideoOut == -1) if (fPhysicalVideoOut == -1)
return B_NAME_NOT_FOUND; return B_NAME_NOT_FOUND;
@@ -266,7 +270,7 @@ DefaultManager::Get(media_node_id *nodeid, char *input_name, int32 *inputid, nod
else else
*nodeid = fSystemTimeSource; *nodeid = fSystemTimeSource;
return B_OK; return B_OK;
case SYSTEM_TIME_SOURCE: case SYSTEM_TIME_SOURCE:
*nodeid = fSystemTimeSource; *nodeid = fSystemTimeSource;
return B_OK; return B_OK;
@@ -299,7 +303,7 @@ void
DefaultManager::RescanThread() DefaultManager::RescanThread()
{ {
printf("DefaultManager::RescanThread() enter\n"); printf("DefaultManager::RescanThread() enter\n");
// We do not search for the system time source, // We do not search for the system time source,
// it should already exist // it should already exist
ASSERT(fSystemTimeSource != -1); ASSERT(fSystemTimeSource != -1);
@@ -307,7 +311,7 @@ DefaultManager::RescanThread()
if (fPhysicalVideoOut == -1) { if (fPhysicalVideoOut == -1) {
FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false, B_MEDIA_RAW_VIDEO); FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false, B_MEDIA_RAW_VIDEO);
FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false, B_MEDIA_ENCODED_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, B_MEDIA_RAW_VIDEO);
FindPhysical(&fPhysicalVideoIn, kMsgTypeVideoIn, true, B_MEDIA_ENCODED_VIDEO); FindPhysical(&fPhysicalVideoIn, kMsgTypeVideoIn, true, B_MEDIA_ENCODED_VIDEO);
@@ -332,7 +336,7 @@ DefaultManager::RescanThread()
} else { } else {
ERROR("DefaultManager: Did not try to connect mixer and soundcard\n"); ERROR("DefaultManager: Did not try to connect mixer and soundcard\n");
} }
addonserver_rescan_finished_notify_command cmd; addonserver_rescan_finished_notify_command cmd;
SendToAddonServer(ADDONSERVER_RESCAN_FINISHED_NOTIFY, &cmd, sizeof(cmd)); SendToAddonServer(ADDONSERVER_RESCAN_FINISHED_NOTIFY, &cmd, sizeof(cmd));
@@ -375,8 +379,8 @@ DefaultManager::FindPhysical(volatile media_node_id *id, uint32 default_type, bo
memset(&format, 0, sizeof(format)); memset(&format, 0, sizeof(format));
format.type = type; format.type = 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");
@@ -384,7 +388,7 @@ DefaultManager::FindPhysical(volatile media_node_id *id, uint32 default_type, bo
} }
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
TRACE("info[%d].name %s\n", i, info[i].name); TRACE("info[%d].name %s\n", i, info[i].name);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
if (isAudio) { if (isAudio) {
if (isInput) { if (isInput) {
@@ -406,7 +410,7 @@ DefaultManager::FindPhysical(volatile media_node_id *id, uint32 default_type, bo
if (0 == strcmp(info[i].name, "DV Output")) // skip the Firewire audio driver if (0 == strcmp(info[i].name, "DV Output")) // skip the Firewire audio driver
continue; continue;
} }
} }
if(msg) { // we have a default info msg if(msg) { // we have a default info msg
dormant_node_info dninfo; dormant_node_info dninfo;
if(BMediaRoster::Roster()->GetDormantNodeFor(info[i].node, &dninfo) != B_OK) { if(BMediaRoster::Roster()->GetDormantNodeFor(info[i].node, &dninfo) != B_OK) {
@@ -419,13 +423,13 @@ DefaultManager::FindPhysical(volatile media_node_id *id, uint32 default_type, bo
continue; continue;
} }
BPath path; BPath path;
if((_DormantNodeManager->FindAddonPath(&path, dninfo.addon)!=B_OK) if((_DormantNodeManager->FindAddonPath(&path, dninfo.addon)!=B_OK)
|| (path != msgPath)) { || (path != msgPath)) {
ERROR("Doesn't match : path\n"); ERROR("Doesn't match : path\n");
continue; continue;
} }
} }
TRACE("Default physical %s %s \"%s\" created!\n", TRACE("Default physical %s %s \"%s\" created!\n",
isAudio ? "audio" : "video", isInput ? "input" : "output", info[i].name); isAudio ? "audio" : "video", isInput ? "input" : "output", info[i].name);
*id = info[i].node.node; *id = info[i].node.node;
if(msg && isAudio && !isInput) if(msg && isAudio && !isInput)
@@ -442,7 +446,7 @@ DefaultManager::FindTimeSource()
media_format input; /* a physical audio output has a logical data input (DAC)*/ media_format input; /* a physical audio output has a logical data input (DAC)*/
int32 count; int32 count;
status_t rv; status_t rv;
/* First try to use the current default physical audio out /* First try to use the current default physical audio out
*/ */
if (fPhysicalAudioOut != -1) { if (fPhysicalAudioOut != -1) {
@@ -462,7 +466,7 @@ DefaultManager::FindTimeSource()
} else { } else {
printf("Default DAC node does not exist!\n"); printf("Default DAC node does not exist!\n");
} }
/* Now try to find another physical audio out node /* Now try to find another physical audio out node
*/ */
memset(&input, 0, sizeof(input)); memset(&input, 0, sizeof(input));
@@ -472,7 +476,7 @@ DefaultManager::FindTimeSource()
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, that is pretty dumb
if (0 == strcmp(info[i].name, "None Out")) // skip the Null audio driver if (0 == strcmp(info[i].name, "None Out")) // skip the Null audio driver
@@ -486,8 +490,8 @@ DefaultManager::FindTimeSource()
} }
} else { } else {
printf("Couldn't find DAC timesource node\n"); printf("Couldn't find DAC timesource node\n");
} }
/* XXX we might use other audio or video clock timesources /* XXX we might use other audio or video clock timesources
*/ */
} }
@@ -526,7 +530,7 @@ DefaultManager::ConnectMixerToOutput()
bigtime_t start_at; bigtime_t start_at;
int32 count; int32 count;
status_t rv; status_t rv;
roster = BMediaRoster::Roster(); roster = BMediaRoster::Roster();
rv = roster->GetNodeFor(fPhysicalAudioOut, &soundcard); rv = roster->GetNodeFor(fPhysicalAudioOut, &soundcard);
@@ -558,13 +562,13 @@ DefaultManager::ConnectMixerToOutput()
rv = B_ERROR; rv = B_ERROR;
goto finish; goto finish;
} }
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
input = inputs[i]; input = inputs[i];
if(input.destination.id == fPhysicalAudioOutInputID) if(input.destination.id == fPhysicalAudioOutInputID)
break; break;
} }
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
switch (i) { switch (i) {
case 0: case 0:
@@ -636,13 +640,13 @@ DefaultManager::ConnectMixerToOutput()
roster->SetTimeSourceFor(soundcard.node, timesource.node); roster->SetTimeSourceFor(soundcard.node, timesource.node);
roster->PrerollNode(mixer); roster->PrerollNode(mixer);
roster->PrerollNode(soundcard); roster->PrerollNode(soundcard);
ts = roster->MakeTimeSourceFor(mixer); ts = roster->MakeTimeSourceFor(mixer);
start_at = ts->Now() + 50000; start_at = ts->Now() + 50000;
roster->StartNode(mixer, start_at); roster->StartNode(mixer, start_at);
roster->StartNode(soundcard, start_at); roster->StartNode(soundcard, start_at);
ts->Release(); ts->Release();
finish: finish:
roster->ReleaseNode(mixer); roster->ReleaseNode(mixer);
roster->ReleaseNode(soundcard); roster->ReleaseNode(soundcard);
+74 -65
View File
@@ -77,7 +77,7 @@ NodeManager::RegisterNode(media_node_id *nodeid, media_addon_id addon_id, int32
BAutolock lock(fLocker); BAutolock lock(fLocker);
bool b; bool b;
registered_node rn; registered_node rn;
rn.nodeid = fNextNodeID; rn.node_id = fNextNodeID;
rn.addon_id = addon_id; rn.addon_id = addon_id;
rn.addon_flavor_id = addon_flavor_id; rn.addon_flavor_id = addon_flavor_id;
strcpy(rn.name, name); strcpy(rn.name, name);
@@ -87,7 +87,7 @@ NodeManager::RegisterNode(media_node_id *nodeid, media_addon_id addon_id, int32
rn.creator = -1; // will be set later rn.creator = -1; // will be set later
rn.globalrefcount = 1; rn.globalrefcount = 1;
rn.teamrefcount.Insert(team, 1); rn.teamrefcount.Insert(team, 1);
b = fRegisteredNodeMap->Insert(fNextNodeID, rn); b = fRegisteredNodeMap->Insert(fNextNodeID, rn);
ASSERT(b); ASSERT(b);
*nodeid = fNextNodeID; *nodeid = fNextNodeID;
@@ -194,12 +194,12 @@ NodeManager::DecrementGlobalRefCount(media_node_id nodeid, team_id team)
ASSERT(b); ASSERT(b);
} }
rn->globalrefcount -= 1; rn->globalrefcount -= 1;
if (rn->globalrefcount == 0) { if (rn->globalrefcount == 0) {
printf("NodeManager::DecrementGlobalRefCount: detected released node is now unused, node %ld\n", nodeid); printf("NodeManager::DecrementGlobalRefCount: detected released node is now unused, node %ld\n", nodeid);
FinalReleaseNode(nodeid); FinalReleaseNode(nodeid);
} }
TRACE("NodeManager::DecrementGlobalRefCount leave: node %ld, team %ld, count %ld, globalcount %ld\n", nodeid, team, debug_count, rn->globalrefcount); TRACE("NodeManager::DecrementGlobalRefCount leave: node %ld, team %ld, count %ld, globalcount %ld\n", nodeid, team, debug_count, rn->globalrefcount);
return B_OK; return B_OK;
} }
@@ -218,12 +218,12 @@ NodeManager::SetNodeCreator(media_node_id nodeid, team_id creator)
ERROR("NodeManager::SetNodeCreator: node %ld not found\n", nodeid); ERROR("NodeManager::SetNodeCreator: node %ld not found\n", nodeid);
return B_ERROR; return B_ERROR;
} }
if (rn->creator != -1) { if (rn->creator != -1) {
ERROR("NodeManager::SetNodeCreator: node %ld is already assigned creator %ld\n", nodeid, rn->creator); ERROR("NodeManager::SetNodeCreator: node %ld is already assigned creator %ld\n", nodeid, rn->creator);
return B_ERROR; return B_ERROR;
} }
rn->creator = creator; rn->creator = creator;
return B_OK; return B_OK;
} }
@@ -253,47 +253,52 @@ NodeManager::FinalReleaseNode(media_node_id nodeid)
status_t status_t
NodeManager::GetCloneForId(media_node *node, media_node_id nodeid, team_id team) NodeManager::GetCloneForID(media_node* node, media_node_id nodeID, team_id team)
{ {
BAutolock lock(fLocker); BAutolock lock(fLocker);
registered_node *rn; TRACE("NodeManager::GetCloneForID enter: node %ld team %ld\n", nodeID,
bool b; team);
TRACE("NodeManager::GetCloneForId enter: node %ld team %ld\n", nodeid, team);
if (B_OK != IncrementGlobalRefCount(nodeid, team)) { if (IncrementGlobalRefCount(nodeID, team) != B_OK) {
ERROR("NodeManager::GetCloneForId: couldn't increment ref count, node %ld team %ld\n", nodeid, team); ERROR("NodeManager::GetCloneForID: couldn't increment ref count, "
"node %ld team %ld\n", nodeID, team);
return B_ERROR; return B_ERROR;
} }
b = fRegisteredNodeMap->Get(nodeid, &rn); registered_node* registeredNode;
if (!b) { if (!fRegisteredNodeMap->Get(nodeID, &registeredNode)) {
ERROR("NodeManager::GetCloneForId: node %ld not found\n", nodeid); ERROR("NodeManager::GetCloneForID: node %ld not found\n", nodeID);
DecrementGlobalRefCount(nodeid, team); DecrementGlobalRefCount(nodeID, team);
return B_ERROR; return B_ERROR;
} }
node->node = rn->nodeid; node->node = registeredNode->node_id;
node->port = rn->port; node->port = registeredNode->port;
node->kind = rn->kinds; node->kind = registeredNode->kinds;
TRACE("NodeManager::GetCloneForId leave: node %ld team %ld\n", nodeid, team); TRACE("NodeManager::GetCloneForID leave: node %ld team %ld\n", nodeID,
team);
return B_OK; return B_OK;
} }
/* This function locates the default "node" for the requested "type" and returnes a clone. /*! This function locates the default "node" for the requested "type" and
* If the requested type is AUDIO_OUTPUT_EX, also "input_name" and "input_id" need to be set and returned, returns a clone.
* as this is required by BMediaRoster::GetAudioOutput(media_node *out_node, int32 *out_input_id, BString *out_input_name) If the requested type is AUDIO_OUTPUT_EX, also "input_name" and "input_id"
*/ need to be set and returned, as this is required by
BMediaRoster::GetAudioOutput(media_node *out_node, int32 *out_input_id,
BString *out_input_name).
*/
status_t status_t
NodeManager::GetClone(media_node *node, char *input_name, int32 *input_id, node_type type, team_id team) NodeManager::GetClone(media_node *node, char *input_name, int32 *input_id,
node_type type, team_id team)
{ {
BAutolock lock(fLocker); BAutolock lock(fLocker);
status_t status; status_t status;
media_node_id id; media_node_id id;
TRACE("NodeManager::GetClone enter: team %ld, type %d (%s)\n", team, type, get_node_type(type)); TRACE("NodeManager::GetClone enter: team %ld, type %d (%s)\n", team, type, get_node_type(type));
status = GetDefaultNode(&id, input_name, input_id, type); status = GetDefaultNode(&id, input_name, input_id, type);
if (status != B_OK) { if (status != B_OK) {
ERROR("NodeManager::GetClone: couldn't GetDefaultNode, team %ld, type %d (%s)\n", team, type, get_node_type(type)); ERROR("NodeManager::GetClone: couldn't GetDefaultNode, team %ld, type %d (%s)\n", team, type, get_node_type(type));
@@ -302,9 +307,9 @@ NodeManager::GetClone(media_node *node, char *input_name, int32 *input_id, node_
} }
ASSERT(id > 0); ASSERT(id > 0);
status = GetCloneForId(node, id, team); status = GetCloneForID(node, id, team);
if (status != B_OK) { if (status != B_OK) {
ERROR("NodeManager::GetClone: couldn't GetCloneForId, id %ld, team %ld, type %d (%s)\n", id, team, type, get_node_type(type)); ERROR("NodeManager::GetClone: couldn't GetCloneForID, id %ld, team %ld, type %d (%s)\n", id, team, type, get_node_type(type));
*node = media_node::null; *node = media_node::null;
return status; return status;
} }
@@ -366,37 +371,39 @@ NodeManager::PublishOutputs(const media_node &node, const media_output *outputs,
status_t status_t
NodeManager::FindNodeId(media_node_id *nodeid, port_id port) NodeManager::FindNodeID(media_node_id* nodeID, port_id port)
{ {
BAutolock lock(fLocker); BAutolock lock(fLocker);
registered_node *rn; registered_node *rn;
for (fRegisteredNodeMap->Rewind(); fRegisteredNodeMap->GetNext(&rn); ) { for (fRegisteredNodeMap->Rewind(); fRegisteredNodeMap->GetNext(&rn); ) {
if (rn->port == port) { if (rn->port == port) {
*nodeid = rn->nodeid; *nodeID = rn->node_id;
TRACE("NodeManager::FindNodeId found port %ld, node %ld\n", port, *nodeid); TRACE("NodeManager::FindNodeID found port %ld, node %ld\n", port,
*nodeID);
return B_OK; return B_OK;
} }
media_output *output; media_output *output;
for (rn->outputlist.Rewind(); rn->outputlist.GetNext(&output); ) { for (rn->outputlist.Rewind(); rn->outputlist.GetNext(&output); ) {
if (output->source.port == port) { if (output->source.port == port) {
*nodeid = rn->nodeid; *nodeID = rn->node_id;
TRACE("NodeManager::FindNodeId found output port %ld, node %ld\n", port, *nodeid); TRACE("NodeManager::FindNodeID found output port %ld, node %ld\n", port, *nodeid);
return B_OK; return B_OK;
} }
} }
media_input *input; media_input *input;
for (rn->inputlist.Rewind(); rn->inputlist.GetNext(&input); ) { for (rn->inputlist.Rewind(); rn->inputlist.GetNext(&input); ) {
if (input->destination.port == port) { if (input->destination.port == port) {
*nodeid = rn->nodeid; *nodeID = rn->node_id;
TRACE("NodeManager::FindNodeId found input port %ld, node %ld\n", port, *nodeid); TRACE("NodeManager::FindNodeID found input port %ld, node %ld\n", port, *nodeid);
return B_OK; return B_OK;
} }
} }
} }
ERROR("NodeManager::FindNodeId failed, port %ld\n", port); ERROR("NodeManager::FindNodeID failed, port %ld\n", port);
return B_ERROR; return B_ERROR;
} }
status_t status_t
NodeManager::GetDormantNodeInfo(dormant_node_info *node_info, const media_node &node) NodeManager::GetDormantNodeInfo(dormant_node_info *node_info, const media_node &node)
{ {
@@ -404,7 +411,7 @@ NodeManager::GetDormantNodeInfo(dormant_node_info *node_info, const media_node &
// XXX not sure if this is correct // XXX not sure if this is correct
registered_node *rn; registered_node *rn;
for (fRegisteredNodeMap->Rewind(); fRegisteredNodeMap->GetNext(&rn); ) { for (fRegisteredNodeMap->Rewind(); fRegisteredNodeMap->GetNext(&rn); ) {
if (rn->nodeid == node.node) { if (rn->node_id == node.node) {
if (rn->addon_id == -1 && node.node != NODE_SYSTEM_TIMESOURCE_ID) { // This function must return an error if the node is application owned if (rn->addon_id == -1 && node.node != NODE_SYSTEM_TIMESOURCE_ID) { // This function must return an error if the node is application owned
TRACE("NodeManager::GetDormantNodeInfo NODE IS APPLICATION OWNED! node %ld, addon_id %ld, addon_flavor_id %ld, name \"%s\"\n", node.node, rn->addon_id, rn->addon_flavor_id, rn->name); TRACE("NodeManager::GetDormantNodeInfo NODE IS APPLICATION OWNED! node %ld, addon_id %ld, addon_flavor_id %ld, name \"%s\"\n", node.node, rn->addon_id, rn->addon_flavor_id, rn->name);
return B_ERROR; return B_ERROR;
@@ -422,13 +429,14 @@ NodeManager::GetDormantNodeInfo(dormant_node_info *node_info, const media_node &
return B_ERROR; return B_ERROR;
} }
status_t status_t
NodeManager::GetLiveNodeInfo(live_node_info *live_info, const media_node &node) NodeManager::GetLiveNodeInfo(live_node_info *live_info, const media_node &node)
{ {
BAutolock lock(fLocker); BAutolock lock(fLocker);
registered_node *rn; registered_node *rn;
for (fRegisteredNodeMap->Rewind(); fRegisteredNodeMap->GetNext(&rn); ) { for (fRegisteredNodeMap->Rewind(); fRegisteredNodeMap->GetNext(&rn); ) {
if (rn->nodeid == node.node) { if (rn->node_id == node.node) {
ASSERT(node.port == rn->port); ASSERT(node.port == rn->port);
ASSERT((node.kind & NODE_KIND_COMPARE_MASK) == (rn->kinds & NODE_KIND_COMPARE_MASK)); ASSERT((node.kind & NODE_KIND_COMPARE_MASK) == (rn->kinds & NODE_KIND_COMPARE_MASK));
live_info->node = node; live_info->node = node;
@@ -451,7 +459,7 @@ NodeManager::GetInstances(media_node_id *node_ids, int32* count, int32 maxcount,
*count = 0; *count = 0;
for (fRegisteredNodeMap->Rewind(); (maxcount > 0) && fRegisteredNodeMap->GetNext(&rn); ) { for (fRegisteredNodeMap->Rewind(); (maxcount > 0) && fRegisteredNodeMap->GetNext(&rn); ) {
if (rn->addon_id == addon_id && rn->addon_flavor_id == addon_flavor_id) { if (rn->addon_id == addon_id && rn->addon_flavor_id == addon_flavor_id) {
node_ids[*count] = rn->nodeid; node_ids[*count] = rn->node_id;
*count += 1; *count += 1;
maxcount -= 1; maxcount -= 1;
} }
@@ -467,7 +475,7 @@ NodeManager::GetLiveNodes(Stack<live_node_info> *livenodes, int32 maxcount, cons
BAutolock lock(fLocker); BAutolock lock(fLocker);
registered_node *rn; registered_node *rn;
int namelen; int namelen;
TRACE("NodeManager::GetLiveNodes: maxcount %ld, in-format %p, out-format %p, name %s, require_kinds 0x%Lx\n", TRACE("NodeManager::GetLiveNodes: maxcount %ld, in-format %p, out-format %p, name %s, require_kinds 0x%Lx\n",
maxcount, inputformat, outputformat, (name ? name : "NULL"), require_kinds); maxcount, inputformat, outputformat, (name ? name : "NULL"), require_kinds);
@@ -513,7 +521,7 @@ NodeManager::GetLiveNodes(Stack<live_node_info> *livenodes, int32 maxcount, cons
} }
live_node_info lni; live_node_info lni;
lni.node.node = rn->nodeid; lni.node.node = rn->node_id;
lni.node.port = rn->port; lni.node.port = rn->port;
lni.node.kind = rn->kinds; lni.node.kind = rn->kinds;
lni.hint_point = BPoint(0, 0); lni.hint_point = BPoint(0, 0);
@@ -526,16 +534,17 @@ NodeManager::GetLiveNodes(Stack<live_node_info> *livenodes, int32 maxcount, cons
return B_OK; return B_OK;
} }
/* Add media_node_id of all live nodes to the message
* int32 "media_node_id" (multiple items) /*! Add media_node_id of all live nodes to the message
*/ int32 "media_node_id" (multiple items)
*/
status_t status_t
NodeManager::GetLiveNodes(BMessage *msg) NodeManager::GetLiveNodes(BMessage *msg)
{ {
BAutolock lock(fLocker); BAutolock lock(fLocker);
registered_node *rn; registered_node *rn;
for (fRegisteredNodeMap->Rewind(); fRegisteredNodeMap->GetNext(&rn); ) { for (fRegisteredNodeMap->Rewind(); fRegisteredNodeMap->GetNext(&rn); ) {
msg->AddInt32("media_node_id", rn->nodeid); msg->AddInt32("media_node_id", rn->node_id);
} }
return B_OK; return B_OK;
} }
@@ -544,16 +553,16 @@ NodeManager::GetLiveNodes(BMessage *msg)
* Registration of BMediaAddOns * Registration of BMediaAddOns
**********************************************************************/ **********************************************************************/
void void
NodeManager::RegisterAddon(const entry_ref &ref, media_addon_id *newid) NodeManager::RegisterAddon(const entry_ref &ref, media_addon_id *newid)
{ {
BAutolock lock(fLocker); BAutolock lock(fLocker);
media_addon_id id; media_addon_id id;
id = fNextAddOnID; id = fNextAddOnID;
fNextAddOnID += 1; fNextAddOnID += 1;
printf("NodeManager::RegisterAddon: ref-name \"%s\", assigning id %ld\n", ref.name, id); printf("NodeManager::RegisterAddon: ref-name \"%s\", assigning id %ld\n", ref.name, id);
fAddonPathMap->Insert(id, ref); fAddonPathMap->Insert(id, ref);
*newid = id; *newid = id;
} }
@@ -579,7 +588,7 @@ NodeManager::GetAddonRef(entry_ref *ref, media_addon_id id)
*ref = *tempref; *ref = *tempref;
return B_OK; return B_OK;
} }
return B_ERROR; return B_ERROR;
} }
@@ -592,7 +601,7 @@ void
NodeManager::AddDormantFlavorInfo(const dormant_flavor_info &dfi) NodeManager::AddDormantFlavorInfo(const dormant_flavor_info &dfi)
{ {
BAutolock lock(fLocker); BAutolock lock(fLocker);
printf("NodeManager::AddDormantFlavorInfo, addon-id %ld, flavor-id %ld, name \"%s\", flavor-name \"%s\", flavor-info \"%s\"\n", dfi.node_info.addon, dfi.node_info.flavor_id, dfi.node_info.name, dfi.name, dfi.info); printf("NodeManager::AddDormantFlavorInfo, addon-id %ld, flavor-id %ld, name \"%s\", flavor-name \"%s\", flavor-info \"%s\"\n", dfi.node_info.addon, dfi.node_info.flavor_id, dfi.node_info.name, dfi.name, dfi.info);
// Try to find the addon-id/flavor-id in the list. // Try to find the addon-id/flavor-id in the list.
@@ -670,8 +679,8 @@ NodeManager::IncrementAddonFlavorInstancesCount(media_addon_id addonid, int32 fl
ERROR("NodeManager::IncrementAddonFlavorInstancesCount addonid %ld, flavorid %ld maximum (or more) instances already exist\n", addonid, flavorid); ERROR("NodeManager::IncrementAddonFlavorInstancesCount addonid %ld, flavorid %ld maximum (or more) instances already exist\n", addonid, flavorid);
return B_ERROR; // maximum (or more) instances already exist return B_ERROR; // maximum (or more) instances already exist
} }
bool b; bool b;
int32 *count; int32 *count;
b = dafi->TeamInstancesCount.Get(team, &count); b = dafi->TeamInstancesCount.Get(team, &count);
if (b) { if (b) {
@@ -697,7 +706,7 @@ NodeManager::DecrementAddonFlavorInstancesCount(media_addon_id addonid, int32 fl
if (dafi->AddonID != addonid || dafi->AddonFlavorID != flavorid) if (dafi->AddonID != addonid || dafi->AddonFlavorID != flavorid)
continue; continue;
bool b; bool b;
int32 *count; int32 *count;
b = dafi->TeamInstancesCount.Get(team, &count); b = dafi->TeamInstancesCount.Get(team, &count);
if (!b) { if (!b) {
@@ -728,7 +737,7 @@ NodeManager::CleanupDormantFlavorInfos()
// XXX FlavorsChanged(media_addon_id addonid, int32 newcount, int32 gonecount) // XXX FlavorsChanged(media_addon_id addonid, int32 newcount, int32 gonecount)
} }
status_t status_t
NodeManager::GetDormantNodes(dormant_node_info * out_info, NodeManager::GetDormantNodes(dormant_node_info * out_info,
int32 * io_count, int32 * io_count,
const media_format * has_input /* = NULL */, const media_format * has_input /* = NULL */,
@@ -751,7 +760,7 @@ NodeManager::GetDormantNodes(dormant_node_info * out_info,
namelen = 0; namelen = 0;
} }
maxcount = *io_count; maxcount = *io_count;
*io_count = 0; *io_count = 0;
for (fDormantAddonFlavorList->Rewind(); (*io_count < maxcount) && fDormantAddonFlavorList->GetNext(&dafi); ) { for (fDormantAddonFlavorList->Rewind(); (*io_count < maxcount) && fDormantAddonFlavorList->GetNext(&dafi); ) {
if (!dafi->InfoValid) if (!dafi->InfoValid)
@@ -788,7 +797,7 @@ NodeManager::GetDormantNodes(dormant_node_info * out_info,
if (!hasit) if (!hasit)
continue; continue;
} }
out_info[*io_count] = dfi->node_info; out_info[*io_count] = dfi->node_info;
*io_count += 1; *io_count += 1;
} }
@@ -796,7 +805,7 @@ NodeManager::GetDormantNodes(dormant_node_info * out_info,
return B_OK; return B_OK;
} }
status_t status_t
NodeManager::GetDormantFlavorInfoFor(media_addon_id addon, NodeManager::GetDormantFlavorInfoFor(media_addon_id addon,
int32 flavor_id, int32 flavor_id,
dormant_flavor_info *outFlavor) dormant_flavor_info *outFlavor)
@@ -807,7 +816,7 @@ NodeManager::GetDormantFlavorInfoFor(media_addon_id addon,
if (dafi->AddonID == addon && dafi->AddonFlavorID == flavor_id && dafi->InfoValid == true) { if (dafi->AddonID == addon && dafi->AddonFlavorID == flavor_id && dafi->InfoValid == true) {
*outFlavor = dafi->Info; *outFlavor = dafi->Info;
return B_OK; return B_OK;
} }
} }
return B_ERROR; return B_ERROR;
} }
@@ -867,9 +876,9 @@ NodeManager::CleanupTeam(team_id team)
PRINT(1, "NodeManager::CleanupTeam: team %ld\n", team); PRINT(1, "NodeManager::CleanupTeam: team %ld\n", team);
// XXX send notifications after removing nodes // XXX send notifications after removing nodes
// Cleanup node references // Cleanup node references
registered_node *rn; registered_node *rn;
for (fRegisteredNodeMap->Rewind(); fRegisteredNodeMap->GetNext(&rn); ) { for (fRegisteredNodeMap->Rewind(); fRegisteredNodeMap->GetNext(&rn); ) {
// if the gone team was the creator of some global dormant node instance, we now invalidate that // if the gone team was the creator of some global dormant node instance, we now invalidate that
@@ -901,11 +910,11 @@ NodeManager::CleanupTeam(team_id team)
fRegisteredNodeMap->RemoveCurrent(); fRegisteredNodeMap->RemoveCurrent();
} }
} }
// Cleanup addon references // Cleanup addon references
dormant_addon_flavor_info *dafi; dormant_addon_flavor_info *dafi;
for (fDormantAddonFlavorList->Rewind(); fDormantAddonFlavorList->GetNext(&dafi); ) { for (fDormantAddonFlavorList->Rewind(); fDormantAddonFlavorList->GetNext(&dafi); ) {
bool b; bool b;
int32 *count; int32 *count;
b = dafi->TeamInstancesCount.Get(team, &count); b = dafi->TeamInstancesCount.Get(team, &count);
if (b) { if (b) {
@@ -946,7 +955,7 @@ NodeManager::Dump()
{ {
BAutolock lock(fLocker); BAutolock lock(fLocker);
printf("\n"); printf("\n");
/* for each addon-id, the addon path map contains an entry_ref /* for each addon-id, the addon path map contains an entry_ref
*/ */
printf("NodeManager: addon path map follows:\n"); printf("NodeManager: addon path map follows:\n");
@@ -966,7 +975,7 @@ NodeManager::Dump()
registered_node *rn; registered_node *rn;
for (fRegisteredNodeMap->Rewind(); fRegisteredNodeMap->GetNext(&rn); ) { for (fRegisteredNodeMap->Rewind(); fRegisteredNodeMap->GetNext(&rn); ) {
printf(" node-id %ld, addon-id %ld, addon-flavor-id %ld, port %ld, creator %ld, team %ld, kinds %#08Lx, name \"%s\"\n", printf(" node-id %ld, addon-id %ld, addon-flavor-id %ld, port %ld, creator %ld, team %ld, kinds %#08Lx, name \"%s\"\n",
rn->nodeid, rn->addon_id, rn->addon_flavor_id, rn->port, rn->creator, rn->team, rn->kinds, rn->name); rn->node_id, rn->addon_id, rn->addon_flavor_id, rn->port, rn->creator, rn->team, rn->kinds, rn->name);
printf(" teams (refcount): "); printf(" teams (refcount): ");
team_id *team; team_id *team;
int32 *refcount; int32 *refcount;
@@ -993,7 +1002,7 @@ NodeManager::Dump()
printf("NodeManager: list end\n"); printf("NodeManager: list end\n");
printf("\n"); printf("\n");
/* /*
*/ */
printf("NodeManager: dormant flavor list follows:\n"); printf("NodeManager: dormant flavor list follows:\n");
dormant_addon_flavor_info *dafi; dormant_addon_flavor_info *dafi;
+13 -12
View File
@@ -1,4 +1,4 @@
/* /*
* Copyright 2002, Marcus Overhagen. All rights reserved. * Copyright 2002, Marcus Overhagen. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -10,7 +10,7 @@
struct registered_node { struct registered_node {
media_node_id nodeid; media_node_id node_id;
media_addon_id addon_id; media_addon_id addon_id;
int32 addon_flavor_id; int32 addon_flavor_id;
char name[B_MEDIA_NAME_LENGTH]; char name[B_MEDIA_NAME_LENGTH];
@@ -26,11 +26,11 @@ struct registered_node {
struct dormant_addon_flavor_info { struct dormant_addon_flavor_info {
media_addon_id AddonID; media_addon_id AddonID;
int32 AddonFlavorID; int32 AddonFlavorID;
int32 MaxInstancesCount; int32 MaxInstancesCount;
int32 GlobalInstancesCount; int32 GlobalInstancesCount;
Map<team_id, int32> TeamInstancesCount; Map<team_id, int32> TeamInstancesCount;
bool InfoValid; bool InfoValid;
@@ -47,23 +47,24 @@ public:
status_t LoadState(); status_t LoadState();
status_t SaveState(); status_t SaveState();
void Dump(); void Dump();
/* Management of system wide default nodes */ /* Management of system wide default nodes */
status_t SetDefaultNode(node_type type, const media_node *node, const dormant_node_info *info, const media_input *input); status_t SetDefaultNode(node_type type, const media_node *node, const dormant_node_info *info, const media_input *input);
status_t GetDefaultNode(media_node_id *nodeid, char *input_name, int32 *input_id, node_type type); status_t GetDefaultNode(media_node_id* nodeID, char* name, int32* id,
node_type type);
status_t RescanDefaultNodes(); status_t RescanDefaultNodes();
/* Management of live nodes */ /* Management of live nodes */
status_t RegisterNode(media_node_id *nodeid, media_addon_id addon_id, int32 addon_flavor_id, const char *name, uint64 kinds, port_id port, team_id team); status_t RegisterNode(media_node_id *nodeid, media_addon_id addon_id, int32 addon_flavor_id, const char *name, uint64 kinds, port_id port, team_id team);
status_t UnregisterNode(media_addon_id *addonid, int32 *flavorid, media_node_id nodeid, team_id team); status_t UnregisterNode(media_addon_id *addonid, int32 *flavorid, media_node_id nodeid, team_id team);
status_t GetCloneForId(media_node *node, media_node_id nodeid, team_id team); status_t GetCloneForID(media_node* node, media_node_id nodeID, team_id team);
status_t GetClone(media_node *node, char *input_name, int32 *input_id, node_type type, team_id team); status_t GetClone(media_node *node, char *input_name, int32 *input_id, node_type type, team_id team);
status_t ReleaseNode(const media_node &node, team_id team); status_t ReleaseNode(const media_node &node, team_id team);
status_t PublishInputs(const media_node &node, const media_input *inputs, int32 count); status_t PublishInputs(const media_node &node, const media_input *inputs, int32 count);
status_t PublishOutputs(const media_node &node, const media_output *outputs, int32 count); status_t PublishOutputs(const media_node &node, const media_output *outputs, int32 count);
status_t FindNodeId(media_node_id *nodeid, port_id port); status_t FindNodeID(media_node_id* nodeID, port_id port);
status_t GetLiveNodeInfo(live_node_info *live_info, const media_node &node); status_t GetLiveNodeInfo(live_node_info *live_info, const media_node &node);
status_t GetInstances(media_node_id *node_ids, int32* count, int32 maxcount, media_addon_id addon_id, int32 addon_flavor_id); status_t GetInstances(media_node_id *node_ids, int32* count, int32 maxcount, media_addon_id addon_id, int32 addon_flavor_id);
status_t GetLiveNodes(Stack<live_node_info> *livenodes, int32 maxcount, const media_format *inputformat = NULL, const media_format *outputformat = NULL, const char* name = NULL, uint64 require_kinds = 0); status_t GetLiveNodes(Stack<live_node_info> *livenodes, int32 maxcount, const media_format *inputformat = NULL, const media_format *outputformat = NULL, const char* name = NULL, uint64 require_kinds = 0);
@@ -80,8 +81,8 @@ public:
void RegisterAddon(const entry_ref &ref, media_addon_id *newid); void RegisterAddon(const entry_ref &ref, media_addon_id *newid);
void UnregisterAddon(media_addon_id id); void UnregisterAddon(media_addon_id id);
void AddDormantFlavorInfo(const dormant_flavor_info &dfi); void AddDormantFlavorInfo(const dormant_flavor_info &dfi);
void InvalidateDormantFlavorInfo(media_addon_id id); void InvalidateDormantFlavorInfo(media_addon_id id);
void RemoveDormantFlavorInfo(media_addon_id id); void RemoveDormantFlavorInfo(media_addon_id id);
void CleanupDormantFlavorInfos(); void CleanupDormantFlavorInfos();
@@ -103,11 +104,11 @@ public:
dormant_flavor_info *outFlavor); dormant_flavor_info *outFlavor);
void CleanupTeam(team_id team); void CleanupTeam(team_id team);
private: private:
media_addon_id fNextAddOnID; media_addon_id fNextAddOnID;
media_node_id fNextNodeID; media_node_id fNextNodeID;
BLocker *fLocker; BLocker *fLocker;
List<dormant_addon_flavor_info> *fDormantAddonFlavorList; List<dormant_addon_flavor_info> *fDormantAddonFlavorList;
Map<media_addon_id,entry_ref> *fAddonPathMap; Map<media_addon_id,entry_ref> *fAddonPathMap;
-63
View File
@@ -1,63 +0,0 @@
#ifndef _SERVER_INTERFACE_H_
#define _SERVER_INTERFACE_H_
#include <MediaDefs.h>
#include <MediaNode.h>
#include <MediaAddOn.h>
#include <Entry.h>
enum {
ADDONSERVER_INSTANTIATE_DORMANT_NODE,
SERVER_REGISTER_MEDIAADDON,
SERVER_UNREGISTER_MEDIAADDON,
SERVER_GET_MEDIAADDON_REF,
SERVER_REGISTER_DORMANT_NODE,
SERVER_GET_DORMANT_NODES,
SERVER_GET_DORMANT_FLAVOR_INFO,
END
};
struct xfer_server_get_dormant_flavor_info
{
media_addon_id addon;
int32 flavor_id;
port_id reply_port;
};
struct xfer_server_get_dormant_flavor_info_reply
{
status_t result;
type_code dfi_type; // the flatten type_code
size_t dfi_size;
char dfi[1]; // a flattened dormant_flavor_info, dfi_size large
};
struct xfer_server_get_dormant_nodes
{
int32 maxcount;
bool has_input;
media_format inputformat;
bool has_output;
media_format outputformat;
bool has_name;
char name[B_MEDIA_NAME_LENGTH + 1]; // 1 for a trailing "*"
uint64 require_kinds;
uint64 deny_kinds;
port_id reply_port;
};
struct xfer_server_get_dormant_nodes_reply
{
status_t result;
int32 count; // if count > 0, a second reply containing count dormant_node_infos is send
};
struct xfer_server_register_dormant_node
{
media_addon_id purge_id; // if > 0, server must first remove all dormant_flavor_infos belonging to that id
type_code dfi_type; // the flatten type_code
size_t dfi_size;
char dfi[1]; // a flattened dormant_flavor_info, dfi_size large
};
#endif
+71 -60
View File
@@ -27,10 +27,15 @@
* *
*/ */
/* to comply with the license above, do not remove the following line */ /* to comply with the license above, do not remove the following line */
char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002, 2003 " char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002, 2003 "
"Marcus Overhagen <[email protected]>"; "Marcus Overhagen <[email protected]>";
#include <stdio.h>
#include <string.h>
#include <Alert.h> #include <Alert.h>
#include <Application.h> #include <Application.h>
#include <Autolock.h> #include <Autolock.h>
@@ -40,9 +45,6 @@ char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002, 2003 "
#include <MediaFormats.h> #include <MediaFormats.h>
#include <Messenger.h> #include <Messenger.h>
#include <stdio.h>
#include <string.h>
#include "AddOnManager.h" #include "AddOnManager.h"
#include "AppManager.h" #include "AppManager.h"
#include "BufferManager.h" #include "BufferManager.h"
@@ -56,12 +58,6 @@ char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002, 2003 "
#include "debug.h" #include "debug.h"
#include "media_server.h" #include "media_server.h"
/*
*
* An implementation of a new media_server for the OpenBeOS MediaKit
* Started by Marcus Overhagen <marcus@overhagen.de> on 2001-10-25
*
*/
AddOnManager * gAddOnManager; AddOnManager * gAddOnManager;
AppManager * gAppManager; AppManager * gAppManager;
@@ -217,7 +213,7 @@ ServerApp::ArgvReceived(int32 argc, char **argv)
void void
ServerApp::StartAddonServer() ServerApp::StartAddonServer()
{ {
// Try to launch media_addon_server by mime signature. // Try to launch media_addon_server by mime signature.
// If it fails (for example on the Live CD, where the executable // If it fails (for example on the Live CD, where the executable
// hasn't yet been mimesetted), try from this application's // hasn't yet been mimesetted), try from this application's
@@ -225,7 +221,7 @@ ServerApp::StartAddonServer()
status_t err = be_roster->Launch(B_MEDIA_ADDON_SERVER_SIGNATURE); status_t err = be_roster->Launch(B_MEDIA_ADDON_SERVER_SIGNATURE);
if (err == B_OK) if (err == B_OK)
return; return;
app_info info; app_info info;
BEntry entry; BEntry entry;
BDirectory dir; BDirectory dir;
@@ -310,10 +306,10 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
ASSERT(request->delta == 1 || request->delta == -1); ASSERT(request->delta == 1 || request->delta == -1);
if (request->delta == 1) { if (request->delta == 1) {
rv = gNodeManager->IncrementAddonFlavorInstancesCount( rv = gNodeManager->IncrementAddonFlavorInstancesCount(
request->addonid, request->flavorid, request->team); request->addon_id, request->flavor_id, request->team);
} else { } else {
rv = gNodeManager->DecrementAddonFlavorInstancesCount( rv = gNodeManager->DecrementAddonFlavorInstancesCount(
request->addonid, request->flavorid, request->team); request->addon_id, request->flavor_id, request->team);
} }
request->SendReply(rv, &reply, sizeof(reply)); request->SendReply(rv, &reply, sizeof(reply));
break; break;
@@ -352,7 +348,7 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
= (server_get_mediaaddon_ref_request *)data; = (server_get_mediaaddon_ref_request *)data;
server_get_mediaaddon_ref_reply reply; server_get_mediaaddon_ref_reply reply;
entry_ref tempref; entry_ref tempref;
reply.result = gNodeManager->GetAddonRef(&tempref, msg->addonid); reply.result = gNodeManager->GetAddonRef(&tempref, msg->addon_id);
reply.ref = tempref; reply.ref = tempref;
write_port(msg->reply_port, 0, &reply, sizeof(reply)); write_port(msg->reply_port, 0, &reply, sizeof(reply));
break; break;
@@ -363,7 +359,7 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
const server_node_id_for_request *request const server_node_id_for_request *request
= reinterpret_cast<const server_node_id_for_request *>(data); = reinterpret_cast<const server_node_id_for_request *>(data);
server_node_id_for_reply reply; server_node_id_for_reply reply;
rv = gNodeManager->FindNodeId(&reply.nodeid, request->port); rv = gNodeManager->FindNodeID(&reply.node_id, request->port);
request->SendReply(rv, &reply, sizeof(reply)); request->SendReply(rv, &reply, sizeof(reply));
break; break;
} }
@@ -432,7 +428,7 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
const server_get_node_for_request *request const server_get_node_for_request *request
= reinterpret_cast<const server_get_node_for_request *>(data); = reinterpret_cast<const server_get_node_for_request *>(data);
server_get_node_for_reply reply; server_get_node_for_reply reply;
rv = gNodeManager->GetCloneForId(&reply.clone, request->nodeid, rv = gNodeManager->GetCloneForID(&reply.clone, request->node_id,
request->team); request->team);
request->SendReply(rv, &reply, sizeof(reply)); request->SendReply(rv, &reply, sizeof(reply));
break; break;
@@ -453,7 +449,7 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
const server_register_node_request *request const server_register_node_request *request
= reinterpret_cast<const server_register_node_request *>(data); = reinterpret_cast<const server_register_node_request *>(data);
server_register_node_reply reply; server_register_node_reply reply;
rv = gNodeManager->RegisterNode(&reply.nodeid, request->addon_id, rv = gNodeManager->RegisterNode(&reply.node_id, request->addon_id,
request->addon_flavor_id, request->name, request->kinds, request->addon_flavor_id, request->name, request->kinds,
request->port, request->team); request->port, request->team);
request->SendReply(rv, &reply, sizeof(reply)); request->SendReply(rv, &reply, sizeof(reply));
@@ -466,8 +462,8 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
= reinterpret_cast<const server_unregister_node_request *>( = reinterpret_cast<const server_unregister_node_request *>(
data); data);
server_unregister_node_reply reply; server_unregister_node_reply reply;
rv = gNodeManager->UnregisterNode(&reply.addonid, &reply.flavorid, rv = gNodeManager->UnregisterNode(&reply.addon_id, &reply.flavor_id,
request->nodeid, request->team); request->node_id, request->team);
request->SendReply(rv, &reply, sizeof(reply)); request->SendReply(rv, &reply, sizeof(reply));
break; break;
} }
@@ -588,7 +584,7 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
server_register_mediaaddon_request *msg server_register_mediaaddon_request *msg
= (server_register_mediaaddon_request *)data; = (server_register_mediaaddon_request *)data;
server_register_mediaaddon_reply reply; server_register_mediaaddon_reply reply;
gNodeManager->RegisterAddon(msg->ref, &reply.addonid); gNodeManager->RegisterAddon(msg->ref, &reply.addon_id);
write_port(msg->reply_port, 0, &reply, sizeof(reply)); write_port(msg->reply_port, 0, &reply, sizeof(reply));
break; break;
} }
@@ -597,20 +593,22 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
{ {
server_unregister_mediaaddon_command *msg server_unregister_mediaaddon_command *msg
= (server_unregister_mediaaddon_command *)data; = (server_unregister_mediaaddon_command *)data;
gNodeManager->UnregisterAddon(msg->addonid); gNodeManager->UnregisterAddon(msg->addon_id);
break; break;
} }
case SERVER_REGISTER_DORMANT_NODE: case SERVER_REGISTER_DORMANT_NODE:
{ {
xfer_server_register_dormant_node *msg xfer_server_register_dormant_node* msg
= (xfer_server_register_dormant_node *)data; = (xfer_server_register_dormant_node*)data;
dormant_flavor_info dfi;
if (msg->purge_id > 0) if (msg->purge_id > 0)
gNodeManager->InvalidateDormantFlavorInfo(msg->purge_id); gNodeManager->InvalidateDormantFlavorInfo(msg->purge_id);
rv = dfi.Unflatten(msg->dfi_type, &(msg->dfi), msg->dfi_size);
ASSERT(rv == B_OK); dormant_flavor_info dormantFlavorInfo;
gNodeManager->AddDormantFlavorInfo(dfi); status_t status = dormantFlavorInfo.Unflatten(msg->type,
msg->flattened_data, msg->flattened_size);
if (status == B_OK)
gNodeManager->AddDormantFlavorInfo(dormantFlavorInfo);
break; break;
} }
@@ -618,24 +616,29 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
{ {
xfer_server_get_dormant_nodes *msg xfer_server_get_dormant_nodes *msg
= (xfer_server_get_dormant_nodes *)data; = (xfer_server_get_dormant_nodes *)data;
xfer_server_get_dormant_nodes_reply reply; xfer_server_get_dormant_nodes_reply reply;
dormant_node_info * infos = new dormant_node_info[msg->maxcount]; reply.count = msg->max_count;
reply.count = msg->maxcount;
reply.result = gNodeManager->GetDormantNodes( dormant_node_info* infos
infos, = new(std::nothrow) dormant_node_info[reply.count];
&reply.count, if (infos != NULL) {
msg->has_input ? &msg->inputformat : NULL, reply.result = gNodeManager->GetDormantNodes(infos,
msg->has_output ? &msg->outputformat : NULL, &reply.count, msg->has_input ? &msg->input_format : NULL,
msg->has_name ? msg->name : NULL, msg->has_output ? &msg->output_format : NULL,
msg->require_kinds, msg->has_name ? msg->name : NULL, msg->require_kinds,
msg->deny_kinds); msg->deny_kinds);
} else
reply.result = B_NO_MEMORY;
if (reply.result != B_OK) if (reply.result != B_OK)
reply.count = 0; reply.count = 0;
write_port(msg->reply_port, 0, &reply, sizeof(reply)); write_port(msg->reply_port, 0, &reply, sizeof(reply));
if (reply.count > 0) if (reply.count > 0) {
write_port(msg->reply_port, 0, infos, reply.count write_port(msg->reply_port, 0, infos,
* sizeof(dormant_node_info)); reply.count * sizeof(dormant_node_info));
delete [] infos; }
delete[] infos;
break; break;
} }
@@ -643,40 +646,48 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
{ {
xfer_server_get_dormant_flavor_info *msg xfer_server_get_dormant_flavor_info *msg
= (xfer_server_get_dormant_flavor_info *)data; = (xfer_server_get_dormant_flavor_info *)data;
dormant_flavor_info dfi; dormant_flavor_info dormantFlavorInfo;
status_t rv; status_t rv;
rv = gNodeManager->GetDormantFlavorInfoFor(msg->addon, rv = gNodeManager->GetDormantFlavorInfoFor(msg->addon,
msg->flavor_id, &dfi); msg->flavor_id, &dormantFlavorInfo);
if (rv != B_OK) { if (rv != B_OK) {
xfer_server_get_dormant_flavor_info_reply reply; xfer_server_get_dormant_flavor_info_reply reply;
reply.result = rv; reply.result = rv;
write_port(msg->reply_port, 0, &reply, sizeof(reply)); write_port(msg->reply_port, 0, &reply, sizeof(reply));
} else { } else {
xfer_server_get_dormant_flavor_info_reply *reply; size_t replySize
int replysize; = sizeof(xfer_server_get_dormant_flavor_info_reply)
replysize = sizeof(xfer_server_get_dormant_flavor_info_reply) + dormantFlavorInfo.FlattenedSize();
+ dfi.FlattenedSize(); xfer_server_get_dormant_flavor_info_reply* reply
reply = (xfer_server_get_dormant_flavor_info_reply *)malloc( = (xfer_server_get_dormant_flavor_info_reply*)malloc(
replysize); replySize);
if (reply != NULL) {
reply->type = dormantFlavorInfo.TypeCode();
reply->flattened_size = dormantFlavorInfo.FlattenedSize();
reply->result = dormantFlavorInfo.Flatten(
reply->flattened_data, reply->flattened_size);
reply->dfi_size = dfi.FlattenedSize(); write_port(msg->reply_port, 0, reply, replySize);
reply->dfi_type = dfi.TypeCode(); free(reply);
reply->result = dfi.Flatten(reply->dfi, reply->dfi_size); } else {
write_port(msg->reply_port, 0, reply, replysize); xfer_server_get_dormant_flavor_info_reply reply;
free(reply); reply.result = B_NO_MEMORY;
write_port(msg->reply_port, 0, &reply, sizeof(reply));
}
} }
break; break;
} }
case SERVER_SET_NODE_CREATOR: case SERVER_SET_NODE_CREATOR:
{ {
const server_set_node_creator_request *request const server_set_node_creator_request* request
= reinterpret_cast<const server_set_node_creator_request *>( = reinterpret_cast<const server_set_node_creator_request*>(
data); data);
server_set_node_creator_reply reply; server_set_node_creator_reply reply;
rv = gNodeManager->SetNodeCreator(request->node, request->creator); status_t status = gNodeManager->SetNodeCreator(request->node,
request->SendReply(rv, &reply, sizeof(reply)); request->creator);
request->SendReply(status, &reply, sizeof(reply));
break; break;
} }
@@ -687,7 +698,7 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
const server_get_shared_buffer_area_request *>(data); const server_get_shared_buffer_area_request *>(data);
server_get_shared_buffer_area_reply reply; server_get_shared_buffer_area_reply reply;
reply.area = gBufferManager->SharedBufferListID(); reply.area = gBufferManager->SharedBufferListArea();
request->SendReply(B_OK, &reply, sizeof(reply)); request->SendReply(B_OK, &reply, sizeof(reply));
break; break;
} }
@@ -722,7 +733,7 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
const server_unregister_buffer_command *cmd = reinterpret_cast< const server_unregister_buffer_command *cmd = reinterpret_cast<
const server_unregister_buffer_command *>(data); const server_unregister_buffer_command *>(data);
gBufferManager->UnregisterBuffer(cmd->team, cmd->bufferid); gBufferManager->UnregisterBuffer(cmd->team, cmd->buffer_id);
break; break;
} }
-4
View File
@@ -6,10 +6,6 @@ UsePrivateHeaders media shared ;
AddResources media_addon_server : media_addon_server.rdef ; AddResources media_addon_server : media_addon_server.rdef ;
# That's ugly. The header (ServerInterface.h) should reside in
# headers/private/media.
SubDirHdrs [ FDirName $(HAIKU_TOP) src servers media ] ;
Server media_addon_server : Server media_addon_server :
main.cpp main.cpp
MediaFilePlayer.cpp MediaFilePlayer.cpp
File diff suppressed because it is too large Load Diff