Modify RtpPcmReader
Rename a few variable to be more relevant Add detailed java docs
This commit is contained in:
parent
bfc1fb9aa7
commit
500c879b8a
@ -93,22 +93,23 @@ public final class RtpPayloadFormat {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PCM Encoding type for RAW track that is associated with the RTP media type.
|
||||
* Gets the PCM Encoding type for audio encoding of track.
|
||||
*
|
||||
* <p>For instance, RTP media type "L8" maps to {@link C.PcmEncoding#ENCODING_PCM_8BIT}.
|
||||
* <p>For instance, Audio encoding "L8" has 8 bits/sample and thus maps to
|
||||
* {@link C.PcmEncoding#ENCODING_PCM_8BIT}. Refer to RFC3551 Section 4.5 Table 1.
|
||||
*
|
||||
* @throws IllegalArgumentException When the media type is not supported/recognized.
|
||||
* @throws IllegalArgumentException When the audio encoding is not supported/recognized.
|
||||
*/
|
||||
public static int getPCMEncodingFromRtpMediaType(String mediaType) {
|
||||
switch (mediaType) {
|
||||
public static int getPcmEncodingFromAudioEncoding(String mediaEncoding) {
|
||||
switch (mediaEncoding) {
|
||||
case RTP_MEDIA_PCM_L8:
|
||||
// Refer to RFC3551#section-4.5.10
|
||||
// Refer to RFC3551 Section 4.5.10
|
||||
return C.ENCODING_PCM_8BIT;
|
||||
case RTP_MEDIA_PCM_L16:
|
||||
// Refer to RFC3551#section-4.5.11
|
||||
// Refer to RFC3551 Section 4.5.11
|
||||
return C.ENCODING_PCM_16BIT_BIG_ENDIAN;
|
||||
default:
|
||||
throw new IllegalArgumentException(mediaType);
|
||||
throw new IllegalArgumentException("Unsupported RAW Audio Encoding " + mediaEncoding);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static androidx.media3.common.util.Util.castNonNull;
|
||||
import static androidx.media3.exoplayer.rtsp.MediaDescription.MEDIA_TYPE_AUDIO;
|
||||
import static androidx.media3.exoplayer.rtsp.RtpPayloadFormat.getMimeTypeFromRtpMediaType;
|
||||
import static androidx.media3.exoplayer.rtsp.RtpPayloadFormat.getPCMEncodingFromRtpMediaType;
|
||||
import static androidx.media3.exoplayer.rtsp.RtpPayloadFormat.getPcmEncodingFromAudioEncoding;
|
||||
import static androidx.media3.exoplayer.rtsp.SessionDescription.ATTR_CONTROL;
|
||||
import static androidx.media3.extractor.NalUnitUtil.NAL_START_CODE;
|
||||
|
||||
@ -103,8 +103,9 @@ import com.google.common.collect.ImmutableMap;
|
||||
}
|
||||
|
||||
int rtpPayloadType = mediaDescription.rtpMapAttribute.payloadType;
|
||||
String mediaEncoding = mediaDescription.rtpMapAttribute.mediaEncoding;
|
||||
|
||||
String mimeType = getMimeTypeFromRtpMediaType(mediaDescription.rtpMapAttribute.mediaEncoding);
|
||||
String mimeType = getMimeTypeFromRtpMediaType(mediaEncoding);
|
||||
formatBuilder.setSampleMimeType(mimeType);
|
||||
|
||||
int clockRate = mediaDescription.rtpMapAttribute.clockRate;
|
||||
@ -131,8 +132,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
processH265FmtpAttribute(formatBuilder, fmtpParameters);
|
||||
break;
|
||||
case MimeTypes.AUDIO_RAW:
|
||||
int pcmEncoding =
|
||||
getPCMEncodingFromRtpMediaType(mediaDescription.rtpMapAttribute.mediaEncoding);
|
||||
int pcmEncoding = getPcmEncodingFromAudioEncoding(mediaEncoding);
|
||||
formatBuilder.setPcmEncoding(pcmEncoding);
|
||||
break;
|
||||
case MimeTypes.AUDIO_AC3:
|
||||
|
@ -43,7 +43,7 @@ import androidx.media3.exoplayer.rtsp.RtpPayloadFormat;
|
||||
case MimeTypes.AUDIO_RAW:
|
||||
case MimeTypes.AUDIO_ALAW:
|
||||
case MimeTypes.AUDIO_MLAW:
|
||||
return new RtpPCMReader(payloadFormat);
|
||||
return new RtpPcmReader(payloadFormat);
|
||||
default:
|
||||
// No supported reader, returning null.
|
||||
}
|
||||
|
@ -29,16 +29,17 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
* Parses byte stream carried on RTP packets, and extracts PCM frames. Refer to RFC3551 for more
|
||||
* details.
|
||||
*/
|
||||
/* package */ public final class RtpPCMReader implements RtpPayloadReader {
|
||||
/* package */ public final class RtpPcmReader implements RtpPayloadReader {
|
||||
|
||||
private final RtpPayloadFormat payloadFormat;
|
||||
private @MonotonicNonNull TrackOutput trackOutput;
|
||||
private long firstReceivedTimestamp;
|
||||
private long startTimeOffsetUs;
|
||||
|
||||
public RtpPCMReader(RtpPayloadFormat payloadFormat) {
|
||||
public RtpPcmReader(RtpPayloadFormat payloadFormat) {
|
||||
this.payloadFormat = payloadFormat;
|
||||
firstReceivedTimestamp = C.TIME_UNSET;
|
||||
startTimeOffsetUs = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,9 +63,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
trackOutput.sampleData(data, size);
|
||||
trackOutput
|
||||
.sampleMetadata(
|
||||
/* timeUs= */ sampleTimeUs,
|
||||
/* flags= */ C.BUFFER_FLAG_KEY_FRAME,
|
||||
/* size= */ size,
|
||||
sampleTimeUs,
|
||||
C.BUFFER_FLAG_KEY_FRAME,
|
||||
size,
|
||||
/* offset= */ 0,
|
||||
/* cryptoData= */ null);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user