1 /*
2 * Copyright (C) 2023 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 "avbuffer_inner_mock.h"
17 #include "avformat_inner_mock.h"
18 #include "meta/meta.h"
19 #include "native_averrors.h"
20 #include "securec.h"
21 #include "unittest_log.h"
22
23 namespace OHOS {
24 namespace Media {
GetAddr()25 uint8_t *AVBufferInnerMock::GetAddr()
26 {
27 UNITTEST_CHECK_AND_RETURN_RET_LOG(buffer_ != nullptr, nullptr, "buffer_ is nullptr!");
28 UNITTEST_CHECK_AND_RETURN_RET_LOG(buffer_->memory_ != nullptr, nullptr, "buffer_->memory_ is nullptr!");
29 return buffer_->memory_->GetAddr();
30 }
31
GetCapacity()32 int32_t AVBufferInnerMock::GetCapacity()
33 {
34 UNITTEST_CHECK_AND_RETURN_RET_LOG(buffer_ != nullptr, -1, "buffer_ is nullptr!");
35 UNITTEST_CHECK_AND_RETURN_RET_LOG(buffer_->memory_ != nullptr, -1, "buffer_->memory_ is nullptr!");
36 return buffer_->memory_->GetCapacity();
37 }
38
GetBufferAttr(OH_AVCodecBufferAttr & attr)39 int32_t AVBufferInnerMock::GetBufferAttr(OH_AVCodecBufferAttr &attr)
40 {
41 UNITTEST_CHECK_AND_RETURN_RET_LOG(buffer_ != nullptr, static_cast<int32_t>(Status::ERROR_UNKNOWN),
42 "buffer_ is nullptr!");
43 attr.pts = buffer_->pts_;
44 attr.offset = buffer_->memory_->GetOffset();
45 attr.size = buffer_->memory_->GetSize();
46 attr.flags = static_cast<uint32_t>(buffer_->flag_);
47 return static_cast<int32_t>(Status::OK);
48 }
49
SetBufferAttr(const OH_AVCodecBufferAttr & attr)50 int32_t AVBufferInnerMock::SetBufferAttr(const OH_AVCodecBufferAttr &attr)
51 {
52 UNITTEST_CHECK_AND_RETURN_RET_LOG(buffer_ != nullptr, static_cast<int32_t>(Status::ERROR_UNKNOWN),
53 "buffer_ is nullptr!");
54 buffer_->pts_ = attr.pts;
55 buffer_->memory_->SetOffset(attr.offset);
56 buffer_->flag_ = attr.flags;
57 return static_cast<int32_t>(buffer_->memory_->SetSize(attr.size));
58 }
59
GetParameter()60 std::shared_ptr<FormatMock> AVBufferInnerMock::GetParameter()
61 {
62 UNITTEST_CHECK_AND_RETURN_RET_LOG(buffer_ != nullptr, nullptr, "buffer_ is nullptr!");
63 Format format;
64 format.SetMeta(buffer_->meta_);
65 auto formatMock = std::make_shared<AVFormatInnerMock>(format);
66 return formatMock;
67 }
68
SetParameter(const std::shared_ptr<FormatMock> & format)69 int32_t AVBufferInnerMock::SetParameter(const std::shared_ptr<FormatMock> &format)
70 {
71 UNITTEST_CHECK_AND_RETURN_RET_LOG(buffer_ != nullptr, static_cast<int32_t>(Status::ERROR_UNKNOWN),
72 "buffer_ is nullptr!");
73 auto &formatAVCodec = std::static_pointer_cast<AVFormatInnerMock>(format)->GetFormat();
74 *(buffer_->meta_) = *(formatAVCodec.GetMeta());
75 return static_cast<int32_t>(Status::OK);
76 }
77
Destroy()78 int32_t AVBufferInnerMock::Destroy()
79 {
80 buffer_ = nullptr;
81 return static_cast<int32_t>(Status::OK);
82 }
83
GetNativeBuffer()84 sptr<SurfaceBuffer> AVBufferInnerMock::GetNativeBuffer()
85 {
86 UNITTEST_CHECK_AND_RETURN_RET_LOG(buffer_ != nullptr, nullptr, "buffer_ is nullptr!");
87 UNITTEST_CHECK_AND_RETURN_RET_LOG(buffer_->memory_ != nullptr, nullptr, "buffer_->memory_ is nullptr!");
88 return buffer_->memory_->GetSurfaceBuffer();
89 }
90
GetAVBuffer()91 std::shared_ptr<AVBuffer> &AVBufferInnerMock::GetAVBuffer()
92 {
93 return buffer_;
94 }
95 } // namespace Media
96 } // namespace OHOS