331 :(char **)outBuffer withFrameCount:(size_t *)outSize
332{
333 char *buffer = NULL, *dst;
334 size_t sizeInFrames = 0;
335 int remaining;
336 long framesRead;
337
338 int frameSize = [self isStereo] ? 4 : 2;
339 ogg_int64_t totalSizeInFrames;
340 BOOL OK = YES;
341
342 if (NULL != outBuffer) *outBuffer = NULL;
343 if (NULL != outSize) *outSize = 0;
344 if (NULL == outBuffer || NULL == outSize) OK = NO;
345
346 if (OK)
347 {
348 totalSizeInFrames = ov_pcm_total(&
_vf, -1);
349 assert ((uint64_t)totalSizeInFrames < (uint64_t)SIZE_MAX);
350 sizeInFrames = (size_t)totalSizeInFrames;
351 }
352
353 if (OK)
354 {
355 buffer = malloc(sizeof (char) * frameSize * sizeInFrames);
356 if (!buffer) OK = NO;
357 }
358
359 if (OK && sizeInFrames)
360 {
361 remaining = (
int)
MIN(frameSize * sizeInFrames, (
size_t)INT_MAX);
362 dst = buffer;
363
364 char pcmout[4096];
365
366 do
367 {
368 int toRead = sizeof(pcmout);
369 if (remaining < toRead)
370 {
371 toRead = remaining;
372 }
373 framesRead = ov_read(&
_vf, pcmout, toRead, 0, 2, 1, NULL);
374 if (framesRead <= 0)
375 {
376 if (OV_HOLE == framesRead) continue;
377
378 break;
379 }
380
381 memcpy(dst, &pcmout, sizeof (char) * framesRead);
382
383 remaining -= framesRead;
384 dst += framesRead;
385 } while (0 < remaining);
386
387 sizeInFrames -= remaining;
388 }
389
390 if (OK)
391 {
392 *outBuffer = buffer;
393 *outSize = sizeInFrames*frameSize;
394 }
395 else
396 {
397 if (buffer) free(buffer);
398 }
399 return OK;
400}
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque