Program: 47268
Project: 47268
Buggy source:
/** 
 * Returns an InputStream of this DLNAResource that starts at a given time, if possible. Very useful if video chapters are being used.
 * @param range
 * @param mediarenderer
 * @return The inputstream
 * @throws IOException
 */
public InputStream getInputStream(Range range,RendererConfiguration mediarenderer) throws IOException {
  LOGGER.trace("String_Node_Str" + range + "String_Node_Str"+ getName()+ "String_Node_Str"+ getPlayer());
  boolean timeseek_auto=false;
  int cbr_video_bitrate=mediarenderer.getCBRVideoBitrate();
  long low=range.isByteRange() && range.isStartOffsetAvailable() ? range.asByteRange().getStart() : 0;
  long high=range.isByteRange() && range.isEndLimitAvailable() ? range.asByteRange().getEnd() : -1;
  Range.Time timeRange=range.createTimeRange();
  if (getPlayer() != null && low > 0 && cbr_video_bitrate > 0) {
    int used_bit_rated=(int)((cbr_video_bitrate + 256) * 1024 / 8 * 1.04);
    if (low > used_bit_rated) {
      timeRange.setStart((double)(low / (used_bit_rated)));
      low=0;
      if (timeRange.getStartOrZero() > getMedia().getDurationInSeconds()) {
        return null;
      }
      int rewind_secs=mediarenderer.getByteToTimeseekRewindSeconds();
      timeRange.rewindStart(rewind_secs);
      timeseek_auto=true;
    }
  }
  if (getPlayer() == null && !isResume()) {
    if (this instanceof IPushOutput) {
      PipedOutputStream out=new PipedOutputStream();
      InputStream fis=new PipedInputStream(out);
      ((IPushOutput)this).push(out);
      if (low > 0) {
        fis.skip(low);
      }
      fis=wrap(fis,high,low);
      return fis;
    }
    InputStream fis;
    if (getFormat() != null && getFormat().isImage() && getMedia() != null && getMedia().getOrientation() > 1 && mediarenderer.isAutoRotateBasedOnExif()) {
      fis=ImagesUtil.getAutoRotateInputStreamImage(getInputStream(),getMedia().getOrientation());
      if (fis == null) {
        fis=getInputStream();
      }
    }
 else {
      fis=getInputStream();
    }
    if (fis != null) {
      if (low > 0) {
        fis.skip(low);
      }
      fis=wrap(fis,high,low);
      if (timeRange.getStartOrZero() > 0 && this instanceof RealFile) {
        fis.skip(MpegUtil.getPositionForTimeInMpeg(((RealFile)this).getFile(),(int)timeRange.getStartOrZero()));
      }
    }
    return fis;
  }
 else {
    OutputParams params=new OutputParams(configuration);
    params.aid=getMediaAudio();
    params.sid=getMediaSubtitle();
    params.header=getHeaders();
    params.mediaRenderer=mediarenderer;
    timeRange.limit(getSplitRange());
    params.timeseek=timeRange.getStartOrZero();
    params.timeend=timeRange.getEndOrZero();
    params.shift_scr=timeseek_auto;
    if (this instanceof IPushOutput) {
      params.stdin=(IPushOutput)this;
    }
    if (resume != null) {
      params.timeseek+=(long)(resume.getTimeOffset() / 1000);
      if (getPlayer() == null) {
        setPlayer(new ResumePlayer());
      }
    }
    LOGGER.debug("String_Node_Str" + externalProcess + "String_Node_Str"+ params.timeseek+ "String_Node_Str"+ getMedia()+ "String_Node_Str"+ getMedia().isMediaparsed()+ "String_Node_Str"+ getMedia().getDurationInSeconds());
    if (externalProcess == null || externalProcess.isDestroyed()) {
      LOGGER.info("String_Node_Str" + getName());
      externalProcess=getPlayer().launchTranscode(getSystemName(),this,getMedia(),params);
      if (params.waitbeforestart > 0) {
        LOGGER.trace("String_Node_Str",params.waitbeforestart);
        try {
          Thread.sleep(params.waitbeforestart);
        }
 catch (        InterruptedException e) {
          LOGGER.error(null,e);
        }
        LOGGER.trace("String_Node_Str" + params.waitbeforestart + "String_Node_Str");
      }
    }
 else     if (params.timeseek > 0 && getMedia() != null && getMedia().isMediaparsed() && getMedia().getDurationInSeconds() > 0) {
      LOGGER.debug("String_Node_Str" + params.timeseek + "String_Node_Str");
      params.minBufferSize=1;
      Runnable r=new Runnable(){
        @Override public void run(){
          externalProcess.stopProcess();
        }
      }
;
      new Thread(r,"String_Node_Str").start();
      ProcessWrapper newExternalProcess=getPlayer().launchTranscode(getSystemName(),this,getMedia(),params);
      try {
        Thread.sleep(1000);
      }
 catch (      InterruptedException e) {
        LOGGER.error(null,e);
      }
      if (newExternalProcess == null) {
        LOGGER.trace("String_Node_Str");
      }
      externalProcess=newExternalProcess;
    }
    if (externalProcess == null) {
      return null;
    }
    InputStream is=null;
    int timer=0;
    while (is == null && timer < 10) {
      is=externalProcess.getInputStream(low);
      timer++;
      if (is == null) {
        LOGGER.trace("String_Node_Str");
        try {
          Thread.sleep(500);
        }
 catch (        InterruptedException e) {
        }
      }
    }
    if (is == null && externalProcess != null && !externalProcess.isDestroyed()) {
      Runnable r=new Runnable(){
        @Override public void run(){
          LOGGER.trace("String_Node_Str");
          externalProcess.stopProcess();
        }
      }
;
      new Thread(r,"String_Node_Str").start();
    }
    return is;
  }
}

