h.264硬件解码
// H264HWDecoder.m
// H264EncoderDecoder
//
// Created by lujunjie on 2016/11/28.
// Copyright © 2016年 陆俊杰. All rights reserved.
// #import "H264HWDecoder.h" @implementation H264HWDecoder - (void)dealloc
{
if(self.decompressionSession != NULL){
VTDecompressionSessionInvalidate(self.decompressionSession);
CFRelease(self.decompressionSession);
self.decompressionSession=NULL;
}
}
- (int)DecodeH264Frames:(unsigned char *)frame withLength:(int)frameSize
{
OSStatus status = -; uint8_t *data = NULL;
uint8_t *pps = NULL;
uint8_t *sps = NULL; int startCodeIndex = ;
int secondStartCodeIndex = ;
int thirdStartCodeIndex = ; long blockLength = ; CMSampleBufferRef sampleBuffer = NULL;
CMBlockBufferRef blockBuffer = NULL; int nalu_type = (frame[startCodeIndex + ] & 0x1F); if (nalu_type != && _formatDesc == NULL)
{
NSLog(@"Video error: Frame is not an I Frame and format description is null");
return -;
} if (nalu_type == )
{
// NSLog(@"=================================================");
// for (int i = 0; i<frameSize; i++) {
// printf(" %x",frame[i]);
// }
for (int i = startCodeIndex + ; i < startCodeIndex + ; i++)
{
if (frame[i] == 0x00 && frame[i+] == 0x00 && frame[i+] == 0x00 && frame[i+] == 0x01)
{
secondStartCodeIndex = i;
_spsSize = secondStartCodeIndex;
break;
}
}
nalu_type = (frame[secondStartCodeIndex + ] & 0x1F); } if(nalu_type == )
{ for (int i = _spsSize + ; i < _spsSize + ; i++)
{
if (frame[i] == 0x00 && frame[i+] == 0x00 && frame[i+] == 0x00 && frame[i+] == 0x01)
{
thirdStartCodeIndex = i;
_ppsSize = thirdStartCodeIndex - _spsSize;
break;
}
} sps = malloc(_spsSize - );
pps = malloc(_ppsSize - ); memcpy (sps, &frame[], _spsSize-);
memcpy (pps, &frame[_spsSize+], _ppsSize-); uint8_t* parameterSetPointers[] = {sps, pps};
size_t parameterSetSizes[] = {_spsSize-, _ppsSize-}; status = CMVideoFormatDescriptionCreateFromH264ParameterSets(kCFAllocatorDefault, ,
(const uint8_t *const*)parameterSetPointers,
parameterSetSizes, ,
&_formatDesc); if(status != noErr){
NSLog(@"MVideoFormatDescriptionCreateFromH264ParameterSets ERROR type: %d", (int)status);
} nalu_type = (frame[thirdStartCodeIndex + ] & 0x1F);
} if(nalu_type == )
{ int offset = _spsSize + _ppsSize;
blockLength = frameSize - offset;
data = malloc(blockLength);
data = memcpy(data, &frame[offset], blockLength); uint32_t dataLength32 = htonl (blockLength - );
memcpy (data, &dataLength32, sizeof (uint32_t)); status = CMBlockBufferCreateWithMemoryBlock(NULL, data,
blockLength,
kCFAllocatorNull, NULL,
,
blockLength,
, &blockBuffer);
if(status != noErr){
NSLog(@"I Frame: CMBlockBufferCreateWithMemoryBlock Error type: %d", (int)status);
} } if (nalu_type == )
{ blockLength = frameSize;
data = malloc(blockLength);
data = memcpy(data, &frame[], blockLength); uint32_t dataLength32 = htonl (blockLength - );
memcpy (data, &dataLength32, sizeof (uint32_t)); status = CMBlockBufferCreateWithMemoryBlock(NULL, data,
blockLength,
kCFAllocatorNull, NULL,
,
blockLength,
, &blockBuffer);
if(status != noErr){
NSLog(@"P Frame: CMBlockBufferCreateWithMemoryBlock Error type: %d", (int)status);
} } if(status == noErr)
{
const size_t sampleSize = blockLength;
status = CMSampleBufferCreate(kCFAllocatorDefault,
blockBuffer, true, NULL, NULL,
_formatDesc, , , NULL, ,
&sampleSize, &sampleBuffer);
if(status != noErr){
NSLog(@"CMSampleBufferCreate Error type: %d", (int)status);
} } if(status == noErr)
{ CFArrayRef attachments = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, YES);
CFMutableDictionaryRef dict = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachments, );
CFDictionarySetValue(dict, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue); if([self.updateDelegate respondsToSelector:@selector(updateDecodedSampleBuffer:)]){
[self.updateDelegate updateDecodedSampleBuffer:sampleBuffer]; } } if (data != NULL)
{
free (data);
data = NULL;
}
if(sps != NULL)
{
free(sps);
sps = NULL;
}
if(pps != NULL)
{
free(pps);
pps = NULL;
} return ;
}
@end
h.264硬件解码的更多相关文章
- 树莓派编译安装 FFmpeg(添加 H.264 硬件编解码器支持)
说明 FFmpeg 是一套开源的音视频编解码库,有非常强大的功能,包括视频采集功能.视频格式转换等.众所周知视频编解码是一个非常消耗系统资源的过程,而树莓派自带了 H.264 的硬件编解码器,因此本文 ...
- h.264并行解码算法3D-Wave实现(基于多核共享内存系统)
3D-Wave算法是2D-Wave的扩展.3D-Wave相对于只在帧内并行的2D-Wave来说,多了帧间并行,不用等待前一帧完成解码后才开始下一帧的解码,而是只要宏块的帧间参考部分以及帧内依赖宏块解码 ...
- h.264并行解码算法2D-Wave实现(基于多核共享内存系统)
cache-coherent shared-memory system 我们最平常使用的很多x86.arm芯片都属于多核共享内存系统,这种系统表现为多个核心能直接对同一内存进行读写访问.尽管内存的存取 ...
- h.264并行解码算法2D-Wave实现(基于多核非共享内存系统)
在<Scalable Parallel Programming Applied to H.264/AVC Decoding>书中,作者基于双芯片18核的Cell BE系统实现了2D-Wav ...
- h.264并行解码算法分析
并行算法类型可以分为两类 Function-level Decomposition,按照功能模块进行并行 Data-level Decomposition,按照数据划分进行并行 Function-le ...
- 让dcef3支持mp3和h.264 mp4解码播放
嵌入式Chromium框架(简称CEF) 是一个由Marshall Greenblatt在2008建立的开源项目,它主要目的是开发一个基于Google Chromium的Webbrowser控件.CE ...
- 音视频编解码技术(一):MPEG-4/H.264 AVC 编解码标准
一.H264 概述 H.264,通常也被称之为H.264/AVC(或者H.264/MPEG-4 AVC或MPEG-4/H.264 AVC) 1. H.264视频编解码的意义 H.264的出现就是为了创 ...
- Android IOS WebRTC 音视频开发总结(七九)-- WebRTC选择H.264的四大理由
本文主要介绍WebRTC选择H.264的理由(我们翻译和整理的,译者:weizhenwei,校验:blacker),最早发表在[编风网] 支持原创,转载必须注明出处,欢迎关注我的微信公众号blacke ...
- iOS硬解H.264:-VideoToolboxDemo源码分析[草稿]
来源:http://www.cnblogs.com/michaellfx/p/understanding_-VideoToolboxDemo.html iOS硬解H.264:-VideoToolbox ...
随机推荐
- Linux 服务器下多网卡的负载均衡
Linux 服务器下多网卡负载均衡的实现 一.引言 现今几乎各行各业内部都建立了自己的服务器,由于服务器的特殊地位,它的可靠性.可用性及其 I/O 速度就显得非常的重要, 保持服务器的高可用 ...
- NARF(Normal Aligned Radial Feature)关键点
NARF(Normal Aligned Radial Feature)关键点是为了从深度图像中识别物体而提出的,对NARF关键点的提取过程有以下要求: a) 提取的过程考虑边缘以及物体表面变化信息在内 ...
- 如何在Centos官网下载所需版本的Centos——靠谱的Centos下载教程
很多小伙伴不知道对应版本的Centos怎么下载,最近小编整理了一份Centos详细的下载教程,希望小伙伴们不在为下不到对应版本的Centos而苦恼. 1.进入Centos官网:https://www. ...
- 入门Python:《趣学Python编程》中英文PDF+代码
入门python推荐学习<趣学python编程>,语言轻松,通俗易懂,讲解由浅入深,力求将读者阅读和学习的难度降到最低.任何对计算机编程有兴趣的人或者首次接触编程的人,不论孩子还是成人,都 ...
- python note #3
Hello, guys! I found it pretty difficult to get my content according to my key words. So in this not ...
- Java技术——Java泛型详解(转)
); for (int i = 0; i < list.size(); i++) { String name = (String) list.get(i); //取出Integer时,运行时出现 ...
- DataGirdView 常用操作
1.将数据源的某列添加到已有DataGirdView的列 例如:将文件夹下所有文件名添加到DataGirdView 的文件名一列,图片如下: 首先在datagridview把文件名列的DATAPROP ...
- QCAD Plugin 开发
QCAD Plugin 开发 eryar@163.com Abstract. QCAD是基于GPL协议的开源CAD软件,核心功能基于Qt使用C++开发,界面及其交互使用Javascript脚本进行开发 ...
- ORA-06575: 程序包或函数 NO_VM_DROP_PROC 处于无效状态
SQL> drop user aaa ; drop user aaa ORA-00604: 递归 SQL 级别 1 出现错误 ORA-06575: 程序包或函数 NO_VM_DROP_P ...
- eclipse中编码的设置
Windows-------->prefenerce------>General-------->Workspace