Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for RTSP PCM/WAV and G711/WAV #56

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Modify RtpPcmReader
Rename a few variable to be more relevant
Add detailed java docs
  • Loading branch information
basantwanishraddha committed Mar 28, 2022
commit 500c879b8ac5f04e2708550d45d3f7179284fa6c
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,23 @@ public static String getMimeTypeFromRtpMediaType(String mediaType) {
}

/**
* 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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;

Expand Down Expand Up @@ -103,8 +103,9 @@ public int hashCode() {
}

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;
Expand All @@ -131,8 +132,7 @@ public int hashCode() {
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public RtpPayloadReader createPayloadReader(RtpPayloadFormat payloadFormat) {
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.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@
* 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
Expand All @@ -62,9 +63,9 @@ public void consume(
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);
}
Expand Down