Fixed version (ground truth):
/** 
 * Returns an InputStream of this DLNAResource that starts at a given time, if possible. Very useful if video chapters are being used.
 * @param range
 * @param mediarenderer
 * @return The inputstream
 * @throws IOException
 */
public InputStream getInputStream(Range range,RendererConfiguration mediarenderer) throws IOException {
  LOGGER.trace("String_Node_Str" + range + "String_Node_Str"+ getName()+ "String_Node_Str"+ getPlayer());
  boolean timeseek_auto=false;
  int cbr_video_bitrate=mediarenderer.getCBRVideoBitrate();
  long low=range.isByteRange() && range.isStartOffsetAvailable() ? range.asByteRange().getStart() : 0;
  long high=range.isByteRange() && range.isEndLimitAvailable() ? range.asByteRange().getEnd() : -1;
  Range.Time timeRange=range.createTimeRange();
  if (getPlayer() != null && low > 0 && cbr_video_bitrate > 0) {
    int used_bit_rated=(int)((cbr_video_bitrate + 256) * 1024 / 8 * 1.04);
    if (low > used_bit_rated) {
      timeRange.setStart((double)(low / (used_bit_rated)));
      low=0;
      if (timeRange.getStartOrZero() > getMedia().getDurationInSeconds()) {
        return null;
      }
      int rewind_secs=mediarenderer.getByteToTimeseekRewindSeconds();
      timeRange.rewindStart(rewind_secs);
      timeseek_auto=true;
    }
  }
  if (getPlayer() == null && !isResume()) {
    if (this instanceof IPushOutput) {
      PipedOutputStream out=new PipedOutputStream();
      InputStream fis=new PipedInputStream(out);
      ((IPushOutput)this).push(out);
      if (low > 0) {
        fis.skip(low);
      }
      fis=wrap(fis,high,low);
      return fis;
    }
    InputStream fis;
    if (getFormat() != null && getFormat().isImage() && getMedia() != null && getMedia().getOrientation() > 1 && mediarenderer.isAutoRotateBasedOnExif()) {
      fis=ImagesUtil.getAutoRotateInputStreamImage(getInputStream(),getMedia().getOrientation());
      if (fis == null) {
        fis=getInputStream();
      }
    }
 else {
      fis=getInputStream();
    }
    if (fis != null) {
      if (low > 0) {
        fis.skip(low);
      }
      fis=wrap(fis,high,low);
      if (timeRange.getStartOrZero() > 0 && this instanceof RealFile) {
        fis.skip(MpegUtil.getPositionForTimeInMpeg(((RealFile)this).getFile(),(int)timeRange.getStartOrZero()));
      }
    }
    return fis;
  }
 else {
    OutputParams params=new OutputParams(configuration);
    params.aid=getMediaAudio();
    params.sid=getMediaSubtitle();
    params.header=getHeaders();
    params.mediaRenderer=mediarenderer;
    timeRange.limit(getSplitRange());
    params.timeseek=timeRange.getStartOrZero();
    params.timeend=timeRange.getEndOrZero();
    params.shift_scr=timeseek_auto;
    if (this instanceof IPushOutput) {
      params.stdin=(IPushOutput)this;
    }
    if (resume != null) {
      params.timeseek+=(long)(resume.getTimeOffset() / 1000);
      if (getPlayer() == null) {
        setPlayer(new ResumePlayer());
      }
    }
    if (externalProcess == null || externalProcess.isDestroyed()) {
      LOGGER.info("String_Node_Str" + getName());
      externalProcess=getPlayer().launchTranscode(getSystemName(),this,getMedia(),params);
      if (params.waitbeforestart > 0) {
        LOGGER.trace("String_Node_Str",params.waitbeforestart);
        try {
          Thread.sleep(params.waitbeforestart);
        }
 catch (        InterruptedException e) {
          LOGGER.error(null,e);
        }
        LOGGER.trace("String_Node_Str" + params.waitbeforestart + "String_Node_Str");
      }
    }
 else     if (params.timeseek > 0 && getMedia() != null && getMedia().isMediaparsed() && getMedia().getDurationInSeconds() > 0) {
      LOGGER.debug("String_Node_Str" + params.timeseek + "String_Node_Str");
      params.minBufferSize=1;
      Runnable r=new Runnable(){
        @Override public void run(){
          externalProcess.stopProcess();
        }
      }
;
      new Thread(r,"String_Node_Str").start();
      ProcessWrapper newExternalProcess=getPlayer().launchTranscode(getSystemName(),this,getMedia(),params);
      try {
        Thread.sleep(1000);
      }
 catch (      InterruptedException e) {
        LOGGER.error(null,e);
      }
      if (newExternalProcess == null) {
        LOGGER.trace("String_Node_Str");
      }
      externalProcess=newExternalProcess;
    }
    if (externalProcess == null) {
      return null;
    }
    InputStream is=null;
    int timer=0;
    while (is == null && timer < 10) {
      is=externalProcess.getInputStream(low);
      timer++;
      if (is == null) {
        LOGGER.trace("String_Node_Str");
        try {
          Thread.sleep(500);
        }
 catch (        InterruptedException e) {
        }
      }
    }
    if (is == null && externalProcess != null && !externalProcess.isDestroyed()) {
      Runnable r=new Runnable(){
        @Override public void run(){
          LOGGER.trace("String_Node_Str");
          externalProcess.stopProcess();
        }
      }
;
      new Thread(r,"String_Node_Str").start();
    }
    return is;
  }
}