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