< prev index next >

src/java.desktop/share/classes/com/sun/media/sound/DirectAudioDevice.java

Print this page


   1 /*
   2  * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 530 
 531         @Override
 532         void implStart() {
 533             if (Printer.trace) Printer.trace(" >> DirectDL: implStart()");
 534 
 535             // check for record permission
 536             if (!isSource) {
 537                 JSSecurityManager.checkRecordPermission();
 538             }
 539 
 540             synchronized (lockNative)
 541             {
 542                 nStart(id, isSource);
 543             }
 544             // check for monitoring/servicing
 545             monitoring = requiresServicing();
 546             if (monitoring) {
 547                 getEventDispatcher().addLineMonitor(this);
 548             }
 549 

 550             doIO = true;
 551 
 552             // need to set Active and Started
 553             // note: the current API always requires that
 554             //       Started and Active are set at the same time...
 555             if (isSource && stoppedWritten) {
 556                 setStarted(true);
 557                 setActive(true);
 558             }

 559 
 560             if (Printer.trace) Printer.trace("<< DirectDL: implStart() succeeded");
 561         }
 562 
 563         @Override
 564         void implStop() {
 565             if (Printer.trace) Printer.trace(">> DirectDL: implStop()");
 566 
 567             // check for record permission
 568             if (!isSource) {
 569                 JSSecurityManager.checkRecordPermission();
 570             }
 571 
 572             if (monitoring) {
 573                 getEventDispatcher().removeLineMonitor(this);
 574                 monitoring = false;
 575             }
 576             synchronized (lockNative) {
 577                 nStop(id, isSource);
 578             }
 579             // wake up any waiting threads
 580             synchronized(lock) {
 581                 // need to set doIO to false before notifying the
 582                 // read/write thread, that's why isStartedRunning()
 583                 // cannot be used
 584                 doIO = false;
 585                 lock.notifyAll();
 586             }
 587             setActive(false);
 588             setStarted(false);


 589             stoppedWritten = false;
 590 
 591             if (Printer.trace) Printer.trace(" << DirectDL: implStop() succeeded");
 592         }
 593 
 594         @Override
 595         void implClose() {
 596             if (Printer.trace) Printer.trace(">> DirectDL: implClose()");
 597 
 598             // check for record permission
 599             if (!isSource) {
 600                 JSSecurityManager.checkRecordPermission();
 601             }
 602 
 603             // be sure to remove this monitor
 604             if (monitoring) {
 605                 getEventDispatcher().removeLineMonitor(this);
 606                 monitoring = false;
 607             }
 608 


 714         public int write(byte[] b, int off, int len) {
 715             flushing = false;
 716             if (len == 0) {
 717                 return 0;
 718             }
 719             if (len < 0) {
 720                 throw new IllegalArgumentException("illegal len: "+len);
 721             }
 722             if (len % getFormat().getFrameSize() != 0) {
 723                 throw new IllegalArgumentException("illegal request to write "
 724                                                    +"non-integral number of frames ("
 725                                                    +len+" bytes, "
 726                                                    +"frameSize = "+getFormat().getFrameSize()+" bytes)");
 727             }
 728             if (off < 0) {
 729                 throw new ArrayIndexOutOfBoundsException(off);
 730             }
 731             if ((long)off + (long)len > (long)b.length) {
 732                 throw new ArrayIndexOutOfBoundsException(b.length);
 733             }
 734 
 735             if (!isActive() && doIO) {
 736                 // this is not exactly correct... would be nicer
 737                 // if the native sub system sent a callback when IO really starts

 738                 setActive(true);
 739                 setStarted(true);
 740             }

 741             int written = 0;
 742             while (!flushing) {
 743                 int thisWritten;
 744                 synchronized (lockNative) {
 745                     thisWritten = nWrite(id, b, off, len,
 746                             softwareConversionSize,
 747                             leftGain, rightGain);
 748                     if (thisWritten < 0) {
 749                         // error in native layer
 750                         break;
 751                     }
 752                     bytePosition += thisWritten;
 753                     if (thisWritten > 0) {
 754                         drained = false;
 755                     }
 756                 }
 757                 len -= thisWritten;
 758                 written += thisWritten;
 759                 if (doIO && len > 0) {
 760                     off += thisWritten;


 940         public int read(byte[] b, int off, int len) {
 941             flushing = false;
 942             if (len == 0) {
 943                 return 0;
 944             }
 945             if (len < 0) {
 946                 throw new IllegalArgumentException("illegal len: "+len);
 947             }
 948             if (len % getFormat().getFrameSize() != 0) {
 949                 throw new IllegalArgumentException("illegal request to read "
 950                                                    +"non-integral number of frames ("
 951                                                    +len+" bytes, "
 952                                                    +"frameSize = "+getFormat().getFrameSize()+" bytes)");
 953             }
 954             if (off < 0) {
 955                 throw new ArrayIndexOutOfBoundsException(off);
 956             }
 957             if ((long)off + (long)len > (long)b.length) {
 958                 throw new ArrayIndexOutOfBoundsException(b.length);
 959             }

 960             if (!isActive() && doIO) {
 961                 // this is not exactly correct... would be nicer
 962                 // if the native sub system sent a callback when IO really starts

 963                 setActive(true);
 964                 setStarted(true);
 965             }

 966             int read = 0;
 967             while (doIO && !flushing) {
 968                 int thisRead;
 969                 synchronized (lockNative) {
 970                     thisRead = nRead(id, b, off, len, softwareConversionSize);
 971                     if (thisRead < 0) {
 972                         // error in native layer
 973                         break;
 974                     }
 975                     bytePosition += thisRead;
 976                     if (thisRead > 0) {
 977                         drained = false;
 978                     }
 979                 }
 980                 len -= thisRead;
 981                 read += thisRead;
 982                 if (len > 0) {
 983                     off += thisRead;
 984                     synchronized(lock) {
 985                         try {


   1 /*
   2  * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 530 
 531         @Override
 532         void implStart() {
 533             if (Printer.trace) Printer.trace(" >> DirectDL: implStart()");
 534 
 535             // check for record permission
 536             if (!isSource) {
 537                 JSSecurityManager.checkRecordPermission();
 538             }
 539 
 540             synchronized (lockNative)
 541             {
 542                 nStart(id, isSource);
 543             }
 544             // check for monitoring/servicing
 545             monitoring = requiresServicing();
 546             if (monitoring) {
 547                 getEventDispatcher().addLineMonitor(this);
 548             }
 549 
 550             synchronized(lock) {
 551                 doIO = true;

 552                 // need to set Active and Started
 553                 // note: the current API always requires that
 554                 //       Started and Active are set at the same time...
 555                 if (isSource && stoppedWritten) {
 556                     setStarted(true);
 557                     setActive(true);
 558                 }
 559             }
 560 
 561             if (Printer.trace) Printer.trace("<< DirectDL: implStart() succeeded");
 562         }
 563 
 564         @Override
 565         void implStop() {
 566             if (Printer.trace) Printer.trace(">> DirectDL: implStop()");
 567 
 568             // check for record permission
 569             if (!isSource) {
 570                 JSSecurityManager.checkRecordPermission();
 571             }
 572 
 573             if (monitoring) {
 574                 getEventDispatcher().removeLineMonitor(this);
 575                 monitoring = false;
 576             }
 577             synchronized (lockNative) {
 578                 nStop(id, isSource);
 579             }
 580             // wake up any waiting threads
 581             synchronized(lock) {
 582                 // need to set doIO to false before notifying the
 583                 // read/write thread, that's why isStartedRunning()
 584                 // cannot be used
 585                 doIO = false;


 586                 setActive(false);
 587                 setStarted(false);
 588                 lock.notifyAll();
 589             }
 590             stoppedWritten = false;
 591 
 592             if (Printer.trace) Printer.trace(" << DirectDL: implStop() succeeded");
 593         }
 594 
 595         @Override
 596         void implClose() {
 597             if (Printer.trace) Printer.trace(">> DirectDL: implClose()");
 598 
 599             // check for record permission
 600             if (!isSource) {
 601                 JSSecurityManager.checkRecordPermission();
 602             }
 603 
 604             // be sure to remove this monitor
 605             if (monitoring) {
 606                 getEventDispatcher().removeLineMonitor(this);
 607                 monitoring = false;
 608             }
 609 


 715         public int write(byte[] b, int off, int len) {
 716             flushing = false;
 717             if (len == 0) {
 718                 return 0;
 719             }
 720             if (len < 0) {
 721                 throw new IllegalArgumentException("illegal len: "+len);
 722             }
 723             if (len % getFormat().getFrameSize() != 0) {
 724                 throw new IllegalArgumentException("illegal request to write "
 725                                                    +"non-integral number of frames ("
 726                                                    +len+" bytes, "
 727                                                    +"frameSize = "+getFormat().getFrameSize()+" bytes)");
 728             }
 729             if (off < 0) {
 730                 throw new ArrayIndexOutOfBoundsException(off);
 731             }
 732             if ((long)off + (long)len > (long)b.length) {
 733                 throw new ArrayIndexOutOfBoundsException(b.length);
 734             }
 735             synchronized(lock) {
 736                 if (!isActive() && doIO) {
 737                     // this is not exactly correct... would be nicer
 738                     // if the native sub system sent a callback when IO really
 739                     // starts
 740                     setActive(true);
 741                     setStarted(true);
 742                 }
 743             }
 744             int written = 0;
 745             while (!flushing) {
 746                 int thisWritten;
 747                 synchronized (lockNative) {
 748                     thisWritten = nWrite(id, b, off, len,
 749                             softwareConversionSize,
 750                             leftGain, rightGain);
 751                     if (thisWritten < 0) {
 752                         // error in native layer
 753                         break;
 754                     }
 755                     bytePosition += thisWritten;
 756                     if (thisWritten > 0) {
 757                         drained = false;
 758                     }
 759                 }
 760                 len -= thisWritten;
 761                 written += thisWritten;
 762                 if (doIO && len > 0) {
 763                     off += thisWritten;


 943         public int read(byte[] b, int off, int len) {
 944             flushing = false;
 945             if (len == 0) {
 946                 return 0;
 947             }
 948             if (len < 0) {
 949                 throw new IllegalArgumentException("illegal len: "+len);
 950             }
 951             if (len % getFormat().getFrameSize() != 0) {
 952                 throw new IllegalArgumentException("illegal request to read "
 953                                                    +"non-integral number of frames ("
 954                                                    +len+" bytes, "
 955                                                    +"frameSize = "+getFormat().getFrameSize()+" bytes)");
 956             }
 957             if (off < 0) {
 958                 throw new ArrayIndexOutOfBoundsException(off);
 959             }
 960             if ((long)off + (long)len > (long)b.length) {
 961                 throw new ArrayIndexOutOfBoundsException(b.length);
 962             }
 963             synchronized(lock) {
 964                 if (!isActive() && doIO) {
 965                     // this is not exactly correct... would be nicer
 966                     // if the native sub system sent a callback when IO really
 967                     // starts
 968                     setActive(true);
 969                     setStarted(true);
 970                 }
 971             }
 972             int read = 0;
 973             while (doIO && !flushing) {
 974                 int thisRead;
 975                 synchronized (lockNative) {
 976                     thisRead = nRead(id, b, off, len, softwareConversionSize);
 977                     if (thisRead < 0) {
 978                         // error in native layer
 979                         break;
 980                     }
 981                     bytePosition += thisRead;
 982                     if (thisRead > 0) {
 983                         drained = false;
 984                     }
 985                 }
 986                 len -= thisRead;
 987                 read += thisRead;
 988                 if (len > 0) {
 989                     off += thisRead;
 990                     synchronized(lock) {
 991                         try {


< prev index next >