-
Notifications
You must be signed in to change notification settings - Fork 543
Add support for RTSP Mp4a-Latm #162
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
048aaf3
Add support for RTSP Mp4a-Latm
rakeshnitb 9648529
Fix review comment in RTP Mp4a-latm Reader
rakeshnitb 15f9655
Added Rtp Mp4a-Latm Reader Test
rakeshnitb 97afe69
Added support for CSD parsing in RTSP Mp4a-Latm Reader
rakeshnitb 4880057
Fix some more review comment in RTP Mp4a-Latm Reader
rakeshnitb 9f8d699
Fix review comment in CSD parsing of Mp4a-Latm Reader
rakeshnitb 0ac84fe
Fix review comment in mp4a-latm Reader
rakeshnitb ce98d6d
Fix review comment in CSD parsing of Mp4a-Latm
rakeshnitb ca5bab5
Fix review comment in mp4a-latm Reader
rakeshnitb cee05d3
Fix review comment in Mp4a-Latm reader
rakeshnitb a89ed98
Fix review comments in mp4a-latm reader and test
rakeshnitb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added Rtp Mp4a-Latm Reader Test
Change-Id: I0054e54183df0bb9370bf3fe7047076e285e1e8f
- Loading branch information
commit 15f9655e9f13b635f4aef73037ad7a9db565208b
There are no files selected for viewing
175 changes: 175 additions & 0 deletions
175
...exoplayer_rtsp/src/test/java/androidx/media3/exoplayer/rtsp/reader/RtpMp4aReaderTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
/* | ||
* Copyright 2022 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package androidx.media3.exoplayer.rtsp.reader; | ||
|
||
import static androidx.media3.common.util.Util.getBytesFromHexString; | ||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import androidx.media3.common.Format; | ||
import androidx.media3.common.MimeTypes; | ||
import androidx.media3.common.ParserException; | ||
import androidx.media3.common.util.ParsableByteArray; | ||
import androidx.media3.exoplayer.rtsp.RtpPacket; | ||
import androidx.media3.exoplayer.rtsp.RtpPayloadFormat; | ||
import androidx.media3.test.utils.FakeExtractorOutput; | ||
import androidx.media3.test.utils.FakeTrackOutput; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.primitives.Bytes; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.junit.MockitoJUnit; | ||
import org.mockito.junit.MockitoRule; | ||
|
||
/** Unit test for {@link RtpMp4aReader}. */ | ||
@RunWith(AndroidJUnit4.class) | ||
public final class RtpMp4aReaderTest { | ||
private static final byte[] FRAME_1_FRAGMENT_1_DATA = | ||
getBytesFromHexString("0102"); | ||
private static final RtpPacket FRAME_1_FRAGMENT_1 = | ||
new RtpPacket.Builder() | ||
.setTimestamp((int) 2599168056L) | ||
.setSequenceNumber(40289) | ||
.setMarker(false) | ||
.setPayloadData(Bytes.concat( | ||
/*payload size */ getBytesFromHexString("02"), FRAME_1_FRAGMENT_1_DATA)) | ||
.build(); | ||
private static final byte[] FRAME_1_FRAGMENT_2_DATA = | ||
getBytesFromHexString("030405"); | ||
private static final RtpPacket FRAME_1_FRAGMENT_2 = | ||
new RtpPacket.Builder() | ||
.setTimestamp((int) 2599168056L) | ||
.setSequenceNumber(40290) | ||
.setMarker(true) | ||
.setPayloadData(Bytes.concat( | ||
/*payload size */ getBytesFromHexString("03"), FRAME_1_FRAGMENT_2_DATA)) | ||
.build(); | ||
private static final byte[] FRAME_1_DATA = | ||
Bytes.concat(FRAME_1_FRAGMENT_1_DATA, FRAME_1_FRAGMENT_2_DATA); | ||
|
||
private static final byte[] FRAME_2_FRAGMENT_1_DATA = | ||
getBytesFromHexString("0607"); | ||
private static final RtpPacket FRAME_2_FRAGMENT_1 = | ||
new RtpPacket.Builder() | ||
.setTimestamp((int) 2599168344L) | ||
.setSequenceNumber(40291) | ||
.setMarker(false) | ||
.setPayloadData(Bytes.concat( | ||
/*payload size */ getBytesFromHexString("02"), FRAME_2_FRAGMENT_1_DATA)) | ||
.build(); | ||
private static final byte[] FRAME_2_FRAGMENT_2_DATA = | ||
getBytesFromHexString("0809"); | ||
private static final RtpPacket FRAME_2_FRAGMENT_2 = | ||
new RtpPacket.Builder() | ||
.setTimestamp((int) 2599168344L) | ||
.setSequenceNumber(40292) | ||
.setMarker(true) | ||
.setPayloadData(Bytes.concat( | ||
/*payload size */ getBytesFromHexString("02"), FRAME_2_FRAGMENT_2_DATA)) | ||
.build(); | ||
private static final byte[] FRAME_2_DATA = | ||
Bytes.concat(FRAME_2_FRAGMENT_1_DATA, FRAME_2_FRAGMENT_2_DATA); | ||
|
||
private static final RtpPayloadFormat MP4ALATM_FORMAT = | ||
new RtpPayloadFormat( | ||
new Format.Builder() | ||
.setSampleMimeType(MimeTypes.AUDIO_AAC) | ||
.setWidth(352) | ||
rakeshnitb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.setHeight(288) | ||
.build(), | ||
/* rtpPayloadType= */ 96, | ||
/* clockRate= */ 90_000, | ||
rakeshnitb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/* fmtpParameters= */ ImmutableMap.of(), RtpPayloadFormat.RTP_MEDIA_MPEG4_AUDIO); | ||
|
||
@Rule public final MockitoRule mockito = MockitoJUnit.rule(); | ||
rakeshnitb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private FakeTrackOutput trackOutput; | ||
|
||
private FakeExtractorOutput extractorOutput; | ||
|
||
@Before | ||
public void setUp() { | ||
extractorOutput = new FakeExtractorOutput(); | ||
} | ||
|
||
@Test | ||
public void consume_validPackets() throws ParserException { | ||
RtpMp4aReader mp4aLatmReader = new RtpMp4aReader(MP4ALATM_FORMAT); | ||
mp4aLatmReader.createTracks(extractorOutput, /* trackId= */ 0); | ||
mp4aLatmReader.onReceivingFirstPacket( | ||
FRAME_1_FRAGMENT_1.timestamp, FRAME_1_FRAGMENT_1.sequenceNumber); | ||
consume(mp4aLatmReader, FRAME_1_FRAGMENT_1); | ||
consume(mp4aLatmReader, FRAME_1_FRAGMENT_2); | ||
consume(mp4aLatmReader, FRAME_2_FRAGMENT_1); | ||
consume(mp4aLatmReader, FRAME_2_FRAGMENT_2); | ||
|
||
trackOutput = extractorOutput.trackOutputs.get(0); | ||
assertThat(trackOutput.getSampleCount()).isEqualTo(2); | ||
assertThat(trackOutput.getSampleData(0)).isEqualTo(FRAME_1_DATA); | ||
assertThat(trackOutput.getSampleTimeUs(0)).isEqualTo(0); | ||
assertThat(trackOutput.getSampleData(1)).isEqualTo(FRAME_2_DATA); | ||
assertThat(trackOutput.getSampleTimeUs(1)).isEqualTo(3200); | ||
} | ||
|
||
@Test | ||
public void consume_fragmentedFrameMissingFirstFragment() throws ParserException { | ||
RtpMp4aReader mp4aLatmReader = new RtpMp4aReader(MP4ALATM_FORMAT); | ||
mp4aLatmReader.createTracks(extractorOutput, /* trackId= */ 0); | ||
mp4aLatmReader.onReceivingFirstPacket( | ||
FRAME_1_FRAGMENT_1.timestamp, FRAME_1_FRAGMENT_1.sequenceNumber); | ||
consume(mp4aLatmReader, FRAME_1_FRAGMENT_2); | ||
consume(mp4aLatmReader, FRAME_2_FRAGMENT_1); | ||
consume(mp4aLatmReader, FRAME_2_FRAGMENT_2); | ||
|
||
trackOutput = extractorOutput.trackOutputs.get(0); | ||
assertThat(trackOutput.getSampleCount()).isEqualTo(2); | ||
assertThat(trackOutput.getSampleData(0)).isEqualTo(FRAME_1_FRAGMENT_2_DATA); | ||
assertThat(trackOutput.getSampleTimeUs(0)).isEqualTo(0); | ||
assertThat(trackOutput.getSampleData(1)).isEqualTo(FRAME_2_DATA); | ||
assertThat(trackOutput.getSampleTimeUs(1)).isEqualTo(3200); | ||
} | ||
|
||
@Test | ||
public void consume_fragmentedFrameMissingBoundaryFragment() throws ParserException { | ||
RtpMp4aReader mp4aLatmReader = new RtpMp4aReader(MP4ALATM_FORMAT); | ||
mp4aLatmReader.createTracks(extractorOutput, /* trackId= */ 0); | ||
mp4aLatmReader.onReceivingFirstPacket( | ||
FRAME_1_FRAGMENT_1.timestamp, FRAME_1_FRAGMENT_1.sequenceNumber); | ||
consume(mp4aLatmReader, FRAME_1_FRAGMENT_1); | ||
consume(mp4aLatmReader, FRAME_2_FRAGMENT_1); | ||
consume(mp4aLatmReader, FRAME_2_FRAGMENT_2); | ||
|
||
trackOutput = extractorOutput.trackOutputs.get(0); | ||
assertThat(trackOutput.getSampleCount()).isEqualTo(2); | ||
assertThat(trackOutput.getSampleData(0)).isEqualTo(FRAME_1_FRAGMENT_1_DATA); | ||
assertThat(trackOutput.getSampleTimeUs(0)).isEqualTo(0); | ||
assertThat(trackOutput.getSampleData(1)).isEqualTo(FRAME_2_DATA); | ||
assertThat(trackOutput.getSampleTimeUs(1)).isEqualTo(3200); | ||
} | ||
|
||
private static void consume(RtpMp4aReader mpeg4Reader, RtpPacket rtpPacket) | ||
throws ParserException { | ||
ParsableByteArray packetData = new ParsableByteArray(); | ||
packetData.reset(rtpPacket.payloadData); | ||
mpeg4Reader.consume( | ||
packetData, | ||
rtpPacket.timestamp, | ||
rtpPacket.sequenceNumber, | ||
/* isFrameBoundary= */ rtpPacket.marker); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.