]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - mfp/cedev.git/blob - packages/ti/sdo/ce/video1/videnc1_skel.c
BIOS: Initial commit of BIOS-only content
[mfp/cedev.git] / packages / ti / sdo / ce / video1 / videnc1_skel.c
1 /*
2  * Copyright (c) 2013, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 /*
34  *  ======== videnc1_skel.c ========
35  *  This file contains the implemenation of the SKEL interface for the
36  *  video 1.0 encoder class of algorithms.
37  *
38  *  These functions are the "server-side" of the the stubs defined in
39  *  videnc1_stubs.c
40  */
42 /* This define must precede inclusion of any xdc header files */
43 #define Registry_CURDESC ti_sdo_ce_video1_videnc1_desc
45 #include <xdc/std.h>
46 #include <xdc/runtime/Registry.h>
48 #include <ti/sdo/ce/skel.h>
49 #include <ti/sdo/ce/osal/Memory.h>
51 #include "videnc1.h"
52 #include "_videnc1.h"
54 extern Registry_Desc ti_sdo_ce_video1_videnc1_desc;
56 /*
57  *  ======== call ========
58  */
59 static VISA_Status call(VISA_Handle visaHandle, VISA_Msg visaMsg)
60 {
61     _VIDENC1_Msg *msg  = (_VIDENC1_Msg *)visaMsg;
62     VIDENC1_Handle handle = (VIDENC1_Handle)visaHandle;
63     Int i;
64     IVIDEO1_BufDescIn inBufs;
65     XDM_BufDesc outBufs;
66     IVIDENC1_OutArgs *pOutArgs;
67     IVIDENC1_Status *pStatus;
68     IVIDENC1_CodecClassConfig *codecClassConfig;
69     Int numBufs;
71     /* get stub/skeleton config data; can be NULL (for old codecs) */
72     codecClassConfig = (IVIDENC1_CodecClassConfig *)
73                         VISA_getCodecClassConfig( visaHandle );
76     /* perform the requested VIDENC1 operation by parsing message. */
77     switch (msg->visa.cmd) {
79         case _VIDENC1_CPROCESS: {
80             /* unmarshall inBufs and outBufs */
81             inBufs           = msg->cmd.process.inBufs;
83             outBufs.bufs     = msg->cmd.process.outBufs;
84             outBufs.numBufs  = msg->cmd.process.numOutBufs;
85             outBufs.bufSizes = msg->cmd.process.outBufSizes;
87             if (SKEL_cachingPolicy == SKEL_LOCALBUFFERINVWB) {
88                 /* invalidate cache for all input buffers */
89                 for (i = 0, numBufs = 0; i < XDM_MAX_IO_BUFFERS; i++) {
90                     if (inBufs.bufDesc[i].buf != NULL) {
91                         /* valid member of sparse array,
92                          * invalidate it unless user configured it not to
93                          */
94                         if (codecClassConfig != NULL &&
95                                 codecClassConfig->manageInBufsCache[i] ==
96                                 FALSE) {
97                             /* do nothing, i.e. don't invalidate */
98                         } else {
99                             Memory_cacheInv(inBufs.bufDesc[i].buf,
100                                     inBufs.bufDesc[i].bufSize);
101                         }
103                         if (++numBufs == inBufs.numBufs) {
104                             break;
105                         }
106                     }
107                 }
109                 /* invalidate cache for all output buffers */
110                 for (i = 0, numBufs = 0; i < XDM_MAX_IO_BUFFERS; i++) {
111                     if (outBufs.bufs[i] != NULL) {
112                         /* valid member of sparse array,
113                          * invalidate it unless user configured it not to
114                          */
115                         if (codecClassConfig != NULL &&
116                                 codecClassConfig->manageOutBufsCache[i] ==
117                                 FALSE) {
118                             /* do nothing, i.e. don't invalidate */
119                         } else {
120                             Memory_cacheInv(outBufs.bufs[i],
121                                     outBufs.bufSizes[i]);
122                         }
124                         if (++numBufs == outBufs.numBufs) {
125                             break;
126                         }
127                     }
128                 }
129             } /* SKEL_cachingPolicy == SKEL_LOCALBUFFERINVWB */
131             /* unmarshall outArgs based on the "size" of inArgs */
132             pOutArgs = (IVIDENC1_OutArgs *)((UInt)(&(msg->cmd.process.inArgs)) +
133                 msg->cmd.process.inArgs.size);
135             /*
136              * Note, there's no need to invalidate cache for
137              * pOutArgs->encodedBuf bufs nor pOutArgs->reconBufs bufs as they're
138              * not _really_ OUT buffers.  Rather they're references to
139              * the _real_ OUT buffers that are provided in outBufs - which
140              * were already invalidated above.
141              */
143             /* make the process call */
144             msg->visa.status = VIDENC1_process(handle,
145                 &inBufs, &outBufs, &(msg->cmd.process.inArgs), pOutArgs);
147             if (SKEL_cachingPolicy == SKEL_WBINVALL) {
148                 Memory_cacheWbInvAll();
149             }
150             else if (SKEL_cachingPolicy == SKEL_LOCALBUFFERINVWB) {
151                 /* writeback cache for encoded buffer */
152                 if ((pOutArgs->encodedBuf.buf != NULL) &&
153                         (XDM_ISACCESSMODE_WRITE(pOutArgs->encodedBuf.accessMask))) {
154                     Memory_cacheWb(pOutArgs->encodedBuf.buf,
155                             pOutArgs->encodedBuf.bufSize);
157                     /*
158                      * Since we've cacheWb this buffer, we arguably should
159                      * reflect this cache state and clear the WRITE bit in
160                      * the .accessMask field.  However, we know the stub
161                      * doesn't propogate this field to the calling app, so
162                      * this extra buffer management detail isn't necessary:
163                      *
164                      * XDM_CLEARACCESSMODE_WRITE(pOutArgs->encodedBuf.accessMask);
165                      */
166                 }
168                 /* writeback cache for recon buffers  */
169                 for (i = 0; ((i < pOutArgs->reconBufs.numBufs) &&
170                              (i < IVIDEO_MAX_YUV_BUFFERS)); i++) {
171                     if ((pOutArgs->reconBufs.bufDesc[i].buf != NULL) &&
172                             (XDM_ISACCESSMODE_WRITE(
173                                 pOutArgs->reconBufs.bufDesc[i].accessMask))) {
175                         Memory_cacheWb(pOutArgs->reconBufs.bufDesc[i].buf,
176                                 pOutArgs->reconBufs.bufDesc[i].bufSize);
178                         /*
179                          * Since we've cacheWb this buffer, we arguably should
180                          * reflect this cache state and clear the WRITE bit in
181                          * the .accessMask field.  However, we know the stub
182                          * doesn't propogate this field to the calling app, so
183                          * this extra buffer management detail isn't necessary:
184                          *
185                          * XDM_CLEARACCESSMODE_WRITE(
186                          *         pOutArgs->reconBufs.bufDesc[i].accessMask);
187                          */
188                     }
189                 }
190             }
192             /*
193              * Note that any changes to individual outBufs[i] values made by
194              * the codec will automatically update msg->cmd.process.outBufs
195              * as we pass the outBufs array by reference.
196              */
198             break;
199         }
201         case _VIDENC1_CCONTROL: {
202             /* unmarshall status based on the "size" of params */
203             pStatus = (IVIDENC1_Status *)((UInt)(&(msg->cmd.control.params)) +
204                 msg->cmd.control.params.size);
206             /* invalidate data buffer */
207             if (pStatus->data.buf != NULL) {
208                 Memory_cacheInv(pStatus->data.buf, pStatus->data.bufSize);
209             }
211             msg->visa.status = VIDENC1_control(handle, msg->cmd.control.id,
212                 &(msg->cmd.control.params), pStatus);
214             /* writeback data buffer */
215             if ((pStatus->data.buf != NULL) &&
216                 XDM_ISACCESSMODE_WRITE(pStatus->data.accessMask)) {
218                 Memory_cacheWb(pStatus->data.buf, pStatus->data.bufSize);
220                 /*
221                  * Since we've cacheWb this buffer, we arguably should
222                  * reflect this cache state and clear the WRITE bit in
223                  * the .accessMask field.  However, we know the stub
224                  * doesn't propogate this field to the calling app, so
225                  * this extra buffer management detail isn't necessary:
226                  *
227                  * XDM_CLEARACCESSMODE_WRITE(pStatus->data.accessMask);
228                  */
229             }
231             break;
232         }
234         default: {
235             msg->visa.status = VISA_EFAIL;
237             break;
238         }
239     }
240     return (VISA_EOK);
243 /*
244  *  ======== VIDENC1_SKEL ========
245  */
246 SKEL_Fxns VIDENC1_SKEL = {
247     call,
248     (SKEL_CREATEFXN)&VIDENC1_create,
249     (SKEL_DESTROYFXN)&VIDENC1_delete,
250 };