status_t MediaOutputInfo::CreateBufferGroup() { bufferPeriod = ComputeBufferPeriod(); if (bufferGroup == 0) { int32 count = int32(downstreamLatency/bufferPeriod)+2; fprintf(stderr," downstream latency = %lld, buffer period = %lld, buffer count = %i\n", downstreamLatency,bufferPeriod,count); // allocate the buffers bufferGroup = new BBufferGroup(ComputeBufferSize(),count); if (bufferGroup == 0) { fprintf(stderr,"<- B_NO_MEMORY\n"); return B_NO_MEMORY; } status_t status = bufferGroup->InitCheck(); if (status != B_OK) { fprintf(stderr,"<- BufferGroup initialization failed\n"); BBufferGroup * group = bufferGroup; bufferGroup = 0; delete group; return status; } } return B_OK; }
// returns result in # of microseconds bigtime_t MediaOutputInfo::ComputeBufferPeriod(const media_format & format) { bigtime_t bufferPeriod = 25*1000; // default 25 milliseconds switch (format.type) { case B_MEDIA_MULTISTREAM: // given a buffer size of 8192 bytes // and a bitrate of 1024 kilobits/millisecond (= 128 bytes/millisecond) // we need to produce a buffer every 64 milliseconds (= every 64000 microseconds) bufferPeriod = bigtime_t(1000.0 * 8.0 * ComputeBufferSize(format) / format.u.multistream.max_bit_rate); break; case B_MEDIA_ENCODED_VIDEO: bufferPeriod = bigtime_t(1000.0 * 8.0 * ComputeBufferSize(format) / format.u.encoded_video.max_bit_rate); break; case B_MEDIA_ENCODED_AUDIO: bufferPeriod = bigtime_t(1000.0 * 8.0 * ComputeBufferSize(format) / format.u.encoded_audio.bit_rate); break; case B_MEDIA_RAW_VIDEO: // Given a field rate of 50.00 fields per second, (PAL) // we need to generate a field/buffer // every 1/50 of a second = 20000 microseconds. bufferPeriod = bigtime_t(1000000.0 / format.u.raw_video.field_rate); break; case B_MEDIA_RAW_AUDIO: // Given a sample size of 4 bytes [B_AUDIO_INT] // and a channel count of 2 and a buffer_size // of 256 bytes and a frame_rate of 44100 Hertz (1/sec) // 1 frame = 1 sample/channel. // comes to ?? // this is a guess: bufferPeriod = bigtime_t(1000000.0 * ComputeBufferSize(format) / (format.u.raw_audio.format & media_raw_audio_format::B_AUDIO_SIZE_MASK) / format.u.raw_audio.channel_count / format.u.raw_audio.frame_rate); break; default: break; } return bufferPeriod; }
dng_simple_image::dng_simple_image (const dng_rect &bounds, uint32 planes, uint32 pixelType, dng_memory_allocator &allocator) : dng_image (bounds, planes, pixelType) , fMemory () , fAllocator (allocator) { uint32 bytes = ComputeBufferSize (pixelType, bounds.Size (), planes, pad16Bytes); fMemory.Reset (allocator.Allocate (bytes)); fBuffer = dng_pixel_buffer (bounds, 0, planes, pixelType, pcInterleaved, fMemory->Buffer ()); }
uint32 MediaOutputInfo::ComputeBufferSize() { return ComputeBufferSize(output.format); }