From ae9cee68f009f457ad54f2315635d17180e66b7d Mon Sep 17 00:00:00 2001 From: Thong Nguyen Date: Fri, 14 Feb 2014 22:06:46 +0000 Subject: [PATCH] Slightly better bitrate calculation for VBR files --- StreamingKit/StreamingKit/STKAudioPlayer.m | 2 +- StreamingKit/StreamingKit/STKQueueEntry.m | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/StreamingKit/StreamingKit/STKAudioPlayer.m b/StreamingKit/StreamingKit/STKAudioPlayer.m index 75c34b0..cb444ba 100644 --- a/StreamingKit/StreamingKit/STKAudioPlayer.m +++ b/StreamingKit/StreamingKit/STKAudioPlayer.m @@ -54,7 +54,7 @@ #define STK_DEFAULT_PCM_BUFFER_SIZE_IN_SECONDS (10) #define STK_DEFAULT_SECONDS_REQUIRED_TO_START_PLAYING (1) #define STK_DEFAULT_SECONDS_REQUIRED_TO_START_PLAYING_AFTER_BUFFER_UNDERRUN (7.5) -#define STK_MAX_COMPRESSED_PACKETS_FOR_BITRATE_CALCULATION (2048) +#define STK_MAX_COMPRESSED_PACKETS_FOR_BITRATE_CALCULATION (4096) #define STK_DEFAULT_READ_BUFFER_SIZE (64 * 1024) #define STK_DEFAULT_PACKET_BUFFER_SIZE (2048) diff --git a/StreamingKit/StreamingKit/STKQueueEntry.m b/StreamingKit/StreamingKit/STKQueueEntry.m index 0b7ab29..d4e4cbd 100644 --- a/StreamingKit/StreamingKit/STKQueueEntry.m +++ b/StreamingKit/StreamingKit/STKQueueEntry.m @@ -9,8 +9,8 @@ #import "STKQueueEntry.h" #import "STKDataSource.h" -#define STK_BIT_RATE_ESTIMATION_MIN_PACKETS_MIN (4) -#define STK_BIT_RATE_ESTIMATION_MIN_PACKETS_MAX (64) +#define STK_BIT_RATE_ESTIMATION_MIN_PACKETS_MIN (2) +#define STK_BIT_RATE_ESTIMATION_MIN_PACKETS_PREFERRED (64) @implementation STKQueueEntry @@ -39,15 +39,16 @@ { double retval; - if (packetDuration && - (processedPacketsCount > STK_BIT_RATE_ESTIMATION_MIN_PACKETS_MAX || (audioStreamBasicDescription.mBytesPerFrame == 0 - && processedPacketsCount > STK_BIT_RATE_ESTIMATION_MIN_PACKETS_MIN))) + if (packetDuration > 0) { - double averagePacketByteSize = processedPacketsSizeTotal / processedPacketsCount; - - retval = averagePacketByteSize / packetDuration * 8; - - return retval; + if (processedPacketsCount > STK_BIT_RATE_ESTIMATION_MIN_PACKETS_PREFERRED || (audioStreamBasicDescription.mBytesPerFrame == 0 && processedPacketsCount > STK_BIT_RATE_ESTIMATION_MIN_PACKETS_MIN)) + { + double averagePacketByteSize = processedPacketsSizeTotal / processedPacketsCount; + + retval = averagePacketByteSize / packetDuration * 8; + + return retval; + } } retval = (audioStreamBasicDescription.mBytesPerFrame * audioStreamBasicDescription.mSampleRate) * 8;