* Rewrote Buffer.h, and BufferConsumer.h, that's enough for a day :-)

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32583 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2009-08-21 20:21:45 +00:00
parent 3580aefbfe
commit 7c26f9d16d
2 changed files with 200 additions and 268 deletions

View File

@ -1,108 +1,96 @@
/*******************************************************************************
/
/ File: Buffer.h
/
/ Description: A BBuffer is a container of media data in the Media Kit
/
/ Copyright 1997-98, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#if !defined(_BUFFER_H)
/*
* Copyright 2009, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _BUFFER_H
#define _BUFFER_H
#include <MediaDefs.h>
/*** A BBuffer is not the same thing as the area segment that gets cloned ***/
/*** For each buffer that gets created, a BBuffer object is created to represent ***/
/*** it in each participant address space. ***/
struct _shared_buffer_list;
struct buffer_clone_info {
buffer_clone_info();
~buffer_clone_info();
media_buffer_id buffer;
area_id area;
size_t offset;
size_t size;
int32 flags;
private:
uint32 _reserved_[4];
};
buffer_clone_info();
~buffer_clone_info();
class BBuffer
{
public:
void * Data(); /* returns NULL if buffer not correctly initialized */
size_t SizeAvailable(); // total size of buffer (how much data can it hold)
size_t SizeUsed(); // how much was written (how much data does it hold)
void SetSizeUsed(
size_t size_used);
uint32 Flags();
void Recycle();
buffer_clone_info CloneInfo() const;
media_buffer_id ID(); /* 0 if not registered */
media_type Type();
media_header * Header();
media_audio_header * AudioHeader();
media_video_header * VideoHeader();
enum { /* for flags */
B_F1_BUFFER = 0x1,
B_F2_BUFFER = 0x2,
B_SMALL_BUFFER = 0x80000000
};
size_t Size(); // deprecated; use SizeAvailable()
media_buffer_id buffer;
area_id area;
size_t offset;
size_t size;
int32 flags;
private:
friend struct _buffer_id_cache;
friend struct _shared_buffer_list;
friend class BMediaRoster;
friend class BBufferProducer;
friend class BBufferConsumer; /* for buffer receiving */
friend class BBufferGroup;
friend class BSmallBuffer;
explicit BBuffer(const buffer_clone_info & info);
~BBuffer(); /* BBuffer is NOT a virtual class!!! */
BBuffer(); /* not implemented */
BBuffer(const BBuffer & clone); /* not implemented */
BBuffer & operator=(const BBuffer & clone); /* not implemented */
void SetHeader(const media_header *header);
media_header fMediaHeader;
_shared_buffer_list * fBufferList;
area_id fArea;
void * fData;
size_t fOffset;
size_t fSize;
media_buffer_id fBufferID;
int32 fFlags;
uint32 _reserved_buffer_[11];
uint32 _reserved_[4];
};
class BSmallBuffer : public BBuffer
{
class BBuffer {
public:
BSmallBuffer();
// flags
enum {
B_F1_BUFFER = 0x1,
B_F2_BUFFER = 0x2,
B_SMALL_BUFFER = 0x80000000
};
static size_t SmallBufferSizeLimit();
void* Data();
size_t SizeAvailable();
size_t SizeUsed();
void SetSizeUsed(size_t used);
uint32 Flags();
void Recycle();
buffer_clone_info CloneInfo() const;
media_buffer_id ID();
media_type Type();
media_header* Header();
media_audio_header* AudioHeader();
media_video_header* VideoHeader();
size_t Size();
private:
friend struct _buffer_id_cache;
friend struct _shared_buffer_list;
friend class BMediaRoster;
friend class BBufferProducer;
friend class BBufferConsumer;
friend class BBufferGroup;
friend class BSmallBuffer;
explicit BBuffer(const buffer_clone_info& info);
~BBuffer();
BBuffer();
BBuffer(const BBuffer& other);
BBuffer& operator=(const BBuffer& other);
// not implemented
void SetHeader(const media_header* header);
media_header fMediaHeader;
_shared_buffer_list* fBufferList;
area_id fArea;
void* fData;
size_t fOffset;
size_t fSize;
media_buffer_id fBufferID;
int32 fFlags;
uint32 _reserved[11];
};
#endif /* _BUFFER_H */
class BSmallBuffer : public BBuffer {
public:
BSmallBuffer();
static size_t SmallBufferSizeLimit();
};
#endif // _BUFFER_H

View File

@ -1,212 +1,156 @@
/*******************************************************************************
/
/ File: BufferConsumer.h
/
/ Description: A BBufferConsumer is anything that wants to receive buffers in the Media Kit
/
/ Copyright 1997-98, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#if !defined(_BUFFER_CONSUMER_H)
/*
* Copyright 2009, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _BUFFER_CONSUMER_H
#define _BUFFER_CONSUMER_H
#include <MediaDefs.h>
#include <MediaNode.h>
class BBuffer;
class BBufferGroup;
class BRegion;
namespace BPrivate { namespace media {
class BMediaRosterEx;
}}
class _buffer_id_cache;
class BBufferConsumer :
public virtual BMediaNode
{
namespace BPrivate {
namespace media {
class BMediaRosterEx;
}
}
class BBufferConsumer : public virtual BMediaNode {
protected:
/* this has to be at the top to force a vtable */
virtual ~BBufferConsumer();
virtual ~BBufferConsumer();
public:
media_type ConsumerType();
media_type ConsumerType();
/* for encoding a region into the format needed for clipping requests */
static status_t RegionToClipData(
const BRegion * region,
int32 * format,
int32 * ioSize,
void * data);
static status_t RegionToClipData(const BRegion* region,
int32* format, int32* size, void* data);
protected:
explicit BBufferConsumer(
media_type consumer_type /* = B_MEDIA_UNKNOWN_TYPE */);
explicit BBufferConsumer(media_type type);
static void NotifyLateProducer(
const media_source & what_source,
bigtime_t how_much,
bigtime_t performance_time);
status_t SetVideoClippingFor(
const media_source & output,
const media_destination & destination,
const int16 * shorts,
int32 short_count,
const media_video_display_info & display,
void * user_data,
int32 * change_tag,
void * _reserved_ = 0); // change_tag value will be passed to RequestCompleted()
status_t SetOutputEnabled(
const media_source & source,
const media_destination & destination,
bool enabled,
void * user_data,
int32 * change_tag,
void * _reserved_ = 0); // change_tag value will be passed to RequestCompleted()
status_t RequestFormatChange(
const media_source & source,
const media_destination & destination,
const media_format & to_format,
void * user_data,
int32 * change_tag,
void * _reserved_ = 0); // change_tag value will be passed to RequestCompleted()
status_t RequestAdditionalBuffer( // new in 4.1
const media_source & source,
BBuffer * prev_buffer,
void * _reserved = NULL);
status_t RequestAdditionalBuffer( // new in 4.1
const media_source & source,
bigtime_t start_time,
void * _reserved = NULL);
status_t SetOutputBuffersFor( // new in 4.1
const media_source & source,
const media_destination & destination,
BBufferGroup * group,
void * user_data,
int32 * change_tag, // passed to RequestCompleted()
bool will_reclaim = false,
void * _reserved_ = 0);
status_t SendLatencyChange(
const media_source & source,
const media_destination & destination,
bigtime_t my_new_latency,
uint32 flags = 0);
static void NotifyLateProducer(
const media_source& whatSource,
bigtime_t howMuch,
bigtime_t performanceTime);
status_t SetVideoClippingFor(const media_source& output,
const media_destination& destination,
const int16* shorts, int32 shortCount,
const media_video_display_info& display,
void* userData, int32* changeTag,
void* _reserved = NULL);
status_t SetOutputEnabled(const media_source& source,
const media_destination& destination,
bool enabled, void* userData,
int32* changeTag, void* _reserved = NULL);
status_t RequestFormatChange(const media_source& source,
const media_destination& destination,
const media_format& toFormat,
void* userData, int32* changeTag,
void* _reserved = NULL);
status_t RequestAdditionalBuffer(
const media_source& source,
BBuffer* previousBuffer,
void* _reserved = NULL);
status_t RequestAdditionalBuffer(
const media_source& source,
bigtime_t startTime,
void* _reserved = NULL);
status_t SetOutputBuffersFor(const media_source& source,
const media_destination& destination,
BBufferGroup* group, void* userData,
int32* changeTag, bool willReclaim = false,
void* _reserved = NULL);
status_t SendLatencyChange(const media_source& source,
const media_destination& destination,
bigtime_t newLatency, uint32 flags = 0);
protected:
virtual status_t HandleMessage(int32 message, const void* data,
size_t size);
virtual status_t HandleMessage(
int32 message,
const void * data,
size_t size);
virtual status_t AcceptFormat(
const media_destination& destination,
media_format* format) = 0;
virtual status_t GetNextInput(int32* cookie,
media_input* _input) = 0;
virtual void DisposeInputCookie(int32 cookie) = 0;
virtual void BufferReceived(BBuffer* buffer) = 0;
virtual void ProducerDataStatus(
const media_destination& forWhom,
int32 status,
bigtime_t atPerformanceTime) = 0;
virtual status_t GetLatencyFor(const media_destination& forWhom,
bigtime_t* _latency,
media_node_id* _timesource) = 0;
virtual status_t Connected(const media_source& producer,
const media_destination& where,
const media_format& withFormat,
media_input* _input) = 0;
virtual void Disconnected(const media_source& producer,
const media_destination& where) = 0;
virtual status_t FormatChanged(const media_source& producer,
const media_destination& consumer,
int32 changeTag,
const media_format& format) = 0;
/* Someone, probably the producer, is asking you about this format. Give */
/* your honest opinion, possibly modifying *format. Do not ask upstream */
/* producer about the format, since he's synchronously waiting for your */
/* reply. */
virtual status_t AcceptFormat(
const media_destination & dest,
media_format * ioFormat) = 0;
virtual status_t GetNextInput(
int32 * cookie,
media_input * out_input) = 0;
virtual void DisposeInputCookie(
int32 cookie) = 0;
virtual void BufferReceived(
BBuffer * buffer) = 0;
virtual void ProducerDataStatus(
const media_destination & for_whom,
int32 status,
bigtime_t at_performance_time) = 0;
virtual status_t GetLatencyFor(
const media_destination & for_whom,
bigtime_t * out_latency,
media_node_id * out_timesource) = 0;
virtual status_t Connected(
const media_source & producer, /* here's a good place to request buffer group usage */
const media_destination & where,
const media_format & with_format,
media_input * out_input) = 0;
virtual void Disconnected(
const media_source & producer,
const media_destination & where) = 0;
/* The notification comes from the upstream producer, so he's already cool with */
/* the format; you should not ask him about it in here. */
virtual status_t FormatChanged(
const media_source & producer,
const media_destination & consumer,
int32 change_tag,
const media_format & format) = 0;
/* Given a performance time of some previous buffer, retrieve the remembered tag */
/* of the closest (previous or exact) performance time. Set *out_flags to 0; the */
/* idea being that flags can be added later, and the understood flags returned in */
/* *out_flags. */
virtual status_t SeekTagRequested(
const media_destination & destination,
bigtime_t in_target_time,
uint32 in_flags,
media_seek_tag * out_seek_tag,
bigtime_t * out_tagged_time,
uint32 * out_flags);
virtual status_t SeekTagRequested(
const media_destination& destination,
bigtime_t targetTime, uint32 flags,
media_seek_tag* _seekTag,
bigtime_t* _taggedTime, uint32* _flags);
private:
BBufferConsumer(); /* private unimplemented */
BBufferConsumer(
const BBufferConsumer & clone);
BBufferConsumer & operator=(
const BBufferConsumer & clone);
// these functions are deprecated from the 4.0 API
static status_t SetVideoClippingFor(
const media_source & output,
const int16 * shorts,
int32 short_count,
const media_video_display_info & display,
int32 * change_tag); // change_tag value will be passed to RequestCompleted()
static status_t RequestFormatChange(
const media_source & source,
const media_destination & destination,
media_format * io_to_format, // the "o" part is unused from 4.1
int32 * change_tag); // change_tag value will be passed to RequestCompleted()
static status_t SetOutputEnabled(
const media_source & source,
bool enabled,
int32 * change_tag); // change_tag value will be passed to RequestCompleted()
/* Mmmh, stuffing! */
status_t _Reserved_BufferConsumer_0(void *); /* SeekTagRequested */
virtual status_t _Reserved_BufferConsumer_1(void *);
virtual status_t _Reserved_BufferConsumer_2(void *);
virtual status_t _Reserved_BufferConsumer_3(void *);
virtual status_t _Reserved_BufferConsumer_4(void *);
virtual status_t _Reserved_BufferConsumer_5(void *);
virtual status_t _Reserved_BufferConsumer_6(void *);
virtual status_t _Reserved_BufferConsumer_7(void *);
virtual status_t _Reserved_BufferConsumer_8(void *);
virtual status_t _Reserved_BufferConsumer_9(void *);
virtual status_t _Reserved_BufferConsumer_10(void *);
virtual status_t _Reserved_BufferConsumer_11(void *);
virtual status_t _Reserved_BufferConsumer_12(void *);
virtual status_t _Reserved_BufferConsumer_13(void *);
virtual status_t _Reserved_BufferConsumer_14(void *);
virtual status_t _Reserved_BufferConsumer_15(void *);
friend class BMediaNode;
friend class BBufferProducer;
friend class BMediaRoster;
friend class BPrivate::media::BMediaRosterEx;
media_type fConsumerType;
_buffer_id_cache * fBufferCache;
BBufferGroup *fDeleteBufferGroup;
uint32 _reserved_buffer_consumer_[14];
BBufferConsumer();
BBufferConsumer(const BBufferConsumer& other);
BBufferConsumer& operator=(const BBufferConsumer& other);
// deprecated methods following
static status_t SetVideoClippingFor(const media_source& output,
const int16* shorts, int32 shortCount,
const media_video_display_info& display,
int32* changeTag);
static status_t RequestFormatChange(const media_source& source,
const media_destination& destination,
media_format* toFormat, int32* changeTag);
static status_t SetOutputEnabled(const media_source& source,
bool enabled, int32* changeTag);
status_t _Reserved_BufferConsumer_0(void*);
// used for SeekTagRequested()
virtual status_t _Reserved_BufferConsumer_1(void*);
virtual status_t _Reserved_BufferConsumer_2(void*);
virtual status_t _Reserved_BufferConsumer_3(void*);
virtual status_t _Reserved_BufferConsumer_4(void*);
virtual status_t _Reserved_BufferConsumer_5(void*);
virtual status_t _Reserved_BufferConsumer_6(void*);
virtual status_t _Reserved_BufferConsumer_7(void*);
virtual status_t _Reserved_BufferConsumer_8(void*);
virtual status_t _Reserved_BufferConsumer_9(void*);
virtual status_t _Reserved_BufferConsumer_10(void*);
virtual status_t _Reserved_BufferConsumer_11(void*);
virtual status_t _Reserved_BufferConsumer_12(void*);
virtual status_t _Reserved_BufferConsumer_13(void*);
virtual status_t _Reserved_BufferConsumer_14(void*);
virtual status_t _Reserved_BufferConsumer_15(void*);
private:
media_type fConsumerType;
_buffer_id_cache* fBufferCache;
BBufferGroup* fDeleteBufferGroup;
uint32 _reserved[14];
};
#endif /* _BUFFER_CONSUMER_H */
#endif // _BUFFER_CONSUMER_H