1 // Copyright 2021 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 //#define LOG_NDEBUG 0 6 #define LOG_TAG "DmabufHelpers" 7 8 #include <v4l2_codec2/plugin_store/DmabufHelpers.h> 9 10 #include <sys/stat.h> 11 #include <sys/types.h> 12 #include <unistd.h> 13 14 #include <log/log.h> 15 16 namespace android { 17 getDmabufId(int dmabufFd)18std::optional<unique_id_t> getDmabufId(int dmabufFd) { 19 struct stat sb {}; 20 if (fstat(dmabufFd, &sb) != 0) { 21 return std::nullopt; 22 } 23 24 if (sb.st_size == 0) { 25 ALOGE("Dma-buf size is 0. Please check your kernel is v5.3+"); 26 return std::nullopt; 27 } 28 29 return static_cast<unique_id_t>(sb.st_ino); 30 } 31 32 } // namespace android 33