first commit

This commit is contained in:
2025-08-22 13:52:24 +08:00
commit 05a551d523
257 changed files with 49217 additions and 0 deletions
+173
View File
@@ -0,0 +1,173 @@
/*-------------------------------------------------------------------------*/
/**
@file dictionary.h
@author N. Devillard
@brief Implements a dictionary for string variables.
This module implements a simple dictionary object, i.e. a list
of string/string associations. This object is useful to store e.g.
informations retrieved from a configuration file (ini files).
*/
/*--------------------------------------------------------------------------*/
#ifndef _DICTIONARY_H_
#define _DICTIONARY_H_
/*---------------------------------------------------------------------------
Includes
---------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef __cplusplus
extern "C" {
#endif
/*---------------------------------------------------------------------------
New types
---------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/**
@brief Dictionary object
This object contains a list of string/string associations. Each
association is identified by a unique string key. Looking up values
in the dictionary is speeded up by the use of a (hopefully collision-free)
hash function.
*/
/*-------------------------------------------------------------------------*/
typedef struct _dictionary_ {
int n ; /** Number of entries in dictionary */
ssize_t size ; /** Storage size */
char ** val ; /** List of string values */
char ** key ; /** List of string keys */
unsigned * hash ; /** List of hash values for keys */
} dictionary ;
/*---------------------------------------------------------------------------
Function prototypes
---------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/**
@brief Compute the hash key for a string.
@param key Character string to use for key.
@return 1 unsigned int on at least 32 bits.
This hash function has been taken from an Article in Dr Dobbs Journal.
This is normally a collision-free function, distributing keys evenly.
The key is stored anyway in the struct so that collision can be avoided
by comparing the key itself in last resort.
*/
/*--------------------------------------------------------------------------*/
unsigned dictionary_hash(const char * key);
/*-------------------------------------------------------------------------*/
/**
@brief Create a new dictionary object.
@param size Optional initial size of the dictionary.
@return 1 newly allocated dictionary objet.
This function allocates a new dictionary object of given size and returns
it. If you do not know in advance (roughly) the number of entries in the
dictionary, give size=0.
*/
/*--------------------------------------------------------------------------*/
dictionary * dictionary_new(size_t size);
/*-------------------------------------------------------------------------*/
/**
@brief Delete a dictionary object
@param d dictionary object to deallocate.
@return void
Deallocate a dictionary object and all memory associated to it.
*/
/*--------------------------------------------------------------------------*/
void dictionary_del(dictionary * vd);
/*-------------------------------------------------------------------------*/
/**
@brief Get a value from a dictionary.
@param d dictionary object to search.
@param key Key to look for in the dictionary.
@param def Default value to return if key not found.
@return 1 pointer to internally allocated character string.
This function locates a key in a dictionary and returns a pointer to its
value, or the passed 'def' pointer if no such key can be found in
dictionary. The returned character pointer points to data internal to the
dictionary object, you should not try to free it or modify it.
*/
/*--------------------------------------------------------------------------*/
const char * dictionary_get(const dictionary * d, const char * key, const char * def);
/*-------------------------------------------------------------------------*/
/**
@brief Set a value in a dictionary.
@param d dictionary object to modify.
@param key Key to modify or add.
@param val Value to add.
@return int 0 if Ok, anything else otherwise
If the given key is found in the dictionary, the associated value is
replaced by the provided one. If the key cannot be found in the
dictionary, it is added to it.
It is Ok to provide a NULL value for val, but NULL values for the dictionary
or the key are considered as errors: the function will return immediately
in such a case.
Notice that if you dictionary_set a variable to NULL, a call to
dictionary_get will return a NULL value: the variable will be found, and
its value (NULL) is returned. In other words, setting the variable
content to NULL is equivalent to deleting the variable from the
dictionary. It is not possible (in this implementation) to have a key in
the dictionary without value.
This function returns non-zero in case of failure.
*/
/*--------------------------------------------------------------------------*/
int dictionary_set(dictionary * vd, const char * key, const char * val);
/*-------------------------------------------------------------------------*/
/**
@brief Delete a key in a dictionary
@param d dictionary object to modify.
@param key Key to remove.
@return void
This function deletes a key in a dictionary. Nothing is done if the
key cannot be found.
*/
/*--------------------------------------------------------------------------*/
void dictionary_unset(dictionary * d, const char * key);
/*-------------------------------------------------------------------------*/
/**
@brief Dump a dictionary to an opened file pointer.
@param d Dictionary to dump
@param f Opened file pointer.
@return void
Dumps a dictionary onto an opened file pointer. Key pairs are printed out
as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as
output file pointers.
*/
/*--------------------------------------------------------------------------*/
void dictionary_dump(const dictionary * d, FILE * out);
#ifdef __cplusplus
}
#endif
#endif
+358
View File
@@ -0,0 +1,358 @@
/*-------------------------------------------------------------------------*/
/**
@file iniparser.h
@author N. Devillard
@brief Parser for ini files.
*/
/*--------------------------------------------------------------------------*/
#ifndef _INIPARSER_H_
#define _INIPARSER_H_
/*---------------------------------------------------------------------------
Includes
---------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* The following #include is necessary on many Unixes but not Linux.
* It is not needed for Windows platforms.
* Uncomment it if needed.
*/
/* #include <unistd.h> */
#include "dictionary.h"
#ifdef __cplusplus
extern "C" {
#endif
/*-------------------------------------------------------------------------*/
/**
@brief Configure a function to receive the error messages.
@param errback Function to call.
By default, the error will be printed on stderr. If a null pointer is passed
as errback the error callback will be switched back to default.
*/
/*--------------------------------------------------------------------------*/
void iniparser_set_error_callback(int (*errback)(const char *, ...));
/*-------------------------------------------------------------------------*/
/**
@brief Get number of sections in a dictionary
@param d Dictionary to examine
@return int Number of sections found in dictionary
This function returns the number of sections found in a dictionary.
The test to recognize sections is done on the string stored in the
dictionary: a section name is given as "section" whereas a key is
stored as "section:key", thus the test looks for entries that do not
contain a colon.
This clearly fails in the case a section name contains a colon, but
this should simply be avoided.
This function returns -1 in case of error.
*/
/*--------------------------------------------------------------------------*/
int iniparser_getnsec(const dictionary * d);
/*-------------------------------------------------------------------------*/
/**
@brief Get name for section n in a dictionary.
@param d Dictionary to examine
@param n Section number (from 0 to nsec-1).
@return Pointer to char string
This function locates the n-th section in a dictionary and returns
its name as a pointer to a string statically allocated inside the
dictionary. Do not free or modify the returned string!
This function returns NULL in case of error.
*/
/*--------------------------------------------------------------------------*/
const char * iniparser_getsecname(const dictionary * d, int n);
/*-------------------------------------------------------------------------*/
/**
@brief Save a dictionary to a loadable ini file
@param d Dictionary to dump
@param f Opened file pointer to dump to
@return void
This function dumps a given dictionary into a loadable ini file.
It is Ok to specify @c stderr or @c stdout as output files.
*/
/*--------------------------------------------------------------------------*/
void iniparser_dump_ini(const dictionary * d, FILE * f);
/*-------------------------------------------------------------------------*/
/**
@brief Save a dictionary section to a loadable ini file
@param d Dictionary to dump
@param s Section name of dictionary to dump
@param f Opened file pointer to dump to
@return void
This function dumps a given section of a given dictionary into a loadable ini
file. It is Ok to specify @c stderr or @c stdout as output files.
*/
/*--------------------------------------------------------------------------*/
void iniparser_dumpsection_ini(const dictionary * d, const char * s, FILE * f);
/*-------------------------------------------------------------------------*/
/**
@brief Dump a dictionary to an opened file pointer.
@param d Dictionary to dump.
@param f Opened file pointer to dump to.
@return void
This function prints out the contents of a dictionary, one element by
line, onto the provided file pointer. It is OK to specify @c stderr
or @c stdout as output files. This function is meant for debugging
purposes mostly.
*/
/*--------------------------------------------------------------------------*/
void iniparser_dump(const dictionary * d, FILE * f);
/*-------------------------------------------------------------------------*/
/**
@brief Get the number of keys in a section of a dictionary.
@param d Dictionary to examine
@param s Section name of dictionary to examine
@return Number of keys in section
*/
/*--------------------------------------------------------------------------*/
int iniparser_getsecnkeys(const dictionary * d, const char * s);
/*-------------------------------------------------------------------------*/
/**
@brief Get the number of keys in a section of a dictionary.
@param d Dictionary to examine
@param s Section name of dictionary to examine
@param keys Already allocated array to store the keys in
@return The pointer passed as `keys` argument or NULL in case of error
This function queries a dictionary and finds all keys in a given section.
The keys argument should be an array of pointers which size has been
determined by calling `iniparser_getsecnkeys` function prior to this one.
Each pointer in the returned char pointer-to-pointer is pointing to
a string allocated in the dictionary; do not free or modify them.
*/
/*--------------------------------------------------------------------------*/
const char ** iniparser_getseckeys(const dictionary * d, const char * s, const char ** keys);
/*-------------------------------------------------------------------------*/
/**
@brief Get the string associated to a key
@param d Dictionary to search
@param key Key string to look for
@param def Default value to return if key not found.
@return pointer to statically allocated character string
This function queries a dictionary for a key. A key as read from an
ini file is given as "section:key". If the key cannot be found,
the pointer passed as 'def' is returned.
The returned char pointer is pointing to a string allocated in
the dictionary, do not free or modify it.
*/
/*--------------------------------------------------------------------------*/
const char * iniparser_getstring(const dictionary * d, const char * key, const char * def);
/*-------------------------------------------------------------------------*/
/**
@brief Get the string associated to a key, convert to an int
@param d Dictionary to search
@param key Key string to look for
@param notfound Value to return in case of error
@return integer
This function queries a dictionary for a key. A key as read from an
ini file is given as "section:key". If the key cannot be found,
the notfound value is returned.
Supported values for integers include the usual C notation
so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
are supported. Examples:
- "42" -> 42
- "042" -> 34 (octal -> decimal)
- "0x42" -> 66 (hexa -> decimal)
Warning: the conversion may overflow in various ways. Conversion is
totally outsourced to strtol(), see the associated man page for overflow
handling.
Credits: Thanks to A. Becker for suggesting strtol()
*/
/*--------------------------------------------------------------------------*/
int iniparser_getint(const dictionary * d, const char * key, int notfound);
/*-------------------------------------------------------------------------*/
/**
@brief Get the string associated to a key, convert to an long int
@param d Dictionary to search
@param key Key string to look for
@param notfound Value to return in case of error
@return integer
This function queries a dictionary for a key. A key as read from an
ini file is given as "section:key". If the key cannot be found,
the notfound value is returned.
Supported values for integers include the usual C notation
so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
are supported. Examples:
- "42" -> 42
- "042" -> 34 (octal -> decimal)
- "0x42" -> 66 (hexa -> decimal)
Warning: the conversion may overflow in various ways. Conversion is
totally outsourced to strtol(), see the associated man page for overflow
handling.
*/
/*--------------------------------------------------------------------------*/
long int iniparser_getlongint(const dictionary * d, const char * key, long int notfound);
/*-------------------------------------------------------------------------*/
/**
@brief Get the string associated to a key, convert to a double
@param d Dictionary to search
@param key Key string to look for
@param notfound Value to return in case of error
@return double
This function queries a dictionary for a key. A key as read from an
ini file is given as "section:key". If the key cannot be found,
the notfound value is returned.
*/
/*--------------------------------------------------------------------------*/
double iniparser_getdouble(const dictionary * d, const char * key, double notfound);
/*-------------------------------------------------------------------------*/
/**
@brief Get the string associated to a key, convert to a boolean
@param d Dictionary to search
@param key Key string to look for
@param notfound Value to return in case of error
@return integer
This function queries a dictionary for a key. A key as read from an
ini file is given as "section:key". If the key cannot be found,
the notfound value is returned.
A true boolean is found if one of the following is matched:
- A string starting with 'y'
- A string starting with 'Y'
- A string starting with 't'
- A string starting with 'T'
- A string starting with '1'
A false boolean is found if one of the following is matched:
- A string starting with 'n'
- A string starting with 'N'
- A string starting with 'f'
- A string starting with 'F'
- A string starting with '0'
The notfound value returned if no boolean is identified, does not
necessarily have to be 0 or 1.
*/
/*--------------------------------------------------------------------------*/
int iniparser_getboolean(const dictionary * d, const char * key, int notfound);
/*-------------------------------------------------------------------------*/
/**
@brief Set an entry in a dictionary.
@param ini Dictionary to modify.
@param entry Entry to modify (entry name)
@param val New value to associate to the entry.
@return int 0 if Ok, -1 otherwise.
If the given entry can be found in the dictionary, it is modified to
contain the provided value. If it cannot be found, the entry is created.
It is Ok to set val to NULL.
*/
/*--------------------------------------------------------------------------*/
int iniparser_set(dictionary * ini, const char * entry, const char * val);
/*-------------------------------------------------------------------------*/
/**
@brief Delete an entry in a dictionary
@param ini Dictionary to modify
@param entry Entry to delete (entry name)
@return void
If the given entry can be found, it is deleted from the dictionary.
*/
/*--------------------------------------------------------------------------*/
void iniparser_unset(dictionary * ini, const char * entry);
/*-------------------------------------------------------------------------*/
/**
@brief Finds out if a given entry exists in a dictionary
@param ini Dictionary to search
@param entry Name of the entry to look for
@return integer 1 if entry exists, 0 otherwise
Finds out if a given entry exists in the dictionary. Since sections
are stored as keys with NULL associated values, this is the only way
of querying for the presence of sections in a dictionary.
*/
/*--------------------------------------------------------------------------*/
int iniparser_find_entry(const dictionary * ini, const char * entry) ;
/*-------------------------------------------------------------------------*/
/**
@brief Parse an ini file and return an allocated dictionary object
@param ininame Name of the ini file to read.
@return Pointer to newly allocated dictionary
This is the parser for ini files. This function is called, providing
the name of the file to be read. It returns a dictionary object that
should not be accessed directly, but through accessor functions
instead.
The returned dictionary must be freed using iniparser_freedict().
*/
/*--------------------------------------------------------------------------*/
dictionary * iniparser_load(const char * ininame);
/*-------------------------------------------------------------------------*/
/**
@brief Free all memory associated to an ini dictionary
@param d Dictionary to free
@return void
Free all memory associated to an ini dictionary.
It is mandatory to call this function before the dictionary object
gets out of the current context.
*/
/*--------------------------------------------------------------------------*/
void iniparser_freedict(dictionary * d);
#ifdef __cplusplus
}
#endif
#endif
+71
View File
@@ -0,0 +1,71 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPI_ENC_UTILS_H__
#define __MPI_ENC_UTILS_H__
#include <stdio.h>
#include "rk_venc_cmd.h"
typedef struct MpiEncTestArgs_t {
char *file_input;
char *file_output;
MppCodingType type;
MppFrameFormat format;
RK_S32 num_frames;
RK_S32 loop_cnt;
RK_S32 width;
RK_S32 height;
RK_S32 hor_stride;
RK_S32 ver_stride;
RK_S32 bps_target;
RK_S32 fps_in_flex;
RK_S32 fps_in_num;
RK_S32 fps_in_den;
RK_S32 fps_out_flex;
RK_S32 fps_out_num;
RK_S32 fps_out_den;
RK_S32 gop_mode;
MppEncHeaderMode header_mode;
MppEncSliceSplit split;
} MpiEncTestArgs;
#ifdef __cplusplus
extern "C" {
#endif
MPP_RET mpi_enc_gen_gop_ref(MppEncGopRef *ref, RK_S32 gop_mode);
MPP_RET mpi_enc_gen_osd_data(MppEncOSDData *osd_data, MppBuffer osd_buf, RK_U32 frame_cnt);
MPP_RET mpi_enc_gen_osd_plt(MppEncOSDPlt *osd_plt, RK_U32 *table);
MpiEncTestArgs *mpi_enc_test_cmd_get(void);
MPP_RET mpi_enc_test_cmd_update_by_args(MpiEncTestArgs* cmd, int argc, char **argv);
MPP_RET mpi_enc_test_cmd_put(MpiEncTestArgs* cmd);
MPP_RET mpi_enc_test_cmd_show_opt(MpiEncTestArgs* cmd);
void mpi_enc_test_help(void);
#ifdef __cplusplus
}
#endif
#endif /*__MPI_ENC_UTILS_H__*/
+42
View File
@@ -0,0 +1,42 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPI_IMPL_H__
#define __MPI_IMPL_H__
#include "mpp.h"
#define MPI_DBG_FUNCTION (0x00000001)
#define mpi_dbg(flag, fmt, ...) _mpp_dbg(mpi_debug, flag, fmt, ## __VA_ARGS__)
#define mpi_dbg_f(flag, fmt, ...) _mpp_dbg_f(mpi_debug, flag, fmt, ## __VA_ARGS__)
#define mpi_dbg_func(fmt, ...) mpi_dbg_f(MPI_DBG_FUNCTION, fmt, ## __VA_ARGS__)
typedef struct MpiImpl_t MpiImpl;
struct MpiImpl_t {
MpiImpl *check;
MppCtxType type;
MppCodingType coding;
MppApi *api;
Mpp *ctx;
};
extern RK_U32 mpi_debug;
#endif /*__MPI_IMPL_H__*/
Executable
+195
View File
@@ -0,0 +1,195 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_H__
#define __MPP_H__
#include "mpp_queue.h"
#include "mpp_task_impl.h"
#include "mpp_dec.h"
#include "mpp_enc.h"
#include "mpp_impl.h"
#define MPP_DBG_FUNCTION (0x00000001)
#define MPP_DBG_PACKET (0x00000002)
#define MPP_DBG_FRAME (0x00000004)
#define MPP_DBG_BUFFER (0x00000008)
/*
* mpp notify event flags
* When event happens mpp will signal deocder / encoder with different flag.
* These event will wake up the codec thread or hal thread
*/
#define MPP_INPUT_ENQUEUE (0x00000001)
#define MPP_OUTPUT_DEQUEUE (0x00000002)
#define MPP_INPUT_DEQUEUE (0x00000004)
#define MPP_OUTPUT_ENQUEUE (0x00000008)
#define MPP_RESET (0xFFFFFFFF)
/* mpp dec event flags */
#define MPP_DEC_NOTIFY_PACKET_ENQUEUE (MPP_INPUT_ENQUEUE)
#define MPP_DEC_NOTIFY_FRAME_DEQUEUE (MPP_OUTPUT_DEQUEUE)
#define MPP_DEC_NOTIFY_EXT_BUF_GRP_READY (0x00000010)
#define MPP_DEC_NOTIFY_INFO_CHG_DONE (0x00000020)
#define MPP_DEC_NOTIFY_BUFFER_VALID (0x00000040)
#define MPP_DEC_NOTIFY_TASK_ALL_DONE (0x00000080)
#define MPP_DEC_NOTIFY_TASK_HND_VALID (0x00000100)
#define MPP_DEC_NOTIFY_TASK_PREV_DONE (0x00000200)
#define MPP_DEC_NOTIFY_BUFFER_MATCH (0x00000400)
#define MPP_DEC_RESET (MPP_RESET)
/* mpp enc event flags */
#define MPP_ENC_NOTIFY_FRAME_ENQUEUE (MPP_INPUT_ENQUEUE)
#define MPP_ENC_NOTIFY_PACKET_DEQUEUE (MPP_OUTPUT_DEQUEUE)
#define MPP_ENC_NOTIFY_FRAME_DEQUEUE (MPP_INPUT_DEQUEUE)
#define MPP_ENC_NOTIFY_PACKET_ENQUEUE (MPP_OUTPUT_ENQUEUE)
#define MPP_ENC_CONTROL (0x00000010)
#define MPP_ENC_RESET (MPP_RESET)
/*
* mpp hierarchy
*
* mpp layer create mpp_dec or mpp_dec instance
* mpp_dec create its parser and hal module
* mpp_enc create its control and hal module
*
* +-------+
* | |
* +-------------+ mpp +-------------+
* | | | |
* | +-------+ |
* | |
* | |
* | |
* +-----+-----+ +-----+-----+
* | | | |
* +---+ mpp_dec +--+ +--+ mpp_enc +---+
* | | | | | | | |
* | +-----------+ | | +-----------+ |
* | | | |
* | | | |
* | | | |
* +-------v------+ +-----v-----+ +-----v-----+ +------v-------+
* | | | | | | | |
* | dec_parser | | dec_hal | | enc_hal | | enc_control |
* | | | | | | | |
* +--------------+ +-----------+ +-----------+ +--------------+
*/
#ifdef __cplusplus
class Mpp
{
public:
Mpp();
~Mpp();
MPP_RET init(MppCtxType type, MppCodingType coding);
MPP_RET put_packet(MppPacket packet);
MPP_RET get_frame(MppFrame *frame);
MPP_RET put_frame(MppFrame frame);
MPP_RET get_packet(MppPacket *packet);
MPP_RET poll(MppPortType type, MppPollType timeout);
MPP_RET dequeue(MppPortType type, MppTask *task);
MPP_RET enqueue(MppPortType type, MppTask task);
MPP_RET reset();
MPP_RET control(MpiCmd cmd, MppParam param);
MPP_RET notify(RK_U32 flag);
MPP_RET notify(MppBufferGroup group);
mpp_list *mPackets;
mpp_list *mFrames;
mpp_list *mTimeStamps;
/* counters for debug */
RK_U32 mPacketPutCount;
RK_U32 mPacketGetCount;
RK_U32 mFramePutCount;
RK_U32 mFrameGetCount;
RK_U32 mTaskPutCount;
RK_U32 mTaskGetCount;
/*
* packet buffer group
* - packets in I/O, can be ion buffer or normal buffer
* frame buffer group
* - frames in I/O, normally should be a ion buffer group
*/
MppBufferGroup mPacketGroup;
MppBufferGroup mFrameGroup;
RK_U32 mExternalFrameGroup;
/*
* Mpp task queue for advance task mode
*/
MppPort mInputPort;
MppPort mOutputPort;
MppTaskQueue mInputTaskQueue;
MppTaskQueue mOutputTaskQueue;
MppPollType mInputTimeout;
MppPollType mOutputTimeout;
MppTask mInputTask;
MppDec mDec;
MppEnc mEnc;
RK_U32 mEncVersion;
private:
void clear();
MppCtxType mType;
MppCodingType mCoding;
RK_U32 mInitDone;
RK_U32 mMultiFrame;
RK_U32 mStatus;
/* decoder paramter before init */
RK_U32 mParserFastMode;
RK_U32 mParserNeedSplit;
RK_U32 mParserInternalPts; /* for MPEG2/MPEG4 */
/* backup extra packet for seek */
MppPacket mExtraPacket;
/* dump info for debug */
MppDump mDump;
MPP_RET control_mpp(MpiCmd cmd, MppParam param);
MPP_RET control_osal(MpiCmd cmd, MppParam param);
MPP_RET control_codec(MpiCmd cmd, MppParam param);
MPP_RET control_dec(MpiCmd cmd, MppParam param);
MPP_RET control_enc(MpiCmd cmd, MppParam param);
MPP_RET control_isp(MpiCmd cmd, MppParam param);
Mpp(const Mpp &);
Mpp &operator=(const Mpp &);
};
extern "C" {
}
#endif
#endif /*__MPP_H__*/
+34
View File
@@ -0,0 +1,34 @@
/*
*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_2STR_H__
#define __MPP_2STR_H__
#include "rk_type.h"
#ifdef __cplusplus
extern "C" {
#endif
const char *strof_ctx_type(MppCtxType type);
const char *strof_coding_type(MppCodingType coding);
#ifdef __cplusplus
}
#endif
#endif
+55
View File
@@ -0,0 +1,55 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_ALLOCATOR_H__
#define __MPP_ALLOCATOR_H__
#include "rk_type.h"
#include "mpp_buffer.h"
typedef void *MppAllocator;
typedef struct MppAllocatorCfg_t {
// input
size_t alignment;
RK_U32 flags;
} MppAllocatorCfg;
typedef struct MppAllocatorApi_t {
RK_U32 size;
RK_U32 version;
MPP_RET (*alloc)(MppAllocator allocator, MppBufferInfo *data);
MPP_RET (*free)(MppAllocator allocator, MppBufferInfo *data);
MPP_RET (*import)(MppAllocator allocator, MppBufferInfo *data);
MPP_RET (*release)(MppAllocator allocator, MppBufferInfo *data);
MPP_RET (*mmap)(MppAllocator allocator, MppBufferInfo *data);
} MppAllocatorApi;
#ifdef __cplusplus
extern "C" {
#endif
MPP_RET mpp_allocator_get(MppAllocator *allocator,
MppAllocatorApi **api, MppBufferType type);
MPP_RET mpp_allocator_put(MppAllocator *allocator);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_ALLOCATOR_H__*/
+50
View File
@@ -0,0 +1,50 @@
/*
*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_BITPUT_H__
#define __MPP_BITPUT_H__
#include <stdio.h>
#include <assert.h>
#include "rk_type.h"
#include "mpp_log.h"
#include "mpp_common.h"
#include "mpp_err.h"
typedef struct bitput_ctx_t {
RK_U32 buflen; //!< max buf length, 64bit uint
RK_U32 index; //!< current uint position
RK_U64 *pbuf; //!< outpacket data
RK_U64 bvalue; //!< buffer value, 64 bit
RK_U8 bitpos; //!< bit pos in 64bit
RK_U32 size; //!< data size,except header
} BitputCtx_t;
#ifdef __cplusplus
extern "C" {
#endif
RK_S32 mpp_set_bitput_ctx(BitputCtx_t *bp, RK_U64 *data, RK_U32 len);
void mpp_put_bits(BitputCtx_t *bp, RK_U64 invalue, RK_S32 lbits);
void mpp_put_align(BitputCtx_t *bp, RK_S32 align_bits, int flag);
#ifdef __cplusplus
}
#endif
#endif
+167
View File
@@ -0,0 +1,167 @@
/*
*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_BITREAD_H__
#define __MPP_BITREAD_H__
#include <stdio.h>
#include <assert.h>
#include "mpp_log.h"
#include "mpp_common.h"
#include "mpp_err.h"
#define __BITREAD_ERR __bitread_error
#define READ_ONEBIT(bitctx, out)\
do {\
RK_S32 _out; \
bitctx->ret = mpp_read_bits(bitctx, 1, &_out); \
if (!bitctx->ret) { *out = _out; }\
else { goto __BITREAD_ERR; }\
} while (0)
#define READ_BITS(bitctx, num_bits, out)\
do {\
RK_S32 _out; \
bitctx->ret = mpp_read_bits(bitctx, num_bits, &_out); \
if (!bitctx->ret) { *out = _out; }\
else { goto __BITREAD_ERR; }\
} while (0)
#define READ_BITS_LONG(bitctx, num_bits, out)\
do {\
RK_U32 _out; \
bitctx->ret = mpp_read_longbits(bitctx, num_bits, &_out); \
if (!bitctx->ret) { *out = _out; }\
else { goto __BITREAD_ERR; }\
} while (0)
#define SHOW_BITS(bitctx, num_bits, out)\
do {\
RK_S32 _out; \
bitctx->ret = mpp_show_bits(bitctx, num_bits, &_out); \
if (!bitctx->ret) { *out = _out; }\
else { goto __BITREAD_ERR; }\
} while (0)
#define SHOW_BITS_LONG(bitctx, num_bits, out)\
do {\
RK_U32 _out; \
bitctx->ret = mpp_show_longbits(bitctx, num_bits, &_out); \
if (!bitctx->ret) { *out = _out; }\
else { goto __BITREAD_ERR; }\
} while (0)
#define SKIP_BITS(bitctx, num_bits)\
do {\
bitctx->ret = mpp_skip_bits(bitctx, num_bits); \
if (bitctx->ret) { goto __BITREAD_ERR; }\
} while (0)
#define SKIP_BITS_LONG(bitctx, num_bits)\
do {\
bitctx->ret = mpp_skip_longbits(bitctx, num_bits); \
if (bitctx->ret) { goto __BITREAD_ERR; }\
} while (0)
#define READ_UE(bitctx, out)\
do {\
RK_U32 _out; \
bitctx->ret = mpp_read_ue(bitctx, &_out); \
if (!bitctx->ret) { *out = _out; }\
else { goto __BITREAD_ERR; }\
} while (0)
#define READ_SE(bitctx, out)\
do {\
RK_S32 _out; \
bitctx->ret = mpp_read_se(bitctx, &_out); \
if (!bitctx->ret) { *out = _out; }\
else { goto __BITREAD_ERR; }\
} while (0)
typedef struct bitread_ctx_t {
// Pointer to the next unread (not in curr_byte_) byte in the stream.
RK_U8 *data_;
// Bytes left in the stream (without the curr_byte_).
RK_U32 bytes_left_;
// Contents of the current byte; first unread bit starting at position
// 8 - num_remaining_bits_in_curr_byte_ from MSB.
RK_S64 curr_byte_;
// Number of bits remaining in curr_byte_
RK_S32 num_remaining_bits_in_curr_byte_;
// Used in emulation prevention three byte detection (see spec).
// Initially set to 0xffff to accept all initial two-byte sequences.
RK_S64 prev_two_bytes_;
// Number of emulation presentation bytes (0x000003) we met.
RK_S64 emulation_prevention_bytes_;
// count PPS SPS SEI read bits
RK_S32 used_bits;
RK_U8 *buf;
RK_S32 buf_len;
// ctx
MPP_RET ret;
RK_S32 need_prevention_detection;
} BitReadCtx_t;
#ifdef __cplusplus
extern "C" {
#endif
//!< set bit read context
void mpp_set_bitread_ctx(BitReadCtx_t *bitctx, RK_U8 *data, RK_S32 size);
//!< Read bits (1-31)
MPP_RET mpp_read_bits(BitReadCtx_t *bitctx, RK_S32 num_bits, RK_S32 *out);
//!< Read bits (1-32)
MPP_RET mpp_read_longbits(BitReadCtx_t *bitctx, RK_S32 num_bits, RK_U32 *out);
//!< Show bits (1-31)
MPP_RET mpp_show_bits(BitReadCtx_t *bitctx, RK_S32 num_bits, RK_S32 *out);
//!< Show bits (1-32)
MPP_RET mpp_show_longbits(BitReadCtx_t *bitctx, RK_S32 num_bits, RK_U32 *out);
//!< skip bits(1-31)
MPP_RET mpp_skip_bits(BitReadCtx_t *bitctx, RK_S32 num_bits);
//!< skip bits(1-32)
MPP_RET mpp_skip_longbits(BitReadCtx_t *bitctx, RK_S32 num_bits);
//!< read ue(1-32)
MPP_RET mpp_read_ue(BitReadCtx_t *bitctx, RK_U32* val);
//!< read se(1-31)
MPP_RET mpp_read_se(BitReadCtx_t *bitctx, RK_S32* val);
//!< set whether detect 0x03 (used in h264 and h265)
void mpp_set_pre_detection(BitReadCtx_t *bitctx);
//!< check whether has more rbsp data(used in h264)
RK_U32 mpp_has_more_rbsp_data(BitReadCtx_t * bitctx);
//!< align bits and get current pointer
RK_U8 *mpp_align_get_bits(BitReadCtx_t *bitctx);
#ifdef __cplusplus
}
#endif
#endif /* __MPP_BITREAD_H__ */
+67
View File
@@ -0,0 +1,67 @@
/*
* Copyright 2015 - 2017 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_BITWRITER_H__
#define __MPP_BITWRITER_H__
#include "rk_type.h"
#include "mpp_err.h"
/*
* Mpp bitstream writer for H.264/H.265
*/
typedef struct MppWriteCtx_t {
RK_U8 *buffer; /* point to first byte of stream */
RK_U8 *stream; /* Pointer to next byte of stream */
RK_U32 size; /* Byte size of stream buffer */
RK_U32 byte_cnt; /* Byte counter */
RK_U32 byte_buffer; /* Byte buffer */
RK_U32 buffered_bits; /* Amount of bits in byte buffer, [0-7] */
RK_U32 zero_bytes; /* Amount of consecutive zero bytes */
RK_S32 overflow; /* This will signal a buffer overflow */
RK_U32 emul_cnt; /* Counter for emulation_3_byte, needed in SEI */
} MppWriteCtx;
MPP_RET mpp_writer_init(MppWriteCtx *ctx, void *p, RK_S32 size);
MPP_RET mpp_writer_reset(MppWriteCtx *ctx);
/* check overflow status */
MPP_RET mpp_writer_status(MppWriteCtx *ctx);
/* write raw bit without emulation prevention 0x03 byte */
void mpp_writer_put_raw_bits(MppWriteCtx *ctx, RK_S32 val, RK_S32 len);
/* write bit with emulation prevention 0x03 byte */
void mpp_writer_put_bits(MppWriteCtx *ctx, RK_S32 val, RK_S32 len);
/* insert zero bits until byte-aligned */
void mpp_writer_align_zero(MppWriteCtx *ctx);
/* insert one bits until byte-aligned */
void mpp_writer_align_one(MppWriteCtx *ctx);
/* insert one bit then pad to byte-align with zero */
void mpp_writer_trailing(MppWriteCtx * ctx);
void mpp_writer_put_ue(MppWriteCtx *ctx, RK_U32 val);
void mpp_writer_put_se(MppWriteCtx *ctx, RK_S32 val);
RK_S32 mpp_writer_bytes(MppWriteCtx *ctx);
RK_S32 mpp_writer_bits(MppWriteCtx *ctx);
RK_S32 mpp_exp_golomb_signed(RK_S32 val);
#endif /* __MPP_BITWRITER_H__ */
+259
View File
@@ -0,0 +1,259 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_BUF_SLOT_H__
#define __MPP_BUF_SLOT_H__
#include "mpp_frame.h"
/*
* mpp_dec will alloc 18 decoded picture buffer slot
* buffer slot is for transferring information between parser / mpp/ hal
* it represent the dpb routine in logical
*
* basic working flow:
*
* buf_slot parser hal
*
* + + +
* | | |
* | +--------+--------+ |
* | | | |
* | | do parsing here | |
* | | | |
* | +--------+--------+ |
* | | |
* | get_slot | |
* | <--------------------------+ |
* | get unused dpb slot for | |
* | current decoder output | |
* | | |
* | update dpb refer status | |
* | <--------------------------+ |
* | parser will send marking | |
* | operation to dpb slot | |
* | including: | |
* | ref/unref/output/display | |
* | | |
* | | |
* | | set buffer status to hal |
* +-------------------------------------------------------> |
* | | |
* | | +--------+--------+
* | | | |
* | | | reg generation |
* | | | |
* | | +--------+--------+
* | | |
* | | get buffer address info |
* | <-------------------------------------------------------+
* | | used buffer index to get |
* | | physical address or iommu |
* | | address for hardware |
* | | |
* | | +--------+--------+
* | | | |
* | | | set/wait hw |
* | | | |
* | | +--------+--------+
* | | |
* | | update the output status |
* | <-------------------------------------------------------+
* | | mark picture is available |
* | | for output and generate |
* | | output frame information |
* + + +
*
* typical buffer status transfer
*
* -> unused initial
* -> set_hw_dst by parser
* -> set_buffer by mpp - do alloc buffer here / info change here
* -> clr_hw_dst by hal()
*
* next four step can be different order
* -> set_dpb_ref by parser
* -> set_display by parser - slot ready to display, can be output
* -> clr_display by mpp - output buffer struct
* -> clr_dpb_ref by parser
*
* -> set_unused automatic clear and dec buffer ref
*
*/
typedef void* MppBufSlots;
/*
* buffer slot index range is 0~254, 0xff (255) will indicated the invalid index
*/
#define SLOT_IDX_BUTT (0xff)
#ifdef __cplusplus
extern "C" {
#endif
/*
* called by mpp context
*
* init / deinit - normal initialize and de-initialize function
* setup - called by parser when slot information changed
* is_changed - called by mpp to detect whether info change flow is needed
* ready - called by mpp when info changed is done
*
* typical info change flow:
*
* mpp_buf_slot_setup called in parser with changed equal to 1
* mpp_buf_slot_is_changed called in mpp and found info change
*
* do info change outside
*
* mpp_buf_slot_ready called in mpp when info change is done
*
*/
MPP_RET mpp_buf_slot_init(MppBufSlots *slots);
MPP_RET mpp_buf_slot_deinit(MppBufSlots slots);
MPP_RET mpp_buf_slot_setup(MppBufSlots slots, RK_S32 count);
RK_U32 mpp_buf_slot_is_changed(MppBufSlots slots);
MPP_RET mpp_buf_slot_ready(MppBufSlots slots);
size_t mpp_buf_slot_get_size(MppBufSlots slots);
/*
* called by parser
*
* mpp_buf_slot_get_unused
* - parser need a new slot for output, on field mode alloc one buffer for two field
*
* mpp_buf_slot_set_dpb_ref
* - mark a slot to be used as reference frame in dpb
*
* mpp_buf_slot_clr_dpb_ref
* - mark a slot to be unused as reference frame and remove from dpb
*
* mpp_buf_slot_set_hw_dst
* - mark a slot to be output destination buffer
* - NOTE: the frame information MUST be set here
*
* mpp_buf_slot_set_display
* - mark a slot to be can be display
* - NOTE: set display will generate a MppFrame for buffer slot internal usage
* for example store pts / buffer address, etc.
*
* mpp_buf_slot_inc_hw_ref
* - MUST be called once when one slot is used in hardware decoding as reference frame
*
* called by mpp
*
* mpp_buf_slot_get_hw_dst
* - mpp_dec need to get the output slot index to check buffer status
*
* mpp_buf_slot_clr_display
* - mark a slot has been send out to display
* - NOTE: will be called inside mpp_buf_slot_get_display
*
* called by hal
*
* mpp_buf_slot_clr_hw_dst
* - mark a slot's buffer is already decoded by hardware
* - NOTE: this call will clear used as output flag
*
* mpp_buf_slot_dec_hw_ref
* - when hal finished on hardware decoding it MUST be called once for each used slot
*/
MPP_RET mpp_buf_slot_get_unused(MppBufSlots slots, RK_S32 *index);
/*
* mpp_buf_slot_set_buffer
* - called by dec thread when find a output index has not buffer
*
* mpp_buf_slot_get_buffer
* - called by hal module on register generation
*
* mpp_buf_slot_get_display
* - called by hal thread to output a display slot's frame info
* NOTE: get display will generate a new MppFrame for external mpp_frame_deinit call
* So that external mpp_frame_deinit will not release the MppFrame used in buf_slot
*/
/*
* NOTE:
* buffer slot will be used both for frame and packet
* when buffer slot is used for packet management only inc_hw_ref and dec_hw_ref is used
*/
typedef enum SlotUsageType_e {
SLOT_CODEC_READY, // bit flag for buffer is prepared by codec
SLOT_CODEC_USE, // bit flag for buffer is used as reference by codec
SLOT_HAL_INPUT, // counter for buffer is used as hardware input
SLOT_HAL_OUTPUT, // counter + bit flag for buffer is used as hardware output
SLOT_QUEUE_USE, // bit flag for buffer is hold in different queues
SLOT_USAGE_BUTT,
} SlotUsageType;
MPP_RET mpp_buf_slot_set_flag(MppBufSlots slots, RK_S32 index, SlotUsageType type);
MPP_RET mpp_buf_slot_clr_flag(MppBufSlots slots, RK_S32 index, SlotUsageType type);
// TODO: can be extended here
typedef enum SlotQueueType_e {
QUEUE_OUTPUT, // queue for mpp output to user
QUEUE_DISPLAY, // queue for decoder output display
QUEUE_DEINTERLACE, // queue for deinterlace process
QUEUE_COLOR_CONVERT, // queue for color convertion process
QUEUE_BUTT,
} SlotQueueType;
MPP_RET mpp_buf_slot_enqueue(MppBufSlots slots, RK_S32 index, SlotQueueType type);
MPP_RET mpp_buf_slot_dequeue(MppBufSlots slots, RK_S32 *index, SlotQueueType type);
typedef enum SlotPropType_e {
SLOT_EOS,
SLOT_FRAME,
SLOT_BUFFER,
SLOT_FRAME_PTR,
SLOT_PROP_BUTT,
} SlotPropType;
MPP_RET mpp_buf_slot_set_prop(MppBufSlots slots, RK_S32 index, SlotPropType type, void *val);
MPP_RET mpp_buf_slot_get_prop(MppBufSlots slots, RK_S32 index, SlotPropType type, void *val);
typedef enum SlotsPropType_e {
SLOTS_EOS,
SLOTS_NUMERATOR, // numerator of buffer size scale ratio
SLOTS_DENOMINATOR, // denominator of buffer size scale ratio
SLOTS_HOR_ALIGN, // input must be buf_align function pointer
SLOTS_VER_ALIGN, // input must be buf_align function pointer
SLOTS_LEN_ALIGN,
SLOTS_COUNT,
SLOTS_SIZE,
SLOTS_FRAME_INFO,
SLOTS_PROP_BUTT,
} SlotsPropType;
typedef RK_U32 (*AlignFunc)(RK_U32 val);
RK_U32 mpp_slots_is_empty(MppBufSlots slots, SlotQueueType type);
RK_S32 mpp_slots_get_used_count(MppBufSlots slots);
RK_S32 mpp_slots_get_unused_count(MppBufSlots slots);
MPP_RET mpp_slots_set_prop(MppBufSlots slots, SlotsPropType type, void *val);
MPP_RET mpp_slots_get_prop(MppBufSlots slots, SlotsPropType type, void *val);
MPP_RET mpp_buf_slot_reset(MppBufSlots slots, RK_S32 index); //rest slot status when info_change no ok
// special one for generate default frame to slot at index and return pointer
MPP_RET mpp_buf_slot_default_info(MppBufSlots slots, RK_S32 index, void *val);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_BUF_SLOT_H__*/
+316
View File
@@ -0,0 +1,316 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_BUFFER_H__
#define __MPP_BUFFER_H__
#include "rk_type.h"
#include "mpp_err.h"
/*
* MppBuffer module has several functions:
*
* 1. buffer get / put / reference management / external commit / get info.
* this part is the basic user interface for MppBuffer.
*
* function:
*
* mpp_buffer_get
* mpp_buffer_put
* mpp_buffer_inc_ref
* mpp_buffer_commit
* mpp_buffer_info_get
*
* 2. user buffer working flow control abstraction.
* buffer should attach to certain group, and buffer mode control the buffer usage flow.
* this part is also a part of user interface.
*
* function:
*
* mpp_buffer_group_get
* mpp_buffer_group_normal_get
* mpp_buffer_group_limit_get
* mpp_buffer_group_put
* mpp_buffer_group_limit_config
*
* 3. buffer allocator management
* this part is for allocator on different os, it does not have user interface
* it will support normal buffer, Android ion buffer, Linux v4l2 vb2 buffer
* user can only use MppBufferType to choose.
*
*/
/*
* mpp buffer group support two work flow mode:
*
* normal flow: all buffer are generated by MPP
* under this mode, buffer pool is maintained internally
*
* typical call flow:
*
* mpp_buffer_group_get() return A
* mpp_buffer_get(A) return a ref +1 -> used
* mpp_buffer_inc_ref(a) ref +1
* mpp_buffer_put(a) ref -1
* mpp_buffer_put(a) ref -1 -> unused
* mpp_buffer_group_put(A)
*
* commit flow: all buffer are commited out of MPP
* under this mode, buffers is commit by external api.
* normally MPP only use it but not generate it.
*
* typical call flow:
*
* ==== external allocator ====
* mpp_buffer_group_get() return A
* mpp_buffer_commit(A, x)
* mpp_buffer_commit(A, y)
*
* ======= internal user ======
* mpp_buffer_get(A) return a
* mpp_buffer_get(A) return b
* mpp_buffer_put(a)
* mpp_buffer_put(b)
*
* ==== external allocator ====
* mpp_buffer_group_put(A)
*
* NOTE: commit interface required group handle to record group information
*/
/*
* mpp buffer group has two buffer limit mode: normal and limit
*
* normal mode: allows any buffer size and always general new buffer is no unused buffer
* is available.
* This mode normally use with normal flow and is used for table / stream buffer
*
* limit mode : restrict the buffer's size and count in the buffer group. if try to calloc
* buffer with different size or extra count it will fail.
* This mode normally use with commit flow and is used for frame buffer
*/
/*
* NOTE: normal mode is recommanded to work with normal flow, working with limit mode is not.
* limit mode is recommanded to work with commit flow, working with normal mode is not.
*/
typedef enum {
MPP_BUFFER_INTERNAL,
MPP_BUFFER_EXTERNAL,
MPP_BUFFER_MODE_BUTT,
} MppBufferMode;
/*
* the mpp buffer has serval types:
*
* normal : normal malloc buffer for unit test or hardware simulation
* ion : use ion device under Android/Linux, MppBuffer will encapsulte ion file handle
* ext_dma : the DMABUF(DMA buffers) come from the application
* drm : use the drm device interface for memory management
*/
typedef enum {
MPP_BUFFER_TYPE_NORMAL,
MPP_BUFFER_TYPE_ION,
MPP_BUFFER_TYPE_EXT_DMA,
MPP_BUFFER_TYPE_DRM,
MPP_BUFFER_TYPE_BUTT,
} MppBufferType;
#define MPP_BUFFER_TYPE_MASK 0x0000FFFF
/*
* MPP_BUFFER_FLAGS cooperate with MppBufferType
* 16 high bits of MppBufferType are used in flags
*
* eg:
* DRM CMA buffer : MPP_BUFFER_TYPE_DRM | MPP_BUFFER_FLAGS_CONTIG
* = 0x00010003
* DRM SECURE buffer: MPP_BUFFER_TYPE_DRM | MPP_BUFFER_FLAGS_SECURE
* = 0x00080003
*
* flags originate from drm_rockchip_gem_mem_type
*/
#define MPP_BUFFER_FLAGS_MASK 0x000f0000 //ROCKCHIP_BO_MASK << 16
#define MPP_BUFFER_FLAGS_CONTIG 0x00010000 //ROCKCHIP_BO_CONTIG << 16
#define MPP_BUFFER_FLAGS_CACHABLE 0x00020000 //ROCKCHIP_BO_CACHABLE << 16
#define MPP_BUFFER_FLAGS_WC 0x00040000 //ROCKCHIP_BO_WC << 16
#define MPP_BUFFER_FLAGS_SECURE 0x00080000 //ROCKCHIP_BO_SECURE << 16
/*
* MppBufferInfo variable's meaning is different in different MppBufferType
*
* Common
* index - the buffer index used to track buffer in buffer pool
* size - the buffer size
*
* MPP_BUFFER_TYPE_NORMAL
*
* ptr - virtual address of normal malloced buffer
* fd - unused and set to -1, the allocator would return its
* internal buffer counter number
*
* MPP_BUFFER_TYPE_ION
*
* ptr - virtual address of ion buffer in user space
* hnd - ion handle in user space
* fd - ion buffer file handle for map / unmap
*
*/
typedef struct MppBufferInfo_t {
MppBufferType type;
size_t size;
void *ptr;
void *hnd;
int fd;
int index;
} MppBufferInfo;
#define BUFFER_GROUP_SIZE_DEFAULT (SZ_1M*80)
/*
* mpp_buffer_import_with_tag(MppBufferGroup group, MppBufferInfo *info, MppBuffer *buffer)
*
* 1. group - specified the MppBuffer to be attached to.
* group can be NULL then this buffer will attached to default legecy group
* Default to NULL on mpp_buffer_import case
*
* 2. info - input information for the output MppBuffer
* info can NOT be NULL. It must contain at least one of ptr/fd.
*
* 3. buffer - generated MppBuffer from MppBufferInfo.
* buffer can be NULL then the buffer is commit to group with unused status.
* Otherwise generated buffer will be directly got and ref_count increased.
* Default to NULL on mpp_buffer_commit case
*
* mpp_buffer_commit usage:
*
* Add a external buffer info to group. This buffer will be on unused status.
* Typical usage is on Android. MediaPlayer gralloc Graphic buffer then commit these buffer
* to decoder's buffer group. Then decoder will recycle these buffer and return buffer reference
* to MediaPlayer for display.
*
* mpp_buffer_import usage:
*
* Transfer a external buffer info to MppBuffer but it is not expected to attached to certain
* buffer group. So the group is set to NULL. Then this buffer can be used for MppFrame/MppPacket.
* Typical usage is for image processing. Image processing normally will be a oneshot operation
* It does not need complicated group management. But in other hand mpp still need to know the
* imported buffer is leak or not and trace its usage inside mpp process. So we attach this kind
* of buffer to default misc buffer group for management.
*/
#define mpp_buffer_commit(group, info) \
mpp_buffer_import_with_tag(group, info, NULL, MODULE_TAG, __FUNCTION__)
#define mpp_buffer_import(buffer, info) \
mpp_buffer_import_with_tag(NULL, info, buffer, MODULE_TAG, __FUNCTION__)
#define mpp_buffer_get(group, buffer, size) \
mpp_buffer_get_with_tag(group, buffer, size, MODULE_TAG, __FUNCTION__)
#define mpp_buffer_put(buffer) \
mpp_buffer_put_with_caller(buffer, __FUNCTION__)
#define mpp_buffer_inc_ref(buffer) \
mpp_buffer_inc_ref_with_caller(buffer, __FUNCTION__)
#define mpp_buffer_info_get(buffer, info) \
mpp_buffer_info_get_with_caller(buffer, info, __FUNCTION__)
#define mpp_buffer_read(buffer, offset, data, size) \
mpp_buffer_read_with_caller(buffer, offset, data, size, __FUNCTION__)
#define mpp_buffer_write(buffer, offset, data, size) \
mpp_buffer_write_with_caller(buffer, offset, data, size, __FUNCTION__)
#define mpp_buffer_get_ptr(buffer) \
mpp_buffer_get_ptr_with_caller(buffer, __FUNCTION__)
#define mpp_buffer_get_fd(buffer) \
mpp_buffer_get_fd_with_caller(buffer, __FUNCTION__)
#define mpp_buffer_get_size(buffer) \
mpp_buffer_get_size_with_caller(buffer, __FUNCTION__)
#define mpp_buffer_get_index(buffer) \
mpp_buffer_get_index_with_caller(buffer, __FUNCTION__)
#define mpp_buffer_set_index(buffer, index) \
mpp_buffer_set_index_with_caller(buffer, index, __FUNCTION__)
#define mpp_buffer_get_offset(buffer) \
mpp_buffer_get_offset_with_caller(buffer, __FUNCTION__)
#define mpp_buffer_set_offset(buffer, offset) \
mpp_buffer_set_offset_with_caller(buffer, offset, __FUNCTION__)
#define mpp_buffer_group_get_internal(group, type, ...) \
mpp_buffer_group_get(group, type, MPP_BUFFER_INTERNAL, MODULE_TAG, __FUNCTION__)
#define mpp_buffer_group_get_external(group, type, ...) \
mpp_buffer_group_get(group, type, MPP_BUFFER_EXTERNAL, MODULE_TAG, __FUNCTION__)
#ifdef __cplusplus
extern "C" {
#endif
/*
* MppBuffer interface
* these interface will change value of group and buffer so before calling functions
* parameter need to be checked.
*
* IMPORTANT:
* mpp_buffer_import_with_tag - compounded interface for commit and import
*
*/
MPP_RET mpp_buffer_import_with_tag(MppBufferGroup group, MppBufferInfo *info, MppBuffer *buffer,
const char *tag, const char *caller);
MPP_RET mpp_buffer_get_with_tag(MppBufferGroup group, MppBuffer *buffer, size_t size,
const char *tag, const char *caller);
MPP_RET mpp_buffer_put_with_caller(MppBuffer buffer, const char *caller);
MPP_RET mpp_buffer_inc_ref_with_caller(MppBuffer buffer, const char *caller);
MPP_RET mpp_buffer_info_get_with_caller(MppBuffer buffer, MppBufferInfo *info, const char *caller);
MPP_RET mpp_buffer_read_with_caller(MppBuffer buffer, size_t offset, void *data, size_t size, const char *caller);
MPP_RET mpp_buffer_write_with_caller(MppBuffer buffer, size_t offset, void *data, size_t size, const char *caller);
void *mpp_buffer_get_ptr_with_caller(MppBuffer buffer, const char *caller);
int mpp_buffer_get_fd_with_caller(MppBuffer buffer, const char *caller);
size_t mpp_buffer_get_size_with_caller(MppBuffer buffer, const char *caller);
int mpp_buffer_get_index_with_caller(MppBuffer buffer, const char *caller);
MPP_RET mpp_buffer_set_index_with_caller(MppBuffer buffer, int index, const char *caller);
size_t mpp_buffer_get_offset_with_caller(MppBuffer buffer, const char *caller);
MPP_RET mpp_buffer_set_offset_with_caller(MppBuffer buffer, size_t offset, const char *caller);
MPP_RET mpp_buffer_group_get(MppBufferGroup *group, MppBufferType type, MppBufferMode mode,
const char *tag, const char *caller);
MPP_RET mpp_buffer_group_put(MppBufferGroup group);
MPP_RET mpp_buffer_group_clear(MppBufferGroup group);
RK_S32 mpp_buffer_group_unused(MppBufferGroup group);
size_t mpp_buffer_group_usage(MppBufferGroup group);
MppBufferMode mpp_buffer_group_mode(MppBufferGroup group);
MppBufferType mpp_buffer_group_type(MppBufferGroup group);
/*
* size : 0 - no limit, other - max buffer size
* count : 0 - no limit, other - max buffer count
*/
MPP_RET mpp_buffer_group_limit_config(MppBufferGroup group, size_t size, RK_S32 count);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_BUFFER_H__*/
+163
View File
@@ -0,0 +1,163 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_BUFFER_IMPL_H__
#define __MPP_BUFFER_IMPL_H__
#include "mpp_list.h"
#include "mpp_common.h"
#include "mpp_allocator.h"
#define MPP_BUF_DBG_FUNCTION (0x00000001)
#define MPP_BUF_DBG_OPS_RUNTIME (0x00000002)
#define MPP_BUF_DBG_OPS_HISTORY (0x00000004)
#define MPP_BUF_DBG_CLR_ON_EXIT (0x00000010)
#define MPP_BUF_DBG_DUMP_ON_EXIT (0x00000020)
#define MPP_BUF_DBG_CHECK_SIZE (0x00000100)
#define mpp_buf_dbg(flag, fmt, ...) _mpp_dbg(mpp_buffer_debug, flag, fmt, ## __VA_ARGS__)
#define mpp_buf_dbg_f(flag, fmt, ...) _mpp_dbg_f(mpp_buffer_debug, flag, fmt, ## __VA_ARGS__)
#define MPP_BUF_FUNCTION_ENTER() mpp_buf_dbg_f(MPP_BUF_DBG_FUNCTION, "enter\n")
#define MPP_BUF_FUNCTION_LEAVE() mpp_buf_dbg_f(MPP_BUF_DBG_FUNCTION, "leave\n")
#define MPP_BUF_FUNCTION_LEAVE_OK() mpp_buf_dbg_f(MPP_BUF_DBG_FUNCTION, "success\n")
#define MPP_BUF_FUNCTION_LEAVE_FAIL() mpp_buf_dbg_f(MPP_BUF_DBG_FUNCTION, "failed\n")
typedef struct MppBufferImpl_t MppBufferImpl;
typedef struct MppBufferGroupImpl_t MppBufferGroupImpl;
typedef void (*MppBufCallback)(void *, void *);
// use index instead of pointer to avoid invalid pointer
struct MppBufferImpl_t {
char tag[MPP_TAG_SIZE];
const char *caller;
RK_U32 group_id;
RK_S32 buffer_id;
MppBufferMode mode;
MppBufferInfo info;
size_t offset;
/* used for buf on group reset mode
set disard value to 1 when frame refcount no zero ,
we will delay relesase buffer after refcount to zero,
not put this buf to unused list
*/
RK_S32 discard;
// used flag is for used/unused list detection
RK_U32 used;
RK_U32 internal;
RK_S32 ref_count;
struct list_head list_status;
};
struct MppBufferGroupImpl_t {
char tag[MPP_TAG_SIZE];
const char *caller;
RK_U32 group_id;
MppBufferMode mode;
MppBufferType type;
// used in limit mode only
size_t limit_size;
RK_S32 limit_count;
// status record
size_t limit;
size_t usage;
RK_S32 buffer_id;
RK_S32 buffer_count;
RK_S32 count_used;
RK_S32 count_unused;
MppAllocator allocator;
MppAllocatorApi *alloc_api;
// thread that will be signal on buffer return
MppBufCallback callback;
void *arg;
// buffer force clear mode flag
RK_U32 clear_on_exit;
// is_orphan: 0 - normal group 1 - orphan group
RK_U32 is_orphan;
// buffer log function
RK_U32 log_runtime_en;
RK_U32 log_history_en;
RK_U32 log_count;
struct list_head list_logs;
// link to the other MppBufferGroupImpl
struct list_head list_group;
// link to list_status in MppBufferImpl
struct list_head list_used;
struct list_head list_unused;
};
#ifdef __cplusplus
extern "C" {
#endif
extern RK_U32 mpp_buffer_debug;
/*
* mpp_buffer_create : create a unused buffer with parameter tag/size/data
* if input buffer is NULL then buffer will be register to unused list
* otherwise the buffer will be register to used list and set to paramter buffer
*
* mpp_buffer_mmap : The created mpp_buffer can not be accessed directly.
* It required map to access. This is an optimization
* for reducing virtual memory usage.
*
* mpp_buffer_get_unused : get unused buffer with size. it will first search
* the unused list. if failed it will create on from
* group allocator.
*
* mpp_buffer_ref_inc : increase buffer's reference counter. if it is unused
* then it will be moved to used list.
*
* mpp_buffer_ref_dec : decrease buffer's reference counter. if the reference
* reduce to zero buffer will be moved to unused list.
*
* normal call flow will be like this:
*
* mpp_buffer_create - create a unused buffer
* mpp_buffer_get_unused - get the unused buffer
* mpp_buffer_ref_inc/dec - use the buffer
* mpp_buffer_destory - destroy the buffer
*/
MPP_RET mpp_buffer_create(const char *tag, const char *caller, MppBufferGroupImpl *group, MppBufferInfo *info, MppBufferImpl **buffer);
MPP_RET mpp_buffer_mmap(MppBufferImpl *buffer, const char* caller);
MPP_RET mpp_buffer_ref_inc(MppBufferImpl *buffer, const char* caller);
MPP_RET mpp_buffer_ref_dec(MppBufferImpl *buffer, const char* caller);
MppBufferImpl *mpp_buffer_get_unused(MppBufferGroupImpl *p, size_t size);
RK_U32 mpp_buffer_to_addr(MppBuffer buffer, size_t offset);
MPP_RET mpp_buffer_group_init(MppBufferGroupImpl **group, const char *tag, const char *caller, MppBufferMode mode, MppBufferType type);
MPP_RET mpp_buffer_group_deinit(MppBufferGroupImpl *p);
MPP_RET mpp_buffer_group_reset(MppBufferGroupImpl *p);
MPP_RET mpp_buffer_group_set_callback(MppBufferGroupImpl *p,
MppBufCallback callback, void *arg);
// mpp_buffer_group helper function
void mpp_buffer_group_dump(MppBufferGroupImpl *p);
void mpp_buffer_service_dump();
MppBufferGroupImpl *mpp_buffer_get_misc_group(MppBufferMode mode, MppBufferType type);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_BUFFER_IMPL_H__*/
+219
View File
@@ -0,0 +1,219 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_COMMON_H__
#define __MPP_COMMON_H__
#include "rk_type.h"
#define MPP_TAG_SIZE 32
#define MPP_ABS(x) ((x) < (0) ? -(x) : (x))
#define MPP_MAX(a, b) ((a) > (b) ? (a) : (b))
#define MPP_MAX3(a, b, c) MPP_MAX(MPP_MAX(a,b),c)
#define MPP_MAX4(a, b, c, d) MPP_MAX((a), MPP_MAX3((b), (c), (d)))
#define MPP_MIN(a,b) ((a) > (b) ? (b) : (a))
#define MPP_MIN3(a,b,c) MPP_MIN(MPP_MIN(a,b),c)
#define MPP_MIN4(a, b, c, d) MPP_MIN((a), MPP_MIN3((b), (c), (d)))
#define MPP_DIV(a, b) ((b) ? (a) / (b) : (a))
#define MPP_CLIP3(l, h, v) ((v) < (l) ? (l) : ((v) > (h) ? (h) : (v)))
#define MPP_SIGN(a) ((a) < (0) ? (-1) : (1))
#define MPP_DIV_SIGN(a, b) (((a) + (MPP_SIGN(a) * (b)) / 2) / (b))
#define MPP_SWAP(type, a, b) do {type SWAP_tmp = b; b = a; a = SWAP_tmp;} while(0)
#define MPP_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
#define MPP_ALIGN(x, a) (((x)+(a)-1)&~((a)-1))
#define MPP_VSWAP(a, b) { a ^= b; b ^= a; a ^= b; }
#define MPP_RB16(x) ((((const RK_U8*)(x))[0] << 8) | ((const RK_U8*)(x))[1])
#define MPP_WB16(p, d) do { \
((RK_U8*)(p))[1] = (d); \
((RK_U8*)(p))[0] = (d)>>8; } while(0)
#define MPP_RL16(x) ((((const RK_U8*)(x))[1] << 8) | \
((const RK_U8*)(x))[0])
#define MPP_WL16(p, d) do { \
((RK_U8*)(p))[0] = (d); \
((RK_U8*)(p))[1] = (d)>>8; } while(0)
#define MPP_RB32(x) ((((const RK_U8*)(x))[0] << 24) | \
(((const RK_U8*)(x))[1] << 16) | \
(((const RK_U8*)(x))[2] << 8) | \
((const RK_U8*)(x))[3])
#define MPP_WB32(p, d) do { \
((RK_U8*)(p))[3] = (d); \
((RK_U8*)(p))[2] = (d)>>8; \
((RK_U8*)(p))[1] = (d)>>16; \
((RK_U8*)(p))[0] = (d)>>24; } while(0)
#define MPP_RL32(x) ((((const RK_U8*)(x))[3] << 24) | \
(((const RK_U8*)(x))[2] << 16) | \
(((const RK_U8*)(x))[1] << 8) | \
((const RK_U8*)(x))[0])
#define MPP_WL32(p, d) do { \
((RK_U8*)(p))[0] = (d); \
((RK_U8*)(p))[1] = (d)>>8; \
((RK_U8*)(p))[2] = (d)>>16; \
((RK_U8*)(p))[3] = (d)>>24; } while(0)
#define MPP_RB64(x) (((RK_U64)((const RK_U8*)(x))[0] << 56) | \
((RK_U64)((const RK_U8*)(x))[1] << 48) | \
((RK_U64)((const RK_U8*)(x))[2] << 40) | \
((RK_U64)((const RK_U8*)(x))[3] << 32) | \
((RK_U64)((const RK_U8*)(x))[4] << 24) | \
((RK_U64)((const RK_U8*)(x))[5] << 16) | \
((RK_U64)((const RK_U8*)(x))[6] << 8) | \
(RK_U64)((const RK_U8*)(x))[7])
#define MPP_WB64(p, d) do { \
((RK_U8*)(p))[7] = (d); \
((RK_U8*)(p))[6] = (d)>>8; \
((RK_U8*)(p))[5] = (d)>>16; \
((RK_U8*)(p))[4] = (d)>>24; \
((RK_U8*)(p))[3] = (d)>>32; \
((RK_U8*)(p))[2] = (d)>>40; \
((RK_U8*)(p))[1] = (d)>>48; \
((RK_U8*)(p))[0] = (d)>>56; } while(0)
#define MPP_RL64(x) (((RK_U64)((const RK_U8*)(x))[7] << 56) | \
((RK_U64)((const RK_U8*)(x))[6] << 48) | \
((RK_U64)((const RK_U8*)(x))[5] << 40) | \
((RK_U64)((const RK_U8*)(x))[4] << 32) | \
((RK_U64)((const RK_U8*)(x))[3] << 24) | \
((RK_U64)((const RK_U8*)(x))[2] << 16) | \
((RK_U64)((const RK_U8*)(x))[1] << 8) | \
(RK_U64)((const RK_U8*)(x))[0])
#define MPP_WL64(p, d) do { \
((RK_U8*)(p))[0] = (d); \
((RK_U8*)(p))[1] = (d)>>8; \
((RK_U8*)(p))[2] = (d)>>16; \
((RK_U8*)(p))[3] = (d)>>24; \
((RK_U8*)(p))[4] = (d)>>32; \
((RK_U8*)(p))[5] = (d)>>40; \
((RK_U8*)(p))[6] = (d)>>48; \
((RK_U8*)(p))[7] = (d)>>56; } while(0)
#define MPP_RB24(x) ((((const RK_U8*)(x))[0] << 16) | \
(((const RK_U8*)(x))[1] << 8) | \
((const RK_U8*)(x))[2])
#define MPP_WB24(p, d) do { \
((RK_U8*)(p))[2] = (d); \
((RK_U8*)(p))[1] = (d)>>8; \
((RK_U8*)(p))[0] = (d)>>16; } while(0)
#define MPP_RL24(x) ((((const RK_U8*)(x))[2] << 16) | \
(((const RK_U8*)(x))[1] << 8) | \
((const RK_U8*)(x))[0])
#define MPP_WL24(p, d) do { \
((RK_U8*)(p))[0] = (d); \
((RK_U8*)(p))[1] = (d)>>8; \
((RK_U8*)(p))[2] = (d)>>16; } while(0)
#include <stdio.h>
#if defined(_WIN32) && !defined(__MINGW32CE__)
#define snprintf _snprintf
#define fseeko _fseeki64
#include <direct.h>
#include <io.h>
#include <sys/stat.h>
#define chdir _chdir
#define mkdir _mkdir
#define access _access
#define off_t _off_t
#define R_OK 4 /* Test for read permission. */
#define W_OK 2 /* Test for write permission. */
#define X_OK 1 /* Test for execute permission. */
#define F_OK 0 /* Test for existence. */
#elif defined(__MINGW32CE__)
#define fseeko fseeko64
#else
#include <unistd.h>
#include <stddef.h>
#include <sys/stat.h>
#include <sys/types.h>
#define mkdir(x) mkdir(x, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
#endif
#define container_of(ptr, type, member) \
((type *)((char *)(ptr) - offsetof(type, member)))
#define __RETURN __Return
#define __FAILED __failed
#define ARG_T(t) t
#define ARG_N(a,b,c,d,N,...) N
#define ARG_N_HELPER(...) ARG_T(ARG_N(__VA_ARGS__))
#define COUNT_ARG(...) ARG_N_HELPER(__VA_ARGS__,4,3,2,1,0)
#define SZ_1K (1024)
#define SZ_2K (SZ_1K*2)
#define SZ_4K (SZ_1K*4)
#define SZ_8K (SZ_1K*8)
#define SZ_16K (SZ_1K*16)
#define SZ_32K (SZ_1K*32)
#define SZ_64K (SZ_1K*64)
#define SZ_128K (SZ_1K*128)
#define SZ_256K (SZ_1K*256)
#define SZ_512K (SZ_1K*512)
#define SZ_1M (SZ_1K*SZ_1K)
#define SZ_2M (SZ_1M*2)
#define SZ_4M (SZ_1M*4)
#define SZ_8M (SZ_1M*8)
#define SZ_16M (SZ_1M*16)
#define SZ_32M (SZ_1M*32)
#define SZ_64M (SZ_1M*64)
#define SZ_80M (SZ_1M*80)
#define SZ_128M (SZ_1M*128)
#ifdef __cplusplus
extern "C" {
#endif
RK_S32 mpp_log2(RK_U32 v);
RK_S32 mpp_log2_16bit(RK_U32 v);
static __inline RK_S32 mpp_ceil_log2(RK_S32 x)
{
return mpp_log2((x - 1) << 1);
}
static __inline RK_S32 mpp_clip(RK_S32 a, RK_S32 amin, RK_S32 amax)
{
if (a < amin) return amin;
else if (a > amax) return amax;
else return a;
}
static __inline RK_U32 mpp_is_32bit()
{
return ((sizeof(void *) == 4) ? (1) : (0));
}
RK_S32 axb_div_c(RK_S32 a, RK_S32 b, RK_S32 c);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_COMMON_H__*/
+45
View File
@@ -0,0 +1,45 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_ENC_CFG_H__
#define __MPP_ENC_CFG_H__
#include "rk_venc_cmd.h"
#include "rc_data.h"
/*
* MppEncCfgSet shows the relationship between different configuration
* Due to the huge amount of configurable parameters we need to setup
* only minimum amount of necessary parameters.
*
* For normal user rc and prep config are enough.
*/
typedef struct MppEncCfgSet_t {
// esential config
MppEncPrepCfg prep;
MppEncRcCfg rc;
// codec detail config
MppEncCodecCfg codec;
MppEncSliceSplit split;
MppEncGopRef gop_ref;
MppEncROICfg roi;
MppEncOSDPltCfg plt_cfg;
MppEncOSDPlt plt_data;
} MppEncCfgSet;
#endif /*__MPP_ENC_H__*/
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_ENV_H__
#define __MPP_ENV_H__
#include "rk_type.h"
#ifdef __cplusplus
extern "C" {
#endif
RK_S32 mpp_env_get_u32(const char *name, RK_U32 *value, RK_U32 default_value);
RK_S32 mpp_env_get_str(const char *name, const char **value, const char *default_value);
RK_S32 mpp_env_set_u32(const char *name, RK_U32 value);
RK_S32 mpp_env_set_str(const char *name, char *value);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_ENV_H__*/
+54
View File
@@ -0,0 +1,54 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_ERR_H__
#define __MPP_ERR_H__
#define RK_OK 0
#define RK_SUCCESS 0
typedef enum {
MPP_SUCCESS = RK_SUCCESS,
MPP_OK = RK_OK,
MPP_NOK = -1,
MPP_ERR_UNKNOW = -2,
MPP_ERR_NULL_PTR = -3,
MPP_ERR_MALLOC = -4,
MPP_ERR_OPEN_FILE = -5,
MPP_ERR_VALUE = -6,
MPP_ERR_READ_BIT = -7,
MPP_ERR_TIMEOUT = -8,
MPP_ERR_PERM = -9,
MPP_ERR_BASE = -1000,
/* The error in stream processing */
MPP_ERR_LIST_STREAM = MPP_ERR_BASE - 1,
MPP_ERR_INIT = MPP_ERR_BASE - 2,
MPP_ERR_VPU_CODEC_INIT = MPP_ERR_BASE - 3,
MPP_ERR_STREAM = MPP_ERR_BASE - 4,
MPP_ERR_FATAL_THREAD = MPP_ERR_BASE - 5,
MPP_ERR_NOMEM = MPP_ERR_BASE - 6,
MPP_ERR_PROTOL = MPP_ERR_BASE - 7,
MPP_FAIL_SPLIT_FRAME = MPP_ERR_BASE - 8,
MPP_ERR_VPUHW = MPP_ERR_BASE - 9,
MPP_EOS_STREAM_REACHED = MPP_ERR_BASE - 11,
MPP_ERR_BUFFER_FULL = MPP_ERR_BASE - 12,
MPP_ERR_DISPLAY_FULL = MPP_ERR_BASE - 13,
} MPP_RET;
#endif /*__MPP_ERR_H__*/
+327
View File
@@ -0,0 +1,327 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_FRAME_H__
#define __MPP_FRAME_H__
#include "mpp_buffer.h"
#include "mpp_meta.h"
/*
* bit definition for mode flag in MppFrame
*/
/* progressive frame */
#define MPP_FRAME_FLAG_FRAME (0x00000000)
/* top field only */
#define MPP_FRAME_FLAG_TOP_FIELD (0x00000001)
/* bottom field only */
#define MPP_FRAME_FLAG_BOT_FIELD (0x00000002)
/* paired field */
#define MPP_FRAME_FLAG_PAIRED_FIELD (MPP_FRAME_FLAG_TOP_FIELD|MPP_FRAME_FLAG_BOT_FIELD)
/* paired field with field order of top first */
#define MPP_FRAME_FLAG_TOP_FIRST (0x00000004)
/* paired field with field order of bottom first */
#define MPP_FRAME_FLAG_BOT_FIRST (0x00000008)
/* paired field with unknown field order (MBAFF) */
#define MPP_FRAME_FLAG_DEINTERLACED (MPP_FRAME_FLAG_TOP_FIRST|MPP_FRAME_FLAG_BOT_FIRST)
#define MPP_FRAME_FLAG_FIELD_ORDER_MASK (0x0000000C)
// for multiview stream
#define MPP_FRAME_FLAG_VIEW_ID_MASK (0x000000f0)
#define MPP_FRAME_FLAG_IEP_DEI_MASK (0x00000f00)
#define MPP_FRAME_FLAG_IEP_DEI_I2O1 (0x00000100)
#define MPP_FRAME_FLAG_IEP_DEI_I4O2 (0x00000200)
#define MPP_FRAME_FLAG_IEP_DEI_I4O1 (0x00000300)
/*
* MPEG vs JPEG YUV range.
*/
typedef enum {
MPP_FRAME_RANGE_UNSPECIFIED = 0,
MPP_FRAME_RANGE_MPEG = 1, ///< the normal 219*2^(n-8) "MPEG" YUV ranges
MPP_FRAME_RANGE_JPEG = 2, ///< the normal 2^n-1 "JPEG" YUV ranges
MPP_FRAME_RANGE_NB, ///< Not part of ABI
} MppFrameColorRange;
/*
* Chromaticity coordinates of the source primaries.
*/
typedef enum {
MPP_FRAME_PRI_RESERVED0 = 0,
MPP_FRAME_PRI_BT709 = 1, ///< also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
MPP_FRAME_PRI_UNSPECIFIED = 2,
MPP_FRAME_PRI_RESERVED = 3,
MPP_FRAME_PRI_BT470M = 4, ///< also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
MPP_FRAME_PRI_BT470BG = 5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
MPP_FRAME_PRI_SMPTE170M = 6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
MPP_FRAME_PRI_SMPTE240M = 7, ///< functionally identical to above
MPP_FRAME_PRI_FILM = 8, ///< colour filters using Illuminant C
MPP_FRAME_PRI_BT2020 = 9, ///< ITU-R BT2020
MPP_FRAME_PRI_SMPTEST428_1 = 10, ///< SMPTE ST 428-1 (CIE 1931 XYZ)
MPP_FRAME_PRI_SMPTE431 = 11, ///< SMPTE ST 431-2 (2011) / DCI P3
MPP_FRAME_PRI_SMPTE432 = 12, ///< SMPTE ST 432-1 (2010) / P3 D65 / Display P3
MPP_FRAME_PRI_NB, ///< Not part of ABI
} MppFrameColorPrimaries;
/*
* Color Transfer Characteristic.
*/
typedef enum {
MPP_FRAME_TRC_RESERVED0 = 0,
MPP_FRAME_TRC_BT709 = 1, ///< also ITU-R BT1361
MPP_FRAME_TRC_UNSPECIFIED = 2,
MPP_FRAME_TRC_RESERVED = 3,
MPP_FRAME_TRC_GAMMA22 = 4, ///< also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
MPP_FRAME_TRC_GAMMA28 = 5, ///< also ITU-R BT470BG
MPP_FRAME_TRC_SMPTE170M = 6, ///< also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
MPP_FRAME_TRC_SMPTE240M = 7,
MPP_FRAME_TRC_LINEAR = 8, ///< "Linear transfer characteristics"
MPP_FRAME_TRC_LOG = 9, ///< "Logarithmic transfer characteristic (100:1 range)"
MPP_FRAME_TRC_LOG_SQRT = 10, ///< "Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range)"
MPP_FRAME_TRC_IEC61966_2_4 = 11, ///< IEC 61966-2-4
MPP_FRAME_TRC_BT1361_ECG = 12, ///< ITU-R BT1361 Extended Colour Gamut
MPP_FRAME_TRC_IEC61966_2_1 = 13, ///< IEC 61966-2-1 (sRGB or sYCC)
MPP_FRAME_TRC_BT2020_10 = 14, ///< ITU-R BT2020 for 10 bit system
MPP_FRAME_TRC_BT2020_12 = 15, ///< ITU-R BT2020 for 12 bit system
MPP_FRAME_TRC_SMPTEST2084 = 16, ///< SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems
MPP_FRAME_TRC_SMPTEST428_1 = 17, ///< SMPTE ST 428-1
MPP_FRAME_TRC_ARIB_STD_B67 = 18, ///< ARIB STD-B67, known as "Hybrid log-gamma"
MPP_FRAME_TRC_NB, ///< Not part of ABI
} MppFrameColorTransferCharacteristic;
/*
* YUV colorspace type.
*/
typedef enum {
MPP_FRAME_SPC_RGB = 0, ///< order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
MPP_FRAME_SPC_BT709 = 1, ///< also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
MPP_FRAME_SPC_UNSPECIFIED = 2,
MPP_FRAME_SPC_RESERVED = 3,
MPP_FRAME_SPC_FCC = 4, ///< FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
MPP_FRAME_SPC_BT470BG = 5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
MPP_FRAME_SPC_SMPTE170M = 6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
MPP_FRAME_SPC_SMPTE240M = 7,
MPP_FRAME_SPC_YCOCG = 8, ///< Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16
MPP_FRAME_SPC_BT2020_NCL = 9, ///< ITU-R BT2020 non-constant luminance system
MPP_FRAME_SPC_BT2020_CL = 10, ///< ITU-R BT2020 constant luminance system
MPP_FRAME_SPC_NB, ///< Not part of ABI
} MppFrameColorSpace;
/*
* Location of chroma samples.
*
* Illustration showing the location of the first (top left) chroma sample of the
* image, the left shows only luma, the right
* shows the location of the chroma sample, the 2 could be imagined to overlay
* each other but are drawn separately due to limitations of ASCII
*
* 1st 2nd 1st 2nd horizontal luma sample positions
* v v v v
* ______ ______
*1st luma line > |X X ... |3 4 X ... X are luma samples,
* | |1 2 1-6 are possible chroma positions
*2nd luma line > |X X ... |5 6 X ... 0 is undefined/unknown position
*/
typedef enum {
MPP_CHROMA_LOC_UNSPECIFIED = 0,
MPP_CHROMA_LOC_LEFT = 1, ///< mpeg2/4 4:2:0, h264 default for 4:2:0
MPP_CHROMA_LOC_CENTER = 2, ///< mpeg1 4:2:0, jpeg 4:2:0, h263 4:2:0
MPP_CHROMA_LOC_TOPLEFT = 3, ///< ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2
MPP_CHROMA_LOC_TOP = 4,
MPP_CHROMA_LOC_BOTTOMLEFT = 5,
MPP_CHROMA_LOC_BOTTOM = 6,
MPP_CHROMA_LOC_NB, ///< Not part of ABI
} MppFrameChromaLocation;
#define MPP_FRAME_FMT_MASK (0x000fffff)
#define MPP_FRAME_FMT_COLOR_MASK (0x000f0000)
#define MPP_FRAME_FMT_YUV (0x00000000)
#define MPP_FRAME_FMT_RGB (0x00010000)
#define MPP_FRAME_FBC_MASK (0x00f00000)
#define MPP_FRAME_FBC_NONE (0x00000000)
#define MPP_FRAME_FBC_AFBC_V1 (0x00100000)
#define MPP_FRAME_FMT_IS_YUV(fmt) (((fmt & MPP_FRAME_FMT_COLOR_MASK) == MPP_FRAME_FMT_YUV) && \
((fmt & MPP_FRAME_FMT_MASK) < MPP_FMT_YUV_BUTT))
#define MPP_FRAME_FMT_IS_RGB(fmt) (((fmt & MPP_FRAME_FMT_COLOR_MASK) == MPP_FRAME_FMT_RGB) && \
((fmt & MPP_FRAME_FMT_MASK) < MPP_FMT_RGB_BUTT))
/*
* For MPP_FRAME_FBC_AFBC_V1 the 16byte aligned stride is used.
*/
#define MPP_FRAME_FMT_IS_FBC(fmt) (fmt & MPP_FRAME_FBC_MASK)
/* mpp color format index definition */
typedef enum {
MPP_FMT_YUV420SP = MPP_FRAME_FMT_YUV, /* YYYY... UV... (NV12) */
/*
* A rockchip specific pixel format, without gap between pixel aganist
* the P010_10LE/P010_10BE
*/
MPP_FMT_YUV420SP_10BIT,
MPP_FMT_YUV422SP, /* YYYY... UVUV... (NV16) */
MPP_FMT_YUV422SP_10BIT, ///< Not part of ABI
MPP_FMT_YUV420P, /* YYYY... U...V... (I420) */
MPP_FMT_YUV420SP_VU, /* YYYY... VUVUVU... (NV21) */
MPP_FMT_YUV422P, /* YYYY... UU...VV...(422P) */
MPP_FMT_YUV422SP_VU, /* YYYY... VUVUVU... (NV61) */
MPP_FMT_YUV422_YUYV, /* YUYVYUYV... (YUY2) */
MPP_FMT_YUV422_YVYU, /* YVYUYVYU... (YVY2) */
MPP_FMT_YUV422_UYVY, /* UYVYUYVY... (UYVY) */
MPP_FMT_YUV422_VYUY, /* VYUYVYUY... (VYUY) */
MPP_FMT_YUV400, /* YYYY... */
MPP_FMT_YUV440SP, /* YYYY... UVUV... */
MPP_FMT_YUV411SP, /* YYYY... UV... */
MPP_FMT_YUV444SP, /* YYYY... UVUVUVUV... */
MPP_FMT_YUV_BUTT,
MPP_FMT_RGB565 = MPP_FRAME_FMT_RGB, /* 16-bit RGB */
MPP_FMT_BGR565, /* 16-bit RGB */
MPP_FMT_RGB555, /* 15-bit RGB */
MPP_FMT_BGR555, /* 15-bit RGB */
MPP_FMT_RGB444, /* 12-bit RGB */
MPP_FMT_BGR444, /* 12-bit RGB */
MPP_FMT_RGB888, /* 24-bit RGB */
MPP_FMT_BGR888, /* 24-bit RGB */
MPP_FMT_RGB101010, /* 30-bit RGB */
MPP_FMT_BGR101010, /* 30-bit RGB */
MPP_FMT_ARGB8888, /* 32-bit RGB */
MPP_FMT_ABGR8888, /* 32-bit RGB */
MPP_FMT_BGRA8888, /* 32-bit RGB */
MPP_FMT_RGBA8888, /* 32-bit RGB */
MPP_FMT_RGB_BUTT,
MPP_FMT_BUTT,
} MppFrameFormat;
/**
* Rational number (pair of numerator and denominator).
*/
typedef struct MppFrameRational {
RK_S32 num; ///< Numerator
RK_S32 den; ///< Denominator
} MppFrameRational;
typedef struct MppFrameMasteringDisplayMetadata {
RK_U16 display_primaries[3][2];
RK_U16 white_point[2];
RK_U32 max_luminance;
RK_U32 min_luminance;
} MppFrameMasteringDisplayMetadata;
typedef struct MppFrameContentLightMetadata {
RK_U16 MaxCLL;
RK_U16 MaxFALL;
} MppFrameContentLightMetadata;
typedef enum {
MPP_FRAME_ERR_UNKNOW = 0x0001,
MPP_FRAME_ERR_UNSUPPORT = 0x0002,
} MPP_FRAME_ERR;
#ifdef __cplusplus
extern "C" {
#endif
/*
* MppFrame interface
*/
MPP_RET mpp_frame_init(MppFrame *frame);
MPP_RET mpp_frame_deinit(MppFrame *frame);
MppFrame mpp_frame_get_next(MppFrame frame);
/*
* normal parameter
*/
RK_U32 mpp_frame_get_width(const MppFrame frame);
void mpp_frame_set_width(MppFrame frame, RK_U32 width);
RK_U32 mpp_frame_get_height(const MppFrame frame);
void mpp_frame_set_height(MppFrame frame, RK_U32 height);
RK_U32 mpp_frame_get_hor_stride(const MppFrame frame);
void mpp_frame_set_hor_stride(MppFrame frame, RK_U32 hor_stride);
RK_U32 mpp_frame_get_ver_stride(const MppFrame frame);
void mpp_frame_set_ver_stride(MppFrame frame, RK_U32 ver_stride);
RK_U32 mpp_frame_get_mode(const MppFrame frame);
void mpp_frame_set_mode(MppFrame frame, RK_U32 mode);
RK_U32 mpp_frame_get_discard(const MppFrame frame);
void mpp_frame_set_discard(MppFrame frame, RK_U32 discard);
RK_U32 mpp_frame_get_viewid(const MppFrame frame);
void mpp_frame_set_viewid(MppFrame frame, RK_U32 viewid);
RK_U32 mpp_frame_get_poc(const MppFrame frame);
void mpp_frame_set_poc(MppFrame frame, RK_U32 poc);
RK_S64 mpp_frame_get_pts(const MppFrame frame);
void mpp_frame_set_pts(MppFrame frame, RK_S64 pts);
RK_S64 mpp_frame_get_dts(const MppFrame frame);
void mpp_frame_set_dts(MppFrame frame, RK_S64 dts);
RK_U32 mpp_frame_get_errinfo(const MppFrame frame);
void mpp_frame_set_errinfo(MppFrame frame, RK_U32 errinfo);
size_t mpp_frame_get_buf_size(const MppFrame frame);
void mpp_frame_set_buf_size(MppFrame frame, size_t buf_size);
/*
* flow control parmeter
*/
RK_U32 mpp_frame_get_eos(const MppFrame frame);
void mpp_frame_set_eos(MppFrame frame, RK_U32 eos);
RK_U32 mpp_frame_get_info_change(const MppFrame frame);
void mpp_frame_set_info_change(MppFrame frame, RK_U32 info_change);
/*
* buffer parameter
*/
MppBuffer mpp_frame_get_buffer(const MppFrame frame);
void mpp_frame_set_buffer(MppFrame frame, MppBuffer buffer);
/*
* meta data parameter
*/
MppMeta mpp_frame_get_meta(const MppFrame frame);
void mpp_frame_set_meta(MppFrame frame, MppMeta meta);
/*
* color related parameter
*/
MppFrameColorRange mpp_frame_get_color_range(const MppFrame frame);
void mpp_frame_set_color_range(MppFrame frame, MppFrameColorRange color_range);
MppFrameColorPrimaries mpp_frame_get_color_primaries(const MppFrame frame);
void mpp_frame_set_color_primaries(MppFrame frame, MppFrameColorPrimaries color_primaries);
MppFrameColorTransferCharacteristic mpp_frame_get_color_trc(const MppFrame frame);
void mpp_frame_set_color_trc(MppFrame frame, MppFrameColorTransferCharacteristic color_trc);
MppFrameColorSpace mpp_frame_get_colorspace(const MppFrame frame);
void mpp_frame_set_colorspace(MppFrame frame, MppFrameColorSpace colorspace);
MppFrameChromaLocation mpp_frame_get_chroma_location(const MppFrame frame);
void mpp_frame_set_chroma_location(MppFrame frame, MppFrameChromaLocation chroma_location);
MppFrameFormat mpp_frame_get_fmt(MppFrame frame);
void mpp_frame_set_fmt(MppFrame frame, MppFrameFormat fmt);
MppFrameRational mpp_frame_get_sar(const MppFrame frame);
void mpp_frame_set_sar(MppFrame frame, MppFrameRational sar);
MppFrameMasteringDisplayMetadata mpp_frame_get_mastering_display(const MppFrame frame);
void mpp_frame_set_mastering_display(MppFrame frame, MppFrameMasteringDisplayMetadata mastering_display);
MppFrameContentLightMetadata mpp_frame_get_content_light(const MppFrame frame);
void mpp_frame_set_content_light(MppFrame frame, MppFrameContentLightMetadata content_light);
/*
* HDR parameter
*/
#ifdef __cplusplus
}
#endif
#endif /*__MPP_FRAME_H__*/
+144
View File
@@ -0,0 +1,144 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_FRAME_IMPL_H__
#define __MPP_FRAME_IMPL_H__
#include "mpp_frame.h"
typedef struct MppFrameImpl_t MppFrameImpl;
struct MppFrameImpl_t {
const char *name;
/*
* dimension parameter for display
*/
RK_U32 width;
RK_U32 height;
RK_U32 hor_stride;
RK_U32 ver_stride;
/*
* interlaced related mode status
*
* 0 - frame
* 1 - top field
* 2 - bottom field
* 3 - paired top and bottom field
* 4 - deinterlaced flag
* 7 - deinterlaced paired field
*/
RK_U32 mode;
/*
* current decoded frame whether to display
*
* 0 - reserve
* 1 - discard
*/
RK_U32 discard;
/*
* send decoded frame belong which view
*/
RK_U32 viewid;
/*
* poc - picture order count
*/
RK_U32 poc;
/*
* pts - display time stamp
* dts - decode time stamp
*/
RK_S64 pts;
RK_S64 dts;
/*
* eos - end of stream
* info_change - set when buffer resized or frame infomation changed
*/
RK_U32 eos;
RK_U32 info_change;
RK_U32 errinfo;
MppFrameColorRange color_range;
MppFrameColorPrimaries color_primaries;
MppFrameColorTransferCharacteristic color_trc;
/**
* YUV colorspace type.
* It must be accessed using av_frame_get_colorspace() and
* av_frame_set_colorspace().
* - encoding: Set by user
* - decoding: Set by libavcodec
*/
MppFrameColorSpace colorspace;
MppFrameChromaLocation chroma_location;
MppFrameFormat fmt;
MppFrameRational sar;
MppFrameMasteringDisplayMetadata mastering_display;
MppFrameContentLightMetadata content_light;
/*
* buffer information
* NOTE: buf_size only access internally
*/
MppBuffer buffer;
size_t buf_size;
/*
* meta data information
*/
MppMeta meta;
/*
* frame buffer compression (FBC) information
*
* NOTE: some constraint on fbc data
* 1. FBC config need two addresses but only one buffer.
* The second address should be represented by base + offset form.
* 2. FBC has header address and payload address
* Both addresses should be 4K aligned.
* 3. The header section size is default defined by:
* header size = aligned(aligned(width, 16) * aligned(height, 16) / 16, 4096)
* 4. The stride in header section is defined by:
* stride = aligned(width, 16)
*/
RK_U32 fbc_offset;
/*
* pointer for multiple frame output at one time
*/
MppFrameImpl *next;
};
#ifdef __cplusplus
extern "C" {
#endif
MPP_RET mpp_frame_set_next(MppFrame frame, MppFrame next);
MPP_RET mpp_frame_copy(MppFrame frame, MppFrame next);
MPP_RET mpp_frame_info_cmp(MppFrame frame0, MppFrame frame1);
RK_U32 mpp_frame_get_fbc_offset(MppFrame frame);
RK_U32 mpp_frame_get_fbc_stride(MppFrame frame);
MPP_RET check_is_mpp_frame(void *pointer);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_FRAME_IMPL_H__*/
+47
View File
@@ -0,0 +1,47 @@
/*
*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_IMPL_H__
#define __MPP_IMPL_H__
#include "rk_type.h"
#include "mpp_err.h"
typedef void* MppDump;
#ifdef __cplusplus
extern "C" {
#endif
MPP_RET mpp_dump_init(MppDump *info);
MPP_RET mpp_dump_deinit(MppDump *info);
MPP_RET mpp_ops_init(MppDump info, MppCtxType type, MppCodingType coding);
MPP_RET mpp_ops_dec_put_pkt(MppDump info, MppPacket pkt);
MPP_RET mpp_ops_dec_get_frm(MppDump info, MppFrame frame);
MPP_RET mpp_ops_enc_put_frm(MppDump info, MppFrame frame);
MPP_RET mpp_ops_enc_get_pkt(MppDump info, MppPacket pkt);
MPP_RET mpp_ops_ctrl(MppDump info, MpiCmd cmd);
MPP_RET mpp_ops_reset(MppDump info);
#ifdef __cplusplus
}
#endif
#endif
+31
View File
@@ -0,0 +1,31 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_INFO_H__
#define __MPP_INFO_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void show_mpp_version(void);
const char *get_mpp_version(void);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_INFO_H__*/
+187
View File
@@ -0,0 +1,187 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_LIST_H__
#define __MPP_LIST_H__
#include "rk_type.h"
#include "mpp_thread.h"
/*
* two list structures are defined, one for C++, the other for C
*/
#ifdef __cplusplus
// desctructor of list node
typedef void *(*node_destructor)(void *);
struct mpp_list_node;
class mpp_list
{
public:
mpp_list(node_destructor func = NULL);
~mpp_list();
// for FIFO or FILO implement
// adding functions support simple structure like C struct or C++ class pointer,
// do not support C++ object
RK_S32 add_at_head(void *data, RK_S32 size);
RK_S32 add_at_tail(void *data, RK_S32 size);
// deleting function will copy the stored data to input pointer with size as size
// if NULL is passed to deleting functions, the node will be delete directly
RK_S32 del_at_head(void *data, RK_S32 size);
RK_S32 del_at_tail(void *data, RK_S32 size);
// direct fifo operation
RK_S32 fifo_wr(void *data, RK_S32 size);
RK_S32 fifo_rd(void *data, RK_S32 *size);
// for status check
RK_S32 list_is_empty();
RK_S32 list_size();
// for vector implement - not implemented yet
// adding function will return a key
RK_S32 add_by_key(void *data, RK_S32 size, RK_U32 *key);
RK_S32 del_by_key(void *data, RK_S32 size, RK_U32 key);
RK_S32 show_by_key(void *data, RK_U32 key);
RK_S32 flush();
// open lock function for external combination usage
void lock();
void unlock();
RK_S32 trylock();
// open lock function for external auto lock
Mutex *mutex();
void wait();
RK_S32 wait(RK_S64 timeout);
void signal();
private:
Mutex mMutex;
Condition mCondition;
node_destructor destroy;
struct mpp_list_node *head;
RK_S32 count;
static RK_U32 keys;
static RK_U32 get_key();
mpp_list(const mpp_list &);
mpp_list &operator=(const mpp_list &);
};
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct list_head {
struct list_head *next, *prev;
};
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
#define INIT_LIST_HEAD(ptr) do { \
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
#define list_entry(ptr, type, member) \
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
/*
* due to typeof gcc extension list_for_each_entry and list_for_each_entry_safe
* can not be used on windows platform
* So we add a extra type parameter to the macro
*/
#define list_for_each_entry(pos, head, type, member) \
for (pos = list_entry((head)->next, type, member); \
&pos->member != (head); \
pos = list_entry(pos->member.next, type, member))
#define list_for_each_entry_safe(pos, n, head, type, member) \
for (pos = list_entry((head)->next, type, member), \
n = list_entry(pos->member.next, type, member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, type, member))
#define list_for_each_entry_reverse(pos, head, type, member) \
for (pos = list_entry((head)->prev, type, member); \
&pos->member != (head); \
pos = list_entry(pos->member.prev, type, member))
static __inline void __list_add(struct list_head * _new,
struct list_head * prev,
struct list_head * next)
{
next->prev = _new;
_new->next = next;
_new->prev = prev;
prev->next = _new;
}
static __inline void list_add(struct list_head *_new, struct list_head *head)
{
__list_add(_new, head, head->next);
}
static __inline void list_add_tail(struct list_head *_new, struct list_head *head)
{
__list_add(_new, head->prev, head);
}
static __inline void __list_del(struct list_head * prev, struct list_head * next)
{
next->prev = prev;
prev->next = next;
}
static __inline void list_del_init(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
INIT_LIST_HEAD(entry);
}
static __inline int list_is_last(const struct list_head *list, const struct list_head *head)
{
return list->next == head;
}
static __inline int list_empty(struct list_head *head)
{
return head->next == head;
}
#ifdef __cplusplus
}
#endif
#endif /*__MPP_LIST_H__*/
+134
View File
@@ -0,0 +1,134 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_LOG_H__
#define __MPP_LOG_H__
#include <stdio.h>
#include <stdlib.h>
#include "rk_type.h"
/*
* mpp runtime log system usage:
* mpp_err is for error status message, it will print for sure.
* mpp_log is for important message like open/close/reset/flush, it will print too.
* mpp_dbg is for all optional message. it can be controlled by debug and flag.
*/
#define mpp_log(fmt, ...) _mpp_log(MODULE_TAG, fmt, NULL, ## __VA_ARGS__)
#define mpp_err(fmt, ...) _mpp_err(MODULE_TAG, fmt, NULL, ## __VA_ARGS__)
#define _mpp_dbg(debug, flag, fmt, ...) \
do { \
if (debug & flag) \
mpp_log(fmt, ## __VA_ARGS__); \
} while (0)
#define mpp_dbg(flag, fmt, ...) _mpp_dbg(mpp_debug, flag, fmt, ## __VA_ARGS__)
/*
* _f function will add function name to the log
*/
#define mpp_log_f(fmt, ...) _mpp_log(MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__)
#define mpp_err_f(fmt, ...) _mpp_err(MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__)
#define _mpp_dbg_f(debug, flag, fmt, ...) \
do { \
if (debug & flag) \
mpp_log_f(fmt, ## __VA_ARGS__); \
} while (0)
#define mpp_dbg_f(flag, fmt, ...) _mpp_dbg_f(mpp_debug, flag, fmt, ## __VA_ARGS__)
#define MPP_DBG_TIMING (0x00000001)
#define MPP_DBG_PTS (0x00000002)
#define MPP_DBG_INFO (0x00000004)
#define MPP_DBG_PLATFORM (0x00000010)
#define MPP_DBG_DUMP_LOG (0x00000100)
#define MPP_DBG_DUMP_IN (0x00000200)
#define MPP_DBG_DUMP_OUT (0x00000400)
#define MPP_DBG_DUMP_CFG (0x00000800)
#define MPP_ABORT (0x10000000)
/*
* mpp_dbg usage:
*
* in h264d module define module debug flag variable like: h265d_debug
* then define h265d_dbg macro as follow :
*
* extern RK_U32 h265d_debug;
*
* #define H265D_DBG_FUNCTION (0x00000001)
* #define H265D_DBG_VPS (0x00000002)
* #define H265D_DBG_SPS (0x00000004)
* #define H265D_DBG_PPS (0x00000008)
* #define H265D_DBG_SLICE_HDR (0x00000010)
*
* #define h265d_dbg(flag, fmt, ...) mpp_dbg(h265d_debug, flag, fmt, ## __VA_ARGS__)
*
* finally use environment control the debug flag
*
* mpp_get_env_u32("h264d_debug", &h265d_debug, 0)
*
*/
/*
* sub-module debug flag usage example:
* +------+-------------------+
* | 8bit | 24bit |
* +------+-------------------+
* 0~15 bit: software debug print
* 16~23 bit: hardware debug print
* 24~31 bit: information print format
*/
#define mpp_abort() do { \
if (mpp_debug & MPP_ABORT) { \
abort(); \
} \
} while (0)
#define MPP_STRINGS(x) MPP_TO_STRING(x)
#define MPP_TO_STRING(x) #x
#define mpp_assert(cond) do { \
if (!(cond)) { \
mpp_err("Assertion %s failed at %s:%d\n", \
MPP_STRINGS(cond), __FUNCTION__, __LINE__); \
mpp_abort(); \
} \
} while (0)
#ifdef __cplusplus
extern "C" {
#endif
extern RK_U32 mpp_debug;
void mpp_log_set_flag(RK_U32 flag);
RK_U32 mpp_log_get_flag(void);
void _mpp_log(const char *tag, const char *fmt, const char *func, ...);
void _mpp_err(const char *tag, const char *fmt, const char *func, ...);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_LOG_H__*/
+80
View File
@@ -0,0 +1,80 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_MEM_H__
#define __MPP_MEM_H__
#include <stdlib.h>
#include "rk_type.h"
#include "mpp_err.h"
#define mpp_malloc_with_caller(type, count, caller) \
(type*)mpp_osal_malloc(caller, sizeof(type) * (count))
#define mpp_malloc(type, count) \
(type*)mpp_osal_malloc(__FUNCTION__, sizeof(type) * (count))
#define mpp_malloc_size(type, size) \
(type*)mpp_osal_malloc(__FUNCTION__, size)
#define mpp_calloc_size(type, size) \
(type*)mpp_osal_calloc(__FUNCTION__, size)
#define mpp_calloc(type, count) \
(type*)mpp_osal_calloc(__FUNCTION__, sizeof(type) * (count))
#define mpp_realloc(ptr, type, count) \
(type*)mpp_osal_realloc(__FUNCTION__, ptr, sizeof(type) * (count))
#define mpp_free(ptr) \
mpp_osal_free(__FUNCTION__, ptr)
#define MPP_FREE(ptr) do { if(ptr) mpp_free(ptr); ptr = NULL; } while (0)
#define MPP_FCLOSE(fp) do { if(fp) fclose(fp); fp = NULL; } while (0)
#ifdef __cplusplus
extern "C" {
#endif
void *mpp_osal_malloc(const char *caller, size_t size);
void *mpp_osal_calloc(const char *caller, size_t size);
void *mpp_osal_realloc(const char *caller, void *ptr, size_t size);
void mpp_osal_free(const char *caller, void *ptr);
void mpp_show_mem_status();
/*
* mpp memory usage snapshot tool
*
* usage:
* call mpp_mem_get_snapshot on context init get one snapshot
* call mpp_mem_get_snapshot on context deinit get another snapshot
* call mpp_mem_diff_snapshot to show the difference between these two snapshot
* call mpp_mem_put_snapshot twice to release these two snapshot
*/
typedef void* MppMemSnapshot;
MPP_RET mpp_mem_get_snapshot(MppMemSnapshot *hnd);
MPP_RET mpp_mem_put_snapshot(MppMemSnapshot *hnd);
MPP_RET mpp_mem_squash_snapshot(MppMemSnapshot hnd0, MppMemSnapshot hnd1);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_MEM_H__*/
+118
View File
@@ -0,0 +1,118 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_META_H__
#define __MPP_META_H__
#include <stdint.h>
#include "rk_type.h"
#define FOURCC_META(a, b, c, d) ((RK_U32)(a) << 24 | \
((RK_U32)(b) << 16) | \
((RK_U32)(c) << 8) | \
((RK_U32)(d) << 0))
/*
* Mpp Metadata definition
*
* Metadata is for information transmision in mpp.
* Mpp task will contain two meta data:
*
* 1. Data flow metadata
* This metadata contains information of input / output data flow. For example
* A. decoder input side task the input packet must be defined and output frame
* may not be defined. Then decoder will try malloc or use committed buffer to
* complete decoding.
* B. decoder output side task
*
*
* 2. Flow control metadata
*
*/
typedef enum MppMetaDataType_e {
/*
* mpp meta data of data flow
* reference counter will be used for these meta data type
*/
TYPE_FRAME = FOURCC_META('m', 'f', 'r', 'm'),
TYPE_PACKET = FOURCC_META('m', 'p', 'k', 't'),
TYPE_BUFFER = FOURCC_META('m', 'b', 'u', 'f'),
/* mpp meta data of normal data type */
TYPE_S32 = FOURCC_META('s', '3', '2', ' '),
TYPE_S64 = FOURCC_META('s', '6', '4', ' '),
TYPE_PTR = FOURCC_META('p', 't', 'r', ' '),
} MppMetaType;
typedef enum MppMetaKey_e {
/* data flow key */
KEY_INPUT_FRAME = FOURCC_META('i', 'f', 'r', 'm'),
KEY_INPUT_PACKET = FOURCC_META('i', 'p', 'k', 't'),
KEY_OUTPUT_FRAME = FOURCC_META('o', 'f', 'r', 'm'),
KEY_OUTPUT_PACKET = FOURCC_META('o', 'p', 'k', 't'),
/* output motion information for motion detection */
KEY_MOTION_INFO = FOURCC_META('m', 'v', 'i', 'f'),
KEY_HDR_INFO = FOURCC_META('h', 'd', 'r', ' '),
/* flow control key */
KEY_INPUT_BLOCK = FOURCC_META('i', 'b', 'l', 'k'),
KEY_OUTPUT_BLOCK = FOURCC_META('o', 'b', 'l', 'k'),
KEY_INPUT_IDR_REQ = FOURCC_META('i', 'i', 'd', 'r'), /* input idr frame request flag */
KEY_OUTPUT_INTRA = FOURCC_META('o', 'i', 'd', 'r'), /* output intra frame indicator */
/* mpp_frame / mpp_packet meta data info key */
KEY_TEMPORAL_ID = FOURCC_META('t', 'l', 'i', 'd'),
KEY_LONG_REF_IDX = FOURCC_META('l', 't', 'i', 'd'),
KEY_ROI_DATA = FOURCC_META('r', 'o', 'i', ' '),
KEY_OSD_DATA = FOURCC_META('o', 's', 'd', ' '),
KEY_USER_DATA = FOURCC_META('u', 's', 'r', 'd'),
/* input motion list for smart p rate control */
KEY_MV_LIST = FOURCC_META('m', 'v', 'l', 't'),
} MppMetaKey;
#define mpp_meta_get(meta) mpp_meta_get_with_tag(meta, MODULE_TAG, __FUNCTION__)
#include "mpp_frame.h"
#include "mpp_packet.h"
#ifdef __cplusplus
extern "C" {
#endif
MPP_RET mpp_meta_get_with_tag(MppMeta *meta, const char *tag, const char *caller);
MPP_RET mpp_meta_put(MppMeta meta);
RK_S32 mpp_meta_size(MppMeta meta);
MPP_RET mpp_meta_set_s32(MppMeta meta, MppMetaKey key, RK_S32 val);
MPP_RET mpp_meta_set_s64(MppMeta meta, MppMetaKey key, RK_S64 val);
MPP_RET mpp_meta_set_ptr(MppMeta meta, MppMetaKey key, void *val);
MPP_RET mpp_meta_get_s32(MppMeta meta, MppMetaKey key, RK_S32 *val);
MPP_RET mpp_meta_get_s64(MppMeta meta, MppMetaKey key, RK_S64 *val);
MPP_RET mpp_meta_get_ptr(MppMeta meta, MppMetaKey key, void **val);
MPP_RET mpp_meta_set_frame (MppMeta meta, MppMetaKey key, MppFrame frame);
MPP_RET mpp_meta_set_packet(MppMeta meta, MppMetaKey key, MppPacket packet);
MPP_RET mpp_meta_set_buffer(MppMeta meta, MppMetaKey key, MppBuffer buffer);
MPP_RET mpp_meta_get_frame (MppMeta meta, MppMetaKey key, MppFrame *frame);
MPP_RET mpp_meta_get_packet(MppMeta meta, MppMetaKey key, MppPacket *packet);
MPP_RET mpp_meta_get_buffer(MppMeta meta, MppMetaKey key, MppBuffer *buffer);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_META_H__*/
+72
View File
@@ -0,0 +1,72 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_META_IMPL_H__
#define __MPP_META_IMPL_H__
#include "mpp_common.h"
#include "mpp_list.h"
#include "mpp_meta.h"
typedef struct MppMetaDef_t {
MppMetaKey key;
MppMetaType type;
} MppMetaDef;
typedef struct MppMetaImpl_t {
char tag[MPP_TAG_SIZE];
const char *caller;
RK_S32 meta_id;
RK_S32 ref_count;
struct list_head list_meta;
struct list_head list_node;
RK_S32 node_count;
} MppMetaImpl;
typedef union MppMetaVal_u {
RK_S32 val_s32;
RK_S64 val_s64;
void *val_ptr;
MppFrame frame;
MppPacket packet;
MppBuffer buffer;
} MppMetaVal;
typedef struct MppMetaNode_t {
struct list_head list_meta;
struct list_head list_node;
MppMetaImpl *meta;
RK_S32 node_id;
RK_S32 type_id;
MppMetaVal val;
} MppMetaNode;
#ifdef __cplusplus
extern "C" {
#endif
RK_S32 mpp_meta_size(MppMeta meta);
MPP_RET mpp_meta_inc_ref(MppMeta meta);
MppMetaNode *mpp_meta_next_node(MppMeta meta);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_META_IMPL_H__*/
+88
View File
@@ -0,0 +1,88 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_PACKET_H__
#define __MPP_PACKET_H__
#include "mpp_meta.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* MppPacket interface
*
* mpp_packet_init = mpp_packet_new + mpp_packet_set_data + mpp_packet_set_size
* mpp_packet_copy_init = mpp_packet_init + memcpy
*/
MPP_RET mpp_packet_new(MppPacket *packet);
MPP_RET mpp_packet_init(MppPacket *packet, void *data, size_t size);
MPP_RET mpp_packet_init_with_buffer(MppPacket *packet, MppBuffer buffer);
MPP_RET mpp_packet_copy_init(MppPacket *packet, const MppPacket src);
MPP_RET mpp_packet_deinit(MppPacket *packet);
/*
* data : ( R/W ) start address of the whole packet memory
* size : ( R/W ) total size of the whole packet memory
* pos : ( R/W ) current access position of the whole packet memory, used for buffer read/write
* length : ( R/W ) the rest length from current position to end of buffer
* NOTE: normally length is updated only by set_pos,
* so set length must be used carefully for special usage
*/
void mpp_packet_set_data(MppPacket packet, void *data);
void mpp_packet_set_size(MppPacket packet, size_t size);
void mpp_packet_set_pos(MppPacket packet, void *pos);
void mpp_packet_set_length(MppPacket packet, size_t size);
void* mpp_packet_get_data(const MppPacket packet);
void* mpp_packet_get_pos(const MppPacket packet);
size_t mpp_packet_get_size(const MppPacket packet);
size_t mpp_packet_get_length(const MppPacket packet);
void mpp_packet_set_pts(MppPacket packet, RK_S64 pts);
RK_S64 mpp_packet_get_pts(const MppPacket packet);
void mpp_packet_set_dts(MppPacket packet, RK_S64 dts);
RK_S64 mpp_packet_get_dts(const MppPacket packet);
void mpp_packet_set_flag(MppPacket packet, RK_U32 flag);
RK_U32 mpp_packet_get_flag(const MppPacket packet);
MPP_RET mpp_packet_set_eos(MppPacket packet);
MPP_RET mpp_packet_clr_eos(MppPacket packet);
RK_U32 mpp_packet_get_eos(MppPacket packet);
MPP_RET mpp_packet_set_extra_data(MppPacket packet);
void mpp_packet_set_buffer(MppPacket packet, MppBuffer buffer);
MppBuffer mpp_packet_get_buffer(const MppPacket packet);
/*
* data access interface
*/
MPP_RET mpp_packet_read(MppPacket packet, size_t offset, void *data, size_t size);
MPP_RET mpp_packet_write(MppPacket packet, size_t offset, void *data, size_t size);
/*
* meta data access interface
*/
MppMeta mpp_packet_get_meta(const MppPacket packet);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_PACKET_H__*/
+70
View File
@@ -0,0 +1,70 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_PACKET_IMPL_H__
#define __MPP_PACKET_IMPL_H__
#include "mpp_meta.h"
#define MPP_PACKET_FLAG_EOS (0x00000001)
#define MPP_PACKET_FLAG_EXTRA_DATA (0x00000002)
#define MPP_PACKET_FLAG_INTERNAL (0x00000004)
/*
* mpp_packet_imp structure
*
* data : pointer
* size : total buffer size
* offset : valid data start offset
* length : valid data length
* pts : packet pts
* dts : packet dts
*/
typedef struct MppPacketImpl_t {
const char *name;
void *data;
void *pos;
size_t size;
size_t length;
RK_S64 pts;
RK_S64 dts;
RK_U32 flag;
MppBuffer buffer;
MppMeta meta;
} MppPacketImpl;
#ifdef __cplusplus
extern "C" {
#endif
/*
* mpp_packet_reset is only used internelly and should NOT be used outside
*/
MPP_RET mpp_packet_reset(MppPacketImpl *packet);
MPP_RET mpp_packet_copy(MppPacket dst, MppPacket src);
MPP_RET mpp_packet_append(MppPacket dst, MppPacket src);
/* pointer check function */
MPP_RET check_is_mpp_packet(void *ptr);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_PACKET_IMPL_H__*/
+101
View File
@@ -0,0 +1,101 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_PLATFORM__
#define __MPP_PLATFORM__
#include "rk_type.h"
/*
* Platform flag detection is for rockchip hardware platform detection
*/
typedef enum MppIoctlVersion_e {
IOCTL_VCODEC_SERVICE,
IOCTL_MPP_SERVICE_V1,
IOCTL_VERSION_BUTT,
} MppIoctlVersion;
/*
* Platform video codec hardware feature
*/
typedef enum {
VPU_CLIENT_VDPU1 = 0, /* 0x00000001 */
VPU_CLIENT_VDPU2 = 1, /* 0x00000002 */
VPU_CLIENT_VDPU1_PP = 2, /* 0x00000004 */
VPU_CLIENT_VDPU2_PP = 3, /* 0x00000008 */
VPU_CLIENT_HEVC_DEC = 8, /* 0x00000100 */
VPU_CLIENT_RKVDEC = 9, /* 0x00000200 */
VPU_CLIENT_AVSPLUS_DEC = 12, /* 0x00001000 */
VPU_CLIENT_RKVENC = 16, /* 0x00010000 */
VPU_CLIENT_VEPU1 = 17, /* 0x00020000 */
VPU_CLIENT_VEPU2 = 18, /* 0x00040000 */
VPU_CLIENT_VEPU2_LITE = 19, /* 0x00080000 */
VPU_CLIENT_VEPU22 = 24, /* 0x01000000 */
VPU_CLIENT_BUTT,
} VPU_CLIENT2_TYPE;
/* RK combined codec */
#define HAVE_VDPU1 (1 << VPU_CLIENT_VDPU1) /* 0x00000001 */
#define HAVE_VDPU2 (1 << VPU_CLIENT_VDPU2) /* 0x00000002 */
#define HAVE_VDPU1_PP (1 << VPU_CLIENT_VDPU1_PP) /* 0x00000004 */
#define HAVE_VDPU2_PP (1 << VPU_CLIENT_VDPU2_PP) /* 0x00000008 */
/* RK standalone decoder */
#define HAVE_HEVC_DEC (1 << VPU_CLIENT_HEVC_DEC) /* 0x00000100 */
#define HAVE_RKVDEC (1 << VPU_CLIENT_RKVDEC) /* 0x00000200 */
#define HAVE_AVSDEC (1 << VPU_CLIENT_AVSPLUS_DEC) /* 0x00001000 */
/* RK standalone encoder */
#define HAVE_RKVENC (1 << VPU_CLIENT_RKVENC) /* 0x00010000 */
#define HAVE_VEPU1 (1 << VPU_CLIENT_VEPU1) /* 0x00020000 */
#define HAVE_VEPU2 (1 << VPU_CLIENT_VEPU2) /* 0x00040000 */
#define HAVE_VEPU2_LITE (1 << VPU_CLIENT_VEPU2_LITE) /* 0x00080000 */
/* External encoder */
#define HAVE_VEPU22 (1 << VPU_CLIENT_VEPU22) /* 0x01000000 */
/* Platform image process hardware feature */
#define HAVE_IPP (0x00000001)
#define HAVE_RGA (0x00000002)
#define HAVE_RGA2 (0x00000004)
#define HAVE_IEP (0x00000008)
/* Hal device id */
typedef enum MppDeviceId_e {
DEV_VDPU, //!< vpu combined decoder
DEV_VEPU, //!< vpu combined encoder
DEV_RKVDEC, //!< rockchip h264 h265 vp9 combined decoder
DEV_RKVENC, //!< rockchip h264 h265 combined encoder
DEV_ID_BUTT,
} MppDeviceId;
#ifdef __cplusplus
extern "C" {
#endif
MppIoctlVersion mpp_get_ioctl_version(void);
const char *mpp_get_soc_name(void);
RK_U32 mpp_get_vcodec_type(void);
RK_U32 mpp_get_2d_hw_flag(void);
RK_U32 mpp_refresh_vcodec_type(RK_U32 vcodec_type);
const char *mpp_get_platform_dev_name(MppCtxType type, MppCodingType coding, RK_U32 platform);
const char *mpp_get_vcodec_dev_name(MppCtxType type, MppCodingType coding);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_PLATFORM__*/
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright 2017 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_QUEUE_H__
#define __MPP_QUEUE_H__
#include "mpp_list.h"
class MppQueue: public mpp_list
{
private:
sem_t mQueuePending;
int mFlushFlag;
public:
MppQueue(node_destructor func);
~MppQueue();
RK_S32 push(void *data, RK_S32 size);
RK_S32 pull(void *data, RK_S32 size);
RK_S32 flush();
};
#endif
+220
View File
@@ -0,0 +1,220 @@
/*
* Copyright 2016 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_RC_API_H__
#define __MPP_RC_API_H__
#include "mpp_err.h"
#include "mpp_rc_defs.h"
/*
* Mpp rate control has three parts:
*
* 1. MPI user config module
* MppEncRcCfg structure is provided to user for overall rate control config
* Mpp will receive MppEncRcCfg from user, check parameter and set it to
* encoder.
*
* 2. Encoder rate control module
* Encoder will implement the rate control strategy required by users
* including CBR, VBR, AVBR and so on.
* This module only implement the target bit calculation behavior and
* quality restriction. And the quality level will be controlled by hal.
*
* 3. Hal rate control module
* Hal will implement the rate control on hardware. Hal will calculate the
* QP parameter for hardware according to the frame level target bit
* specified by the encoder. And the report the real bitrate and quality to
* encoder.
*
* The header defines the communication interfaces and structures used between
* MPI, encoder and hal.
*/
typedef enum RcMode_e {
RC_CBR,
RC_VBR,
RC_AVBR,
RC_CVBR,
RC_QVBR,
RC_FIXQP,
RC_LEARNING,
RC_MODE_BUTT,
} RcMode;
/*
* frame rate parameters have great effect on rate control
*
* fps_in_flex
* 0 - fix input frame rate
* 1 - variable input frame rate
*
* fps_in_num
* input frame rate numerator, if 0 then default 30
*
* fps_in_denorm
* input frame rate denorminator, if 0 then default 1
*
* fps_out_flex
* 0 - fix output frame rate
* 1 - variable output frame rate
*
* fps_out_num
* output frame rate numerator, if 0 then default 30
*
* fps_out_denorm
* output frame rate denorminator, if 0 then default 1
*/
typedef struct RcFpsCfg_t {
RK_S32 fps_in_flex;
RK_S32 fps_in_num;
RK_S32 fps_in_denorm;
RK_S32 fps_out_flex;
RK_S32 fps_out_num;
RK_S32 fps_out_denorm;
} RcFpsCfg;
/*
* Control parameter from external config
*
* It will be updated on rc/prep/gopref config changed.
*/
typedef struct RcCfg_s {
/* encode image size */
RK_S32 width;
RK_S32 height;
/* Use rc_mode to find different api */
RcMode mode;
RcFpsCfg fps;
/* I frame gop len */
RK_S32 igop;
/* visual gop len */
RK_S32 vgop;
/* bitrate parameter */
RK_S32 bps_min;
RK_S32 bps_target;
RK_S32 bps_max;
RK_S32 stat_times;
/* max I frame bit ratio to P frame bit */
RK_S32 max_i_bit_prop;
RK_S32 min_i_bit_prop;
/* layer bitrate proportion */
RK_S32 layer_bit_prop[4];
/* quality parameter */
RK_S32 init_quality;
RK_S32 max_quality;
RK_S32 min_quality;
RK_S32 max_i_quality;
RK_S32 min_i_quality;
RK_S32 i_quality_delta;
/* layer quality proportion */
RK_S32 layer_quality_delta[4];
/* reencode parameter */
RK_S32 max_reencode_times;
/* still / motion desision parameter */
RK_S32 min_still_prop;
RK_S32 max_still_quality;
/*
* vbr parameter
*
* vbr_hi_prop - high proportion bitrate for reduce quality
* vbr_lo_prop - low proportion bitrate for increase quality
*/
RK_S32 vbr_hi_prop;
RK_S32 vbr_lo_prop;
} RcCfg;
/*
* Different rate control strategy will be implemented by different API config
*/
typedef struct RcImplApi_t {
char *name;
MppCodingType type;
RK_U32 ctx_size;
MPP_RET (*init)(void *ctx, RcCfg *cfg);
MPP_RET (*deinit)(void *ctx);
MPP_RET (*check_drop)(void *ctx, EncRcTask *task);
/*
* frm_start - frame level rate control frm_start.
* The EncRcTaskInfo will be output to hal for hardware to implement.
* frm_end - frame level rate control frm_end.
* The EncRcTaskInfo is returned for real quality and bitrate.
*/
MPP_RET (*frm_start)(void *ctx, EncRcTask *task);
MPP_RET (*frm_end)(void *ctx, EncRcTask *task);
/*
* hal_start - hardware level rate control start.
* The EncRcTaskInfo will be output to hal for hardware to implement.
* hal_end - hardware level rate control end.
* The EncRcTaskInfo is returned for real quality and bitrate.
*/
MPP_RET (*hal_start)(void *ctx, EncRcTask *task);
MPP_RET (*hal_end)(void *ctx, EncRcTask *task);
} RcImplApi;
/*
* structures for RC API register and query
*/
typedef struct RcApiBrief_t {
const char *name;
MppCodingType type;
} RcApiBrief;
typedef struct RcApiQueryAll_t {
/* input param for query */
RcApiBrief *brief;
RK_S32 max_count;
/* output query count */
RK_S32 count;
} RcApiQueryAll;
typedef struct RcApiQueryType_t {
/* input param for query */
RcApiBrief *brief;
RK_S32 max_count;
MppCodingType type;
/* output query count */
RK_S32 count;
} RcApiQueryType;
#ifdef __cplusplus
extern "C" {
#endif
MPP_RET rc_api_add(const RcImplApi *api);
MPP_RET rc_brief_get_all(RcApiQueryAll *query);
MPP_RET rc_brief_get_by_type(RcApiQueryType *query);
#ifdef __cplusplus
}
#endif
#endif /* __MPP_RC_API_H__ */
+144
View File
@@ -0,0 +1,144 @@
/*
* Copyright 2016 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __RC_DEFS_H__
#define __RC_DEFS_H__
#include "rk_type.h"
/*
* EncFrmStatus controls record the encoding frame status and also control
* work flow of encoder. It is the communicat channel between encoder implement
* module, rate control module and hardware module.
*
* bit 0 ~ 31 frame status
* 0 ~ 15 current frame status
* 16 ~ 31 reference frame status
* bit 32 ~ 63 encoding flow control
*/
typedef struct EncFrmStatus_t {
/*
* bit 0 ~ 31 frame status
*/
/*
* 0 - inter frame
* 1 - intra frame
*/
RK_U32 is_intra : 1;
/*
* Valid when is_intra is true
* 0 - normal intra frame
* 1 - IDR frame
*/
RK_U32 is_idr : 1;
/*
* 0 - mark as reference frame
* 1 - mark as non-refernce frame
*/
RK_U32 is_non_ref : 1;
/*
* Valid when is_non_ref is false
* 0 - mark as short-term reference frame
* 1 - mark as long-term refernce frame
*/
RK_U32 is_lt_ref : 1;
RK_U32 reserved0 : 4;
/* bit 8 - 15 */
RK_U32 lt_idx : 4;
RK_U32 temporal_id : 4;
/* distance between current frame and reference frame */
RK_S32 ref_dist : 16;
/*
* bit 32 ~ 63 encoder flow control flags
*/
/*
* 0 - normal frame encoding
* 1 - current frame will be dropped
*/
RK_U32 drop : 1;
/*
* 0 - rate control module does not change frame type parameter
* 1 - rate control module changes frame type parameter reencode is needed
* to reprocess the dpb process. Also this means dpb module will follow
* the frame status parameter provided by rate control module.
*/
RK_U32 re_dpb_proc : 1;
/*
* 0 - current frame encoding is in normal flow
* 1 - current frame encoding is in reencode flow
*/
RK_U32 reencode : 1;
/*
* When true current frame size is super large then the frame should be reencoded.
*/
RK_U32 super_frame : 1;
/*
* When true currnet frame is force to encoded as software skip frame
*/
RK_U32 force_pskip : 1;
RK_U32 reserved1 : 3;
/* reencode times */
RK_U32 reencode_times : 8;
/* sequential index for each frame */
RK_U32 seq_idx : 16;
} EncFrmStatus;
/*
* communication channel between rc / hal / hardware
*
* rc -> hal bit_target / bit_max / bit_min
* hal -> hw quality_target / quality_max / quality_min
* hw -> rc / hal bit_real / quality_real / madi / madp
*/
typedef struct EncRcCommonInfo_t {
/* rc to hal */
RK_S32 bit_target;
RK_S32 bit_max;
RK_S32 bit_min;
RK_S32 quality_target;
RK_S32 quality_max;
RK_S32 quality_min;
/* rc from hardware */
RK_S32 bit_real;
RK_S32 quality_real;
RK_S32 madi;
RK_S32 madp;
RK_S32 reserve[16];
} EncRcTaskInfo;
typedef struct EncRcTask_s {
EncFrmStatus frm;
EncRcTaskInfo info;
MppFrame frame;
} EncRcTask;
#endif /* __RC_DEFS_H__ */
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_RUNTIME__
#define __MPP_RUNTIME__
#include "mpp_buffer.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Runtime function detection is to support different binary on different
* runtime environment. This is usefull on product environemnt.
*/
RK_U32 mpp_rt_allcator_is_valid(MppBufferType type);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_RUNTIME__*/
+237
View File
@@ -0,0 +1,237 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_TASK_H__
#define __MPP_TASK_H__
#include "mpp_meta.h"
/*
* Advanced task flow
* Advanced task flow introduces three concepts: port, task and item
*
* Port is from OpenMAX
* Port has two type: input port and output port which are all for data transaction.
* Port work like a queue. task will be dequeue from or enqueue to one port.
* On input side user will dequeue task from input port, setup task and enqueue task
* back to input port.
* On output side user will dequeue task from output port, get the information from
* and then enqueue task back to output port.
*
* Task indicates one transaction on the port.
* Task has two working mode: async mode and sync mode
* If mpp is work in sync mode on task enqueue function return the task has been done
* If mpp is work in async mode on task enqueue function return the task is just put
* on the task queue for process.
* Task can carry different items. Task just like a container of items
*
* Item indicates MppPacket or MppFrame which is contained in one task
*/
/*
* One mpp task queue has two ports: input and output
*
* The whole picture is:
* Top layer mpp has two ports: mpp_input_port and mpp_output_port
* But internally these two ports belongs to two task queue.
* The mpp_input_port is the mpp_input_task_queue's input port.
* The mpp_output_port is the mpp_output_task_queue's output port.
*
* Each port uses its task queue to communication
*/
typedef enum {
MPP_PORT_INPUT,
MPP_PORT_OUTPUT,
MPP_PORT_BUTT,
} MppPortType;
/*
* Advance task work flow mode:
******************************************************************************
* 1. async mode (default_val)
*
* mpp_init(type, coding, MPP_WORK_ASYNC)
*
* input thread
* a - poll(input)
* b - dequeue(input, *task)
* c - task_set_item(packet/frame)
* d - enqueue(input, task) // when enqueue return the task is not done yet
*
* output thread
* a - poll(output)
* b - dequeue(output, *task)
* c - task_get_item(frame/packet)
* d - enqueue(output, task)
******************************************************************************
* 2. sync mode
*
* mpp_init(type, coding, MPP_WORK_SYNC)
*
* a - poll(input)
* b - dequeue(input, *task)
* c - task_set_item(packet/frame)
* d - enqueue(task) // when enqueue return the task is finished
******************************************************************************
*/
typedef enum {
MPP_TASK_ASYNC,
MPP_TASK_SYNC,
MPP_TASK_WORK_MODE_BUTT,
} MppTaskWorkMode;
/*
* Mpp port pull type
*
* MPP_POLL_BLOCK - for block poll
* MPP_POLL_NON_BLOCK - for non-block poll
* small than MPP_POLL_MAX - for poll with timeout in ms
* small than MPP_POLL_BUTT or larger than MPP_POLL_MAX is invalid value
*/
typedef enum {
MPP_POLL_BUTT = -2,
MPP_POLL_BLOCK = -1,
MPP_POLL_NON_BLOCK = 0,
MPP_POLL_MAX = 8000,
} MppPollType;
/*
* Mpp timeout define
* MPP_TIMEOUT_BLOCK - for block poll
* MPP_TIMEOUT_NON_BLOCK - for non-block poll
* small than MPP_TIMEOUT_MAX - for poll with timeout in ms
* small than MPP_TIMEOUT_BUTT or larger than MPP_TIMEOUT_MAX is invalid value
*/
#define MPP_TIMEOUT_BUTT (-2L)
#define MPP_TIMEOUT_BLOCK (-1L)
#define MPP_TIMEOUT_NON_BLOCK (0L)
#define MPP_TIMEOUT_MAX (8000L)
/*
* MppTask is descriptor of a task which send to mpp for process
* mpp can support different type of work mode, for example:
*
* decoder:
*
* 1. typical decoder mode:
* input - MppPacket (normal cpu buffer, need cpu copy)
* output - MppFrame (ion/drm buffer in external/internal mode)
* 2. secure decoder mode:
* input - MppPacket (externel ion/drm buffer, cpu can not access)
* output - MppFrame (ion/drm buffer in external/internal mode, cpu can not access)
*
* interface usage:
*
* typical flow
* input side:
* task_dequeue(ctx, PORT_INPUT, &task);
* task_put_item(task, MODE_INPUT, packet)
* task_enqueue(ctx, PORT_INPUT, task);
* output side:
* task_dequeue(ctx, PORT_OUTPUT, &task);
* task_get_item(task, MODE_OUTPUT, &frame)
* task_enqueue(ctx, PORT_OUTPUT, task);
*
* secure flow
* input side:
* task_dequeue(ctx, PORT_INPUT, &task);
* task_put_item(task, MODE_INPUT, packet)
* task_put_item(task, MODE_OUTPUT, frame) // buffer will be specified here
* task_enqueue(ctx, PORT_INPUT, task);
* output side:
* task_dequeue(ctx, PORT_OUTPUT, &task);
* task_get_item(task, MODE_OUTPUT, &frame)
* task_enqueue(ctx, PORT_OUTPUT, task);
*
* encoder:
*
* 1. typical encoder mode:
* input - MppFrame (ion/drm buffer in external mode)
* output - MppPacket (normal cpu buffer, need cpu copy)
* 2. user input encoder mode:
* input - MppFrame (normal cpu buffer, need to build hardware table for this buffer)
* output - MppPacket (normal cpu buffer, need cpu copy)
* 3. secure encoder mode:
* input - MppFrame (ion/drm buffer in external mode, cpu can not access)
* output - MppPacket (externel ion/drm buffer, cpu can not access)
*
* typical / user input flow
* input side:
* task_dequeue(ctx, PORT_INPUT, &task);
* task_put_item(task, MODE_INPUT, frame)
* task_enqueue(ctx, PORT_INPUT, task);
* output side:
* task_dequeue(ctx, PORT_OUTPUT, &task);
* task_get_item(task, MODE_OUTPUT, &packet)
* task_enqueue(ctx, PORT_OUTPUT, task);
*
* secure flow
* input side:
* task_dequeue(ctx, PORT_INPUT, &task);
* task_put_item(task, MODE_OUTPUT, packet) // buffer will be specified here
* task_put_item(task, MODE_INPUT, frame)
* task_enqueue(ctx, PORT_INPUT, task);
* output side:
* task_dequeue(ctx, PORT_OUTPUT, &task);
* task_get_item(task, MODE_OUTPUT, &packet)
* task_get_item(task, MODE_OUTPUT, &frame)
* task_enqueue(ctx, PORT_OUTPUT, task);
*
* NOTE: this flow can specify the output frame. User will setup both intput frame and output packet
* buffer at the input side. Then at output side when user gets a finished task user can get the output
* packet and corresponding released input frame.
*
* image processing
*
* 1. typical image process mode:
* input - MppFrame (ion/drm buffer in external mode)
* output - MppFrame (ion/drm buffer in external mode)
*
* typical / user input flow
* input side:
* task_dequeue(ctx, PORT_INPUT, &task);
* task_put_item(task, MODE_INPUT, frame)
* task_enqueue(ctx, PORT_INPUT, task);
* output side:
* task_dequeue(ctx, PORT_OUTPUT, &task);
* task_get_item(task, MODE_OUTPUT, &frame)
* task_enqueue(ctx, PORT_OUTPUT, task);
*/
/* NOTE: use index rather then handle to descripbe task */
#ifdef __cplusplus
extern "C" {
#endif
MPP_RET mpp_task_meta_set_s32(MppTask task, MppMetaKey key, RK_S32 val);
MPP_RET mpp_task_meta_set_s64(MppTask task, MppMetaKey key, RK_S64 val);
MPP_RET mpp_task_meta_set_ptr(MppTask task, MppMetaKey key, void *val);
MPP_RET mpp_task_meta_set_frame (MppTask task, MppMetaKey key, MppFrame frame);
MPP_RET mpp_task_meta_set_packet(MppTask task, MppMetaKey key, MppPacket packet);
MPP_RET mpp_task_meta_set_buffer(MppTask task, MppMetaKey key, MppBuffer buffer);
MPP_RET mpp_task_meta_get_s32(MppTask task, MppMetaKey key, RK_S32 *val, RK_S32 default_val);
MPP_RET mpp_task_meta_get_s64(MppTask task, MppMetaKey key, RK_S64 *val, RK_S64 default_val);
MPP_RET mpp_task_meta_get_ptr(MppTask task, MppMetaKey key, void **val, void *default_val);
MPP_RET mpp_task_meta_get_frame (MppTask task, MppMetaKey key, MppFrame *frame);
MPP_RET mpp_task_meta_get_packet(MppTask task, MppMetaKey key, MppPacket *packet);
MPP_RET mpp_task_meta_get_buffer(MppTask task, MppMetaKey key, MppBuffer *buffer);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_QUEUE_H__*/
+125
View File
@@ -0,0 +1,125 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_TASK_IMPL_H__
#define __MPP_TASK_IMPL_H__
#include "mpp_list.h"
#include "mpp_task.h"
typedef void* MppPort;
typedef void* MppTaskQueue;
/*
* mpp task status transaction
*
* mpp task is generated from mpp port. When create a mpp port the corresponding task
* will be created, too. Then external user will dequeue task from port and enqueue to
* mpp port for process.
*
* input port task work flow:
*
* description | call | status transaction
* 1. input port init | enqueue(external) | -> external_queue
* 2. input port user dequeue | dequeue(external) | external_queue -> external_hold
* 3. user setup task for processing| |
* 4. input port user enqueue | enqueue(external) | external_hold -> internal_queue
* 5. input port mpp start process | dequeue(internal) | internal_queue -> internal_hold
* 6. mpp process task | |
* 7. input port mpp task finish | enqueue(internal) | internal_hold -> external_queue
* loop to 2
*
* output port task work flow:
* description | call | status transaction
* 1. output port init | enqueue(internal) | -> internal_queue
* 2. output port mpp task dequeue | dequeue(internal) | internal_queue -> internal_hold
* 3. mpp setup task by processed frame/packet |
* 4. output port mpp task enqueue | enqueue(internal) | internal_hold -> external_queue
* 5. output port user task dequeue | dequeue(external) | external_queue -> external_hold
* 6. user get task as output | |
* 7. output port user release task | enqueue(external) | external_hold -> external_queue
* loop to 2
*
*/
typedef enum MppTaskStatus_e {
MPP_INPUT_PORT, /* in external queue and ready for external dequeue */
MPP_INPUT_HOLD, /* dequeued and hold by external user, user will config */
MPP_OUTPUT_PORT, /* in mpp internal work queue and ready for mpp dequeue */
MPP_OUTPUT_HOLD, /* dequeued and hold by mpp internal worker, mpp is processing */
MPP_TASK_STATUS_BUTT,
} MppTaskStatus;
typedef struct MppTaskImpl_t {
const char *name;
struct list_head list;
MppTaskQueue queue;
RK_S32 index;
MppTaskStatus status;
MppMeta meta;
} MppTaskImpl;
#ifdef __cplusplus
extern "C" {
#endif
MPP_RET check_mpp_task_name(MppTask task);
/*
* Mpp task queue function:
*
* mpp_task_queue_init - create task queue structure
* mpp_task_queue_deinit - destory task queue structure
* mpp_task_queue_get_port - return input or output port of task queue
*
* Typical work flow, task mpp_dec for example:
*
* 1. Mpp layer creates one task queue in order to connect mpp input and mpp_dec input.
* 2. Mpp layer setups the task count in task queue input port.
* 3. Get input port from the task queue and assign to mpp input as mpp_input_port.
* 4. Get output port from the task queue and assign to mpp_dec input as dec_input_port.
* 5. Let the loop start.
* a. mpi user will dequeue task from mpp_input_port.
* b. mpi user will setup task.
* c. mpi user will enqueue task back to mpp_input_port.
* d. task will automatically transfer to dec_input_port.
* e. mpp_dec will dequeue task from dec_input_port.
* f. mpp_dec will process task.
* g. mpp_dec will enqueue task back to dec_input_port.
* h. task will automatically transfer to mpp_input_port.
* 6. Stop the loop. All tasks must be return to input port with idle status.
* 6. Mpp layer destory the task queue.
*/
MPP_RET mpp_task_queue_init(MppTaskQueue *queue);
MPP_RET mpp_task_queue_setup(MppTaskQueue queue, RK_S32 task_count);
MPP_RET mpp_task_queue_deinit(MppTaskQueue queue);
MppPort mpp_task_queue_get_port(MppTaskQueue queue, MppPortType type);
#define mpp_port_poll(port, timeout) _mpp_port_poll(__FUNCTION__, port, timeout)
#define mpp_port_dequeue(port, task) _mpp_port_dequeue(__FUNCTION__, port, task)
#define mpp_port_enqueue(port, task) _mpp_port_enqueue(__FUNCTION__, port, task)
#define mpp_port_awake(port) _mpp_port_awake(__FUNCTION__, port)
MPP_RET _mpp_port_poll(const char *caller, MppPort port, MppPollType timeout);
MPP_RET _mpp_port_dequeue(const char *caller, MppPort port, MppTask *task);
MPP_RET _mpp_port_enqueue(const char *caller, MppPort port, MppTask task);
MPP_RET _mpp_port_awake(const char *caller, MppPort port);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_TASK_IMPL_H__*/
+281
View File
@@ -0,0 +1,281 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* File : mpp_thread.h
* Description : thread library for different OS
* Author : herman.chen@rock-chips.com
* Date : 9:47 2015/7/27
*/
#ifndef __MPP_THREAD_H__
#define __MPP_THREAD_H__
#if defined(_WIN32) && !defined(__MINGW32CE__)
/*
* NOTE: POSIX Threads for Win32
* Downloaded from http://www.sourceware.org/pthreads-win32/
*/
#include "semaphore.h"
#include "pthread.h"
#pragma comment(lib, "pthreadVC2.lib")
/*
* add pthread_setname_np for windows
*/
int pthread_setname_np(pthread_t thread, const char *name);
#else
#include <unistd.h>
#include <semaphore.h>
#include <pthread.h>
#include <sys/time.h>
#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER
#endif
#endif
#define THREAD_NAME_LEN 16
typedef void *(*MppThreadFunc)(void *);
typedef enum {
MPP_THREAD_UNINITED,
MPP_THREAD_RUNNING,
MPP_THREAD_WAITING,
MPP_THREAD_STOPPING,
} MppThreadStatus;
#ifdef __cplusplus
#include "mpp_log.h"
class Mutex;
class Condition;
/*
* for shorter type name and function name
*/
class Mutex
{
public:
Mutex();
~Mutex();
void lock();
void unlock();
int trylock();
class Autolock
{
public:
inline Autolock(Mutex& mutex) : mLock(mutex) { mLock.lock(); }
inline Autolock(Mutex* mutex) : mLock(*mutex) { mLock.lock(); }
inline ~Autolock() { mLock.unlock(); }
private:
Mutex& mLock;
};
private:
friend class Condition;
pthread_mutex_t mMutex;
Mutex(const Mutex &);
Mutex &operator = (const Mutex&);
};
inline Mutex::Mutex()
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&mMutex, &attr);
pthread_mutexattr_destroy(&attr);
}
inline Mutex::~Mutex()
{
pthread_mutex_destroy(&mMutex);
}
inline void Mutex::lock()
{
pthread_mutex_lock(&mMutex);
}
inline void Mutex::unlock()
{
pthread_mutex_unlock(&mMutex);
}
inline int Mutex::trylock()
{
return pthread_mutex_trylock(&mMutex);
}
typedef Mutex::Autolock AutoMutex;
/*
* for shorter type name and function name
*/
class Condition
{
public:
Condition();
Condition(int type);
~Condition();
RK_S32 wait(Mutex& mutex);
RK_S32 wait(Mutex* mutex);
RK_S32 timedwait(Mutex& mutex, RK_S64 timeout);
RK_S32 timedwait(Mutex* mutex, RK_S64 timeout);
RK_S32 signal();
private:
pthread_cond_t mCond;
};
inline Condition::Condition()
{
pthread_cond_init(&mCond, NULL);
}
inline Condition::~Condition()
{
pthread_cond_destroy(&mCond);
}
inline RK_S32 Condition::wait(Mutex& mutex)
{
return pthread_cond_wait(&mCond, &mutex.mMutex);
}
inline RK_S32 Condition::wait(Mutex* mutex)
{
return pthread_cond_wait(&mCond, &mutex->mMutex);
}
inline RK_S32 Condition::timedwait(Mutex& mutex, RK_S64 timeout)
{
return timedwait(&mutex, timeout);
}
inline RK_S32 Condition::timedwait(Mutex* mutex, RK_S64 timeout)
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME_COARSE, &ts);
ts.tv_sec += timeout / 1000;
ts.tv_nsec += (timeout % 1000) * 1000000;
/* Prevent the out of range at nanoseconds field */
ts.tv_sec += ts.tv_nsec / 1000000000;
ts.tv_nsec %= 1000000000;
return pthread_cond_timedwait(&mCond, &mutex->mMutex, &ts);
}
inline RK_S32 Condition::signal()
{
return pthread_cond_signal(&mCond);
}
class MppMutexCond
{
public:
MppMutexCond() {};
~MppMutexCond() {};
void lock() { mLock.lock(); }
void unlock() { mLock.unlock(); }
void wait() { mCondition.wait(mLock); }
void signal() { mCondition.signal(); }
Mutex *mutex() { return &mLock; }
private:
Mutex mLock;
Condition mCondition;
};
// Thread lock / signal is distinguished by its source
typedef enum MppThreadSignal_e {
THREAD_WORK, // for working loop
THREAD_INPUT, // for thread input
THREAD_OUTPUT, // for thread output
THREAD_CONTROL, // for thread async control (reset)
THREAD_SIGNAL_BUTT,
} MppThreadSignal;
#define THREAD_NORMAL 0
#define THRE 0
class MppThread
{
public:
MppThread(MppThreadFunc func, void *ctx, const char *name = NULL);
~MppThread() {};
MppThreadStatus get_status(MppThreadSignal id = THREAD_WORK);
void set_status(MppThreadStatus status, MppThreadSignal id = THREAD_WORK);
void dump_status();
void start();
void stop();
void lock(MppThreadSignal id = THREAD_WORK) {
mpp_assert(id < THREAD_SIGNAL_BUTT);
mMutexCond[id].lock();
}
void unlock(MppThreadSignal id = THREAD_WORK) {
mpp_assert(id < THREAD_SIGNAL_BUTT);
mMutexCond[id].unlock();
}
void wait(MppThreadSignal id = THREAD_WORK) {
mpp_assert(id < THREAD_SIGNAL_BUTT);
MppThreadStatus status = mStatus[id];
mStatus[id] = MPP_THREAD_WAITING;
mMutexCond[id].wait();
// check the status is not changed then restore status
if (mStatus[id] == MPP_THREAD_WAITING)
mStatus[id] = status;
}
void signal(MppThreadSignal id = THREAD_WORK) {
mpp_assert(id < THREAD_SIGNAL_BUTT);
mMutexCond[id].signal();
}
Mutex *mutex(MppThreadSignal id = THREAD_WORK) {
mpp_assert(id < THREAD_SIGNAL_BUTT);
return mMutexCond[id].mutex();
}
private:
pthread_t mThread;
MppMutexCond mMutexCond[THREAD_SIGNAL_BUTT];
MppThreadStatus mStatus[THREAD_SIGNAL_BUTT];
MppThreadFunc mFunction;
char mName[THREAD_NAME_LEN];
void *mContext;
MppThread();
MppThread(const MppThread &);
MppThread &operator=(const MppThread &);
};
#endif
#endif /*__MPP_THREAD_H__*/
+119
View File
@@ -0,0 +1,119 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_TIME_H__
#define __MPP_TIME_H__
#include "rk_type.h"
#include "mpp_thread.h"
#if defined(_WIN32) && !defined(__MINGW32CE__)
#include <windows.h>
#define msleep Sleep
#define sleep(x) Sleep((x)*1000)
#else
#include <unistd.h>
#define msleep(x) usleep((x)*1000)
#endif
typedef void* MppClock;
typedef void* MppTimer;
#ifdef __cplusplus
extern "C" {
#endif
RK_S64 mpp_time();
void mpp_time_diff(RK_S64 start, RK_S64 end, RK_S64 limit, const char *fmt);
/*
* Clock create / destroy / enable / disable function
* Note when clock is create it is default disabled user need to call enable
* fucntion with enable = 1 to enable the clock.
* User can use enable function with enable = 0 to disable the clock.
*/
MppClock mpp_clock_get(const char *name);
void mpp_clock_put(MppClock clock);
void mpp_clock_enable(MppClock clock, RK_U32 enable);
/*
* Clock basic operation function:
* start : let clock start timing counter
* pause : let clock pause and return the diff to start time
* reset : let clock counter to all zero
*/
RK_S64 mpp_clock_start(MppClock clock);
RK_S64 mpp_clock_pause(MppClock clock);
RK_S64 mpp_clock_reset(MppClock clock);
/*
* These clock helper function can only be call when clock is paused:
* mpp_clock_get_sum - Return clock sum up total value
* mpp_clock_get_count - Return clock sum up counter value
* mpp_clock_get_name - Return clock name
*/
RK_S64 mpp_clock_get_sum(MppClock clock);
RK_S64 mpp_clock_get_count(MppClock clock);
const char *mpp_clock_get_name(MppClock clock);
/*
* MppTimer is for timer with callback function
* It will provide the ability to repeat doing something until it is
* disalble or put.
*
* Timer work flow:
*
* 1. mpp_timer_get
* 2. mpp_timer_set_callback
* 3. mpp_timer_set_timing(initial, interval)
* 4. mpp_timer_set_enable(initial, 1)
* ... running ...
* 5. mpp_timer_set_enable(initial, 0)
* 6. mpp_timer_put
*/
MppTimer mpp_timer_get(const char *name);
void mpp_timer_set_callback(MppTimer timer, MppThreadFunc func, void *ctx);
void mpp_timer_set_timing(MppTimer timer, RK_S32 initial, RK_S32 interval);
void mpp_timer_set_enable(MppTimer timer, RK_S32 enable);
void mpp_timer_put(MppTimer timer);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
class AutoTiming
{
public:
AutoTiming(const char *name = __FUNCTION__);
~AutoTiming();
private:
const char *mName;
RK_S64 mStart;
RK_S64 mEnd;
AutoTiming(const AutoTiming &);
AutoTiming &operator = (const AutoTiming&);
};
#endif
#define AUTO_TIMER_STRING(name, cnt) name ## cnt
#define AUTO_TIMER_NAME_STRING(name, cnt) AUTO_TIMER_STRING(name, cnt)
#define AUTO_TIMER_NAME(name) AUTO_TIMER_NAME_STRING(name, __COUNTER__)
#define AUTO_TIMING() AutoTiming AUTO_TIMER_NAME(auto_timing)(__FUNCTION__)
#endif /*__MPP_TIME_H__*/
+205
View File
@@ -0,0 +1,205 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __RK_MPI_H__
#define __RK_MPI_H__
/**
* @addtogroup rk_mpi
* @brief rockchip media process interface
*
* Mpp provides application programming interface for the application layer.
*/
#include "rk_mpi_cmd.h"
#include "mpp_task.h"
/**
* @ingroup rk_mpi
* @brief mpp main work function set
*
* @note all api function are seperated into two sets: data io api set and control api set
*
* the data api set is for data input/output flow including:
*
* simple data api set:
*
* decode : both send video stream packet to decoder and get video frame from
* decoder at the same time.
* encode : both send video frame to encoder and get encoded video stream from
* encoder at the same time.
*
* decode_put_packet: send video stream packet to decoder only, async interface
* decode_get_frame : get video frame from decoder only, async interface
*
* encode_put_frame : send video frame to encoder only, async interface
* encode_get_packet: get encoded video packet from encoder only, async interface
*
* advance task api set:
*
*
* the control api set is for mpp context control including:
* control : similiar to ioctl in kernel driver, setup or get mpp internal parameter
* reset : clear all data in mpp context, reset to initialized status
* the simple api set is for simple codec usage including:
*
*
* reset : discard all packet and frame, reset all component,
* for both decoder and encoder
* control : control function for mpp property setting
*/
typedef struct MppApi_t {
RK_U32 size;
RK_U32 version;
// simple data flow interface
/**
* @brief both send video stream packet to decoder and get video frame from
* decoder at the same time
* @param ctx The context of mpp
* @param packet[in] The input video stream
* @param frame[out] The output picture
* @return 0 for decode success, others for failure
*/
MPP_RET (*decode)(MppCtx ctx, MppPacket packet, MppFrame *frame);
/**
* @brief send video stream packet to decoder only, async interface
* @param ctx The context of mpp
* @param packet The input video stream
* @return 0 for success, others for failure
*/
MPP_RET (*decode_put_packet)(MppCtx ctx, MppPacket packet);
/**
* @brief get video frame from decoder only, async interface
* @param ctx The context of mpp
* @param frame The output picture
* @return 0 for success, others for failure
*/
MPP_RET (*decode_get_frame)(MppCtx ctx, MppFrame *frame);
/**
* @brief both send video frame to encoder and get encoded video stream from
* encoder at the same time
* @param ctx The context of mpp
* @param frame[in] The input video data
* @param packet[out] The output compressed data
* @return 0 for encode success, others for failure
*/
MPP_RET (*encode)(MppCtx ctx, MppFrame frame, MppPacket *packet);
/**
* @brief send video frame to encoder only, async interface
* @param ctx The context of mpp
* @param frame The input video data
* @return 0 for success, others for failure
*/
MPP_RET (*encode_put_frame)(MppCtx ctx, MppFrame frame);
/**
* @brief get encoded video packet from encoder only, async interface
* @param ctx The context of mpp
* @param packet The output compressed data
* @return 0 for success, others for failure
*/
MPP_RET (*encode_get_packet)(MppCtx ctx, MppPacket *packet);
MPP_RET (*isp)(MppCtx ctx, MppFrame dst, MppFrame src);
MPP_RET (*isp_put_frame)(MppCtx ctx, MppFrame frame);
MPP_RET (*isp_get_frame)(MppCtx ctx, MppFrame *frame);
// advance data flow interface
/**
* @brief poll port for dequeue
* @param ctx The context of mpp
* @param type input port or output port which are both for data transaction
* @return 0 for success there is valid task for dequeue, others for failure
*/
MPP_RET (*poll)(MppCtx ctx, MppPortType type, MppPollType timeout);
/**
* @brief dequeue MppTask
* @param ctx The context of mpp
* @param type input port or output port which are both for data transaction
* @param task MppTask which is sent to mpp for process
* @return 0 for success, others for failure
*/
MPP_RET (*dequeue)(MppCtx ctx, MppPortType type, MppTask *task);
/**
* @brief enqueue MppTask
* @param ctx The context of mpp
* @param type input port or output port which are both for data transaction
* @param task MppTask which is sent to mpp for process
* @return 0 for success, others for failure
*/
MPP_RET (*enqueue)(MppCtx ctx, MppPortType type, MppTask task);
// control interface
/**
* @brief discard all packet and frame, reset all component,
* for both decoder and encoder
* @param ctx The context of mpp
*/
MPP_RET (*reset)(MppCtx ctx);
/**
* @brief control function for mpp property setting
* @param ctx The context of mpp
* @param cmd The mpi command
* @param param The mpi command parameter
* @return 0 for success, others for failure
*/
MPP_RET (*control)(MppCtx ctx, MpiCmd cmd, MppParam param);
/**
* @brief The reserved segment
*/
RK_U32 reserv[16];
} MppApi;
#ifdef __cplusplus
extern "C" {
#endif
/**
* @ingroup rk_mpi
* @brief Create empty context structure and mpi function pointers.
* Use functions in MppApi to access mpp services.
* @param ctx pointer of the mpp context
* @param mpi pointer of mpi function
*/
MPP_RET mpp_create(MppCtx *ctx, MppApi **mpi);
/**
* @ingroup rk_mpi
* @brief Call after mpp_create to setup mpp type and video format.
* This function will call internal context init function.
* @param ctx The context of mpp
* @param type MppCtxType, decoder or encoder
* @param coding video compression coding
*/
MPP_RET mpp_init(MppCtx ctx, MppCtxType type, MppCodingType coding);
/**
* @ingroup rk_mpi
* @brief Destroy mpp context and free both context and mpi structure
* @param ctx The context of mpp
*/
MPP_RET mpp_destroy(MppCtx ctx);
// coding type format function
MPP_RET mpp_check_support_format(MppCtxType type, MppCodingType coding);
void mpp_show_support_format(void);
void mpp_show_color_format(void);
#ifdef __cplusplus
}
#endif
#endif /*__RK_MPI_H__*/
+196
View File
@@ -0,0 +1,196 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __RK_MPI_CMD_H__
#define __RK_MPI_CMD_H__
/*
* Command id bit usage is defined as follows:
* bit 20 - 23 - module id
* bit 16 - 19 - contex id
* bit 0 - 15 - command id
*/
#define CMD_MODULE_ID_MASK (0x00F00000)
#define CMD_MODULE_OSAL (0x00100000)
#define CMD_MODULE_MPP (0x00200000)
#define CMD_MODULE_CODEC (0x00300000)
#define CMD_MODULE_HAL (0x00400000)
#define CMD_CTX_ID_MASK (0x000F0000)
#define CMD_CTX_ID_DEC (0x00010000)
#define CMD_CTX_ID_ENC (0x00020000)
#define CMD_CTX_ID_ISP (0x00030000)
/* separate encoder control command to different segment */
#define CMD_CFG_ID_MASK (0x0000FF00)
#define CMD_ENC_CFG_ALL (0x00000000)
#define CMD_ENC_CFG_RC_API (0x00000100)
#define CMD_ENC_CFG_FRM (0x00000200)
#define CMD_ENC_CFG_PREP (0x00000300)
#define CMD_ENC_CFG_CODEC (0x00001000)
#define CMD_ENC_CFG_H264 (0x00001000)
#define CMD_ENC_CFG_H265 (0x00001800)
#define CMD_ENC_CFG_VP8 (0x00002000)
#define CMD_ENC_CFG_VP9 (0x00002800)
#define CMD_ENC_CFG_AV1 (0x00003000)
#define CMD_ENC_CFG_MJPEG (0x00004000)
#define CMD_ENC_CFG_MISC (0x00008000)
#define CMD_ENC_CFG_SPLIT (0x00008100)
#define CMD_ENC_CFG_GOPREF (0x00008200)
#define CMD_ENC_CFG_ROI (0x00008300)
#define CMD_ENC_CFG_OSD (0x00008400)
typedef enum {
MPP_OSAL_CMD_BASE = CMD_MODULE_OSAL,
MPP_OSAL_CMD_END,
MPP_CMD_BASE = CMD_MODULE_MPP,
MPP_ENABLE_DEINTERLACE,
MPP_SET_INPUT_BLOCK, /* deprecated */
MPP_SET_INTPUT_BLOCK_TIMEOUT, /* deprecated */
MPP_SET_OUTPUT_BLOCK, /* deprecated */
MPP_SET_OUTPUT_BLOCK_TIMEOUT, /* deprecated */
/*
* timeout setup, refer to MPP_TIMEOUT_XXX
* zero - non block
* negative - block with no timeout
* positive - timeout in milisecond
*/
MPP_SET_INPUT_TIMEOUT, /* parameter type RK_S64 */
MPP_SET_OUTPUT_TIMEOUT, /* parameter type RK_S64 */
MPP_CMD_END,
MPP_CODEC_CMD_BASE = CMD_MODULE_CODEC,
MPP_CODEC_GET_FRAME_INFO,
MPP_CODEC_CMD_END,
MPP_DEC_CMD_BASE = CMD_MODULE_CODEC | CMD_CTX_ID_DEC,
MPP_DEC_SET_FRAME_INFO, /* vpu api legacy control for buffer slot dimension init */
MPP_DEC_SET_EXT_BUF_GROUP, /* IMPORTANT: set external buffer group to mpp decoder */
MPP_DEC_SET_INFO_CHANGE_READY,
MPP_DEC_SET_PRESENT_TIME_ORDER, /* use input time order for output */
MPP_DEC_SET_PARSER_SPLIT_MODE, /* Need to setup before init */
MPP_DEC_SET_PARSER_FAST_MODE, /* Need to setup before init */
MPP_DEC_GET_STREAM_COUNT,
MPP_DEC_GET_VPUMEM_USED_COUNT,
MPP_DEC_SET_VC1_EXTRA_DATA,
MPP_DEC_SET_OUTPUT_FORMAT,
MPP_DEC_SET_DISABLE_ERROR, /* When set it will disable sw/hw error (H.264 / H.265) */
MPP_DEC_SET_IMMEDIATE_OUT,
MPP_DEC_SET_ENABLE_DEINTERLACE, /* MPP enable deinterlace by default. Vpuapi can disable it */
MPP_DEC_CMD_END,
MPP_ENC_CMD_BASE = CMD_MODULE_CODEC | CMD_CTX_ID_ENC,
/* basic encoder setup control */
MPP_ENC_SET_ALL_CFG, /* set MppEncCfgSet structure */
MPP_ENC_GET_ALL_CFG, /* get MppEncCfgSet structure */
MPP_ENC_SET_PREP_CFG, /* set MppEncPrepCfg structure */
MPP_ENC_GET_PREP_CFG, /* get MppEncPrepCfg structure */
MPP_ENC_SET_RC_CFG, /* set MppEncRcCfg structure */
MPP_ENC_GET_RC_CFG, /* get MppEncRcCfg structure */
MPP_ENC_SET_CODEC_CFG, /* set MppEncCodecCfg structure */
MPP_ENC_GET_CODEC_CFG, /* get MppEncCodecCfg structure */
/* runtime encoder setup control */
MPP_ENC_SET_IDR_FRAME, /* next frame will be encoded as intra frame */
MPP_ENC_SET_OSD_LEGACY_0, /* deprecated */
MPP_ENC_SET_OSD_LEGACY_1, /* deprecated */
MPP_ENC_SET_OSD_LEGACY_2, /* deprecated */
MPP_ENC_GET_HDR_SYNC, /* get vps / sps / pps which has better sync behavior parameter is MppPacket */
MPP_ENC_GET_EXTRA_INFO, /* deprecated */
MPP_ENC_SET_SEI_CFG, /* SEI: Supplement Enhancemant Information, parameter is MppSeiMode */
MPP_ENC_GET_SEI_DATA, /* SEI: Supplement Enhancemant Information, parameter is MppPacket */
MPP_ENC_PRE_ALLOC_BUFF, /* allocate buffers before encoding */
MPP_ENC_SET_QP_RANGE, /* used for adjusting qp range, the parameter can be 1 or 2 */
MPP_ENC_SET_ROI_CFG, /* set MppEncROICfg structure */
MPP_ENC_SET_CTU_QP, /* for H265 Encoder,set CTU's size and QP */
/* User define rate control stategy API control */
MPP_ENC_CFG_RC_API = CMD_MODULE_CODEC | CMD_CTX_ID_ENC | CMD_ENC_CFG_RC_API,
/*
* Get RcApiQueryAll structure
* Get all available rate control stategy string and count
*/
MPP_ENC_GET_RC_API_ALL = MPP_ENC_CFG_RC_API + 1,
/*
* Get RcApiQueryType structure
* Get available rate control stategy string with certain type
*/
MPP_ENC_GET_RC_API_BY_TYPE = MPP_ENC_CFG_RC_API + 2,
/*
* Set RcImplApi structure
* Add new or update rate control stategy function pointers
*/
MPP_ENC_SET_RC_API_CFG = MPP_ENC_CFG_RC_API + 3,
/*
* Get RcApiBrief structure
* Get current used rate control stategy brief information (type and name)
*/
MPP_ENC_GET_RC_API_CURRENT = MPP_ENC_CFG_RC_API + 4,
/*
* Set RcApiBrief structure
* Set current used rate control stategy brief information (type and name)
*/
MPP_ENC_SET_RC_API_CURRENT = MPP_ENC_CFG_RC_API + 5,
MPP_ENC_CFG_FRM = CMD_MODULE_CODEC | CMD_CTX_ID_ENC | CMD_ENC_CFG_FRM,
MPP_ENC_SET_FRM, /* set MppFrame structure */
MPP_ENC_GET_FRM, /* get MppFrame structure */
MPP_ENC_CFG_PREP = CMD_MODULE_CODEC | CMD_CTX_ID_ENC | CMD_ENC_CFG_PREP,
MPP_ENC_SET_PREP, /* set MppEncPrepCfg structure */
MPP_ENC_GET_PREP, /* get MppEncPrepCfg structure */
MPP_ENC_CFG_H264 = CMD_MODULE_CODEC | CMD_CTX_ID_ENC | CMD_ENC_CFG_H264,
MPP_ENC_CFG_H265 = CMD_MODULE_CODEC | CMD_CTX_ID_ENC | CMD_ENC_CFG_H265,
MPP_ENC_CFG_VP8 = CMD_MODULE_CODEC | CMD_CTX_ID_ENC | CMD_ENC_CFG_VP8,
MPP_ENC_CFG_MJPEG = CMD_MODULE_CODEC | CMD_CTX_ID_ENC | CMD_ENC_CFG_MJPEG,
MPP_ENC_CFG_MISC = CMD_MODULE_CODEC | CMD_CTX_ID_ENC | CMD_ENC_CFG_MISC,
MPP_ENC_SET_HEADER_MODE, /* set MppEncHeaderMode */
MPP_ENC_GET_HEADER_MODE, /* get MppEncHeaderMode */
MPP_ENC_CFG_SPLIT = CMD_MODULE_CODEC | CMD_CTX_ID_ENC | CMD_ENC_CFG_SPLIT,
MPP_ENC_SET_SPLIT, /* set MppEncSliceSplit structure */
MPP_ENC_GET_SPLIT, /* get MppEncSliceSplit structure */
MPP_ENC_CFG_GOPREF = CMD_MODULE_CODEC | CMD_CTX_ID_ENC | CMD_ENC_CFG_GOPREF,
MPP_ENC_SET_GOPREF, /* set MppEncGopRef structure */
MPP_ENC_CFG_OSD = CMD_MODULE_CODEC | CMD_CTX_ID_ENC | CMD_ENC_CFG_OSD,
MPP_ENC_SET_OSD_PLT_CFG, /* set OSD palette, parameter should be pointer to MppEncOSDPltCfg */
MPP_ENC_GET_OSD_PLT_CFG, /* get OSD palette, parameter should be pointer to MppEncOSDPltCfg */
MPP_ENC_SET_OSD_DATA_CFG, /* set OSD data with at most 8 regions, parameter should be pointer to MppEncOSDData */
MPP_ENC_GET_OSD_DATA_CFG, /* get OSD data with at most 8 regions, parameter should be pointer to MppEncOSDData */
MPP_ENC_CMD_END,
MPP_ISP_CMD_BASE = CMD_MODULE_CODEC | CMD_CTX_ID_ISP,
MPP_ISP_CMD_END,
MPP_HAL_CMD_BASE = CMD_MODULE_HAL,
MPP_HAL_CMD_END,
MPI_CMD_BUTT,
} MpiCmd;
#include "rk_venc_cmd.h"
#endif /*__RK_MPI_CMD_H__*/
+137
View File
@@ -0,0 +1,137 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __RK_TYPE_H__
#define __RK_TYPE_H__
#include <stddef.h>
#if defined(_WIN32) && !defined(__MINGW32CE__)
typedef unsigned char RK_U8;
typedef unsigned short RK_U16;
typedef unsigned int RK_U32;
typedef unsigned long RK_ULONG;
typedef unsigned __int64 RK_U64;
typedef signed char RK_S8;
typedef signed short RK_S16;
typedef signed int RK_S32;
typedef signed long RK_LONG;
typedef signed __int64 RK_S64;
#else
typedef unsigned char RK_U8;
typedef unsigned short RK_U16;
typedef unsigned int RK_U32;
typedef unsigned long RK_ULONG;
typedef unsigned long long int RK_U64;
typedef signed char RK_S8;
typedef signed short RK_S16;
typedef signed int RK_S32;
typedef signed long RK_LONG;
typedef signed long long int RK_S64;
#endif
#ifndef MODULE_TAG
#define MODULE_TAG NULL
#endif
/**
* @ingroup rk_mpi
* @brief The type of mpp context
*/
typedef enum {
MPP_CTX_DEC, /**< decoder */
MPP_CTX_ENC, /**< encoder */
MPP_CTX_ISP, /**< isp */
MPP_CTX_BUTT, /**< undefined */
} MppCtxType;
/**
* @ingroup rk_mpi
* @brief Enumeration used to define the possible video compression codings.
* sync with the omx_video.h
*
* @note This essentially refers to file extensions. If the coding is
* being used to specify the ENCODE type, then additional work
* must be done to configure the exact flavor of the compression
* to be used. For decode cases where the user application can
* not differentiate between MPEG-4 and H.264 bit streams, it is
* up to the codec to handle this.
*/
typedef enum {
MPP_VIDEO_CodingUnused, /**< Value when coding is N/A */
MPP_VIDEO_CodingAutoDetect, /**< Autodetection of coding type */
MPP_VIDEO_CodingMPEG2, /**< AKA: H.262 */
MPP_VIDEO_CodingH263, /**< H.263 */
MPP_VIDEO_CodingMPEG4, /**< MPEG-4 */
MPP_VIDEO_CodingWMV, /**< Windows Media Video (WMV1,WMV2,WMV3)*/
MPP_VIDEO_CodingRV, /**< all versions of Real Video */
MPP_VIDEO_CodingAVC, /**< H.264/AVC */
MPP_VIDEO_CodingMJPEG, /**< Motion JPEG */
MPP_VIDEO_CodingVP8, /**< VP8 */
MPP_VIDEO_CodingVP9, /**< VP9 */
MPP_VIDEO_CodingVC1 = 0x01000000, /**< Windows Media Video (WMV1,WMV2,WMV3)*/
MPP_VIDEO_CodingFLV1, /**< Sorenson H.263 */
MPP_VIDEO_CodingDIVX3, /**< DIVX3 */
MPP_VIDEO_CodingVP6,
MPP_VIDEO_CodingHEVC, /**< H.265/HEVC */
MPP_VIDEO_CodingAVSPLUS, /**< AVS+ */
MPP_VIDEO_CodingAVS, /**< AVS profile=0x20 */
MPP_VIDEO_CodingKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
MPP_VIDEO_CodingVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
MPP_VIDEO_CodingMax = 0x7FFFFFFF
} MppCodingType;
/*
* All external interface object list here.
* The interface object is defined as void * for expandability
* The cross include between these objects will introduce extra
* compiling difficulty. So we move them together in this header.
*
* Object interface header list:
*
* MppCtx - rk_mpi.h
* MppParam - rk_mpi.h
*
* MppFrame - mpp_frame.h
* MppPacket - mpp_packet.h
*
* MppBuffer - mpp_buffer.h
* MppBufferGroup - mpp_buffer.h
*
* MppTask - mpp_task.h
* MppMeta - mpp_meta.h
*/
typedef void* MppCtx;
typedef void* MppParam;
typedef void* MppFrame;
typedef void* MppPacket;
typedef void* MppBuffer;
typedef void* MppBufferGroup;
typedef void* MppTask;
typedef void* MppMeta;
#endif /*__RK_TYPE_H__*/
+1182
View File
File diff suppressed because it is too large Load Diff
+85
View File
@@ -0,0 +1,85 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __UTILS_H__
#define __UTILS_H__
#include <stdio.h>
#include "mpp_frame.h"
typedef struct OptionInfo_t {
const char* name;
const char* argname;
const char* help;
} OptionInfo;
typedef struct data_crc_t {
RK_U32 len;
RK_U32 sum;
RK_U32 vor; // value of the xor
} DataCrc;
typedef struct frame_crc_t {
DataCrc luma;
DataCrc chroma;
} FrmCrc;
#define show_options(opt) \
do { \
_show_options(sizeof(opt)/sizeof(OptionInfo), opt); \
} while (0)
#ifdef __cplusplus
extern "C" {
#endif
void _show_options(int count, OptionInfo *options);
void dump_mpp_frame_to_file(MppFrame frame, FILE *fp);
void calc_data_crc(RK_U8 *dat, RK_U32 len, DataCrc *crc);
void write_data_crc(FILE *fp, DataCrc *crc);
void read_data_crc(FILE *fp, DataCrc *crc);
void calc_frm_crc(MppFrame frame, FrmCrc *crc);
void write_frm_crc(FILE *fp, FrmCrc *crc);
void read_frm_crc(FILE *fp, FrmCrc *crc);
MPP_RET read_image(RK_U8 *buf, FILE *fp, RK_U32 width, RK_U32 height,
RK_U32 hor_stride, RK_U32 ver_stride,
MppFrameFormat fmt);
MPP_RET fill_image(RK_U8 *buf, RK_U32 width, RK_U32 height,
RK_U32 hor_stride, RK_U32 ver_stride, MppFrameFormat fmt,
RK_U32 frame_count);
typedef struct OpsLine_t {
RK_U32 index;
char cmd[8];
RK_U64 value1;
RK_U64 value2;
} OpsLine;
RK_S32 parse_config_line(const char *str, OpsLine *info);
MPP_RET name_to_frame_format(const char *name, MppFrameFormat *fmt);
MPP_RET name_to_coding_type(const char *name, MppCodingType *coding);
#ifdef __cplusplus
}
#endif
#endif /*__UTILS_H__*/
Executable
+153
View File
@@ -0,0 +1,153 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __VPU_H__
#define __VPU_H__
#ifdef __cplusplus
extern "C"
{
#endif
#include "rk_type.h"
#define VPU_SUCCESS (0)
#define VPU_FAILURE (-1)
#define VPU_HW_WAIT_OK VPU_SUCCESS
#define VPU_HW_WAIT_ERROR VPU_FAILURE
#define VPU_HW_WAIT_TIMEOUT 1
// vpu decoder 60 registers, size 240B
#define VPU_REG_NUM_DEC (60)
// vpu post processor 41 registers, size 164B
#define VPU_REG_NUM_PP (41)
// vpu decoder + post processor 101 registers, size 404B
#define VPU_REG_NUM_DEC_PP (VPU_REG_NUM_DEC+VPU_REG_NUM_PP)
// vpu encoder 96 registers, size 384B
#define VPU_REG_NUM_ENC (96)
typedef enum {
VPU_ENC = 0x0,
VPU_DEC = 0x1,
VPU_PP = 0x2,
VPU_DEC_PP = 0x3,
VPU_DEC_HEVC = 0x4,
VPU_DEC_RKV = 0x5,
VPU_ENC_RKV = 0x6,
VPU_DEC_AVS = 0x7,
VPU_ENC_VEPU22 = 0x8,
VPU_TYPE_BUTT ,
} VPU_CLIENT_TYPE;
/* Hardware decoder configuration description */
typedef struct VPUHwDecConfig {
RK_U32 maxDecPicWidth; /* Maximum video decoding width supported */
RK_U32 maxPpOutPicWidth; /* Maximum output width of Post-Processor */
RK_U32 h264Support; /* HW supports h.264 */
RK_U32 jpegSupport; /* HW supports JPEG */
RK_U32 mpeg4Support; /* HW supports MPEG-4 */
RK_U32 customMpeg4Support; /* HW supports custom MPEG-4 features */
RK_U32 vc1Support; /* HW supports VC-1 Simple */
RK_U32 mpeg2Support; /* HW supports MPEG-2 */
RK_U32 ppSupport; /* HW supports post-processor */
RK_U32 ppConfig; /* HW post-processor functions bitmask */
RK_U32 sorensonSparkSupport; /* HW supports Sorenson Spark */
RK_U32 refBufSupport; /* HW supports reference picture buffering */
RK_U32 vp6Support; /* HW supports VP6 */
RK_U32 vp7Support; /* HW supports VP7 */
RK_U32 vp8Support; /* HW supports VP8 */
RK_U32 avsSupport; /* HW supports AVS */
RK_U32 jpegESupport; /* HW supports JPEG extensions */
RK_U32 rvSupport; /* HW supports REAL */
RK_U32 mvcSupport; /* HW supports H264 MVC extension */
} VPUHwDecConfig_t;
/* Hardware encoder configuration description */
typedef struct VPUHwEndConfig {
RK_U32 maxEncodedWidth; /* Maximum supported width for video encoding (not JPEG) */
RK_U32 h264Enabled; /* HW supports H.264 */
RK_U32 jpegEnabled; /* HW supports JPEG */
RK_U32 mpeg4Enabled; /* HW supports MPEG-4 */
RK_U32 vsEnabled; /* HW supports video stabilization */
RK_U32 rgbEnabled; /* HW supports RGB input */
RK_U32 reg_size; /* HW bus type in use */
RK_U32 reserv[2];
} VPUHwEncConfig_t;
typedef enum {
// common command
VPU_CMD_REGISTER ,
VPU_CMD_REGISTER_ACK_OK ,
VPU_CMD_REGISTER_ACK_FAIL ,
VPU_CMD_UNREGISTER ,
VPU_SEND_CONFIG ,
VPU_SEND_CONFIG_ACK_OK ,
VPU_SEND_CONFIG_ACK_FAIL ,
VPU_GET_HW_INFO ,
VPU_GET_HW_INFO_ACK_OK ,
VPU_GET_HW_INFO_ACK_FAIL ,
VPU_CMD_BUTT ,
} VPU_CMD_TYPE;
typedef enum {
MPP_DEV_CMD_QUERY_BASE = 0,
MPP_DEV_CMD_PROBE_HW_SUPPORT = MPP_DEV_CMD_QUERY_BASE + 0,
MPP_DEV_CMD_PROBE_IOMMU_STATUS = MPP_DEV_CMD_QUERY_BASE + 1,
MPP_DEV_CMD_INIT_BASE = 0x100,
MPP_DEV_CMD_INIT_CLIENT_TYPE = MPP_DEV_CMD_INIT_BASE + 0,
MPP_DEV_CMD_INIT_DRIVER_DATA = MPP_DEV_CMD_INIT_BASE + 1,
MPP_DEV_CMD_INIT_TRANS_TABLE = MPP_DEV_CMD_INIT_BASE + 2,
MPP_DEV_CMD_SEND_BASE = 0x200,
MPP_DEV_CMD_SET_REG_WRITE = MPP_DEV_CMD_SEND_BASE + 0,
MPP_DEV_CMD_SET_REG_READ = MPP_DEV_CMD_SEND_BASE + 1,
MPP_DEV_CMD_SET_REG_ADDR_OFFSET = MPP_DEV_CMD_SEND_BASE + 2,
MPP_DEV_CMD_POLL_BASE = 0x300,
MPP_DEV_CMD_POLL_HW_FINISH = MPP_DEV_CMD_POLL_BASE + 0,
MPP_DEV_CMD_CONTROL_BASE = 0x400,
MPP_DEV_CMD_RESET_SESSION = MPP_DEV_CMD_CONTROL_BASE + 0,
MPP_DEV_CMD_TRANS_FD_TO_IOVA = MPP_DEV_CMD_CONTROL_BASE + 1,
MPP_DEV_CMD_RELEASE_FD = MPP_DEV_CMD_CONTROL_BASE + 2,
MPP_DEV_CMD_BUTT,
} MPP_DEV_CMD_TYPE;
int VPUClientInit(VPU_CLIENT_TYPE type);
RK_S32 VPUClientRelease(int socket);
RK_S32 VPUClientSendReg(int socket, RK_U32 *regs, RK_U32 nregs);
RK_S32 VPUClientSendReg2(RK_S32 socket, RK_S32 offset, RK_S32 size, void *param);
RK_S32 VPUClientWaitResult(int socket, RK_U32 *regs, RK_U32 nregs, VPU_CMD_TYPE *cmd, RK_S32 *len);
RK_S32 VPUClientGetHwCfg(int socket, RK_U32 *cfg, RK_U32 cfg_size);
RK_S32 VPUClientGetIOMMUStatus();
RK_U32 VPUCheckSupportWidth();
#ifdef __cplusplus
}
#endif
#endif /* __VPU_H__ */
+459
View File
@@ -0,0 +1,459 @@
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __VPU_API_LEGACY_H__
#define __VPU_API_LEGACY_H__
#include "rk_type.h"
#include "mpp_err.h"
/**
* @brief rockchip media process interface
*/
#define VPU_API_NOPTS_VALUE (0x8000000000000000LL)
/*
* bit definition of ColorType in structure VPU_FRAME
*/
#define VPU_OUTPUT_FORMAT_TYPE_MASK (0x0000ffff)
#define VPU_OUTPUT_FORMAT_ARGB8888 (0x00000000)
#define VPU_OUTPUT_FORMAT_ABGR8888 (0x00000001)
#define VPU_OUTPUT_FORMAT_RGB888 (0x00000002)
#define VPU_OUTPUT_FORMAT_RGB565 (0x00000003)
#define VPU_OUTPUT_FORMAT_RGB555 (0x00000004)
#define VPU_OUTPUT_FORMAT_YUV420_SEMIPLANAR (0x00000005)
#define VPU_OUTPUT_FORMAT_YUV420_PLANAR (0x00000006)
#define VPU_OUTPUT_FORMAT_YUV422 (0x00000007)
#define VPU_OUTPUT_FORMAT_YUV444 (0x00000008)
#define VPU_OUTPUT_FORMAT_YCH420 (0x00000009)
#define VPU_OUTPUT_FORMAT_BIT_MASK (0x000f0000)
#define VPU_OUTPUT_FORMAT_BIT_8 (0x00000000)
#define VPU_OUTPUT_FORMAT_BIT_10 (0x00010000)
#define VPU_OUTPUT_FORMAT_BIT_12 (0x00020000)
#define VPU_OUTPUT_FORMAT_BIT_14 (0x00030000)
#define VPU_OUTPUT_FORMAT_BIT_16 (0x00040000)
#define VPU_OUTPUT_FORMAT_COLORSPACE_MASK (0x00f00000)
#define VPU_OUTPUT_FORMAT_COLORSPACE_BT709 (0x00100000)
#define VPU_OUTPUT_FORMAT_COLORSPACE_BT2020 (0x00200000)
#define VPU_OUTPUT_FORMAT_DYNCRANGE_MASK (0x0f000000)
#define VPU_OUTPUT_FORMAT_DYNCRANGE_SDR (0x00000000)
#define VPU_OUTPUT_FORMAT_DYNCRANGE_HDR10 (0x01000000)
#define VPU_OUTPUT_FORMAT_DYNCRANGE_HDR_HLG (0x02000000)
#define VPU_OUTPUT_FORMAT_DYNCRANGE_HDR_DOLBY (0x03000000)
/**
* @brief input picture type
*/
typedef enum {
ENC_INPUT_YUV420_PLANAR = 0, /**< YYYY... UUUU... VVVV */
ENC_INPUT_YUV420_SEMIPLANAR = 1, /**< YYYY... UVUVUV... */
ENC_INPUT_YUV422_INTERLEAVED_YUYV = 2, /**< YUYVYUYV... */
ENC_INPUT_YUV422_INTERLEAVED_UYVY = 3, /**< UYVYUYVY... */
ENC_INPUT_RGB565 = 4, /**< 16-bit RGB */
ENC_INPUT_BGR565 = 5, /**< 16-bit RGB */
ENC_INPUT_RGB555 = 6, /**< 15-bit RGB */
ENC_INPUT_BGR555 = 7, /**< 15-bit RGB */
ENC_INPUT_RGB444 = 8, /**< 12-bit RGB */
ENC_INPUT_BGR444 = 9, /**< 12-bit RGB */
ENC_INPUT_RGB888 = 10, /**< 24-bit RGB */
ENC_INPUT_BGR888 = 11, /**< 24-bit RGB */
ENC_INPUT_RGB101010 = 12, /**< 30-bit RGB */
ENC_INPUT_BGR101010 = 13 /**< 30-bit RGB */
} EncInputPictureType;
typedef enum VPU_API_CMD {
VPU_API_ENC_SETCFG,
VPU_API_ENC_GETCFG,
VPU_API_ENC_SETFORMAT,
VPU_API_ENC_SETIDRFRAME,
VPU_API_ENABLE_DEINTERLACE,
VPU_API_SET_VPUMEM_CONTEXT,
VPU_API_USE_PRESENT_TIME_ORDER,
VPU_API_SET_DEFAULT_WIDTH_HEIGH,
VPU_API_SET_INFO_CHANGE,
VPU_API_USE_FAST_MODE,
VPU_API_DEC_GET_STREAM_COUNT,
VPU_API_GET_VPUMEM_USED_COUNT,
VPU_API_GET_FRAME_INFO,
VPU_API_SET_OUTPUT_BLOCK,
VPU_API_GET_EOS_STATUS,
VPU_API_SET_IMMEDIATE_OUT = 0x1000,
VPU_API_ENC_VEPU22_START = 0x2000,
VPU_API_ENC_SET_VEPU22_CFG,
VPU_API_ENC_GET_VEPU22_CFG,
VPU_API_ENC_SET_VEPU22_CTU_QP,
VPU_API_ENC_SET_VEPU22_ROI,
} VPU_API_CMD;
typedef struct {
RK_U32 TimeLow;
RK_U32 TimeHigh;
} TIME_STAMP;
typedef struct {
RK_U32 CodecType;
RK_U32 ImgWidth;
RK_U32 ImgHeight;
RK_U32 ImgHorStride;
RK_U32 ImgVerStride;
RK_U32 BufSize;
} VPU_GENERIC;
typedef struct VPUMem {
RK_U32 phy_addr;
RK_U32 *vir_addr;
RK_U32 size;
RK_U32 *offset;
} VPUMemLinear_t;
typedef struct tVPU_FRAME {
RK_U32 FrameBusAddr[2]; // 0: Y address; 1: UV address;
RK_U32 FrameWidth; // buffer horizontal stride
RK_U32 FrameHeight; // buffer vertical stride
RK_U32 OutputWidth; // deprecated
RK_U32 OutputHeight; // deprecated
RK_U32 DisplayWidth; // valid width for display
RK_U32 DisplayHeight; // valid height for display
RK_U32 CodingType;
RK_U32 FrameType; // frame; top_field_first; bot_field_first
RK_U32 ColorType;
RK_U32 DecodeFrmNum;
TIME_STAMP ShowTime;
RK_U32 ErrorInfo; // error information
RK_U32 employ_cnt;
VPUMemLinear_t vpumem;
struct tVPU_FRAME *next_frame;
union {
struct {
RK_U32 Res0[2];
struct {
RK_U32 ColorPrimaries : 8;
RK_U32 ColorTransfer : 8;
RK_U32 ColorCoeffs : 8;
RK_U32 ColorRange : 1;
RK_U32 Res1 : 7;
};
RK_U32 Res2;
};
RK_U32 Res[4];
};
} VPU_FRAME;
typedef struct VideoPacket {
RK_S64 pts; /* with unit of us*/
RK_S64 dts; /* with unit of us*/
RK_U8 *data;
RK_S32 size;
RK_U32 capability;
RK_U32 nFlags;
} VideoPacket_t;
typedef struct DecoderOut {
RK_U8 *data;
RK_U32 size;
RK_S64 timeUs;
RK_S32 nFlags;
} DecoderOut_t;
typedef struct ParserOut {
RK_U8 *data;
RK_U32 size;
RK_S64 timeUs;
RK_U32 nFlags;
RK_U32 width;
RK_U32 height;
} ParserOut_t;
typedef struct EncInputStream {
RK_U8 *buf;
RK_S32 size;
RK_U32 bufPhyAddr;
RK_S64 timeUs;
RK_U32 nFlags;
} EncInputStream_t;
typedef struct EncoderOut {
RK_U8 *data;
RK_S32 size;
RK_S64 timeUs;
RK_S32 keyFrame;
} EncoderOut_t;
/*
* @brief Enumeration used to define the possible video compression codings.
* @note This essentially refers to file extensions. If the coding is
* being used to specify the ENCODE type, then additional work
* must be done to configure the exact flavor of the compression
* to be used. For decode cases where the user application can
* not differentiate between MPEG-4 and H.264 bit streams, it is
* up to the codec to handle this.
*
* sync with the omx_video.h
*/
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)*/
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, /**< Windows Media Video (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_CodingAVS, /**< AVS+ */
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;
typedef enum CODEC_TYPE {
CODEC_NONE,
CODEC_DECODER,
CODEC_ENCODER,
CODEC_BUTT,
} CODEC_TYPE;
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;
typedef enum VPU_FRAME_ERR {
VPU_FRAME_ERR_UNKNOW = 0x0001,
VPU_FRAME_ERR_UNSUPPORT = 0x0002,
} VPU_FRAME_ERR;
typedef struct EncParameter {
RK_S32 width;
RK_S32 height;
RK_S32 rc_mode; /* 0 - CQP mode; 1 - CBR mode; */
RK_S32 bitRate; /* target bitrate */
RK_S32 framerate;
RK_S32 qp;
RK_S32 enableCabac;
RK_S32 cabacInitIdc;
RK_S32 format;
RK_S32 intraPicRate;
RK_S32 framerateout;
RK_S32 profileIdc;
RK_S32 levelIdc;
RK_S32 reserved[3];
} EncParameter_t;
typedef struct EXtraCfg {
RK_S32 vc1extra_size;
RK_S32 vp6codeid;
RK_S32 tsformat;
RK_U32 ori_vpu; /* use origin vpu framework */
/* below used in decode */
RK_U32 mpp_mode; /* use mpp framework */
RK_U32 bit_depth; /* 8 or 10 bit */
RK_U32 yuv_format; /* 0:420 1:422 2:444 */
RK_U32 reserved[16];
} EXtraCfg_t;
/**
* @brief vpu function interface
*/
typedef struct VpuCodecContext {
void* vpuApiObj;
CODEC_TYPE codecType;
OMX_RK_VIDEO_CODINGTYPE videoCoding;
RK_U32 width;
RK_U32 height;
void *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);
/**
* @brief both send video stream packet to decoder and get video frame from
* decoder at the same time
* @param ctx The context of vpu codec
* @param pkt[in] Stream to be decoded
* @param aDecOut[out] Decoding frame
* @return 0 for decode success, others for failure.
*/
RK_S32 (*decode)(struct VpuCodecContext *ctx, VideoPacket_t *pkt, DecoderOut_t *aDecOut);
/**
* @brief both send video frame to encoder and get encoded video stream from
* encoder at the same time.
* @param ctx The context of vpu codec
* @param aEncInStrm[in] Frame to be encoded
* @param aEncOut[out] Encoding stream
* @return 0 for encode success, others for failure.
*/
RK_S32 (*encode)(struct VpuCodecContext *ctx, EncInputStream_t *aEncInStrm, EncoderOut_t *aEncOut);
/**
* @brief flush codec while do fast forward playing.
* @param ctx The context of vpu codec
* @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);
/**
* @brief send video stream packet to decoder only, async interface
* @param ctx The context of vpu codec
* @param pkt Stream to be decoded
* @return 0 for success, others for failure.
*/
RK_S32 (*decode_sendstream)(struct VpuCodecContext *ctx, VideoPacket_t *pkt);
/**
* @brief get video frame from decoder only, async interface
* @param ctx The context of vpu codec
* @param aDecOut Decoding frame
* @return 0 for success, others for failure.
*/
RK_S32 (*decode_getframe)(struct VpuCodecContext *ctx, DecoderOut_t *aDecOut);
/**
* @brief send video frame to encoder only, async interface
* @param ctx The context of vpu codec
* @param aEncInStrm Frame to be encoded
* @return 0 for success, others for failure.
*/
RK_S32 (*encoder_sendframe)(struct VpuCodecContext *ctx, EncInputStream_t *aEncInStrm);
/**
* @brief get encoded video packet from encoder only, async interface
* @param ctx The context of vpu codec
* @param aEncOut Encoding stream
* @return 0 for success, others for failure.
*/
RK_S32 (*encoder_getstream)(struct VpuCodecContext *ctx, EncoderOut_t *aEncOut);
} VpuCodecContext_t;
/* allocated vpu codec context */
#ifdef __cplusplus
extern "C"
{
#endif
/**
* @brief open context of vpu
* @param ctx pointer of vpu codec context
*/
RK_S32 vpu_open_context(struct VpuCodecContext **ctx);
/**
* @brief close context of vpu
* @param ctx pointer of vpu codec context
*/
RK_S32 vpu_close_context(struct VpuCodecContext **ctx);
#ifdef __cplusplus
}
#endif
/*
* vpu_mem api
*/
#define vpu_display_mem_pool_FIELDS \
RK_S32 (*commit_hdl)(vpu_display_mem_pool *p, RK_S32 hdl, RK_S32 size); \
void* (*get_free)(vpu_display_mem_pool *p); \
RK_S32 (*inc_used)(vpu_display_mem_pool *p, void *hdl); \
RK_S32 (*put_used)(vpu_display_mem_pool *p, void *hdl); \
RK_S32 (*reset)(vpu_display_mem_pool *p); \
RK_S32 (*get_unused_num)(vpu_display_mem_pool *p); \
RK_S32 buff_size;\
float version; \
RK_S32 res[18];
typedef struct vpu_display_mem_pool vpu_display_mem_pool;
struct vpu_display_mem_pool {
vpu_display_mem_pool_FIELDS
};
#ifdef __cplusplus
extern "C"
{
#endif
/*
* vpu memory handle interface
*/
RK_S32 VPUMemJudgeIommu(void);
RK_S32 VPUMallocLinear(VPUMemLinear_t *p, RK_U32 size);
RK_S32 VPUFreeLinear(VPUMemLinear_t *p);
RK_S32 VPUMemDuplicate(VPUMemLinear_t *dst, VPUMemLinear_t *src);
RK_S32 VPUMemLink(VPUMemLinear_t *p);
RK_S32 VPUMemFlush(VPUMemLinear_t *p);
RK_S32 VPUMemClean(VPUMemLinear_t *p);
RK_S32 VPUMemInvalidate(VPUMemLinear_t *p);
RK_S32 VPUMemGetFD(VPUMemLinear_t *p);
RK_S32 VPUMallocLinearFromRender(VPUMemLinear_t *p, RK_U32 size, void *ctx);
/*
* vpu memory allocator and manager interface
*/
vpu_display_mem_pool* open_vpu_memory_pool(void);
void close_vpu_memory_pool(vpu_display_mem_pool *p);
int create_vpu_memory_pool_allocator(vpu_display_mem_pool **ipool, int num, int size);
void release_vpu_memory_pool_allocator(vpu_display_mem_pool *ipool);
#ifdef __cplusplus
}
#endif
#endif /*__VPU_API_LEGACY_H__*/