Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4671382

the Mixer.getTargetLineInfo() method returns Line.Info for source line

XMLWordPrintable

    • 1.4.1
    • generic
    • generic



      Name: abR10010 Date: 04/19/2002



      The specification for the Mixer.getTargetLineInfo() from the javax.sound.sampled
      package says:

      "
      ...
      Obtains information about the set of target lines supported by this mixer.
      ...
      "


      However the test (see below) shows the Mixer.getTargetLineInfo() method returns
      a Line.Info object for which there is no supported target line but there is
      a source line. It is revealed for the one of installed on the system mixers.

      Please note that the source line matching the returned Line.Info object matches
      also a Line.Info object returned by the Mixer.getSourceLineInfo() method.

      But the returned (by the Mixer.getTargetLineInfo()) Line.Info object itself is not
      contained in the array returned by the Mixer.getSourceLineInfo() method.

      It is possible that nevertheless there is a corresponding target line but
      the Mixer.getLine(Line.Info) method doesn't see it.

      Such behavior is shown by the test running with JDK 1.4.1-beta-b08.


      Please, see test log:

      % java -version
      java version "1.4.1-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b08)
      Java HotSpot(TM) Client VM (build 1.4.1-beta-b08, mixed mode)

      % java test

      ==> Test for Mixer.getSourceLineInfo() and Mixer.getTargetLineInfo() methods:

      >>> installedMixersInfo.length = 3

      >>> testedMixer[0] = com.sun.media.sound.HeadspaceMixer@80f4cb

      >> supportedSourceLineInfo.length = 2

      > testSourceLineInfo[0] =
              interface SourceDataLine supporting 8 audio formats@26281671
      > testSourceLine =
              com.sun.media.sound.MixerSourceLine@913fe2
      > testSourceLine.getLineInfo() =
              interface SourceDataLine supporting 8 audio formats@26281671

      > testSourceLineInfo[1] =
              interface Clip supporting 8 audio formats, and buffers of 0 to 4194304 bytes@33109165
      > testSourceLine =
              com.sun.media.sound.MixerClip@e94e92
      > testSourceLine.getLineInfo() =
              interface Clip supporting 8 audio formats, and buffers of 0 to 4194304 bytes@33109165

      >> supportedTargetLineInfo.length = 1

      > testTargetLineInfo[0] =
              interface DataLine supporting 22 audio formats@19224790
      > testTargetLine =
              com.sun.media.sound.MixerSourceLine@eb7859
      > testTargetLine.getLineInfo() =
              interface SourceDataLine supporting 8 audio formats@26281671
      ## Mixer.getTargetLineInfo() FAILED:
      # returned Line.Info object is NOT Line.Info for target line

      >>> testedMixer[1] = com.sun.media.sound.SimpleInputDevice@12a54f9

      >> supportedSourceLineInfo.length = 0

      >> supportedTargetLineInfo.length = 1

      > testTargetLineInfo[0] =
              interface TargetDataLine supporting 60 audio formats@3203712
      > testTargetLine =
              com.sun.media.sound.SimpleInputDevice$InputDeviceDataLine@1ccb029
      > testTargetLine.getLineInfo() =
              interface TargetDataLine supporting 60 audio formats@3203712

      >>> testedMixer[2] = com.sun.media.sound.SimpleOutputDevice@1415de6

      >> supportedSourceLineInfo.length = 1

      > testSourceLineInfo[0] =
              interface SourceDataLine supporting 24 audio formats@8116722
      > testSourceLine =
              com.sun.media.sound.SimpleOutputDevice$OutputDeviceDataLine@1e893df
      > testSourceLine.getLineInfo() =
              interface SourceDataLine supporting 24 audio formats@8116722

      >> supportedTargetLineInfo.length = 0

      ==> test FAILED!
       
       
      The test source:
      ------------------------------- test.java --------------------------------
      // File: %Z%%M% %I% %E%
      // Copyright %G% Sun Microsystems, Inc. All Rights Reserved

      import javax.sound.sampled.*;

      public class test {

          static final int STATUS_PASSED = 0;
          static final int STATUS_FAILED = 2;
          static final int STATUS_TEMP = 95;
          
          public static void main(String argv[]) {
              int testExitStatus = run(argv, System.out) + STATUS_TEMP;
              System.exit(testExitStatus);
          }

          public static int run(String argv[], java.io.PrintStream out) {
              int testResult = STATUS_PASSED;
          
              out.println
                  ("==> Test for Mixer.getSourceLineInfo() and Mixer.getTargetLineInfo() methods:");

              Mixer.Info[] installedMixersInfo = AudioSystem.getMixerInfo();
          
              if ( installedMixersInfo == null ) {
                  out.println("## AudioSystem.getMixerInfo() returned unexpected result:");
                  out.println
                      ("# expected: an array of Mixer.Info objects (may be array of length 0);");
                  out.println("# produced: null;");
                  return STATUS_FAILED;
              }

              if ( installedMixersInfo.length == 0 ) {
                  out.println(">> there are no mixers installed on the system");
                  return STATUS_PASSED;
              }

              out.println("\n>>> installedMixersInfo.length = " + installedMixersInfo.length);
              Mixer testedMixer = null;
              for (int i=0; i < installedMixersInfo.length; i++) {
                  try {
                      testedMixer = AudioSystem.getMixer(installedMixersInfo[i]);
                  } catch (SecurityException securityException) {
                      // installed Mixer is unavailable because of security restrictions
                      continue;
                  } catch (Throwable thrown) {
                      out.println("## AudioSystem.getMixer() threw unexpected exception:");
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                      continue;
                  }

                  out.println("\n>>> testedMixer[" + i + "] = " + testedMixer);
                  try {
                      testedMixer.open();
                  } catch (LineUnavailableException lineUnavailableException) {
                      // testedMixer is not available due to resource restrictions
                      continue;
                  } catch (SecurityException securityException) {
                      // testedMixer is not available due to security restrictions
                      continue;
                  } catch (Throwable thrown) {
                      out.println("## Mixer.open() threw unexpected exception:");
                      out.println("# Mixer = " + testedMixer);
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                      continue;
                  }

                  while ( true ) { // test block for source lines

                  Line.Info supportedSourceLineInfo[] = null;
                  try {
                      supportedSourceLineInfo = testedMixer.getSourceLineInfo();
                  } catch (Throwable thrown) {
                      out.println("## Mixer.getSourceLineInfo() threw unexpected exception:");
                      out.println("# Mixer = " + testedMixer);
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                      testedMixer.close();
                      break;
                  }
                  if ( supportedSourceLineInfo == null ) {
                      out.println("## Mixer.getSourceLineInfo() returned null array");
                      out.println("# Mixer = " + testedMixer);
                      testResult = STATUS_FAILED;
                      testedMixer.close();
                      break;
                  }

                  out.println("\n>> supportedSourceLineInfo.length = " + supportedSourceLineInfo.length);
                  for (int j=0; j < supportedSourceLineInfo.length; j++) {
                      Line.Info testSourceLineInfo = supportedSourceLineInfo[j];
                      if ( testSourceLineInfo == null ) {
                          out.println("## Mixer.getSourceLineInfo() returned array with null Line.Info object!");
                          out.println("# Mixer = " + testedMixer);
                          testResult = STATUS_FAILED;
                          continue;
                      }

                      out.println("\n> testSourceLineInfo[" + j + "] = \n "
                          + testSourceLineInfo + "@" + testSourceLineInfo.hashCode());
                      Line testSourceLine = null;
                      try {
                          testSourceLine = testedMixer.getLine(testSourceLineInfo);
                      } catch (LineUnavailableException lineUnavailableException) {
                          // line is not available due to resource restrictions
                          break;
                      } catch (SecurityException securityException) {
                          // line is not available due to security restrictions
                          break;
                      } catch (Throwable thrown) {
                          out.println("## Mixer.getLine(Line.Info) threw unexpected Exception:");
                          out.println("# Mixer = " + testedMixer);
                          out.println("# Line.Info = " + testSourceLineInfo);
                          thrown.printStackTrace(out);
                          testResult = STATUS_FAILED;
                          break;
                      }

                      out.println("> testSourceLine = \n " + testSourceLine);
                      out.println("> testSourceLine.getLineInfo() = \n "
                          + testSourceLine.getLineInfo() + "@" + testSourceLine.getLineInfo().hashCode());
                      boolean isSourceLine = false;
                      if ( (testSourceLine instanceof SourceDataLine) ) {
                          // it is OK for source line
                          isSourceLine = true;
                      }
                      if ( (testSourceLine instanceof Port) ) {
                          // it is OK for source line
                          isSourceLine = true;
                      }
                      if ( (testSourceLine instanceof Clip) ) {
                          // it is OK for source line
                          isSourceLine = true;
                      }
                      if ( ! isSourceLine ) {
                          out.println("\n## Mixer.getSourceLineInfo() FAILED:");
                          out.println("# returned Line.Info object is NOT Line.Info for source line");
                          testResult = STATUS_FAILED;
                      }
                  } // for (int j=0; j < supportedSourceLineInfo.length; j++)
                  break;

                  } // while ( true ) { // test block for source lines


                  // test block for target lines
                  Line.Info supportedTargetLineInfo[] = null;
                  try {
                      supportedTargetLineInfo = testedMixer.getTargetLineInfo();
                  } catch (Throwable thrown) {
                      out.println("## Mixer.getTargetLineInfo() threw unexpected exception:");
                      out.println("# Mixer = " + testedMixer);
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                      testedMixer.close();
                      continue;
                  }
                  if ( supportedTargetLineInfo == null ) {
                      out.println("## Mixer.getTargetLineInfo() returned null array");
                      out.println("# Mixer = " + testedMixer);
                      testResult = STATUS_FAILED;
                      testedMixer.close();
                      continue;
                  }

                  out.println("\n>> supportedTargetLineInfo.length = " + supportedTargetLineInfo.length);
                  for (int j=0; j < supportedTargetLineInfo.length; j++) {
                      Line.Info testTargetLineInfo = supportedTargetLineInfo[j];
                      if ( testTargetLineInfo == null ) {
                          out.println("## Mixer.getTargetLineInfo() returned array with null Line.Info object!");
                          out.println("# Mixer = " + testedMixer);
                          testResult = STATUS_FAILED;
                          continue;
                      }

                      out.println("\n> testTargetLineInfo[" + j + "] = \n "
                          + testTargetLineInfo + "@" + testTargetLineInfo.hashCode());
                      Line testTargetLine = null;
                      try {
                          testTargetLine = testedMixer.getLine(testTargetLineInfo);
                      } catch (LineUnavailableException lineUnavailableException) {
                          // line is not available due to resource restrictions
                          break;
                      } catch (SecurityException securityException) {
                          // line is not available due to security restrictions
                          break;
                      } catch (Throwable thrown) {
                          out.println("## Mixer.getLine(Line.Info) threw unexpected Exception:");
                          out.println("# Mixer = " + testedMixer);
                          out.println("# Line.Info = " + testTargetLineInfo);
                          thrown.printStackTrace(out);
                          testResult = STATUS_FAILED;
                          break;
                      }

                      out.println("> testTargetLine = \n " + testTargetLine);
                      out.println("> testTargetLine.getLineInfo() = \n "
                          + testTargetLine.getLineInfo() + "@" + testTargetLine.getLineInfo().hashCode());
                      boolean isTargetLine = false;
                      if ( (testTargetLine instanceof TargetDataLine) ) {
                          // it is OK for target line
                          isTargetLine = true;
                      }
                      if ( (testTargetLine instanceof Port) ) {
                          // it is OK for target line
                          isTargetLine = true;
                      }
                      if ( ! isTargetLine ) {
                          out.println("## Mixer.getTargetLineInfo() FAILED:");
                          out.println("# returned Line.Info object is NOT Line.Info for target line");
                          testResult = STATUS_FAILED;
                      }
                  } // for (int j=0; j < supportedTargetLineInfo.length; j++)

                  testedMixer.close();
                  
              } // for (int i=0; i < installedMixersInfo.length; i++)

              if ( testResult == STATUS_FAILED ) {
                  out.println("\n==> test FAILED!");
              } else {
                  out.println("\n==> test PASSED!");
              }
              return testResult;
          }
      } // end of test class
      -------------------------------------------------------------------------
       
      ======================================================================

            fbomerssunw Florian Bomers (Inactive)
            bondsunw Bond Bond (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: