Application Programming Interface (API) for RK Hardware Codec. Application Programming Interface (API) for RK Hardware Codec

Similar documents
Xvid. Introduction. Junjie Cao. What s Xvid? WhyXvid. An open source implementation of the MPEG-4 standard.

WinCE6.0 MFC SMDKV210. Revision 1.90 October Samsung Electronics Co., Ltd. All rights reserved.

Building an Area-optimized Multi-format Video Encoder IP. Tomi Jalonen VP Sales

MPEG Video Decoder (VdecMpeg) API 2

libtheora Reference Manual

Using MV/SAD information from DM365 encoder in application

NVIDIA VIDEO CODEC SDK SAMPLES GUIDE. SDK Samples Guide

Avpy Documentation. Release sydh

TriMedia Motion JPEG Encoder (VencMjpeg) API 1

Video Quality Monitoring

TriMedia Motion JPEG Decoder (VdecMjpeg) API 1

Accelerated Verbs. Liran Liss Mellanox Technologies

NVJPEG. DA _v0.2.0 October nvjpeg Libary Guide

Encoder Core. API Specification. Revision: SOC Technologies Inc.

A Linux multimedia platform for SH-Mobile processors

Request for Comments: 4425 Category: Standards Track February 2006

ArduCAM USB Camera C/C++ SDK

ArduCAM USB Camera SDK

Introduction to Video Encoding

STUDY AND IMPLEMENTATION OF VIDEO COMPRESSION STANDARDS (H.264/AVC, DIRAC)

IEEE 1857 Standard Empowering Smart Video Surveillance Systems

Data compression.

THE H.264 ADVANCED VIDEO COMPRESSION STANDARD

Comparative and performance analysis of HEVC and H.264 Intra frame coding and JPEG2000

MULTIMEDIA AND CODING

int fnvgetconfig(handle h, UINT32 id, const void *cfg, size_t sz);... 4

NVJPEG. DA _v0.1.4 August nvjpeg Libary Guide

MPEG4 Programming Guide

Digital Video Processing

The Basics of Video Compression

Path Objects. Introduction. Methods. Data Types. Create, Delete, Validate Methods. Configuration and Information Methods. Relational Methods

PREFACE...XIII ACKNOWLEDGEMENTS...XV

Emerging Architectures for HD Video Transcoding. Leon Adams Worldwide Manager Catalog DSP Marketing Texas Instruments

Emerging Architectures for HD Video Transcoding. Jeremiah Golston CTO, Digital Entertainment Products Texas Instruments

H264 Encoder Codec. API Specification 12/20/2017. Revision SOC Technologies Inc.

HikVision Mpeg4 linux Player SDK

HTML 5 and CSS 3, Illustrated Complete. Unit K: Incorporating Video and Audio

Scalable Multi-DM642-based MPEG-2 to H.264 Transcoder. Arvind Raman, Sriram Sethuraman Ittiam Systems (Pvt.) Ltd. Bangalore, India

STUDY AND PERFORMANCE COMPARISON OF HEVC AND H.264 VIDEO CODECS

GM8126 DVR DRIVER. User Guide Rev.: 1.1 Issue Date: June 2011

STUDY AND PERFORMANCE COMPARISON OF HEVC AND H.264 VIDEO ENCODERS

EE 5359 H.264 to VC 1 Transcoding

H264 Encoder Codec. API Specification. 04/27/2017 Revision SOC Technologies Inc.

Opus Generated by Doxygen Thu May :22:05

Video Compression An Introduction

High Efficiency Video Coding. Li Li 2016/10/18

4K Video Processing and Streaming Platform on TX1

Intel Stress Bitstreams and Encoder (Intel SBE) HEVC Getting Started

Intel Media Server Studio 2018 R1 - HEVC Decoder and Encoder Release Notes (Version )

OFV-WG: Accelerated Verbs

IMPROVED CONTEXT-ADAPTIVE ARITHMETIC CODING IN H.264/AVC

4K Video Processing and Streaming Platform on TX1

The VC-1 and H.264 Video Compression Standards for Broadband Video Services

Efficient Video Processing on Embedded GPU

Marek Szyprowski Samsung R&D Institute Poland

Module 10 MULTIMEDIA SYNCHRONIZATION

Introduction to Video Encoding

Video Codecs. National Chiao Tung University Chun-Jen Tsai 1/5/2015

Comparative and performance analysis of HEVC and H.264 Intra frame coding and JPEG2000

CAE Plugin SDK. A Basic How-to

