xref: /aosp_15_r20/external/v4l2_codec2/components/include/v4l2_codec2/components/DecodeInterface.h (revision 0ec5a0ec62797f775085659156625e7f1bdb369f)
1 // Copyright 2023 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef ANDROID_V4L2_CODEC2_COMPONENTS_DECODE_INTERFACE_H
6 #define ANDROID_V4L2_CODEC2_COMPONENTS_DECODE_INTERFACE_H
7 
8 #include <memory>
9 #include <string>
10 
11 #include <C2Config.h>
12 #include <ui/Size.h>
13 #include <util/C2InterfaceHelper.h>
14 
15 #include <v4l2_codec2/common/Common.h>
16 #include <v4l2_codec2/common/VideoTypes.h>
17 
18 namespace android {
19 
20 class DecodeInterface : public C2InterfaceHelper {
21 public:
22     DecodeInterface(const std::string& name, const std::shared_ptr<C2ReflectorHelper>& helper,
23                     const SupportedCapabilities& caps);
24     DecodeInterface(const DecodeInterface&) = delete;
25     DecodeInterface& operator=(const DecodeInterface&) = delete;
26     ~DecodeInterface() = default;
27 
28     // interfaces for the client component.
status()29     c2_status_t status() const { return mInitStatus; }
getBlockPoolId()30     C2BlockPool::local_id_t getBlockPoolId() const { return mOutputBlockPoolIds->m.values[0]; }
getVideoCodec()31     std::optional<VideoCodec> getVideoCodec() const { return mVideoCodec; }
32 
33     static uint32_t getOutputDelay(VideoCodec codec);
34 
35     size_t getInputBufferSize() const;
36     c2_status_t queryColorAspects(
37             std::shared_ptr<C2StreamColorAspectsInfo::output>* targetColorAspects);
38 
39 private:
40     // Configurable parameter setters.
41     static C2R ProfileLevelSetter(bool mayBlock, C2P<C2StreamProfileLevelInfo::input>& info);
42     static C2R SizeSetter(bool mayBlock, C2P<C2StreamPictureSizeInfo::output>& videoSize);
43     static C2R InputSizeSetter(bool mayBlock, C2P<C2StreamMaxBufferSizeInfo::input>& inputSize);
44     static C2R MaxInputBufferSizeCalculator(bool mayBlock,
45                                             C2P<C2StreamMaxBufferSizeInfo::input>& me,
46                                             const C2P<C2StreamPictureSizeInfo::output>& size);
47 
48     template <typename T>
49     static C2R DefaultColorAspectsSetter(bool mayBlock, C2P<T>& def);
50 
51     static C2R MergedColorAspectsSetter(bool mayBlock,
52                                         C2P<C2StreamColorAspectsInfo::output>& merged,
53                                         const C2P<C2StreamColorAspectsTuning::output>& def,
54                                         const C2P<C2StreamColorAspectsInfo::input>& coded);
55 
56     // The kind of the component; should be C2Component::KIND_DECODER.
57     std::shared_ptr<C2ComponentKindSetting> mKind;
58     // The input format kind; should be C2FormatCompressed.
59     std::shared_ptr<C2StreamBufferTypeSetting::input> mInputFormat;
60     // The memory usage flag of input buffer; should be BufferUsage::VIDEO_DECODER.
61     std::shared_ptr<C2StreamUsageTuning::input> mInputMemoryUsage;
62     // The output format kind; should be C2FormatVideo.
63     std::shared_ptr<C2StreamBufferTypeSetting::output> mOutputFormat;
64     // The MIME type of input port.
65     std::shared_ptr<C2PortMediaTypeSetting::input> mInputMediaType;
66     // The MIME type of output port; should be MEDIA_MIMETYPE_VIDEO_RAW.
67     std::shared_ptr<C2PortMediaTypeSetting::output> mOutputMediaType;
68     // The number of additional output frames that might need to be generated before an output
69     // buffer can be released by the component; only used for H264 because H264 may reorder the
70     // output frames.
71     std::shared_ptr<C2PortDelayTuning::output> mOutputDelay;
72     // The number of extra frames processed at one time by the component. Allows more input
73     // buffers to be simultaneously enqueued.
74     std::shared_ptr<C2PipelineDelayTuning> mPipelineDelay;
75     // The input codec profile and level. For now configuring this parameter is useless since
76     // the component always uses fixed codec profile to initialize accelerator. It is only used
77     // for the client to query supported profile and level values.
78     // TODO: use configured profile/level to initialize accelerator.
79     std::shared_ptr<C2StreamProfileLevelInfo::input> mProfileLevel;
80     // Decoded video size for output.
81     std::shared_ptr<C2StreamPictureSizeInfo::output> mSize;
82     // Maximum size of one input buffer.
83     std::shared_ptr<C2StreamMaxBufferSizeInfo::input> mMaxInputSize;
84     // The suggested usage of input buffer allocator ID.
85     std::shared_ptr<C2PortAllocatorsTuning::input> mInputAllocatorIds;
86     // The suggested usage of output buffer allocator ID.
87     std::shared_ptr<C2PortAllocatorsTuning::output> mOutputAllocatorIds;
88     // The suggested usage of output buffer allocator ID with surface.
89     std::shared_ptr<C2PortSurfaceAllocatorTuning::output> mOutputSurfaceAllocatorId;
90     // Component uses this ID to fetch corresponding output block pool from platform.
91     std::shared_ptr<C2PortBlockPoolsTuning::output> mOutputBlockPoolIds;
92     // The color aspects parsed from input bitstream. This parameter should be configured by
93     // component while decoding.
94     std::shared_ptr<C2StreamColorAspectsInfo::input> mCodedColorAspects;
95     // The default color aspects specified by requested output format. This parameter should be
96     // configured by client.
97     std::shared_ptr<C2StreamColorAspectsTuning::output> mDefaultColorAspects;
98     // The combined color aspects by |mCodedColorAspects| and |mDefaultColorAspects|, and the
99     // former has higher priority. This parameter is used for component to provide color aspects
100     // as C2Info in decoded output buffers.
101     std::shared_ptr<C2StreamColorAspectsInfo::output> mColorAspects;
102 
103     c2_status_t mInitStatus;
104     std::optional<VideoCodec> mVideoCodec;
105 };
106 
107 }  // namespace android
108 
109 #endif  // ANDROID_V4L2_CODEC2_COMPONENTS_DECODE_INTERFACE_H
110