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