It should now list and instanciate devices correctly... but doesn't work yet :-(

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20361 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol 2007-03-09 15:43:41 +00:00
parent 517df2f7f3
commit 75d00d2451
2 changed files with 136 additions and 7 deletions

View File

@ -7,11 +7,13 @@
#include <media/MediaAddOn.h>
#include <Autolock.h>
#include <Directory.h>
#include <Entry.h>
#include <Path.h>
#include <String.h>
#include "LegacyMediaAddOn.h"
#include "LegacyAudioConsumer.h"
@ -21,20 +23,38 @@
LegacyMediaAddOn::LegacyMediaAddOn( image_id imid )
: BMediaAddOn( imid )
, fInternalIds( 0 )
, fListsLock( "LegacyMediaAddOn:ListLock" )
{
fInitStatus = B_NO_INIT;
consumer = new LegacyAudioConsumer( this, "ymf744/1", 0 );
fMediaFormat.type = B_MEDIA_RAW_AUDIO;
fMediaFormat.u.raw_audio = media_raw_audio_format::wildcard;
fInitStatus = RecursiveScanForDevices();
//consumer = new LegacyAudioConsumer( this, "ymf744/1", 0 );
//producer = new LegacyAudioProducer( "maestro2/1" );
fInitStatus = B_OK;
}
LegacyMediaAddOn::~LegacyMediaAddOn()
{
delete consumer;
//delete consumer;
//delete producer;
LegacyDevice *dev;
while ((dev = (LegacyDevice *)fConsumers.RemoveItem((int32)0))) {
delete dev->consumer;
//delete dev->producer;
delete dev;
}
while ((dev = (LegacyDevice *)fProducers.RemoveItem((int32)0))) {
//delete dev->consumer;
//delete dev->producer;
delete dev;
}
}
@ -48,13 +68,35 @@ LegacyMediaAddOn::InitCheck( const char **out_failure_text )
int32
LegacyMediaAddOn::CountFlavors()
{
return 0;
int32 count;
BAutolock al(fListsLock);
count = fConsumers.CountItems() + fProducers.CountItems();
return count;
}
status_t
LegacyMediaAddOn::GetFlavorAt( int32 n, const flavor_info **out_info )
{
BAutolock al(fListsLock);
LegacyDevice *dev;
if (n < 0)
return EINVAL;
for (n = fConsumers.CountItems() - 1; n >= 0; n--) {
dev = (LegacyDevice *)fConsumers.ItemAt(n);
if (dev->flavor.internal_id != n)
continue;
*out_info = &dev->flavor;
return B_OK;
}
for (n = fProducers.CountItems() - 1; n >= 0; n--) {
dev = (LegacyDevice *)fProducers.ItemAt(n);
if (dev->flavor.internal_id != n)
continue;
*out_info = &dev->flavor;
return B_OK;
}
return B_ERROR;
}
@ -62,6 +104,37 @@ LegacyMediaAddOn::GetFlavorAt( int32 n, const flavor_info **out_info )
BMediaNode *
LegacyMediaAddOn::InstantiateNodeFor( const flavor_info *info, BMessage *config, status_t *out_error )
{
BAutolock al(fListsLock);
LegacyDevice *dev;
int32 n;
int32 consumerCount = fConsumers.CountItems();
for (n = consumerCount - 1; n >= 0; n--) {
dev = (LegacyDevice *)fConsumers.ItemAt(n);
//if (info != &dev->flavor) // XXX memcmp?
if (info->internal_id != dev->flavor.internal_id)
continue;
if (dev->inuse) // EBUSY!
return NULL;
dev->consumer = new LegacyAudioConsumer( this, dev->name.String(), n );
if (!dev->consumer)
return NULL;
dev->inuse = true;
return dev->consumer;
}
/*
for (n = fProducers.CountItems() - 1; n >= 0; n--) {
dev = (LegacyDevice *)fProducers.ItemAt(n);
if (info != &dev->flavor) // XXX memcmp?
continue;
if (dev->inuse) // EBUSY!
return NULL;
dev->producer = new LegacyAudioProducer( this, dev->name.String(), consumerCount + n );
if (!dev->producer)
return NULL;
dev->inuse = true;
return dev->producer;
}
*/
return NULL;
}
@ -94,14 +167,56 @@ LegacyMediaAddOn::RecursiveScanForDevices(const char *path)
s.RemoveFirst(LEGACY_DEVICE_PATH_BASE"/");
// XXX: should check first for consumer or producer...
// XXX: use a struct/class
fConsumers.AddItem((void *)s.String());
LegacyDevice *dev = new LegacyDevice;
dev->name = s.String();
dev->flavor.name = (char *)/*WTF*/dev->name.String();
dev->flavor.info = (char *)dev->name.String();
dev->flavor.kinds = B_BUFFER_CONSUMER | /*B_CONTROLLABLE |*/ B_PHYSICAL_OUTPUT;
dev->flavor.flavor_flags = 0; //B_FLAVOR_IS_GLOBAL;
dev->flavor.internal_id = fInternalIds++;
dev->flavor.possible_count = 1;
dev->flavor.in_format_count = 1;
dev->flavor.in_format_flags = 0;
dev->flavor.in_formats = &fMediaFormat;
dev->flavor.out_format_count = 0;
dev->flavor.out_format_flags = 0;
dev->flavor.out_formats = NULL;
dev->inuse = false;
dev->consumer = NULL;
//dev->producer = NULL;
fConsumers.AddItem((void *)dev);
//XXX: only cons for now
//fProducers.AddItem(s.String());
}
return B_OK;
}
#if 0
struct flavor_info {
char * name;
char * info;
uint64 kinds; /* node_kind */
uint32 flavor_flags;
int32 internal_id; /* For BMediaAddOn internal use */
int32 possible_count; /* 0 for "any number" */
int32 in_format_count; /* for BufferConsumer kinds */
uint32 in_format_flags; /* set to 0 */
const media_format * in_formats;
int32 out_format_count; /* for BufferProducer kinds */
uint32 out_format_flags; /* set to 0 */
const media_format * out_formats;
uint32 _reserved_[16];
private:
flavor_info & operator=(const flavor_info & other);
};
#endif
BMediaAddOn *
make_media_addon( image_id imid )
{

View File

@ -3,11 +3,23 @@
#include <media/MediaAddOn.h>
#include <List.h>
#include <Locker.h>
#include <String.h>
#include "LegacyAudioConsumer.h"
//#include "LegacyAudioProducer.h"
class LegacyDevice {
public:
BString name;
flavor_info flavor;
bool inuse;
LegacyAudioConsumer *consumer;
//LegacyAudioProducer *producer;
};
class LegacyMediaAddOn : public BMediaAddOn
{
public:
@ -34,14 +46,16 @@ class LegacyMediaAddOn : public BMediaAddOn
private:
status_t fInitStatus;
int32 fInternalIds;
flavor_info fFlavorInfo;
media_format fMediaFormat;
BLocker fListsLock;
BList fConsumers;
BList fProducers;
LegacyAudioConsumer *consumer;
//OLD:LegacyAudioConsumer *consumer;
};