Use the Codec Engine API function (4), codecengine

Source: Internet
Author: User

Use the Codec Engine API function (4), codecengine
This article is translated from TI's manual, which is a golden document for studying GPP + DSP development. I hope it will be helpful for you to get started. Please kindly advise if you have any improper understanding.
Codec Engine Application Developer User's Guide.pdf (Literature Number: SPRUE67D)
Codec Engine application development user manual http://blog.csdn.net/dyzok88/article/details/42154487
Chapter I Codec Engine overview http://blog.csdn.net/dyzok88/article/details/42214813
Chapter 2 Codec Engine installation and setting http://blog.csdn.net/dyzok88/article/details/42278109

Chapter 3 sample applications using Codec Engine http://blog.csdn.net/dyzok88/article/details/42302793


// Body


4.4 Codec Server API functions

In a dual-CPU system, the configured engine runs (in DSP) algorithms remotely and transparently uses a DSP server ". The DSP Server is an executable program that integrates an algorithm and its framework (such as DSP/BIOS, framework components, codecs, and DSP Link drivers). When the engine is turned on, these components are loaded on the DSP and started to run.

The Server API function can be called by applications running on GPP. It can access information about DSP servers and control DSP servers. More specifically, these API functions allow GPP applications to obtain information about the memory heap quantity configured in the DSP server, and the current usage of a separate memory heap. And reconfigure the base address and size of the algorithm heap of the DSP server.

The server-related API functions are:
1. Engine_getServer (). Obtain the server handle.

2. Server_getNumMemSegs (). Obtain the number of heaps on a server.

3. Server_getMemStat (). Obtain heap statistics about the server.

4. Server_redefineHeap (). Set the base address and size of the Server Heap.

5. Server_restoreHeap (). Reset the Server Heap to the default base address and size.


4.4.1 get server handle

To access the DSP server engine, the GPP application must first obtain a server handle by calling the Engine_getServer () API. For example:

static String engineName = "auddec";Engine_Handle engine;Server_Handle server;Engine_Error err;engine = Engine_open(engineName, NULL, &err);server = Engine_getServer(engine);

Note: Engine handles and server handles are NOT thread-protected. Each thread must use the server handle to execute its own Engine_getServer () call (use its own engine handle), or ensure synchronous access to the Shared Server handle.

If Engine_getServer () returns NULL, the engine does not have a server.

4.4.2 obtain memory heap Information

GPP applications can call the Server_getNumMemSegs () function to obtain the number of memory heaps configured to the DSP server. For example:

Server_Handle server;Server_Status status;Int numSegs;/* Get the server handle from a previously opened Engine */server = Engine_getServer(engine);status = Server_getNumMemSegs(server, &numSegs);

The following error codes are returned for these API functions:
1. Server_EOK-success. In this case, numSegs contains the number of heaps on the DSP server.
2. Server_ERUNTIME-Internal runtime error.

Once the number of heaps is known, the GPP application uses the Server_getMemStat () function to obtain statistics for each heap Through iteration. The memory statistics are returned to the Server_MemStat struct:

typedef struct Server_MemStat {    Char name[Server_MAXSEGNAMELENTH+1];                           /* Name of heap segment */    Uint32 base;          /* Base address of heap */    Uint32 size;          /* Original heap size */    Uint32 used;          /* DSP MAUs of heap used */    Uint32 maxBlockLen;   /* Length of largest free block */} Server_MemStat;

The following sample code shows the usage of these API functions (ignore error checks for readability)

Server_Handle  server;Int            numSegs, i;Server_MemStat stat;Server_Status  status;status = Server_getNumMemSegs(server, &numSegs);for (i = 0; i < numSegs; i++) {    status = Server_getMemStat(server, i, &stat);    printf("%s: base: 0x%x size: 0x%x used: 0x%x         max free block: 0x%x",        stat.name, stat.base, stat.size, stat.used,         stat.maxBlockLen);}

Server_getMemStat () returns the following values:
1. Server_EOK. Success.
2. Server_ENOTFOUND. The field number is out of the range.

3. Server_ERUNTIME. An internal running error occurs.

