1 /* 2 * Copyright (c) 2025 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 DEMUXER_PLUGIN_FLV_TEST_H 17 #define DEMUXER_PLUGIN_FLV_TEST_H 18 19 #include <cstddef> 20 #include <cstdint> 21 #include <memory> 22 #include <string> 23 #include "ffmpeg_demuxer_plugin.h" 24 25 #define DEFAULT_BUFFSIZE (3840 * 2160 * 3) 26 using MediaAVBuffer = OHOS::Media::AVBuffer; 27 using MediaInfo = OHOS::Media::Plugins::MediaInfo; 28 namespace OHOS { 29 namespace Media { 30 struct AVBufferWrapper { 31 std::shared_ptr<MediaAVBuffer> mediaAVBuffer; AVBufferWrapperAVBufferWrapper32 explicit AVBufferWrapper(uint32_t size) 33 { 34 if (size == 0) { 35 size = DEFAULT_BUFFSIZE; 36 } 37 ptr = std::make_unique<uint8_t []>(size); 38 mediaAVBuffer = MediaAVBuffer::CreateAVBuffer(ptr.get(), size, 0); 39 } 40 private: 41 AVBufferWrapper() = delete; 42 std::unique_ptr<uint8_t []> ptr; 43 }; 44 45 class DemuxerPluginFlvTest { 46 public: 47 DemuxerPluginFlvTest(); 48 ~DemuxerPluginFlvTest(); 49 bool InitWithFlvData(const uint8_t* data, size_t size); 50 void RunDemuxerInterfaceFuzz(); 51 private: 52 void PrepareDemuxerPlugin(MediaInfo& mediaInfo, size_t& bufferSize, AVBufferWrapper& buffer); 53 void OperateDemuxerPlugin(MediaInfo& mediaInfo, size_t bufferSize, AVBufferWrapper& buffer); 54 55 int32_t fd_ = -1; 56 size_t dataSize_ = 0; 57 std::shared_ptr<Plugins::Ffmpeg::FFmpegDemuxerPlugin> demuxerPlugin_ = nullptr; 58 }; 59 60 } // namespace Media 61 } // namespace OHOS 62 63 #endif // DEMUXER_PLUGIN_FLV_TEST_H