Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QIODevice::bytesAvailable in non sequential mode has a bug as follows
Forum Update on Monday, May 27th 2025

QIODevice::bytesAvailable in non sequential mode has a bug as follows

Scheduled Pinned Locked Moved Unsolved General and Desktop
multimediaqt6qiodevice
1 Posts 1 Posters 255 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johnco3
    wrote on last edited by
    #1

    Re: How to minimise audio output latency?

    I found some references to a bug in this quite old post online. I was wondering if others came across this bug where the bytesAvailable is double. I tracked the bug down to virtual size() call in the QIODevice::bytesAvaiable superclass when not in sequential mode.

    /**
     * Return the number of bytes available.
     *
     * <p>Note that there may be an issue with this when the
     * IOIDevice is not sequential due to the requirement
     * that the we must call QIODevice::bytesAvailable which
     * in turn calls size().
     *
     * @return number of bytes available.
     */
    qint64
    IODeviceSink::bytesAvailable() const {
        const qint64 my_size = mAudioData.size();
        const qint64 builtin_size = QIODevice::bytesAvailable();
    
        return (my_size + builtin_size);
    }
    
    /**
     * Gets the Audio buffer Size.
     *
     * @return size of the audio buffer
     */
    qint64
    IODeviceSink::size() const
    {
        return mAudioData.size();
    }
    
    

    The QIODevice::bytesAvailable documentation indicates that

    Subclasses that reimplement this function must call the base implementation in order to include the size of the buffer of QIODevice. Example:

    The problem with calling the base class' bytesAvailable is that it in turn calls a virtual size() function if the device is opened in default (non sequential mode). Per:

    /*!
        Returns the number of bytes that are available for reading. This
        function is commonly used with sequential devices to determine the
        number of bytes to allocate in a buffer before reading.
    
        Subclasses that reimplement this function must call the base
        implementation in order to include the size of the buffer of QIODevice. Example:
    
        \snippet code/src_corelib_io_qiodevice.cpp 1
    
        \sa bytesToWrite(), readyRead(), isSequential()
    */
    qint64 QIODevice::bytesAvailable() const
    {
        Q_D(const QIODevice);
        if (!d->isSequential())
            return qMax(size() - d->pos, qint64(0)); <<<< size() is virtual and calls the subclass
        return d->buffer.size() - d->transactionPos;
    }
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved