19f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong/*
29f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * Copyright (C) 2011 The Android Open Source Project
39f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong *
49f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * Licensed under the Apache License, Version 2.0 (the "License");
59f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * you may not use this file except in compliance with the License.
69f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * You may obtain a copy of the License at
79f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong *
89f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong *      http://www.apache.org/licenses/LICENSE-2.0
99f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong *
109f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * Unless required by applicable law or agreed to in writing, software
119f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * distributed under the License is distributed on an "AS IS" BASIS,
129f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * See the License for the specific language governing permissions and
149f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * limitations under the License.
159f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong */
169f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong
179f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong#ifndef METADATA_BUFFER_TYPE_H
189f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong#define METADATA_BUFFER_TYPE_H
199f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong
209f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong#ifdef __cplusplus
219f70b92f1bca0e09fdfdeec7be053f41271478edJames Dongextern "C" {
229f70b92f1bca0e09fdfdeec7be053f41271478edJames Dongnamespace android {
239f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong#endif
249f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong
259f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong/*
269f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * MetadataBufferType defines the type of the metadata buffers that
279f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * can be passed to video encoder component for encoding, via Stagefright
289f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * media recording framework. To see how to work with the metadata buffers
299f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * in media recording framework, please consult HardwareAPI.h
309f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong *
319f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * The creator of metadata buffers and video encoder share common knowledge
329f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * on what is actually being stored in these metadata buffers, and
339f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * how the information can be used by the video encoder component
349f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * to locate the actual pixel data as the source input for video
359f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * encoder, plus whatever other information that is necessary. Stagefright
369f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * media recording framework does not need to know anything specific about the
379f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * metadata buffers, except for receving each individual metadata buffer
389f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * as the source input, making a copy of the metadata buffer, and passing the
399f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * copy via OpenMAX API to the video encoder component.
409f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong *
419f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * The creator of the metadata buffers must ensure that the first
429f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * 4 bytes in every metadata buffer indicates its buffer type,
439f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * and the rest of the metadata buffer contains the
449f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * actual metadata information. When a video encoder component receives
459f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * a metadata buffer, it uses the first 4 bytes in that buffer to find
469f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * out the type of the metadata buffer, and takes action appropriate
479f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * to that type of metadata buffers (for instance, locate the actual
489f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * pixel data input and then encoding the input data to produce a
499f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * compressed output buffer).
509f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong *
519f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * The following shows the layout of a metadata buffer,
529f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * where buffer type is a 4-byte field of MetadataBufferType,
539f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * and the payload is the metadata information.
549f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong *
559f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * --------------------------------------------------------------
569f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * |  buffer type  |          payload                           |
579f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong * --------------------------------------------------------------
589f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong *
599f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong */
609f70b92f1bca0e09fdfdeec7be053f41271478edJames Dongtypedef enum {
619f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong
629f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong    /*
639f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     * kMetadataBufferTypeCameraSource is used to indicate that
649f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     * the source of the metadata buffer is the camera component.
659f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     */
669f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong    kMetadataBufferTypeCameraSource  = 0,
679f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong
689f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong    /*
699f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     * kMetadataBufferTypeGrallocSource is used to indicate that
709f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     * the payload of the metadata buffers can be interpreted as
719f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     * a buffer_handle_t.
729f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     * So in this case,the metadata that the encoder receives
739f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     * will have a byte stream that consists of two parts:
749f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     * 1. First, there is an integer indicating that it is a GRAlloc
759f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     * source (kMetadataBufferTypeGrallocSource)
769f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     * 2. This is followed by the buffer_handle_t that is a handle to the
779f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     * GRalloc buffer. The encoder needs to interpret this GRalloc handle
789f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     * and encode the frames.
799f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     * --------------------------------------------------------------
809f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * |  kMetadataBufferTypeGrallocSource | buffer_handle_t buffer |
819f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     * --------------------------------------------------------------
829f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     *
839f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * See the VideoGrallocMetadata structure.
849f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong     */
859f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong    kMetadataBufferTypeGrallocSource = 1,
869f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong
873454f123d0a10bd0ce0760828996aa26c80a8fd4Lajos Molnar    /*
883454f123d0a10bd0ce0760828996aa26c80a8fd4Lajos Molnar     * kMetadataBufferTypeGraphicBuffer is used to indicate that
893454f123d0a10bd0ce0760828996aa26c80a8fd4Lajos Molnar     * the payload of the metadata buffers can be interpreted as
909f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * an ANativeWindowBuffer, and that a fence is provided.
919f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     *
929f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * In this case, the metadata will have a byte stream that consists of three parts:
933454f123d0a10bd0ce0760828996aa26c80a8fd4Lajos Molnar     * 1. First, there is an integer indicating that the metadata
949f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * contains an ANativeWindowBuffer (kMetadataBufferTypeANWBuffer)
959f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * 2. This is followed by the pointer to the ANativeWindowBuffer.
969f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * Codec must not free this buffer as it does not actually own this buffer.
979f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * 3. Finally, there is an integer containing a fence file descriptor.
989f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * The codec must wait on the fence before encoding or decoding into this
999f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * buffer. When the buffer is returned, codec must replace this file descriptor
1009f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * with a new fence, that will be waited on before the buffer is replaced
1019f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * (encoder) or read (decoder).
1029f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * ---------------------------------
1039f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * |  kMetadataBufferTypeANWBuffer |
1049f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * ---------------------------------
1059f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * |  ANativeWindowBuffer *buffer  |
1069f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * ---------------------------------
1079f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * |  int fenceFd                  |
1089f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * ---------------------------------
1099f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     *
1109f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar     * See the VideoNativeMetadata structure.
1113454f123d0a10bd0ce0760828996aa26c80a8fd4Lajos Molnar     */
1129f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar    kMetadataBufferTypeANWBuffer = 2,
1139f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar
114999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan    /*
115999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * kMetadataBufferTypeNativeHandleSource is used to indicate that
116999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * the payload of the metadata buffers can be interpreted as
117999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * a native_handle_t.
118999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     *
119999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * In this case, the metadata that the encoder receives
120999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * will have a byte stream that consists of two parts:
121999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * 1. First, there is an integer indicating that the metadata contains a
122999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * native handle (kMetadataBufferTypeNativeHandleSource).
123999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * 2. This is followed by a pointer to native_handle_t. The encoder needs
124999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * to interpret this native handle and encode the frame. The encoder must
125999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * not free this native handle as it does not actually own this native
126999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * handle. The handle will be freed after the encoder releases the buffer
127999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * back to camera.
128999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * ----------------------------------------------------------------
129999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * |  kMetadataBufferTypeNativeHandleSource | native_handle_t* nh |
130999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * ----------------------------------------------------------------
131999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     *
132999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     * See the VideoNativeHandleMetadata structure.
133999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan     */
134999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan    kMetadataBufferTypeNativeHandleSource = 3,
135999083756c117b5b5bce862c296d525a2f7b94acPraveen Chavan
1369f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar    /* This value is used by framework, but is never used inside a metadata buffer  */
1379f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar    kMetadataBufferTypeInvalid = -1,
1389f590df0b73d14e0c30e970098f2369403eb2617Lajos Molnar
1393454f123d0a10bd0ce0760828996aa26c80a8fd4Lajos Molnar
1409f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong    // Add more here...
1419f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong
1429f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong} MetadataBufferType;
1439f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong
1449f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong#ifdef __cplusplus
1459f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong}  // namespace android
1469f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong}
1479f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong#endif
1489f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong
1499f70b92f1bca0e09fdfdeec7be053f41271478edJames Dong#endif  // METADATA_BUFFER_TYPE_H
150