mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-04 13:10:15 +00:00
8167028: SunCodec.java can be removed
Reviewed-by: prr, amenkov
This commit is contained in:
parent
d55a3a75b1
commit
2cf11bb58d
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -30,25 +30,26 @@ import java.util.Objects;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioFormat.Encoding;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.spi.FormatConversionProvider;
|
||||
|
||||
/**
|
||||
* A-law encodes linear data, and decodes a-law data to linear data.
|
||||
*
|
||||
* @author Kara Kytle
|
||||
*/
|
||||
public final class AlawCodec extends SunCodec {
|
||||
public final class AlawCodec extends FormatConversionProvider {
|
||||
|
||||
/* Tables used for A-law decoding */
|
||||
|
||||
private static final byte[] ALAW_TABH = new byte[256];
|
||||
private static final byte[] ALAW_TABL = new byte[256];
|
||||
|
||||
private static final AudioFormat.Encoding[] alawEncodings = { AudioFormat.Encoding.ALAW, AudioFormat.Encoding.PCM_SIGNED };
|
||||
|
||||
private static final short seg_end [] = {0xFF, 0x1FF, 0x3FF,
|
||||
0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF};
|
||||
private static final short seg_end[] = {
|
||||
0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes the decode tables.
|
||||
@ -73,13 +74,14 @@ public final class AlawCodec extends SunCodec {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AudioFormat.Encoding[] getSourceEncodings() {
|
||||
return new Encoding[]{Encoding.ALAW, Encoding.PCM_SIGNED};
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ALAW codec object.
|
||||
*/
|
||||
public AlawCodec() {
|
||||
|
||||
super(alawEncodings, alawEncodings);
|
||||
@Override
|
||||
public AudioFormat.Encoding[] getTargetEncodings() {
|
||||
return getSourceEncodings();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -562,8 +562,7 @@ public final class AudioFloatFormatConverter extends FormatConversionProvider {
|
||||
|
||||
@Override
|
||||
public Encoding[] getTargetEncodings() {
|
||||
return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
|
||||
Encoding.PCM_FLOAT };
|
||||
return getSourceEncodings();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -30,32 +30,26 @@ import java.util.Objects;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioFormat.Encoding;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.spi.FormatConversionProvider;
|
||||
|
||||
/**
|
||||
* Converts among signed/unsigned and little/big endianness of sampled.
|
||||
*
|
||||
* @author Jan Borgersen
|
||||
*/
|
||||
public final class PCMtoPCMCodec extends SunCodec {
|
||||
public final class PCMtoPCMCodec extends FormatConversionProvider {
|
||||
|
||||
private static final AudioFormat.Encoding[] inputEncodings = {
|
||||
AudioFormat.Encoding.PCM_SIGNED,
|
||||
AudioFormat.Encoding.PCM_UNSIGNED,
|
||||
};
|
||||
@Override
|
||||
public AudioFormat.Encoding[] getSourceEncodings() {
|
||||
return new Encoding[]{Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED};
|
||||
}
|
||||
|
||||
private static final AudioFormat.Encoding[] outputEncodings = {
|
||||
AudioFormat.Encoding.PCM_SIGNED,
|
||||
AudioFormat.Encoding.PCM_UNSIGNED,
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructs a new PCMtoPCM codec object.
|
||||
*/
|
||||
public PCMtoPCMCodec() {
|
||||
|
||||
super( inputEncodings, outputEncodings);
|
||||
@Override
|
||||
public AudioFormat.Encoding[] getTargetEncodings() {
|
||||
return getSourceEncodings();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.media.sound;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.spi.FormatConversionProvider;
|
||||
|
||||
/**
|
||||
* A codec can encode and/or decode audio data. It provides an
|
||||
* AudioInputStream from which processed data may be read.
|
||||
* <p>
|
||||
* Its input format represents the format of the incoming
|
||||
* audio data, or the format of the data in the underlying stream.
|
||||
* <p>
|
||||
* Its output format represents the format of the processed, outgoing
|
||||
* audio data. This is the format of the data which may be read from
|
||||
* the filtered stream.
|
||||
*
|
||||
* @author Kara Kytle
|
||||
*/
|
||||
abstract class SunCodec extends FormatConversionProvider {
|
||||
|
||||
private final AudioFormat.Encoding[] inputEncodings;
|
||||
private final AudioFormat.Encoding[] outputEncodings;
|
||||
|
||||
/**
|
||||
* Constructs a new codec object.
|
||||
*/
|
||||
SunCodec(final AudioFormat.Encoding[] inputEncodings,
|
||||
final AudioFormat.Encoding[] outputEncodings) {
|
||||
this.inputEncodings = inputEncodings;
|
||||
this.outputEncodings = outputEncodings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final AudioFormat.Encoding[] getSourceEncodings() {
|
||||
AudioFormat.Encoding[] encodings = new AudioFormat.Encoding[inputEncodings.length];
|
||||
System.arraycopy(inputEncodings, 0, encodings, 0, inputEncodings.length);
|
||||
return encodings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final AudioFormat.Encoding[] getTargetEncodings() {
|
||||
AudioFormat.Encoding[] encodings = new AudioFormat.Encoding[outputEncodings.length];
|
||||
System.arraycopy(outputEncodings, 0, encodings, 0, outputEncodings.length);
|
||||
return encodings;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -30,26 +30,26 @@ import java.util.Objects;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioFormat.Encoding;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.spi.FormatConversionProvider;
|
||||
|
||||
/**
|
||||
* U-law encodes linear data, and decodes u-law data to linear data.
|
||||
*
|
||||
* @author Kara Kytle
|
||||
*/
|
||||
public final class UlawCodec extends SunCodec {
|
||||
public final class UlawCodec extends FormatConversionProvider {
|
||||
|
||||
/* Tables used for U-law decoding */
|
||||
|
||||
private static final byte[] ULAW_TABH = new byte[256];
|
||||
private static final byte[] ULAW_TABL = new byte[256];
|
||||
|
||||
private static final AudioFormat.Encoding[] ulawEncodings = {AudioFormat.Encoding.ULAW,
|
||||
AudioFormat.Encoding.PCM_SIGNED};
|
||||
|
||||
private static final short seg_end [] = {0xFF, 0x1FF, 0x3FF,
|
||||
0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF};
|
||||
private static final short seg_end[] = {
|
||||
0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes the decode tables.
|
||||
@ -69,11 +69,14 @@ public final class UlawCodec extends SunCodec {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ULAW codec object.
|
||||
*/
|
||||
public UlawCodec() {
|
||||
super(ulawEncodings, ulawEncodings);
|
||||
@Override
|
||||
public AudioFormat.Encoding[] getSourceEncodings() {
|
||||
return new Encoding[]{Encoding.ULAW, Encoding.PCM_SIGNED};
|
||||
}
|
||||
|
||||
@Override
|
||||
public AudioFormat.Encoding[] getTargetEncodings() {
|
||||
return getSourceEncodings();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,7 +25,7 @@
|
||||
|
||||
package javax.sound.sampled.spi;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
@ -81,16 +81,8 @@ public abstract class FormatConversionProvider {
|
||||
* {@code false}
|
||||
* @throws NullPointerException if {@code sourceEncoding} is {@code null}
|
||||
*/
|
||||
public boolean isSourceEncodingSupported(Encoding sourceEncoding) {
|
||||
Objects.requireNonNull(sourceEncoding);
|
||||
Encoding sourceEncodings[] = getSourceEncodings();
|
||||
|
||||
for(int i=0; i<sourceEncodings.length; i++) {
|
||||
if( sourceEncoding.equals( sourceEncodings[i]) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public boolean isSourceEncodingSupported(final Encoding sourceEncoding) {
|
||||
return Stream.of(getSourceEncodings()).anyMatch(sourceEncoding::equals);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,16 +95,8 @@ public abstract class FormatConversionProvider {
|
||||
* {@code false}
|
||||
* @throws NullPointerException if {@code targetEncoding} is {@code null}
|
||||
*/
|
||||
public boolean isTargetEncodingSupported(Encoding targetEncoding) {
|
||||
Objects.requireNonNull(targetEncoding);
|
||||
Encoding targetEncodings[] = getTargetEncodings();
|
||||
|
||||
for(int i=0; i<targetEncodings.length; i++) {
|
||||
if( targetEncoding.equals( targetEncodings[i]) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public boolean isTargetEncodingSupported(final Encoding targetEncoding) {
|
||||
return Stream.of(getTargetEncodings()).anyMatch(targetEncoding::equals);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,17 +121,10 @@ public abstract class FormatConversionProvider {
|
||||
* @throws NullPointerException if {@code targetEncoding} or
|
||||
* {@code sourceFormat} are {@code null}
|
||||
*/
|
||||
public boolean isConversionSupported(Encoding targetEncoding,
|
||||
AudioFormat sourceFormat) {
|
||||
Objects.requireNonNull(targetEncoding);
|
||||
Encoding targetEncodings[] = getTargetEncodings(sourceFormat);
|
||||
|
||||
for(int i=0; i<targetEncodings.length; i++) {
|
||||
if( targetEncoding.equals( targetEncodings[i]) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public boolean isConversionSupported(final Encoding targetEncoding,
|
||||
final AudioFormat sourceFormat) {
|
||||
return Stream.of(getTargetEncodings(sourceFormat))
|
||||
.anyMatch(targetEncoding::equals);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,17 +152,11 @@ public abstract class FormatConversionProvider {
|
||||
* @throws NullPointerException if {@code targetFormat} or
|
||||
* {@code sourceFormat} are {@code null}
|
||||
*/
|
||||
public boolean isConversionSupported(AudioFormat targetFormat,
|
||||
AudioFormat sourceFormat) {
|
||||
|
||||
AudioFormat targetFormats[] = getTargetFormats( targetFormat.getEncoding(), sourceFormat );
|
||||
|
||||
for(int i=0; i<targetFormats.length; i++) {
|
||||
if( targetFormat.matches( targetFormats[i] ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public boolean isConversionSupported(final AudioFormat targetFormat,
|
||||
final AudioFormat sourceFormat) {
|
||||
final Encoding targetEncoding = targetFormat.getEncoding();
|
||||
return Stream.of(getTargetFormats(targetEncoding, sourceFormat))
|
||||
.anyMatch(targetFormat::matches);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user