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.

585 lines
21 KiB

  1. /*
  2. * @DEC_COPYRIGHT@
  3. */
  4. /*
  5. * HISTORY
  6. * $Log: slib_audio.c,v $
  7. * Revision 1.1.6.14 1996/12/13 18:19:06 Hans_Graves
  8. * Added initialization of AudioPTimeBase.
  9. * [1996/12/13 18:07:26 Hans_Graves]
  10. *
  11. * Revision 1.1.6.13 1996/12/04 22:34:30 Hans_Graves
  12. * Make AC3 detection in audio streams more accurate.
  13. * [1996/12/04 22:19:21 Hans_Graves]
  14. *
  15. * Revision 1.1.6.12 1996/11/18 23:07:34 Hans_Graves
  16. * Make use of presentation timestamps. Make seeking time-based.
  17. * [1996/11/18 22:47:36 Hans_Graves]
  18. *
  19. * Revision 1.1.6.11 1996/11/11 18:21:06 Hans_Graves
  20. * Added AC3 support for multiplexed streams.
  21. * [1996/11/11 18:00:25 Hans_Graves]
  22. *
  23. * Revision 1.1.6.10 1996/11/08 21:51:04 Hans_Graves
  24. * Added AC3 support. Better seperation of stream types.
  25. * [1996/11/08 21:28:01 Hans_Graves]
  26. *
  27. * Revision 1.1.6.9 1996/10/28 17:32:30 Hans_Graves
  28. * MME-1402, 1431, 1435: Timestamp related changes.
  29. * [1996/10/28 17:23:01 Hans_Graves]
  30. *
  31. * Revision 1.1.6.8 1996/10/15 17:34:11 Hans_Graves
  32. * Added MPEG-2 Program Stream support. Fix MPEG-2 not skipping audio.
  33. * [1996/10/15 17:31:11 Hans_Graves]
  34. *
  35. * Revision 1.1.6.7 1996/09/29 22:19:39 Hans_Graves
  36. * Removed SLIB_MODE_DECOMPRESS_QUERY.
  37. * [1996/09/29 21:33:10 Hans_Graves]
  38. *
  39. * Revision 1.1.6.6 1996/09/25 19:16:46 Hans_Graves
  40. * Added SLIB_INTERNAL define.
  41. * [1996/09/25 19:01:51 Hans_Graves]
  42. *
  43. * Revision 1.1.6.5 1996/09/18 23:46:37 Hans_Graves
  44. * Use slibSetMaxInput under MPEG
  45. * [1996/09/18 22:03:03 Hans_Graves]
  46. *
  47. * Revision 1.1.6.4 1996/05/24 12:39:52 Hans_Graves
  48. * Disable debugging printfs
  49. * [1996/05/24 12:39:37 Hans_Graves]
  50. *
  51. * Revision 1.1.6.3 1996/05/23 18:46:37 Hans_Graves
  52. * Merge fixes MME-1292, MME-1293, and MME-1304.
  53. * [1996/05/23 18:45:22 Hans_Graves]
  54. *
  55. * Revision 1.1.6.2 1996/05/10 21:17:20 Hans_Graves
  56. * Fix calculation of audio lengths (NT)
  57. * [1996/05/10 20:44:27 Hans_Graves]
  58. *
  59. * Revision 1.1.4.4 1996/04/22 15:04:53 Hans_Graves
  60. * Added slibValidateAudioParams()
  61. * [1996/04/22 14:43:35 Hans_Graves]
  62. *
  63. * Revision 1.1.4.3 1996/04/01 16:23:14 Hans_Graves
  64. * NT porting
  65. * [1996/04/01 16:15:58 Hans_Graves]
  66. *
  67. * Revision 1.1.4.2 1996/03/29 22:21:33 Hans_Graves
  68. * Added MPEG/JPEG/H261_SUPPORT ifdefs
  69. * [1996/03/29 21:56:58 Hans_Graves]
  70. *
  71. * Revision 1.1.2.12 1996/02/21 22:52:45 Hans_Graves
  72. * Fixed MPEG 2 systems stuff
  73. * [1996/02/21 22:51:03 Hans_Graves]
  74. *
  75. * Revision 1.1.2.11 1996/02/19 18:03:56 Hans_Graves
  76. * Fixed a number of MPEG related bugs
  77. * [1996/02/19 17:57:40 Hans_Graves]
  78. *
  79. * Revision 1.1.2.10 1996/02/13 18:47:48 Hans_Graves
  80. * Added slibSkipAudio()
  81. * [1996/02/13 18:41:27 Hans_Graves]
  82. *
  83. * Revision 1.1.2.9 1996/02/07 23:23:56 Hans_Graves
  84. * Added SEEK_EXACT. Fixed most frame counting problems.
  85. * [1996/02/07 23:20:31 Hans_Graves]
  86. *
  87. * Revision 1.1.2.8 1996/02/02 17:36:03 Hans_Graves
  88. * Enhanced audio info. Cleaned up API
  89. * [1996/02/02 17:29:46 Hans_Graves]
  90. *
  91. * Revision 1.1.2.7 1996/01/31 14:50:39 Hans_Graves
  92. * Renamed SLIB_TYPE_WAVE to SLIB_TYPE_PCM_WAVE
  93. * [1996/01/31 14:50:27 Hans_Graves]
  94. *
  95. * Revision 1.1.2.6 1996/01/15 16:26:29 Hans_Graves
  96. * Added MPEG 1 Audio compression support
  97. * [1996/01/15 15:46:07 Hans_Graves]
  98. *
  99. * Revision 1.1.2.5 1996/01/11 16:17:31 Hans_Graves
  100. * Added MPEG II Systems decode support
  101. * [1996/01/11 16:12:35 Hans_Graves]
  102. *
  103. * Revision 1.1.2.4 1996/01/08 16:41:32 Hans_Graves
  104. * Added MPEG II decoding support
  105. * [1996/01/08 15:53:05 Hans_Graves]
  106. *
  107. * Revision 1.1.2.3 1995/11/09 23:14:06 Hans_Graves
  108. * Added MPEG audio decompression
  109. * [1995/11/09 23:08:41 Hans_Graves]
  110. *
  111. * Revision 1.1.2.2 1995/11/06 18:47:55 Hans_Graves
  112. * First time under SLIB
  113. * [1995/11/06 18:36:03 Hans_Graves]
  114. *
  115. * $EndLog$
  116. */
  117. /*****************************************************************************
  118. ** Copyright (c) Digital Equipment Corporation, 1995 **
  119. ** **
  120. ** All Rights Reserved. Unpublished rights reserved under the copyright **
  121. ** laws of the United States. **
  122. ** **
  123. ** The software contained on this media is proprietary to and embodies **
  124. ** the confidential technology of Digital Equipment Corporation. **
  125. ** Possession, use, duplication or dissemination of the software and **
  126. ** media is authorized only pursuant to a valid written license from **
  127. ** Digital Equipment Corporation. **
  128. ** **
  129. ** RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure by the U.S. **
  130. ** Government is subject to restrictions as set forth in Subparagraph **
  131. ** (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, as applicable. **
  132. ******************************************************************************/
  133. /*
  134. #define _SLIBDEBUG_
  135. */
  136. #define SLIB_INTERNAL
  137. #include "slib.h"
  138. #include "mpeg.h"
  139. #include "avi.h"
  140. #ifdef AC3_SUPPORT
  141. #include "ac3.h"
  142. #endif /* AC3_SUPPORT */
  143. #ifdef _SLIBDEBUG_
  144. #define _DEBUG_ 1 /* detailed debuging statements */
  145. #define _VERBOSE_ 1 /* show progress */
  146. #define _VERIFY_ 1 /* verify correct operation */
  147. #define _WARN_ 1 /* warnings about strange behavior */
  148. #endif
  149. #ifdef AC3_SUPPORT
  150. SlibBoolean_t slibParseAC3Header(SlibInfo_t *Info, SlibPin_t *srcpin,
  151. unsigned char *buf, unsigned dword size,
  152. int *channels, int *sps, int *bps)
  153. {
  154. /*
  155. * Initial cut at parameters -
  156. * Update later using header parsing - ***tfm***
  157. */
  158. Info->AudioBitRate = 256000;
  159. *channels = 2;
  160. *sps = 48000;
  161. *bps = 16;
  162. _SlibDebug(_VERBOSE_,
  163. printf("AC3: bitrate=%d channels=%d sps=%d bps=%s\n",
  164. Info->AudioBitRate, channels, sps, bps) );
  165. return(TRUE);
  166. }
  167. #endif /* AC3_SUPPORT */
  168. void SlibUpdateAudioInfo(SlibInfo_t *Info)
  169. {
  170. int channels=2, sps=44100, bps=16;
  171. SlibTime_t ptime=SLIB_TIME_NONE;
  172. _SlibDebug(_DEBUG_, printf("SlibUpdateAudioInfo()\n") );
  173. if (SlibTypeIsVideoOnly(Info->Type)) /* no audio? */
  174. return;
  175. if (Info->Mode == SLIB_MODE_COMPRESS)
  176. {
  177. switch (Info->Type)
  178. {
  179. case SLIB_TYPE_G723:
  180. //Initialize some info
  181. sps = 8000;
  182. bps = 16;
  183. channels =1;
  184. break;
  185. default:
  186. break;
  187. }
  188. }
  189. else if (Info->Mode == SLIB_MODE_DECOMPRESS)
  190. {
  191. SlibPin_t *srcpin;
  192. unsigned char *buf;
  193. unsigned dword size;
  194. switch (Info->Type)
  195. {
  196. case SLIB_TYPE_RIFF: /* might be WAVE format */
  197. case SLIB_TYPE_PCM_WAVE: /* might be WAVE format */
  198. srcpin=slibGetPin(Info, SLIB_DATA_COMPRESSED);
  199. buf = slibSearchBuffersOnPin(Info, srcpin,
  200. NULL, &size, RIFF_WAVE, 4, FALSE);
  201. if (buf)
  202. {
  203. Info->Type = SLIB_TYPE_PCM_WAVE;
  204. buf = slibSearchBuffersOnPin(Info, srcpin,
  205. NULL, &size, RIFF_FORMAT, 4, FALSE);
  206. if (buf)
  207. {
  208. dword datasize=((int)buf[3]<<24) | (int)buf[2]<<16 |
  209. (int)buf[1]<<8 | (int)buf[0];
  210. WAVE_format fmt;
  211. _SlibDebug(_DEBUG_,
  212. printf("datasize=%d\n", datasize);
  213. printf("%02X %02X %02X %02X\n", buf[0], buf[1], buf[2], buf[3]);
  214. printf("WAVE: SamplesPerSec=%d BitsPerSample=%d Channels=%d\n",
  215. sps, bps, channels) );
  216. buf+=4; /* skip size */
  217. memcpy(&fmt, buf, sizeof(fmt));
  218. channels = fmt.nChannels;
  219. sps = fmt.nSamplesPerSec;
  220. if (datasize<sizeof(WAVE_format)) /* not PCM */
  221. bps = 8;
  222. else
  223. bps = fmt.wBitsPerSample;
  224. if ((sps*channels*bps)>800)
  225. Info->AudioLength = (qword)(Info->FileSize*10L)/
  226. (qword)((sps*channels*bps)/800);
  227. if ((srcpin=slibLoadPin(Info, SLIB_DATA_AUDIO))==NULL)
  228. return;
  229. Info->AudioType=SLIB_TYPE_PCM;
  230. }
  231. else
  232. return; /* couldn't find format */
  233. }
  234. break;
  235. #ifdef MPEG_SUPPORT
  236. case SLIB_TYPE_MPEG1_AUDIO:
  237. case SLIB_TYPE_MPEG_SYSTEMS:
  238. case SLIB_TYPE_MPEG_SYSTEMS_MPEG2:
  239. case SLIB_TYPE_MPEG_TRANSPORT:
  240. case SLIB_TYPE_MPEG_PROGRAM:
  241. slibSetMaxInput(Info, 1000*1024);
  242. if ((srcpin=slibLoadPin(Info, SLIB_DATA_AUDIO))==NULL)
  243. {
  244. _SlibDebug(_DEBUG_ || _WARN_,
  245. printf("SlibUpdateAudioInfo() no audio data found\n") );
  246. if ((srcpin=slibLoadPin(Info, SLIB_DATA_PRIVATE))==NULL)
  247. {
  248. Info->AudioStreams = 0;
  249. _SlibDebug(_DEBUG_ || _WARN_,
  250. printf("SlibUpdateAudioInfo() no private data found\n") );
  251. slibSetMaxInput(Info, 0); /* no limit to input data */
  252. return;
  253. }
  254. buf=slibGetBufferFromPin(Info, srcpin, &size, NULL);
  255. if (buf && size>=4)
  256. {
  257. _SlibDebug(_DEBUG_,
  258. printf("AC3 Audio Head: %02X %02X %02X %02X\n",
  259. buf[0], buf[1], buf[2], buf[3]));
  260. /* check for AC3 sync code, may be reverse ordered */
  261. if ((buf[0]==0x0B && buf[1]==0x77) ||
  262. (buf[2]==0x0B && buf[3]==0x77) ||
  263. (buf[0]==0x77 && buf[1]==0x0B) ||
  264. (buf[2]==0x77 && buf[3]==0x0B))
  265. {
  266. Info->AudioType=SLIB_TYPE_AC3_AUDIO;
  267. _SlibDebug(_DEBUG_, printf("AC3 Audio Sync Word found\n") );
  268. }
  269. }
  270. }
  271. if (Info->AudioType==SLIB_TYPE_UNKNOWN ||
  272. Info->AudioType==SLIB_TYPE_MPEG1_AUDIO)
  273. {
  274. /* search for MPEG audio sync word */
  275. buf = NULL;
  276. slibSetMaxInput(Info, 10*1024); /* don't search too much */
  277. do {
  278. buf = slibSearchBuffersOnPin(Info, srcpin, buf, &size,
  279. 0xFF, 1, FALSE);
  280. } while (buf && (*buf&0xF0) != 0xF0);
  281. slibSetMaxInput(Info, 0); /* no limit to input data */
  282. if (buf)
  283. {
  284. const char *mode_names[4] =
  285. { "stereo", "j-stereo", "dual-ch", "single-ch" };
  286. const char *layer_names[4] = { "?", "I", "II", "III" };
  287. const int mpeg_freq[4] = {44100, 48000, 32000, 0};
  288. const int bitrate[4][15] = {
  289. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  290. {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448},
  291. {0,32,48,56,64,80,96,112,128,160,192,224,256,320,384},
  292. {0,32,40,48,56,64,80,96,112,128,160,192,224,256,320}
  293. };
  294. int bitrate_index, layer, mode, freq_index;
  295. _SlibDebug(_DEBUG_,
  296. printf("MPEG Audio Head: %02X %02X %02X %02X\n",
  297. buf[0], buf[1], buf[2], buf[3]));
  298. if ((*buf & 0xF0)==0xF0)
  299. {
  300. layer = 4-((*buf>>1) & 0x03);
  301. buf++; size--;
  302. bitrate_index = *buf >> 4;
  303. freq_index = (*buf>>2) & 0x03;
  304. buf++; size--;
  305. mode = *buf >> 6;
  306. Info->AudioBitRate = bitrate[layer][bitrate_index]*1000;
  307. channels = mode==3 ? 1 : 2;
  308. sps = mpeg_freq[freq_index];
  309. bps = 16;
  310. if (Info->AudioBitRate>100)
  311. Info->AudioLength = (qword)(Info->FileSize*80L)/
  312. (qword)(Info->AudioBitRate/100);
  313. _SlibDebug(_VERBOSE_,
  314. printf("layer=%d bitrate=%d(%d) mode=%s freq(%d)=%d\n",
  315. layer, bitrate[layer][bitrate_index], bitrate_index,
  316. mode_names[mode], freq_index, mpeg_freq[freq_index]) );
  317. if (layer<=2 && Info->AudioBitRate>0 &&
  318. Info->AudioBitRate<10000000) /* valid header */
  319. Info->AudioType=SLIB_TYPE_MPEG1_AUDIO;
  320. else
  321. Info->AudioBitRate=0;
  322. }
  323. }
  324. }
  325. if (Info->AudioType==SLIB_TYPE_UNKNOWN ||
  326. Info->AudioType==SLIB_TYPE_AC3_AUDIO)
  327. {
  328. #ifdef AC3_SUPPORT
  329. _SlibDebug(_VERBOSE_,
  330. printf("Searching for AC-3 on %s\n", srcpin->name) );
  331. /* Search for AC-3 sync word */
  332. slibSetMaxInput(Info, 1000*1024);
  333. buf = slibSearchBuffersOnPin(Info, srcpin, NULL, &size,
  334. AC3_SYNC_WORD_REV, AC3_SYNC_WORD_LEN/8, FALSE);
  335. slibSetMaxInput(Info, 0); /* no limit to input data */
  336. if (buf) /* found sync word */
  337. {
  338. Info->AudioType=SLIB_TYPE_AC3_AUDIO;
  339. _SlibDebug(_VERBOSE_, printf("AC3\n"));
  340. slibParseAC3Header(Info, srcpin, buf, size,
  341. &channels, &sps, &bps);
  342. if (srcpin->ID==SLIB_DATA_PRIVATE)
  343. {
  344. /* the private data pin now become the audio pin */
  345. slibRenamePin(Info, SLIB_DATA_PRIVATE, SLIB_DATA_AUDIO,
  346. "Audio");
  347. /* audio will be pulled from PRIVATE packets */
  348. Info->AudioMainStream=MPEG_PRIVATE_STREAM1_BASE;
  349. }
  350. }
  351. else
  352. {
  353. slibRemovePin(Info, SLIB_DATA_AUDIO);
  354. return;
  355. }
  356. #else /* !AC3_SUPPORT */
  357. slibRemovePin(Info, SLIB_DATA_AUDIO);
  358. return;
  359. #endif /* !AC3_SUPPORT */
  360. }
  361. break;
  362. #endif /* MPEG_SUPPORT */
  363. #ifdef AC3_SUPPORT
  364. case SLIB_TYPE_AC3_AUDIO:
  365. slibSetMaxInput(Info, 1000*1024);
  366. if ((srcpin=slibLoadPin(Info, SLIB_DATA_AUDIO))==NULL)
  367. {
  368. Info->AudioStreams = 0;
  369. _SlibDebug(_DEBUG_ || _WARN_,
  370. printf("SlibUpdateAudioInfo() no audio data found\n") );
  371. slibSetMaxInput(Info, 0);
  372. return;
  373. }
  374. /* buf = slibGetBufferFromPin(Info, srcpin, &size, NULL); */
  375. /* Search for AC-3 sync word */
  376. buf = slibSearchBuffersOnPin(Info, srcpin, NULL, &size,
  377. AC3_SYNC_WORD_REV, AC3_SYNC_WORD_LEN/8, FALSE);
  378. slibSetMaxInput(Info, 0);
  379. if (buf)
  380. {
  381. slibParseAC3Header(Info, srcpin, buf, size,
  382. &channels, &sps, &bps);
  383. if (Info->AudioBitRate>100)
  384. Info->AudioLength = (qword)(Info->FileSize*80L)/
  385. (qword)(Info->AudioBitRate/100);
  386. }
  387. else
  388. {
  389. slibRemovePin(Info, SLIB_DATA_AUDIO);
  390. return;
  391. }
  392. Info->AudioType=SLIB_TYPE_AC3_AUDIO;
  393. break;
  394. #endif /* AC3_SUPPORT */
  395. #ifdef G723_SUPPORT
  396. case SLIB_TYPE_G723:
  397. slibSetMaxInput(Info, 1000*1024);
  398. if ((srcpin=slibLoadPin(Info, SLIB_DATA_AUDIO))==NULL)
  399. {
  400. Info->AudioStreams = 0;
  401. _SlibDebug(_DEBUG_ || _WARN_,
  402. printf("SlibUpdateAudioInfo() no audio data found\n") );
  403. slibSetMaxInput(Info, 0);
  404. return;
  405. }
  406. slibSetMaxInput(Info, 0);
  407. buf = slibPeekBufferOnPin(Info, srcpin, &size, NULL);
  408. if (buf)
  409. {
  410. /* we need to parse the G.723 frame header to
  411. * get the actual bitrate
  412. */
  413. if(buf[0] & 0x1) /* read the rate bit in the G.723 frame header */
  414. Info->AudioBitRate=5333;
  415. else
  416. Info->AudioBitRate=6400;
  417. if (Info->AudioBitRate>0)
  418. Info->AudioLength = (qword)(Info->FileSize*80L)/
  419. (qword)(Info->AudioBitRate/100);
  420. }
  421. else
  422. {
  423. slibRemovePin(Info, SLIB_DATA_AUDIO);
  424. return;
  425. }
  426. //Initialize some info
  427. sps = 8000;
  428. bps = 16;
  429. channels =1;
  430. Info->AudioType=SLIB_TYPE_G723;
  431. break;
  432. #endif /*G723_SUPPORT*/
  433. default:
  434. return;
  435. }
  436. }
  437. Info->AudioStreams = 1;
  438. if (SlibTypeHasTimeStamps(Info->Type))
  439. {
  440. ptime=slibGetNextTimeOnPin(Info, slibGetPin(Info, SLIB_DATA_AUDIO), 100*1024);
  441. if (SlibTimeIsValid(ptime))
  442. Info->AudioPTimeBase=ptime;
  443. }
  444. /* round sample rate to nearest valid rate */
  445. if (sps<=8000)
  446. sps=8000;
  447. else if (sps<=11025)
  448. sps=11025;
  449. else if (sps<=22050)
  450. sps=22050;
  451. else if (sps<=32000)
  452. sps=32000;
  453. else if (sps<=44100)
  454. sps=44100;
  455. Info->SamplesPerSec = sps;
  456. Info->BitsPerSample = bps;
  457. Info->Channels = channels;
  458. if (Info->CompAudioFormat==NULL)
  459. Info->CompAudioFormat=(WAVEFORMATEX *)ScAlloc(sizeof(WAVEFORMATEX));
  460. if (Info->CompAudioFormat!=NULL)
  461. {
  462. Info->CompAudioFormat->wFormatTag = WAVE_FORMAT_PCM;
  463. Info->CompAudioFormat->nChannels = (WORD)channels;
  464. Info->CompAudioFormat->wBitsPerSample = (WORD)bps;
  465. Info->CompAudioFormat->nSamplesPerSec = sps;
  466. Info->CompAudioFormat->nBlockAlign = bps>>3 * channels;
  467. Info->CompAudioFormat->nAvgBytesPerSec =
  468. Info->CompAudioFormat->nBlockAlign * sps;
  469. }
  470. if (Info->AudioFormat==NULL)
  471. Info->AudioFormat=(WAVEFORMATEX *)ScAlloc(sizeof(WAVEFORMATEX));
  472. if (Info->AudioFormat!=NULL)
  473. {
  474. Info->AudioFormat->wFormatTag = WAVE_FORMAT_PCM;
  475. Info->AudioFormat->nChannels = (WORD)channels;
  476. Info->AudioFormat->wBitsPerSample = (WORD)bps;
  477. Info->AudioFormat->nSamplesPerSec = sps;
  478. Info->AudioFormat->nBlockAlign = (bps>>3) * channels;
  479. Info->AudioFormat->nAvgBytesPerSec =
  480. Info->AudioFormat->nBlockAlign * sps;
  481. }
  482. }
  483. SlibTime_t slibSkipAudio(SlibInfo_t *Info, SlibStream_t stream,
  484. SlibTime_t timems)
  485. {
  486. dword timeskipped=0, samples=0, frames=0;
  487. SlibPin_t *srcpin;
  488. if (Info->AudioStreams<=0)
  489. return(0);
  490. srcpin=slibLoadPin(Info, SLIB_DATA_AUDIO);
  491. if (!srcpin)
  492. return(0);
  493. _SlibDebug(_VERBOSE_, printf("slibSkipAudio(stream=%d, %d ms)\n",
  494. stream,timems) );
  495. switch (Info->AudioType)
  496. {
  497. #ifdef MPEG_SUPPORT
  498. case SLIB_TYPE_MPEG1_AUDIO:
  499. {
  500. unsigned char *buf, *bufstart;
  501. unsigned dword size, sps, channels, layer;
  502. static const int layer_samples[4] = {384, 384, 1152, 1152};
  503. static const int mpeg_freq[4] = {44100, 48000, 32000, 0};
  504. while (timeskipped<timems)
  505. {
  506. do {
  507. bufstart=buf=slibSearchBuffersOnPin(Info, srcpin, NULL, &size,
  508. 0xFF, 1, TRUE);
  509. _SlibDebug(_WARN_ && size==0, printf("SkipAudio() size=0\n"));
  510. if (!bufstart)
  511. return(timeskipped);
  512. if ((buf[0]&0xF0)==0xF0 && buf[0]!=0xFF)
  513. break;
  514. else
  515. slibInsertBufferOnPin(srcpin, buf, size, SLIB_TIME_NONE);
  516. } while (1);
  517. frames++;
  518. layer = 4-((*buf>>1) & 0x03);
  519. buf++; size--;
  520. if (!size)
  521. {
  522. SlibFreeBuffer(bufstart);
  523. bufstart=buf=slibGetBufferFromPin(Info, srcpin, &size, NULL);
  524. if (!bufstart)
  525. return(timeskipped);
  526. }
  527. sps = mpeg_freq[(*buf>>2) & 0x03];
  528. buf++; size--;
  529. if (!size)
  530. {
  531. SlibFreeBuffer(bufstart);
  532. bufstart=buf=slibGetBufferFromPin(Info, srcpin, &size, NULL);
  533. if (!bufstart)
  534. return(timeskipped);
  535. }
  536. channels = (*buf >> 6)==3 ? 1 : 2;
  537. buf++; size--;
  538. samples+=layer_samples[layer];
  539. if (sps)
  540. timeskipped=(1000*samples)/sps;
  541. _SlibDebug(_DEBUG_,
  542. printf("samples=%d timeskipped=%d\n", samples, timeskipped));
  543. if (size)
  544. {
  545. SlibAllocSubBuffer(buf, size);
  546. slibInsertBufferOnPin(srcpin, buf, size, SLIB_TIME_NONE);
  547. }
  548. SlibFreeBuffer(bufstart);
  549. }
  550. }
  551. break;
  552. #endif /* MPEG_SUPPORT */
  553. #ifdef AC3_SUPPORT
  554. case SLIB_TYPE_AC3_AUDIO:
  555. /* For better audio/video synchronization - add Dolby AC-3 support here */
  556. break;
  557. #endif /* AC3_SUPPORT */
  558. default:
  559. break;
  560. }
  561. _SlibDebug(_VERBOSE_,
  562. printf("slibSkipAudio() frames=%d samples=%d timeskipped=%d ms\n",
  563. frames, samples, timeskipped));
  564. return(timeskipped);
  565. }
  566. SlibStatus_t slibValidateAudioParams(SlibInfo_t *Info)
  567. {
  568. return(SlibErrorNone);
  569. }