1 2 Previous Next 20 Replies Latest reply: Jun 30, 2011 5:32 AM by 855587 Go to original post RSS
      • 15. Re: ERROR while querying ACM driver's information
        captfoss
        852584 wrote:
        but nothing have changed.
        shrug Unless your copyFile code is holding the lock on the file, then I don't see anything else in your code that could be causing the problem...
        • 16. Re: ERROR while querying ACM driver's information
          855587
          I've created a wav files manually with names 0.wav 1.wav and 2.wav. And executed this code:
              public static void main(String[] args) {
          
                  for (int i = 0; i < 3; i++) {
          
                      System.out.format("Try number %d\n", i);
          
                      File file = new File("D:\\Projects\\Test projects\\JMF ACM test\\" + Integer.toString(i) + ".wav");
          
                      DataSource ds;
                      try {
                          ds = javax.media.Manager.createDataSource(new MediaLocator("file:" + file.getPath()));
                      } catch (Exception e) {
                          System.err.format("Cannot create datasource %s \n", e);
                          return;
                      }
          
                      Format[] formats = new Format[1];
          
                      formats[0] = new AudioFormat(AudioFormat.ULAW_RTP, 8000, 8, 1);
          
                      ProcessorModel prm = new ProcessorModel(ds, formats, new ContentDescriptor(ContentDescriptor.RAW_RTP));
          
                      Processor processor;
          
                      try {
                          processor = Manager.createRealizedProcessor(prm);
                      } catch (Exception e) {
                          System.err.format("Cannot create processor %s \n", e);
                          return;
                      }
          
                      processor.stop();
                      processor.close();
          
                      try {
                          ds.stop();
                      } catch (IOException e) {
                          System.err.format("Error while stopping datasource %s \n", e);
                      }
          
                      ds.disconnect();
          
                      Object mutex = new Object();
          
                      synchronized (mutex) {
                          try {
                              mutex.wait(1000);
                          } catch (InterruptedException e) {
                              System.err.format("Thread interrupted, try number " + i + "\n");
                              return;
                          }
                      }
          
                      if (!file.delete()) {
                          System.err.format("Cannot delete temporary file, try number " + i + "\n");
                      }
          
                      System.out.format("Try end number %d\n", i);
                  }
              }
          I am getting following output:
          Try number 0
          Try end number 0
          Try number 1
          Try end number 1
          Try number 2
          Cannot delete temporary file, try number 1
          Cannot delete temporary file, try number 2
          Try end number 2
          
          Process finished with exit code 0
          What do you think about this?
          • 17. Re: ERROR while querying ACM driver's information
            captfoss
            852584 wrote:
            What do you think about this?
            Well, first... when you're debugging something, always use System.err.println for your debug statements. System.out is very bad for debugging purposes because there's no guarantee when/if a statement will appear in terms of processing. For instance, note that your debug output is in a weird ordering because you've mixed Out and Err. Use Err exclusively and it'll be easier to debug. That's general Java programming advice. I use System.out for logging and System.err. for debugging...

            Anyway... to further track down the problem, try scaling back the JMF usage of the files and then add it back iteratively... try the following debug plan.

            1) Comment out all of the JMF code so that your program does nothing but delete the files
            2) Comment out all of the processor code so JMF does nothing but create the datasource, connect to it (you'll need to add the command in manually for that), disconnect it, and then delete the file
            3) Try adding "processor.deallocate" both before xor (not a typo) after you close the processor...
            • 18. Re: ERROR while querying ACM driver's information
              855587
              1) Comment out all of the JMF code so that your program does nothing but delete the files
              App deleted all files successfully.
              2) Comment out all of the processor code so JMF does nothing but create the datasource, connect to it (you'll need to add the command in manually for that), disconnect it, and then delete the file
              App failed to delete any file.
              3) Try adding "processor.deallocate" both before xor (not a typo) after you close the processor...
              If app calling processor.deallocate() after closing processor - app stops responding.
              If app calling processor.deallocate() before closing processor - nothig changes (first file deleted, other not).
              • 19. Re: ERROR while querying ACM driver's information
                captfoss
                852584 wrote:
                2) Comment out all of the processor code so JMF does nothing but create the datasource, connect to it (you'll need to add the command in manually for that), disconnect it, and then delete the file
                App failed to delete any file.
                This suggests that the DataSource is the thing that's not shutting down the file operation properly... and you're shutting it down correctly, it seems, so I'm not sure what else you could do "fix" the problem.

                The only potential workaround would be to write your own DataSource that handles reading from the file directly... that way, you can make sure it shuts down correctly because you'll be the one coding it.
                • 20. Re: ERROR while querying ACM driver's information
                  855587
                  I've found a bug in Sun code... in com.sun.media.protocol.file.DataSource. When they trying get file content they do:
                              URLConnection urlC = url.openConnection();
                              try {
                                  contentType = urlC.getContentType();
                              } catch (Throwable t) {
                                  contentType = null;
                              }
                  They dont close an URLConnection!

                  There is my modified solution:
                              URLConnection urlC = url.openConnection();
                              try {
                                  contentType = urlC.getContentType();
                                  if (urlC.getInputStream() != null){
                                      urlC.getInputStream().close();
                                  }
                                  if (urlC.getOutputStream() != null){
                                      urlC.getOutputStream().close();
                                  }
                              } catch (Throwable t) {
                                  contentType = null;
                              }
                  After this modification everything works fine.
                  1 2 Previous Next