MetadataBufferType.h revision 3454f123d0a10bd0ce0760828996aa26c80a8fd4
1b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent/*
2b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * Copyright (C) 2011 The Android Open Source Project
3b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent *
4b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * Licensed under the Apache License, Version 2.0 (the "License");
5b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * you may not use this file except in compliance with the License.
6b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * You may obtain a copy of the License at
7b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent *
8b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent *      http://www.apache.org/licenses/LICENSE-2.0
9b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent *
10b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * Unless required by applicable law or agreed to in writing, software
11b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * distributed under the License is distributed on an "AS IS" BASIS,
12b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * See the License for the specific language governing permissions and
14b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * limitations under the License.
15b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent */
16b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent
17b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent#ifndef METADATA_BUFFER_TYPE_H
18b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent#define METADATA_BUFFER_TYPE_H
19b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent
20b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent#ifdef __cplusplus
21b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurentextern "C" {
22b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurentnamespace android {
23b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent#endif
24b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent
258ba53d87a2d311ff4b3f04e30b2e09309ae7421cEric Laurent/*
26936c84a5b743dce2a2572fdf54b37b187bc88b60Eric Laurent * MetadataBufferType defines the type of the metadata buffers that
27936c84a5b743dce2a2572fdf54b37b187bc88b60Eric Laurent * can be passed to video encoder component for encoding, via Stagefright
28936c84a5b743dce2a2572fdf54b37b187bc88b60Eric Laurent * media recording framework. To see how to work with the metadata buffers
29936c84a5b743dce2a2572fdf54b37b187bc88b60Eric Laurent * in media recording framework, please consult HardwareAPI.h
308ba53d87a2d311ff4b3f04e30b2e09309ae7421cEric Laurent *
318ba53d87a2d311ff4b3f04e30b2e09309ae7421cEric Laurent * The creator of metadata buffers and video encoder share common knowledge
328ba53d87a2d311ff4b3f04e30b2e09309ae7421cEric Laurent * on what is actually being stored in these metadata buffers, and
338ba53d87a2d311ff4b3f04e30b2e09309ae7421cEric Laurent * how the information can be used by the video encoder component
34936c84a5b743dce2a2572fdf54b37b187bc88b60Eric Laurent * to locate the actual pixel data as the source input for video
358ba53d87a2d311ff4b3f04e30b2e09309ae7421cEric Laurent * encoder, plus whatever other information that is necessary. Stagefright
368ba53d87a2d311ff4b3f04e30b2e09309ae7421cEric Laurent * media recording framework does not need to know anything specific about the
37b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * metadata buffers, except for receving each individual metadata buffer
38b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * as the source input, making a copy of the metadata buffer, and passing the
39b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * copy via OpenMAX API to the video encoder component.
40b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent *
41b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * The creator of the metadata buffers must ensure that the first
42b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * 4 bytes in every metadata buffer indicates its buffer type,
43b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * and the rest of the metadata buffer contains the
44b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * actual metadata information. When a video encoder component receives
45b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * a metadata buffer, it uses the first 4 bytes in that buffer to find
46b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * out the type of the metadata buffer, and takes action appropriate
47b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * to that type of metadata buffers (for instance, locate the actual
48b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * pixel data input and then encoding the input data to produce a
49b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * compressed output buffer).
50b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent *
51b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * The following shows the layout of a metadata buffer,
52b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * where buffer type is a 4-byte field of MetadataBufferType,
53b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * and the payload is the metadata information.
54b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent *
55b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * --------------------------------------------------------------
56b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * |  buffer type  |          payload                           |
57b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent * --------------------------------------------------------------
58b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent *
59b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent */
60b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurenttypedef enum {
61b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent
62b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent    /*
63b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * kMetadataBufferTypeCameraSource is used to indicate that
64b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * the source of the metadata buffer is the camera component.
65b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     */
66b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent    kMetadataBufferTypeCameraSource  = 0,
67b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent
68b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent    /*
69b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * kMetadataBufferTypeGrallocSource is used to indicate that
70b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * the payload of the metadata buffers can be interpreted as
71b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * a buffer_handle_t.
72b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * So in this case,the metadata that the encoder receives
73b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * will have a byte stream that consists of two parts:
74b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * 1. First, there is an integer indicating that it is a GRAlloc
75b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * source (kMetadataBufferTypeGrallocSource)
76b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * 2. This is followed by the buffer_handle_t that is a handle to the
77b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * GRalloc buffer. The encoder needs to interpret this GRalloc handle
78b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * and encode the frames.
79b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * --------------------------------------------------------------
80b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * |  kMetadataBufferTypeGrallocSource | sizeof(buffer_handle_t) |
81b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * --------------------------------------------------------------
82b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     */
83b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent    kMetadataBufferTypeGrallocSource = 1,
84b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent
85b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent    /*
86b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * kMetadataBufferTypeGraphicBuffer is used to indicate that
87b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * the payload of the metadata buffers can be interpreted as
88b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * a GraphicBuffer.  It is only to be used by software encoders.
89b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * In this case, the metadata that the encoder receives
90b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * will have a byte stream that consists of two parts:
91b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * 1. First, there is an integer indicating that the metadata
92b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * contains a GraphicBuffer (kMetadataBufferTypeGraphicBuffer)
93b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * 2. This is followed by the pointer to the GraphicBuffer that
94b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * is to be encoded.  Encoder must not create a sp<> from this
95b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * graphic buffer, or free it, as it does not actually own this
96b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * buffer.
97b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * --------------------------------------------------------------
98b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * |  kMetadataBufferTypeGraphicBuffer | sizeof(GraphicBuffer *) |
99b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     * --------------------------------------------------------------
100b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent     */
101b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent    kMetadataBufferTypeGraphicBuffer = 2,
102b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent
103b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent    // Add more here...
104b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent
105b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent} MetadataBufferType;
1068ba53d87a2d311ff4b3f04e30b2e09309ae7421cEric Laurent
1078ba53d87a2d311ff4b3f04e30b2e09309ae7421cEric Laurent#ifdef __cplusplus
1088ba53d87a2d311ff4b3f04e30b2e09309ae7421cEric Laurent}  // namespace android
1098ba53d87a2d311ff4b3f04e30b2e09309ae7421cEric Laurent}
110b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent#endif
111b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent
112b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent#endif  // METADATA_BUFFER_TYPE_H
113b7a11d83f749ad0200778c4815e907d011d4b5d3Eric Laurent