Author: axeld Date: 2010-04-12 15:15:46 +0200 (Mon, 12 Apr 2010) New Revision: 36184 Changeset: http://dev.haiku-os.org/changeset/36184/haiku Modified: haiku/trunk/headers/os/media/BufferProducer.h haiku/trunk/headers/os/media/MediaDefs.h haiku/trunk/src/add-ons/media/media-add-ons/dvb/DVBMediaNode.cpp haiku/trunk/src/add-ons/media/media-add-ons/firewire_dv/FireWireDVNode.cpp haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.cpp haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.h haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundNode.cpp haiku/trunk/src/add-ons/media/media-add-ons/tone_producer_demo/ToneProducer.cpp haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/Producer.cpp haiku/trunk/src/add-ons/media/media-add-ons/video_producer_demo/Producer.cpp haiku/trunk/src/apps/cortex/addons/Flanger/FlangerNode.cpp haiku/trunk/src/apps/cortex/addons/common/AudioFilterNode.cpp haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp haiku/trunk/src/apps/mediaplayer/media_node_framework/video/VideoProducer.cpp haiku/trunk/src/kits/game/GameProducer.cpp haiku/trunk/src/kits/media/BufferProducer.cpp haiku/trunk/src/kits/media/SoundPlayNode.cpp Log: * A BBuffer does not know where it came from, so BBufferConsumer::BufferReceived() cannot know whom to send the "buffer is late" notification (unless we only have a single input). To solve this, the media_header now contains extra fields that can be used to create a media_source object. * Unfortunately, BBufferProducer::SendBuffer() cannot know the output either in case there is more than one. Hence, I deprecated the existing SendBuffer() call and moved it into "private" - IOW old sources using it won't compile anymore under Haiku. * I introduced a new SendBuffer() variant that also gets the media_source as argument. * Updated all sources (that are part of the image) to use the new variant. * Removed some purposely commented out code in the audio mixer. * Implemented late buffer notification, as well as late buffer handling in the audio mixer; this is a bit of work in progress, so the debug output is left in there. * Some cleanup. Modified: haiku/trunk/headers/os/media/BufferProducer.h =================================================================== --- haiku/trunk/headers/os/media/BufferProducer.h 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/headers/os/media/BufferProducer.h 2010-04-12 13:15:46 UTC (rev 36184) @@ -138,6 +138,7 @@ // NOTE: Use this function to pass on the buffer on to the BBufferConsumer. status_t SendBuffer(BBuffer* buffer, + const media_source& source, const media_destination& destination); status_t SendDataStatus(int32 status, @@ -205,6 +206,10 @@ virtual status_t _Reserved_BufferProducer_14(void*); virtual status_t _Reserved_BufferProducer_15(void*); + // deprecated calls + status_t SendBuffer(BBuffer* buffer, + const media_destination& destination); + private: friend class BBufferConsumer; friend class BMediaNode; Modified: haiku/trunk/headers/os/media/MediaDefs.h =================================================================== --- haiku/trunk/headers/os/media/MediaDefs.h 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/headers/os/media/MediaDefs.h 2010-04-12 13:15:46 UTC (rev 36184) @@ -671,7 +671,8 @@ }; type_code user_data_type; uchar user_data[64]; // user_data_type indicates what this is - uint32 _reserved_[2]; + int32 source; + port_id source_port; off_t file_pos; // where in a file this data came from size_t orig_size; // and how big it was. if unused, zero out Modified: haiku/trunk/src/add-ons/media/media-add-ons/dvb/DVBMediaNode.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/dvb/DVBMediaNode.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/add-ons/media/media-add-ons/dvb/DVBMediaNode.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -22,6 +22,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ + #include <fcntl.h> #include <malloc.h> #include <math.h> @@ -1670,7 +1671,8 @@ hdr->time_source = TimeSource()->ID(); // set time source id hdr->start_time = start_time; // set start time lock.Lock(); - if (B_OK != SendBuffer(buf, fOutputRawAudio.destination)) { + if (SendBuffer(buf, fOutputRawAudio.source, fOutputRawAudio.destination) + != B_OK) { TRACE("audio: sending buffer failed\n"); buf->Recycle(); } @@ -1866,7 +1868,8 @@ hdr->time_source = TimeSource()->ID(); // set time source id hdr->start_time = start_time; // set start time lock.Lock(); - if (B_OK != SendBuffer(buf, fOutputRawVideo.destination)) { + if (SendBuffer(buf, fOutputRawVideo.source, fOutputRawVideo.destination) + != B_OK) { TRACE("video: sending buffer failed\n"); buf->Recycle(); } Modified: haiku/trunk/src/add-ons/media/media-add-ons/firewire_dv/FireWireDVNode.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/firewire_dv/FireWireDVNode.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/add-ons/media/media-add-ons/firewire_dv/FireWireDVNode.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -8,6 +8,7 @@ * Copyright (c) 2004-2007 Marcus Overhagen <marcus@xxxxxxxxxxxx> */ + #include "FireWireDVNode.h" #include <fcntl.h> @@ -602,7 +603,8 @@ hdr->start_time = TimeSource()->PerformanceTimeFor(system_time()); fLock.Lock(); - if (B_OK != SendBuffer(buf, fOutputEncVideo.destination)) { + if (SendBuffer(buf, fOutputEncVideo.source, + fOutputEncVideo.destination) != B_OK) { TRACE("OutVideo: sending buffer failed\n"); buf->Recycle(); } Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -100,7 +100,8 @@ fBufferGroup(0), fDownstreamLatency(1), fInternalLatency(1), - fDisableStop(false) + fDisableStop(false), + fLastLateNotification(0) { BMediaNode::AddNodeKind(B_SYSTEM_MIXER); @@ -294,13 +295,6 @@ //PRINT(4, "buffer received at %12Ld, should arrive at %12Ld, delta %12Ld\n", TimeSource()->Now(), buffer->Header()->start_time, TimeSource()->Now() - buffer->Header()->start_time); - // Note: The following code is outcommented on purpose - // and is about to be modified at a later point - // HandleInputBuffer(buffer, 0); - // buffer->Recycle(); - // return; - - // to receive the buffer at the right time, // push it through the event looper media_timed_event event(buffer->Header()->start_time, @@ -311,37 +305,33 @@ void -AudioMixer::HandleInputBuffer(BBuffer *buffer, bigtime_t lateness) +AudioMixer::HandleInputBuffer(BBuffer* buffer, bigtime_t lateness) { - // Note: The following code is outcommented on purpose - // and is about to be modified at a later point - /* - if (lateness > 5000) { - printf("Received buffer with way to high lateness %Ld\n", lateness); - if (RunMode() != B_DROP_DATA) { - printf("sending notify\n"); - NotifyLateProducer(channel->fInput.source, lateness / 2, TimeSource()->Now()); - } else if (RunMode() == B_DROP_DATA) { - printf("dropping buffer\n"); - return; + if (lateness > 0) { + debug_printf("Received buffer %Ld usec late\n", lateness); + if (RunMode() == B_DROP_DATA || RunMode() == B_DECREASE_PRECISION + || RunMode() == B_INCREASE_LATENCY) { + debug_printf("sending notify\n"); + + // Build a media_source out of the header data + media_source source = media_source::null; + source.port = buffer->Header()->source_port; + source.id = buffer->Header()->source; + + NotifyLateProducer(source, lateness, TimeSource()->Now()); + + if (RunMode() == B_DROP_DATA) { + debug_printf("dropping buffer\n"); + return; + } } } - */ // printf("Received buffer with lateness %Ld\n", lateness); fCore->Lock(); fCore->BufferReceived(buffer, lateness); fCore->Unlock(); - - // Note: The following code is outcommented on purpose - // and is about to be modified at a later point - /* - if ((B_OFFLINE == RunMode()) && (B_DATA_AVAILABLE == channel->fProducerDataStatus)) - { - RequestAdditionalBuffer(channel->fInput.source, buffer); - } - */ } @@ -894,9 +884,8 @@ return; } - /* Switch our prefered format to have the same - * frame_rate and channel count as the output. - */ + // Switch our prefered format to have the same + // frame_rate and channel count as the output. fDefaultFormat.u.raw_audio.frame_rate = format.u.raw_audio.frame_rate; fDefaultFormat.u.raw_audio.channel_count = format.u.raw_audio.channel_count; @@ -953,6 +942,7 @@ UpdateParameterWeb(); } + void AudioMixer::Disconnect(const media_source &what, const media_destination &where) { @@ -991,37 +981,37 @@ void -AudioMixer::LateNoticeReceived(const media_source &what, bigtime_t how_much, - bigtime_t performance_time) +AudioMixer::LateNoticeReceived(const media_source& what, bigtime_t howMuch, + bigtime_t performanceTime) { // We've produced some late buffers... Increase Latency // is the only runmode in which we can do anything about this + // TODO: quality could be decreased, too - ERROR("AudioMixer::LateNoticeReceived, %Ld too late at %Ld\n", how_much, - performance_time); - // Note: The following code is outcommented on purpose - // and is about to be modified at a later point - /* - if (what == fOutput.source) { - if (RunMode() == B_INCREASE_LATENCY) { - fInternalLatency += how_much; + ERROR("AudioMixer::LateNoticeReceived, %Ld too late at %Ld\n", howMuch, + performanceTime); - if (fInternalLatency > 50000) - fInternalLatency = 50000; + if (what == fCore->Output()->MediaOutput().source + && RunMode() == B_INCREASE_LATENCY) { + // We need to ignore subsequent notices whose performance time + // lies before the performance time of the last notification + if (performanceTime < fLastLateNotification) + return; - printf("AudioMixer: increasing internal latency to %Ld usec\n", fInternalLatency); - SetEventLatency(fDownstreamLatency + fInternalLatency); + fInternalLatency += howMuch; + fLastLateNotification = TimeSource()->Now(); - PublishEventLatencyChange(); - } + debug_printf("AudioMixer: increasing internal latency to %Ld usec\n", fInternalLatency); + SetEventLatency(fDownstreamLatency + fInternalLatency); + + PublishEventLatencyChange(); } - */ } void -AudioMixer::EnableOutput(const media_source &what, bool enabled, - int32 *_deprecated_) +AudioMixer::EnableOutput(const media_source& what, bool enabled, + int32 */*deprecated*/) { // we only have one output if (what.id != 0 || what.port != ControlPort()) @@ -1046,12 +1036,12 @@ void -AudioMixer::SetTimeSource(BTimeSource * time_source) +AudioMixer::SetTimeSource(BTimeSource* timeSource) { TRACE("AudioMixer::SetTimeSource: timesource is now %ld\n", - time_source->ID()); + timeSource->ID()); fCore->Lock(); - fCore->SetTimingInfo(time_source, fDownstreamLatency); + fCore->SetTimingInfo(timeSource, fDownstreamLatency); fCore->Unlock(); } @@ -1156,6 +1146,14 @@ } +status_t +AudioMixer::SendBuffer(BBuffer* buffer, MixerOutput* output) +{ + return BBufferProducer::SendBuffer(buffer, output->MediaOutput().source, + output->MediaOutput().destination); +} + + float AudioMixer::dB_to_Gain(float db) { @@ -1200,7 +1198,7 @@ } -// #pragma markß - BControllable methods +// #pragma mark - BControllable methods status_t Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.h =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.h 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.h 2010-04-12 13:15:46 UTC (rev 36184) @@ -1,11 +1,11 @@ /* * Copyright 2002 David Shipman, * Copyright 2003-2007 Marcus Overhagen - * Copyright 2007 Haiku Inc. All rights reserved. + * Copyright 2007-2010 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. */ -#ifndef _AUDIOMIXER_H -#define _AUDIOMIXER_H +#ifndef AUDIO_MIXER_H +#define AUDIO_MIXER_H #include <BufferConsumer.h> @@ -17,125 +17,126 @@ class MixerCore; +class MixerOutput; class AudioMixer : public BBufferConsumer, public BBufferProducer, public BControllable, public BMediaEventLooper { public: - AudioMixer(BMediaAddOn *addOn, bool isSystemMixer); - ~AudioMixer(); + AudioMixer(BMediaAddOn* addOn, + bool isSystemMixer); + virtual ~AudioMixer(); - void DisableNodeStop(); + void DisableNodeStop(); - // AudioMixer support - void ApplySettings(); + // AudioMixer support + void ApplySettings(); - void PublishEventLatencyChange(); - void UpdateParameterWeb(); + void PublishEventLatencyChange(); + void UpdateParameterWeb(); - void HandleInputBuffer(BBuffer *buffer, bigtime_t lateness); + void HandleInputBuffer(BBuffer* buffer, + bigtime_t lateness); - BBufferGroup * CreateBufferGroup(); + BBufferGroup* CreateBufferGroup(); - float dB_to_Gain(float db); - float Gain_to_dB(float gain); + status_t SendBuffer(BBuffer* buffer, + MixerOutput* output); - // BMediaNode methods - BMediaAddOn * AddOn(int32 *internal_id) const; - void NodeRegistered(); - void Stop(bigtime_t performance_time, bool immediate); - void SetTimeSource(BTimeSource * time_source); - using BBufferProducer::SendBuffer; + float dB_to_Gain(float db); + float Gain_to_dB(float gain); + // BMediaNode methods + virtual BMediaAddOn* AddOn(int32* _internalID) const; + virtual void NodeRegistered(); + virtual void Stop(bigtime_t performanceTime, bool immediate); + virtual void SetTimeSource(BTimeSource* timeSource); + protected: - // BControllable methods - status_t GetParameterValue(int32 id, - bigtime_t *last_change, - void *value, - size_t *ioSize); + // BControllable methods + virtual status_t GetParameterValue(int32 id, + bigtime_t* _lastChange, void* _value, + size_t* _size); + virtual void SetParameterValue(int32 id, bigtime_t when, + const void* value, size_t size); - void SetParameterValue(int32 id, bigtime_t when, - const void *value, - size_t size); + // BBufferConsumer methods + virtual status_t HandleMessage(int32 message, const void* data, + size_t size); + 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); - // BBufferConsumer methods - status_t HandleMessage(int32 message, const void* data, - size_t size); - status_t AcceptFormat(const media_destination &dest, - media_format *format); - status_t GetNextInput(int32 *cookie, - media_input *out_input); - void DisposeInputCookie(int32 cookie); - void BufferReceived(BBuffer *buffer); - void ProducerDataStatus(const media_destination &for_whom, - int32 status, - bigtime_t at_performance_time); - status_t GetLatencyFor(const media_destination &for_whom, - bigtime_t *out_latency, - media_node_id *out_timesource); - status_t Connected(const media_source &producer, - const media_destination &where, - const media_format &with_format, - media_input *out_input); - void Disconnected(const media_source &producer, - const media_destination &where); - status_t FormatChanged(const media_source &producer, - const media_destination &consumer, - int32 change_tag, - const media_format &format); + // BBufferProducer methods + virtual status_t FormatSuggestionRequested(media_type type, + int32 quality, media_format* format); + virtual status_t FormatProposal(const media_source& output, + media_format* format); + virtual status_t FormatChangeRequested( + const media_source& source, + const media_destination &destination, + media_format* format, + int32* /*deprecated*/); + virtual status_t GetNextOutput(int32* cookie, + media_output* _output); + virtual status_t DisposeOutputCookie(int32 cookie); + virtual status_t SetBufferGroup(const media_source& source, + BBufferGroup* group); + virtual status_t GetLatency(bigtime_t* _latency); + virtual status_t PrepareToConnect(const media_source& what, + const media_destination& where, + media_format* format, media_source* _source, + char* _name); + virtual void Connect(status_t error, + const media_source& source, + const media_destination& destination, + const media_format& format, char *_name); + virtual void Disconnect(const media_source& what, + const media_destination& where); + virtual void LateNoticeReceived(const media_source& what, + bigtime_t howMuch, + bigtime_t performanceTime); + virtual void EnableOutput(const media_source& what, + bool enabled, int32* /*_deprecated_*/); + virtual void LatencyChanged(const media_source& source, + const media_destination& destination, + bigtime_t newLatency, uint32 flags); - // BBufferProducer methods - status_t FormatSuggestionRequested(media_type type, - int32 quality, - media_format *format); - status_t FormatProposal(const media_source &output, - media_format *format); - status_t FormatChangeRequested( - const media_source& source, - const media_destination &destination, - media_format *io_format, - int32 *_deprecated_); - status_t GetNextOutput(int32 *cookie,media_output *out_output); - status_t DisposeOutputCookie(int32 cookie); - status_t SetBufferGroup(const media_source &for_source, - BBufferGroup *group); - status_t GetLatency(bigtime_t *out_latency); - status_t PrepareToConnect(const media_source &what, - const media_destination &where, - media_format *format, - media_source *out_source, - char *out_name); - void Connect(status_t error, - const media_source &source, - const media_destination &destination, - const media_format &format, - char *io_name); - void Disconnect(const media_source &what, - const media_destination &where); - void LateNoticeReceived(const media_source &what, - bigtime_t how_much, - bigtime_t performance_time); - void EnableOutput(const media_source &what, - bool enabled, - int32 *_deprecated_); - void LatencyChanged(const media_source &source, - const media_destination &destination, - bigtime_t new_latency, uint32 flags); - // BMediaEventLooper methods - void HandleEvent(const media_timed_event *event, - bigtime_t lateness, - bool realTimeEvent = false); + virtual void HandleEvent(const media_timed_event* event, + bigtime_t lateness, + bool realTimeEvent = false); private: - BMediaAddOn *fAddOn; - MixerCore *fCore; - BParameterWeb *fWeb; // local pointer to parameterweb - BBufferGroup *fBufferGroup; - bigtime_t fDownstreamLatency; - bigtime_t fInternalLatency; - bool fDisableStop; - media_format fDefaultFormat; + BMediaAddOn* fAddOn; + MixerCore* fCore; + BParameterWeb* fWeb; + BBufferGroup* fBufferGroup; + bigtime_t fDownstreamLatency; + bigtime_t fInternalLatency; + bool fDisableStop; + media_format fDefaultFormat; + bigtime_t fLastLateNotification; }; -#endif // _AUDIOMIXER_H + +#endif // AUDIO_MIXER_H Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -1,5 +1,5 @@ /* - * Copyright 2003-2009 Haiku Inc. All rights reserved. + * Copyright 2003-2010 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -530,8 +530,7 @@ hdr->size_used = size; hdr->time_source = fTimeSource->ID(); hdr->start_time = event_time; - if (fNode->SendBuffer(buf, fOutput->MediaOutput().destination) - != B_OK) { + if (fNode->SendBuffer(buf, fOutput) != B_OK) { #if DEBUG ERROR("MixerCore: SendBuffer failed for buffer %Ld\n", buffer_num); @@ -664,8 +663,7 @@ fOutput->AdjustByteOrder(buf); // send the buffer - status_t res = fNode->SendBuffer(buf, - fOutput->MediaOutput().destination); + status_t res = fNode->SendBuffer(buf, fOutput); if (res != B_OK) { #if DEBUG ERROR("MixerCore: SendBuffer failed for buffer %Ld\n", Modified: haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -1764,7 +1764,7 @@ // enabled status_t err = B_ERROR; if (output->fOutputEnabled) { - err = SendBuffer(buffer, + err = SendBuffer(buffer, output->fOutput.source, output->fOutput.destination); } if (err) { Modified: haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundNode.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundNode.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundNode.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -5,6 +5,8 @@ * Copyright (c) 2002, 2003 Jerome Duval (jerome.duval@xxxxxxx) * Distributed under the terms of the MIT License. */ + + #include "OpenSoundNode.h" #include <Autolock.h> @@ -2356,8 +2358,10 @@ if (buffer) { // send the buffer downstream if and only if output is enabled status_t err = B_ERROR; - if (output->fOutputEnabled) - err = SendBuffer(buffer, output->fOutput.destination); + if (output->fOutputEnabled) { + err = SendBuffer(buffer, output->fOutput.source, + output->fOutput.destination); + } // TRACE("OpenSoundNode::_RunThread: I avail: %d, OE %d, %s\n", // avail, output->fOutputEnabled, strerror(err)); if (err != B_OK) { Modified: haiku/trunk/src/add-ons/media/media-add-ons/tone_producer_demo/ToneProducer.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/tone_producer_demo/ToneProducer.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/add-ons/media/media-add-ons/tone_producer_demo/ToneProducer.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -797,17 +797,18 @@ case BTimedEventQueue::B_HANDLE_BUFFER: { // make sure we're both started *and* connected before delivering a buffer - if ((RunState() == BMediaEventLooper::B_STARTED) && (mOutput.destination != media_destination::null)) - { + if (RunState() == BMediaEventLooper::B_STARTED + && mOutput.destination != media_destination::null) { // Get the next buffer of data BBuffer* buffer = FillNextBuffer(event->event_time); - if (buffer) - { + if (buffer) { // send the buffer downstream if and only if output is enabled status_t err = B_ERROR; - if (mOutputEnabled) err = SendBuffer(buffer, mOutput.destination); - if (err) - { + if (mOutputEnabled) { + err = SendBuffer(buffer, mOutput.source, + mOutput.destination); + } + if (err) { // we need to recycle the buffer ourselves if output is disabled or // if the call to SendBuffer() fails buffer->Recycle(); @@ -820,8 +821,10 @@ mFramesSent += nFrames; // The buffer is on its way; now schedule the next one to go - bigtime_t nextEvent = mStartTime + bigtime_t(double(mFramesSent) / double(mOutput.format.u.raw_audio.frame_rate) * 1000000.0); - media_timed_event nextBufferEvent(nextEvent, BTimedEventQueue::B_HANDLE_BUFFER); + bigtime_t nextEvent = mStartTime + bigtime_t(double(mFramesSent) + / double(mOutput.format.u.raw_audio.frame_rate) * 1000000.0); + media_timed_event nextBufferEvent(nextEvent, + BTimedEventQueue::B_HANDLE_BUFFER); EventQueue()->AddEvent(nextBufferEvent); } } Modified: haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/Producer.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/Producer.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/Producer.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -968,7 +968,7 @@ PRINTF(1, ("FrameGenerator: SendBuffer...\n")); /* Send the buffer on down to the consumer */ - if (SendBuffer(buffer, fOutput.destination) < B_OK) { + if (SendBuffer(buffer, fOutput.source, fOutput.destination) < B_OK) { PRINTF(-1, ("FrameGenerator: Error sending buffer\n")); /* If there is a problem sending the buffer, return it to its * buffer group. */ Modified: haiku/trunk/src/add-ons/media/media-add-ons/video_producer_demo/Producer.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/video_producer_demo/Producer.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/add-ons/media/media-add-ons/video_producer_demo/Producer.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -2,6 +2,8 @@ Copyright 1999, Be Incorporated. All Rights Reserved. This file may be used under the terms of the Be Sample Code License. */ + + #include <fcntl.h> #include <malloc.h> #include <math.h> @@ -717,7 +719,7 @@ *(p++) = ((((x+y)^0^x)+fFrame) & 0xff) * (0x01010101 & fColor); /* Send the buffer on down to the consumer */ - if (SendBuffer(buffer, fOutput.destination) < B_OK) { + if (SendBuffer(buffer, fOutput.source, fOutput.destination) < B_OK) { PRINTF(-1, ("FrameGenerator: Error sending buffer\n")); /* If there is a problem sending the buffer, return it to its * buffer group. */ Modified: haiku/trunk/src/apps/cortex/addons/Flanger/FlangerNode.cpp =================================================================== --- haiku/trunk/src/apps/cortex/addons/Flanger/FlangerNode.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/apps/cortex/addons/Flanger/FlangerNode.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -296,8 +296,8 @@ // process and retransmit buffer filterBuffer(pBuffer); - status_t err = SendBuffer(pBuffer, m_output.destination); - if(err < B_OK) { + status_t err = SendBuffer(pBuffer, m_output.source, m_output.destination); + if (err < B_OK) { PRINT(("FlangerNode::BufferReceived():\n" "\tSendBuffer() failed: %s\n", strerror(err))); pBuffer->Recycle(); @@ -309,12 +309,11 @@ // pFormat; as of R4.5 the Media Kit passes poInput->format to // the producer in BBufferProducer::Connect(). -status_t FlangerNode::Connected( - const media_source& source, - const media_destination& destination, - const media_format& format, - media_input* poInput) { - +status_t +FlangerNode::Connected(const media_source& source, + const media_destination& destination, const media_format& format, + media_input* poInput) +{ PRINT(("FlangerNode::Connected()\n" "\tto source %ld\n", source.id)); Modified: haiku/trunk/src/apps/cortex/addons/common/AudioFilterNode.cpp =================================================================== --- haiku/trunk/src/apps/cortex/addons/common/AudioFilterNode.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/apps/cortex/addons/common/AudioFilterNode.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -523,8 +523,8 @@ // process and retransmit buffer processBuffer(buffer, outBuffer); - status_t err = SendBuffer(outBuffer, m_output.destination); - if(err < B_OK) { + status_t err = SendBuffer(outBuffer, m_output.source, m_output.destination); + if (err < B_OK) { PRINT(("AudioFilterNode::BufferReceived():\n" "\tSendBuffer() failed: %s\n", strerror(err))); outBuffer->Recycle(); Modified: haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -7,6 +7,7 @@ * All Rights Reserved. Distributed under the terms of the MIT license. */ + #include "AudioProducer.h" #include <math.h> @@ -465,7 +466,7 @@ TRACE("%p->AudioProducer::Disconnect()\n", this); // Make sure that our connection is the one being disconnected - if ((where == fOutput.destination) && (what == fOutput.source)) { + if (where == fOutput.destination && what == fOutput.source) { fOutput.destination = media_destination::null; fOutput.format = fPreferredFormat; TRACE("AudioProducer: deleting buffer group...\n"); @@ -547,7 +548,7 @@ { TRACE("%p->AudioProducer::LatencyChanged(%lld)\n", this, newLatency); - if ((source == fOutput.source) && (destination == fOutput.destination)) { + if (source == fOutput.source && destination == fOutput.destination) { fLatency = newLatency; SetEventLatency(fLatency + fInternalLatency); } @@ -610,20 +611,22 @@ TRACE("AudioProducer::HandleEvent(B_STOP) done\n"); break; - case BTimedEventQueue::B_HANDLE_BUFFER: { + case BTimedEventQueue::B_HANDLE_BUFFER: + { TRACE_BUFFER("AudioProducer::HandleEvent(B_HANDLE_BUFFER)\n"); - if ((RunState() == BMediaEventLooper::B_STARTED) - && (fOutput.destination != media_destination::null)) { + if (RunState() == BMediaEventLooper::B_STARTED + && fOutput.destination != media_destination::null) { BBuffer* buffer = _FillNextBuffer(event->event_time); if (buffer) { status_t err = B_ERROR; - if (fOutputEnabled) - err = SendBuffer(buffer, fOutput.destination); + if (fOutputEnabled) { + err = SendBuffer(buffer, fOutput.source, + fOutput.destination); + } if (err) buffer->Recycle(); } - size_t sampleSize - = fOutput.format.u.raw_audio.format + size_t sampleSize = fOutput.format.u.raw_audio.format & media_raw_audio_format::B_AUDIO_SIZE_MASK; size_t nFrames = fOutput.format.u.raw_audio.buffer_size Modified: haiku/trunk/src/apps/mediaplayer/media_node_framework/video/VideoProducer.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/media_node_framework/video/VideoProducer.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/apps/mediaplayer/media_node_framework/video/VideoProducer.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -5,6 +5,8 @@ * Copyright (c) 2000-2008, Stephan Aßmus <superstippi@xxxxxx>, * All Rights Reserved. Distributed under the terms of the MIT license. */ + + #include "VideoProducer.h" #include <stdio.h> @@ -812,7 +814,8 @@ err = B_OK; } // Send the buffer on down to the consumer - if (SendBuffer(buffer, fOutput.destination) < B_OK) { + if (SendBuffer(buffer, fOutput.source, + fOutput.destination) < B_OK) { ERROR("_FrameGeneratorThread: Error " "sending buffer\n"); // If there is a problem sending the buffer, Modified: haiku/trunk/src/kits/game/GameProducer.cpp =================================================================== --- haiku/trunk/src/kits/game/GameProducer.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/kits/game/GameProducer.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -1,73 +1,53 @@ -/*****************************************************************************/ -// GameProdcure.h -// -// This produce creates audio buffer on behalf of the GameKit. -// -// Copyright (c) 2001 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// 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 THE SOFTWARE. -// -// File Name: GameProducer.cpp -// Author: Christopher ML Zumwalt May (zummy@xxxxxxxxxxxx) -// Description: A MediaKit producer node which mixes sound from the GameKit -// and sends them to the audio mixer -/*****************************************************************************/ +/* + * Copyright 2002-2010 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Christopher ML Zumwalt May (zummy@xxxxxxxxxxxx) + */ -// Standard Includes ----------------------------------------------------------- + +/*! A MediaKit producer node which mixes sound from the GameKit + and sends them to the audio mixer +*/ + + #include <string.h> #include <stdio.h> -// System Includes ------------------------------------------------------------- -#include <ByteOrder.h> -#include <BufferGroup.h> #include <Buffer.h> +#include <BufferGroup.h> +#include <ByteOrder.h> #include <List.h> -#include <TimeSource.h> #include <MediaDefs.h> +#include <TimeSource.h> -// Project Includes ------------------------------------------------------------ #include "GameSoundBuffer.h" #include "GameSoundDevice.h" #include "GSUtility.h" -// Local Includes -------------------------------------------------------------- #include "GameProducer.h" -// Local Defines --------------------------------------------------------------- -struct _gs_play -{ - gs_id sound; - bool * hook; + +struct _gs_play { + gs_id sound; + bool* hook; - _gs_play * next; - _gs_play * previous; + _gs_play* next; + _gs_play* previous; }; -GameProducer::GameProducer(GameSoundBuffer * object, - const gs_audio_format * format) - : BMediaNode("GameProducer.h"), - BBufferProducer(B_MEDIA_RAW_AUDIO), - BMediaEventLooper(), - fBufferGroup(NULL), - fLatency(0), - fInternalLatency(0), - fOutputEnabled(true) + +GameProducer::GameProducer(GameSoundBuffer* object, + const gs_audio_format* format) + : + BMediaNode("GameProducer.h"), + BBufferProducer(B_MEDIA_RAW_AUDIO), + BMediaEventLooper(), + fBufferGroup(NULL), + fLatency(0), + fInternalLatency(0), + fOutputEnabled(true) { // initialize our preferred format object fPreferredFormat.type = B_MEDIA_RAW_AUDIO; @@ -468,8 +448,10 @@ if (buffer) { // send the buffer downstream if and only if output is enabled status_t err = B_ERROR; - if (fOutputEnabled) - err = SendBuffer(buffer, fOutput.destination); + if (fOutputEnabled) { + err = SendBuffer(buffer, fOutput.source, + fOutput.destination); + } if (err) { // we need to recycle the buffer ourselves if output is disabled or // if the call to SendBuffer() fails Modified: haiku/trunk/src/kits/media/BufferProducer.cpp =================================================================== --- haiku/trunk/src/kits/media/BufferProducer.cpp 2010-04-12 13:07:21 UTC (rev 36183) +++ haiku/trunk/src/kits/media/BufferProducer.cpp 2010-04-12 13:15:46 UTC (rev 36184) @@ -1,67 +1,49 @@ /* - * Copyright (c) 2002, 2003 Marcus Overhagen <Marcus@xxxxxxxxxxxx> + * Copyright 2002-2010, Haiku. + * Distributed under the terms of the MIT License. * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files or portions - * thereof (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice - * in the binary, as well as this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * 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 - * THE SOFTWARE. - * + * Authors: + * Marcus Overhagen, <Marcus@xxxxxxxxxxxx> + * Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx */ -#include <BufferProducer.h> + +#include <Buffer.h> [... truncated: 839 lines follow ...]