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_ENCODE_INTERFACE_H 6 #define ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_ENCODE_INTERFACE_H 7 8 #include <optional> 9 #include <vector> 10 11 #include <C2.h> 12 #include <C2Buffer.h> 13 #include <C2Config.h> 14 #include <util/C2InterfaceHelper.h> 15 16 #include <size.h> 17 #include <v4l2_codec2/common/EncodeHelpers.h> 18 #include <video_codecs.h> 19 20 namespace media { 21 class V4L2Device; 22 }; 23 24 namespace android { 25 26 // Codec 2.0 interface describing the V4L2EncodeComponent. This interface is used by the codec 2.0 27 // framework to query the component's capabilities and request configuration changes. 28 class V4L2EncodeInterface : public C2InterfaceHelper { 29 public: 30 V4L2EncodeInterface(const C2String& name, std::shared_ptr<C2ReflectorHelper> helper); 31 32 // Interfaces for the V4L2EncodeInterface 33 // Note: these getters are not thread-safe. For dynamic parameters, component should use 34 // formal query API for C2ComponentInterface instead. status()35 c2_status_t status() const { return mInitStatus; } getOutputProfile()36 C2Config::profile_t getOutputProfile() const { return mProfileLevel->profile; } getOutputLevel()37 C2Config::level_t getOutputLevel() const { return mProfileLevel->level; } getInputVisibleSize()38 const media::Size getInputVisibleSize() const { 39 return media::Size(mInputVisibleSize->width, mInputVisibleSize->height); 40 } getBlockPoolId()41 C2BlockPool::local_id_t getBlockPoolId() const { return mOutputBlockPoolIds->m.values[0]; } 42 // Get sync key-frame period in frames. 43 uint32_t getKeyFramePeriod() const; 44 45 protected: 46 void Initialize(const C2String& name); 47 48 // Configurable parameter setters. 49 static C2R ProfileLevelSetter(bool mayBlock, C2P<C2StreamProfileLevelInfo::output>& info, 50 const C2P<C2StreamPictureSizeInfo::input>& videosize, 51 const C2P<C2StreamFrameRateInfo::output>& frameRate, 52 const C2P<C2StreamBitrateInfo::output>& bitrate); 53 54 static C2R SizeSetter(bool mayBlock, C2P<C2StreamPictureSizeInfo::input>& videoSize); 55 56 static C2R IntraRefreshPeriodSetter(bool mayBlock, 57 C2P<C2StreamIntraRefreshTuning::output>& period); 58 59 // Constant parameters 60 61 // The input format kind; should be C2FormatVideo. 62 std::shared_ptr<C2StreamBufferTypeSetting::input> mInputFormat; 63 // The memory usage flag of input buffer; should be BufferUsage::VIDEO_ENCODER. 64 std::shared_ptr<C2StreamUsageTuning::input> mInputMemoryUsage; 65 // The output format kind; should be C2FormatCompressed. 66 std::shared_ptr<C2StreamBufferTypeSetting::output> mOutputFormat; 67 // The MIME type of input port; should be MEDIA_MIMETYPE_VIDEO_RAW. 68 std::shared_ptr<C2PortMediaTypeSetting::input> mInputMediaType; 69 // The MIME type of output port. 70 std::shared_ptr<C2PortMediaTypeSetting::output> mOutputMediaType; 71 72 // The suggested usage of input buffer allocator ID. 73 std::shared_ptr<C2PortAllocatorsTuning::input> mInputAllocatorIds; 74 // The suggested usage of output buffer allocator ID. 75 std::shared_ptr<C2PortAllocatorsTuning::output> mOutputAllocatorIds; 76 77 // Initialization parameters 78 79 // The visible size for input raw video. 80 std::shared_ptr<C2StreamPictureSizeInfo::input> mInputVisibleSize; 81 // The output codec profile and level. 82 std::shared_ptr<C2StreamProfileLevelInfo::output> mProfileLevel; 83 // The expected period for key frames in microseconds. 84 std::shared_ptr<C2StreamSyncFrameIntervalTuning::output> mKeyFramePeriodUs; 85 // Component uses this ID to fetch corresponding output block pool from platform. 86 std::shared_ptr<C2PortBlockPoolsTuning::output> mOutputBlockPoolIds; 87 88 // Dynamic parameters 89 90 // The requested bitrate of the encoded output stream, in bits per second. 91 std::shared_ptr<C2StreamBitrateInfo::output> mBitrate; 92 // The requested framerate, in frames per second. 93 std::shared_ptr<C2StreamFrameRateInfo::output> mFrameRate; 94 // The switch-type parameter that will be set to true while client requests keyframe. It 95 // will be reset once encoder gets the request. 96 std::shared_ptr<C2StreamRequestSyncFrameTuning::output> mRequestKeyFrame; 97 // The intra-frame refresh period. This is unused for the component now. 98 // TODO: adapt intra refresh period to encoder. 99 std::shared_ptr<C2StreamIntraRefreshTuning::output> mIntraRefreshPeriod; 100 101 c2_status_t mInitStatus = C2_NO_INIT; 102 }; 103 104 } // namespace android 105 106 #endif // ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_ENCODE_INTERFACE_H 107