xref: /aosp_15_r20/external/libgav1/examples/gav1_decode_cv_pixel_buffer_pool.h (revision 095378508e87ed692bf8dfeb34008b65b3735891)
1 /*
2  * Copyright 2020 The libgav1 Authors
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 LIBGAV1_EXAMPLES_GAV1_DECODE_CV_PIXEL_BUFFER_POOL_H_
18 #define LIBGAV1_EXAMPLES_GAV1_DECODE_CV_PIXEL_BUFFER_POOL_H_
19 
20 #include <CoreVideo/CoreVideo.h>
21 
22 #include <cstddef>
23 #include <memory>
24 
25 #include "gav1/frame_buffer.h"
26 
27 extern "C" libgav1::StatusCode Gav1DecodeOnCVPixelBufferSizeChanged(
28     void* callback_private_data, int bitdepth,
29     libgav1::ImageFormat image_format, int width, int height, int left_border,
30     int right_border, int top_border, int bottom_border, int stride_alignment);
31 
32 extern "C" libgav1::StatusCode Gav1DecodeGetCVPixelBuffer(
33     void* callback_private_data, int bitdepth,
34     libgav1::ImageFormat image_format, int width, int height, int left_border,
35     int right_border, int top_border, int bottom_border, int stride_alignment,
36     libgav1::FrameBuffer* frame_buffer);
37 
38 extern "C" void Gav1DecodeReleaseCVPixelBuffer(void* callback_private_data,
39                                                void* buffer_private_data);
40 
41 class Gav1DecodeCVPixelBufferPool {
42  public:
43   static std::unique_ptr<Gav1DecodeCVPixelBufferPool> Create(
44       size_t num_buffers);
45 
46   // Not copyable or movable.
47   Gav1DecodeCVPixelBufferPool(const Gav1DecodeCVPixelBufferPool&) = delete;
48   Gav1DecodeCVPixelBufferPool& operator=(const Gav1DecodeCVPixelBufferPool&) =
49       delete;
50 
51   ~Gav1DecodeCVPixelBufferPool();
52 
53   libgav1::StatusCode OnCVPixelBufferSizeChanged(
54       int bitdepth, libgav1::ImageFormat image_format, int width, int height,
55       int left_border, int right_border, int top_border, int bottom_border,
56       int stride_alignment);
57 
58   libgav1::StatusCode GetCVPixelBuffer(int bitdepth,
59                                        libgav1::ImageFormat image_format,
60                                        int width, int height, int left_border,
61                                        int right_border, int top_border,
62                                        int bottom_border, int stride_alignment,
63                                        libgav1::FrameBuffer* frame_buffer);
64   void ReleaseCVPixelBuffer(void* buffer_private_data);
65 
66  private:
67   Gav1DecodeCVPixelBufferPool(size_t num_buffers);
68 
69   CVPixelBufferPoolRef pool_ = nullptr;
70   const int num_buffers_;
71 };
72 
73 #endif  // LIBGAV1_EXAMPLES_GAV1_DECODE_CV_PIXEL_BUFFER_POOL_H_
74