Akshata Kadam | 9d946be | 2022-07-06 09:25:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 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 | #pragma once |
| 17 | #include <android/native_window.h> |
| 18 | #include <fuzzer/FuzzedDataProvider.h> |
| 19 | #include <media/NdkMediaCodec.h> |
| 20 | #include <media/NdkMediaCodecPlatform.h> |
| 21 | #include <media/NdkMediaFormat.h> |
| 22 | #include <media/stagefright/MediaCodecConstants.h> |
| 23 | |
| 24 | constexpr int32_t kMinBytes = 1; |
| 25 | constexpr int32_t kMaxBytes = 256; |
| 26 | constexpr int32_t kMinIntKeyValue = 0; |
| 27 | constexpr int32_t kMaxIntKeyValue = 6000000; |
| 28 | constexpr int32_t kMinFloatKeyValue = 1.0f; |
| 29 | constexpr int32_t kMaxFloatKeyValue = 500.f; |
| 30 | constexpr int32_t kMinTimeOutUs = 0; |
| 31 | constexpr int32_t kMaxTimeOutUs = 5000; |
| 32 | constexpr int32_t kMinAPICase = 0; |
| 33 | constexpr int32_t kMaxCodecFormatAPIs = 2; |
| 34 | constexpr int32_t kMaxCryptoKey = 16; |
| 35 | constexpr int32_t kMinIterations = 10; |
| 36 | constexpr int32_t kMaxIterations = 100; |
| 37 | constexpr size_t kMinBufferIndex = 1; |
| 38 | constexpr size_t kMaxBufferIndex = 128; |
| 39 | |
| 40 | class NdkMediaCodecFuzzerBase { |
| 41 | public: |
kunal rai | 205a321 | 2022-09-22 13:47:06 +0530 | [diff] [blame] | 42 | NdkMediaCodecFuzzerBase() { mFormat = AMediaFormat_new(); } |
Akshata Kadam | 9d946be | 2022-07-06 09:25:38 +0000 | [diff] [blame] | 43 | void invokeCodecFormatAPI(AMediaCodec* codec); |
| 44 | void invokeInputBufferOperationAPI(AMediaCodec* codec); |
| 45 | void invokeOutputBufferOperationAPI(AMediaCodec* codec); |
| 46 | AMediaCodecCryptoInfo* getAMediaCodecCryptoInfo(); |
| 47 | AMediaCodec* createCodec(bool isEncoder, bool isCodecForClient); |
| 48 | AMediaFormat* getCodecFormat() { return mFormat; }; |
| 49 | void setFdp(FuzzedDataProvider* fdp) { mFdp = fdp; } |
Akshata Kadam | 5dd792c | 2022-09-06 12:42:39 +0530 | [diff] [blame] | 50 | ~NdkMediaCodecFuzzerBase() { |
| 51 | if (mFormat) { |
| 52 | AMediaFormat_delete(mFormat); |
| 53 | } |
| 54 | } |
Akshata Kadam | 9d946be | 2022-07-06 09:25:38 +0000 | [diff] [blame] | 55 | |
| 56 | private: |
| 57 | AMediaCodec* createAMediaCodecByname(bool isEncoder, bool isCodecForClient); |
| 58 | AMediaCodec* createAMediaCodecByType(bool isEncoder, bool isCodecForClient); |
| 59 | AMediaFormat* getSampleAudioFormat(); |
| 60 | AMediaFormat* getSampleVideoFormat(); |
kunal rai | 205a321 | 2022-09-22 13:47:06 +0530 | [diff] [blame] | 61 | void setCodecFormat(); |
Akshata Kadam | 9d946be | 2022-07-06 09:25:38 +0000 | [diff] [blame] | 62 | AMediaFormat* mFormat = nullptr; |
| 63 | FuzzedDataProvider* mFdp = nullptr; |
| 64 | }; |