Program: 47086
Project: 47086
Buggy source:
/** 
 * Determine whether we are a candidate for streaming or transcoding to the given renderer, and return the relevant player or null as appropriate.
 * @param renderer The target renderer
 * @return A player if transcoding or null if streaming
 */
public Player resolvePlayer(RendererConfiguration renderer){
  PmsConfiguration configurationSpecificToRenderer=PMS.getConfiguration(renderer);
  boolean parserV2=media != null && renderer != null && renderer.isUseMediaInfo();
  Player resolvedPlayer=null;
  if (media == null) {
    media=new DLNAMediaInfo();
  }
  if (format == null) {
    Format f=FormatFactory.getAssociatedFormat(getSystemName());
    setFormat(f != null ? f : FormatFactory.getAssociatedFormat("String_Node_Str"));
  }
  if (isNoName() && (getParent() instanceof FileTranscodeVirtualFolder)) {
    resolvedPlayer=getPlayer();
    LOGGER.trace("String_Node_Str",resolvedPlayer);
    return resolvedPlayer;
  }
  boolean hasSubsToTranscode=false;
  boolean hasEmbeddedSubs=false;
  for (  DLNAMediaSubtitle s : media.getSubtitleTracksList()) {
    hasEmbeddedSubs=(hasEmbeddedSubs || s.isEmbedded());
  }
  if (format.isVideo() && !configurationSpecificToRenderer.isDisableSubtitles()) {
    if (hasEmbeddedSubs || hasExternalSubtitles()) {
      OutputParams params=new OutputParams(configurationSpecificToRenderer);
      Player.setAudioAndSubs(getSystemName(),media,params);
      if (params.sid != null) {
        if (params.sid.isExternal()) {
          if (renderer != null && renderer.isExternalSubtitlesFormatSupported(params.sid,media)) {
            media_subtitle=params.sid;
            media_subtitle.setSubsStreamable(true);
            LOGGER.trace("String_Node_Str");
          }
 else {
            hasSubsToTranscode=true;
            LOGGER.trace("String_Node_Str");
          }
        }
 else         if (params.sid.isEmbedded()) {
          if (renderer != null && renderer.isEmbeddedSubtitlesFormatSupported(params.sid)) {
            LOGGER.trace("String_Node_Str");
          }
 else {
            hasSubsToTranscode=true;
            LOGGER.trace("String_Node_Str");
          }
        }
      }
    }
 else {
      LOGGER.trace("String_Node_Str");
    }
  }
  if (configurationSpecificToRenderer.isDisableTranscoding()) {
    LOGGER.trace("String_Node_Str",getName());
    return null;
  }
  String configurationSkipExtensions=configurationSpecificToRenderer.getDisableTranscodeForExtensions();
  String rendererSkipExtensions=renderer == null ? null : renderer.getStreamedExtensions();
  skipTranscode=format.skip(configurationSkipExtensions,rendererSkipExtensions);
  if (skipTranscode) {
    LOGGER.trace("String_Node_Str",getName());
    return null;
  }
  resolvedPlayer=PlayerFactory.getPlayer(this);
  if (resolvedPlayer != null) {
    String configurationForceExtensions=configurationSpecificToRenderer.getForceTranscodeForExtensions();
    String rendererForceExtensions=null;
    if (renderer != null) {
      rendererForceExtensions=renderer.getTranscodedExtensions();
    }
    boolean forceTranscode=format.skip(configurationForceExtensions,rendererForceExtensions);
    boolean isIncompatible=false;
    String audioTracksList=getName() + media.getAudioTracksList().toString();
    String prependTraceReason="String_Node_Str";
    if (forceTranscode) {
      LOGGER.trace(prependTraceReason + "String_Node_Str",getName());
    }
 else     if (!format.isCompatible(media,renderer)) {
      isIncompatible=true;
      LOGGER.trace(prependTraceReason + "String_Node_Str",getName());
    }
 else     if (configurationSpecificToRenderer.isEncodedAudioPassthrough() && (audioTracksList.contains("String_Node_Str") || audioTracksList.contains("String_Node_Str"))) {
      isIncompatible=true;
      LOGGER.trace(prependTraceReason + "String_Node_Str",getName());
    }
 else     if (format.isVideo() && parserV2 && renderer != null) {
      int maxBandwidth=renderer.getMaxBandwidth();
      if (renderer.isKeepAspectRatio() && !"String_Node_Str".equals(media.getAspectRatioContainer())) {
        isIncompatible=true;
        LOGGER.trace(prependTraceReason + "String_Node_Str",getName(),media.getAspectRatioContainer());
      }
 else       if (!renderer.isResolutionCompatibleWithRenderer(media.getWidth(),media.getHeight())) {
        isIncompatible=true;
        LOGGER.trace(prependTraceReason + "String_Node_Str",getName());
      }
 else       if (media.getBitrate() > maxBandwidth) {
        isIncompatible=true;
        LOGGER.trace(prependTraceReason + "String_Node_Str",getName(),media.getBitrate(),maxBandwidth);
      }
 else       if (!renderer.isVideoBitDepthSupported(media.getVideoBitDepth())) {
        isIncompatible=true;
        LOGGER.trace(prependTraceReason + "String_Node_Str",getName(),media.getVideoBitDepth());
      }
 else       if (renderer.isH264Level41Limited() && media.isH264()) {
        if (media.getAvcLevel() != null) {
          double h264Level=4.1;
          try {
            h264Level=Double.parseDouble(media.getAvcLevel());
          }
 catch (          NumberFormatException e) {
            LOGGER.trace("String_Node_Str",media.getAvcLevel(),e.getMessage());
          }
          if (h264Level > 4.1) {
            isIncompatible=true;
            LOGGER.trace(prependTraceReason + "String_Node_Str",getName(),h264Level);
          }
        }
 else {
          isIncompatible=true;
          LOGGER.trace(prependTraceReason + "String_Node_Str",getName());
        }
      }
    }
    boolean preferTranscode=isIncompatible || hasSubsToTranscode;
    if (forceTranscode || (preferTranscode && !isSkipTranscode())) {
      if (parserV2) {
        LOGGER.trace("String_Node_Str",getName(),resolvedPlayer.toString(),renderer != null ? renderer.getMimeType(mimeType(resolvedPlayer),media) : media.getMimeType());
      }
 else {
        LOGGER.trace("String_Node_Str",getName(),resolvedPlayer.toString());
      }
    }
 else {
      resolvedPlayer=null;
      LOGGER.trace("String_Node_Str",getName());
    }
  }
 else {
    LOGGER.trace("String_Node_Str");
  }
  return resolvedPlayer;
}