4.4.3 reconfigure the algorithm heap of the DSP Server

The DSP server can be configured as a memory segment dedicated to algorithm heap. In some cases, the DSP server is configured with a small algorithm heap. When the GPP application is running, it may need to provide a large continuous memory block for the algorithm heap, which is used by the DSP server. Then, when the heap is not used by the DSP, the memory can be recycled from the DSP and used by GPP. The following Server API functions provide the means to reconfigure the DSP algorithm heap:

Server_Status Server_redefineHeap(Server_Handle server,    String name, Uint32 base, Uint32 size);Server_Status Server_restoreHeap(Server_Handle server,    String name);

The parameter "name" passed to these functions is the name of the heap to be reconfigured; it must be no longer than Server_MAXSEGNAMELENGTH. The "base" address passed to Server_redefineHeap () must be the DSP address. The memory from base to base + size must be continuous physical memory. The parameter "size" is given in the DSP MADUs (minimum addressable data units, minimum addressable data unit. The base address should be 8-byte alignment, but there is no alignment limit on the size. The value of 0 is acceptable.

When no memory is allocated on the heap, the DSP algorithm heap can only be reconfigured. The Server_restoreHeap () function resets the base address and size of the algorithm heap and returns to their original values (any value before Server_redefineHeap () is called ). After Server_restoreHeap () is successfully called, the memory is previously "redefined" to the heap and can be used again by the system.

Server_redefineHeap () returns the following values:
1. Server_EOK. Success.
2. Changed Server_EINVAL to the new base address and size, resulting in overlapping with the other heap.
3. Server_EINUSE. The memory is currently allocated in the algorithm heap.
4. Server_ENOTFOUND. No heap with the specified name is found.

5. Server_ERUNTIME. An internal running error occurs.

Server_restoreHeap () returns any of the following values:

1. Server_EOK. Success.
2. Changed Server_EINVAL to the new base address and size, resulting in overlapping with the other heap.

3. Server_EINUSE. The memory is currently allocated in the algorithm heap.
4. Server_ENOTFOUND. No heap with the specified name is found.
5. Server_ERUNTIME. An internal running error occurs.

The following code illustrates how these two APIs can be used on DM644x (a GPP + DSP device). In this example, GPP applications use Memory_contigAlloc () the function allocates a continuous memory block. However, the address returned by this function is a virtual address of GPP, so it must be transferred to Server_redefineHeap () before conversion to the DSP address, Memory_getBufferPhysicalAddress () the function can convert a virtual address to the physical address of GPP. In this way, DM644x is the address of the same DSP.

After the algorithm runs, the algorithm heap is reset to its original size and position. For better readability, the error check is omitted.

Server_Handle  server = NULL;Server_Status  status;Engine_Handle  ce = NULL;XDAS_Int8     *buf;Uint32         base;String decoderName  = "auddec_copy";String encoderName  = "audenc_copy";String engineName   = "audio_copy";/* Open the Engine and get Server handle. Note, the * Engine_open() call will load and start the DSP. */ce = Engine_open(engineName, NULL, NULL);server = Engine_getServer(ce);/* Allocate block of memory, contiguous in physical memory */buf = (XDAS_Int8 *)Memory_contigAlloc(BUFSIZE, ALIGNMENT);/* Convert virtual address to physical address, which on  * DM644x, happens to be the same as the DSP address. */    base = Memory_getBufferPhysicalAddress(buf, BUFSIZE, NULL);/* Reconfigure the algorithm heap */status = Server_redefineHeap(server, "DDRALGHEAP", base,      BUFSIZE);'Create and run codecs''Delete codecs'/* Reconfigure algorithm heap back to its original state. */status = Server_restoreHeap(server, "DDRALGHEAP");/* Free the buffer */Memory_contigFree(buf, BUFSIZE);

In other cases, the application may need to reconfigure the algorithm to heap an address, and the address cannot be obtained by allocating a buffer on the ARM. For example, assume that there is a fixed memory space on the DSP, which is used by applications for switching between algorithm heap, depending on the algorithm to run. In this case, the application can directly pass the DSP address to the Server_redefineHeap () function.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.