14 #include "MfcDriver.h"
15 #include "MfcDrvParams.h"
17 #include "SsbSipH264Decode.h"
18 #include "SsbSipLogMsg.h"
20 #define _MFCLIB_H264_DEC_MAGIC_NUMBER 0x92241002
30 unsigned char *mapped_addr
;
33 unsigned int buf_width
;
34 unsigned int buf_height
;
38 void *SsbSipH264DecodeInit()
40 _MFCLIB_H264_DEC
*pCTX
;
45 //////////////////////////////
46 ///// CreateFile /////
47 //////////////////////////////
48 hOpen
= open(MFC_DEV_NAME
, O_RDWR
|O_NDELAY
);
50 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeInit", "MFC Open failure.\n");
54 //////////////////////////////////////////
55 // Mapping the MFC Input/Output Buffer //
56 //////////////////////////////////////////
57 // mapping shared in/out buffer between application and MFC device driver
58 addr
= (unsigned char *) mmap(0, BUF_SIZE
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, hOpen
, 0);
60 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeInit", "MFC Mmap failure.\n");
64 pCTX
= (_MFCLIB_H264_DEC
*) malloc(sizeof(_MFCLIB_H264_DEC
));
66 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeInit", "malloc failed.\n");
70 memset(pCTX
, 0, sizeof(_MFCLIB_H264_DEC
));
72 pCTX
->magic
= _MFCLIB_H264_DEC_MAGIC_NUMBER
;
75 pCTX
->mapped_addr
= addr
;
81 int SsbSipH264DecodeExe(void *openHandle
, long lengthBufFill
)
83 _MFCLIB_H264_DEC
*pCTX
;
88 ////////////////////////////////
89 // Input Parameter Checking //
90 ////////////////////////////////
91 if (openHandle
== NULL
) {
92 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeExe", "openHandle is NULL\n");
93 return SSBSIP_H264_DEC_RET_ERR_INVALID_HANDLE
;
95 if ((lengthBufFill
< 0) || (lengthBufFill
> 0x100000)) {
96 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeExe", "lengthBufFill is invalid. (lengthBufFill=%d)\n", lengthBufFill
);
97 return SSBSIP_H264_DEC_RET_ERR_INVALID_PARAM
;
100 pCTX
= (_MFCLIB_H264_DEC
*) openHandle
;
105 /////////////////////////////////////////////////
106 ///// (DeviceIoControl) /////
107 ///// IOCTL_MFC_H264_DEC_INIT /////
108 /////////////////////////////////////////////////
109 mfc_args
.dec_init
.in_strmSize
= lengthBufFill
;
110 r
= ioctl(pCTX
->hOpen
, IOCTL_MFC_H264_DEC_INIT
, &mfc_args
);
111 if ((r
< 0) || (mfc_args
.dec_init
.ret_code
< 0)) {
112 return SSBSIP_H264_DEC_RET_ERR_CONFIG_FAIL
;
115 // Output argument (width , height)
116 pCTX
->width
= mfc_args
.dec_init
.out_width
;
117 pCTX
->height
= mfc_args
.dec_init
.out_height
;
118 pCTX
->buf_width
= mfc_args
.dec_init
.out_buf_width
;
119 pCTX
->buf_height
= mfc_args
.dec_init
.out_buf_height
;
123 return SSBSIP_H264_DEC_RET_OK
;
127 /////////////////////////////////////////////////
128 ///// (DeviceIoControl) /////
129 ///// IOCTL_MFC_H264_DEC_EXE /////
130 /////////////////////////////////////////////////
131 mfc_args
.dec_exe
.in_strmSize
= lengthBufFill
;
132 r
= ioctl(pCTX
->hOpen
, IOCTL_MFC_H264_DEC_EXE
, &mfc_args
);
133 if ((r
< 0) || (mfc_args
.dec_exe
.ret_code
< 0)) {
134 return SSBSIP_H264_DEC_RET_ERR_DECODE_FAIL
;
137 return SSBSIP_H264_DEC_RET_OK
;
141 int SsbSipH264DecodeDeInit(void *openHandle
)
143 _MFCLIB_H264_DEC
*pCTX
;
146 ////////////////////////////////
147 // Input Parameter Checking //
148 ////////////////////////////////
149 if (openHandle
== NULL
) {
150 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeDeInit", "openHandle is NULL\n");
151 return SSBSIP_H264_DEC_RET_ERR_INVALID_HANDLE
;
154 pCTX
= (_MFCLIB_H264_DEC
*) openHandle
;
157 munmap(pCTX
->mapped_addr
, BUF_SIZE
);
161 return SSBSIP_H264_DEC_RET_OK
;
165 void *SsbSipH264DecodeGetInBuf(void *openHandle
, long size
)
170 _MFCLIB_H264_DEC
*pCTX
;
175 ////////////////////////////////
176 // Input Parameter Checking //
177 ////////////////////////////////
178 if (openHandle
== NULL
) {
179 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeGetInBuf", "openHandle is NULL\n");
182 if ((size
< 0) || (size
> 0x100000)) {
183 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeGetInBuf", "size is invalid. (size=%d)\n", size
);
187 pCTX
= (_MFCLIB_H264_DEC
*) openHandle
;
189 /////////////////////////////////////////////////
190 ///// (DeviceIoControl) /////
191 ///// IOCTL_MFC_GET_STRM_BUF_ADDR /////
192 /////////////////////////////////////////////////
193 mfc_args
.get_buf_addr
.in_usr_data
= (int)pCTX
->mapped_addr
;
194 r
= ioctl(pCTX
->hOpen
, IOCTL_MFC_GET_LINE_BUF_ADDR
, &mfc_args
);
195 if ((r
< 0) || (mfc_args
.get_buf_addr
.ret_code
< 0)) {
196 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeGetInBuf", "Failed in get LINE_BUF address\n");
201 pStrmBuf
= (void *) mfc_args
.get_buf_addr
.out_buf_addr
;
202 nStrmBufSize
= mfc_args
.get_buf_addr
.out_buf_size
;
205 if ((long)nStrmBufSize
< size
) {
206 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeGetInBuf", \
207 "Requested size is greater than available buffer. (size=%d, avail=%d)\n", size
, nStrmBufSize
);
215 void *SsbSipH264DecodeGetOutBuf(void *openHandle
, long *size
)
220 _MFCLIB_H264_DEC
*pCTX
;
225 ////////////////////////////////
226 // Input Parameter Checking //
227 ////////////////////////////////
228 if (openHandle
== NULL
) {
229 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeGetOutBuf", "openHandle is NULL\n");
233 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeGetOutBuf", "size is NULL\n");
237 pCTX
= (_MFCLIB_H264_DEC
*) openHandle
;
241 /////////////////////////////////////////////////
242 ///// (DeviceIoControl) /////
243 ///// IOCTL_MFC_GET_FRAM_BUF_ADDR /////
244 /////////////////////////////////////////////////
245 mfc_args
.get_buf_addr
.in_usr_data
= (int)pCTX
->mapped_addr
;
246 r
= ioctl(pCTX
->hOpen
, IOCTL_MFC_GET_FRAM_BUF_ADDR
, &mfc_args
);
247 if ((r
< 0) || (mfc_args
.get_buf_addr
.ret_code
< 0)) {
248 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeGetOutBuf", "Failed in get FRAM_BUF address.\n");
253 pFramBuf
= (void *) mfc_args
.get_buf_addr
.out_buf_addr
;
254 nFramBufSize
= mfc_args
.get_buf_addr
.out_buf_size
;
256 *size
= nFramBufSize
;
262 int SsbSipH264DecodeSetConfig(void *openHandle
, H264_DEC_CONF conf_type
, void *value
)
264 _MFCLIB_H264_DEC
*pCTX
;
266 MFC_SET_CONFIG_ARG set_config
;
269 ////////////////////////////////
270 // Input Parameter Checking //
271 ////////////////////////////////
272 if (openHandle
== NULL
) {
273 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeSetConfig", "openHandle is NULL\n");
274 return SSBSIP_H264_DEC_RET_ERR_INVALID_HANDLE
;
277 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeSetConfig", "value is NULL\n");
278 return SSBSIP_H264_DEC_RET_ERR_INVALID_PARAM
;
281 pCTX
= (_MFCLIB_H264_DEC
*) openHandle
;
285 case H264_DEC_SETCONF_POST_ROTATE
:
287 set_config
.in_config_param
= MFC_SET_CONFIG_DEC_ROTATE
;
288 set_config
.in_config_value
[0] = *((unsigned int *) value
);
289 set_config
.in_config_value
[1] = 0;
290 r
= ioctl(pCTX
->hOpen
, IOCTL_MFC_SET_CONFIG
, &set_config
);
291 if ( (r
< 0) || (set_config
.ret_code
< 0) ) {
292 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeSetConfig", "Error in H264_DEC_SETCONF_POST_ROTATE.\n");
293 return SSBSIP_H264_DEC_RET_ERR_SETCONF_FAIL
;
298 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeSetConfig", "No such conf_type is supported.\n");
299 return SSBSIP_H264_DEC_RET_ERR_SETCONF_FAIL
;
302 return SSBSIP_H264_DEC_RET_OK
;
307 int SsbSipH264DecodeGetConfig(void *openHandle
, H264_DEC_CONF conf_type
, void *value
)
309 _MFCLIB_H264_DEC
*pCTX
;
312 ////////////////////////////////
313 // Input Parameter Checking //
314 ////////////////////////////////
315 if (openHandle
== NULL
) {
316 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeGetConfig", "openHandle is NULL\n");
317 return SSBSIP_H264_DEC_RET_ERR_INVALID_HANDLE
;
320 pCTX
= (_MFCLIB_H264_DEC
*) openHandle
;
325 case H264_DEC_GETCONF_STREAMINFO
:
326 ((SSBSIP_H264_STREAM_INFO
*)value
)->width
= pCTX
->width
;
327 ((SSBSIP_H264_STREAM_INFO
*)value
)->height
= pCTX
->height
;
328 ((SSBSIP_H264_STREAM_INFO
*)value
)->buf_width
= pCTX
->buf_width
;
329 ((SSBSIP_H264_STREAM_INFO
*)value
)->buf_height
= pCTX
->buf_height
;
332 case H264_DEC_GETCONF_PHYADDR_FRAM_BUF
:
333 r
= ioctl(pCTX
->hOpen
, IOCTL_MFC_GET_PHY_FRAM_BUF_ADDR
, &mfc_args
);
334 if ((r
< 0) || (mfc_args
.get_buf_addr
.ret_code
< 0)) {
335 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeGetConfig", "Failed in get FRAM_BUF physical address.\n");
336 return SSBSIP_H264_DEC_RET_ERR_GETCONF_FAIL
;
338 ((unsigned int *) value
)[0] = mfc_args
.get_buf_addr
.out_buf_addr
;
339 ((unsigned int *) value
)[1] = mfc_args
.get_buf_addr
.out_buf_size
;
343 case H264_DEC_GETCONF_FRAM_NEED_COUNT
:
344 mfc_args
.get_config
.in_config_param
= MFC_GET_CONFIG_DEC_FRAME_NEED_COUNT
;
345 mfc_args
.get_config
.out_config_value
[0] = 0;
346 mfc_args
.get_config
.out_config_value
[1] = 0;
348 r
= ioctl(pCTX
->hOpen
, IOCTL_MFC_GET_CONFIG
, &mfc_args
);
349 if ((r
<0) || (mfc_args
.get_config
.ret_code
< 0)) {
350 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeGetConfig", "Error in H264_DEC_GETCONF_FRAM_NEED_COUNT.\n");
351 return SSBSIP_H264_DEC_RET_ERR_GETCONF_FAIL
;
353 ((int *) value
)[0] = mfc_args
.get_config
.out_config_value
[0];
358 LOG_MSG(LOG_ERROR
, "SsbSipH264DecodeGetConfig", "No such conf_type is suppoted.\n");
359 return SSBSIP_H264_DEC_RET_ERR_GETCONF_FAIL
;
362 return SSBSIP_H264_DEC_RET_OK
;