API functions using Codec Engine (iii)

Source: Internet
Author: User

This article is translated from TI's Handbook, the Handbook is a study of gpp+dsp development of the Golden Code document, I hope that the introduction of the help, there is an inappropriate understanding of the hope please enlighten.
Codec Engine application Developer User ' s Guide.pdf (literature number:sprue67d)
"Codec Engine Application Development Manual" http://blog.csdn.net/dyzok88/article/details/42154487
Chapter One Codec Engine Overview http://blog.csdn.net/dyzok88/article/details/42214813
chapter II Installation and setup of Codec Engine http://blog.csdn.net/dyzok88/article/details/42278109
Chapter Three uses CODEC Engine's sample application http://blog.csdn.net/dyzok88/article/details/42302793


Body


the 4th chapter uses the API function of Codec Engine

4.3 VISA Category: Video, image, voice, audio


The following API functions are provided to each VISA Class encoder (encoder ) and decoder (decoder ) Both sides, where mod is the prefix of the module:

1. mod_create. Create an instance of the type algorithm. Create An instance of the this type of algorithm.
2. Mod_process. Executes the "process" method on the instance of this algorithm.
3. Mod_control. Execute the "control" method on the instance of this algorithm .

4. Mod_delete. Deletes the specified instance of this type of algorithm.


4.3.1 VISA API Configuration Code

For each VISA API module that the application uses, you should include the corresponding header file. For example, the following statement includes the header file for the Audio decoder API module, and the directory path is relative to the Ce_install_dir/packages package library.

#include <ti/sdo/ce/audio/auddec.h>

4.3.2 Creating an algorithm instance

Create an instance of the algorithm within the engine to use the *_create () function for the appropriate Visa encoder or decoder module.

Engine_handle CE;  Auddec_handle dec;static String decodername = "auddec_copy";/* Allocate and initialize audio decoder on the Engine */dec = Auddec_create (CE, decodername, NULL);

In this function, the first parameter,-ce-, is the Engine_handle type, which is returned by the Engine_open () function.

The second parameter,-decodername-, is a string that identifies the type of algorithm to be created. These strings are part of the configuration file created by the system integration engineer.

The third parameter allows you to specify the parameters to use when instantiating the algorithm . These parameters control the behavioral aspects of the algorithm. The structure of the parameter differs from each VISA encoder or decoder class. For example, the audio decoder parameter structure is as follows:

typedef struct IAUDDEC_PARAMS {xdas_int32 size;  /* Size of this structure */Xdas_int32 maxsamplerate;  /* Max sampling freq in Hz */Xdas_int32 maxbitrate;      /* Max Bit-rate in bits per sec */Xdas_int32 maxnoofch; /* Max Number of channels */Xdas_int32 dataendianness; /* Endianness of input data */} Iauddec_params;

This function returns a handle that is used for other functions to access the algorithm instance.


4.3.3 Deleting an algorithm instance

To delete an algorithm instance and release its memory footprint, your application should call Mod_delete (). For example:

/* Tear down the codec and Engine */auddec_delete (DEC);

You should do so after you have released all the buffers or other memory-related algorithm instances.


4.3.4 Control Algorithm Example

using the module's *_control () functions can control and query the function of the algorithm.

For example, the following code uses the Auddec_control () function to query a decoder to verify that the decoder accepts an input buffer, returns an output buffer, and uses buffer sizes to process nsamples bytes of data.

#define Nsamples    1024#define iframesize (nsamples * sizeof (INT8))/* RAW (IN) */#define OFRAMESIZE (nsamples * sizeof (INT8)/* decoded */static char inbuf[iframesize];static char outbuf[oframesize]; Xdm_bufdesc                 INBUFDESC; Xdm_bufdesc                 OUTBUFDESC; Xdas_int32                  status; Xdas_int32                  bufsizes = nsamples;iauddec_dynamicparams       Decdynparams;iauddec_status              decstatus;/* prepare "global" bu Ffer Descriptor Settings */inbufdesc.numbufs = Outbufdesc.numbufs = 1;inbufdesc.bufsizes = outbufdesc.bufsizes = &buf sizes;/* Query the decoder */status = Auddec_control (Dec, xdm_getstatus, &decDynParams,      &NBSP;&AM P;decstatus); if (status! = Auddec_eok) {   /* failure,Report error and exit */   printf ("decode Control status =%ld\n", status);   return;} /* Validate decoder codec would meet buffer requirements */if ((Inbufdesc.numbufs > DecStatus.bufInfo.maxNumInBufs) | |     (sizeof (INBUF) > decstatus.bufinfo.maxinbufsize[0]) | |     (Outbufdesc.numbufs > DecStatus.bufInfo.maxNumOutBufs) | |     (sizeof (OUTBUF) > Decstatus.bufinfo.maxoutbufsize[0]) {   /* failure, report error and Exit */    printf ("Error:  decoder codec feature conflict\n");   return;}

In the example of the Auddec_control () function, the first parameter,-dec-, is the handle (handle) of the algorithm returned by the Auddec_create () function.

The second parameter isfromxdm.hof the fileCommand ID Constants, the constant'soptions are:
1.xdm_getstatus. Query algorithm, andpopulate a structure that contains state information about the algorithm's functionalityBody.
2.xdm_setparams. Setting the algorithm run timeof thedynamic parameters.
3.Xdm_getparams.Getcurrent settings for dynamic parameters at runtime for this algorithm.

4 . xdm_reset. Reset algorithm. after an error or data loss occurs , an initialization function or a special function may be run for recovery.

5. Xdm_setdefault. Set all parameters to the default values.

6. Xdm_flush. after the flow condition is processed , the algorithm output is forced, regardless of the additional input. The recommended order is to call the *_control () API with the parameter Xdm_flush and then make repeated calls to the *_process () API.

7. xdm_getbufinfo. Query algorithm Instance , about its input and output buffer properties .

For more information about XDm, please refer to the XDAIS-DM (digital Media) User Guide (SPRUEC8).

If the specified xdm_setparams or xdm_getparams command code is used, the third parameter is the address of a dynamic parameter structure, which differs from the structure of the VISA encoder and decoder module.

If the specified xdm_getstatus command code is used, the fourth parameter is the address of a State structure, which differs from the structure of the VISA encoder and decoder module.


data processing of 4.3.5 algorithm instance

You can run the algorithm using the *_process () function of the module.

For example, the following code continues the example in the previous section. It uses the auddec_process () function to read frames from "in" , decode the audio, and then write the output to "out".

Int                        n; Xdm_bufdesc                inBufDesc; Xdm_bufdesc                outbufdesc;iauddec_inargs         & nbsp   Decinargs;iauddec_outargs            decoutargs;/* Prepare "global" buffer Descripto R settings */inbufdesc.numbufs = Outbufdesc.numbufs = 1;inbufdesc.bufsizes = outbufdesc.bufsizes = &bufSizes; decinargs.size = sizeof (Decinargs), .../* Read complete frames from in, decode and write to out */for (n = 0; Fread (inbuf, sizeof (INBUF), 1, in) = = 1; n++) {    xdas_int8 *src = inbuf;    Xdas_int8 *DST = outbuf;   /* prepare "per loop" Buffe R Descriptor Settings */    INBUFDESC.BUFS = &src;    OUTBUFDESC.BUFS = &dst;    Dec inargs.size = sizeof (Decinargs);    decinargs.numbytes = sizeof (InBUF);   /* decode the frame */    status = Auddec_process (Dec, &inbufdesc, &outbufdesc, & nbsp          &decinargs, &decoutargs);    if (status! = Auddec_eok) {         printf ("frame%d:decode status =%ld\n", n, status);   }   /* Write to file */    Fwrite (DST, sizeof (OUTBUF), 1, out);} printf ("%d frames decoded\n", n);

