1 /*
2 * Copyright (C) 2022 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 #include "avformat_native_mock.h"
17 #include "securec.h"
18
19 namespace OHOS {
20 namespace Media {
PutIntValue(const std::string_view & key,int32_t value)21 bool AVFormatNativeMock::PutIntValue(const std::string_view &key, int32_t value)
22 {
23 return format_.PutIntValue(key, value);
24 }
25
GetIntValue(const std::string_view & key,int32_t & value)26 bool AVFormatNativeMock::GetIntValue(const std::string_view &key, int32_t &value)
27 {
28 return format_.GetIntValue(key, value);
29 }
30
PutStringValue(const std::string_view & key,const std::string_view & value)31 bool AVFormatNativeMock::PutStringValue(const std::string_view &key, const std::string_view &value)
32 {
33 return format_.PutStringValue(key, value);
34 }
35
GetStringValue(const std::string_view & key,std::string & value)36 bool AVFormatNativeMock::GetStringValue(const std::string_view &key, std::string &value)
37 {
38 return format_.GetStringValue(key, value);
39 }
40
Destroy()41 void AVFormatNativeMock::Destroy()
42 {
43 if (dumpInfo_ != nullptr) {
44 free(dumpInfo_);
45 dumpInfo_ = nullptr;
46 }
47 return;
48 }
49
GetFormat()50 Format &AVFormatNativeMock::GetFormat()
51 {
52 return format_;
53 }
54
PutLongValue(const std::string_view & key,int64_t value)55 bool AVFormatNativeMock::PutLongValue(const std::string_view &key, int64_t value)
56 {
57 return format_.PutLongValue(key, value);
58 }
59
GetLongValue(const std::string_view & key,int64_t & value)60 bool AVFormatNativeMock::GetLongValue(const std::string_view &key, int64_t &value)
61 {
62 return format_.GetLongValue(key, value);
63 }
64
PutFloatValue(const std::string_view & key,float value)65 bool AVFormatNativeMock::PutFloatValue(const std::string_view &key, float value)
66 {
67 return format_.PutFloatValue(key, value);
68 }
69
GetFloatValue(const std::string_view & key,float & value)70 bool AVFormatNativeMock::GetFloatValue(const std::string_view &key, float &value)
71 {
72 return format_.GetFloatValue(key, value);
73 }
74
PutDoubleValue(const std::string_view & key,double value)75 bool AVFormatNativeMock::PutDoubleValue(const std::string_view &key, double value)
76 {
77 return format_.PutDoubleValue(key, value);
78 }
79
GetDoubleValue(const std::string_view & key,double & value)80 bool AVFormatNativeMock::GetDoubleValue(const std::string_view &key, double &value)
81 {
82 return format_.GetDoubleValue(key, value);
83 }
84
GetBuffer(const std::string_view & key,uint8_t ** addr,size_t & size)85 bool AVFormatNativeMock::GetBuffer(const std::string_view &key, uint8_t **addr, size_t &size)
86 {
87 return format_.GetBuffer(key, addr, size);
88 }
89
PutBuffer(const std::string_view & key,const uint8_t * addr,size_t size)90 bool AVFormatNativeMock::PutBuffer(const std::string_view &key, const uint8_t *addr, size_t size)
91 {
92 return format_.PutBuffer(key, addr, size);
93 }
94
DumpInfo()95 const char *AVFormatNativeMock::DumpInfo()
96 {
97 if (dumpInfo_ != nullptr) {
98 free(dumpInfo_);
99 dumpInfo_ = nullptr;
100 }
101 std::string info = format_.Stringify();
102 if (info.empty()) {
103 return nullptr;
104 }
105 constexpr uint32_t maxDumpLength = 1024;
106 uint32_t bufLength = info.size() > maxDumpLength ? maxDumpLength : info.size();
107 dumpInfo_ = static_cast<char *>(malloc((bufLength + 1) * sizeof(char)));
108 if (dumpInfo_ == nullptr) {
109 return nullptr;
110 }
111 if (strcpy_s(dumpInfo_, bufLength + 1, info.c_str()) != 0) {
112 free(dumpInfo_);
113 dumpInfo_ = nullptr;
114 }
115 return dumpInfo_;
116 }
117 } // Media
118 } // OHOS