1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "SurroundViewStream.h" 18 19 namespace android::hardware::automotive::sv::V1_0::implementation::fuzzer { 20 21 using std::lock_guard; 22 SurroundViewStream(sp<ISurroundViewSession> pSession)23SurroundViewStream::SurroundViewStream(sp<ISurroundViewSession> pSession) 24 : mSession(pSession), mReceiveFramesCount(0) {} 25 notify(SvEvent svEvent)26Return<void> SurroundViewStream::notify(SvEvent svEvent) { 27 lock_guard<mutex> lock(mLock); 28 switch (svEvent) { 29 case SvEvent::STREAM_STARTED: 30 case SvEvent::CONFIG_UPDATED: 31 case SvEvent::STREAM_STOPPED: 32 case SvEvent::FRAME_DROPPED: 33 case SvEvent::TIMEOUT: 34 mReceivedEvents.emplace_back(svEvent); 35 break; 36 default: 37 break; 38 } 39 40 return android::hardware::Void(); 41 } 42 receiveFrames(const SvFramesDesc & svFramesDesc)43Return<void> SurroundViewStream::receiveFrames(const SvFramesDesc& svFramesDesc) { 44 lock_guard<mutex> lock(mLock); 45 if ((mLastReceivedFrames.timestampNs >= svFramesDesc.timestampNs || 46 mLastReceivedFrames.sequenceId >= svFramesDesc.sequenceId) && 47 mReceiveFramesCount != 0) { 48 // The incoming frames are with invalid timestamp or sequenceId 49 mAllFramesValid = false; 50 } 51 52 for (int i = 0; i < svFramesDesc.svBuffers.size(); ++i) { 53 if (svFramesDesc.svBuffers[i].hardwareBuffer.nativeHandle == nullptr) { 54 mAllFramesValid = false; 55 // The incoming frames are with invalid nativeHandle 56 break; 57 } 58 } 59 60 ++mReceiveFramesCount; 61 62 // Store all the information except for the handle 63 mLastReceivedFrames.timestampNs = svFramesDesc.timestampNs; 64 mLastReceivedFrames.sequenceId = svFramesDesc.sequenceId; 65 mLastReceivedFrames.svBuffers.resize(svFramesDesc.svBuffers.size()); 66 for (int i = 0; i < svFramesDesc.svBuffers.size(); ++i) { 67 mLastReceivedFrames.svBuffers[i].viewId = svFramesDesc.svBuffers[i].viewId; 68 mLastReceivedFrames.svBuffers[i].hardwareBuffer.description = 69 svFramesDesc.svBuffers[i].hardwareBuffer.description; 70 } 71 72 return android::hardware::Void(); 73 } 74 } // namespace android::hardware::automotive::sv::V1_0::implementation::fuzzer 75