/*
 * Copyright (C) 2016 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 android.hardware.camera.device@1.0;

interface ICameraDeviceCallback {

    /**
     * Notify the camera service of a particular event occurring
     * The meaning of each parameter is defined by the value of msgType, and
     * documented in the definition of NotifyCallbackMsg.
     *
     * @param msgType The type of the event.
     * @param ext1 The first parameter for the event, if needed.
     * @param ext2 The second parameter for the event, if needed.
     */
    notifyCallback(NotifyCallbackMsg msgType, int32_t ext1, int32_t ext2);

    /**
     * Define a memory buffer from the provided handle and size, and return a
     * unique identifier for the HAL to use to reference it with.
     *
     * @param descriptor A native handle that must have exactly one file
     *     descriptor in it; the file descriptor must be memory mappable to
     *     bufferSize * bufferCount bytes.
     * @param bufferSize The number of bytes a single buffer consists of.
     * @param bufferCount The number of contiguous buffers that the descriptor
     *     contains.
     *
     * @return memId A positive integer identifier for this memory buffer, for
     *     use with data callbacks and unregistering memory. 0 must be returned
     *     in case of error, such as if the descriptor does not contain exactly
     *     one FD.
     */
    registerMemory(handle descriptor, uint32_t bufferSize, uint32_t bufferCount)
            generates (MemoryId memId);

    /**
     * Unregister a previously registered memory buffer
     */
    unregisterMemory(MemoryId memId);

    /**
     * Send a buffer of image data to the camera service
     *
     * @param msgType The kind of image buffer data this call represents.
     * @param data A memory handle to the buffer containing the data.
     * @param bufferIndex The offset into the memory handle where the buffer
     *     starts.
     *
     */
    dataCallback(DataCallbackMsg msgType, MemoryId data, uint32_t bufferIndex,
            CameraFrameMetadata metadata);

    /**
     * Send a buffer of image data to the camera service, with a timestamp
     *
     * @param msgType The kind of image buffer data this call represents.
     * @param data A memory handle to the buffer containing the data.
     * @param bufferIndex The offset into the memory handle where the buffer
     *     starts.
     * @param timestamp The time this buffer was captured by the camera, in
     *     nanoseconds.
     *
     */
    dataCallbackTimestamp(DataCallbackMsg msgType, MemoryId data, uint32_t bufferIndex,
            int64_t timestamp);

    /**
     * Send a buffer of image data to the camera service, with a timestamp
     *
     * @param msgType The kind of image buffer data this call represents.
     * @param handle The handle of image buffer data this call represents.
     * @param data A memory handle to the buffer containing the data.
     * @param bufferIndex The offset into the memory handle where the buffer
     *     starts.
     * @param timestamp The time this buffer was captured by the camera, in
     *     nanoseconds.
     *
     */
    handleCallbackTimestamp(DataCallbackMsg msgType, handle frameData, MemoryId data,
            uint32_t bufferIndex, int64_t timestamp);

    /**
     * Send a batch of image data buffer to the camera service, with timestamps
     *
     * This callback can be used to send multiple frames to camera framework in one callback, which
     * reduce number of callbacks in performance intensive use cases, such as high speed video
     * recording. The HAL must not mix use of this method with handleCallbackTimestamp in one
     * recording session (between startRecording and stopRecording)
     *
     * @param msgType The kind of image buffer data this call represents.
     * @param batch a vector messages. Each message contains a image buffer and a timestamp. The
     *     messages must be ordered in time from lower index to higher index, so that timestamp of
     *     i-th message is always smaller than i+1-th message.
     *
     */
    handleCallbackTimestampBatch(DataCallbackMsg msgType, vec<HandleTimestampMessage> batch);

};