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 OH_VEF_UT_COMMON_DATA_H 17 #define OH_VEF_UT_COMMON_DATA_H 18 19 #include "gmock/gmock.h" 20 #include "gtest/gtest.h" 21 #include "video_editor_impl.h" 22 #include "codec/video_decoder_engine.h" 23 #include "codec/video_encoder_engine.h" 24 #include <fcntl.h> 25 #include <iostream> 26 27 namespace OHOS { 28 namespace Media { 29 30 constexpr const char* WATER_MARK_DESC = 31 "{\"imageEffect\":{\"filters\":[{\"name\":\"InplaceSticker\",\"values\":" 32 "{\"RESOURCE_DIRECTORY\":\"/sys_prod/resource/camera\"}}],\"name\":\"brandWaterMark\"}}"; 33 34 constexpr const char* SURFACE_VERTEX_SHADER_CODE = R"(uniform mat4 uTexMatrix; 35 attribute vec4 aPosition; 36 attribute vec4 aTextureCoord; 37 varying vec2 vTextureCoord; 38 void main() { 39 gl_Position = aPosition; 40 vTextureCoord = (uTexMatrix * vec4(aTextureCoord.xy, 0.0, 1.0)).xy; 41 } 42 )"; 43 44 constexpr const char* SURFACE_ROTATE_FRAGMENT_SHADER_CODE = R"( 45 precision mediump float; 46 varying vec2 vTextureCoord; 47 uniform sampler2D sTexture; 48 void main() { 49 gl_FragColor = texture2D(sTexture, vTextureCoord); 50 } 51 )"; 52 53 class CompositionCallbackTesterImpl : public CompositionCallback { 54 public: 55 CompositionCallbackTesterImpl() = default; 56 virtual ~CompositionCallbackTesterImpl() = default; onResult(VEFResult result,VEFError errorCode)57 void onResult(VEFResult result, VEFError errorCode) override 58 { 59 result_ = result; 60 } onProgress(uint32_t progress)61 void onProgress(uint32_t progress) override 62 { 63 progress_ = progress; 64 } 65 private: 66 VEFResult result_ = VEFResult::UNKNOWN; 67 uint32_t progress_ = 0; 68 }; 69 70 class VideoDecodeCallbackTester : public VideoDecodeCallback { 71 public: 72 VideoDecodeCallbackTester() = default; 73 virtual ~VideoDecodeCallbackTester() = default; OnDecodeFrame(uint64_t pts)74 void OnDecodeFrame(uint64_t pts) override 75 { 76 pts_ = pts; 77 }; OnDecodeResult(CodecResult result)78 void OnDecodeResult(CodecResult result) override 79 { 80 result_ = result; 81 }; 82 83 uint64_t pts_ { 0 }; 84 CodecResult result_ { CodecResult::FAILED }; 85 }; 86 87 class VideoEncodeCallbackTester : public VideoEncodeCallback { 88 public: 89 VideoEncodeCallbackTester() = default; 90 virtual ~VideoEncodeCallbackTester() = default; OnEncodeFrame(uint64_t pts)91 void OnEncodeFrame(uint64_t pts) override 92 { 93 pts_ = pts; 94 }; OnEncodeResult(CodecResult result)95 void OnEncodeResult(CodecResult result) override 96 { 97 result_ = result; 98 }; 99 100 uint64_t pts_ { 0 }; 101 CodecResult result_ { CodecResult::FAILED }; 102 }; 103 104 class VideoResource { 105 public: ~VideoResource()106 virtual ~VideoResource() {}; instance()107 static VideoResource& instance() 108 { 109 static VideoResource instance; 110 return instance; 111 } 112 getFileResource(std::string & fileName)113 int32_t getFileResource(std::string& fileName) 114 { 115 const std::string videoFilePath = "/data/test/" + fileName; 116 int32_t srcFd = open(videoFilePath.c_str(), O_RDWR); 117 if (srcFd <= 0) { 118 std::cout << "Open file failed" << std::endl; 119 return -1; 120 } 121 return srcFd; 122 } 123 getEncodeParam(int32_t & srcFd,std::shared_ptr<IVideoDecoderEngine> decoderEngine)124 VideoEncodeParam getEncodeParam(int32_t& srcFd, std::shared_ptr<IVideoDecoderEngine> decoderEngine) 125 { 126 VideoEncodeParam enCodeParam; 127 if (decoderEngine == nullptr) { 128 std::cout << "decoderEngine is nullptr, get enCodeParam failed" << std::endl; 129 return enCodeParam; 130 } 131 enCodeParam.videoTrunkFormat = decoderEngine->GetVideoFormat(); 132 enCodeParam.audioTrunkFormat = decoderEngine->GetAudioFormat(); 133 enCodeParam.muxerParam.targetFileFd = srcFd; 134 enCodeParam.muxerParam.avOutputFormat = AV_OUTPUT_FORMAT_MPEG_4; 135 enCodeParam.muxerParam.rotation = decoderEngine->GetRotation(); 136 return enCodeParam; 137 } 138 139 private: VideoResource()140 VideoResource() {}; 141 }; 142 } // namespace Media 143 } // namespace OHOS 144 145 #endif // OH_VEF_UT_COMMON_DATA_H