Ticket #7703: 0001-Audio-debug-output.patch

File 0001-Audio-debug-output.patch, 11.9 KB (added by mmlr, 4 years ago)
  • src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp

    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)  
    10181018        controller->Write16(HDAC_CORB_WRITE_POS, controller->corb_write_pos);
    10191019        status_t status = acquire_sem_etc(codec->response_sem, queued,
    10201020            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));
    10221024            return status;
     1025        }
    10231026    }
    10241027
    10251028    if (responses != NULL)
  • src/add-ons/media/media-add-ons/mixer/AudioMixer.cpp

    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)  
    315315        return;
    316316    }
    317317
    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);
    319322
    320323    // to receive the buffer at the right time,
    321324    // push it through the event looper
    AudioMixer::BufferReceived(BBuffer *buffer)  
    329332void
    330333AudioMixer::HandleInputBuffer(BBuffer* buffer, bigtime_t lateness)
    331334{
     335    debug_printf("AudioMixer: handle input buffer\n");
    332336    bigtime_t variation = 0;
    333337    if (lateness > fLastLateness)
    334338        variation = lateness-fLastLateness;
    AudioMixer::HandleInputBuffer(BBuffer* buffer, bigtime_t lateness)  
    348352            NotifyLateProducer(source, variation, TimeSource()->Now());
    349353
    350354            if (RunMode() == B_DROP_DATA) {
    351                 TRACE("AudioMixer: dropping buffer\n");
     355                debug_printf("AudioMixer: dropping buffer\n");
    352356                return;
    353357            }
    354358        }
    void  
    11011105AudioMixer::HandleEvent(const media_timed_event *event, bigtime_t lateness,
    11021106    bool realTimeEvent)
    11031107{
     1108    debug_printf("AudioMixer: handle event, lateness %" B_PRIdBIGTIME "\n",
     1109        lateness);
     1110
    11041111    switch (event->type) {
    11051112        case BTimedEventQueue::B_HANDLE_BUFFER:
    11061113        {
    AudioMixer::CreateBufferGroup(BBufferGroup** buffer) const  
    12151222status_t
    12161223AudioMixer::SendBuffer(BBuffer* buffer, MixerOutput* output)
    12171224{
     1225    debug_printf("AudioMixer: send buffer\n");
    12181226    return BBufferProducer::SendBuffer(buffer, output->MediaOutput().source,
    12191227        output->MediaOutput().destination);
    12201228}
  • src/add-ons/media/media-add-ons/mixer/MixerCore.cpp

    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()  
    500500    bigtime_t bufferRequestTimeout = buffer_duration(
    501501        fOutput->MediaOutput().format.u.raw_audio) / 2;
    502502
    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);
    506507
    507508    // We must read from the input buffer at a position (pos) that is always
    508509    // a multiple of fMixBufferFrameCount.
    MixerCore::_MixThread()  
    511512        * fMixBufferFrameCount;
    512513    bigtime_t timeBase = duration_for_frames(fMixBufferFrameRate, frameBase);
    513514
    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);
    516518
    517519    ASSERT(fMixBufferFrameCount > 0);
    518520
    MixerCore::_MixThread()  
    534536    status_t ret = B_ERROR;
    535537
    536538    while(fRunning == true) {
     539        debug_printf("mix thread\n");
    537540        if (fHasEvent == false)
    538541            goto schedule_next_event;
    539542
    schedule_next_event:  
    735738        media_timed_event mixerEvent(PickEvent(),
    736739            MIXER_PROCESS_EVENT, 0, BTimedEventQueue::B_NO_CLEANUP);
    737740
     741        debug_printf("schedule next event: event time %" B_PRIdBIGTIME " -> %"
     742            B_PRIdBIGTIME "\n", fEventTime, mixerEvent.event_time);
    738743        ret = write_port(fNode->ControlPort(), MIXER_SCHEDULE_EVENT,
    739744            &mixerEvent, sizeof(mixerEvent));
    740745        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");
    742747
    743748        fHasEvent = true;
    744749
  • src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp

    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  
    2525#ifdef DEBUG
    2626#   define PRINTING
    2727#endif
     28#define DEBUG 3
    2829#include "debug.h"
    2930#include "Resampler.h"
    3031
     
    3536#define PARAMETER_ID_OUTPUT_FREQUENCY   2
    3637
    3738
     39#define printf(x...)        debug_printf(x)
     40#define fprintf(x, y...)    debug_printf(y)
     41
     42
    3843//This represent an hardware output
    3944class node_input {
    4045public:
    MultiAudioNode::DisposeInputCookie(int32 cookie)  
    630635void
    631636MultiAudioNode::BufferReceived(BBuffer* buffer)
    632637{
    633     //CALLED();
     638    CALLED();
    634639    switch (buffer->Header()->type) {
    635640        /*case B_MEDIA_PARAMETERS:
    636641            {
    void  
    672677MultiAudioNode::ProducerDataStatus(const media_destination& forWhom,
    673678    int32 status, bigtime_t atPerformanceTime)
    674679{
     680    CALLED();
    675681    node_input* channel = _FindInput(forWhom);
    676682    if (channel == NULL) {
    677683        fprintf(stderr, "invalid destination received in "
    void  
    11521158MultiAudioNode::HandleEvent(const media_timed_event* event, bigtime_t lateness,
    11531159    bool realTimeEvent)
    11541160{
     1161    CALLED();
    11551162    switch (event->type) {
    11561163        case BTimedEventQueue::B_START:
    11571164            _HandleStart(event, lateness, realTimeEvent);
    status_t  
    11871194MultiAudioNode::_HandleBuffer(const media_timed_event* event,
    11881195    bigtime_t lateness, bool realTimeEvent)
    11891196{
     1197    CALLED();
    11901198    BBuffer* buffer = const_cast<BBuffer*>((BBuffer*)event->pointer);
    11911199    if (buffer == NULL)
    11921200        return B_BAD_VALUE;
    status_t  
    12341242MultiAudioNode::_HandleDataStatus(const media_timed_event* event,
    12351243    bigtime_t lateness, bool realTimeEvent)
    12361244{
     1245    CALLED();
    12371246    PRINT(("MultiAudioNode::HandleDataStatus status:%" B_PRIi32 ", lateness:%"
    12381247        B_PRIiBIGTIME "\n", event->data, lateness));
    12391248    switch (event->data) {
    MultiAudioNode::MakeParameterWeb()  
    16801689const char*
    16811690MultiAudioNode::_GetControlName(multi_mix_control& control)
    16821691{
     1692    CALLED();
    16831693    if (control.string != S_null)
    16841694        return kMultiControlString[control.string];
    16851695
    void  
    17841794MultiAudioNode::_CreateFrequencyParameterGroup(BParameterGroup* parentGroup,
    17851795    const char* name, int32 parameterID, uint32 rateMask)
    17861796{
     1797    CALLED();
    17871798    BParameterGroup* group = parentGroup->MakeGroup(name);
    17881799    BDiscreteParameter* frequencyParam = group->MakeDiscreteParameter(
    17891800        parameterID, B_MEDIA_NO_TYPE,
    MultiAudioNode::_OutputThread()  
    18681879                    //PRINT(("MultiAudioNode::Runthread WriteZeros\n"));
    18691880                }
    18701881            } 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);
    18721884            }
    18731885        }
    18741886
    MultiAudioNode::_OutputThread()  
    19211933
    19221934                    output->fOldBufferInfo = bufferInfo;
    19231935                } else {
    1924                     //PRINT(("record_buffer_cycle non ok\n"));
     1936                    debug_printf("record_buffer_cycle non ok: %" B_PRId32 "\n",
     1937                        i);
    19251938                }
    19261939            }
    19271940        }
    MultiAudioNode::_OutputThread()  
    19341947void
    19351948MultiAudioNode::_WriteZeros(node_input& input, uint32 bufferCycle)
    19361949{
    1937     //CALLED();
     1950    CALLED();
    19381951    /*int32 samples = input.fInput.format.u.raw_audio.buffer_size;
    19391952    if(input.fInput.format.u.raw_audio.format == media_raw_audio_format::B_AUDIO_UCHAR) {
    19401953        uint8 *sample = (uint8*)fDevice->BufferList().playback_buffers[input.fBufferCycle][input.fChannelId].base;
    MultiAudioNode::_FillWithZeros(node_input& input)  
    20362049void
    20372050MultiAudioNode::_FillNextBuffer(node_input& input, BBuffer* buffer)
    20382051{
     2052    CALLED();
    20392053    uint32 channelCount = input.fInput.format.u.raw_audio.channel_count;
    20402054    size_t inputSampleSize = input.fInput.format.u.raw_audio.format
    20412055            & media_raw_audio_format::B_AUDIO_SIZE_MASK;
    void  
    21222136MultiAudioNode::_UpdateTimeSource(multi_buffer_info& info,
    21232137    multi_buffer_info& oldInfo, node_input& input)
    21242138{
    2125     //CALLED();
     2139    CALLED();
    21262140    if (!fTimeSourceStarted || oldInfo.played_real_time == 0)
    21272141        return;
    21282142
    21292143    fTimeComputer.AddTimeStamp(info.played_real_time,
    21302144        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
    21312150    PublishTime(fTimeComputer.PerformanceTime(), fTimeComputer.RealTime(),
    21322151        fTimeComputer.Drift());
    21332152}
    MultiAudioNode::_UpdateTimeSource(multi_buffer_info& info,  
    21362155BBuffer*
    21372156MultiAudioNode::_FillNextBuffer(multi_buffer_info& info, node_output& output)
    21382157{
    2139     //CALLED();
     2158    CALLED();
    21402159    // get a buffer from our buffer group
    21412160    //PRINT(("buffer size: %i, buffer duration: %i\n", fOutput.format.u.raw_audio.buffer_size, BufferDuration()));
    21422161    //PRINT(("MBI.record_buffer_cycle: %i\n", MBI.record_buffer_cycle));
    MultiAudioNode::GetConfigurationFor(BMessage* message)  
    22452264node_output*
    22462265MultiAudioNode::_FindOutput(media_source source)
    22472266{
     2267    CALLED();
    22482268    node_output* channel = NULL;
    22492269
    22502270    for (int32 i = 0; i < fOutputs.CountItems(); i++) {
    MultiAudioNode::_FindOutput(media_source source)  
    22632283node_input*
    22642284MultiAudioNode::_FindInput(media_destination dest)
    22652285{
     2286    CALLED();
    22662287    node_input* channel = NULL;
    22672288
    22682289    for (int32 i = 0; i < fInputs.CountItems(); i++) {
    MultiAudioNode::_FindInput(media_destination dest)  
    22812302node_input*
    22822303MultiAudioNode::_FindInput(int32 destinationId)
    22832304{
     2305    CALLED();
    22842306    node_input* channel = NULL;
    22852307
    22862308    for (int32 i = 0; i < fInputs.CountItems(); i++) {
    MultiAudioNode::_OutputThreadEntry(void* data)  
    23072329status_t
    23082330MultiAudioNode::_SetNodeInputFrameRate(float frameRate)
    23092331{
     2332    CALLED();
    23102333    // check whether the frame rate is supported
    23112334    uint32 multiAudioRate = MultiAudio::convert_from_sample_rate(frameRate);
    23122335    if ((fDevice->Description().output_rates & multiAudioRate) == 0)
    MultiAudioNode::_SetNodeInputFrameRate(float frameRate)  
    23592382status_t
    23602383MultiAudioNode::_SetNodeOutputFrameRate(float frameRate)
    23612384{
     2385    CALLED();
    23622386    // check whether the frame rate is supported
    23632387    uint32 multiAudioRate = MultiAudio::convert_from_sample_rate(frameRate);
    23642388    if ((fDevice->Description().input_rates & multiAudioRate) == 0)
    MultiAudioNode::_SetNodeOutputFrameRate(float frameRate)  
    24112435void
    24122436MultiAudioNode::_UpdateInternalLatency(const media_format& format)
    24132437{
     2438    CALLED();
    24142439    // use half a buffer length latency
    24152440    fInternalLatency = format.u.raw_audio.buffer_size * 10000 / 2
    24162441        / ((format.u.raw_audio.format