blob: 2875f9f8420b29c6624b42222a85f51b5964e2b2 [file] [log] [blame]
Akshata Kadam9d946be2022-07-06 09:25:38 +00001/*
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
24constexpr int32_t kMinBytes = 1;
25constexpr int32_t kMaxBytes = 256;
26constexpr int32_t kMinIntKeyValue = 0;
27constexpr int32_t kMaxIntKeyValue = 6000000;
28constexpr int32_t kMinFloatKeyValue = 1.0f;
29constexpr int32_t kMaxFloatKeyValue = 500.f;
30constexpr int32_t kMinTimeOutUs = 0;
31constexpr int32_t kMaxTimeOutUs = 5000;
32constexpr int32_t kMinAPICase = 0;
33constexpr int32_t kMaxCodecFormatAPIs = 2;
34constexpr int32_t kMaxCryptoKey = 16;
35constexpr int32_t kMinIterations = 10;
36constexpr int32_t kMaxIterations = 100;
37constexpr size_t kMinBufferIndex = 1;
38constexpr size_t kMaxBufferIndex = 128;
39
40class NdkMediaCodecFuzzerBase {
41 public:
kunal rai205a3212022-09-22 13:47:06 +053042 NdkMediaCodecFuzzerBase() { mFormat = AMediaFormat_new(); }
Akshata Kadam9d946be2022-07-06 09:25:38 +000043 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 Kadam5dd792c2022-09-06 12:42:39 +053050 ~NdkMediaCodecFuzzerBase() {
51 if (mFormat) {
52 AMediaFormat_delete(mFormat);
53 }
54 }
Akshata Kadam9d946be2022-07-06 09:25:38 +000055
56 private:
57 AMediaCodec* createAMediaCodecByname(bool isEncoder, bool isCodecForClient);
58 AMediaCodec* createAMediaCodecByType(bool isEncoder, bool isCodecForClient);
59 AMediaFormat* getSampleAudioFormat();
60 AMediaFormat* getSampleVideoFormat();
kunal rai205a3212022-09-22 13:47:06 +053061 void setCodecFormat();
Akshata Kadam9d946be2022-07-06 09:25:38 +000062 AMediaFormat* mFormat = nullptr;
63 FuzzedDataProvider* mFdp = nullptr;
64};