Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ public MediaRecorder(Path file) throws IOException {
* @throws IOException If the file cannot be written, or is a directory.
*/
public MediaRecorder(Path file, boolean overwrite) throws IOException {
this(file, overwrite, NativeApi.tableAddress());
}

/**
* Creates a recorder writing to the given file that takes its frames and
* its clock from the given webrtc-java function table, as the tests do.
*/
MediaRecorder(Path file, boolean overwrite, long tableAddress) throws IOException {
Objects.requireNonNull(file, "File is null");

Path target = file.toAbsolutePath();
Expand All @@ -229,7 +237,7 @@ public MediaRecorder(Path file, boolean overwrite) throws IOException {
this.output = overwrite ? createTemporaryFile(target) : Files.createFile(target);

try {
this.handle = create(output.toString(), NativeApi.tableAddress());
this.handle = create(output.toString(), tableAddress);
}
catch (IOException | RuntimeException | Error e) {
deleteOutput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ final class FakeTrack implements AutoCloseable {
static final int DELTA_FRAME_SIZE = 1000;
static final int AUDIO_FRAME_SIZE = 100;

/** 20 ms of G.711, one byte a sample. */
static final int G711_FRAME_SIZE = 160;

private static int nextSsrc = 1000;

private final long frames;
Expand Down Expand Up @@ -100,6 +103,15 @@ static FakeTrack opus() {
return new FakeTrack(false, "audio/opus", 48000);
}

/**
* @param mimeType "audio/PCMU" or "audio/PCMA".
*
* @return A G.711 track.
*/
static FakeTrack g711(String mimeType) {
return new FakeTrack(false, mimeType, 8000);
}

boolean isVideo() {
return video;
}
Expand Down Expand Up @@ -245,7 +257,7 @@ else if (keyFrameIn > 0) {
pushed++;
}

byte[] data = video ? videoPayload(codec, key) : audioPayload();
byte[] data = video ? videoPayload(codec, key) : audioPayload(codec);

FakeMedia.push(frames, video, codec, ssrc, rtpTimestamp, key, key ? WIDTH : 0, key ? HEIGHT : 0, timeUs,
data);
Expand Down Expand Up @@ -297,9 +309,14 @@ private static byte[] videoPayload(String codec, boolean key) {
}

/**
* An Opus packet of one 20 ms CELT frame, mono (RFC 6716, section 3.1).
* An Opus packet of one 20 ms CELT frame, mono (RFC 6716, section 3.1),
* or 20 ms of G.711, every byte of which is a sample.
*/
private static byte[] audioPayload() {
private static byte[] audioPayload(String codec) {
if (!codec.equals("audio/opus")) {
return new byte[G711_FRAME_SIZE];
}

byte[] data = new byte[AUDIO_FRAME_SIZE];

data[0] = (byte) 0xF8;
Expand Down
Loading
Loading