JEXEC DEFINITIONS The Resource Manager is specified in rmtaskid.h as JEXEC_TASKID_RESOURCE_MANAGER.

WHITE PAPER ON2 TECHNOLOGIES, INC. TrueMotion VP7 Video Codec. January 10, 2005 Document Version: 1.0

MISB ST STANDARD. Timestamps for Class 1/Class 2 Motion Imagery. 25 February Scope. 2 References

Online Webinar. June 16, Intel SDK for opencl applications. Intel Media SDK

ArduCAM USB Camera SDK

Secure RTP Library API Documentation. David A. McGrew Cisco Systems, Inc.

AMD AMF Reference Manual

Image and video processing

DTMediaRead Programmers Interface

Adhocracy Innovation with Imaging technology. Socionext Inc. Hiroyuki Komori July 5th, 2017

Video Codec Design Developing Image and Video Compression Systems

Lecture 13 Video Coding H.264 / MPEG4 AVC

OptimiData. JPEG2000 Software Development Kit for C/C++ Reference Manual. Version 1.6. from

Qualcomm High Efficiency Video Coding (HEVC) Video Encoder

This application note describes the specification of the JPEG codec unit (in the following, JCU) driver of SH7268/SH7269.

Final exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Dec 20, Student's name: Student ID:

SDK API Reference Manual for VP8. API Version 1.12

Osprey Talon Encoder Configuration and Control API User Guide. Osprey Talon Encoder Configuration and Control API User Guide

H.264 Video Transmission with High Quality and Low Bitrate over Wireless Network