Fixed version (ground truth):
/** 
 * Determine whether we are a candidate for streaming or transcoding to the given renderer, and return the relevant player or null as appropriate.
 * @param renderer The target renderer
 * @return A player if transcoding or null if streaming
 */
public Player resolvePlayer(RendererConfiguration renderer){
  PmsConfiguration configurationSpecificToRenderer=PMS.getConfiguration(renderer);
  boolean parserV2=media != null && renderer != null && renderer.isUseMediaInfo();
  Player resolvedPlayer=null;
  if (media == null) {
    media=new DLNAMediaInfo();
  }
  if (format == null) {
    Format f=FormatFactory.getAssociatedFormat(getSystemName());
    setFormat(f != null ? f : FormatFactory.getAssociatedFormat("String_Node_Str"));
  }
  if (isNoName() && (getParent() instanceof FileTranscodeVirtualFolder)) {
    resolvedPlayer=getPlayer();
    LOGGER.trace("String_Node_Str",resolvedPlayer);
    return resolvedPlayer;
  }
  boolean hasSubsToTranscode=false;
  boolean hasEmbeddedSubs=false;
  for (  DLNAMediaSubtitle s : media.getSubtitleTracksList()) {
    hasEmbeddedSubs=(hasEmbeddedSubs || s.isEmbedded());
  }
  if (format.isVideo() && !configurationSpecificToRenderer.isDisableSubtitles()) {
    if (hasEmbeddedSubs || hasExternalSubtitles()) {
      OutputParams params=new OutputParams(configurationSpecificToRenderer);
      Player.setAudioAndSubs(getSystemName(),media,params);
      if (params.sid != null) {
        if (params.sid.isExternal()) {
          if (renderer != null && renderer.isExternalSubtitlesFormatSupported(params.sid,media)) {
            media_subtitle=params.sid;
            media_subtitle.setSubsStreamable(true);
            LOGGER.trace("String_Node_Str");
          }
 else {
            hasSubsToTranscode=true;
            LOGGER.trace("String_Node_Str");
          }
        }
 else         if (params.sid.isEmbedded()) {
          if (renderer != null && renderer.isEmbeddedSubtitlesFormatSupported(params.sid)) {
            LOGGER.trace("String_Node_Str");
          }
 else {
            hasSubsToTranscode=true;
            LOGGER.trace("String_Node_Str");
          }
        }
      }
    }
 else {
      LOGGER.trace("String_Node_Str");
    }
  }
  if (configurationSpecificToRenderer.isDisableTranscoding()) {
    LOGGER.trace("String_Node_Str",getName());
    return null;
  }
  String configurationSkipExtensions=configurationSpecificToRenderer.getDisableTranscodeForExtensions();
  String rendererSkipExtensions=renderer == null ? null : renderer.getStreamedExtensions();
  skipTranscode=format.skip(configurationSkipExtensions,rendererSkipExtensions);
  if (skipTranscode) {
    LOGGER.trace("String_Node_Str",getName());
    return null;
  }
  resolvedPlayer=PlayerFactory.getPlayer(this);
  if (resolvedPlayer != null) {
    String configurationForceExtensions=configurationSpecificToRenderer.getForceTranscodeForExtensions();
    String rendererForceExtensions=null;
    if (renderer != null) {
      rendererForceExtensions=renderer.getTranscodedExtensions();
    }
    boolean forceTranscode=format.skip(configurationForceExtensions,rendererForceExtensions);
    boolean isIncompatible=false;
    String audioTracksList=getName() + media.getAudioTracksList().toString();
    String prependTraceReason="String_Node_Str";
    if (forceTranscode) {
      LOGGER.trace(prependTraceReason + "String_Node_Str",getName());
    }
 else     if (!format.isCompatible(media,renderer)) {
      isIncompatible=true;
      LOGGER.trace(prependTraceReason + "String_Node_Str",getName());
    }
 else     if (configurationSpecificToRenderer.isEncodedAudioPassthrough() && (audioTracksList.contains("String_Node_Str") || audioTracksList.contains("String_Node_Str"))) {
      isIncompatible=true;
      LOGGER.trace(prependTraceReason + "String_Node_Str",getName());
    }
 else     if (format.isVideo() && parserV2 && renderer != null) {
      int maxBandwidth=renderer.getMaxBandwidth();
      if (renderer.isKeepAspectRatio() && !"String_Node_Str".equals(media.getAspectRatioContainer())) {
        isIncompatible=true;
        LOGGER.trace(prependTraceReason + "String_Node_Str",getName(),media.getAspectRatioContainer());
      }
 else       if (!renderer.isResolutionCompatibleWithRenderer(media.getWidth(),media.getHeight())) {
        isIncompatible=true;
        LOGGER.trace(prependTraceReason + "String_Node_Str",getName());
      }
 else       if (media.getBitrate() > maxBandwidth) {
        isIncompatible=true;
        LOGGER.trace(prependTraceReason + "String_Node_Str",getName(),media.getBitrate(),maxBandwidth);
      }
 else       if (!renderer.isVideoBitDepthSupported(media.getVideoBitDepth())) {
        isIncompatible=true;
        LOGGER.trace(prependTraceReason + "String_Node_Str",getName(),media.getVideoBitDepth());
      }
 else       if (renderer.isH264Level41Limited() && media.isH264()) {
        if (media.getAvcLevel() != null) {
          double h264Level=4.1;
          try {
            h264Level=Double.parseDouble(media.getAvcLevel());
          }
 catch (          NumberFormatException e) {
            LOGGER.trace("String_Node_Str",media.getAvcLevel(),e.getMessage());
          }
          if (h264Level > 4.1) {
            isIncompatible=true;
            LOGGER.trace(prependTraceReason + "String_Node_Str",getName(),h264Level);
          }
        }
 else {
          isIncompatible=true;
          LOGGER.trace(prependTraceReason + "String_Node_Str",getName());
        }
      }
    }
    boolean preferTranscode=isIncompatible || hasSubsToTranscode;
    if (forceTranscode || (preferTranscode && !isSkipTranscode())) {
      if (parserV2) {
        LOGGER.trace("String_Node_Str",getName(),resolvedPlayer.toString(),renderer != null ? renderer.getMimeType(mimeType(resolvedPlayer),media) : media.getMimeType());
      }
 else {
        LOGGER.trace("String_Node_Str",getName(),resolvedPlayer.toString());
      }
    }
 else {
      resolvedPlayer=null;
      LOGGER.trace("String_Node_Str",getName());
    }
  }
 else {
    LOGGER.trace("String_Node_Str",getName());
  }
  return resolvedPlayer;
}