Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-116075

[Windows] Audio recording starts not at once

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.6
    • 6.3.2, 6.5.2, 6.6.0 Beta2
    • Multimedia
    • None
    • Windows
    • 9fcfa21aa (dev), 34e6dec02 (6.6), d2feae42c (dev), 77050605b (6.6), ff4ddd4d5 (6.5), 0caa9caea (6.5)

    Description

      Audio recording does not start immediately. There is a delay (about a second) between calling the record() function and starting to actually record the sound.

      Sample code:

      import QtQuick
      import QtQuick.Window
      import QtMultimedia
      
      Window {
          width: 640
          height: 480
          visible: true
      
          CaptureSession {
              id: captureSession
              audioInput: AudioInput {}
              recorder: MediaRecorder {
                  id: recorder
                  onRecorderStateChanged: function (state) {
                      if (state === MediaRecorder.RecordingState) {
                          console.log('Recording started')
                          console.timeEnd('Initialization cost')
                      }
                  }
                  onErrorOccurred: function (error, errorString) {
                      console.log('Error: ' + error + ' (' + errorString + ')')
                  }
              }
          }
      
          Component.onCompleted: {
              console.time('Initialization cost')
              console.log('Start recording...')
              recorder.record()
          }
      }
      

      Just run it and check console output.

      qml: Start recording...
      qml: Recording started
      Initialization cost: 1720ms
      

       

      The problem analysis:
      When recording starts, the QMediaFormat::resolveForEncoding() function is called internally, which enumerates all system codecs and supported file formats, also for video, regardless of whether video recording is actually required. This happens directly in QWindowsFormatInfo constructor.
      On my system (Win 10 with standard system codecs) enumerating video codecs takes about 900-12000ms (in a release build). Note that this not only delays the recording, but also blocks the UI thread for a while.

      Just a sample call stack when pausing execution during recorder initialization:

                                                                                                                                                              
                                                                                                                                                              
      1  NtMapViewOfSection                                                                               ntdll                                0x7ffd4bc4d514 
      2  umppc17010                                                                                                                            0x1b1b0ef7963  
      3  umppc17010                                                                                                                            0x1b1b0ef7d09  
      4  RtlIsCriticalSectionLockedByThread                                                               ntdll                                0x7ffd4bbc4d42 
      5  RtlIsCriticalSectionLockedByThread                                                               ntdll                                0x7ffd4bbc4aaa 
      6  RtlUnlockHeap                                                                                    ntdll                                0x7ffd4bc0fd93 
      7  RtlUnlockHeap                                                                                    ntdll                                0x7ffd4bc0fac0 
      8  RtlUnlockHeap                                                                                    ntdll                                0x7ffd4bc0ed5f 
      9  RtlGetFullPathName_UstrEx                                                                        ntdll                                0x7ffd4bbcfb53 
      10 RtlDosPathNameToNtPathName_U                                                                     ntdll                                0x7ffd4bbc73e4 
      11 LdrLoadDll                                                                                       ntdll                                0x7ffd4bbc6af4 
      12 LoadLibraryExW                                                                                   KERNELBASE                           0x7ffd496556b2 
      13 LoadLibraryExA                                                                                   KERNELBASE                           0x7ffd4964e6a1 
      14 OpenAdapter10_2                                                                                  igd10um64gen11                       0x7ffd3193417b 
      15 GTPin_Init                                                                                       igd10um64gen11                       0x7ffd31ad80d6 
      16 OpenAdapter10_2                                                                                  igd10um64gen11                       0x7ffd319a1673 
      17 D3DKMTWaitForVerticalBlankEvent                                                                  d3d11                                0x7ffd44d8617e 
      18 EnableFeatureLevelUpgrade                                                                        d3d11                                0x7ffd44d07f8e 
      19 D3D11CoreCreateDevice                                                                            d3d11                                0x7ffd44d3cc26 
      20 D3D11CoreCreateDevice                                                                            d3d11                                0x7ffd44d3c676 
      21 D3D11CoreCreateDevice                                                                            d3d11                                0x7ffd44d2df03 
      22 DllUnregisterServer                                                                              mfx_mft_mjpgvd_64                    0x7ffcb7b67958 
      23 DllUnregisterServer                                                                              mfx_mft_mjpgvd_64                    0x7ffcb7b677f4 
      24 DllUnregisterServer                                                                              mfx_mft_mjpgvd_64                    0x7ffcb7b662e2 
      25 DllUnregisterServer                                                                              mfx_mft_mjpgvd_64                    0x7ffcb7b66a73 
      26 DllUnregisterServer                                                                              mfx_mft_mjpgvd_64                    0x7ffcb7b6655e 
      27 DllUnregisterServer                                                                              mfx_mft_mjpgvd_64                    0x7ffcb7b98d8a 
      28 DllUnregisterServer                                                                              mfx_mft_mjpgvd_64                    0x7ffcb7b8ccbc 
      29 DllUnregisterServer                                                                              mfx_mft_mjpgvd_64                    0x7ffcb7b8eccf 
      30 CoGetTreatAsClass                                                                                combase                              0x7ffd49de5134 
      31 StringFromGUID2                                                                                  combase                              0x7ffd49d91a00 
      32 CoGetTreatAsClass                                                                                combase                              0x7ffd49de58bc 
      33 CoDisableCallCancellation                                                                        combase                              0x7ffd49e21b88 
      34 Ordinal167                                                                                       combase                              0x7ffd49e26a90 
      35 CoTaskMemRealloc                                                                                 combase                              0x7ffd49e1eff1 
      36 CoDisableCallCancellation                                                                        combase                              0x7ffd49e21dc0 
      37 StringFromGUID2                                                                                  combase                              0x7ffd49d91a00 
      38 StringFromGUID2                                                                                  combase                              0x7ffd49d8dc6f 
      39 StringFromGUID2                                                                                  combase                              0x7ffd49d91a00 
      40 CoCreateInstance                                                                                 combase                              0x7ffd49d7bd2a 
      41 CoCreateInstance                                                                                 combase                              0x7ffd49d7a7d0 
      42 CoCreateInstance                                                                                 combase                              0x7ffd49d7a52c 
      43 MFGetAttributesAsBlob                                                                            MFPlat                               0x7ffd4321da68 
      44 MFGetAttributesAsBlob                                                                            MFPlat                               0x7ffd4321d764 
      45 MFInitVideoFormat_RGB                                                                            MFPlat                               0x7ffd4322e3fc 
      46 MFEnumLocalMFTRegistrations                                                                      MFPlat                               0x7ffd4322fb78 
      47 getCodecSet<enum QMediaFormat::VideoCodec>                                                       qwindowsformatinfo.cpp          49   0x7ffcedb91b59 
      48 QWindowsFormatInfo::QWindowsFormatInfo                                                           qwindowsformatinfo.cpp          153  0x7ffcedb90cbf 
      49 QWindowsMediaIntegration::formatInfo                                                             qwindowsintegration.cpp         55   0x7ffcedbac567 
      50 formatInfo                                                                                       qmediaformat.cpp                462  0x7ffcbc847231 
      51 QMediaFormat::supportedFileFormats                                                               qmediaformat.cpp                504  0x7ffcbc846021 
      52 QMediaFormat::resolveForEncoding                                                                 qmediaformat.cpp                789  0x7ffcbc846cea 
      53 QMediaEncoderSettings::resolveFormat                                                             qplatformmediarecorder_p.h      52   0x7ffcbc80594a 
      54 QMediaRecorder::record                                                                           qmediarecorder.cpp              347  0x7ffcbc874716 
      55 QMediaRecorder::qt_static_metacall                                                               moc_qmediarecorder.cpp          331  0x7ffcbc872955 
      56 QMediaRecorder::qt_metacall                                                                      moc_qmediarecorder.cpp          525  0x7ffcbc8726ab 
      57 QMetaObject::metacall                                                                            qmetaobject.cpp                 335  0x7ffcae4bf939 
      58 QQmlObjectOrGadget::metacall                                                                     qqmlobjectorgadget.cpp          15   0x7ffcb182c9e0 
      59 QV4::CallMethod                                                                                  qv4qobjectwrapper.cpp           1542 0x7ffcb147e1eb 
      60 QV4::CallPrecise                                                                                 qv4qobjectwrapper.cpp           1834 0x7ffcb147f51c 
      61 <lambda_3e8464433ed092c25780b342b967fe3f>::operator()                                            qv4qobjectwrapper.cpp           2731 0x7ffcb1481b53 
      62 <lambda_4473c4284921ec2280ffebb7045bfe66>::operator()<<lambda_3e8464433ed092c25780b342b967fe3f>> qv4qobjectwrapper.cpp           2709 0x7ffcb148d1fc 
      63 QV4::QObjectMethod::callInternal                                                                 qv4qobjectwrapper.cpp           2731 0x7ffcb14784ae 
      64 QV4::QObjectMethod::virtualCall                                                                  qv4qobjectwrapper.cpp           2621 0x7ffcb1477ddc 
      65 QV4::FunctionObject::call                                                                        qv4functionobject_p.h           172  0x7ffcb12afbed 
      66 QV4::Moth::VME::interpret                                                                        qv4vme_moth.cpp                 902  0x7ffcb155c501 
      67 QV4::Moth::VME::exec                                                                             qv4vme_moth.cpp                 584  0x7ffcb1558b35 
      68 QV4::doCall                                                                                      qv4function.cpp                 54   0x7ffcb13d4647 
      69 QV4::Function::call                                                                              qv4function.cpp                 80   0x7ffcb13d3876 
      70 <lambda_f15eb9b3a6e26b3d0034fc979a0ed169>::operator()                                            qv4function.cpp                 31   0x7ffcb13d441d 
      71 QV4::convertAndCall<<lambda_f15eb9b3a6e26b3d0034fc979a0ed169>>                                   qv4jscall_p.h                   185  0x7ffcb13d7439 
      72 QV4::Function::call                                                                              qv4function.cpp                 27   0x7ffcb13d352e 
      73 QQmlJavaScriptExpression::evaluate                                                               qqmljavascriptexpression.cpp    270  0x7ffcb1791a3d 
      74 QQmlBoundSignalExpression::evaluate                                                              qqmlboundsignal.cpp             202  0x7ffcb160fad1 
      75 QQmlBoundSignal_callback                                                                         qqmlboundsignal.cpp             315  0x7ffcb16100d9 
      76 QQmlNotifier::emitNotify                                                                         qqmlnotifier.cpp                71   0x7ffcb180113a 
      77 QQmlData::signalEmitted                                                                          qqmlengine.cpp                  356  0x7ffcb1673328 
      78 doActivate<0>                                                                                    qobject.cpp                     3913 0x7ffcae56d3b0 
      79 QMetaObject::activate                                                                            qobject.cpp                     4078 0x7ffcae554408 
      80 QQmlComponentAttached::completed                                                                 moc_qqmlcomponentattached_p.cpp 163  0x7ffcb1639f52 
      81 QQmlObjectCreator::finalize                                                                      qqmlobjectcreator.cpp           1520 0x7ffcb1804469 
      82 QQmlComponentPrivate::complete                                                                   qqmlcomponent.cpp               1149 0x7ffcb16389db 
      83 QQmlComponentPrivate::completeCreate                                                             qqmlcomponent.cpp               1253 0x7ffcb16372db 
      84 QQmlComponent::completeCreate                                                                    qqmlcomponent.cpp               1231 0x7ffcb1633e53 
      85 QQmlComponentPrivate::createWithProperties                                                       qqmlcomponent.cpp               959  0x7ffcb16399f5 
      86 QQmlComponent::create                                                                            qqmlcomponent.cpp               908  0x7ffcb1633c35 
      87 QQmlApplicationEnginePrivate::finishLoad                                                         qqmlapplicationengine.cpp       135  0x7ffcb15effcb 
      88 QQmlApplicationEnginePrivate::ensureLoadingFinishes                                              qqmlapplicationengine.cpp       163  0x7ffcb15f026e 
      89 QQmlApplicationEnginePrivate::startLoad                                                          qqmlapplicationengine.cpp       110  0x7ffcb15efa3b 
      90 QQmlApplicationEngine::load                                                                      qqmlapplicationengine.cpp       324  0x7ffcb15ee9ae 
      91 main                                                                                             main.cpp                        16   0x7ff6eea1399b 
      92 qtEntryPoint                                                                                     qtentrypoint_win.cpp            50   0x7ff6eea22107 
      93 WinMain                                                                                          qtentrypoint_win.cpp            60   0x7ff6eea21f0e 
      94 invoke_main                                                                                      exe_common.inl                  107  0x7ff6eea1ebb2 
      95 __scrt_common_main_seh                                                                           exe_common.inl                  288  0x7ff6eea1ea9e 
      96 __scrt_common_main                                                                               exe_common.inl                  331  0x7ff6eea1e95e 
      97 WinMainCRTStartup                                                                                exe_winmain.cpp                 17   0x7ff6eea1ec4e 
      98 BaseThreadInitThunk                                                                              KERNEL32                             0x7ffd4a7a7614 
      99 RtlUserThreadStart                                                                               ntdll                                0x7ffd4bc026b1 
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              padubsky Pavel Dubsky
              studiosus Vladimir Belyavsky
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: