II420ColorConverter.h revision e936584ac1216e4d23dc9edd963f9785a77bf6b0
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef II420_COLOR_CONVERTER_H
18
19#define II420_COLOR_CONVERTER_H
20
21#include <stdint.h>
22#include <android/rect.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28typedef struct II420ColorConverter {
29
30    /*
31     * getDecoderOutputFormat
32     * Returns the color format (OMX_COLOR_FORMATTYPE) of the decoder output.
33     * If it is I420 (OMX_COLOR_FormatYUV420Planar), no conversion is needed,
34     * and convertDecoderOutputToI420() can be a no-op.
35     */
36    int (*getDecoderOutputFormat)();
37
38    /*
39     * convertDecoderOutputToI420
40     * @Desc     Converts from the decoder output format to I420 format.
41     * @note     Caller (e.g. VideoEditor) owns the buffers
42     * @param    decoderBits   (IN) Pointer to the buffer contains decoder output
43     * @param    decoderWidth  (IN) Buffer width, as reported by the decoder
44     *                              metadata (kKeyWidth)
45     * @param    decoderHeight (IN) Buffer height, as reported by the decoder
46     *                              metadata (kKeyHeight)
47     * @param    decoderRect   (IN) The rectangle of the actual frame, as
48     *                              reported by decoder metadata (kKeyCropRect)
49     * @param    dstBits      (OUT) Pointer to the output I420 buffer
50     * @return   -1 Any error
51     * @return   0  No Error
52     */
53    int (*convertDecoderOutputToI420)(
54        void* decoderBits, int decoderWidth, int decoderHeight,
55        ARect decoderRect, void* dstBits);
56
57    /*
58     * getEncoderIntputFormat
59     * Returns the color format (OMX_COLOR_FORMATTYPE) of the encoder input.
60     * If it is I420 (OMX_COLOR_FormatYUV420Planar), no conversion is needed,
61     * and convertI420ToEncoderInput() and getEncoderInputBufferInfo() can
62     * be no-ops.
63     */
64    int (*getEncoderInputFormat)();
65
66    /* convertI420ToEncoderInput
67     * @Desc     This function converts from I420 to the encoder input format
68     * @note     Caller (e.g. VideoEditor) owns the buffers
69     * @param    srcBits       (IN) Pointer to the input I420 buffer
70     * @param    srcWidth      (IN) Width of the I420 frame
71     * @param    srcHeight     (IN) Height of the I420 frame
72     * @param    encoderWidth  (IN) Encoder buffer width, as calculated by
73     *                              getEncoderBufferInfo()
74     * @param    encoderHeight (IN) Encoder buffer height, as calculated by
75     *                              getEncoderBufferInfo()
76     * @param    encoderRect   (IN) Rect coordinates of the actual frame inside
77     *                              the encoder buffer, as calculated by
78     *                              getEncoderBufferInfo().
79     * @param    encoderBits  (OUT) Pointer to the output buffer. The size of
80     *                              this buffer is calculated by
81     *                              getEncoderBufferInfo()
82     * @return   -1 Any error
83     * @return   0  No Error
84     */
85    int (*convertI420ToEncoderInput)(
86        void* srcBits, int srcWidth, int srcHeight,
87        int encoderWidth, int encoderHeight, ARect encoderRect,
88        void* encoderBits);
89
90    /* getEncoderInputBufferInfo
91     * @Desc     This function returns metadata for the encoder input buffer
92     *           based on the actual I420 frame width and height.
93     * @note     This API should be be used to obtain the necessary information
94     *           before calling convertI420ToEncoderInput().
95     *           VideoEditor knows only the width and height of the I420 buffer,
96     *           but it also needs know the width, height, and size of the
97     *           encoder input buffer. The encoder input buffer width and height
98     *           are used to set the metadata for the encoder.
99     * @param    srcWidth      (IN) Width of the I420 frame
100     * @param    srcHeight     (IN) Height of the I420 frame
101     * @param    encoderWidth  (OUT) Encoder buffer width needed
102     * @param    encoderHeight (OUT) Encoder buffer height needed
103     * @param    encoderRect   (OUT) Rect coordinates of the actual frame inside
104     *                               the encoder buffer
105     * @param    encoderBufferSize  (OUT) The size of the buffer that need to be
106     *                              allocated by the caller before invoking
107     *                              convertI420ToEncoderInput().
108     * @return   -1 Any error
109     * @return   0  No Error
110     */
111    int (*getEncoderInputBufferInfo)(
112        int srcWidth, int srcHeight,
113        int* encoderWidth, int* encoderHeight,
114        ARect* encoderRect, int* encoderBufferSize);
115
116} II420ColorConverter;
117
118/* The only function that the shared library needs to expose: It fills the
119   function pointers in II420ColorConverter */
120void getI420ColorConverter(II420ColorConverter *converter);
121
122#if defined(__cplusplus)
123}
124#endif
125
126#endif  // II420_COLOR_CONVERTER_H
127