* Cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33998 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
#include <TimeSource.h>
|
||||
#include <Buffer.h>
|
||||
#include <stdlib.h>
|
||||
#include "ConsumerNode.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <Buffer.h>
|
||||
#include <TimeSource.h>
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
ConsumerNode::ConsumerNode() :
|
||||
|
||||
ConsumerNode::ConsumerNode()
|
||||
:
|
||||
BBufferConsumer(B_MEDIA_RAW_AUDIO),
|
||||
BMediaEventLooper(),
|
||||
BMediaNode("ConsumerNode")
|
||||
@@ -12,127 +18,130 @@ ConsumerNode::ConsumerNode() :
|
||||
out("ConsumerNode::ConsumerNode\n");
|
||||
}
|
||||
|
||||
|
||||
ConsumerNode::~ConsumerNode()
|
||||
{
|
||||
{
|
||||
out("ConsumerNode::~ConsumerNode\n");
|
||||
Quit();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConsumerNode::NodeRegistered()
|
||||
{
|
||||
out("ConsumerNode::NodeRegistered\n");
|
||||
InitializeInput();
|
||||
SetPriority(108);
|
||||
Run();
|
||||
SetPriority(108);
|
||||
Run();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ConsumerNode::AcceptFormat(
|
||||
const media_destination & dest,
|
||||
media_format * format)
|
||||
ConsumerNode::AcceptFormat(const media_destination& dest, media_format* format)
|
||||
{
|
||||
out("ConsumerNode::AcceptFormat\n");
|
||||
|
||||
if (dest != mInput.destination)
|
||||
if (dest != fInput.destination)
|
||||
return B_MEDIA_BAD_DESTINATION;
|
||||
|
||||
if (format == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
|
||||
if (format->type != B_MEDIA_RAW_AUDIO)
|
||||
return B_MEDIA_BAD_FORMAT;
|
||||
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ConsumerNode::GetNextInput(
|
||||
int32 * cookie,
|
||||
media_input * out_input)
|
||||
ConsumerNode::GetNextInput(int32* cookie, media_input* _input)
|
||||
{
|
||||
out("ConsumerNode::GetNextInput\n");
|
||||
|
||||
if (out_input == NULL)
|
||||
if (_input == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
|
||||
if (++(*cookie) > 1)
|
||||
return B_BAD_INDEX;
|
||||
|
||||
*out_input = mInput;
|
||||
|
||||
*_input = fInput;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConsumerNode::DisposeInputCookie(
|
||||
int32 cookie)
|
||||
ConsumerNode::DisposeInputCookie(int32 cookie)
|
||||
{
|
||||
out("ConsumerNode::DisposeInputCookie\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConsumerNode::BufferReceived(
|
||||
BBuffer * buffer)
|
||||
ConsumerNode::BufferReceived(BBuffer* buffer)
|
||||
{
|
||||
out("ConsumerNode::BufferReceived, sheduled time = %5.4f\n",buffer->Header()->start_time / 1E6);
|
||||
media_timed_event event(buffer->Header()->start_time,BTimedEventQueue::B_HANDLE_BUFFER,
|
||||
buffer, BTimedEventQueue::B_RECYCLE_BUFFER);
|
||||
out("ConsumerNode::BufferReceived, sheduled time = %5.4f\n",
|
||||
buffer->Header()->start_time / 1E6);
|
||||
|
||||
media_timed_event event(buffer->Header()->start_time,
|
||||
BTimedEventQueue::B_HANDLE_BUFFER, buffer,
|
||||
BTimedEventQueue::B_RECYCLE_BUFFER);
|
||||
EventQueue()->AddEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConsumerNode::ProducerDataStatus(
|
||||
const media_destination & for_whom,
|
||||
int32 status,
|
||||
bigtime_t at_performance_time)
|
||||
ConsumerNode::ProducerDataStatus(const media_destination& forWhom, int32 status,
|
||||
bigtime_t atPerformanceTime)
|
||||
{
|
||||
out("ConsumerNode::ProducerDataStatus\n");
|
||||
if (for_whom == mInput.destination) {
|
||||
media_timed_event event(at_performance_time,BTimedEventQueue::B_DATA_STATUS,
|
||||
&mInput, BTimedEventQueue::B_NO_CLEANUP, status, 0, NULL);
|
||||
|
||||
if (forWhom == fInput.destination) {
|
||||
media_timed_event event(atPerformanceTime,
|
||||
BTimedEventQueue::B_DATA_STATUS, &fInput,
|
||||
BTimedEventQueue::B_NO_CLEANUP, status, 0, NULL);
|
||||
EventQueue()->AddEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ConsumerNode::GetLatencyFor(
|
||||
const media_destination & for_whom,
|
||||
bigtime_t * out_latency,
|
||||
media_node_id * out_timesource)
|
||||
ConsumerNode::GetLatencyFor(const media_destination& forWhom,
|
||||
bigtime_t* _latency, media_node_id* _timesource)
|
||||
{
|
||||
out("ConsumerNode::GetLatencyFor\n");
|
||||
// make sure this is one of my valid inputs
|
||||
if (for_whom != mInput.destination)
|
||||
if (forWhom != fInput.destination)
|
||||
return B_MEDIA_BAD_DESTINATION;
|
||||
|
||||
*out_latency = 23000;
|
||||
*out_timesource = TimeSource()->ID();
|
||||
*_latency = 23000;
|
||||
*_timesource = TimeSource()->ID();
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ConsumerNode::Connected(
|
||||
const media_source & producer,
|
||||
const media_destination & where,
|
||||
const media_format & with_format,
|
||||
media_input * out_input)
|
||||
ConsumerNode::Connected(const media_source& producer,
|
||||
const media_destination& where, const media_format& withFormat,
|
||||
media_input* _input)
|
||||
{
|
||||
out("ConsumerNode::Connected\n");
|
||||
if (where != mInput.destination)
|
||||
if (where != fInput.destination)
|
||||
return B_MEDIA_BAD_DESTINATION;
|
||||
|
||||
// calculate my latency here, because it may depend on buffer sizes/durations, then
|
||||
// tell the BMediaEventLooper how early we need to get the buffers
|
||||
SetEventLatency(10 * 1000); //fixme
|
||||
// calculate my latency here, because it may depend on buffer
|
||||
// sizes/durations, then tell the BMediaEventLooper how early
|
||||
// we need to get the buffers
|
||||
SetEventLatency(10 * 1000); // TODO: fix me
|
||||
|
||||
/* reserve the connection */
|
||||
mInput.source = producer;
|
||||
mInput.format = with_format;
|
||||
fInput.source = producer;
|
||||
fInput.format = withFormat;
|
||||
|
||||
/* and publish it's name and connection info */
|
||||
*out_input = mInput;
|
||||
*_input = fInput;
|
||||
|
||||
#if 0
|
||||
/* create the buffer group */
|
||||
@@ -150,10 +159,10 @@ ConsumerNode::Connected(
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConsumerNode::Disconnected(
|
||||
const media_source & producer,
|
||||
const media_destination & where)
|
||||
ConsumerNode::Disconnected(const media_source& producer,
|
||||
const media_destination& where)
|
||||
{
|
||||
out("ConsumerNode::Disconnected\n");
|
||||
|
||||
@@ -166,136 +175,127 @@ ConsumerNode::Disconnected(
|
||||
if (mOwnBufferGroup != NULL) {
|
||||
delete_own_buffer_group();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ConsumerNode::FormatChanged(
|
||||
const media_source & producer,
|
||||
const media_destination & consumer,
|
||||
int32 change_tag,
|
||||
const media_format & format)
|
||||
ConsumerNode::FormatChanged(const media_source& producer,
|
||||
const media_destination& consumer, int32 changeTag,
|
||||
const media_format& format)
|
||||
{
|
||||
out("ConsumerNode::FormatChanged\n");
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
status_t
|
||||
ConsumerNode::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)
|
||||
|
||||
status_t
|
||||
ConsumerNode::SeekTagRequested(const media_destination& destination,
|
||||
bigtime_t targetTime, uint32 flags, media_seek_tag* _seekTag,
|
||||
bigtime_t* _taggedTime, uint32* _flags)
|
||||
{
|
||||
out("ConsumerNode::SeekTagRequested\n");
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
BMediaAddOn*
|
||||
ConsumerNode::AddOn(int32 * internal_id) const
|
||||
|
||||
BMediaAddOn*
|
||||
ConsumerNode::AddOn(int32* internalID) const
|
||||
{
|
||||
out("ConsumerNode::AddOn\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
ConsumerNode::HandleEvent(const media_timed_event *event,
|
||||
bigtime_t lateness,
|
||||
bool realTimeEvent)
|
||||
|
||||
void
|
||||
ConsumerNode::HandleEvent(const media_timed_event* event, bigtime_t lateness,
|
||||
bool realTimeEvent)
|
||||
{
|
||||
switch (event->type)
|
||||
{
|
||||
case BTimedEventQueue::B_HANDLE_BUFFER:
|
||||
switch (event->type) {
|
||||
case BTimedEventQueue::B_HANDLE_BUFFER:
|
||||
{
|
||||
out("ConsumerNode::HandleEvent B_HANDLE_BUFFER\n");
|
||||
BBuffer* buffer = const_cast<BBuffer*>((BBuffer*) event->pointer);
|
||||
BBuffer* buffer = const_cast<BBuffer*>((BBuffer*)event->pointer);
|
||||
|
||||
out("### sheduled time = %5.4f, current time = %5.4f, lateness = "
|
||||
"%5.4f\n", buffer->Header()->start_time / 1E6,
|
||||
TimeSource()->Now() / 1E6,lateness / 1E6);
|
||||
|
||||
snooze((rand() * 100) % 200000);
|
||||
|
||||
out("### sheduled time = %5.4f, current time = %5.4f, lateness = %5.4f\n",buffer->Header()->start_time / 1E6,TimeSource()->Now() / 1E6,lateness / 1E6);
|
||||
|
||||
snooze((rand()*100) % 200000);
|
||||
|
||||
if (buffer)
|
||||
buffer->Recycle();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case BTimedEventQueue::B_PARAMETER:
|
||||
{
|
||||
case BTimedEventQueue::B_PARAMETER:
|
||||
out("ConsumerNode::HandleEvent B_PARAMETER\n");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case BTimedEventQueue::B_START:
|
||||
{
|
||||
case BTimedEventQueue::B_START:
|
||||
out("ConsumerNode::HandleEvent B_START\n");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case BTimedEventQueue::B_STOP:
|
||||
{
|
||||
case BTimedEventQueue::B_STOP:
|
||||
out("ConsumerNode::HandleEvent B_STOP\n");
|
||||
}
|
||||
// stopping implies not handling any more buffers. So, we flush all pending
|
||||
// buffers out of the event queue before returning to the event loop.
|
||||
EventQueue()->FlushEvents(0, BTimedEventQueue::B_ALWAYS, true, BTimedEventQueue::B_HANDLE_BUFFER);
|
||||
break;
|
||||
// stopping implies not handling any more buffers. So, we flush
|
||||
// all pending buffers out of the event queue before returning to
|
||||
// the event loop.
|
||||
EventQueue()->FlushEvents(0, BTimedEventQueue::B_ALWAYS, true,
|
||||
BTimedEventQueue::B_HANDLE_BUFFER);
|
||||
break;
|
||||
|
||||
case BTimedEventQueue::B_SEEK:
|
||||
{
|
||||
case BTimedEventQueue::B_SEEK:
|
||||
out("ConsumerNode::HandleEvent B_SEEK\n");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case BTimedEventQueue::B_WARP:
|
||||
{
|
||||
case BTimedEventQueue::B_WARP:
|
||||
out("ConsumerNode::HandleEvent B_WARP\n");
|
||||
}
|
||||
// similarly, time warps aren't meaningful to the logger, so just record it and return
|
||||
//mLogger->Log(LOG_WARP_HANDLED, logMsg);
|
||||
break;
|
||||
// similarly, time warps aren't meaningful to the logger, so just
|
||||
// record it and return
|
||||
//mLogger->Log(LOG_WARP_HANDLED, logMsg);
|
||||
break;
|
||||
|
||||
case BTimedEventQueue::B_DATA_STATUS:
|
||||
{
|
||||
case BTimedEventQueue::B_DATA_STATUS:
|
||||
out("ConsumerNode::HandleEvent B_DATA_STATUS\n");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
default:
|
||||
out("ConsumerNode::HandleEvent default\n");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
status_t
|
||||
ConsumerNode::HandleMessage(int32 message,const void *data, size_t size)
|
||||
|
||||
status_t
|
||||
ConsumerNode::HandleMessage(int32 message, const void* data, size_t size)
|
||||
{
|
||||
out("ConsumerNode::HandleMessage %lx\n",message);
|
||||
if (B_OK == BBufferConsumer::HandleMessage(message,data,size))
|
||||
out("ConsumerNode::HandleMessage %lx\n", message);
|
||||
|
||||
if (BBufferConsumer::HandleMessage(message, data, size) == B_OK
|
||||
|| BMediaEventLooper::HandleMessage(message, data, size) == B_OK)
|
||||
return B_OK;
|
||||
if (B_OK == BMediaEventLooper::HandleMessage(message,data,size))
|
||||
return B_OK;
|
||||
return BMediaNode::HandleMessage(message,data,size);
|
||||
|
||||
return BMediaNode::HandleMessage(message, data, size);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
void
|
||||
ConsumerNode::InitializeInput()
|
||||
{
|
||||
out("ConsumerNode::InitializeInput()\n");
|
||||
mInput.source = media_source::null;
|
||||
mInput.destination.port = ControlPort();
|
||||
mInput.destination.id = 0;
|
||||
mInput.node = Node();
|
||||
mInput.format.type = B_MEDIA_RAW_AUDIO;
|
||||
mInput.format.u.raw_audio = media_raw_audio_format::wildcard;
|
||||
mInput.format.u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT;
|
||||
mInput.format.u.raw_audio.channel_count = 1;
|
||||
mInput.format.u.raw_audio.frame_rate = 44100;
|
||||
mInput.format.u.raw_audio.byte_order = (B_HOST_IS_BENDIAN) ? B_MEDIA_BIG_ENDIAN : B_MEDIA_LITTLE_ENDIAN;
|
||||
strcpy(mInput.name, "this way in");
|
||||
fInput.source = media_source::null;
|
||||
fInput.destination.port = ControlPort();
|
||||
fInput.destination.id = 0;
|
||||
fInput.node = Node();
|
||||
fInput.format.type = B_MEDIA_RAW_AUDIO;
|
||||
fInput.format.u.raw_audio = media_raw_audio_format::wildcard;
|
||||
fInput.format.u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT;
|
||||
fInput.format.u.raw_audio.channel_count = 1;
|
||||
fInput.format.u.raw_audio.frame_rate = 44100;
|
||||
fInput.format.u.raw_audio.byte_order = B_HOST_IS_BENDIAN
|
||||
? B_MEDIA_BIG_ENDIAN : B_MEDIA_LITTLE_ENDIAN;
|
||||
strcpy(fInput.name, "this way in");
|
||||
}
|
||||
|
||||
@@ -2,71 +2,60 @@
|
||||
#include <BufferConsumer.h>
|
||||
#include <MediaEventLooper.h>
|
||||
|
||||
class ConsumerNode : public virtual BBufferConsumer, BMediaEventLooper
|
||||
{
|
||||
|
||||
class ConsumerNode : public virtual BBufferConsumer, BMediaEventLooper {
|
||||
public:
|
||||
ConsumerNode();
|
||||
~ConsumerNode();
|
||||
ConsumerNode();
|
||||
virtual ~ConsumerNode();
|
||||
|
||||
protected:
|
||||
/* functionality of BMediaNode */
|
||||
virtual void NodeRegistered();
|
||||
virtual void NodeRegistered();
|
||||
|
||||
/* BBufferConsumer */
|
||||
virtual status_t AcceptFormat(
|
||||
const media_destination & dest,
|
||||
media_format * format);
|
||||
virtual status_t GetNextInput(
|
||||
int32 * cookie,
|
||||
media_input * out_input);
|
||||
virtual void DisposeInputCookie(
|
||||
int32 cookie);
|
||||
virtual void BufferReceived(
|
||||
BBuffer * buffer);
|
||||
virtual void ProducerDataStatus(
|
||||
const media_destination & for_whom,
|
||||
int32 status,
|
||||
bigtime_t at_performance_time);
|
||||
virtual status_t GetLatencyFor(
|
||||
const media_destination & for_whom,
|
||||
bigtime_t * out_latency,
|
||||
media_node_id * out_timesource);
|
||||
virtual status_t Connected(
|
||||
const media_source & producer,
|
||||
const media_destination & where,
|
||||
const media_format & with_format,
|
||||
media_input * out_input);
|
||||
virtual void Disconnected(
|
||||
const media_source & producer,
|
||||
const media_destination & where);
|
||||
virtual status_t FormatChanged(
|
||||
const media_source & producer,
|
||||
const media_destination & consumer,
|
||||
int32 change_tag,
|
||||
const media_format & format);
|
||||
virtual status_t AcceptFormat(const media_destination& dest,
|
||||
media_format* format);
|
||||
virtual status_t GetNextInput(int32* cookie,
|
||||
media_input* _input);
|
||||
virtual void DisposeInputCookie(int32 cookie);
|
||||
virtual void BufferReceived(BBuffer* buffer);
|
||||
virtual void ProducerDataStatus(
|
||||
const media_destination& forWhom,
|
||||
int32 status, bigtime_t atPerformanceTime);
|
||||
virtual status_t GetLatencyFor(const media_destination& forWhom,
|
||||
bigtime_t* _latency,
|
||||
media_node_id* _timesource);
|
||||
virtual status_t Connected(const media_source& producer,
|
||||
const media_destination& where,
|
||||
const media_format& withFormat,
|
||||
media_input* _input);
|
||||
virtual void Disconnected(const media_source& producer,
|
||||
const media_destination& where);
|
||||
virtual status_t FormatChanged(const media_source& producer,
|
||||
const media_destination& consumer,
|
||||
int32 changeTag,
|
||||
const media_format& format);
|
||||
|
||||
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 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);
|
||||
|
||||
/* from BMediaNode */
|
||||
virtual BMediaAddOn* AddOn(
|
||||
int32 * internal_id) const;
|
||||
virtual status_t SeekTagRequested(
|
||||
const media_destination& destination,
|
||||
bigtime_t targetTime, uint32 flags,
|
||||
media_seek_tag* _seekTag,
|
||||
bigtime_t* _taggedTime, uint32* _flags);
|
||||
|
||||
/* from BMediaEventLooper */
|
||||
virtual void HandleEvent(const media_timed_event *event,
|
||||
bigtime_t lateness,
|
||||
bool realTimeEvent = false);
|
||||
/* from BMediaNode */
|
||||
virtual BMediaAddOn* AddOn(int32* internalID) const;
|
||||
|
||||
/* our own functionality */
|
||||
void InitializeInput();
|
||||
/* from BMediaEventLooper */
|
||||
virtual void HandleEvent(const media_timed_event* event,
|
||||
bigtime_t lateness,
|
||||
bool realTimeEvent = false);
|
||||
|
||||
media_input mInput;
|
||||
media_format mPreferredFormat;
|
||||
/* our own functionality */
|
||||
void InitializeInput();
|
||||
|
||||
private:
|
||||
media_input fInput;
|
||||
};
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
SubDir HAIKU_TOP src tests kits media nodetest ;
|
||||
|
||||
SimpleTest NodeTest
|
||||
: main.cpp
|
||||
misc.cpp
|
||||
ConsumerNode.cpp
|
||||
ProducerNode.cpp
|
||||
: libmedia.so be root
|
||||
:
|
||||
main.cpp
|
||||
misc.cpp
|
||||
ConsumerNode.cpp
|
||||
ProducerNode.cpp
|
||||
|
||||
: be media
|
||||
;
|
||||
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
#include <TimeSource.h>
|
||||
#include <BufferGroup.h>
|
||||
#include <Buffer.h>
|
||||
#include "ProducerNode.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <Buffer.h>
|
||||
#include <BufferGroup.h>
|
||||
#include <TimeSource.h>
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
ProducerNode::ProducerNode() :
|
||||
|
||||
#define DELAY 2000000
|
||||
|
||||
|
||||
ProducerNode::ProducerNode()
|
||||
:
|
||||
BBufferProducer(B_MEDIA_RAW_AUDIO),
|
||||
BMediaEventLooper(),
|
||||
BMediaNode("ProducerNode"),
|
||||
@@ -17,28 +26,28 @@ ProducerNode::ProducerNode() :
|
||||
mBufferGroup = new BBufferGroup(4096,3);
|
||||
}
|
||||
|
||||
|
||||
ProducerNode::~ProducerNode()
|
||||
{
|
||||
{
|
||||
out("ProducerNode::~ProducerNode\n");
|
||||
Quit();
|
||||
delete mBufferGroup;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ProducerNode::NodeRegistered()
|
||||
{
|
||||
out("ProducerNode::NodeRegistered\n");
|
||||
InitializeOutput();
|
||||
SetPriority(108);
|
||||
Run();
|
||||
SetPriority(108);
|
||||
Run();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ProducerNode::FormatSuggestionRequested(
|
||||
media_type type,
|
||||
int32 quality,
|
||||
media_format * format)
|
||||
status_t
|
||||
ProducerNode::FormatSuggestionRequested(media_type type, int32 quality,
|
||||
media_format* format)
|
||||
{
|
||||
out("ProducerNode::FormatSuggestionRequested\n");
|
||||
|
||||
@@ -54,10 +63,9 @@ ProducerNode::FormatSuggestionRequested(
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
status_t
|
||||
ProducerNode::FormatProposal(
|
||||
const media_source & output,
|
||||
media_format * format)
|
||||
|
||||
status_t
|
||||
ProducerNode::FormatProposal(const media_source& output, media_format* format)
|
||||
{
|
||||
out("ProducerNode::FormatProposal\n");
|
||||
|
||||
@@ -66,62 +74,58 @@ ProducerNode::FormatProposal(
|
||||
|
||||
if (output != mOutput.source)
|
||||
return B_MEDIA_BAD_SOURCE;
|
||||
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
status_t
|
||||
ProducerNode::FormatChangeRequested(
|
||||
const media_source & source,
|
||||
const media_destination & destination,
|
||||
media_format * io_format,
|
||||
int32 * _deprecated_)
|
||||
|
||||
status_t
|
||||
ProducerNode::FormatChangeRequested(const media_source& source,
|
||||
const media_destination& destination, media_format* _format,
|
||||
int32* _deprecated_)
|
||||
{
|
||||
out("ProducerNode::FormatChangeRequested\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t
|
||||
ProducerNode::GetNextOutput( /* cookie starts as 0 */
|
||||
int32 * cookie,
|
||||
media_output * out_output)
|
||||
|
||||
status_t
|
||||
ProducerNode::GetNextOutput(int32* cookie, media_output* _output)
|
||||
{
|
||||
out("ProducerNode::GetNextOutput\n");
|
||||
if (++(*cookie) > 1)
|
||||
return B_BAD_INDEX;
|
||||
|
||||
|
||||
mOutput.node = Node();
|
||||
*out_output = mOutput;
|
||||
*_output = mOutput;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
status_t
|
||||
ProducerNode::DisposeOutputCookie(
|
||||
int32 cookie)
|
||||
|
||||
status_t
|
||||
ProducerNode::DisposeOutputCookie(int32 cookie)
|
||||
{
|
||||
out("ProducerNode::DisposeOutputCookie\n");
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
/*********************************************************
|
||||
* In this function, you should either pass on the group to your upstream guy,
|
||||
* or delete your current group and hang on to this group. Deleting the previous
|
||||
* group (unless you passed it on with the reclaim flag set to false) is very
|
||||
* important, else you will 1) leak memory and 2) block someone who may want
|
||||
* to reclaim the buffers living in that group.
|
||||
|
||||
/*! In this function, you should either pass on the group to your upstream guy,
|
||||
or delete your current group and hang on to this group. Deleting the
|
||||
previous group (unless you passed it on with the reclaim flag set to false)
|
||||
is very important, else you will 1) leak memory and 2) block someone who may
|
||||
want to reclaim the buffers living in that group.
|
||||
*/
|
||||
status_t
|
||||
ProducerNode::SetBufferGroup(
|
||||
const media_source & for_source,
|
||||
BBufferGroup * group)
|
||||
status_t
|
||||
ProducerNode::SetBufferGroup(const media_source& forSource, BBufferGroup* group)
|
||||
{
|
||||
out("ProducerNode::SetBufferGroup\n");
|
||||
|
||||
if (for_source != mOutput.source)
|
||||
|
||||
if (forSource != mOutput.source)
|
||||
return B_MEDIA_BAD_SOURCE;
|
||||
|
||||
#if 0
|
||||
if (mBufferGroup != NULL && mBufferGroup != mOwnBufferGroup) {
|
||||
if (mBufferGroup != NULL && mBufferGroup != mOwnBufferGroup) {
|
||||
// fixme! really delete if it isn't ours ?
|
||||
trace("deleting buffer group!...\n");
|
||||
delete mBufferGroup;
|
||||
@@ -138,62 +142,58 @@ ProducerNode::SetBufferGroup(
|
||||
/* allocate new buffer group if necessary */
|
||||
if (mBufferGroup == NULL) {
|
||||
create_own_buffer_group();
|
||||
mBufferGroup = mOwnBufferGroup;
|
||||
mBufferGroup = mOwnBufferGroup;
|
||||
}
|
||||
return B_OK;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t
|
||||
ProducerNode::VideoClippingChanged(
|
||||
const media_source & for_source,
|
||||
int16 num_shorts,
|
||||
int16 * clip_data,
|
||||
const media_video_display_info & display,
|
||||
int32 * _deprecated_)
|
||||
|
||||
status_t
|
||||
ProducerNode::VideoClippingChanged(const media_source& forSource,
|
||||
int16 numShorts, int16* clipData, const media_video_display_info& display,
|
||||
int32* _deprecated_)
|
||||
{
|
||||
out("ProducerNode::VideoClippingChanged\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t
|
||||
ProducerNode::GetLatency(
|
||||
bigtime_t * out_lantency)
|
||||
|
||||
|
||||
status_t
|
||||
ProducerNode::GetLatency(bigtime_t* _latency)
|
||||
{
|
||||
out("ProducerNode::GetLatency\n");
|
||||
*out_lantency = 23000;
|
||||
*_latency = 23000;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
status_t
|
||||
ProducerNode::PrepareToConnect(
|
||||
const media_source & what,
|
||||
const media_destination & where,
|
||||
media_format * format,
|
||||
media_source * out_source,
|
||||
char * out_name)
|
||||
|
||||
status_t
|
||||
ProducerNode::PrepareToConnect(const media_source& what,
|
||||
const media_destination& where, media_format* format, media_source* _source,
|
||||
char* _name)
|
||||
{
|
||||
out("ProducerNode::PrepareToConnect\n");
|
||||
|
||||
if (mOutput.source != what)
|
||||
return B_MEDIA_BAD_SOURCE;
|
||||
|
||||
|
||||
if (mOutput.destination != media_destination::null)
|
||||
return B_MEDIA_ALREADY_CONNECTED;
|
||||
|
||||
if (format == NULL || out_source == NULL || out_name == NULL)
|
||||
if (format == NULL || _source == NULL || _name == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
#if 0
|
||||
#if 0
|
||||
ASSERT(mOutputEnabled == false);
|
||||
|
||||
trace("old format:\n");
|
||||
dump_format(format);
|
||||
|
||||
status_t status;
|
||||
|
||||
|
||||
status = specialize_format_to_inputformat(format);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
@@ -201,20 +201,18 @@ ProducerNode::PrepareToConnect(
|
||||
#endif
|
||||
|
||||
|
||||
*out_source = mOutput.source;
|
||||
strcpy(out_name,mOutput.name);
|
||||
*_source = mOutput.source;
|
||||
strcpy(_name, mOutput.name);
|
||||
//mOutput.destination = where; //really now? fixme
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ProducerNode::Connect(
|
||||
status_t error,
|
||||
const media_source & source,
|
||||
const media_destination & destination,
|
||||
const media_format & format,
|
||||
char * io_name)
|
||||
ProducerNode::Connect(status_t error, const media_source& source,
|
||||
const media_destination& destination, const media_format& format,
|
||||
char* name)
|
||||
{
|
||||
out("ProducerNode::Connect\n");
|
||||
|
||||
@@ -227,15 +225,15 @@ ProducerNode::Connect(
|
||||
trace("error mOutput.destination != destination\n");
|
||||
return;
|
||||
}
|
||||
*/
|
||||
*/
|
||||
mOutput.destination = destination;
|
||||
|
||||
if (mOutput.source != source) {
|
||||
out("error mOutput.source != source\n");
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(io_name,mOutput.name);
|
||||
}
|
||||
|
||||
strcpy(name, mOutput.name);
|
||||
|
||||
#if 0
|
||||
trace("format (final and approved):\n");
|
||||
@@ -247,10 +245,10 @@ ProducerNode::Connect(
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ProducerNode::Disconnect(
|
||||
const media_source & what,
|
||||
const media_destination & where)
|
||||
ProducerNode::Disconnect(const media_source& what,
|
||||
const media_destination& where)
|
||||
{
|
||||
out("ProducerNode::Disconnect\n");
|
||||
mOutputEnabled = false;
|
||||
@@ -259,68 +257,63 @@ ProducerNode::Disconnect(
|
||||
InitializeOutput();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ProducerNode::LateNoticeReceived(
|
||||
const media_source & what,
|
||||
bigtime_t how_much,
|
||||
bigtime_t performance_time)
|
||||
ProducerNode::LateNoticeReceived(const media_source& what, bigtime_t howMuch,
|
||||
bigtime_t performanceTime)
|
||||
{
|
||||
out("ProducerNode::LateNoticeReceived\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ProducerNode::EnableOutput(
|
||||
const media_source & what,
|
||||
bool enabled,
|
||||
int32 * _deprecated_)
|
||||
ProducerNode::EnableOutput(const media_source& what, bool enabled,
|
||||
int32* _deprecated_)
|
||||
{
|
||||
out("ProducerNode::EnableOutput\n");
|
||||
mOutputEnabled = enabled;
|
||||
return;
|
||||
}
|
||||
|
||||
BMediaAddOn*
|
||||
ProducerNode::AddOn(int32 * internal_id) const
|
||||
|
||||
BMediaAddOn*
|
||||
ProducerNode::AddOn(int32* internalID) const
|
||||
{
|
||||
out("ProducerNode::AddOn\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
ProducerNode::HandleEvent(const media_timed_event *event,
|
||||
bigtime_t lateness,
|
||||
bool realTimeEvent)
|
||||
|
||||
void
|
||||
ProducerNode::HandleEvent(const media_timed_event* event, bigtime_t lateness,
|
||||
bool realTimeEvent)
|
||||
{
|
||||
out("ProducerNode::HandleEvent\n");
|
||||
switch (event->type)
|
||||
{
|
||||
case BTimedEventQueue::B_HANDLE_BUFFER:
|
||||
{
|
||||
switch (event->type) {
|
||||
case BTimedEventQueue::B_HANDLE_BUFFER:
|
||||
out("B_HANDLE_BUFFER (should not happen)\n");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case BTimedEventQueue::B_PARAMETER:
|
||||
{
|
||||
case BTimedEventQueue::B_PARAMETER:
|
||||
out("B_PARAMETER\n");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case BTimedEventQueue::B_START:
|
||||
case BTimedEventQueue::B_START:
|
||||
{
|
||||
out("B_START\n");
|
||||
if (mBufferProducer != -1) {
|
||||
out("already running\n");
|
||||
break;
|
||||
}
|
||||
mBufferProducerSem = create_sem(0,"producer blocking sem");
|
||||
mBufferProducer = spawn_thread(_bufferproducer,"Buffer Producer",B_NORMAL_PRIORITY,this);
|
||||
mBufferProducerSem = create_sem(0, "producer blocking sem");
|
||||
mBufferProducer = spawn_thread(_bufferproducer, "Buffer Producer",
|
||||
B_NORMAL_PRIORITY, this);
|
||||
resume_thread(mBufferProducer);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case BTimedEventQueue::B_STOP:
|
||||
case BTimedEventQueue::B_STOP:
|
||||
{
|
||||
out("B_STOP\n");
|
||||
if (mBufferProducer == -1) {
|
||||
@@ -332,42 +325,38 @@ ProducerNode::HandleEvent(const media_timed_event *event,
|
||||
wait_for_thread(mBufferProducer,&err);
|
||||
mBufferProducer = -1;
|
||||
mBufferProducerSem = -1;
|
||||
}
|
||||
// stopping implies not handling any more buffers. So, we flush all pending
|
||||
// buffers out of the event queue before returning to the event loop.
|
||||
EventQueue()->FlushEvents(0, BTimedEventQueue::B_ALWAYS, true, BTimedEventQueue::B_HANDLE_BUFFER);
|
||||
break;
|
||||
|
||||
case BTimedEventQueue::B_SEEK:
|
||||
{
|
||||
// stopping implies not handling any more buffers. So, we flush
|
||||
// all pending buffers out of the event queue before returning to
|
||||
// the event loop.
|
||||
EventQueue()->FlushEvents(0, BTimedEventQueue::B_ALWAYS, true,
|
||||
BTimedEventQueue::B_HANDLE_BUFFER);
|
||||
break;
|
||||
}
|
||||
|
||||
case BTimedEventQueue::B_SEEK:
|
||||
out("B_SEEK\n");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case BTimedEventQueue::B_WARP:
|
||||
{
|
||||
case BTimedEventQueue::B_WARP:
|
||||
out("B_WARP\n");
|
||||
}
|
||||
// similarly, time warps aren't meaningful to the logger, so just record it and return
|
||||
//mLogger->Log(LOG_WARP_HANDLED, logMsg);
|
||||
break;
|
||||
// similarly, time warps aren't meaningful to the logger, so just
|
||||
// record it and return
|
||||
//mLogger->Log(LOG_WARP_HANDLED, logMsg);
|
||||
break;
|
||||
|
||||
case BTimedEventQueue::B_DATA_STATUS:
|
||||
{
|
||||
case BTimedEventQueue::B_DATA_STATUS:
|
||||
out("B_DATA_STATUS\n");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
default:
|
||||
out("default\n");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
status_t
|
||||
ProducerNode::HandleMessage(int32 message,const void *data, size_t size)
|
||||
{
|
||||
out("ProducerNode::HandleMessage %lx\n",message);
|
||||
@@ -378,28 +367,26 @@ ProducerNode::HandleMessage(int32 message,const void *data, size_t size)
|
||||
return BMediaNode::HandleMessage(message,data,size);
|
||||
}
|
||||
|
||||
void
|
||||
ProducerNode::AdditionalBufferRequested(
|
||||
const media_source & source,
|
||||
media_buffer_id prev_buffer,
|
||||
bigtime_t prev_time,
|
||||
const media_seek_tag * prev_tag)
|
||||
|
||||
void
|
||||
ProducerNode::AdditionalBufferRequested(const media_source& source,
|
||||
media_buffer_id previousBuffer, bigtime_t previousTime,
|
||||
const media_seek_tag* previousTag)
|
||||
{
|
||||
out("ProducerNode::AdditionalBufferRequested\n");
|
||||
release_sem(mBufferProducerSem);
|
||||
}
|
||||
|
||||
void
|
||||
ProducerNode::LatencyChanged(
|
||||
const media_source & source,
|
||||
const media_destination & destination,
|
||||
bigtime_t new_latency,
|
||||
uint32 flags)
|
||||
|
||||
|
||||
void
|
||||
ProducerNode::LatencyChanged(const media_source& source,
|
||||
const media_destination& destination, bigtime_t newLatency, uint32 flags)
|
||||
{
|
||||
out("ProducerNode::LatencyChanged\n");
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
void
|
||||
ProducerNode::InitializeOutput()
|
||||
{
|
||||
out("ConsumerNode::InitializeOutput()\n");
|
||||
@@ -412,18 +399,19 @@ ProducerNode::InitializeOutput()
|
||||
mOutput.format.u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT;
|
||||
mOutput.format.u.raw_audio.channel_count = 1;
|
||||
mOutput.format.u.raw_audio.frame_rate = 44100;
|
||||
mOutput.format.u.raw_audio.byte_order = (B_HOST_IS_BENDIAN) ? B_MEDIA_BIG_ENDIAN : B_MEDIA_LITTLE_ENDIAN;
|
||||
mOutput.format.u.raw_audio.byte_order = B_HOST_IS_BENDIAN
|
||||
? B_MEDIA_BIG_ENDIAN : B_MEDIA_LITTLE_ENDIAN;
|
||||
strcpy(mOutput.name, "this way out");
|
||||
}
|
||||
|
||||
int32
|
||||
ProducerNode::_bufferproducer(void *arg)
|
||||
|
||||
int32
|
||||
ProducerNode::_bufferproducer(void* arg)
|
||||
{
|
||||
((ProducerNode *)arg)->BufferProducer();
|
||||
((ProducerNode*)arg)->BufferProducer();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define DELAY 2000000
|
||||
|
||||
void
|
||||
ProducerNode::BufferProducer()
|
||||
@@ -434,7 +422,7 @@ ProducerNode::BufferProducer()
|
||||
|
||||
status_t rv;
|
||||
for (;;) {
|
||||
rv = acquire_sem_etc(mBufferProducerSem,1,B_RELATIVE_TIMEOUT,DELAY);
|
||||
rv = acquire_sem_etc(mBufferProducerSem, 1, B_RELATIVE_TIMEOUT, DELAY);
|
||||
if (rv == B_INTERRUPTED) {
|
||||
continue;
|
||||
} else if (rv == B_OK) {
|
||||
@@ -446,14 +434,15 @@ ProducerNode::BufferProducer()
|
||||
}
|
||||
if (!mOutputEnabled)
|
||||
continue;
|
||||
|
||||
|
||||
BBuffer *buffer;
|
||||
// out("ProducerNode: RequestBuffer\n");
|
||||
buffer = mBufferGroup->RequestBuffer(2048);
|
||||
if (!buffer) {
|
||||
}
|
||||
buffer->Header()->start_time = TimeSource()->Now() + DELAY / 2;
|
||||
out("ProducerNode: SendBuffer, sheduled time = %5.4f\n",buffer->Header()->start_time / 1E6);
|
||||
out("ProducerNode: SendBuffer, sheduled time = %5.4f\n",
|
||||
buffer->Header()->start_time / 1E6);
|
||||
rv = SendBuffer(buffer, mOutput.destination);
|
||||
if (rv != B_OK) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user