Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1352 lines
49 KiB

  1. /*
  2. * @DEC_COPYRIGHT@
  3. */
  4. /*
  5. * HISTORY
  6. * $Log: slib_param.c,v $
  7. * Revision 1.1.6.25 1996/12/13 18:19:09 Hans_Graves
  8. * Adjust file size in NEED_ACCURACY, if end of file is bad.
  9. * [1996/12/13 18:13:11 Hans_Graves]
  10. *
  11. * Revision 1.1.6.24 1996/12/12 20:54:47 Hans_Graves
  12. * Fixed NT compile warning with use of ftime.
  13. * [1996/12/12 20:51:38 Hans_Graves]
  14. *
  15. * Revision 1.1.6.23 1996/12/05 20:10:18 Hans_Graves
  16. * Change max choosen MPEG audio bitrate to 192kbits
  17. * [1996/12/05 20:09:25 Hans_Graves]
  18. *
  19. * Revision 1.1.6.22 1996/12/04 22:34:34 Hans_Graves
  20. * Make seeking in NEEDACCURACY quicker when seeks fail.
  21. * [1996/12/04 22:20:18 Hans_Graves]
  22. *
  23. * Revision 1.1.6.21 1996/12/03 23:15:18 Hans_Graves
  24. * MME-1498: Made seeks with PERCENT100 more accurate
  25. * [1996/12/03 23:10:48 Hans_Graves]
  26. *
  27. * Revision 1.1.6.20 1996/12/03 00:08:36 Hans_Graves
  28. * Handling of End Of Sequence points. Added PERCENT100 support.
  29. * [1996/12/03 00:06:06 Hans_Graves]
  30. *
  31. * Revision 1.1.6.19 1996/11/18 23:07:38 Hans_Graves
  32. * Make use of presentation timestamps. Make seeking time-based.
  33. * [1996/11/18 22:48:00 Hans_Graves]
  34. *
  35. * Revision 1.1.6.18 1996/11/14 22:32:10 Hans_Graves
  36. * AUDIOCHANNELS can only be changed under AC3 decompression.
  37. * [1996/11/14 22:31:39 Hans_Graves]
  38. *
  39. * Revision 1.1.6.17 1996/11/14 21:49:29 Hans_Graves
  40. * Multichannel setting using AUDIOCHANNELS param.
  41. * [1996/11/14 21:44:44 Hans_Graves]
  42. *
  43. * Revision 1.1.6.16 1996/11/11 18:21:10 Hans_Graves
  44. * Added SlibGetParamString() support for SLIB_PARAM_TYPE.
  45. * [1996/11/11 18:01:25 Hans_Graves]
  46. *
  47. * Revision 1.1.6.15 1996/11/08 21:51:08 Hans_Graves
  48. * Added new PARAMs VIDEOMAINSTREAM, AUDIOMAINSTREAM and TYPE
  49. * [1996/11/08 21:31:08 Hans_Graves]
  50. *
  51. * Revision 1.1.6.14 1996/10/28 17:32:34 Hans_Graves
  52. * MME-1402, 1431, 1435: Timestamp related changes.
  53. * [1996/10/28 17:23:07 Hans_Graves]
  54. *
  55. * Revision 1.1.6.13 1996/10/17 00:23:36 Hans_Graves
  56. * Added SLIB_PARAM_VIDEOFRAME and SLIB_PARAM_FRAMEDURATION.
  57. * [1996/10/17 00:19:44 Hans_Graves]
  58. *
  59. * Revision 1.1.6.12 1996/10/12 17:18:56 Hans_Graves
  60. * Added SLIB_PARAM_SKIPPEL and SLIB_PARAM_HALFPEL support.
  61. * [1996/10/12 17:02:37 Hans_Graves]
  62. *
  63. * Revision 1.1.6.11 1996/10/03 19:14:26 Hans_Graves
  64. * Added Presentation and Decoding timestamp support.
  65. * [1996/10/03 19:10:42 Hans_Graves]
  66. *
  67. * Revision 1.1.6.10 1996/09/29 22:19:44 Hans_Graves
  68. * Added STRIDE param.
  69. * [1996/09/29 21:31:34 Hans_Graves]
  70. *
  71. * Revision 1.1.6.9 1996/09/25 19:16:50 Hans_Graves
  72. * Added SLIB_INTERNAL define.
  73. * [1996/09/25 19:01:56 Hans_Graves]
  74. *
  75. * Revision 1.1.6.8 1996/09/23 18:04:05 Hans_Graves
  76. * Added STATS params.
  77. * [1996/09/23 17:58:54 Hans_Graves]
  78. *
  79. * Revision 1.1.6.7 1996/09/18 23:47:17 Hans_Graves
  80. * Added new PARAMs: VBV, ASPECTRATIO, TIMECODE, VERSION
  81. * [1996/09/18 22:07:17 Hans_Graves]
  82. *
  83. * Revision 1.1.6.6 1996/08/09 20:51:53 Hans_Graves
  84. * Allows deselecting of SLIB_PARAM_VIDEOSTREAMS and SLIB_PARAM_AUDIOSTREAMS
  85. * [1996/08/09 20:12:16 Hans_Graves]
  86. *
  87. * Revision 1.1.6.5 1996/07/30 20:25:38 Wei_Hsu
  88. * Add motion algorithm param.
  89. * [1996/07/30 15:59:07 Wei_Hsu]
  90. *
  91. * Revision 1.1.6.4 1996/07/19 02:11:17 Hans_Graves
  92. * Added SLIB_PARAM_DEBUG support
  93. * [1996/07/19 01:59:50 Hans_Graves]
  94. *
  95. * Revision 1.1.6.3 1996/05/23 18:46:38 Hans_Graves
  96. * Merge MME-1220 & MME-1221 - Multiply MPEG audio bitrates by 1000 instead of 1024
  97. * [1996/05/23 18:46:09 Hans_Graves]
  98. *
  99. * Revision 1.1.6.2 1996/05/10 21:17:47 Hans_Graves
  100. * Allow FILESIZE param to be set, for callbacks.
  101. * [1996/05/10 20:46:23 Hans_Graves]
  102. *
  103. * Revision 1.1.4.13 1996/04/30 17:05:35 Hans_Graves
  104. * Report SlibErrorSettingNotEqual correctly under SetParamFloat(). Fixes MME-01173
  105. * [1996/04/30 16:49:06 Hans_Graves]
  106. *
  107. * Revision 1.1.4.12 1996/04/24 22:33:48 Hans_Graves
  108. * MPEG encoding bitrate fixups.
  109. * [1996/04/24 22:27:16 Hans_Graves]
  110. *
  111. * Revision 1.1.4.11 1996/04/23 21:01:42 Hans_Graves
  112. * Fix SlibValidateParams(). Add error checking for SlibErrorSettingNotEqual
  113. * [1996/04/23 20:59:03 Hans_Graves]
  114. *
  115. * Revision 1.1.4.10 1996/04/22 15:04:54 Hans_Graves
  116. * Added SlibValidateParams()
  117. * [1996/04/22 14:43:04 Hans_Graves]
  118. *
  119. * Revision 1.1.4.9 1996/04/19 21:52:26 Hans_Graves
  120. * Fix BITRATE parameter settings
  121. * [1996/04/19 21:47:01 Hans_Graves]
  122. *
  123. * Revision 1.1.4.8 1996/04/11 14:14:12 Hans_Graves
  124. * Fix NT warnings
  125. * [1996/04/11 14:10:21 Hans_Graves]
  126. *
  127. * Revision 1.1.4.7 1996/04/10 21:47:43 Hans_Graves
  128. * Added params: FASTENCODE, FASTDECODE, and QUALITY
  129. * [1996/04/10 21:40:18 Hans_Graves]
  130. *
  131. * Revision 1.1.4.6 1996/04/09 16:04:43 Hans_Graves
  132. * Handle setting negative Height
  133. * [1996/04/09 14:42:13 Hans_Graves]
  134. *
  135. * Revision 1.1.4.5 1996/04/01 19:07:57 Hans_Graves
  136. * And some error checking
  137. * [1996/04/01 19:04:40 Hans_Graves]
  138. *
  139. * Revision 1.1.4.4 1996/04/01 16:23:17 Hans_Graves
  140. * NT porting
  141. * [1996/04/01 16:16:03 Hans_Graves]
  142. *
  143. * Revision 1.1.4.3 1996/03/12 16:15:54 Hans_Graves
  144. * Added SLIB_PARAM_FILEBUFSIZE param
  145. * [1996/03/12 15:54:22 Hans_Graves]
  146. *
  147. * Revision 1.1.4.2 1996/03/08 18:46:49 Hans_Graves
  148. * Added SlibGetParamString()
  149. * [1996/03/08 18:34:51 Hans_Graves]
  150. *
  151. * Revision 1.1.2.6 1996/02/07 23:23:59 Hans_Graves
  152. * Added SEEK_EXACT. Fixed most frame counting problems.
  153. * [1996/02/07 23:20:37 Hans_Graves]
  154. *
  155. * Revision 1.1.2.5 1996/02/06 22:54:08 Hans_Graves
  156. * Seek fix-ups. More accurate MPEG frame counts.
  157. * [1996/02/06 22:45:21 Hans_Graves]
  158. *
  159. * Revision 1.1.2.4 1996/02/02 17:36:05 Hans_Graves
  160. * Enhanced audio info. Cleaned up API
  161. * [1996/02/02 17:29:49 Hans_Graves]
  162. *
  163. * Revision 1.1.2.3 1996/01/15 16:26:32 Hans_Graves
  164. * Added Audio Params
  165. * [1996/01/15 15:48:20 Hans_Graves]
  166. *
  167. * Revision 1.1.2.2 1996/01/11 16:17:35 Hans_Graves
  168. * First time under SLIB
  169. * [1996/01/11 16:11:45 Hans_Graves]
  170. *
  171. * $EndLog$
  172. */
  173. /*****************************************************************************
  174. ** Copyright (c) Digital Equipment Corporation, 1995 **
  175. ** **
  176. ** All Rights Reserved. Unpublished rights reserved under the copyright **
  177. ** laws of the United States. **
  178. ** **
  179. ** The software contained on this media is proprietary to and embodies **
  180. ** the confidential technology of Digital Equipment Corporation. **
  181. ** Possession, use, duplication or dissemination of the software and **
  182. ** media is authorized only pursuant to a valid written license from **
  183. ** Digital Equipment Corporation. **
  184. ** **
  185. ** RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure by the U.S. **
  186. ** Government is subject to restrictions as set forth in Subparagraph **
  187. ** (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, as applicable. **
  188. ******************************************************************************/
  189. /*
  190. #define _SLIBDEBUG_
  191. */
  192. #include <stdio.h>
  193. #ifdef WIN32
  194. #include <time.h>
  195. #include <sys/timeb.h>
  196. #else
  197. #include <sys/time.h>
  198. #endif /* WIN32 */
  199. #define SLIB_INTERNAL
  200. #include "slib.h"
  201. #include "SC_err.h"
  202. #ifdef _SLIBDEBUG_
  203. #define _DEBUG_ 1 /* detailed debuging statements */
  204. #define _VERBOSE_ 1 /* show progress */
  205. #define _VERIFY_ 1 /* verify correct operation */
  206. #define _WARN_ 1 /* warnings about strange behavior */
  207. #endif
  208. static float _version = 2.10F;
  209. static char _version_date[] = { __DATE__ };
  210. SlibTime_t slibGetSystemTime()
  211. {
  212. SlibTime_t mstime;
  213. #ifdef WIN32
  214. struct _timeb t ;
  215. _ftime(&t);
  216. mstime = (SlibTime_t)(t.time * 1000 + t.millitm);
  217. #else
  218. struct timeval t;
  219. struct timezone tz;
  220. gettimeofday(&t, &tz);
  221. mstime = (SlibTime_t)(t.tv_sec * 1000 + t.tv_usec / 1000);
  222. #endif
  223. return(mstime);
  224. }
  225. qword SlibGetFrameNumber(SlibHandle_t handle, SlibStream_t stream)
  226. {
  227. SlibInfo_t *Info=(SlibInfo_t *)handle;
  228. if (Info && Info->FramesPerSec>0.0F)
  229. return(slibTimeToFrame(Info, Info->VideoTimeStamp
  230. +(Info->VideoFrameDuration/200)));
  231. else
  232. return((qword)-1);
  233. }
  234. SlibTime_t SlibGetVideoTime(SlibHandle_t handle, SlibStream_t stream)
  235. {
  236. if (!handle)
  237. return(0);
  238. return((long)((SlibInfo_t *)handle)->VideoTimeStamp);
  239. }
  240. SlibTime_t SlibGetAudioTime(SlibHandle_t handle, SlibStream_t stream)
  241. {
  242. if (!handle)
  243. return(0);
  244. return((long)((SlibInfo_t *)handle)->AudioTimeStamp);
  245. }
  246. SlibBoolean_t SlibCanSetParam(SlibHandle_t handle, SlibStream_t stream,
  247. SlibParameter_t param)
  248. {
  249. return(TRUE);
  250. }
  251. SlibBoolean_t SlibCanGetParam(SlibHandle_t handle, SlibStream_t stream,
  252. SlibParameter_t param)
  253. {
  254. return(TRUE);
  255. }
  256. SlibStatus_t SlibSetParamInt(SlibHandle_t handle, SlibStream_t stream,
  257. SlibParameter_t param, long value)
  258. {
  259. SlibInfo_t *Info=(SlibInfo_t *)handle;
  260. SlibStatus_t status=SlibErrorNone;
  261. long actvalue=value;
  262. if (!handle)
  263. return(SlibErrorBadHandle);
  264. _SlibDebug(_DEBUG_, printf("SlibSetParamInt(stream=%d, param=%d, %d)\n",
  265. stream, param, value) );
  266. switch (param)
  267. {
  268. case SLIB_PARAM_FPS:
  269. _SlibDebug(_DEBUG_, printf("SlibSetParamInt(SLIB_PARAM_FPS)\n") );
  270. status=SlibSetParamFloat(handle, stream, param, (float)value);
  271. break;
  272. case SLIB_PARAM_BITRATE:
  273. _SlibDebug(_DEBUG_,
  274. printf("SlibSetParamInt(SLIB_PARAM_BITRATE, %d)\n", value) );
  275. if (stream==SLIB_STREAM_MAINAUDIO)
  276. status=SlibSetParamInt(handle, stream, SLIB_PARAM_AUDIOBITRATE,
  277. value);
  278. else if (stream==SLIB_STREAM_MAINVIDEO)
  279. status=SlibSetParamInt(handle, stream, SLIB_PARAM_VIDEOBITRATE,
  280. value);
  281. else /* setting overall bitrate: try to calc best audio+video rates */
  282. {
  283. long vbitrate=value;
  284. /* spread total bitrate across all streams */
  285. if (Info->AudioStreams)
  286. {
  287. long abitrate=Info->VideoStreams ? (value*Info->Channels)/10
  288. : value;
  289. /* don't set bitrates higher than necessary */
  290. if (Info->Channels==1 && abitrate>112*1000)
  291. abitrate=112*1000;
  292. else if (abitrate>192*1000)
  293. abitrate=192*1000;
  294. status=SlibSetParamInt(handle, stream, SLIB_PARAM_AUDIOBITRATE,
  295. abitrate);
  296. abitrate=SlibGetParamInt(handle, stream, SLIB_PARAM_AUDIOBITRATE);
  297. vbitrate=value-abitrate; /* subtract bitrate allocated to audio */
  298. }
  299. if (Info->VideoStreams)
  300. status=SlibSetParamInt(handle, stream, SLIB_PARAM_VIDEOBITRATE,
  301. vbitrate);
  302. slibValidateBitrates(Info); /* check the bitrate setting */
  303. if (Info->VideoStreams && Info->TotalBitRate>value)
  304. {
  305. /*
  306. * Since the total bitrate is over the desired bitrate
  307. * subtract the difference from the video bitrate
  308. */
  309. vbitrate=Info->VideoBitRate-(Info->TotalBitRate-value);
  310. status=SlibSetParamInt(handle, stream, SLIB_PARAM_VIDEOBITRATE,
  311. vbitrate);
  312. }
  313. }
  314. slibValidateBitrates(Info);
  315. actvalue=Info->TotalBitRate;
  316. _SlibDebug(_DEBUG_,
  317. printf("MuxBitRate=%d TotalBitRate=%d abitrate=%d vbitrate=%d\n",
  318. Info->MuxBitRate, Info->TotalBitRate,
  319. SlibGetParamInt(handle, stream, SLIB_PARAM_AUDIOBITRATE),
  320. SlibGetParamInt(handle, stream, SLIB_PARAM_VIDEOBITRATE) ) );
  321. break;
  322. case SLIB_PARAM_VIDEOBITRATE:
  323. _SlibDebug(_DEBUG_,
  324. printf("SlibSetParamInt(SLIB_PARAM_VIDEOBITRATE, %d)\n", value) );
  325. if (Info->Svh)
  326. {
  327. SvSetParamInt(Info->Svh, SV_PARAM_BITRATE, value);
  328. actvalue=(long)SvGetParamInt(Info->Svh, SV_PARAM_BITRATE);
  329. }
  330. if (actvalue>0)
  331. Info->VideoBitRate=actvalue;
  332. slibValidateBitrates(Info);
  333. break;
  334. case SLIB_PARAM_VIDEOSTREAMS:
  335. if (Info->VideoStreams!=(int)value)
  336. {
  337. Info->VideoStreams=(int)value;
  338. if (Info->VideoStreams)
  339. slibAddPin(Info, SLIB_DATA_VIDEO, "Video");
  340. else
  341. {
  342. slibPinPrepareReposition(Info, SLIB_DATA_VIDEO);
  343. slibRemovePin(Info, SLIB_DATA_VIDEO);
  344. }
  345. }
  346. break;
  347. case SLIB_PARAM_MOTIONALG:
  348. if (Info->Svh)
  349. SvSetParamInt(Info->Svh, SV_PARAM_MOTIONALG, value);
  350. break;
  351. case SLIB_PARAM_ALGFLAGS:
  352. if (Info->Svh)
  353. SvSetParamInt(Info->Svh, SV_PARAM_ALGFLAGS, value);
  354. break;
  355. case SLIB_PARAM_MOTIONSEARCH:
  356. if (Info->Svh)
  357. SvSetParamInt(Info->Svh, SV_PARAM_MOTIONSEARCH, value);
  358. break;
  359. case SLIB_PARAM_MOTIONTHRESH:
  360. if (Info->Svh)
  361. SvSetParamInt(Info->Svh, SV_PARAM_MOTIONTHRESH, value);
  362. break;
  363. case SLIB_PARAM_QUANTI:
  364. if (Info->Svh)
  365. SvSetParamInt(Info->Svh, SV_PARAM_QUANTI, value);
  366. break;
  367. case SLIB_PARAM_QUANTP:
  368. if (Info->Svh)
  369. SvSetParamInt(Info->Svh, SV_PARAM_QUANTP, value);
  370. break;
  371. case SLIB_PARAM_QUANTB:
  372. if (Info->Svh)
  373. SvSetParamInt(Info->Svh, SV_PARAM_QUANTB, value);
  374. break;
  375. case SLIB_PARAM_KEYSPACING:
  376. if (Info->Svh)
  377. SvSetParamInt(Info->Svh, SV_PARAM_KEYSPACING, value);
  378. break;
  379. case SLIB_PARAM_SUBKEYSPACING:
  380. if (Info->Svh)
  381. SvSetParamInt(Info->Svh, SV_PARAM_SUBKEYSPACING, value);
  382. break;
  383. case SLIB_PARAM_FRAMETYPE:
  384. if (Info->Svh)
  385. SvSetParamInt(Info->Svh, SV_PARAM_FRAMETYPE, value);
  386. break;
  387. case SLIB_PARAM_VIDEOPROGRAM:
  388. Info->VideoPID=(int)value;
  389. break;
  390. case SLIB_PARAM_AUDIOPROGRAM:
  391. Info->AudioPID=(int)value;
  392. break;
  393. case SLIB_PARAM_VIDEOMAINSTREAM:
  394. Info->VideoMainStream=(int)value;
  395. break;
  396. case SLIB_PARAM_AUDIOMAINSTREAM:
  397. Info->AudioMainStream=(int)value;
  398. break;
  399. case SLIB_PARAM_WIDTH:
  400. _SlibDebug(_DEBUG_,
  401. printf("SlibSetParamInt(SLIB_PARAM_WIDTH)\n") );
  402. Info->Width=(short)value;
  403. if (Info->Mode==SLIB_MODE_COMPRESS && Info->CompVideoFormat)
  404. Info->CompVideoFormat->biWidth=Info->Width;
  405. if (Info->Mode==SLIB_MODE_COMPRESS && Info->CodecVideoFormat)
  406. Info->CodecVideoFormat->biWidth=Info->Width;
  407. if (Info->VideoFormat)
  408. Info->VideoFormat->biWidth=Info->Width;
  409. return(slibValidateVideoParams(Info));
  410. case SLIB_PARAM_STRIDE:
  411. _SlibDebug(_DEBUG_,
  412. printf("SlibSetParamInt(SLIB_PARAM_STRIDE)\n") );
  413. Info->Stride=(long)value;
  414. if (Info->Sch && Info->Mode==SLIB_MODE_DECOMPRESS)
  415. SconSetParamInt(Info->Sch, SCON_OUTPUT, SCON_PARAM_STRIDE, Info->Stride);
  416. break;
  417. case SLIB_PARAM_HEIGHT:
  418. _SlibDebug(_DEBUG_,
  419. printf("SlibSetParamInt(SLIB_PARAM_HEIGHT)\n") );
  420. Info->Height=(short)value<0 ? (short)-value : (short)value;
  421. if (Info->Mode==SLIB_MODE_COMPRESS && Info->CompVideoFormat)
  422. Info->CompVideoFormat->biHeight=Info->Height;
  423. if (Info->Mode==SLIB_MODE_COMPRESS && Info->CodecVideoFormat)
  424. Info->CodecVideoFormat->biHeight=Info->Height;
  425. if (Info->VideoFormat)
  426. Info->VideoFormat->biHeight=(short)value;
  427. return(slibValidateVideoParams(Info));
  428. case SLIB_PARAM_VIDEOFORMAT:
  429. _SlibDebug(_DEBUG_,
  430. printf("SlibSetParamInt(SLIB_PARAM_VIDEOFORMAT, '%c%c%c%c')\n",
  431. value&0xFF, (value>>8)&0xFF, (value>>16)&0xFF,(value>>24)&0xFF) );
  432. if (Info->VideoFormat)
  433. Info->VideoFormat->biCompression=(dword)value;
  434. #if 0
  435. if (Info->Mode==SLIB_MODE_COMPRESS && Info->CodecVideoFormat)
  436. Info->CodecVideoFormat->biCompression=(dword)value;
  437. #endif
  438. return(slibValidateVideoParams(Info));
  439. case SLIB_PARAM_VIDEOBITS:
  440. _SlibDebug(_DEBUG_,
  441. printf("SlibSetParamInt(SLIB_PARAM_VIDEOBITS, %d)\n", value) );
  442. if (Info->VideoFormat)
  443. Info->VideoFormat->biBitCount=(word)value;
  444. if (Info->Mode==SLIB_MODE_COMPRESS && Info->CodecVideoFormat)
  445. Info->CodecVideoFormat->biBitCount=(dword)value;
  446. return(slibValidateVideoParams(Info));
  447. case SLIB_PARAM_AUDIOSTREAMS:
  448. if (Info->AudioStreams!=(int)value)
  449. {
  450. Info->AudioStreams=(int)value;
  451. if (Info->AudioStreams)
  452. slibAddPin(Info, SLIB_DATA_AUDIO, "Audio");
  453. else
  454. {
  455. slibPinPrepareReposition(Info, SLIB_DATA_AUDIO);
  456. slibRemovePin(Info, SLIB_DATA_AUDIO);
  457. }
  458. }
  459. break;
  460. case SLIB_PARAM_AUDIOBITRATE:
  461. _SlibDebug(_DEBUG_,
  462. printf("SlibSetParamInt(SLIB_PARAM_AUDIOBITRATE, %d)\n", value) );
  463. if (Info->Sah)
  464. {
  465. SaSetParamInt(Info->Sah, SA_PARAM_BITRATE, value);
  466. actvalue=(long)SaGetParamInt(Info->Sah, SA_PARAM_BITRATE);
  467. }
  468. if (actvalue>0)
  469. Info->AudioBitRate=actvalue;
  470. slibValidateBitrates(Info);
  471. break;
  472. case SLIB_PARAM_AUDIOCHANNELS:
  473. if (Info->Mode==SLIB_MODE_COMPRESS ||
  474. Info->AudioType==SLIB_TYPE_AC3_AUDIO)
  475. {
  476. Info->Channels=value;
  477. if (Info->AudioFormat)
  478. Info->AudioFormat->nChannels=(word)value;
  479. SaSetParamInt(Info->Sah, SA_PARAM_CHANNELS, value);
  480. }
  481. actvalue=Info->Channels;
  482. break;
  483. case SLIB_PARAM_SAMPLESPERSEC:
  484. {
  485. unsigned dword nativesps;
  486. Info->SamplesPerSec=value;
  487. nativesps=value;
  488. #ifdef MPEG_SUPPORT
  489. if (SlibTypeIsMPEG(Info->Type))
  490. {
  491. /* choose a MPEG supported native sample rate */
  492. if (value%11025 == 0) /* multiples of 11025 can be converted */
  493. nativesps=44100;
  494. else if (value==48000)
  495. nativesps=48000;
  496. else if (value%8000 == 0) /* multiples of 8000 can be converted */
  497. nativesps=32000;
  498. }
  499. #endif /* MPEG_SUPPORT */
  500. if (Info->AudioFormat)
  501. Info->AudioFormat->nSamplesPerSec=nativesps;
  502. }
  503. break;
  504. case SLIB_PARAM_NATIVESAMPLESPERSEC:
  505. if (Info->AudioFormat)
  506. Info->AudioFormat->nSamplesPerSec=(dword)value;
  507. break;
  508. case SLIB_PARAM_BITSPERSAMPLE:
  509. Info->BitsPerSample=value;
  510. if (Info->AudioFormat && value==16)
  511. Info->AudioFormat->wBitsPerSample=(word)value;
  512. break;
  513. case SLIB_PARAM_NATIVEBITSPERSAMPLE:
  514. if (Info->AudioFormat)
  515. Info->AudioFormat->wBitsPerSample=(word)value;
  516. break;
  517. case SLIB_PARAM_VIDEOQUALITY:
  518. if (Info->Svh)
  519. SvSetParamInt(Info->Svh, SV_PARAM_QUALITY, (ScBoolean_t)value);
  520. break;
  521. case SLIB_PARAM_AUDIOQUALITY:
  522. if (Info->Sah)
  523. SaSetParamInt(Info->Sah, SA_PARAM_QUALITY, (ScBoolean_t)value);
  524. break;
  525. case SLIB_PARAM_FILESIZE:
  526. Info->FileSize=(unsigned long)value;
  527. break;
  528. case SLIB_PARAM_FILEBUFSIZE:
  529. Info->FileBufSize=(unsigned dword)value;
  530. break;
  531. case SLIB_PARAM_COMPBUFSIZE:
  532. if (value<=0)
  533. Info->CompBufSize=(unsigned dword)2*1024; /* default */
  534. else
  535. Info->CompBufSize=(unsigned dword)value;
  536. break;
  537. case SLIB_PARAM_PACKETSIZE:
  538. if (Info->Svh)
  539. SvSetParamInt(Info->Svh, SV_PARAM_PACKETSIZE, value);
  540. break;
  541. case SLIB_PARAM_FORMATEXT:
  542. if (Info->Svh)
  543. SvSetParamInt(Info->Svh, SV_PARAM_FORMATEXT, value);
  544. break;
  545. case SLIB_PARAM_OVERFLOWSIZE:
  546. Info->OverflowSize=(unsigned long)value;
  547. break;
  548. case SLIB_PARAM_DEBUG:
  549. Info->dbg=(void *)value;
  550. if (Info->Svh)
  551. SvSetParamInt(Info->Svh, SV_PARAM_DEBUG, value);
  552. if (Info->Sah)
  553. SaSetParamInt(Info->Sah, SA_PARAM_DEBUG, value);
  554. break;
  555. default:
  556. return(SlibErrorUnsupportedParam);
  557. }
  558. if (actvalue!=value)
  559. {
  560. _SlibDebug(_DEBUG_ || _WARN_,
  561. printf("SlibSetParamFloat() SettingNotEqual: %ld(req) != %ld(act)\n",
  562. value, actvalue) );
  563. return(SlibErrorSettingNotEqual);
  564. }
  565. return(status);
  566. }
  567. SlibStatus_t SlibSetParamLong(SlibHandle_t handle, SlibStream_t stream,
  568. SlibParameter_t param, qword value)
  569. {
  570. SlibInfo_t *Info=(SlibInfo_t *)handle;
  571. SlibStatus_t status=SlibErrorNone;
  572. qword actvalue=value;
  573. if (!handle)
  574. return(SlibErrorBadHandle);
  575. _SlibDebug(_DEBUG_, printf("SlibSetParamLong(stream=%d, param=%d, %ld)\n",
  576. stream, param, value) );
  577. /* this needs to be implemented */
  578. return(SlibSetParamInt(handle, stream, param, (long)value));
  579. }
  580. SlibStatus_t SlibSetParamFloat(SlibHandle_t handle, SlibStream_t stream,
  581. SlibParameter_t param, float value)
  582. {
  583. SlibInfo_t *Info=(SlibInfo_t *)handle;
  584. SlibStatus_t status=SlibErrorNone;
  585. float actvalue=value;
  586. if (!handle)
  587. return(SlibErrorBadHandle);
  588. _SlibDebug(_DEBUG_, printf("SlibSetParamFloat()\n") );
  589. switch (param)
  590. {
  591. case SLIB_PARAM_FPS:
  592. _SlibDebug(_DEBUG_,
  593. printf("SlibSetParamFloat(SLIB_PARAM_FPS)\n") );
  594. if (Info->Svh)
  595. {
  596. SvSetParamFloat(Info->Svh, SV_PARAM_FPS, value);
  597. actvalue=SvGetParamFloat(Info->Svh, SV_PARAM_FPS);
  598. }
  599. if (actvalue>0.0F)
  600. Info->FramesPerSec=actvalue;
  601. break;
  602. default:
  603. return(SlibSetParamInt(handle, stream, param, (long)value));
  604. }
  605. if (actvalue>value+(float)0.0000001 ||
  606. actvalue<value-(float)0.0000001)
  607. {
  608. _SlibDebug(_DEBUG_ || _WARN_,
  609. printf("SlibSetParamFloat() SettingNotEqual: %.3f(req) != %.3f(act)\n",
  610. value, actvalue) );
  611. return(SlibErrorSettingNotEqual);
  612. }
  613. return(status);
  614. }
  615. SlibStatus_t SlibSetParamBoolean(SlibHandle_t handle, SlibStream_t stream,
  616. SlibParameter_t param, SlibBoolean_t value)
  617. {
  618. SlibInfo_t *Info=(SlibInfo_t *)handle;
  619. if (!handle)
  620. return(SlibErrorBadHandle);
  621. _SlibDebug(_DEBUG_, printf("SlibSetParamFloat()\n") );
  622. switch (param)
  623. {
  624. case SLIB_PARAM_STATS:
  625. if (value)
  626. {
  627. if (Info->stats==NULL)
  628. {
  629. Info->stats = (SlibStats_t *)ScAlloc(sizeof(SlibStats_t));
  630. if (Info->stats==NULL)
  631. return(SlibErrorMemory);
  632. SlibSetParamBoolean(handle, stream, SLIB_PARAM_STATS_RESET, TRUE);
  633. }
  634. else
  635. Info->stats->StartTime=slibGetSystemTime();
  636. Info->stats->Record=TRUE;
  637. }
  638. else if (Info->stats)
  639. {
  640. Info->stats->Record=FALSE;
  641. Info->stats->StopTime=slibGetSystemTime();
  642. }
  643. break;
  644. case SLIB_PARAM_STATS_RESET:
  645. if (Info->stats)
  646. {
  647. Info->stats->StartTime=Info->stats->StopTime=
  648. slibGetSystemTime();
  649. Info->stats->FramesProcessed=0;
  650. Info->stats->FramesSkipped=0;
  651. }
  652. break;
  653. case SLIB_PARAM_NEEDACCURACY:
  654. Info->NeedAccuracy = value ? TRUE : FALSE;
  655. if (Info->NeedAccuracy && slibHasTimeCode(Info))
  656. {
  657. /*
  658. * We'll seek toward the end of the file so the frame count
  659. * can be more accurately measured
  660. */
  661. if (!Info->VideoLengthKnown && Info->FileSize>0)
  662. {
  663. int minpercent=0, maxpercent=9900, lastpercent=0, trypercent=9900;
  664. int tries=0;
  665. unsigned qword newfilesize=Info->FileSize;
  666. qword stime = Info->VideoTimeStamp;
  667. SlibStatus_t status;
  668. if (SlibTimeIsInValid(stime)) stime=0;
  669. while (!Info->VideoLengthKnown && maxpercent-minpercent>200 && tries<5)
  670. {
  671. status=SlibSeekEx(handle, SLIB_STREAM_ALL, SLIB_SEEK_KEY,
  672. trypercent, SLIB_UNIT_PERCENT100, NULL);
  673. if (status==SlibErrorEndOfStream)
  674. break;
  675. else if (status==SlibErrorNoBeginning)
  676. {
  677. /* adjust the file size, data at end must be invalid */
  678. newfilesize=(Info->FileSize*(trypercent/100))/100;
  679. lastpercent=trypercent;
  680. maxpercent=trypercent;
  681. trypercent=(minpercent+maxpercent)/2; /* try half way between min and max */
  682. }
  683. else if (status==SlibErrorNone)
  684. {
  685. if (maxpercent-trypercent<=300)
  686. break;
  687. else
  688. {
  689. lastpercent=trypercent;
  690. minpercent=trypercent;
  691. trypercent=(minpercent+maxpercent)/2; /* try half way between min and max */
  692. }
  693. }
  694. else
  695. {
  696. lastpercent=trypercent;
  697. trypercent=((trypercent-minpercent)*3)/4;
  698. }
  699. tries++;
  700. }
  701. Info->FileSize=newfilesize;
  702. while (status==SlibErrorNone && !Info->VideoLengthKnown)
  703. status=SlibSeek(handle, SLIB_STREAM_ALL, SLIB_SEEK_NEXT_KEY, 0);
  704. SlibSeekEx(handle, SLIB_STREAM_ALL, SLIB_SEEK_KEY, stime,
  705. SLIB_UNIT_MS, NULL);
  706. }
  707. }
  708. break;
  709. case SLIB_PARAM_FASTENCODE:
  710. if (Info->Svh)
  711. SvSetParamBoolean(Info->Svh, SV_PARAM_FASTENCODE,
  712. (ScBoolean_t)value);
  713. if (Info->Sah)
  714. SvSetParamBoolean(Info->Sah, SV_PARAM_FASTENCODE,
  715. (ScBoolean_t)value);
  716. break;
  717. case SLIB_PARAM_FASTDECODE:
  718. if (Info->Svh)
  719. SvSetParamBoolean(Info->Svh, SV_PARAM_FASTDECODE,
  720. (ScBoolean_t)value);
  721. if (Info->Sah)
  722. SvSetParamBoolean(Info->Sah, SV_PARAM_FASTDECODE,
  723. (ScBoolean_t)value);
  724. break;
  725. case SLIB_PARAM_MOTIONALG:
  726. SlibSetParamInt(handle, stream, param, value?1:0);
  727. break;
  728. default:
  729. return(SlibErrorUnsupportedParam);
  730. }
  731. return(SlibErrorNone);
  732. }
  733. SlibStatus_t SlibSetParamStruct(SlibHandle_t handle, SlibStream_t stream,
  734. SlibParameter_t param,
  735. void *data, unsigned dword datasize)
  736. {
  737. SlibInfo_t *Info=(SlibInfo_t *)handle;
  738. SlibStatus_t status=SlibErrorNone;
  739. if (!handle)
  740. return(SlibErrorBadHandle);
  741. if (data==NULL || datasize==0)
  742. return(SlibErrorBadArgument);
  743. _SlibDebug(_DEBUG_, printf("SlibSetParamStruct(stream=%d, param=%d, data=%p datasize=%ld)\n",
  744. stream, param, data, datasize) );
  745. switch (param)
  746. {
  747. case SLIB_PARAM_VIDEOFORMAT:
  748. {
  749. BITMAPINFOHEADER *bmh=(BITMAPINFOHEADER *)data;
  750. _SlibDebug(_DEBUG_,
  751. printf("SlibSetParamStruct(SLIB_PARAM_VIDEOFORMAT)\n") );
  752. if (Info->VideoFormat==NULL || Info->VideoFormat->biSize<datasize)
  753. {
  754. ScFree(Info->VideoFormat);
  755. Info->VideoFormat=NULL;
  756. }
  757. if (Info->VideoFormat==NULL)
  758. Info->VideoFormat=(BITMAPINFOHEADER *)ScAlloc(datasize);
  759. Info->Width=(word)bmh->biWidth;
  760. Info->Height=abs(bmh->biHeight);
  761. if (Info->VideoFormat)
  762. {
  763. memcpy(Info->VideoFormat, bmh, datasize);
  764. return(slibValidateVideoParams(Info));
  765. }
  766. else
  767. return(SlibErrorMemory);
  768. }
  769. default:
  770. return(SlibErrorUnsupportedParam);
  771. }
  772. /* this needs to be implemented */
  773. return(SlibErrorNone);
  774. }
  775. long SlibGetParamInt(SlibHandle_t handle, SlibStream_t stream,
  776. SlibParameter_t param)
  777. {
  778. SlibInfo_t *Info=(SlibInfo_t *)handle;
  779. if (!handle)
  780. return(0);
  781. switch (param)
  782. {
  783. case SLIB_PARAM_TYPE:
  784. if (stream==SLIB_STREAM_MAINAUDIO)
  785. return((long)Info->AudioType);
  786. else if (stream==SLIB_STREAM_MAINVIDEO)
  787. return((long)Info->VideoType);
  788. else
  789. return((long)Info->Type);
  790. break;
  791. case SLIB_PARAM_FPS:
  792. return((long)Info->FramesPerSec);
  793. break;
  794. case SLIB_PARAM_BITRATE:
  795. return((long)Info->TotalBitRate);
  796. case SLIB_PARAM_VIDEOBITRATE:
  797. return((long)Info->VideoBitRate);
  798. case SLIB_PARAM_WIDTH:
  799. return((long)Info->Width);
  800. case SLIB_PARAM_HEIGHT:
  801. return((long)Info->Height);
  802. case SLIB_PARAM_STRIDE:
  803. return((long)Info->Stride);
  804. case SLIB_PARAM_NATIVEWIDTH:
  805. if (Info->CompVideoFormat)
  806. return((long)Info->CompVideoFormat->biWidth);
  807. else
  808. return((long)Info->Width);
  809. case SLIB_PARAM_NATIVEHEIGHT:
  810. if (Info->CompVideoFormat)
  811. return((long)Info->CompVideoFormat->biHeight);
  812. else
  813. return((long)Info->Height);
  814. case SLIB_PARAM_NATIVEVIDEOFORMAT:
  815. {
  816. long format=(long)SvGetParamInt(Info->Svh, SV_PARAM_NATIVEFORMAT);
  817. if (format==0)
  818. format=Info->CodecVideoFormat
  819. ? Info->CodecVideoFormat->biCompression
  820. : Info->VideoFormat->biCompression;
  821. return(format);
  822. }
  823. case SLIB_PARAM_IMAGESIZE:
  824. return((long)Info->ImageSize);
  825. case SLIB_PARAM_MININPUTSIZE:
  826. {
  827. long size=0;
  828. if (Info->Mode==SLIB_MODE_COMPRESS)
  829. {
  830. if (slibHasVideo(Info))
  831. size+=Info->ImageSize;
  832. if (slibHasAudio(Info))
  833. switch (Info->AudioType)
  834. {
  835. case SLIB_TYPE_G723:
  836. size+=480;
  837. break;
  838. default:
  839. if (Info->AudioFormat)
  840. size+=Info->AudioFormat->nBlockAlign;
  841. }
  842. }
  843. else if (Info->Mode==SLIB_MODE_DECOMPRESS)
  844. {
  845. if (slibHasVideo(Info))
  846. switch (Info->AudioType)
  847. {
  848. case SLIB_TYPE_H263:
  849. size+=Info->VideoBitRate>0?(Info->VideoBitRate/8):(64*1024);
  850. break;
  851. default:
  852. size+=Info->VideoBitRate>0?(Info->VideoBitRate/8):(64*1024);
  853. }
  854. if (slibHasAudio(Info))
  855. switch (Info->AudioType)
  856. {
  857. case SLIB_TYPE_G723:
  858. size+=(Info->AudioBitRate>=6000)?24:20;
  859. break;
  860. default:
  861. if (Info->AudioFormat)
  862. size+=Info->AudioFormat->nBlockAlign;
  863. }
  864. }
  865. return(size);
  866. }
  867. break;
  868. case SLIB_PARAM_INPUTSIZE:
  869. {
  870. long size=0;
  871. size+=SlibGetParamInt(handle, stream, SLIB_PARAM_MININPUTSIZE);
  872. if (size<=8) size=8*1024;
  873. if (Info->Mode==SLIB_MODE_DECOMPRESS)
  874. {
  875. if (slibHasVideo(Info))
  876. switch (Info->Type) /* add in bytes for header */
  877. {
  878. case SLIB_TYPE_AVI: size+=64; break;
  879. }
  880. if (slibHasAudio(Info))
  881. {
  882. if (!Info->HeaderProcessed) /* add in header */
  883. switch (Info->Type)
  884. {
  885. case SLIB_TYPE_PCM_WAVE: size+=40; break;
  886. }
  887. }
  888. }
  889. return(size);
  890. }
  891. break;
  892. case SLIB_PARAM_VIDEOFRAME:
  893. if (Info->FramesPerSec)
  894. return((long)slibTimeToFrame(Info, Info->VideoTimeStamp
  895. +(Info->VideoFrameDuration/200)));
  896. break;
  897. case SLIB_PARAM_FRAMEDURATION:
  898. if (Info->FramesPerSec)
  899. return((long)(10000000L/Info->FramesPerSec));
  900. else
  901. return((long)0);
  902. case SLIB_PARAM_VIDEOFORMAT:
  903. if (Info->VideoFormat)
  904. return((long)Info->VideoFormat->biCompression);
  905. else
  906. return(0L);
  907. break;
  908. case SLIB_PARAM_VIDEOBITS:
  909. if (Info->VideoFormat)
  910. return((long)Info->VideoFormat->biBitCount);
  911. else
  912. return(0L);
  913. case SLIB_PARAM_VIDEOPROGRAM:
  914. return((long)Info->VideoPID);
  915. case SLIB_PARAM_AUDIOPROGRAM:
  916. return((long)Info->AudioPID);
  917. case SLIB_PARAM_VIDEOMAINSTREAM:
  918. return((long)Info->VideoMainStream);
  919. case SLIB_PARAM_AUDIOMAINSTREAM:
  920. return((long)Info->AudioMainStream);
  921. case SLIB_PARAM_KEYSPACING:
  922. if (Info->Svh)
  923. return((long)SvGetParamInt(Info->Svh, SV_PARAM_KEYSPACING));
  924. else
  925. return((long)Info->KeySpacing);
  926. case SLIB_PARAM_SUBKEYSPACING:
  927. if (Info->Svh)
  928. return((long)SvGetParamInt(Info->Svh, SV_PARAM_SUBKEYSPACING));
  929. else
  930. return((long)Info->SubKeySpacing);
  931. case SLIB_PARAM_AUDIOFORMAT:
  932. if (Info->AudioFormat)
  933. return((long)Info->AudioFormat->wFormatTag);
  934. else
  935. return(0);
  936. break;
  937. case SLIB_PARAM_AUDIOBITRATE:
  938. if (Info->AudioBitRate==0 && Info->Sah)
  939. Info->AudioBitRate=(dword)SaGetParamInt(Info->Sah, SA_PARAM_BITRATE);
  940. return((long)Info->AudioBitRate);
  941. case SLIB_PARAM_VIDEOSTREAMS:
  942. return((long)Info->VideoStreams);
  943. case SLIB_PARAM_AUDIOSTREAMS:
  944. return((long)Info->AudioStreams);
  945. case SLIB_PARAM_AUDIOCHANNELS:
  946. return((long)Info->Channels);
  947. case SLIB_PARAM_SAMPLESPERSEC:
  948. return((long)Info->SamplesPerSec);
  949. case SLIB_PARAM_NATIVESAMPLESPERSEC:
  950. if (Info->AudioFormat)
  951. return((long)Info->AudioFormat->nSamplesPerSec);
  952. break;
  953. case SLIB_PARAM_BITSPERSAMPLE:
  954. return((long)Info->BitsPerSample);
  955. case SLIB_PARAM_NATIVEBITSPERSAMPLE:
  956. if (Info->AudioFormat)
  957. return((long)Info->AudioFormat->wBitsPerSample);
  958. break;
  959. case SLIB_PARAM_FILESIZE:
  960. return((long)Info->FileSize);
  961. case SLIB_PARAM_FILEBUFSIZE:
  962. return((long)Info->FileBufSize);
  963. case SLIB_PARAM_COMPBUFSIZE:
  964. return((long)Info->CompBufSize);
  965. case SLIB_PARAM_OVERFLOWSIZE:
  966. return((long)Info->OverflowSize);
  967. case SLIB_PARAM_VIDEOQUALITY:
  968. if (Info->Svh)
  969. return((long)SvGetParamInt(Info->Svh, SV_PARAM_QUALITY));
  970. break;
  971. case SLIB_PARAM_AUDIOQUALITY:
  972. if (Info->Sah)
  973. return((long)SaGetParamInt(Info->Sah, SA_PARAM_QUALITY));
  974. break;
  975. case SLIB_PARAM_VBVBUFFERSIZE:
  976. {
  977. dword vbv;
  978. if (Info->Svh)
  979. vbv=(dword)SvGetParamInt(Info->Svh, SV_PARAM_VBVBUFFERSIZE);
  980. if (vbv<=0)
  981. vbv=Info->VBVbufSize;
  982. return(vbv);
  983. }
  984. case SLIB_PARAM_VBVDELAY:
  985. if (Info->Svh)
  986. return((long)SvGetParamInt(Info->Svh, SV_PARAM_VBVDELAY));
  987. break;
  988. case SLIB_PARAM_MOTIONALG:
  989. if (Info->Svh)
  990. return((long)SvGetParamInt(Info->Svh, SV_PARAM_MOTIONALG));
  991. break;
  992. case SLIB_PARAM_ALGFLAGS:
  993. if (Info->Svh)
  994. return((long)SvGetParamInt(Info->Svh, SV_PARAM_ALGFLAGS));
  995. break;
  996. case SLIB_PARAM_MOTIONSEARCH:
  997. if (Info->Svh)
  998. return((long)SvGetParamInt(Info->Svh, SV_PARAM_MOTIONSEARCH));
  999. break;
  1000. case SLIB_PARAM_MOTIONTHRESH:
  1001. if (Info->Svh)
  1002. return((long)SvGetParamInt(Info->Svh, SV_PARAM_MOTIONTHRESH));
  1003. break;
  1004. case SLIB_PARAM_PACKETSIZE:
  1005. if (Info->Svh)
  1006. return((long)SvGetParamInt(Info->Svh, SV_PARAM_PACKETSIZE));
  1007. break;
  1008. case SLIB_PARAM_FORMATEXT:
  1009. if (Info->Svh)
  1010. return((long)SvGetParamInt(Info->Svh, SV_PARAM_FORMATEXT));
  1011. break;
  1012. case SLIB_PARAM_QUANTI:
  1013. if (Info->Svh)
  1014. return((long)SvGetParamInt(Info->Svh, SV_PARAM_QUANTI));
  1015. break;
  1016. case SLIB_PARAM_QUANTP:
  1017. if (Info->Svh)
  1018. return((long)SvGetParamInt(Info->Svh, SV_PARAM_QUANTP));
  1019. break;
  1020. case SLIB_PARAM_QUANTB:
  1021. if (Info->Svh)
  1022. return((long)SvGetParamInt(Info->Svh, SV_PARAM_QUANTB));
  1023. break;
  1024. case SLIB_PARAM_FRAMETYPE:
  1025. if (Info->Svh)
  1026. return((long)SvGetParamInt(Info->Svh, SV_PARAM_FRAMETYPE));
  1027. break;
  1028. case SLIB_PARAM_STATS_FPS:
  1029. return((long)SlibGetParamFloat(handle, stream, SLIB_PARAM_STATS_FPS));
  1030. default:
  1031. return((long)SlibGetParamLong(handle, stream, param));
  1032. }
  1033. return(0);
  1034. }
  1035. qword SlibGetParamLong(SlibHandle_t handle, SlibStream_t stream,
  1036. SlibParameter_t param)
  1037. {
  1038. SlibInfo_t *Info=(SlibInfo_t *)handle;
  1039. if (!handle)
  1040. return((qword)0);
  1041. switch (param)
  1042. {
  1043. case SLIB_PARAM_VIDEOFRAMES:
  1044. if (Info->FramesPerSec)
  1045. return(slibTimeToFrame(Info, Info->VideoLength
  1046. +(Info->VideoFrameDuration/200)));
  1047. break;
  1048. case SLIB_PARAM_VIDEOLENGTH:
  1049. return(Info->VideoLength);
  1050. case SLIB_PARAM_AUDIOLENGTH:
  1051. return((long)Info->AudioLength);
  1052. case SLIB_PARAM_STATS_TIME:
  1053. if (Info->stats)
  1054. {
  1055. if (Info->stats->Record) /* still recording */
  1056. Info->stats->StopTime=slibGetSystemTime();
  1057. return((long)(Info->stats->StopTime-Info->stats->StartTime));
  1058. }
  1059. break;
  1060. case SLIB_PARAM_STATS_FRAMESPROCESSED:
  1061. if (Info->stats)
  1062. return(Info->stats->FramesProcessed);
  1063. break;
  1064. case SLIB_PARAM_STATS_FRAMESSKIPPED:
  1065. if (Info->stats)
  1066. return(Info->stats->FramesSkipped);
  1067. break;
  1068. case SLIB_PARAM_STATS_FRAMES:
  1069. if (Info->stats)
  1070. return(Info->stats->FramesSkipped+
  1071. Info->stats->FramesProcessed);
  1072. break;
  1073. case SLIB_PARAM_TIMECODE:
  1074. if (Info->Svh)
  1075. return(SvGetParamInt(Info->Svh, SV_PARAM_TIMECODE));
  1076. break;
  1077. case SLIB_PARAM_CALCTIMECODE:
  1078. if (Info->Svh)
  1079. return(SvGetParamInt(Info->Svh, SV_PARAM_CALCTIMECODE));
  1080. break;
  1081. case SLIB_PARAM_PTIMECODE:
  1082. if (stream==SLIB_STREAM_MAINAUDIO)
  1083. return(Info->AudioPTimeCode);
  1084. else if (Info->VideoPTimeCode==SLIB_TIME_NONE && Info->Svh &&
  1085. SvGetParamInt(Info->Svh, SV_PARAM_TIMECODE)>0)
  1086. return(SvGetParamInt(Info->Svh, SV_PARAM_TIMECODE));
  1087. else
  1088. return(Info->VideoPTimeCode);
  1089. case SLIB_PARAM_DTIMECODE:
  1090. if (stream==SLIB_STREAM_MAINAUDIO)
  1091. return(Info->AudioDTimeCode);
  1092. else if (Info->VideoDTimeCode==SLIB_TIME_NONE && Info->Svh &&
  1093. SvGetParamInt(Info->Svh, SV_PARAM_TIMECODE)>0)
  1094. return(SvGetParamInt(Info->Svh, SV_PARAM_TIMECODE));
  1095. else
  1096. return(Info->VideoDTimeCode);
  1097. case SLIB_PARAM_PERCENT100:
  1098. if (Info->FileSize>0)
  1099. {
  1100. ScBitstream_t *bs;
  1101. SlibPosition_t pos=slibGetPinPosition(Info, SLIB_DATA_COMPRESSED);
  1102. /* subtract all the unused data from the input position */
  1103. pos-=slibDataOnPin(Info, SLIB_DATA_VIDEO);
  1104. pos-=slibDataOnPin(Info, SLIB_DATA_AUDIO);
  1105. if ((bs=SvGetDataSource(Info->Svh))!=NULL)
  1106. pos-=ScBSBufferedBytesUnused(bs); /* Video Codec unused bytes */
  1107. if ((bs=SaGetDataSource(Info->Sah))!=NULL)
  1108. pos-=ScBSBufferedBytesUnused(bs); /* Audio Codec unused bytes */
  1109. if (pos>=(SlibPosition_t)Info->FileSize)
  1110. return(10000);
  1111. else if (pos>=0)
  1112. return((pos*10000)/Info->FileSize);
  1113. else
  1114. return(0);
  1115. }
  1116. else
  1117. {
  1118. if (stream==SLIB_STREAM_MAINAUDIO &&
  1119. SlibTimeIsValid(Info->AudioTimeStamp) &&
  1120. Info->AudioLength>0)
  1121. return((Info->AudioTimeStamp*10000)/Info->AudioLength);
  1122. else if (SlibTimeIsValid(Info->VideoTimeStamp)
  1123. && Info->VideoLength>0)
  1124. return((Info->VideoTimeStamp*10000)/Info->VideoLength);
  1125. }
  1126. return((qword)-1);
  1127. }
  1128. return((qword)0);
  1129. }
  1130. float SlibGetParamFloat(SlibHandle_t handle, SlibStream_t stream,
  1131. SlibParameter_t param)
  1132. {
  1133. SlibInfo_t *Info=(SlibInfo_t *)handle;
  1134. switch (param)
  1135. {
  1136. case SLIB_PARAM_VERSION:
  1137. return(_version);
  1138. }
  1139. if (!handle)
  1140. return((float)0.0);
  1141. switch (param)
  1142. {
  1143. case SLIB_PARAM_FPS:
  1144. return((float)Info->FramesPerSec);
  1145. case SLIB_PARAM_VIDEOASPECTRATIO:
  1146. if (Info->Svh)
  1147. return(SvGetParamFloat(Info->Svh, SV_PARAM_ASPECTRATIO));
  1148. break;
  1149. case SLIB_PARAM_STATS_FPS:
  1150. if (Info->stats)
  1151. {
  1152. float fps=0.0F;
  1153. if (Info->stats->Record) /* still recording */
  1154. Info->stats->StopTime=slibGetSystemTime();
  1155. if (Info->stats->StartTime<Info->stats->StopTime)
  1156. {
  1157. qword ellapsedtime=Info->stats->StopTime-Info->stats->StartTime;
  1158. fps=(float)(Info->stats->FramesProcessed*1000)/ellapsedtime;
  1159. }
  1160. return(fps);
  1161. }
  1162. else
  1163. return(0.0F);
  1164. }
  1165. return((float)SlibGetParamInt(handle, stream, param));
  1166. }
  1167. SlibBoolean_t SlibGetParamBoolean(SlibHandle_t handle, SlibStream_t stream,
  1168. SlibParameter_t param)
  1169. {
  1170. SlibInfo_t *Info=(SlibInfo_t *)handle;
  1171. if (!handle)
  1172. return(SlibErrorBadHandle);
  1173. switch (param)
  1174. {
  1175. case SLIB_PARAM_STATS:
  1176. return(Info->stats ? Info->stats->Record : FALSE);
  1177. case SLIB_PARAM_NEEDACCURACY:
  1178. return((SlibBoolean_t)Info->NeedAccuracy);
  1179. case SLIB_PARAM_FASTENCODE:
  1180. if (Info->Svh)
  1181. return((SlibBoolean_t)SvGetParamBoolean(Info->Svh,
  1182. SV_PARAM_FASTENCODE));
  1183. break;
  1184. case SLIB_PARAM_FASTDECODE:
  1185. if (Info->Svh)
  1186. return((SlibBoolean_t)SvGetParamBoolean(Info->Svh,
  1187. SV_PARAM_FASTDECODE));
  1188. break;
  1189. }
  1190. return(FALSE);
  1191. }
  1192. char *SlibGetParamString(SlibHandle_t handle, SlibStream_t stream,
  1193. SlibParameter_t param)
  1194. {
  1195. SlibInfo_t *Info=(SlibInfo_t *)handle;
  1196. static char result[100];
  1197. strcpy(result, "Unknown");
  1198. switch (param)
  1199. {
  1200. case SLIB_PARAM_VERSION_DATE:
  1201. return(_version_date);
  1202. break;
  1203. }
  1204. if (!handle)
  1205. return(result);
  1206. switch (param)
  1207. {
  1208. case SLIB_PARAM_NATIVEVIDEOFORMAT:
  1209. if (Info->CodecVideoFormat)
  1210. switch(Info->CodecVideoFormat->biCompression)
  1211. {
  1212. case BI_YUY2:
  1213. case BI_DECYUVDIB: strcpy(result, "YUV 4:2:2 Interleaved");
  1214. break;
  1215. case BI_BITFIELDS: strcpy(result, "BITFIELDS");
  1216. break;
  1217. case BI_DECXIMAGEDIB: sprintf(result, "XIMAGE %d",
  1218. Info->VideoFormat->biBitCount);
  1219. break;
  1220. case BI_YU12SEP: strcpy(result, "YUV 4:1:1 Separated");
  1221. break;
  1222. case BI_YU16SEP: strcpy(result, "YUV 4:2:2 Separated");
  1223. break;
  1224. case BI_RGB: sprintf(result, "RGB %d",
  1225. Info->VideoFormat->biBitCount);
  1226. break;
  1227. }
  1228. break;
  1229. case SLIB_PARAM_VIDEOFORMAT:
  1230. if (Info->VideoFormat)
  1231. switch(Info->VideoFormat->biCompression)
  1232. {
  1233. case BI_YUY2:
  1234. case BI_DECYUVDIB: strcpy(result, "YUV 4:2:2 Interleaved");
  1235. break;
  1236. case BI_BITFIELDS: strcpy(result, "BITFIELDS");
  1237. break;
  1238. case BI_DECXIMAGEDIB: sprintf(result, "XIMAGE %d",
  1239. Info->VideoFormat->biBitCount);
  1240. break;
  1241. case BI_YU12SEP: strcpy(result, "YUV 4:1:1 Separated");
  1242. break;
  1243. case BI_YU16SEP: strcpy(result, "YUV 4:2:2 Separated");
  1244. break;
  1245. case BI_RGB: sprintf(result, "RGB %d",
  1246. Info->VideoFormat->biBitCount);
  1247. break;
  1248. }
  1249. break;
  1250. case SLIB_PARAM_AUDIOFORMAT:
  1251. if (Info->AudioFormat)
  1252. switch (Info->AudioFormat->wFormatTag)
  1253. {
  1254. case WAVE_FORMAT_PCM: strcpy(result, "PCM");
  1255. break;
  1256. }
  1257. break;
  1258. case SLIB_PARAM_TYPE:
  1259. if (stream==SLIB_STREAM_MAINAUDIO)
  1260. return(SlibQueryForDesc(SLIB_QUERY_TYPES, Info->AudioType));
  1261. else if (stream==SLIB_STREAM_MAINVIDEO)
  1262. return(SlibQueryForDesc(SLIB_QUERY_TYPES, Info->VideoType));
  1263. else
  1264. return(SlibQueryForDesc(SLIB_QUERY_TYPES, Info->Type));
  1265. break;
  1266. }
  1267. return(result);
  1268. }
  1269. /*
  1270. ** Name: SlibValidateParams
  1271. ** Purpose: Ensure that the the Video and Audio parameter settings are
  1272. ** valid and supported.
  1273. */
  1274. SlibStatus_t SlibValidateParams(SlibHandle_t handle)
  1275. {
  1276. SlibInfo_t *Info=(SlibInfo_t *)handle;
  1277. if (Info->VideoStreams>0 && slibValidateVideoParams(Info)!=SlibErrorNone)
  1278. return(slibValidateVideoParams(Info));
  1279. if (Info->AudioStreams>0 && slibValidateAudioParams(Info)!=SlibErrorNone)
  1280. return(slibValidateAudioParams(Info));
  1281. if (Info->Svh)
  1282. {
  1283. SvStatus_t status;
  1284. _SlibDebug(_DEBUG_, printf("SvQuery(%c%c%c%c,%d bits,%dx%d,%c%c%c%c,%d bits,%dx%d)\n",
  1285. (Info->CodecVideoFormat->biCompression)&0xFF,
  1286. (Info->CodecVideoFormat->biCompression>>8)&0xFF,
  1287. (Info->CodecVideoFormat->biCompression>>16)&0xFF,
  1288. (Info->CodecVideoFormat->biCompression>>24)&0xFF,
  1289. Info->CodecVideoFormat->biBitCount,
  1290. Info->CodecVideoFormat->biWidth,
  1291. Info->CodecVideoFormat->biHeight,
  1292. (Info->CompVideoFormat->biCompression)&0xFF,
  1293. (Info->CompVideoFormat->biCompression>>8)&0xFF,
  1294. (Info->CompVideoFormat->biCompression>>16)&0xFF,
  1295. (Info->CompVideoFormat->biCompression>>24)&0xFF,
  1296. Info->CompVideoFormat->biBitCount,
  1297. Info->CompVideoFormat->biWidth,
  1298. Info->CompVideoFormat->biHeight) );
  1299. if (Info->Mode==SLIB_MODE_COMPRESS)
  1300. status=SvCompressQuery(Info->Svh, Info->CodecVideoFormat,
  1301. Info->CompVideoFormat);
  1302. else
  1303. status=SvDecompressQuery(Info->Svh, Info->CompVideoFormat,
  1304. Info->CodecVideoFormat);
  1305. if (status!=NoErrors)
  1306. {
  1307. _SlibDebug(_WARN_, printf("SlibValidateParams() SvQuery failed\n");
  1308. ScGetErrorText(status,0,0) );
  1309. return(SlibErrorUnsupportedFormat);
  1310. }
  1311. }
  1312. if (Info->Sah)
  1313. {
  1314. SaStatus_t status;
  1315. if (Info->Mode==SLIB_MODE_COMPRESS)
  1316. status=SaCompressQuery(Info->Sah, Info->AudioFormat,
  1317. Info->CompAudioFormat);
  1318. else
  1319. status=SaDecompressQuery(Info->Sah, Info->CompAudioFormat,
  1320. Info->AudioFormat);
  1321. if (status!=NoErrors)
  1322. {
  1323. _SlibDebug(_WARN_, printf("SlibValidateParams() SaBegin failed\n");
  1324. ScGetErrorText(status,0,0) );
  1325. return(SlibErrorUnsupportedFormat);
  1326. }
  1327. }
  1328. return(SlibErrorNone);
  1329. }