1*c0909341SAndroid Build Coastguard Worker /* 2*c0909341SAndroid Build Coastguard Worker * Copyright © 2018-2020, VideoLAN and dav1d authors 3*c0909341SAndroid Build Coastguard Worker * Copyright © 2018, Two Orioles, LLC 4*c0909341SAndroid Build Coastguard Worker * All rights reserved. 5*c0909341SAndroid Build Coastguard Worker * 6*c0909341SAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 7*c0909341SAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions are met: 8*c0909341SAndroid Build Coastguard Worker * 9*c0909341SAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright notice, this 10*c0909341SAndroid Build Coastguard Worker * list of conditions and the following disclaimer. 11*c0909341SAndroid Build Coastguard Worker * 12*c0909341SAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright notice, 13*c0909341SAndroid Build Coastguard Worker * this list of conditions and the following disclaimer in the documentation 14*c0909341SAndroid Build Coastguard Worker * and/or other materials provided with the distribution. 15*c0909341SAndroid Build Coastguard Worker * 16*c0909341SAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17*c0909341SAndroid Build Coastguard Worker * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18*c0909341SAndroid Build Coastguard Worker * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19*c0909341SAndroid Build Coastguard Worker * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20*c0909341SAndroid Build Coastguard Worker * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21*c0909341SAndroid Build Coastguard Worker * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22*c0909341SAndroid Build Coastguard Worker * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23*c0909341SAndroid Build Coastguard Worker * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24*c0909341SAndroid Build Coastguard Worker * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25*c0909341SAndroid Build Coastguard Worker * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26*c0909341SAndroid Build Coastguard Worker */ 27*c0909341SAndroid Build Coastguard Worker 28*c0909341SAndroid Build Coastguard Worker #ifndef DAV1D_PICTURE_H 29*c0909341SAndroid Build Coastguard Worker #define DAV1D_PICTURE_H 30*c0909341SAndroid Build Coastguard Worker 31*c0909341SAndroid Build Coastguard Worker #include <stddef.h> 32*c0909341SAndroid Build Coastguard Worker #include <stdint.h> 33*c0909341SAndroid Build Coastguard Worker 34*c0909341SAndroid Build Coastguard Worker #include "common.h" 35*c0909341SAndroid Build Coastguard Worker #include "headers.h" 36*c0909341SAndroid Build Coastguard Worker 37*c0909341SAndroid Build Coastguard Worker #ifdef __cplusplus 38*c0909341SAndroid Build Coastguard Worker extern "C" { 39*c0909341SAndroid Build Coastguard Worker #endif 40*c0909341SAndroid Build Coastguard Worker 41*c0909341SAndroid Build Coastguard Worker /* Number of bytes to align AND pad picture memory buffers by, so that SIMD 42*c0909341SAndroid Build Coastguard Worker * implementations can over-read by a few bytes, and use aligned read/write 43*c0909341SAndroid Build Coastguard Worker * instructions. */ 44*c0909341SAndroid Build Coastguard Worker #define DAV1D_PICTURE_ALIGNMENT 64 45*c0909341SAndroid Build Coastguard Worker 46*c0909341SAndroid Build Coastguard Worker typedef struct Dav1dPictureParameters { 47*c0909341SAndroid Build Coastguard Worker int w; ///< width (in pixels) 48*c0909341SAndroid Build Coastguard Worker int h; ///< height (in pixels) 49*c0909341SAndroid Build Coastguard Worker enum Dav1dPixelLayout layout; ///< format of the picture 50*c0909341SAndroid Build Coastguard Worker int bpc; ///< bits per pixel component (8 or 10) 51*c0909341SAndroid Build Coastguard Worker } Dav1dPictureParameters; 52*c0909341SAndroid Build Coastguard Worker 53*c0909341SAndroid Build Coastguard Worker typedef struct Dav1dPicture { 54*c0909341SAndroid Build Coastguard Worker Dav1dSequenceHeader *seq_hdr; 55*c0909341SAndroid Build Coastguard Worker Dav1dFrameHeader *frame_hdr; 56*c0909341SAndroid Build Coastguard Worker 57*c0909341SAndroid Build Coastguard Worker /** 58*c0909341SAndroid Build Coastguard Worker * Pointers to planar image data (Y is [0], U is [1], V is [2]). The data 59*c0909341SAndroid Build Coastguard Worker * should be bytes (for 8 bpc) or words (for 10 bpc). In case of words 60*c0909341SAndroid Build Coastguard Worker * containing 10 bpc image data, the pixels should be located in the LSB 61*c0909341SAndroid Build Coastguard Worker * bits, so that values range between [0, 1023]; the upper bits should be 62*c0909341SAndroid Build Coastguard Worker * zero'ed out. 63*c0909341SAndroid Build Coastguard Worker */ 64*c0909341SAndroid Build Coastguard Worker void *data[3]; 65*c0909341SAndroid Build Coastguard Worker 66*c0909341SAndroid Build Coastguard Worker /** 67*c0909341SAndroid Build Coastguard Worker * Number of bytes between 2 lines in data[] for luma [0] or chroma [1]. 68*c0909341SAndroid Build Coastguard Worker */ 69*c0909341SAndroid Build Coastguard Worker ptrdiff_t stride[2]; 70*c0909341SAndroid Build Coastguard Worker 71*c0909341SAndroid Build Coastguard Worker Dav1dPictureParameters p; 72*c0909341SAndroid Build Coastguard Worker Dav1dDataProps m; 73*c0909341SAndroid Build Coastguard Worker 74*c0909341SAndroid Build Coastguard Worker /** 75*c0909341SAndroid Build Coastguard Worker * High Dynamic Range Content Light Level metadata applying to this picture, 76*c0909341SAndroid Build Coastguard Worker * as defined in section 5.8.3 and 6.7.3 77*c0909341SAndroid Build Coastguard Worker */ 78*c0909341SAndroid Build Coastguard Worker Dav1dContentLightLevel *content_light; 79*c0909341SAndroid Build Coastguard Worker /** 80*c0909341SAndroid Build Coastguard Worker * High Dynamic Range Mastering Display Color Volume metadata applying to 81*c0909341SAndroid Build Coastguard Worker * this picture, as defined in section 5.8.4 and 6.7.4 82*c0909341SAndroid Build Coastguard Worker */ 83*c0909341SAndroid Build Coastguard Worker Dav1dMasteringDisplay *mastering_display; 84*c0909341SAndroid Build Coastguard Worker /** 85*c0909341SAndroid Build Coastguard Worker * Array of ITU-T T.35 metadata as defined in section 5.8.2 and 6.7.2 86*c0909341SAndroid Build Coastguard Worker */ 87*c0909341SAndroid Build Coastguard Worker Dav1dITUTT35 *itut_t35; 88*c0909341SAndroid Build Coastguard Worker 89*c0909341SAndroid Build Coastguard Worker /** 90*c0909341SAndroid Build Coastguard Worker * Number of ITU-T T35 metadata entries in the array 91*c0909341SAndroid Build Coastguard Worker */ 92*c0909341SAndroid Build Coastguard Worker size_t n_itut_t35; 93*c0909341SAndroid Build Coastguard Worker 94*c0909341SAndroid Build Coastguard Worker uintptr_t reserved[4]; ///< reserved for future use 95*c0909341SAndroid Build Coastguard Worker 96*c0909341SAndroid Build Coastguard Worker struct Dav1dRef *frame_hdr_ref; ///< Dav1dFrameHeader allocation origin 97*c0909341SAndroid Build Coastguard Worker struct Dav1dRef *seq_hdr_ref; ///< Dav1dSequenceHeader allocation origin 98*c0909341SAndroid Build Coastguard Worker struct Dav1dRef *content_light_ref; ///< Dav1dContentLightLevel allocation origin 99*c0909341SAndroid Build Coastguard Worker struct Dav1dRef *mastering_display_ref; ///< Dav1dMasteringDisplay allocation origin 100*c0909341SAndroid Build Coastguard Worker struct Dav1dRef *itut_t35_ref; ///< Dav1dITUTT35 allocation origin 101*c0909341SAndroid Build Coastguard Worker uintptr_t reserved_ref[4]; ///< reserved for future use 102*c0909341SAndroid Build Coastguard Worker struct Dav1dRef *ref; ///< Frame data allocation origin 103*c0909341SAndroid Build Coastguard Worker 104*c0909341SAndroid Build Coastguard Worker void *allocator_data; ///< pointer managed by the allocator 105*c0909341SAndroid Build Coastguard Worker } Dav1dPicture; 106*c0909341SAndroid Build Coastguard Worker 107*c0909341SAndroid Build Coastguard Worker typedef struct Dav1dPicAllocator { 108*c0909341SAndroid Build Coastguard Worker void *cookie; ///< custom data to pass to the allocator callbacks. 109*c0909341SAndroid Build Coastguard Worker /** 110*c0909341SAndroid Build Coastguard Worker * Allocate the picture buffer based on the Dav1dPictureParameters. 111*c0909341SAndroid Build Coastguard Worker * 112*c0909341SAndroid Build Coastguard Worker * The data[0], data[1] and data[2] must be DAV1D_PICTURE_ALIGNMENT byte 113*c0909341SAndroid Build Coastguard Worker * aligned and with a pixel width/height multiple of 128 pixels. Any 114*c0909341SAndroid Build Coastguard Worker * allocated memory area should also be padded by DAV1D_PICTURE_ALIGNMENT 115*c0909341SAndroid Build Coastguard Worker * bytes. 116*c0909341SAndroid Build Coastguard Worker * data[1] and data[2] must share the same stride[1]. 117*c0909341SAndroid Build Coastguard Worker * 118*c0909341SAndroid Build Coastguard Worker * This function will be called on the main thread (the thread which calls 119*c0909341SAndroid Build Coastguard Worker * dav1d_get_picture()). 120*c0909341SAndroid Build Coastguard Worker * 121*c0909341SAndroid Build Coastguard Worker * @param pic The picture to allocate the buffer for. The callback needs to 122*c0909341SAndroid Build Coastguard Worker * fill the picture data[0], data[1], data[2], stride[0] and 123*c0909341SAndroid Build Coastguard Worker * stride[1]. 124*c0909341SAndroid Build Coastguard Worker * The allocator can fill the pic allocator_data pointer with 125*c0909341SAndroid Build Coastguard Worker * a custom pointer that will be passed to 126*c0909341SAndroid Build Coastguard Worker * release_picture_callback(). 127*c0909341SAndroid Build Coastguard Worker * @param cookie Custom pointer passed to all calls. 128*c0909341SAndroid Build Coastguard Worker * 129*c0909341SAndroid Build Coastguard Worker * @note No fields other than data, stride and allocator_data must be filled 130*c0909341SAndroid Build Coastguard Worker * by this callback. 131*c0909341SAndroid Build Coastguard Worker * @return 0 on success. A negative DAV1D_ERR value on error. 132*c0909341SAndroid Build Coastguard Worker */ 133*c0909341SAndroid Build Coastguard Worker int (*alloc_picture_callback)(Dav1dPicture *pic, void *cookie); 134*c0909341SAndroid Build Coastguard Worker /** 135*c0909341SAndroid Build Coastguard Worker * Release the picture buffer. 136*c0909341SAndroid Build Coastguard Worker * 137*c0909341SAndroid Build Coastguard Worker * If frame threading is used, this function may be called by the main 138*c0909341SAndroid Build Coastguard Worker * thread (the thread which calls dav1d_get_picture()) or any of the frame 139*c0909341SAndroid Build Coastguard Worker * threads and thus must be thread-safe. If frame threading is not used, 140*c0909341SAndroid Build Coastguard Worker * this function will only be called on the main thread. 141*c0909341SAndroid Build Coastguard Worker * 142*c0909341SAndroid Build Coastguard Worker * @param pic The picture that was filled by alloc_picture_callback(). 143*c0909341SAndroid Build Coastguard Worker * @param cookie Custom pointer passed to all calls. 144*c0909341SAndroid Build Coastguard Worker */ 145*c0909341SAndroid Build Coastguard Worker void (*release_picture_callback)(Dav1dPicture *pic, void *cookie); 146*c0909341SAndroid Build Coastguard Worker } Dav1dPicAllocator; 147*c0909341SAndroid Build Coastguard Worker 148*c0909341SAndroid Build Coastguard Worker /** 149*c0909341SAndroid Build Coastguard Worker * Release reference to a picture. 150*c0909341SAndroid Build Coastguard Worker */ 151*c0909341SAndroid Build Coastguard Worker DAV1D_API void dav1d_picture_unref(Dav1dPicture *p); 152*c0909341SAndroid Build Coastguard Worker 153*c0909341SAndroid Build Coastguard Worker #ifdef __cplusplus 154*c0909341SAndroid Build Coastguard Worker } /* extern "C" */ 155*c0909341SAndroid Build Coastguard Worker #endif 156*c0909341SAndroid Build Coastguard Worker 157*c0909341SAndroid Build Coastguard Worker #endif /* DAV1D_PICTURE_H */ 158