From 374b49aed382dfc1fc79eaa6ad4eccfb25a88957 Mon Sep 17 00:00:00 2001
From: Michael Lotz <mmlr@mlotz.ch>
Date: Sun, 26 Jul 2020 22:21:35 +0200
Subject: [PATCH] Audio debug output.
---
.../kernel/drivers/audio/hda/hda_controller.cpp | 5 ++-
.../media/media-add-ons/mixer/AudioMixer.cpp | 12 +++++--
.../media/media-add-ons/mixer/MixerCore.cpp | 17 ++++++----
.../media-add-ons/multi_audio/MultiAudioNode.cpp | 37 ++++++++++++++++++----
4 files changed, 56 insertions(+), 15 deletions(-)
diff --git a/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp b/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp
index 72c6fa9..ab8959a 100644
a
|
b
|
hda_send_verbs(hda_codec* codec, corb_t* verbs, uint32* responses, uint32 count)
|
1018 | 1018 | controller->Write16(HDAC_CORB_WRITE_POS, controller->corb_write_pos); |
1019 | 1019 | status_t status = acquire_sem_etc(codec->response_sem, queued, |
1020 | 1020 | B_RELATIVE_TIMEOUT, 50000ULL); |
1021 | | if (status != B_OK) |
| 1021 | if (status != B_OK) { |
| 1022 | dprintf("hda: ERROR: failed to acquire codec response sem: %s\n", |
| 1023 | strerror(status)); |
1022 | 1024 | return status; |
| 1025 | } |
1023 | 1026 | } |
1024 | 1027 | |
1025 | 1028 | if (responses != NULL) |
diff --git a/src/add-ons/media/media-add-ons/mixer/AudioMixer.cpp b/src/add-ons/media/media-add-ons/mixer/AudioMixer.cpp
index 5d2ebb1..2b2c5f2 100644
a
|
b
|
AudioMixer::BufferReceived(BBuffer *buffer)
|
315 | 315 | return; |
316 | 316 | } |
317 | 317 | |
318 | | //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); |
| 318 | debug_printf("buffer received at %12" B_PRIdBIGTIME ", should arrive at %12" |
| 319 | B_PRIdBIGTIME ", delta %12" B_PRIdBIGTIME "\n", TimeSource()->Now(), |
| 320 | buffer->Header()->start_time, |
| 321 | TimeSource()->Now() - buffer->Header()->start_time); |
319 | 322 | |
320 | 323 | // to receive the buffer at the right time, |
321 | 324 | // push it through the event looper |
… |
… |
AudioMixer::BufferReceived(BBuffer *buffer)
|
329 | 332 | void |
330 | 333 | AudioMixer::HandleInputBuffer(BBuffer* buffer, bigtime_t lateness) |
331 | 334 | { |
| 335 | debug_printf("AudioMixer: handle input buffer\n"); |
332 | 336 | bigtime_t variation = 0; |
333 | 337 | if (lateness > fLastLateness) |
334 | 338 | variation = lateness-fLastLateness; |
… |
… |
AudioMixer::HandleInputBuffer(BBuffer* buffer, bigtime_t lateness)
|
348 | 352 | NotifyLateProducer(source, variation, TimeSource()->Now()); |
349 | 353 | |
350 | 354 | if (RunMode() == B_DROP_DATA) { |
351 | | TRACE("AudioMixer: dropping buffer\n"); |
| 355 | debug_printf("AudioMixer: dropping buffer\n"); |
352 | 356 | return; |
353 | 357 | } |
354 | 358 | } |
… |
… |
void
|
1101 | 1105 | AudioMixer::HandleEvent(const media_timed_event *event, bigtime_t lateness, |
1102 | 1106 | bool realTimeEvent) |
1103 | 1107 | { |
| 1108 | debug_printf("AudioMixer: handle event, lateness %" B_PRIdBIGTIME "\n", |
| 1109 | lateness); |
| 1110 | |
1104 | 1111 | switch (event->type) { |
1105 | 1112 | case BTimedEventQueue::B_HANDLE_BUFFER: |
1106 | 1113 | { |
… |
… |
AudioMixer::CreateBufferGroup(BBufferGroup** buffer) const
|
1215 | 1222 | status_t |
1216 | 1223 | AudioMixer::SendBuffer(BBuffer* buffer, MixerOutput* output) |
1217 | 1224 | { |
| 1225 | debug_printf("AudioMixer: send buffer\n"); |
1218 | 1226 | return BBufferProducer::SendBuffer(buffer, output->MediaOutput().source, |
1219 | 1227 | output->MediaOutput().destination); |
1220 | 1228 | } |
diff --git a/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp b/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp
index cb832f6..6afed0f 100644
a
|
b
|
MixerCore::_MixThread()
|
500 | 500 | bigtime_t bufferRequestTimeout = buffer_duration( |
501 | 501 | fOutput->MediaOutput().format.u.raw_audio) / 2; |
502 | 502 | |
503 | | TRACE("MixerCore: starting _MixThread at %Ld with latency %Ld and " |
504 | | "downstream latency %Ld, bufferRequestTimeout %Ld\n", start, latency, |
505 | | fDownstreamLatency, bufferRequestTimeout); |
| 503 | debug_printf("MixerCore: starting _MixThread at %" B_PRIdBIGTIME |
| 504 | " with latency %" B_PRIdBIGTIME " and downstream latency %" |
| 505 | B_PRIdBIGTIME ", bufferRequestTimeout %" B_PRIdBIGTIME "\n", start, |
| 506 | fEventLatency, fDownstreamLatency, bufferRequestTimeout); |
506 | 507 | |
507 | 508 | // We must read from the input buffer at a position (pos) that is always |
508 | 509 | // a multiple of fMixBufferFrameCount. |
… |
… |
MixerCore::_MixThread()
|
511 | 512 | * fMixBufferFrameCount; |
512 | 513 | bigtime_t timeBase = duration_for_frames(fMixBufferFrameRate, frameBase); |
513 | 514 | |
514 | | TRACE("MixerCore: starting _MixThread, start %Ld, timeBase %Ld, " |
515 | | "frameBase %Ld\n", start, timeBase, frameBase); |
| 515 | debug_printf("MixerCore: starting _MixThread, start %" B_PRIdBIGTIME |
| 516 | ", timeBase %" B_PRIdBIGTIME ", frameBase %" B_PRIdBIGTIME "\n", start, |
| 517 | timeBase, frameBase); |
516 | 518 | |
517 | 519 | ASSERT(fMixBufferFrameCount > 0); |
518 | 520 | |
… |
… |
MixerCore::_MixThread()
|
534 | 536 | status_t ret = B_ERROR; |
535 | 537 | |
536 | 538 | while(fRunning == true) { |
| 539 | debug_printf("mix thread\n"); |
537 | 540 | if (fHasEvent == false) |
538 | 541 | goto schedule_next_event; |
539 | 542 | |
… |
… |
schedule_next_event:
|
735 | 738 | media_timed_event mixerEvent(PickEvent(), |
736 | 739 | MIXER_PROCESS_EVENT, 0, BTimedEventQueue::B_NO_CLEANUP); |
737 | 740 | |
| 741 | debug_printf("schedule next event: event time %" B_PRIdBIGTIME " -> %" |
| 742 | B_PRIdBIGTIME "\n", fEventTime, mixerEvent.event_time); |
738 | 743 | ret = write_port(fNode->ControlPort(), MIXER_SCHEDULE_EVENT, |
739 | 744 | &mixerEvent, sizeof(mixerEvent)); |
740 | 745 | if (ret != B_OK) |
741 | | TRACE("MixerCore::_MixThread: can't write to owner port\n"); |
| 746 | debug_printf("MixerCore::_MixThread: can't write to owner port\n"); |
742 | 747 | |
743 | 748 | fHasEvent = true; |
744 | 749 | |
diff --git a/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp b/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp
index 69d1819..1b2594f 100644
a
|
b
|
|
25 | 25 | #ifdef DEBUG |
26 | 26 | # define PRINTING |
27 | 27 | #endif |
| 28 | #define DEBUG 3 |
28 | 29 | #include "debug.h" |
29 | 30 | #include "Resampler.h" |
30 | 31 | |
… |
… |
|
35 | 36 | #define PARAMETER_ID_OUTPUT_FREQUENCY 2 |
36 | 37 | |
37 | 38 | |
| 39 | #define printf(x...) debug_printf(x) |
| 40 | #define fprintf(x, y...) debug_printf(y) |
| 41 | |
| 42 | |
38 | 43 | //This represent an hardware output |
39 | 44 | class node_input { |
40 | 45 | public: |
… |
… |
MultiAudioNode::DisposeInputCookie(int32 cookie)
|
630 | 635 | void |
631 | 636 | MultiAudioNode::BufferReceived(BBuffer* buffer) |
632 | 637 | { |
633 | | //CALLED(); |
| 638 | CALLED(); |
634 | 639 | switch (buffer->Header()->type) { |
635 | 640 | /*case B_MEDIA_PARAMETERS: |
636 | 641 | { |
… |
… |
void
|
672 | 677 | MultiAudioNode::ProducerDataStatus(const media_destination& forWhom, |
673 | 678 | int32 status, bigtime_t atPerformanceTime) |
674 | 679 | { |
| 680 | CALLED(); |
675 | 681 | node_input* channel = _FindInput(forWhom); |
676 | 682 | if (channel == NULL) { |
677 | 683 | fprintf(stderr, "invalid destination received in " |
… |
… |
void
|
1152 | 1158 | MultiAudioNode::HandleEvent(const media_timed_event* event, bigtime_t lateness, |
1153 | 1159 | bool realTimeEvent) |
1154 | 1160 | { |
| 1161 | CALLED(); |
1155 | 1162 | switch (event->type) { |
1156 | 1163 | case BTimedEventQueue::B_START: |
1157 | 1164 | _HandleStart(event, lateness, realTimeEvent); |
… |
… |
status_t
|
1187 | 1194 | MultiAudioNode::_HandleBuffer(const media_timed_event* event, |
1188 | 1195 | bigtime_t lateness, bool realTimeEvent) |
1189 | 1196 | { |
| 1197 | CALLED(); |
1190 | 1198 | BBuffer* buffer = const_cast<BBuffer*>((BBuffer*)event->pointer); |
1191 | 1199 | if (buffer == NULL) |
1192 | 1200 | return B_BAD_VALUE; |
… |
… |
status_t
|
1234 | 1242 | MultiAudioNode::_HandleDataStatus(const media_timed_event* event, |
1235 | 1243 | bigtime_t lateness, bool realTimeEvent) |
1236 | 1244 | { |
| 1245 | CALLED(); |
1237 | 1246 | PRINT(("MultiAudioNode::HandleDataStatus status:%" B_PRIi32 ", lateness:%" |
1238 | 1247 | B_PRIiBIGTIME "\n", event->data, lateness)); |
1239 | 1248 | switch (event->data) { |
… |
… |
MultiAudioNode::MakeParameterWeb()
|
1680 | 1689 | const char* |
1681 | 1690 | MultiAudioNode::_GetControlName(multi_mix_control& control) |
1682 | 1691 | { |
| 1692 | CALLED(); |
1683 | 1693 | if (control.string != S_null) |
1684 | 1694 | return kMultiControlString[control.string]; |
1685 | 1695 | |
… |
… |
void
|
1784 | 1794 | MultiAudioNode::_CreateFrequencyParameterGroup(BParameterGroup* parentGroup, |
1785 | 1795 | const char* name, int32 parameterID, uint32 rateMask) |
1786 | 1796 | { |
| 1797 | CALLED(); |
1787 | 1798 | BParameterGroup* group = parentGroup->MakeGroup(name); |
1788 | 1799 | BDiscreteParameter* frequencyParam = group->MakeDiscreteParameter( |
1789 | 1800 | parameterID, B_MEDIA_NO_TYPE, |
… |
… |
MultiAudioNode::_OutputThread()
|
1868 | 1879 | //PRINT(("MultiAudioNode::Runthread WriteZeros\n")); |
1869 | 1880 | } |
1870 | 1881 | } else { |
1871 | | //PRINT(("playback_buffer_cycle non ok input: %i\n", i)); |
| 1882 | debug_printf("playback_buffer_cycle non ok input: %" B_PRId32 |
| 1883 | "\n", i); |
1872 | 1884 | } |
1873 | 1885 | } |
1874 | 1886 | |
… |
… |
MultiAudioNode::_OutputThread()
|
1921 | 1933 | |
1922 | 1934 | output->fOldBufferInfo = bufferInfo; |
1923 | 1935 | } else { |
1924 | | //PRINT(("record_buffer_cycle non ok\n")); |
| 1936 | debug_printf("record_buffer_cycle non ok: %" B_PRId32 "\n", |
| 1937 | i); |
1925 | 1938 | } |
1926 | 1939 | } |
1927 | 1940 | } |
… |
… |
MultiAudioNode::_OutputThread()
|
1934 | 1947 | void |
1935 | 1948 | MultiAudioNode::_WriteZeros(node_input& input, uint32 bufferCycle) |
1936 | 1949 | { |
1937 | | //CALLED(); |
| 1950 | CALLED(); |
1938 | 1951 | /*int32 samples = input.fInput.format.u.raw_audio.buffer_size; |
1939 | 1952 | if(input.fInput.format.u.raw_audio.format == media_raw_audio_format::B_AUDIO_UCHAR) { |
1940 | 1953 | uint8 *sample = (uint8*)fDevice->BufferList().playback_buffers[input.fBufferCycle][input.fChannelId].base; |
… |
… |
MultiAudioNode::_FillWithZeros(node_input& input)
|
2036 | 2049 | void |
2037 | 2050 | MultiAudioNode::_FillNextBuffer(node_input& input, BBuffer* buffer) |
2038 | 2051 | { |
| 2052 | CALLED(); |
2039 | 2053 | uint32 channelCount = input.fInput.format.u.raw_audio.channel_count; |
2040 | 2054 | size_t inputSampleSize = input.fInput.format.u.raw_audio.format |
2041 | 2055 | & media_raw_audio_format::B_AUDIO_SIZE_MASK; |
… |
… |
void
|
2122 | 2136 | MultiAudioNode::_UpdateTimeSource(multi_buffer_info& info, |
2123 | 2137 | multi_buffer_info& oldInfo, node_input& input) |
2124 | 2138 | { |
2125 | | //CALLED(); |
| 2139 | CALLED(); |
2126 | 2140 | if (!fTimeSourceStarted || oldInfo.played_real_time == 0) |
2127 | 2141 | return; |
2128 | 2142 | |
2129 | 2143 | fTimeComputer.AddTimeStamp(info.played_real_time, |
2130 | 2144 | info.played_frames_count); |
| 2145 | |
| 2146 | debug_printf("publish time: performance: %" B_PRIdBIGTIME ", real: %" |
| 2147 | B_PRIdBIGTIME ", drift %f\n", fTimeComputer.PerformanceTime(), |
| 2148 | fTimeComputer.RealTime(), fTimeComputer.Drift()); |
| 2149 | |
2131 | 2150 | PublishTime(fTimeComputer.PerformanceTime(), fTimeComputer.RealTime(), |
2132 | 2151 | fTimeComputer.Drift()); |
2133 | 2152 | } |
… |
… |
MultiAudioNode::_UpdateTimeSource(multi_buffer_info& info,
|
2136 | 2155 | BBuffer* |
2137 | 2156 | MultiAudioNode::_FillNextBuffer(multi_buffer_info& info, node_output& output) |
2138 | 2157 | { |
2139 | | //CALLED(); |
| 2158 | CALLED(); |
2140 | 2159 | // get a buffer from our buffer group |
2141 | 2160 | //PRINT(("buffer size: %i, buffer duration: %i\n", fOutput.format.u.raw_audio.buffer_size, BufferDuration())); |
2142 | 2161 | //PRINT(("MBI.record_buffer_cycle: %i\n", MBI.record_buffer_cycle)); |
… |
… |
MultiAudioNode::GetConfigurationFor(BMessage* message)
|
2245 | 2264 | node_output* |
2246 | 2265 | MultiAudioNode::_FindOutput(media_source source) |
2247 | 2266 | { |
| 2267 | CALLED(); |
2248 | 2268 | node_output* channel = NULL; |
2249 | 2269 | |
2250 | 2270 | for (int32 i = 0; i < fOutputs.CountItems(); i++) { |
… |
… |
MultiAudioNode::_FindOutput(media_source source)
|
2263 | 2283 | node_input* |
2264 | 2284 | MultiAudioNode::_FindInput(media_destination dest) |
2265 | 2285 | { |
| 2286 | CALLED(); |
2266 | 2287 | node_input* channel = NULL; |
2267 | 2288 | |
2268 | 2289 | for (int32 i = 0; i < fInputs.CountItems(); i++) { |
… |
… |
MultiAudioNode::_FindInput(media_destination dest)
|
2281 | 2302 | node_input* |
2282 | 2303 | MultiAudioNode::_FindInput(int32 destinationId) |
2283 | 2304 | { |
| 2305 | CALLED(); |
2284 | 2306 | node_input* channel = NULL; |
2285 | 2307 | |
2286 | 2308 | for (int32 i = 0; i < fInputs.CountItems(); i++) { |
… |
… |
MultiAudioNode::_OutputThreadEntry(void* data)
|
2307 | 2329 | status_t |
2308 | 2330 | MultiAudioNode::_SetNodeInputFrameRate(float frameRate) |
2309 | 2331 | { |
| 2332 | CALLED(); |
2310 | 2333 | // check whether the frame rate is supported |
2311 | 2334 | uint32 multiAudioRate = MultiAudio::convert_from_sample_rate(frameRate); |
2312 | 2335 | if ((fDevice->Description().output_rates & multiAudioRate) == 0) |
… |
… |
MultiAudioNode::_SetNodeInputFrameRate(float frameRate)
|
2359 | 2382 | status_t |
2360 | 2383 | MultiAudioNode::_SetNodeOutputFrameRate(float frameRate) |
2361 | 2384 | { |
| 2385 | CALLED(); |
2362 | 2386 | // check whether the frame rate is supported |
2363 | 2387 | uint32 multiAudioRate = MultiAudio::convert_from_sample_rate(frameRate); |
2364 | 2388 | if ((fDevice->Description().input_rates & multiAudioRate) == 0) |
… |
… |
MultiAudioNode::_SetNodeOutputFrameRate(float frameRate)
|
2411 | 2435 | void |
2412 | 2436 | MultiAudioNode::_UpdateInternalLatency(const media_format& format) |
2413 | 2437 | { |
| 2438 | CALLED(); |
2414 | 2439 | // use half a buffer length latency |
2415 | 2440 | fInternalLatency = format.u.raw_audio.buffer_size * 10000 / 2 |
2416 | 2441 | / ((format.u.raw_audio.format |