Skip to content
This repository has been archived by the owner on Feb 9, 2018. It is now read-only.

Commit

Permalink
Fix for issue 1194: remove 50 MB minimum buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
Raptor399 committed Aug 26, 2011
1 parent f3e213e commit 94407df
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions ps3mediaserver/net/pms/io/BufferedOutputFileImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ private byte[] growBuffer(byte[] buffer, int newSize) {
// Try to allocate the requested new size
copy = new byte[newSize];
} catch (OutOfMemoryError e) {
logger.debug("Cannot grow buffer size from " + buffer.length + " bytes to " + newSize + " bytes."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (buffer.length == 0) {
logger.trace("Cannot initialize buffer to " + formatter.format(newSize) + " bytes."); //$NON-NLS-1$ //$NON-NLS-2$
} else {
logger.debug("Cannot grow buffer size from " + formatter.format(buffer.length) + " bytes to " + formatter.format(newSize) + " bytes."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

}

// Could not allocate the requested new size, use 30% of free memory instead.
// Rationale behind using 30%: multiple threads are running at the same time,
Expand Down Expand Up @@ -168,12 +173,6 @@ public BufferedOutputFileImpl(OutputParams params) {
this.minMemorySize = (int) (1048576 * params.minBufferSize);
this.maxMemorySize = (int) (1048576 * params.maxBufferSize);

// Enforce the minimum transcoding buffer size
if (maxMemorySize < INITIAL_BUFFER_SIZE) {
maxMemorySize = INITIAL_BUFFER_SIZE;
minMemorySize = INITIAL_BUFFER_SIZE / 2;
}

// FIXME: Better to relate margin directly to maxMemorySize instead of using arbitrary fixed values

int margin = MARGIN_LARGE; // Issue 220: extends to 20Mb : readCount is wrongly set cause of the ps3's
Expand All @@ -190,8 +189,13 @@ public BufferedOutputFileImpl(OutputParams params) {
this.timeend = params.timeend;
this.shiftScr = params.shift_scr;

// Allocate the buffer
buffer = growBuffer(null, maxMemorySize);
if (maxMemorySize > INITIAL_BUFFER_SIZE) {
// Try to limit memory usage a bit.
// Start with a modest allocation initially, grow to max when needed later.
buffer = growBuffer(null, INITIAL_BUFFER_SIZE);
} else {
buffer = growBuffer(null, maxMemorySize);
}

if (buffer.length == 0) {
// Cannot transcode without a buffer
Expand Down

0 comments on commit 94407df

Please sign in to comment.