📄 app.bak
字号:
/* * Copyright 2006 by Texas Instruments Incorporated. * * All rights reserved. Property of Texas Instruments Incorporated. * Restricted rights to use, duplicate or disclose this code are * granted through contract. * *//* * ======== app.c ======== * * Non-Codec-Engine-using part of the Arm-side Linux application, that at * certain points talks to the Codec-Engine-using part of the Arm-side * Linux application. The latter module is in file ceapp.c. * * The call flow is: app.c functions -> ceapp.c functions -> CodecEngine libs */#include <stdio.h>#include <stdlib.h>/* Definition of buffer sizes for input data, encoded data * * Our application reads a raw file one block at the time at the * input buffer. It calls ceapp to encodes that from the input buffer into the * "encoded data" buffer. Actually the codec does not do anything but makes * a copy of the input data. Then appliation writes the * output block to another file. This flow is illustrated here: * * <input file block> ==(app)==> [inBuf] ==> * ==(ceapp/encoder)==> [encodedBuf] ==> * ==(app)==> <output file block> * * For simplicity, below we define all blocks to be 1K, but those sizes * could be arbitrary (though they must match). * * Note: It is EXTREMELY important that the buffers that hold the data are not * simply malloc()ed, but are actually physically contiguous. This is so * because the buffers are passed on to the codecs running on the DSP * verbatim (there is no buffer copying involved). CodecEngine * (and the ceapp module) provides and API for allocating such buffers. */#define INFRAMESIZE (1024 * sizeof(char)) /* raw frame (input) */#define ENCODEDFRAMESIZE (1024 * sizeof(char)) /* encoded frame *//* prototypes of functions defined in ceapp.c: */extern int ceapp_init(); /* initialize the ceapp module */extern char *ceapp_allocContigBuf( /* allocate physically contiguous */ int bufSize, /* buffer of given size; description */ char *bufDescription /* is used only for print */ );extern int ceapp_validateBufSizes( /* confirm that the codec */ int inBufSize, /* support these buffer sizes */ int encodedBufSize /* for the raw input audio and encoded */ );extern int ceapp_encodeBuf( /* encode raw audio data in inBuf */ char *inBuf, /* and store result in encodedBuf */ int inBufSize, char *encodedBuf, int encodedBufSize );extern void ceapp_freeContigBuf( /* free the contiguous buffer */ char *buf, int bufSize );extern void ceapp_exit(); /* exit the ceapp module *//* * ======== encodeDecodeFile ======== * This function reads blocks of the input file one at the time, encodes * each block, verify whether the output is the same as input, and writes * the result to the output file. */static int encodeFile(char *inFileName, char *outFileName){ /* pointers to contiguous shared data buffers (shared b/w Arm and DSP) */ static char *inBuf = NULL; /* to contig-alloc for INFRAMESIZE */ static char *encodedBuf = NULL; /* to contig-alloc for ENCODEDFRAMESIZE */ FILE *inFile = NULL, *outFile = NULL; int status, n; /* open file streams for input and output */ if ((inFile = fopen(inFileName, "rb")) == NULL) { printf("App-> ERROR: can't read file %s\n", inFileName); exit(1); } if ((outFile = fopen(outFileName, "wb")) == NULL) { printf("App-> ERROR: can't write to file %s\n", outFileName); exit(1); } /* initialize the ceapp which in turns initializes Codec Engine */ status = ceapp_init(); if (status != 0) { goto end; } /* Allocate 2 contiguous buffers. * The text description we pass alongside are used only in a printf. */ inBuf = ceapp_allocContigBuf(INFRAMESIZE, "input data"); encodedBuf = ceapp_allocContigBuf(ENCODEDFRAMESIZE, "encoded data"); if (inBuf == NULL || encodedBuf == NULL ) { printf("App-> Error allocating buffers (%p, %p)!\n", inBuf, encodedBuf); status = -1; goto end; } /* * Optional call: validate that the codec we'll use really supports the * sizes we specify here. There's no reason why they shouldn't, in this * particular case. */ status = ceapp_validateBufSizes( INFRAMESIZE, ENCODEDFRAMESIZE ); if (status != 0) { goto end; } /* * Read frames from the input file, and write * encoded data to an output file file */ for (n = 0 ;; n++) { printf("App-> Processing frame %d...\n", n); if (fread(inBuf, INFRAMESIZE, 1, inFile) == 0) { /* until EOF */ break; } status = ceapp_encodeBuf(inBuf, INFRAMESIZE, encodedBuf, ENCODEDFRAMESIZE); if(status != 0) { printf("App-> ERROR: Encoding frame %d FAILED\n", n); goto end; } /* write to file */ fwrite(encodedBuf, ENCODEDFRAMESIZE, 1, outFile); } printf("App-> Finished encoding %d frames\n", n); status = 0; /* success */end: /* close the files */ fclose(inFile); fclose(outFile); /* free the contiguous buffers */ if (inBuf != NULL) { ceapp_freeContigBuf(inBuf, INFRAMESIZE); } if (encodedBuf != NULL) { ceapp_freeContigBuf(encodedBuf, ENCODEDFRAMESIZE); } /* quit the CE application */ ceapp_exit(); /* and return success (0) or failure (non-0) */ return status;}/* * ======== main ======== */int main(int argc, char *argv[]){ char *inFileName, *outFileName; if (argc <= 1) { inFileName = "in.dat"; outFileName = "out.dat"; } else if (argc != 3 && argc != 4) { printf("Usage: %s input-file output-file\n", argv[0]); exit(1); } else { inFileName = argv[1]; outFileName = argv[2]; } printf("App-> Application started.\n"); if (encodeFile(inFileName, outFileName) == 0) { printf("App-> Application finished successfully.\n"); } else { printf("App-> Application FAILED.\n"); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -