Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing bit-rate calculation, thus fixing 'duration' and 'progress' parameters for long files #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Classes/AudioStreamer.m
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,7 @@ - (double)calculatedBitRate
{
if (packetDuration && processedPacketsCount > BitRateEstimationMinPackets)
{
double averagePacketByteSize = processedPacketsSizeTotal / processedPacketsCount;
return 8.0 * averagePacketByteSize / packetDuration;
return processedPacketsSizeTotal / processedPacketsCount;
}

if (bitRate)
Expand Down Expand Up @@ -1730,7 +1729,7 @@ - (void)handleAudioPackets:(const void *)inInputData

if (processedPacketsCount < BitRateEstimationMaxPackets)
{
processedPacketsSizeTotal += packetSize;
processedPacketsSizeTotal += 8.0 * packetSize / packetDuration;
processedPacketsCount += 1;
}

Expand Down
17 changes: 14 additions & 3 deletions Classes/iPhoneStreamingPlayerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ - (void)updateProgress:(NSTimer *)updatedTimer
if (duration > 0)
{
[positionLabel setText:
[NSString stringWithFormat:@"Time Played: %.1f/%.1f seconds",
progress,
duration]];
[NSString stringWithFormat:@"Time Played: %@/%@",
[self stringFromTimeInterval:progress],
[self stringFromTimeInterval:duration]]];
[progressSlider setEnabled:YES];
[progressSlider setValue:100 * progress / duration];
}
Expand All @@ -287,6 +287,17 @@ - (void)updateProgress:(NSTimer *)updatedTimer
}
}

//
// To get the time formatted in HH:MM:SS format
// Takes a second value, and returns a formatted string
//
- (NSString *)stringFromTimeInterval:(CGFloat)interval {
NSInteger ti = (NSInteger)interval;
NSInteger seconds = ti % 60;
NSInteger minutes = (ti / 60) % 60;
NSInteger hours = (ti / 3600);
return [NSString stringWithFormat:@"%02ld:%02ld:%02ld", (long)hours, (long)minutes, (long)seconds];
}
//
// textFieldShouldReturn:
//
Expand Down