Clean up of debug output. Fixed volume control bug introduced yesterday.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9475 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper
2004-10-24 10:37:46 +00:00
parent a539f68be5
commit 40c2c00a34
2 changed files with 76 additions and 62 deletions
+18 -25
View File
@@ -14,16 +14,6 @@
#include "SoundPlayNode.h" #include "SoundPlayNode.h"
#include "debug.h" #include "debug.h"
#define DPRINTF 1
#if DPRINTF
#undef DPRINTF
#define DPRINTF printf
#else
#undef DPRINTF
#define DPRINTF if (1) {} else printf
#endif
#define SEND_NEW_BUFFER_EVENT (BTimedEventQueue::B_USER_EVENT + 1) #define SEND_NEW_BUFFER_EVENT (BTimedEventQueue::B_USER_EVENT + 1)
_SoundPlayNode::_SoundPlayNode(const char *name, BSoundPlayer *player) : _SoundPlayNode::_SoundPlayNode(const char *name, BSoundPlayer *player) :
@@ -179,9 +169,11 @@ _SoundPlayNode::FormatProposal(const media_source& output, media_format* format)
return B_MEDIA_BAD_FORMAT; return B_MEDIA_BAD_FORMAT;
} }
#if DEBUG >0
char buf[100]; char buf[100];
string_for_format(*format, buf, sizeof(buf)); string_for_format(*format, buf, sizeof(buf));
printf("_SoundPlayNode::FormatProposal: format %s\n", buf); TRACE("_SoundPlayNode::FormatProposal: format %s\n", buf);
#endif
return B_OK; return B_OK;
} }
@@ -292,9 +284,11 @@ _SoundPlayNode::PrepareToConnect(const media_source& what, const media_destinati
// passed back some wildcards). Finish specializing it now, and return an // passed back some wildcards). Finish specializing it now, and return an
// error if we don't support the requested format. // error if we don't support the requested format.
#if DEBUG > 0
char buf[100]; char buf[100];
string_for_format(*format, buf, sizeof(buf)); string_for_format(*format, buf, sizeof(buf));
printf("_SoundPlayNode::PrepareToConnect: input format %s\n", buf); TRACE("_SoundPlayNode::PrepareToConnect: input format %s\n", buf);
#endif
// if not raw audio, we can't support it // if not raw audio, we can't support it
if (format->type != B_MEDIA_UNKNOWN_TYPE && format->type != B_MEDIA_RAW_AUDIO) { if (format->type != B_MEDIA_UNKNOWN_TYPE && format->type != B_MEDIA_RAW_AUDIO) {
@@ -314,12 +308,8 @@ _SoundPlayNode::PrepareToConnect(const media_source& what, const media_destinati
&& *(uint32 *)&format->user_data[44] == FORMAT_USER_DATA_MAGIC_2) { && *(uint32 *)&format->user_data[44] == FORMAT_USER_DATA_MAGIC_2) {
channel_count = *(uint32 *)&format->user_data[4]; channel_count = *(uint32 *)&format->user_data[4];
frame_rate = *(float *)&format->user_data[20]; frame_rate = *(float *)&format->user_data[20];
printf("_SoundPlayNode::PrepareToConnect: found mixer info: channel_count %ld, frame_rate %.1f\n", channel_count, frame_rate); TRACE("_SoundPlayNode::PrepareToConnect: found mixer info: channel_count %ld, frame_rate %.1f\n", channel_count, frame_rate);
} }
if (channel_count <= 0)
channel_count = 2;
if (frame_rate <= 0)
frame_rate = 44100;
media_format default_format; media_format default_format;
default_format.type = B_MEDIA_RAW_AUDIO; default_format.type = B_MEDIA_RAW_AUDIO;
@@ -335,9 +325,11 @@ _SoundPlayNode::PrepareToConnect(const media_source& what, const media_destinati
format->u.raw_audio.channel_count, format->u.raw_audio.channel_count,
format->u.raw_audio.format, format->u.raw_audio.format,
format->u.raw_audio.frame_rate); format->u.raw_audio.frame_rate);
#if DEBUG > 0
string_for_format(*format, buf, sizeof(buf)); string_for_format(*format, buf, sizeof(buf));
printf("_SoundPlayNode::PrepareToConnect: output format %s\n", buf); TRACE("_SoundPlayNode::PrepareToConnect: output format %s\n", buf);
#endif
// Now reserve the connection, and return information about it // Now reserve the connection, and return information about it
mOutput.destination = where; mOutput.destination = where;
@@ -432,7 +424,7 @@ _SoundPlayNode::LateNoticeReceived(const media_source& what, bigtime_t how_much,
{ {
CALLED(); CALLED();
printf("_SoundPlayNode::LateNoticeReceived, %Ld too late at %Ld\n", how_much, performance_time); TRACE("_SoundPlayNode::LateNoticeReceived, %Ld too late at %Ld\n", how_much, performance_time);
// is this our output? // is this our output?
if (what != mOutput.source) if (what != mOutput.source)
@@ -505,7 +497,7 @@ _SoundPlayNode::LatencyChanged(const media_source& source, const media_destinati
{ {
CALLED(); CALLED();
printf("_SoundPlayNode::LatencyChanged: new_latency %Ld\n", new_latency); TRACE("_SoundPlayNode::LatencyChanged: new_latency %Ld\n", new_latency);
// something downstream changed latency, so we need to start producing // something downstream changed latency, so we need to start producing
// buffers earlier (or later) than we were previously. Make sure that the // buffers earlier (or later) than we were previously. Make sure that the
@@ -516,7 +508,7 @@ _SoundPlayNode::LatencyChanged(const media_source& source, const media_destinati
mLatency = new_latency; mLatency = new_latency;
SetEventLatency(mLatency + mInternalLatency); SetEventLatency(mLatency + mInternalLatency);
} else { } else {
printf("_SoundPlayNode::LatencyChanged: ignored\n"); TRACE("_SoundPlayNode::LatencyChanged: ignored\n");
} }
} }
@@ -690,7 +682,7 @@ _SoundPlayNode::HandleSeek(
bool realTimeEvent = false) bool realTimeEvent = false)
{ {
CALLED(); CALLED();
DPRINTF("_SoundPlayNode::HandleSeek(t=%lld,d=%li,bd=%lld)\n",event->event_time,event->data,event->bigdata); TRACE("_SoundPlayNode::HandleSeek(t=%lld, d=%li, bd=%lld)\n", event->event_time, event->data, event->bigdata);
return B_OK; return B_OK;
} }
@@ -736,12 +728,13 @@ _SoundPlayNode::AllocateBuffers()
size_t size = mOutput.format.u.raw_audio.buffer_size; size_t size = mOutput.format.u.raw_audio.buffer_size;
int32 count = int32(mLatency / BufferDuration() + 1 + 1); int32 count = int32(mLatency / BufferDuration() + 1 + 1);
DPRINTF("\tlatency = %Ld, buffer duration = %Ld, count %ld\n", mLatency, BufferDuration(), count); TRACE("_SoundPlayNode::AllocateBuffers: latency = %Ld, buffer duration = %Ld, count %ld\n", mLatency, BufferDuration(), count);
if (count < 3) if (count < 3)
count = 3; count = 3;
DPRINTF("\tcreating group of %ld buffers, size = %lu\n", count, size); TRACE("_SoundPlayNode::AllocateBuffers: creating group of %ld buffers, size = %lu\n", count, size);
mBufferGroup = new BBufferGroup(size, count); mBufferGroup = new BBufferGroup(size, count);
} }
+58 -37
View File
@@ -13,12 +13,6 @@
#include "SoundPlayNode.h" #include "SoundPlayNode.h"
#include "SoundPlayer.h" #include "SoundPlayer.h"
#define TRACE_SOUND_PLAYER
#ifdef TRACE_SOUND_PLAYER
#undef TRACE
#define TRACE printf
#endif
#define atomic_read(a) atomic_or(a, 0) #define atomic_read(a) atomic_or(a, 0)
// Flags used internally in BSoundPlayer // Flags used internally in BSoundPlayer
@@ -42,14 +36,10 @@ BSoundPlayer::BSoundPlayer(const char * name,
{ {
CALLED(); CALLED();
TRACE("BSoundPlayer::BSoundPlayer: default constructor used"); TRACE("BSoundPlayer::BSoundPlayer: default constructor used\n");
media_multi_audio_format fmt = media_multi_audio_format::wildcard; media_multi_audio_format fmt = media_multi_audio_format::wildcard;
// fmt.frame_rate = 44100.0f;
// fmt.channel_count = 2;
// fmt.format = media_raw_audio_format::B_AUDIO_FLOAT;
// fmt.byte_order = B_MEDIA_HOST_ENDIAN;
// fmt.buffer_size = 4096;
Init(NULL, &fmt, name, NULL, PlayBuffer, Notifier, cookie); Init(NULL, &fmt, name, NULL, PlayBuffer, Notifier, cookie);
} }
@@ -62,10 +52,18 @@ BSoundPlayer::BSoundPlayer(const media_raw_audio_format * format,
{ {
CALLED(); CALLED();
TRACE("BSoundPlayer::BSoundPlayer: raw audio format constructor used"); TRACE("BSoundPlayer::BSoundPlayer: raw audio format constructor used\n");
media_multi_audio_format fmt = media_multi_audio_format::wildcard; media_multi_audio_format fmt = media_multi_audio_format::wildcard;
*(media_raw_audio_format *)&fmt = *format; *(media_raw_audio_format *)&fmt = *format;
#if DEBUG > 0
char buf[100];
media_format tmp; tmp.type = B_MEDIA_RAW_AUDIO; tmp.u.raw_audio = fmt;
string_for_format(tmp, buf, sizeof(buf));
TRACE("BSoundPlayer::BSoundPlayer: format %s\n", buf);
#endif
Init(NULL, &fmt, name, NULL, PlayBuffer, Notifier, cookie); Init(NULL, &fmt, name, NULL, PlayBuffer, Notifier, cookie);
} }
@@ -80,11 +78,18 @@ BSoundPlayer::BSoundPlayer(const media_node & toNode,
{ {
CALLED(); CALLED();
TRACE("BSoundPlayer::BSoundPlayer: multi audio format constructor used"); TRACE("BSoundPlayer::BSoundPlayer: multi audio format constructor used\n");
if (toNode.kind & B_BUFFER_CONSUMER == 0) if (toNode.kind & B_BUFFER_CONSUMER == 0)
debugger("BSoundPlayer: toNode must have B_BUFFER_CONSUMER kind!\n"); debugger("BSoundPlayer: toNode must have B_BUFFER_CONSUMER kind!\n");
#if DEBUG > 0
char buf[100];
media_format tmp; tmp.type = B_MEDIA_RAW_AUDIO; tmp.u.raw_audio = *format;
string_for_format(tmp, buf, sizeof(buf));
TRACE("BSoundPlayer::BSoundPlayer: format %s\n", buf);
#endif
Init(&toNode, format, name, input, PlayBuffer, Notifier, cookie); Init(&toNode, format, name, input, PlayBuffer, Notifier, cookie);
} }
@@ -168,20 +173,33 @@ BSoundPlayer::Init( const media_node * node,
goto the_end; goto the_end;
} }
// find a free media_input
if (!input) { if (!input) {
err = roster->GetFreeInputsFor(inputNode, &_input, 1, &inputCount, B_MEDIA_RAW_AUDIO); err = roster->GetFreeInputsFor(inputNode, &_input, 1, &inputCount, B_MEDIA_RAW_AUDIO);
if (err != B_OK || inputCount < 1) { if (err != B_OK) {
TRACE("BSoundPlayer::Init: Couldn't GetFreeInputsFor\n"); TRACE("BSoundPlayer::Init: Couldn't GetFreeInputsFor\n");
goto the_end; goto the_end;
} }
if (inputCount < 1) {
TRACE("BSoundPlayer::Init: Couldn't find a free input\n");
err = B_ERROR;
goto the_end;
}
} else { } else {
_input = *input; _input = *input;
} }
// find a free media_output
err = roster->GetFreeOutputsFor(fPlayerNode->Node(), &_output, 1, &outputCount, B_MEDIA_RAW_AUDIO); err = roster->GetFreeOutputsFor(fPlayerNode->Node(), &_output, 1, &outputCount, B_MEDIA_RAW_AUDIO);
if (err != B_OK || outputCount < 1) { if (err != B_OK) {
TRACE("BSoundPlayer::Init: Couldn't GetFreeOutputsFor\n"); TRACE("BSoundPlayer::Init: Couldn't GetFreeOutputsFor\n");
goto the_end; goto the_end;
} }
if (outputCount < 1) {
TRACE("BSoundPlayer::Init: Couldn't find a free output\n");
err = B_ERROR;
goto the_end;
}
// Set an appropriate run mode for the producer // Set an appropriate run mode for the producer
err = roster->SetRunModeNode(fPlayerNode->Node(), BMediaNode::B_INCREASE_LATENCY); err = roster->SetRunModeNode(fPlayerNode->Node(), BMediaNode::B_INCREASE_LATENCY);
@@ -194,9 +212,11 @@ BSoundPlayer::Init( const media_node * node,
tryFormat.type = B_MEDIA_RAW_AUDIO; tryFormat.type = B_MEDIA_RAW_AUDIO;
tryFormat.u.raw_audio = *format; tryFormat.u.raw_audio = *format;
#if DEBUG > 0
char buf[100]; char buf[100];
string_for_format(tryFormat, buf, sizeof(buf)); string_for_format(tryFormat, buf, sizeof(buf));
TRACE("BSoundPlayer::Init: trying to connect with format %s\n", buf); TRACE("BSoundPlayer::Init: trying to connect with format %s\n", buf);
#endif
// and connect the nodes // and connect the nodes
err = roster->Connect(_output.source, _input.destination, &tryFormat, &fMediaOutput, &fMediaInput); err = roster->Connect(_output.source, _input.destination, &tryFormat, &fMediaOutput, &fMediaInput);
@@ -209,7 +229,7 @@ BSoundPlayer::Init( const media_node * node,
get_volume_slider(); get_volume_slider();
printf("BSoundPlayer node %ld has timesource %ld\n", fPlayerNode->Node().node, fPlayerNode->TimeSource()->Node().node); TRACE("BSoundPlayer node %ld has timesource %ld\n", fPlayerNode->Node().node, fPlayerNode->TimeSource()->Node().node);
the_end: the_end:
TRACE("BSoundPlayer::Init: %s\n", strerror(err)); TRACE("BSoundPlayer::Init: %s\n", strerror(err));
@@ -245,18 +265,22 @@ BSoundPlayer::~BSoundPlayer()
// we're using. We *are* supposed to do that even for global nodes like the Mixer. // we're using. We *are* supposed to do that even for global nodes like the Mixer.
err = roster->Disconnect(fMediaInput.node.node, fMediaInput.source, err = roster->Disconnect(fMediaInput.node.node, fMediaInput.source,
fMediaOutput.node.node, fMediaOutput.destination); fMediaOutput.node.node, fMediaOutput.destination);
#if DEBUG >0
if (err) { if (err) {
TRACE("BSoundPlayer::~BSoundPlayer: Error disconnecting nodes: %ld (%s)\n", err, strerror(err)); TRACE("BSoundPlayer::~BSoundPlayer: Error disconnecting nodes: %ld (%s)\n", err, strerror(err));
} }
#endif
} }
if (fFlags & F_MUST_RELEASE_MIXER) { if (fFlags & F_MUST_RELEASE_MIXER) {
// Release the mixer as it was acquired // Release the mixer as it was acquired
// through BMediaRoster::GetAudioMixer() // through BMediaRoster::GetAudioMixer()
err = roster->ReleaseNode(fMediaInput.node); err = roster->ReleaseNode(fMediaInput.node);
#if DEBUG >0
if (err) { if (err) {
TRACE("BSoundPlayer::~BSoundPlayer: Error releasing input node: %ld (%s)\n", err, strerror(err)); TRACE("BSoundPlayer::~BSoundPlayer: Error releasing input node: %ld (%s)\n", err, strerror(err));
} }
#endif
} }
cleanup: cleanup:
@@ -292,18 +316,6 @@ BSoundPlayer::Format() const
return media_raw_audio_format::wildcard; return media_raw_audio_format::wildcard;
return fPlayerNode->Format(); return fPlayerNode->Format();
#if 0
media_raw_audio_format temp = media_raw_audio_format::wildcard;
if (fPlayerNode) {
media_multi_audio_format fmt;
fmt = fPlayerNode->Format();
memcpy(&temp,&fmt,sizeof(temp));
}
return temp;
#endif
} }
@@ -373,7 +385,7 @@ BSoundPlayer::Stop(bool block,
for (maxtrys = 250; fPlayerNode->IsPlaying() && maxtrys != 0; maxtrys--) for (maxtrys = 250; fPlayerNode->IsPlaying() && maxtrys != 0; maxtrys--)
snooze(2000); snooze(2000);
DEBUG_ONLY(if (maxtrys == 0) printf("BSoundPlayer::Stop: waiting for node stop failed\n")); DEBUG_ONLY(if (maxtrys == 0) TRACE("BSoundPlayer::Stop: waiting for node stop failed\n"));
// wait until all buffers on the way to the physical output have been played // wait until all buffers on the way to the physical output have been played
snooze(Latency() + 2000); snooze(Latency() + 2000);
@@ -402,6 +414,8 @@ BSoundPlayer::Latency()
return 0; return 0;
} }
TRACE("BSoundPlayer::Latency: latency is %Ld\n", latency);
return latency; return latency;
} }
@@ -425,7 +439,6 @@ BSoundPlayer::HasData()
} }
BSoundPlayer::BufferPlayerFunc BSoundPlayer::BufferPlayerFunc
BSoundPlayer::BufferPlayer() const BSoundPlayer::BufferPlayer() const
{ {
@@ -648,12 +661,12 @@ BSoundPlayer::SetVolumeDB(float volume_dB)
return; return;
float min_dB = fVolumeSlider->MinValue(); float min_dB = fVolumeSlider->MinValue();
float max_dB = fVolumeSlider->MinValue(); float max_dB = fVolumeSlider->MaxValue();
if (volume_dB < min_dB) if (volume_dB < min_dB)
volume_dB = min_dB; volume_dB = min_dB;
if (volume_dB > max_dB) if (volume_dB > max_dB)
volume_dB = max_dB; volume_dB = max_dB;
int count = fVolumeSlider->CountChannels(); int count = fVolumeSlider->CountChannels();
float values[count]; float values[count];
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
@@ -731,11 +744,15 @@ BSoundPlayer::get_volume_slider()
ASSERT(fVolumeSlider == NULL); ASSERT(fVolumeSlider == NULL);
BMediaRoster *roster = BMediaRoster::CurrentRoster(); BMediaRoster *roster = BMediaRoster::CurrentRoster();
if (!roster) if (!roster) {
TRACE("BSoundPlayer::get_volume_slider failed to get BMediaRoster");
return; return;
}
if (!fParameterWeb && roster->GetParameterWebFor(fMediaInput.node, &fParameterWeb) < B_OK) if (!fParameterWeb && roster->GetParameterWebFor(fMediaInput.node, &fParameterWeb) < B_OK) {
TRACE("BSoundPlayer::get_volume_slider couldn't get parameter web");
return; return;
}
int count = fParameterWeb->CountParameters(); int count = fParameterWeb->CountParameters();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
@@ -749,6 +766,12 @@ BSoundPlayer::get_volume_slider()
fVolumeSlider = (BContinuousParameter *)parameter; fVolumeSlider = (BContinuousParameter *)parameter;
break; break;
} }
#if DEBUG >0
if (!fVolumeSlider) {
TRACE("BSoundPlayer::get_volume_slider couldn't find volume control");
}
#endif
} }
@@ -782,7 +805,6 @@ BSoundPlayer::PlayBuffer(void *buffer, size_t size, const media_raw_audio_format
sound_error::sound_error(const char *str) sound_error::sound_error(const char *str)
{ {
CALLED();
m_str_const = str; m_str_const = str;
} }
@@ -790,7 +812,6 @@ sound_error::sound_error(const char *str)
const char * const char *
sound_error::what() const sound_error::what() const
{ {
CALLED();
return m_str_const; return m_str_const;
} }