| 1 | /* | 
|---|
| 2 | Copyright (c) 2012, Broadcom Europe Ltd | 
|---|
| 3 | All rights reserved. | 
|---|
| 4 |  | 
|---|
| 5 | Redistribution and use in source and binary forms, with or without | 
|---|
| 6 | modification, are permitted provided that the following conditions are met: | 
|---|
| 7 | * Redistributions of source code must retain the above copyright | 
|---|
| 8 | notice, this list of conditions and the following disclaimer. | 
|---|
| 9 | * Redistributions in binary form must reproduce the above copyright | 
|---|
| 10 | notice, this list of conditions and the following disclaimer in the | 
|---|
| 11 | documentation and/or other materials provided with the distribution. | 
|---|
| 12 | * Neither the name of the copyright holder nor the | 
|---|
| 13 | names of its contributors may be used to endorse or promote products | 
|---|
| 14 | derived from this software without specific prior written permission. | 
|---|
| 15 |  | 
|---|
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | 
|---|
| 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 
|---|
| 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
|---|
| 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY | 
|---|
| 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 
|---|
| 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 
|---|
| 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 
|---|
| 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
|---|
| 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 
|---|
| 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
|---|
| 26 | */ | 
|---|
| 27 |  | 
|---|
| 28 | /** \file | 
|---|
| 29 | *  Jpeg encoder and decoder library using the hardware jpeg codec | 
|---|
| 30 | */ | 
|---|
| 31 |  | 
|---|
| 32 | #ifndef BRCM_JPEG_H | 
|---|
| 33 | #define BRCM_JPEG_H | 
|---|
| 34 |  | 
|---|
| 35 | #ifdef __cplusplus | 
|---|
| 36 | extern "C"{ | 
|---|
| 37 | #endif | 
|---|
| 38 |  | 
|---|
| 39 | /** Status return codes from the API */ | 
|---|
| 40 | typedef enum | 
|---|
| 41 | { | 
|---|
| 42 | BRCMJPEG_SUCCESS = 0, | 
|---|
| 43 | BRCMJPEG_ERROR_NOMEM, | 
|---|
| 44 | BRCMJPEG_ERROR_INIT, | 
|---|
| 45 | BRCMJPEG_ERROR_INPUT_FORMAT, | 
|---|
| 46 | BRCMJPEG_ERROR_OUTPUT_FORMAT, | 
|---|
| 47 | BRCMJPEG_ERROR_INPUT_BUFFER, | 
|---|
| 48 | BRCMJPEG_ERROR_OUTPUT_BUFFER, | 
|---|
| 49 | BRCMJPEG_ERROR_EXECUTE, | 
|---|
| 50 | BRCMJPEG_ERROR_REQUEST, | 
|---|
| 51 | } BRCMJPEG_STATUS_T; | 
|---|
| 52 |  | 
|---|
| 53 | /** Type of the codec instance to create */ | 
|---|
| 54 | typedef enum | 
|---|
| 55 | { | 
|---|
| 56 | BRCMJPEG_TYPE_ENCODER = 0, | 
|---|
| 57 | BRCMJPEG_TYPE_DECODER | 
|---|
| 58 | } BRCMJPEG_TYPE_T; | 
|---|
| 59 |  | 
|---|
| 60 | /** Pixel formats supported by the codec */ | 
|---|
| 61 | typedef enum | 
|---|
| 62 | { | 
|---|
| 63 | PIXEL_FORMAT_UNKNOWN = 0, | 
|---|
| 64 | PIXEL_FORMAT_I420, /* planar YUV 4:2:0 */ | 
|---|
| 65 | PIXEL_FORMAT_YV12, /* planar YVU 4:2:0 */ | 
|---|
| 66 | PIXEL_FORMAT_I422, /* planar YUV 4:2:2 */ | 
|---|
| 67 | PIXEL_FORMAT_YV16, /* planar YVU 4:2:2 */ | 
|---|
| 68 | PIXEL_FORMAT_YUYV, /* interleaved YUV 4:2:2 */ | 
|---|
| 69 | PIXEL_FORMAT_RGBA, /* interleaved RGBA */ | 
|---|
| 70 | } BRCMJPEG_PIXEL_FORMAT_T; | 
|---|
| 71 |  | 
|---|
| 72 | /** Definition of a codec request  */ | 
|---|
| 73 | typedef struct | 
|---|
| 74 | { | 
|---|
| 75 | /** Pointer to the buffer containing the input data | 
|---|
| 76 | * A client should set input OR input_handle, but not both. */ | 
|---|
| 77 | const unsigned char *input; | 
|---|
| 78 | /** Actual size of the input data */ | 
|---|
| 79 | unsigned int input_size; | 
|---|
| 80 | /** Handle to input buffer containing input data */ | 
|---|
| 81 | unsigned int input_handle; | 
|---|
| 82 |  | 
|---|
| 83 | /** Pointer to the buffer used for the output data | 
|---|
| 84 | * A client should set output OR output_handle, but not both. */ | 
|---|
| 85 | unsigned char *output; | 
|---|
| 86 | /** Total size of the output buffer */ | 
|---|
| 87 | unsigned int output_alloc_size; | 
|---|
| 88 | /** Actual size of the output data (this is an output parameter) */ | 
|---|
| 89 | unsigned int output_size; | 
|---|
| 90 | /** Handle to the buffer used for the output data */ | 
|---|
| 91 | unsigned int output_handle; | 
|---|
| 92 |  | 
|---|
| 93 | /** Width of the raw frame (this is an input parameter for encode) */ | 
|---|
| 94 | unsigned int width; | 
|---|
| 95 | /** Height of the raw frame (this is an input parameter for encode) */ | 
|---|
| 96 | unsigned int height; | 
|---|
| 97 | /** Pixel format of the raw frame (this is an input parameter) */ | 
|---|
| 98 | BRCMJPEG_PIXEL_FORMAT_T pixel_format; | 
|---|
| 99 |  | 
|---|
| 100 | /** Width of the buffer containing the raw frame (input parameter). | 
|---|
| 101 | * This is optional but if set, is used to specify the actual width | 
|---|
| 102 | * of the buffer containing the raw frame */ | 
|---|
| 103 | unsigned int buffer_width; | 
|---|
| 104 | /** Height of the buffer containing the raw frame (input parameter). | 
|---|
| 105 | * This is optional but if set, is used to specify the actual height | 
|---|
| 106 | * of the buffer containing the raw frame */ | 
|---|
| 107 | unsigned int buffer_height; | 
|---|
| 108 |  | 
|---|
| 109 | /** Encode quality - 0 to 100 */ | 
|---|
| 110 | unsigned int quality; | 
|---|
| 111 | } BRCMJPEG_REQUEST_T; | 
|---|
| 112 |  | 
|---|
| 113 | /** Type of the codec instance */ | 
|---|
| 114 | typedef struct BRCMJPEG_T BRCMJPEG_T; | 
|---|
| 115 |  | 
|---|
| 116 | /** Create an instance of the jpeg codec | 
|---|
| 117 | * This will actually re-use an existing instance if one is | 
|---|
| 118 | * available. | 
|---|
| 119 | * | 
|---|
| 120 | * @param type type of codec instance required | 
|---|
| 121 | * @param ctx will point to the newly created instance | 
|---|
| 122 | * @return BRCMJPEG_SUCCESS on success | 
|---|
| 123 | */ | 
|---|
| 124 | BRCMJPEG_STATUS_T brcmjpeg_create(BRCMJPEG_TYPE_T type, BRCMJPEG_T **ctx); | 
|---|
| 125 |  | 
|---|
| 126 | /** Acquire a new reference on a codec instance | 
|---|
| 127 | * | 
|---|
| 128 | * @param ctx instance to acquire a reference on | 
|---|
| 129 | */ | 
|---|
| 130 | void brcmjpeg_acquire(BRCMJPEG_T *ctx); | 
|---|
| 131 |  | 
|---|
| 132 | /** Release an instance of the jpeg codec | 
|---|
| 133 | * This will only trigger the destruction of the codec instance when | 
|---|
| 134 | * the last reference to it is being released. | 
|---|
| 135 | * | 
|---|
| 136 | * @param ctx instance to release | 
|---|
| 137 | */ | 
|---|
| 138 | void brcmjpeg_release(BRCMJPEG_T *ctx); | 
|---|
| 139 |  | 
|---|
| 140 | /** Process a jpeg codec request | 
|---|
| 141 | * | 
|---|
| 142 | * @param ctx instance of codec to use | 
|---|
| 143 | * @param request codec request to execute | 
|---|
| 144 | * @return BRCMJPEG_SUCCESS on success | 
|---|
| 145 | */ | 
|---|
| 146 | BRCMJPEG_STATUS_T brcmjpeg_process(BRCMJPEG_T *ctx, BRCMJPEG_REQUEST_T *request); | 
|---|
| 147 |  | 
|---|
| 148 | #ifdef __cplusplus | 
|---|
| 149 | } | 
|---|
| 150 | #endif | 
|---|
| 151 |  | 
|---|
| 152 | #endif /* BRCM_JPEG_H */ | 
|---|
| 153 |  | 
|---|