public interface

BufferProvider<T>

implements Observable<BufferProvider.State>

 androidx.camera.video.internal.BufferProvider<T>

Subclasses:

Encoder.ByteBufferInput

Gradle dependencies

compile group: 'androidx.camera', name: 'camera-video', version: '1.2.0-alpha01'

  • groupId: androidx.camera
  • artifactId: camera-video
  • version: 1.2.0-alpha01

Artifact androidx.camera:camera-video:1.2.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

BufferProvider provides buffers for writing data.

BufferProvider has BufferProvider.State, it could be either BufferProvider.State.ACTIVE or BufferProvider.State.INACTIVE. The state can be fetched directly through Observable.fetchData() or use Observable.addObserver(Executor, Observable.Observer) to receive state changes.

A buffer for writing data can be acquired with BufferProvider.acquireBuffer()". The buffer can only be obtained when the state is BufferProvider.State.ACTIVE. If the state is BufferProvider.State.INACTIVE, the BufferProvider.acquireBuffer() will return a failed with java.lang.IllegalStateException. If the state is transitioned from BufferProvider.State.ACTIVE to BufferProvider.State.INACTIVE, the incomplete will get java.util.concurrent.CancellationException. Buffer acquisition can be cancelled with if acquisition is not yet complete.

Summary

Methods
public <any>acquireBuffer()

Acquires a buffer.

Methods

public <any> acquireBuffer()

Acquires a buffer.

A buffer can only be obtained when the state is BufferProvider.State.ACTIVE. If the state is BufferProvider.State.INACTIVE, the BufferProvider.acquireBuffer() will return an failed with java.lang.IllegalStateException. If the state is transitioned from BufferProvider.State.ACTIVE to BufferProvider.State.INACTIVE, the incomplete will get java.util.concurrent.CancellationException. Buffer acquisition can be cancelled with if acquisition is not yet complete.

Returns:

a to represent the acquisition.

Source

/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.camera.video.internal;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.camera.core.impl.Observable;

import com.google.common.util.concurrent.ListenableFuture;

/**
 * BufferProvider provides buffers for writing data.
 *
 * <p>BufferProvider has {@link State}, it could be either {@link State#ACTIVE} or
 * {@link State#INACTIVE}. The state can be fetched directly through {@link #fetchData()} or use
 * {@link #addObserver} to receive state changes.
 *
 * <p>A buffer for writing data can be acquired with {@link #acquireBuffer()}". The buffer can
 * only be obtained when the state is {@link State#ACTIVE}. If the state is
 * {@link State#INACTIVE}, the {@link #acquireBuffer()} will return a failed
 * {@link ListenableFuture} with {@link IllegalStateException}. If the state is transitioned from
 * {@link State#ACTIVE} to {@link State#INACTIVE}, the incomplete {@link ListenableFuture} will
 * get {@link java.util.concurrent.CancellationException}. Buffer acquisition can be cancelled
 * with {@link ListenableFuture#cancel} if acquisition is not yet complete.
 *
 * @param <T> the buffer data type
 */
@RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java
public interface BufferProvider<T> extends Observable<BufferProvider.State> {

    /**
     * Acquires a buffer.
     *
     * <p>A buffer can only be obtained when the state is {@link State#ACTIVE}. If the state is
     * {@link State#INACTIVE}, the {@link #acquireBuffer()} will return an failed
     * {@link ListenableFuture} with {@link IllegalStateException}. If the state is transitioned
     * from {@link State#ACTIVE} to {@link State#INACTIVE}, the incomplete
     * {@link ListenableFuture} will get {@link java.util.concurrent.CancellationException}.
     * Buffer acquisition can be cancelled with {@link ListenableFuture#cancel} if acquisition
     * is not yet complete.
     *
     * @return a {@link ListenableFuture} to represent the acquisition.
     */
    @NonNull
    ListenableFuture<T> acquireBuffer();

    /** The state of the BufferProvider. */
    enum State {

        /** The state means it is able to acquire a buffer. */
        ACTIVE,

        /**
         * The state means it is not able to acquire buffer.
         *
         * <p>The acquisition via {@link #acquireBuffer()} will get a result with
         * {@link IllegalStateException}.
         */
        INACTIVE,
    }
}