• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 "surface_buffer_info.h"
17 
18 #include "message_parcel.h"
19 
20 #include "vpe_log.h"
21 
22 using namespace OHOS;
23 using namespace OHOS::Media::VideoProcessingEngine;
24 
rectStr() const25 std::string SurfaceBufferInfo::rectStr() const
26 {
27     return surfacebuffer == nullptr ? "image=null" :
28         std::to_string(surfacebuffer->GetWidth()) + "(" + std::to_string(surfacebuffer->GetStride()) + ")x" +
29         std::to_string(surfacebuffer->GetHeight());
30 }
31 
str() const32 std::string SurfaceBufferInfo::str() const
33 {
34     return "buffer:{ id=" + std::to_string(videoInfo.videoIndex) + " idx=" + std::to_string(videoInfo.frameIndex) +
35         " " + rectStr() + " }";
36 }
37 
CopyInfo(const SurfaceBufferInfo & input)38 void SurfaceBufferInfo::CopyInfo(const SurfaceBufferInfo& input)
39 {
40     // Copy information from input except SurfaceBuffer
41     videoInfo = input.videoInfo;
42 }
43 
ReadFromParcel(Parcel & parcel)44 bool SurfaceBufferInfo::ReadFromParcel(Parcel &parcel)
45 {
46     CHECK_AND_RETURN_RET_LOG(surfacebuffer != nullptr, false, "surfacebuffer is null!");
47     return parcel.ReadUint64(videoInfo.videoIndex) && parcel.ReadUint64(videoInfo.frameIndex) &&
48         surfacebuffer->ReadFromMessageParcel(*static_cast<MessageParcel*>(&parcel)) == GSERROR_OK;
49 }
50 
Marshalling(Parcel & parcel) const51 bool SurfaceBufferInfo::Marshalling(Parcel &parcel) const
52 {
53     CHECK_AND_RETURN_RET_LOG(surfacebuffer != nullptr, false, "surfacebuffer is null!");
54     return parcel.WriteUint64(videoInfo.videoIndex) && parcel.WriteUint64(videoInfo.frameIndex) &&
55         surfacebuffer->WriteToMessageParcel(*static_cast<MessageParcel*>(&parcel)) == GSERROR_OK;
56 }
57 
Unmarshalling(Parcel & parcel)58 SurfaceBufferInfo *SurfaceBufferInfo::Unmarshalling(Parcel &parcel)
59 {
60     SurfaceBufferInfo *info = new (std::nothrow) SurfaceBufferInfo();
61     if (info == nullptr) [[unlikely]] {
62         return nullptr;
63     }
64     info->surfacebuffer = SurfaceBuffer::Create();
65     if (!info->ReadFromParcel(parcel)) [[unlikely]] {
66         delete info;
67         return nullptr;
68     }
69 
70     return info;
71 }