heifwriter/src/main/java/androidx/heifwriter/HeifEncoder.java
private void maybeCopyOneTileYUV() {
        ByteBuffer currentBuffer;
        while ((currentBuffer = getCurrentBuffer()) != null && !mCodecInputBuffers.isEmpty()) {
            int index = mCodecInputBuffers.remove(0);

            // 0-length input means EOS.
            boolean inputEOS = (mInputIndex % mNumTiles == 0) && (currentBuffer.remaining() == 0);

            if (!inputEOS) {
                Image image = mEncoder.getInputImage(index);
                int left = mGridWidth * (mInputIndex % mGridCols);
                int top = mGridHeight * (mInputIndex / mGridCols % mGridRows);
                mSrcRect.set(left, top, left + mGridWidth, top + mGridHeight);
                copyOneTileYUV(currentBuffer, image, mWidth, mHeight, mSrcRect, mDstRect);
            }

            mEncoder.queueInputBuffer(index, 0,
                    inputEOS ? 0 : mEncoder.getInputBuffer(index).capacity(),
                    computePresentationTime(mInputIndex++),
                    inputEOS ? MediaCodec.BUFFER_FLAG_END_OF_STREAM : 0);

            if (inputEOS || mInputIndex % mNumTiles == 0) {
                returnEmptyBufferAndNotify(inputEOS);
            }
        }
    }
/**
     * Routine to copy one tile if we have both input and codec buffer available.
     *
     * Must be called on the handler looper that also handles the MediaCodec callback.
     */
Routine to copy one tile if we have both input and codec buffer available.
Must be called on the handler looper that also handles the MediaCodec callback.
Routine to copy one tile if we have both input and codec buffer available . Must be called on the handler looper that also handles the MediaCodec callback .
private void maybeCopyOneTileYUV() {
        ByteBuffer currentBuffer;
        while ((currentBuffer = getCurrentBuffer()) != null && !mCodecInputBuffers.isEmpty()) {
            int index = mCodecInputBuffers.remove(0);
            boolean inputEOS = (mInputIndex % mNumTiles == 0) && (currentBuffer.remaining() == 0);
            if (!inputEOS) {
                Image image = mEncoder.getInputImage(index);
                int left = mGridWidth * (mInputIndex % mGridCols);
                int top = mGridHeight * (mInputIndex / mGridCols % mGridRows);
                mSrcRect.set(left, top, left + mGridWidth, top + mGridHeight);
                copyOneTileYUV(currentBuffer, image, mWidth, mHeight, mSrcRect, mDstRect);
            }
            mEncoder.queueInputBuffer(index, 0,
                    inputEOS ? 0 : mEncoder.getInputBuffer(index).capacity(),
                    computePresentationTime(mInputIndex++),
                    inputEOS ? MediaCodec.BUFFER_FLAG_END_OF_STREAM : 0);
            if (inputEOS || mInputIndex % mNumTiles == 0) {
                returnEmptyBufferAndNotify(inputEOS);
            }
        }
    }
private void maybeCopyOneTileYUV ( ) { ByteBuffer currentBuffer ; while ( ( currentBuffer = getCurrentBuffer ( ) ) != null && ! mCodecInputBuffers . isEmpty ( ) ) { int index = mCodecInputBuffers . remove ( 0 ) ; boolean inputEOS = ( mInputIndex % mNumTiles == 0 ) && ( currentBuffer . remaining ( ) == 0 ) ; if ( ! inputEOS ) { Image image = mEncoder . getInputImage ( index ) ; int left = mGridWidth * ( mInputIndex % mGridCols ) ; int top = mGridHeight * ( mInputIndex / mGridCols % mGridRows ) ; mSrcRect . set ( left , top , left + mGridWidth , top + mGridHeight ) ; copyOneTileYUV ( currentBuffer , image , mWidth , mHeight , mSrcRect , mDstRect ) ; } mEncoder . queueInputBuffer ( index , 0 , inputEOS ? 0 : mEncoder . getInputBuffer ( index ) . capacity ( ) , computePresentationTime ( mInputIndex ++ ) , inputEOS ? MediaCodec . BUFFER_FLAG_END_OF_STREAM : 0 ) ; if ( inputEOS || mInputIndex % mNumTiles == 0 ) { returnEmptyBufferAndNotify ( inputEOS ) ; } } }
Routine to copy one tile if we have both input and codec buffer available.
Routine to copy one tile if we have both input and codec buffer available .
// 0-length input means EOS.