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 #ifndef AVBUFFER_UTILS_H
17 #define AVBUFFER_UTILS_H
18 
19 #include <unistd.h>
20 #include "message_parcel.h"
21 #include "buffer/avbuffer_common.h"
22 
23 
24 namespace OHOS {
25 namespace Media {
26 [[maybe_unused]] bool MarshallingConfig(MessageParcel &parcel, const AVBufferConfig &config);
27 [[maybe_unused]] bool UnmarshallingConfig(MessageParcel &parcel, AVBufferConfig &config);
28 
29 template <typename T>
30 using MakeUnsigned = typename std::make_unsigned<T>::type;
31 template <typename T, typename U>
AlignUp(T num,U alignment)32 [[maybe_unused]] constexpr T AlignUp(T num, U alignment)
33 {
34     return (alignment > 0) ? (static_cast<uint64_t>((num + static_cast<MakeUnsigned<T>>(alignment) - 1)) &
35                               static_cast<uint64_t>((~(static_cast<MakeUnsigned<T>>(alignment) - 1))))
36                            : num;
37 }
38 } // namespace Media
39 } // namespace OHOS
40 #endif // AVBUFFER_UTILS_H