• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef NOTIFYCHANGE_FUZZER_H
17 #define NOTIFYCHANGE_FUZZER_H
18 
19 #define FUZZ_PROJECT_NAME "medialibrarymediaphotoassetproxy_fuzzer"
20 
21 #include <cstdint>
22 #include <string>
23 #include <ctime>
24 #include <iostream>
25 #include <sstream>
26 #include <iomanip>
27 
28 #include "photo_proxy.h"
29 #include "media_photo_asset_proxy.h"
30 
31 namespace OHOS {
32 namespace Media {
33 using namespace std;
34 const int32_t WIDTH = 3072;
35 const int32_t HEIGHT = 4096;
36 const int32_t PADDING_WIDTH = 2;
37 const char FILL_CHAR = '0';
38 const int32_t BASE_YEAR = 1900;
39 const int32_t MONTH_GAP = 1;
40 
41 class PhotoProxyFuzzTest : public PhotoProxy {
42 public:
PhotoProxyFuzzTest()43     PhotoProxyFuzzTest()
44     {
45         time_t nowTime = time(NULL);
46         if (nowTime == -1) {
47             return;
48         }
49         tm *localTime = localtime(&nowTime);
50         if (localTime == nullptr) {
51             return;
52         }
53         std::ostringstream streamObj;
54         // 设置宽度并使用 '0' 填充未使用的位置
55         streamObj << std::setw(PADDING_WIDTH) << std::setfill(FILL_CHAR) << to_string(localTime->tm_mon + MONTH_GAP) <<
56             to_string(localTime->tm_mday) << "_" << to_string(localTime->tm_hour) << to_string(localTime->tm_min) <<
57             to_string(localTime->tm_sec);
58         title_ = "IMG_" + to_string(localTime->tm_year + BASE_YEAR) + streamObj.str();
59 
60         std::ostringstream streamObj2;
61         // 设置宽度并使用 '0' 填充未使用的位置
62         streamObj2 << std::setw(PADDING_WIDTH) << std::setfill(FILL_CHAR) << to_string(localTime->tm_mon + MONTH_GAP) <<
63             to_string(localTime->tm_mday) << to_string(localTime->tm_hour) << to_string(localTime->tm_min) <<
64             to_string(localTime->tm_sec);
65         photoId_ = to_string(localTime->tm_year + BASE_YEAR) + streamObj2.str();
66     }
67 
GetTitle()68     std::string GetTitle() override
69     {
70         return title_;
71     }
72 
73     // 图片后缀,例如:jpg/png
GetExtension()74     std::string GetExtension() override
75     {
76         return "jpg";
77     }
78 
79     // 分段式图片id
GetPhotoId()80     std::string GetPhotoId() override
81     {
82         return photoId_;
83     }
84 
85     // 分段式拍照类型,相机框架写入,通过媒体库直接透传回相机框架
GetDeferredProcType()86     DeferredProcType GetDeferredProcType() override
87     {
88         return deferredProcType_;
89     }
90 
SetDeferredProcType(DeferredProcType deferredProcType)91     void SetDeferredProcType(DeferredProcType deferredProcType)
92     {
93         deferredProcType_ = deferredProcType;
94     }
95 
GetWidth()96     int32_t GetWidth() override
97     {
98         return WIDTH;
99     }
100 
GetHeight()101     int32_t GetHeight() override
102     {
103         return HEIGHT;
104     }
105 
GetFileDataAddr()106     void* GetFileDataAddr() override
107     {
108         return fileDataAddr_;
109     }
110 
SetFileDataAddr(void * addr)111     void SetFileDataAddr(void *addr)
112     {
113         fileDataAddr_ = addr;
114     }
115 
GetFileSize()116     size_t GetFileSize() override
117     {
118         return fileSize_;
119     }
120 
SetFileSize(int32_t size)121     void SetFileSize(int32_t size)
122     {
123         fileSize_ = size;
124     }
125 
Release()126     void Release() override
127     {
128     }
129 
130     // RGBA、JPG、YUV
GetFormat()131     PhotoFormat GetFormat() override
132     {
133         return this->photoFormat_;
134     }
135 
SetFormat(PhotoFormat format)136     void SetFormat(PhotoFormat format)
137     {
138         photoFormat_ = format;
139     }
140 
141     // 后续相机框架可能通过AddPhotoProxy传入高质量图
GetPhotoQuality()142     PhotoQuality GetPhotoQuality() override
143     {
144         return this->photoQuality_;
145     }
146 
SetPhotoQuality(PhotoQuality quality)147     void SetPhotoQuality(PhotoQuality quality)
148     {
149         photoQuality_ = quality;
150     }
151 
GetLatitude()152     double GetLatitude() override
153     {
154         return 0.0;
155     }
156 
GetLongitude()157     double GetLongitude() override
158     {
159         return 0.0;
160     }
161 
GetShootingMode()162     int32_t GetShootingMode() override
163     {
164         return 0;
165     }
166 
GetBurstKey()167     std::string GetBurstKey() override
168     {
169         return this->burstKey_;
170     }
171 
IsCoverPhoto()172     bool IsCoverPhoto() override
173     {
174         return this->isCoverPhoto_;
175     }
176 
GetCloudImageEnhanceFlag()177     uint32_t GetCloudImageEnhanceFlag() override
178     {
179         return 0;
180     }
181 
SetIsCoverPhoto(bool isCoverPhoto)182     void SetIsCoverPhoto(bool isCoverPhoto)
183     {
184         this->isCoverPhoto_ = isCoverPhoto;
185     }
186 
SetBurstKey(std::string burstKey)187     void SetBurstKey(std::string burstKey)
188     {
189         this->burstKey_ = burstKey;
190     }
191 private:
192     void *fileDataAddr_ = nullptr;
193     int32_t fileSize_ = 0;
194     std::string title_;
195     std::string photoId_;
196     PhotoFormat photoFormat_;
197     PhotoQuality photoQuality_;
198     DeferredProcType deferredProcType_ = DeferredProcType::OFFLINE;
199     std::string burstKey_;
200     bool isCoverPhoto_;
201 };
202 
203 const std::vector<CameraShotType> CameraShotType_FUZZER_LISTS = {
204     CameraShotType::IMAGE,
205     CameraShotType::VIDEO,
206     CameraShotType::MOVING_PHOTO,
207     CameraShotType::BURST,
208 };
209 
210 const std::vector<PhotoFormat> PhotoFormat_FUZZER_LISTS = {
211     PhotoFormat::RGBA,
212     PhotoFormat::JPG,
213     PhotoFormat::MP4,
214     PhotoFormat::HEIF,
215     PhotoFormat::YUV,
216 };
217 
218 const std::vector<PhotoQuality> PhotoQuality_FUZZER_LISTS = {
219     PhotoQuality::HIGH,
220     PhotoQuality::LOW,
221 };
222 
223 const std::vector<DeferredProcType> DeferredProcType_FUZZER_LISTS = {
224     DeferredProcType::BACKGROUND,
225     DeferredProcType::OFFLINE,
226 };
227 } // Media
228 } // OHOS
229 
230 #endif