In the example of the auddec_process () function, the first parameter,-dec-, is the handle (handle) of the algorithm returned by the Auddec_create () function.

for the Audio decoder module (for most other The second and third parameters of the VISA module provide the address of the structure body of the buffer descriptor of type Xdm_bufdesc. This type of structure is defined as follows:

typedef struct XDM_BUFDESC {xdas_int8 **bufs;      Xdas_int32 Numbufs; Xdas_int32 *bufsizes; } Xdm_bufdesc;

for the Audio decoder module (for most other the fourth and fifth parameters of the VISA module provide an address for the input and output parameters of the algorithm. This structure differs from the structure of the VISA encoder and decoder module.


4.3.6rewritepriority and memory requests for remote algorithms

4.3.6.1rewriteprioritization of the algorithm's configuration

in some cases, application developers may want to run multiple instances of a remote codec at different priorities. as an example , suppose you want to run two instances of the sample audio encoder copy codec: One with a priority of 4 and another with a priority of 5. In the server that contains the codec, the originally configured audio encoder runs on priority 4, as shown in the following configuration code (assuming SERVER.MINPRI is 1).

Server.algs = [{name: ' Audenc_copy ', mod:audenc_copy, Threadattrs: {stackmemid:0, Priority:Server.MINPRI + 3}}, ...];

The solution to this problem seems to be by configuring the DSP server by adding another audio encoder that uses the new priority and a different name than the server algorithm list, as follows:

Server.algs = [/* Audio copy encoder configured with priority 4 */{name: "Audenc_copy", Mod:audenc_copy, Threadat TRS: {stackmemid:0, Priority:Server.MINPRI + 3}},/* Audio copy encoder configured with priority 5 (wrong)   */{name: "Audenc_copy_2", Mod:audenc_copy, Threadattrs: {stackmemid:0, Priority:Server.MINPRI + 4}}, ...];

However, when you try to rebuild the server, this causes an error to occur because UUIDs is generated for both codecs. The UUIDs is determined by the MOD (audenc_copy) configuration parameters and the results are identical. Because it is the UUID, not the name of the codec, the information is applied from the arm to the DSP server through and instantiates the codec, and the two codecs cannot be distinguished. Therefore, this method is not feasible.

The correct way to create a codec with a different priority than the  DSP  server configuration is by passing the name parameter to &NBSP;MOD_CR . Span style= "Color:rgb (255,0,0)" >eate ()  api, which mod, is  VISA  One of the modules. The name is the name of the codec with the override ( overriding ) precedence attached to it, separated by ":". For example, run the audio encoder as shown in priority 5 by passing the name " audenc_copy:5 "

Engine_handle CE;    Audenc_handle Enc;    Audenc_handle Enc_high;    CE = Engine_open ("audio_copy", NULL, NULL);    /* Create codec at the configured priority */enc = audenc_create (CE, "audenc_copy", NULL); /* Create Second instance of codec, overriding the * configured priority with a priority of 5 */Enc_high = Audenc _create (CE, "audenc_copy:5", NULL);

4.3.6.2 memory request for rewrite algorithm

A codec's request to allocate a buffer location can be ignored, and the codec can force all codec memory requests to be allocated to the external heap, which can be mapped to the Esdata configuration parameters of the DSKT2 module.

Pass to Mod_create () by attaching the codec name of the function can implement the above function, to rewrite the memory location of the request, append ": 1" to after the priority-adjusted name. For example, the name below passed to Audenc_create () has the following meanings:

1. "Audenc_copy:5:1"
Creates a audenc_copy of the priority 5, allocated external memory buffer.
2. "Audenc_copy::1"
Creates the priority of its configuration, allocating the audenc_copy in the external memory buffer.

Append ":: 0 "To the codec name (or": 0 "If a new priority is also appended), meaning that the memory request of the codec should be valued, passing the following name to Audenc_create () is equivalent:

1. "Audenc_copy"
2. "Audenc_copy::0"

API functions using Codec Engine (iii)

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.