Android 13 - Media框架(22)- ACodecBufferChannel

这一节我们将了解 ACodecBufferChannel 中的 buffer 传输机制

status_t ACodecBufferChannel::queueInputBuffer(const sp<MediaCodecBuffer> &buffer) {std::shared_ptr<const std::vector<const BufferInfo>> array(std::atomic_load(&mInputBuffers));BufferInfoIterator it = findClientBuffer(array, buffer);if (it == array->end()) {return -ENOENT;}if (it->mClientBuffer != it->mCodecBuffer) {// Copy metadata from client to codec buffer.it->mCodecBuffer->meta()->clear();int64_t timeUs;CHECK(it->mClientBuffer->meta()->findInt64("timeUs", &timeUs));it->mCodecBuffer->meta()->setInt64("timeUs", timeUs);int32_t eos;if (it->mClientBuffer->meta()->findInt32("eos", &eos)) {it->mCodecBuffer->meta()->setInt32("eos", eos);}int32_t csd;if (it->mClientBuffer->meta()->findInt32("csd", &csd)) {it->mCodecBuffer->meta()->setInt32("csd", csd);}}ALOGV("queueInputBuffer #%d", it->mBufferId);sp<AMessage> msg = mInputBufferFilled->dup();msg->setObject("buffer", it->mCodecBuffer);msg->setInt32("buffer-id", it->mBufferId);msg->post();return OK;
}status_t ACodecBufferChannel::queueSecureInputBuffer(const sp<MediaCodecBuffer> &buffer, bool secure, const uint8_t *key,const uint8_t *iv, CryptoPlugin::Mode mode, CryptoPlugin::Pattern pattern,const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,AString *errorDetailMsg) {if (!hasCryptoOrDescrambler() || mDealer == nullptr) {return -ENOSYS;}std::shared_ptr<const std::vector<const BufferInfo>> array(std::atomic_load(&mInputBuffers));BufferInfoIterator it = findClientBuffer(array, buffer);if (it == array->end()) {return -ENOENT;}native_handle_t *secureHandle = NULL;if (secure) {sp<SecureBuffer> secureData =static_cast<SecureBuffer *>(it->mCodecBuffer.get());if (secureData->getDestinationType() != ICrypto::kDestinationTypeNativeHandle) {return BAD_VALUE;}secureHandle = static_cast<native_handle_t *>(secureData->getDestinationPointer());}ssize_t result = -1;ssize_t codecDataOffset = 0;if (numSubSamples == 1&& subSamples[0].mNumBytesOfClearData == 0&& subSamples[0].mNumBytesOfEncryptedData == 0) {// We don't need to go through crypto or descrambler if the input is empty.result = 0;} else if (mCrypto != NULL) {hardware::drm::V1_0::DestinationBuffer destination;if (secure) {destination.type = DrmBufferType::NATIVE_HANDLE;destination.secureMemory = hidl_handle(secureHandle);} else {destination.type = DrmBufferType::SHARED_MEMORY;IMemoryToSharedBuffer(mDecryptDestination, mHeapSeqNum, &destination.nonsecureMemory);}hardware::drm::V1_0::SharedBuffer source;IMemoryToSharedBuffer(it->mSharedEncryptedBuffer, mHeapSeqNum, &source);result = mCrypto->decrypt(key, iv, mode, pattern,source, it->mClientBuffer->offset(),subSamples, numSubSamples, destination, errorDetailMsg);if (result < 0) {return result;}if (destination.type == DrmBufferType::SHARED_MEMORY) {memcpy(it->mCodecBuffer->base(), mDecryptDestination->unsecurePointer(), result);}} else {// Here we cast CryptoPlugin::SubSample to hardware::cas::native::V1_0::SubSample// directly, the structure definitions should match as checked in DescramblerImpl.cpp.hidl_vec<SubSample> hidlSubSamples;hidlSubSamples.setToExternal((SubSample *)subSamples, numSubSamples, false /*own*/);ssize_t offset;size_t size;it->mSharedEncryptedBuffer->getMemory(&offset, &size);hardware::cas::native::V1_0::SharedBuffer srcBuffer = {.heapBase = *mHidlMemory,.offset = (uint64_t) offset,.size = size};DestinationBuffer dstBuffer;if (secure) {dstBuffer.type = BufferType::NATIVE_HANDLE;dstBuffer.secureMemory = hidl_handle(secureHandle);} else {dstBuffer.type = BufferType::SHARED_MEMORY;dstBuffer.nonsecureMemory = srcBuffer;}Status status = Status::OK;hidl_string detailedError;ScramblingControl sctrl = ScramblingControl::UNSCRAMBLED;if (key != NULL) {sctrl = (ScramblingControl)key[0];// Adjust for the PES offsetcodecDataOffset = key[2] | (key[3] << 8);}auto returnVoid = mDescrambler->descramble(sctrl,hidlSubSamples,srcBuffer,0,dstBuffer,0,[&status, &result, &detailedError] (Status _status, uint32_t _bytesWritten,const hidl_string& _detailedError) {status = _status;result = (ssize_t)_bytesWritten;detailedError = _detailedError;});if (!returnVoid.isOk() || status != Status::OK || result < 0) {ALOGE("descramble failed, trans=%s, status=%d, result=%zd",returnVoid.description().c_str(), status, result);return UNKNOWN_ERROR;}if (result < codecDataOffset) {ALOGD("invalid codec data offset: %zd, result %zd", codecDataOffset, result);return BAD_VALUE;}ALOGV("descramble succeeded, %zd bytes", result);if (dstBuffer.type == BufferType::SHARED_MEMORY) {memcpy(it->mCodecBuffer->base(),(uint8_t*)it->mSharedEncryptedBuffer->unsecurePointer(),result);}}it->mCodecBuffer->setRange(codecDataOffset, result - codecDataOffset);// Copy metadata from client to codec buffer.it->mCodecBuffer->meta()->clear();int64_t timeUs;CHECK(it->mClientBuffer->meta()->findInt64("timeUs", &timeUs));it->mCodecBuffer->meta()->setInt64("timeUs", timeUs);int32_t eos;if (it->mClientBuffer->meta()->findInt32("eos", &eos)) {it->mCodecBuffer->meta()->setInt32("eos", eos);}int32_t csd;if (it->mClientBuffer->meta()->findInt32("csd", &csd)) {it->mCodecBuffer->meta()->setInt32("csd", csd);}ALOGV("queueSecureInputBuffer #%d", it->mBufferId);sp<AMessage> msg = mInputBufferFilled->dup();msg->setObject("buffer", it->mCodecBuffer);msg->setInt32("buffer-id", it->mBufferId);msg->post();return OK;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/192852.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Pikachu(三)

RCE(remote command/code execute)概述 RCE漏洞&#xff0c;可以让攻击者直接向后台服务器远程注入操作系统命令或者代码&#xff0c;从而控制后台系统。 远程系统命令执行 一般出现这种漏洞&#xff0c;是因为应用系统从设计上需要给用户提供指定的远程命令操作的接口 比如我…

flink源码分析之功能组件(四)-slot管理组件I

简介 本系列是flink源码分析的第二个系列&#xff0c;上一个《flink源码分析之集群与资源》分析集群与资源&#xff0c;本系列分析功能组件&#xff0c;kubeclient&#xff0c;rpc&#xff0c;心跳&#xff0c;高可用&#xff0c;slotpool&#xff0c;rest&#xff0c;metrics&…

docker+jmeter+influxdb+granfana

centos7国内阿里源安装docker 1、安装必要的系统工具 sudo yum install -y yum-utils device-mapper-persistent-data lvm2 2添加官方仓库 sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.reposudo sed -i sdownload.doc…

Knowledge Review(CVPR 2021)论文解析

paper&#xff1a;Distilling Knowledge via Knowledge Review official implementation&#xff1a;https://github.com/dvlab-research/ReviewKD 前言 识蒸馏将知识从教师网络转移到学生网络&#xff0c;可以提高学生网络的性能&#xff0c;作为一种“模型压缩”的方法被…

np.array无法直接用matplotlib画图,因为需要借用np.squeeze先转化

文章目录 前言一、使用步骤1.没使用np.squeeze转化2.使用np.squeeze转化 前言 实际工作中&#xff0c;时而难免会遇见np.array无法直接用matplotlib画图的情况&#xff0c;这个时候&#xff0c;是因为在画图之前少了一个步骤&#xff0c;需要先借用np.squeeze先转化 一、使用步…

如何学习 Spring ?学习 Spring 前要学习什么?

整理了一下Spring的核心概念BeanDefinitionBeanDefinition表示Bean定义&#xff0c;BeanDefinition中存在很多属性用来描述一个Bean的特点。比如&#xff1a;class&#xff0c;表示Bean类型scope&#xff0c;表示Bean作用域&#xff0c;单例或原型等lazyInit&#xff1a;表示Be…

Matlab 在一个文件中调用另一个文件中的函数

文章目录 Part.I IntroductionPart.II 方法Chap.I A 文件中只有一个函数Chap.II A 文件中有多个函数 Part.I Introduction 本文介绍一下在脚本文件 B 中调用文件 A 中的函数的方法。 Part.II 方法 目的&#xff1a;在文件B.m调用A.m中的函数 默认两个文件在一个文件夹下&…

Python中查看对象的所有属性和方法以及查看属性是否存在

Python中查看对象的所有属性和方法以及查看属性是否存在 作者&#xff1a;爱编程的小金毛球球 日期&#xff1a;2023年12月3日 Python提供许多的内置函数和模块来帮助开发人员查看对象的所有属性&#xff0c;例如&#xff1a;dir()&#xff0c;vars()&#xff0c;__dict__等。 …

深度学习好文记录,反复学习

recent update time&#xff1a;2023.12.2 深度学习入门 - 知乎、这本书也很好&#xff0c;作者写的专栏不错。 机器学习&#xff0c;深度学习一些好文_一只菜得不行的鸟的博客-CSDN博客 卷积神经网络学习路线&#xff08;五&#xff09;| 卷积神经网络参数设置&#xff0c;提…

Python 错误 TypeError: __str__ Returned Non-String but Printing Output

本文旨在解决当我们尝试打印字符串而不是在函数中使用 return 语句时出现的问题。 Python 返回非字符串错误但打印输出 以下代码显示了 TypeError: str returned non-string&#xff0c;但它仍然打印输出。 示例代码&#xff1a; class xy:def __init__(self, x, y):self.x …

华为OD机试真题-靠谱的车-2023年OD统一考试(C卷)

题目描述: 程序员小明打了一辆出租车去上班。出于职业敏感,他注意到这辆出租车的计费表有点问题,总是偏大。 出租车司机解释说他不喜欢数字4,所以改装了计费表,任何数字位置遇到数字4就直接跳过,其余功能都正常。 比如: 1. 23再多一块钱就变为25; 2. 39再多一块…

力扣611题 有效三角形的个数 双指针算法

611. 有效三角形的个数 给定一个包含非负整数的数组 nums &#xff0c;返回其中可以组成三角形三条边的三元组个数。 示例 1: 输⼊: nums [2,2,3,4] 输出: 3 解释:有效的组合是: 2,3,4 (使⽤第⼀个 2) 2,3,4 (使⽤第⼆个 2) 2,2,3 ⽰例 2: 输⼊: nums [4,2,3,4] 输出: 4 解…

Topic和Partition

作用 主题作为消息的一级分类, 分区是对二级分类。分区是Kafka可伸缩性和水平扩展的关键, 也是多副本机制保证可用性的基础。分区可以有一到多个副本, 每个副本对应1个日志文件, 每个日志文件对应1到多个日志分段。每个日志分段又可以细分为日志文件, 索引文件和快照文件。 创…

CAP概念和三种情况、Redis和分布式事务的权衡

借鉴&#xff1a;https://cloud.tencent.com/developer/article/1840206 https://www.cnblogs.com/huanghuanghui/p/9592016.html 一&#xff1a;CAP概念和三种情况 1.概念&#xff1a; C全称Consistency&#xff08;一致性&#xff09;&#xff1a;这个表示所有节点返回的数…

轻易云AI:引领企业数智化转型提升企业AI效率

近期&#xff0c;轻易云AI与汤臣倍健的合作引起了业界的广泛关注。通过这一合作&#xff0c;轻易云AI不仅成功打造了集团小汤AI助手这一标志性的企业智能助手&#xff0c;更重要的是&#xff0c;这一合作凸显了轻易云AI作为专业AI应用集成专家的核心能力。轻易云AI已成功集成了…

Spring之RestTemplate详解

Spring之RestTemplate详解 1 RestTemplate1.1 引言1.2 环境配置1.2.1 非Spring环境下使用RestTemplate1.2.2 Spring环境下使用 RestTemplate1.2.3 Spring环境下增加线程号 1.3 API 实践1.3.1 GET请求1.3.1.1 不带参请求1.3.1.2 带参的get请求(使用占位符号传参)1.3.1.3 带参的g…

创建内存泄漏(js的问题)

如果没有有意识地编写代码来避免内存泄漏&#xff0c;那么内存泄漏几乎是不可避免的JavaScript问题。它们的发生方式有很多种&#xff0c;所以我们只重点介绍几种比较常见的情况。 内存泄漏实例1:对不存在的对象的悬空引用 考虑以下代码: var theThing null; var replaceTh…

Redis7--基础篇4(Redis事务)

Redis事务是什么 可以一次执行多个命令&#xff0c;本质是一组命令的集合&#xff0c;一个事务中的所有命令都会序列化&#xff0c;按顺序串行&#xff0c;而不会被其他命令插入。 其作用就是在一个队列中&#xff0c;一次性、顺序、排他的执行一系列命令。 Redis事务 VS 数据…

【每日一题】拼车+【差分数组】

文章目录 Tag题目来源解题思路方法一&#xff1a;差分 写在最后 Tag 【差分数组】【数组】【2023-12-02】 题目来源 1094. 拼车 解题思路 本题朴素的解题思路是统计题目中提到的每一个站点的车上人数&#xff0c;如果某个站点的车上人数大于车上的座位数直接返回 false&…