[CAMERA PROGRAMMER'S MANUAL] EMERGENT VISION TECHNOLOGIES INC March 3, 2013

SCD - Scorpion Camera Drivers Specification Documentation

SENSORAY CO., INC. 24oo Software Development Kit Version 1.0.1

H.264 STANDARD BASED SIDE INFORMATION GENERATION IN WYNER-ZIV CODING

Lecture 5: Error Resilience & Scalability

Encoding Video for the Highest Quality and Performance

NVIDIA VIDEO ENCODER (NVENC) INTERFACE

H.261 / H.263 Video CODEC Library For Philips Trimedia

AET60 BioCARDKey. Application Programming Interface. Subject to change without prior notice

Scalable Extension of HEVC 한종기

GStreamer Daemon - Building a media server under 30min. Michael Grüner - David Soto -

Optimized architectures of CABAC codec for IA-32-, DSP- and FPGAbased

Solid State Graphics (SSG) SDK Setup and Raw Video Player Guide

Osprey Talon Encoder Configuration and Control API User Guide. Osprey Talon Encoder Configuration and Control API User Guide

MPEG-2. And Scalability Support. Nimrod Peleg Update: July.2004

IO [io] MAYAH. IO [io] Audio Video Codec Systems

4K HEVC Video Processing with GPU Optimization on Jetson TX1

DVP-7020BE 16 Channel PCI-bus Surveillance Capture card

White paper: Video Coding A Timeline

Dotstack Porting Guide.

PDF Document structure, that need for managing of PDF file. It uses in all functions from EMF2PDF SDK.

Transcription:

Application Programming Interface (API) for RK Hardware Codec 1

Table of Contents 1. Codecs Supported by RK... 3 2. Head file and Library Files... 3 3. Structure... 3 3.1 Defining the Codec Enumeration Type... 3 3.2 Defining the Codec Structure... 5 4. Process of Calling Decoder... 8 4.1 Creating a Decoder... 8 4.2 Applying the Decoder... 9 4.3 Destroying the Decoder... 9 5. Process of Calling Encoder... 10 5.1 Creating a Encoder... 10 5.2 Applying the Encoder... 11 5.3 Destroying the Encoder... 11 2

1. Codecs Supported by RK Only H264 and VP8 are supported. 2. Head file and Library Files The head file we need: vpu_api.h The library files we need: librk_vpuapi.so libvpu.so 3. Structure 3.1 Defining the Codec Enumeration Type The enumeration type of the image inputted when encoding: typedef enum VPU_H264ENC_YUV420_PLANAR = 0, /* YYYY... UUUU... VVVV */ VPU_H264ENC_YUV420_SEMIPLANAR = 1, /* YYYY... UVUVUV... */ VPU_H264ENC_YUV422_INTERLEAVED_YUYV = 2, /* YUYVYUYV... */ VPU_H264ENC_YUV422_INTERLEAVED_UYVY = 3, /* UYVYUYVY... */ VPU_H264ENC_RGB565 = 4, /* 16-bit RGB */ VPU_H264ENC_BGR565 = 5, /* 16-bit RGB */ VPU_H264ENC_RGB555 = 6, /* 15-bit RGB */ VPU_H264ENC_BGR555 = 7, /* 15-bit RGB */ VPU_H264ENC_RGB444 = 8, /* 12-bit RGB */ VPU_H264ENC_BGR444 = 9, /* 12-bit RGB */ VPU_H264ENC_RGB888 = 10, /* 24-bit RGB */ VPU_H264ENC_BGR888 = 11, /* 24-bit RGB */ VPU_H264ENC_RGB101010 = 12, /* 30-bit RGB */ VPU_H264ENC_BGR101010 = 13 /* 30-bit RGB */ H264EncPictureType; The enumeration type of the codec type structure: typedef enum OMX_RK_VIDEO_CODINGTYPE OMX_RK_VIDEO_CodingUnused, /**< Value when coding is N/A */ OMX_RK_VIDEO_CodingAutoDetect, /**< Autodetection of coding type */ OMX_RK_VIDEO_CodingMPEG2, /**< AKA: H.262 */ OMX_RK_VIDEO_CodingH263, /**< H.263 */ OMX_RK_VIDEO_CodingMPEG4, /**< MPEG-4 */ OMX_RK_VIDEO_CodingWMV, /**< Windows Media Video (WMV1,WMV2,WMV3)*/ 3

OMX_RK_VIDEO_CodingRV, /**< all versions of Real Video */ OMX_RK_VIDEO_CodingAVC, /**< H.264/AVC */ OMX_RK_VIDEO_CodingMJPEG, /**< Motion JPEG */ OMX_RK_VIDEO_CodingVP8, /**< VP8 */ OMX_RK_VIDEO_CodingVP9, /**< VP9 */ OMX_RK_VIDEO_CodingVC1=0x01000000, /**<WindowsMediaVideo(WMV1,WMV2,WMV3)*/ OMX_RK_VIDEO_CodingFLV1, /**< Sorenson H.263 */ OMX_RK_VIDEO_CodingDIVX3, /**< DIVX3 */ OMX_RK_VIDEO_CodingVP6, OMX_RK_VIDEO_CodingHEVC, /**< H.265/HEVC */ OMX_RK_VIDEO_CodingKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */ OMX_RK_VIDEO_CodingVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */ OMX_RK_VIDEO_CodingMax = 0x7FFFFFFF OMX_RK_VIDEO_CODINGTYPE; The enumeration type of the codec category structure: typedef enum CODEC_TYPE CODEC_NONE, CODEC_DECODER,/*Decoding*/ CODEC_ENCODER,/*Encoding*/ CODEC_BUTT, CODEC_TYPE; The enumeration type of the value type for the returned error message: typedef enum VPU_API_ERR VPU_API_OK = 0, VPU_API_ERR_UNKNOW = -1, VPU_API_ERR_BASE = -1000, VPU_API_ERR_LIST_STREAM = VPU_API_ERR_BASE - 1, VPU_API_ERR_INIT = VPU_API_ERR_BASE - 2, VPU_API_ERR_VPU_CODEC_INIT = VPU_API_ERR_BASE - 3, VPU_API_ERR_STREAM = VPU_API_ERR_BASE - 4, VPU_API_ERR_FATAL_THREAD = VPU_API_ERR_BASE - 5, VPU_API_EOS_STREAM_REACHED = VPU_API_ERR_BASE - 11, VPU_API_ERR_BUTT, VPU_API_ERR; 4

3.2 Defining the Codec Structure The structure of the video packet: typedef struct VideoPacket RK_S64 pts; /* with unit of us*/ RK_S64 dts; /* with unit of us*/ RK_U8 *data; /* start address of stream data per frame*/ RK_S32 size; /* length of the stream per frame*/ RK_U32 capability; /* NOTE: 0- RK_U32 nflags; VideoPacket_t; The structure of the image outputted after decoding: typedef struct DecoderOut RK_U8 *data; /*image data after decoding*/ RK_U32 size; /*image size after decoding*/ RK_S64 timeus; RK_S32 nflags; DecoderOut_t; The structure of the image inputted before encoding: typedef struct EncInputStream RK_U8 *buf; /* image data after encoding */ RK_S32 size; /* image size after encoding * RK_U32 bufphyaddr; /*image s physical address after encoding*/ RK_S64 timeus; RK_U32 nflags; EncInputStream_t; The structure of the bit stream outputted after encoding: typedef struct EncoderOut RK_U8 *data; /*stream data per frame */ RK_S32 size; /*stream data per frame*/ RK_S64 timeus; RK_S32 keyframe; /*key frame*/ EncoderOut_t; 5

The structure of the encoding parameters: typedef struct EncParameter int width; int height; int rc_mode; int bitrate; int framerate; int qp; int enablecabac; int cabacinitidc; int format; int intrapicrate; int framerateout; int profileidc; int levelidc; int reserved[3]; EncParameter_t; The structure of the encoding parameters (no need to configure and set): typedef struct int width; int height; int rc_mode; int bitrate; int framerate; int qp; int reserved[10]; EncParams1; The structure of the extra codec parameters (no need to configure and set): typedef struct EXtraCfg RK_S32 vc1extra_size; RK_S32 vp6codeid; RK_S32 tsformat; RK_U32 reserved[20]; EXtraCfg_t; The context structure of VPU codec: typedef struct VpuCodecContext void* vpuapiobj; CODEC_TYPE codectype; OMX_RK_VIDEO_CODINGTYPE videocoding; 6

7 RK_U32 width; RK_U32 height; RK_U8 *extradata; RK_S32 extradata_size; RK_U8 enableparsing; RK_S32 no_thread; EXtraCfg_t extra_cfg; void* private_data; /* ** 1: error state(not working) 0: working */ RK_S32 decoder_err; /** * Allocate and initialize an VpuCodecContext. * * @param ctx The context of vpu api, allocated in this function. * @param extradata The extra data of codec, some codecs need / can * use extradata like Huffman tables, also live VC1 codec can * use extradata to initialize itself. * @param extra_size The size of extra data. * * @return 0 for init success, others for failure. * note: check whether ctx has been allocated success after you do init. */ RK_S32 (*init)(struct VpuCodecContext *ctx, RK_U8 *extradata, RK_U32 extra_size); /** * @return 0 for decode success, others for failure. */ RK_S32 (*decode)(struct VpuCodecContext *ctx, VideoPacket_t *pkt, DecoderOut_t *adecout); /** * @return 0 for encode success, others for failure. */ RK_S32 (*encode)(struct VpuCodecContext *ctx, EncInputStream_t *aencinstrm, EncoderOut_t *aencout); /** * flush codec while do fast forward playing. * * @return 0 for flush success, others for failure. */ RK_S32 (*flush)(struct VpuCodecContext *ctx); RK_S32 (*control)(struct VpuCodecContext *ctx, VPU_API_CMD cmdtype, void* param); /** *seperate the decode function to two function

* */ RK_S32 (*decode_sendstream)(struct VpuCodecContext *ctx, VideoPacket_t *pkt); RK_S32 (*decode_getframe)(struct VpuCodecContext *ctx, DecoderOut_t *adecout); RK_S32 (*encoder_sendframe)(struct VpuCodecContext *ctx, EncInputStream_t *aencinstrm); RK_S32 (*encoder_getstream)(struct VpuCodecContext *ctx, EncoderOut_t *aencout); VpuCodecContext_t; /* allocated vpu codec context */ #ifdef cplusplus extern "C" #endif RK_S32 vpu_open_context(struct VpuCodecContext **ctx); #ifdef cplusplus #endif #ifdef cplusplus extern "C" #endif RK_S32 vpu_close_context(struct VpuCodecContext **ctx); #ifdef cplusplus #endif 4. Process of Calling Decoder An example for decoding the video when the resolution is less than 720P @ 30fps: VpuCodecContext_t *_vpu_ctx = NULL; 4.1 Creating a Decoder (1) Create _vpu_ctx int ret = vpu_open_context(&_vpu_ctx); if (ret < 0 (_vpu_ctx == NULL)) ERROR ("can not create context"); return -1; (2) Initialize _vpu_ctx->width = 1280; _vpu_ctx->height = 720;/*resolution720P*/ _vpu_ctx->videocoding = OMX_RK_VIDEO_CodingAVC;/*H264*/ _vpu_ctx->codectype = CODEC_DECODER;/*decoding*/ 8

ret = _vpu_ctx->init(_vpu_ctx, NULL, 0); if (ret < 0) ERROR (" decoder init failed"); return -1; 4.2 Applying the Decoder VideoPacket_t pkt; DecoderOut_t picture; VPU_FRAME* _vpu_fm; memset(&pkt, 0, sizeof(videopacket_t)); memset(&picture, 0, sizeof(decoderout_t)); pkt.data = coded_data_ptr; pkt.size = frame_len; picture.data = (RK_U8*)_vpu_fm; picture.size = 0; int ret = _vpu_ctx->decode(_vpu_ctx, &pkt, &picture); if (ret!= 0) ALOGE("[ER] failed to decode this frame"); return -1; if (_vpu_fm->vpumem.vir_addr == NULL) It is required to cache two frames for decoding, and the data should be less than 30fps. Note: The buffer should be released after the data has been used. if (_vpu_fm->vpumem.vir_addr!= NULL) VPUMemLink(&_vpu_fm->vpumem); VPUFreeLinear(&_vpu_fm->vpumem); memset(_vpu_fm, 0, sizeof(vpu_frame)); Note: The functions of decoder_getstream, decoder_sendframe and decode interface are the same. 4.3 Destroying the Decoder if (_vpu_ctx!= NULL) int res = vpu_close_context(&_vpu_ctx); _vpu_ctx = NULL; 9

5. Process of Calling Encoder An example for encoding the video when the resolution is less than 720P @ 30fps: VpuCodecContext_t *_vpu_ctx = NULL; 5.1 Creating a Encoder (1) Create _vpu_ctx int ret = vpu_open_context(&_vpu_ctx); if (ret < 0 (_vpu_ctx == NULL)) ERROR ("can not create context"); return -1; (2) Initialize EncParameter_t *_vpu_enc_param; _vpu_enc_param = (EncParameter_t*)malloc(sizeof(EncParameter_t)); memset(_vpu_enc_param, 0, sizeof(encparameter_t)); _vpu_ctx->width = 1280; _vpu_ctx->height = 720;/*resolution 720P*/ _vpu_ctx->videocoding = OMX_RK_VIDEO_CodingAVC;/*H264*/ _vpu_ctx->codectype = CODEC_ENCODER;/*encoding*/ _vpu_enc_param->bitrate = 512;/* bit rate */ _vpu_enc_param->enablecabac = false;/*enabling cabac*/ _vpu_enc_param->cabacinitidc = 0; _vpu_enc_param->format = 0; _vpu_enc_param->framerate =30;/*frame rate*/ _vpu_enc_param->width = 1280; _vpu_enc_param->height = 720; _vpu_enc_param->profileidc = profile; _vpu_enc_param->intrapicrate =_gop_len; _vpu_enc_param->levelidc = level_id; _vpu_enc_param->rc_mode = 1; _vpu_enc_param->qp = 35; _vpu_ctx->private_data = _vpu_enc_param; ret = _vpu_ctx->init(_vpu_ctx, NULL, 0); if (ret < 0) ERROR (" decoder init failed"); return -1; /*Obtain encoding parameters*/ EncParameter_t vpug; _vpu_ctx->control(_vpu_ctx,vpu_api_enc_getcfg,(void*)&vpug); 10

/*Set encoding parameters*/ vpug.rc_mode = 1; _vpu_ctx->control(_vpu_ctx,vpu_api_enc_setcfg,(void*)&vpug); /*Set encoding type*/ H264EncPictureType enctype = VPU_H264ENC_YUV420_SEMIPLANAR; // nv12 res=_vpu_ctx->control(_vpu_ctx,vpu_api_enc_setformat, (void*) &enctype); if (res < 0) ERROR ("init control failed!"); return -1; 5.2 Applying the Encoder EncInputStream_t input; /*Input the information of the image*/ input.buf = pic.viraddr /*The address of image*/ input.size = size;/*image size*/ res = _vpu_ctx->encoder_sendframe(_vpu_ctx, &input); if (res!= 0) ERROR ("enc send frame to vpu error"); return -1; EncoderOut_t output;/*the bit stream data after encoding*/ memset(&output, 0, sizeof(encoderout_t)); output.data = NULL; output.size = 0; /*Bit stream size*/ res = _vpu_ctx->encoder_getstream(_vpu_ctx, &output); if (res!= 0) ERROR ("enc get frame to vpu error"); return -1; Note: The functions of decoder_getstream, decoder_sendframe and encoder interface are the same. 5.3 Destroying the Encoder if (_vpu_ctx!= NULL) res = _vpu_ctx->flush(_vpu_ctx); 11 if (res!= 0)

ERROR ("enc flush vpu error"); return -1; res = vpu_close_context(&_vpu_ctx); if (res!= 0) ERROR ("enc close vpu error"); return -1; _vpu_ctx = NULL; Note: It is required to apply for I-frame (Intra-coded picture) when packet loss occurs, and RK hardware encode does not support multi-slice encodes. 12