Changeset 280948 in webkit


Ignore:
Timestamp:
Aug 11, 2021 5:46:39 PM (11 months ago)
Author:
Jean-Yves Avenard
Message:

Audio buffer may contain more frames than decoded.
https://bugs.webkit.org/show_bug.cgi?id=228732
rdar://problem/81447014

Reviewed by Eric Carlson.

Source/WebCore:

It is necessary to call repeatedly ExtAudioFileRead until it explicitly indicates that
it reached EOF.
Test: webaudio/decode-audio-data-wav.html.

  • platform/audio/cocoa/AudioFileReaderCocoa.cpp:

(WebCore::AudioFileReader::createBus): Ensure that all frames have been decoded and
trim length to the actual number of frames returned.
This was already done for the webm case.

LayoutTests:

  • platform/mac/TestExpectations:
  • webaudio/decode-audio-data-wav-expected.txt: Added.
  • webaudio/decode-audio-data-wav.html: Added.
  • webaudio/pinknoise.wav: Added. Generated with command

sox -b 16 -r 44100 -n pinknoise.wav synth 4 pinknoise

Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r280938 r280948  
     12021-08-11  Jean-Yves Avenard  <jya@apple.com>
     2
     3        Audio buffer may contain more frames than decoded.
     4        https://bugs.webkit.org/show_bug.cgi?id=228732
     5        rdar://problem/81447014
     6
     7        Reviewed by Eric Carlson.
     8
     9        * platform/mac/TestExpectations:
     10        * webaudio/decode-audio-data-wav-expected.txt: Added.
     11        * webaudio/decode-audio-data-wav.html: Added.
     12        * webaudio/pinknoise.wav: Added. Generated with command
     13        sox -b 16 -r 44100 -n pinknoise.wav synth 4 pinknoise
     14
    1152021-08-11  Wenson Hsieh  <wenson_hsieh@apple.com>
    216
  • trunk/LayoutTests/platform/mac/TestExpectations

    r280789 r280948  
    22672267[ Monterey ] imported/w3c/web-platform-tests/html/canvas/element/imagebitmap/createImageBitmap-serializable.html [ Timeout ]
    22682268
    2269 # rdar://80344665 ([ Monterey ] webaudio/codec-tests/mp3/128kbps-44khz.html is a constant audio failure)
    2270 [ Monterey ] webaudio/codec-tests/mp3/128kbps-44khz.html [ Failure ]
     2269[ BigSur Monterey ] webaudio/codec-tests/mp3/128kbps-44khz.html [ Pass ]
     2270[ BigSur Monterey ] webaudio/Panner/hrtf-database.html [ Pass ]
     2271[ BigSur Monterey ] webaudio/codec-tests/aac/vbr-128kbps-44khz.html [ Pass ]
    22712272
    22722273# rdar://80347712 ([ Monterey ] media/video-src-blob-replay.html is a flaky timeout)
  • trunk/Source/WebCore/ChangeLog

    r280933 r280948  
     12021-08-11  Jean-Yves Avenard  <jya@apple.com>
     2
     3        Audio buffer may contain more frames than decoded.
     4        https://bugs.webkit.org/show_bug.cgi?id=228732
     5        rdar://problem/81447014
     6
     7        Reviewed by Eric Carlson.
     8
     9        It is necessary to call repeatedly ExtAudioFileRead until it explicitly indicates that
     10        it reached EOF.
     11        Test: webaudio/decode-audio-data-wav.html.
     12
     13        * platform/audio/cocoa/AudioFileReaderCocoa.cpp:
     14        (WebCore::AudioFileReader::createBus): Ensure that all frames have been decoded and
     15        trim length to the actual number of frames returned.
     16        This was already done for the webm case.
     17
    1182021-08-11  Chris Dumez  <cdumez@apple.com>
    219
  • trunk/Source/WebCore/platform/audio/cocoa/AudioFileReaderCocoa.cpp

    r280584 r280948  
    577577        if (!decodedFrames)
    578578            return nullptr;
    579         // The actual decoded number of frames may not match the number of frames calculated
    580         // while demuxing as frames can be trimmed. It will always be lower.
    581         audioBus->setLength(*decodedFrames);
    582579        numberOfFrames = *decodedFrames;
    583580#endif
     
    587584
    588585        // Read from the file (or in-memory version)
    589         UInt32 framesToRead = numberOfFrames;
    590         if (PAL::ExtAudioFileRead(m_extAudioFileRef, &framesToRead, bufferList) != noErr)
    591             return nullptr;
    592     }
     586        size_t framesLeftToRead = numberOfFrames;
     587        size_t framesRead = 0;
     588        UInt32 framesToRead;
     589        do {
     590            framesToRead = std::min<size_t>(std::numeric_limits<UInt32>::max(), framesLeftToRead);
     591            if (PAL::ExtAudioFileRead(m_extAudioFileRef, &framesToRead, bufferList) != noErr)
     592                return nullptr;
     593            framesRead += framesToRead;
     594            RELEASE_ASSERT(framesRead <= numberOfFrames, "We read more than what we have room for");
     595            framesLeftToRead -= framesToRead;
     596            for (size_t i = 0; i < numberOfChannels; ++i) {
     597                bufferList->mBuffers[i].mDataByteSize = (numberOfFrames - framesRead) * sizeof(float);
     598                bufferList->mBuffers[i].mData = static_cast<float*>(bufferList->mBuffers[i].mData) + framesToRead;
     599            }
     600        } while (framesToRead);
     601        numberOfFrames = framesRead;
     602    }
     603
     604    // The actual decoded number of frames may not match the number of frames calculated
     605    // while demuxing as frames can be trimmed. It will always be lower.
     606    audioBus->setLength(numberOfFrames);
    593607
    594608    if (mixToMono && numberOfChannels == 2) {
Note: See TracChangeset for help on using the changeset viewer.