vidstabapi.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*------------------------------------------------------------------------------
  2. -- --
  3. -- This software is confidential and proprietary and may be used --
  4. -- only as expressly authorized by a licensing agreement from --
  5. -- --
  6. -- Hantro Products Oy. --
  7. -- --
  8. -- (C) COPYRIGHT 2006 HANTRO PRODUCTS OY --
  9. -- ALL RIGHTS RESERVED --
  10. -- --
  11. -- The entire notice above must be reproduced --
  12. -- on all copies and should not be removed. --
  13. -- --
  14. --------------------------------------------------------------------------------
  15. -
  16. - Description : Video stabilization standalone API
  17. -
  18. ------------------------------------------------------------------------------*/
  19. #include "vidstbapi.h"
  20. #include "vidstabinternal.h"
  21. #include "vidstabcommon.h"
  22. #include "ewl.h"
  23. /* Tracing macro */
  24. #ifdef VIDEOSTB_TRACE
  25. #define APITRACE(str) VideoStb_Trace(str)
  26. #else
  27. #define APITRACE(str)
  28. #endif
  29. #define VIDEOSTB_MAJOR_VERSION 1
  30. #define VIDEOSTB_MINOR_VERSION 0
  31. #define VIDEOSTB_BUILD_MAJOR 1
  32. #define VIDEOSTB_BUILD_MINOR 14
  33. #define VIDEOSTB_BUILD_REVISION 0
  34. #define VIDEOSTB_SW_BUILD ((VIDEOSTB_BUILD_MAJOR * 1000000) + \
  35. (VIDEOSTB_BUILD_MINOR * 1000) + VIDEOSTB_BUILD_REVISION)
  36. #define VS_BUS_ADDRESS_VALID(bus_address) (((bus_address) != 0) && \
  37. ((bus_address & 0x07) == 0))
  38. /*------------------------------------------------------------------------------
  39. Function name : VideoStbGetApiVersion
  40. Description : Return the API version info
  41. Return type : VideoStbApiVersion
  42. Argument : void
  43. ------------------------------------------------------------------------------*/
  44. VideoStbApiVersion VideoStbGetApiVersion(void)
  45. {
  46. VideoStbApiVersion ver;
  47. ver.major = VIDEOSTB_MAJOR_VERSION;
  48. ver.minor = VIDEOSTB_MINOR_VERSION;
  49. APITRACE("VideoStbGetApiVersion# OK");
  50. return ver;
  51. }
  52. /*------------------------------------------------------------------------------
  53. Function name : VideoStbGetBuild
  54. Description : Return the SW and HW build information
  55. Return type : VideoStbBuild
  56. Argument : void
  57. ------------------------------------------------------------------------------*/
  58. VideoStbBuild VideoStbGetBuild(void)
  59. {
  60. VideoStbBuild ver;
  61. ver.swBuild = VIDEOSTB_SW_BUILD;
  62. ver.hwBuild = EWLReadAsicID();
  63. APITRACE("VideoStbGetBuild# OK");
  64. return ver;
  65. }
  66. /*------------------------------------------------------------------------------
  67. Function name : VideoStbInit
  68. Description : Initilaizes a stabilization ínstance
  69. Return type : VideoStbRet
  70. Argument : VideoStbInst * instAddr
  71. Argument : const VideoStbParam * param
  72. ------------------------------------------------------------------------------*/
  73. VideoStbRet VideoStbInit(VideoStbInst * instAddr, const VideoStbParam * param)
  74. {
  75. VideoStb *pVideoStb = NULL;
  76. const void *ewl = NULL;
  77. EWLInitParam_t ewlParam;
  78. APITRACE("VideoStbInit#");
  79. /* Check for illegal inputs */
  80. if(instAddr == NULL || param == NULL)
  81. {
  82. APITRACE("VideoStbInit: ERROR Null argument");
  83. return VIDEOSTB_NULL_ARGUMENT;
  84. }
  85. /* check HW limitations */
  86. {
  87. EWLHwConfig_t cfg = EWLReadAsicConfig();
  88. /* is video stabilization supported? */
  89. if(cfg.vsEnabled == EWL_HW_CONFIG_NOT_SUPPORTED)
  90. {
  91. APITRACE("VideoStbInit: ERROR HW support missing");
  92. return VIDEOSTB_INVALID_ARGUMENT;
  93. }
  94. /* is RGB input supported? */
  95. if(cfg.rgbEnabled == EWL_HW_CONFIG_NOT_SUPPORTED &&
  96. param->format > 3)
  97. {
  98. APITRACE("VideoStbInit: ERROR RGB input not supported");
  99. return VIDEOSTB_INVALID_ARGUMENT;
  100. }
  101. }
  102. if(VSCheckInput(param) != 0)
  103. {
  104. APITRACE("VideoStbInit: ERROR Invalid argument(s)");
  105. return VIDEOSTB_INVALID_ARGUMENT;
  106. }
  107. /* Init EWL */
  108. ewlParam.clientType = EWL_CLIENT_TYPE_VIDEOSTAB;
  109. if((ewl = EWLInit(&ewlParam)) == NULL)
  110. {
  111. APITRACE("VideoStbInit: ERROR EWLInit failed");
  112. return VIDEOSTB_EWL_ERROR;
  113. }
  114. /* allocate camstab instance */
  115. pVideoStb = (VideoStb *) EWLcalloc(1, sizeof(VideoStb));
  116. if(pVideoStb == NULL)
  117. {
  118. APITRACE("VideoStbInit: ERROR Initialization failed");
  119. return VIDEOSTB_MEMORY_ERROR;
  120. }
  121. pVideoStb->ewl = ewl; /* store EWL instance */
  122. pVideoStb->checksum = pVideoStb; /* this is used as a checksum */
  123. VSInitAsicCtrl(pVideoStb);
  124. VSAlgInit(&pVideoStb->data, param->inputWidth, param->inputHeight,
  125. param->stabilizedWidth, param->stabilizedHeight);
  126. pVideoStb->stride = param->stride;
  127. pVideoStb->yuvFormat = param->format;
  128. *instAddr = (VideoStbInst) pVideoStb;
  129. APITRACE("VideoStbInit: VIDEOSTB_OK");
  130. return VIDEOSTB_OK;
  131. }
  132. /*------------------------------------------------------------------------------
  133. Function name : VideoStbReset
  134. Description : Resets stabilization and loads new parameters
  135. Return type : VideoStbRet
  136. Argument : VideoStbInst vidStab
  137. Argument : const VideoStbParam * param
  138. ------------------------------------------------------------------------------*/
  139. VideoStbRet VideoStbReset(VideoStbInst vidStab, const VideoStbParam * param)
  140. {
  141. VideoStb *pVideoStb = (VideoStb *) vidStab;
  142. APITRACE("VideoStbReset#");
  143. /* Check for illegal inputs */
  144. if(pVideoStb == NULL || param == NULL)
  145. {
  146. APITRACE("VideoStbReset: ERROR Null argument");
  147. return VIDEOSTB_NULL_ARGUMENT;
  148. }
  149. /* Check instance */
  150. if(pVideoStb->checksum != pVideoStb)
  151. {
  152. APITRACE("VideoStbReset: ERROR Invalid instance");
  153. return VIDEOSTB_INSTANCE_ERROR;
  154. }
  155. if(VSCheckInput(param) != 0)
  156. {
  157. APITRACE("VideoStbReset: ERROR Invalid argument(s)");
  158. return VIDEOSTB_INVALID_ARGUMENT;
  159. }
  160. VSAlgInit(&pVideoStb->data, param->inputWidth, param->inputHeight,
  161. param->stabilizedWidth, param->stabilizedHeight);
  162. pVideoStb->stride = param->stride;
  163. pVideoStb->yuvFormat = param->format;
  164. APITRACE("VideoStbReset: VIDEOSTB_OK");
  165. return VIDEOSTB_OK;
  166. }
  167. /*------------------------------------------------------------------------------
  168. Function name : VideoStbStabilize
  169. Description : Stabilizes a picture based on a previous reference pict
  170. Return type : VideoStbRet
  171. Argument : VideoStbInst vidStab
  172. Argument : VideoStbResult * result
  173. Argument : u32 referencePictureLum
  174. Argument : u32 stabilizePictureLum
  175. ------------------------------------------------------------------------------*/
  176. VideoStbRet VideoStbStabilize(VideoStbInst vidStab,
  177. VideoStbResult * result,
  178. u32 referenceFrameLum, u32 stabilizeFrameLum)
  179. {
  180. VideoStb *pVideoStb = (VideoStb *) vidStab;
  181. i32 ret;
  182. APITRACE("VideoStbStabilize#");
  183. /* Check for illegal inputs */
  184. if(pVideoStb == NULL || result == NULL)
  185. {
  186. APITRACE("VideoStbStabilize: ERROR Null argument");
  187. return VIDEOSTB_NULL_ARGUMENT;
  188. }
  189. /* Check instance */
  190. if(pVideoStb->checksum != pVideoStb)
  191. {
  192. APITRACE("VideoStbStabilize: ERROR Invalid instance");
  193. return VIDEOSTB_INSTANCE_ERROR;
  194. }
  195. if(!VS_BUS_ADDRESS_VALID(referenceFrameLum) ||
  196. !VS_BUS_ADDRESS_VALID(stabilizeFrameLum))
  197. {
  198. APITRACE("VideoStbStabilize: ERROR Invalid bus address(s)");
  199. return VIDEOSTB_INVALID_ARGUMENT;
  200. }
  201. if(EWLReserveHw(pVideoStb->ewl) != EWL_OK)
  202. {
  203. APITRACE("VideoStbStabilize: ERROR HW locked by another instance");
  204. return VIDEOSTB_HW_RESERVED;
  205. }
  206. VSSetCropping(pVideoStb, referenceFrameLum, stabilizeFrameLum);
  207. VSSetupAsicAll(pVideoStb);
  208. ret = VSWaitAsicReady(pVideoStb);
  209. EWLReleaseHw(pVideoStb->ewl);
  210. if(ret == VIDEOSTB_OK)
  211. {
  212. u32 no_motion;
  213. VSReadStabData(pVideoStb->regMirror, &pVideoStb->regval.hwStabData);
  214. no_motion =
  215. VSAlgStabilize(&pVideoStb->data, &pVideoStb->regval.hwStabData);
  216. if(no_motion)
  217. {
  218. VSAlgReset(&pVideoStb->data);
  219. }
  220. VSAlgGetResult(&pVideoStb->data, &result->stabOffsetX,
  221. &result->stabOffsetY);
  222. APITRACE("VideoStbStabilize: VIDEOSTB_OK");
  223. }
  224. else
  225. {
  226. APITRACE("VideoStbStabilize: ERROR Waiting for HW ready");
  227. }
  228. return (VideoStbRet) ret;
  229. }
  230. /*------------------------------------------------------------------------------
  231. Function name : VideoStbRelease
  232. Description : Release a stabilization instance
  233. Return type : VideoStbRet
  234. Argument : VideoStbInst vidStab
  235. ------------------------------------------------------------------------------*/
  236. VideoStbRet VideoStbRelease(VideoStbInst vidStab)
  237. {
  238. VideoStb *pVideoStb = (VideoStb *) vidStab;
  239. const void *ewl;
  240. APITRACE("VideoStbRelease#");
  241. /* Check for illegal inputs */
  242. if(pVideoStb == NULL)
  243. {
  244. APITRACE("VideoStbRelease: ERROR Null argument");
  245. return VIDEOSTB_NULL_ARGUMENT;
  246. }
  247. /* Check instance */
  248. if(pVideoStb->checksum != pVideoStb)
  249. {
  250. APITRACE("VideoStbRelease: ERROR Invalid instance");
  251. return VIDEOSTB_INSTANCE_ERROR;
  252. }
  253. ewl = pVideoStb->ewl;
  254. EWLfree(pVideoStb);
  255. if(EWLRelease(ewl) != EWL_OK)
  256. {
  257. APITRACE("VideoStbRelease: ERROR EWLRelease");
  258. return VIDEOSTB_EWL_ERROR;
  259. }
  260. APITRACE("VideoStbRelease: VIDEOSTB_OK");
  261. return VIDEOSTB_OK;
  262. }