1fa7767c5Sopenharmony_ci/* 2fa7767c5Sopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd. 3fa7767c5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fa7767c5Sopenharmony_ci * you may not use this file except in compliance with the License. 5fa7767c5Sopenharmony_ci * You may obtain a copy of the License at 6fa7767c5Sopenharmony_ci * 7fa7767c5Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fa7767c5Sopenharmony_ci * 9fa7767c5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fa7767c5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fa7767c5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fa7767c5Sopenharmony_ci * See the License for the specific language governing permissions and 13fa7767c5Sopenharmony_ci * limitations under the License. 14fa7767c5Sopenharmony_ci */ 15fa7767c5Sopenharmony_ci 16fa7767c5Sopenharmony_ci#include "avbuffer_utils.h" 17fa7767c5Sopenharmony_ci#include <unordered_map> 18fa7767c5Sopenharmony_ci#include "buffer/avbuffer.h" 19fa7767c5Sopenharmony_ci#include "surface_type.h" 20fa7767c5Sopenharmony_ci 21fa7767c5Sopenharmony_cinamespace { 22fa7767c5Sopenharmony_ciusing namespace OHOS; 23fa7767c5Sopenharmony_ciusing namespace OHOS::Media; 24fa7767c5Sopenharmony_cibool WriteSurfaceBufferConfig(MessageParcel &parcel, const BufferRequestConfig &config) 25fa7767c5Sopenharmony_ci{ 26fa7767c5Sopenharmony_ci#ifdef MEDIA_OHOS 27fa7767c5Sopenharmony_ci return parcel.WriteInt32(config.width) && parcel.WriteInt32(config.height) && 28fa7767c5Sopenharmony_ci parcel.WriteInt32(config.strideAlignment) && parcel.WriteInt32(config.format) && 29fa7767c5Sopenharmony_ci parcel.WriteUint64(config.usage) && parcel.WriteInt32(config.timeout) && 30fa7767c5Sopenharmony_ci parcel.WriteInt32(static_cast<GraphicColorGamut>(config.colorGamut)) && 31fa7767c5Sopenharmony_ci parcel.WriteInt32(static_cast<GraphicTransformType>(config.transform)); 32fa7767c5Sopenharmony_ci#else 33fa7767c5Sopenharmony_ci return false; 34fa7767c5Sopenharmony_ci#endif 35fa7767c5Sopenharmony_ci} 36fa7767c5Sopenharmony_ci 37fa7767c5Sopenharmony_civoid ReadSurfaceBufferConfig(MessageParcel &parcel, BufferRequestConfig &config) 38fa7767c5Sopenharmony_ci{ 39fa7767c5Sopenharmony_ci#ifdef MEDIA_OHOS 40fa7767c5Sopenharmony_ci config.width = parcel.ReadInt32(); 41fa7767c5Sopenharmony_ci config.height = parcel.ReadInt32(); 42fa7767c5Sopenharmony_ci config.strideAlignment = parcel.ReadInt32(); 43fa7767c5Sopenharmony_ci config.format = parcel.ReadInt32(); 44fa7767c5Sopenharmony_ci config.usage = parcel.ReadUint64(); 45fa7767c5Sopenharmony_ci config.timeout = parcel.ReadInt32(); 46fa7767c5Sopenharmony_ci config.colorGamut = static_cast<GraphicColorGamut>(parcel.ReadInt32()); 47fa7767c5Sopenharmony_ci config.transform = static_cast<GraphicTransformType>(parcel.ReadInt32()); 48fa7767c5Sopenharmony_ci#endif 49fa7767c5Sopenharmony_ci} 50fa7767c5Sopenharmony_ci} // namespace 51fa7767c5Sopenharmony_cinamespace OHOS { 52fa7767c5Sopenharmony_cinamespace Media { 53fa7767c5Sopenharmony_cibool MarshallingConfig(MessageParcel &parcel, const AVBufferConfig &config) 54fa7767c5Sopenharmony_ci{ 55fa7767c5Sopenharmony_ci#ifdef MEDIA_OHOS 56fa7767c5Sopenharmony_ci MessageParcel configParcel; 57fa7767c5Sopenharmony_ci bool ret = configParcel.WriteInt32(config.size) && configParcel.WriteInt32(config.align) && 58fa7767c5Sopenharmony_ci configParcel.WriteUint8(static_cast<uint8_t>(config.memoryType)) && 59fa7767c5Sopenharmony_ci configParcel.WriteUint8(static_cast<uint8_t>(config.memoryFlag)) && 60fa7767c5Sopenharmony_ci WriteSurfaceBufferConfig(configParcel, *(config.surfaceBufferConfig)) && 61fa7767c5Sopenharmony_ci configParcel.WriteInt32(config.capacity) && configParcel.WriteInt32(config.dmaFd); 62fa7767c5Sopenharmony_ci if (ret) { 63fa7767c5Sopenharmony_ci ret = ret && parcel.Append(configParcel); 64fa7767c5Sopenharmony_ci } 65fa7767c5Sopenharmony_ci return ret; 66fa7767c5Sopenharmony_ci#else 67fa7767c5Sopenharmony_ci return false; 68fa7767c5Sopenharmony_ci#endif 69fa7767c5Sopenharmony_ci} 70fa7767c5Sopenharmony_ci 71fa7767c5Sopenharmony_cibool UnmarshallingConfig(MessageParcel &parcel, AVBufferConfig &config) 72fa7767c5Sopenharmony_ci{ 73fa7767c5Sopenharmony_ci#ifdef MEDIA_OHOS 74fa7767c5Sopenharmony_ci config.size = static_cast<int32_t>(parcel.ReadUint32()); 75fa7767c5Sopenharmony_ci config.align = parcel.ReadInt32(); 76fa7767c5Sopenharmony_ci config.memoryType = static_cast<MemoryType>(parcel.ReadUint8()); 77fa7767c5Sopenharmony_ci config.memoryFlag = static_cast<MemoryFlag>(parcel.ReadUint8()); 78fa7767c5Sopenharmony_ci ReadSurfaceBufferConfig(parcel, *(config.surfaceBufferConfig)); 79fa7767c5Sopenharmony_ci config.capacity = parcel.ReadInt32(); 80fa7767c5Sopenharmony_ci config.dmaFd = parcel.ReadInt32(); 81fa7767c5Sopenharmony_ci#endif 82fa7767c5Sopenharmony_ci return true; 83fa7767c5Sopenharmony_ci} 84fa7767c5Sopenharmony_ci} // namespace Media 85fa7767c5Sopenharmony_ci} // namespace OHOS 86