Skip to content

Commit

Permalink
add setExtractor method
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Oct 22, 2024
1 parent 287313e commit f73fb36
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public abstract class BaseDecoder {
protected AtomicBoolean pause = new AtomicBoolean(false);
protected volatile boolean looped = false;
private final DecoderInterface decoderInterface;
private final Extractor extractor = new AndroidExtractor();
private Extractor extractor = new AndroidExtractor();

public BaseDecoder(DecoderInterface decoderInterface) {
this.decoderInterface = decoderInterface;
Expand Down Expand Up @@ -264,4 +264,12 @@ private boolean sleep(long sleepTime) {
return false;
}
}

public void setExtractor(Extractor extractor) {
this.extractor = extractor;
}

public Extractor getExtractor() {
return extractor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.pedro.encoder.Frame
import com.pedro.encoder.input.audio.GetMicrophoneData
import com.pedro.encoder.input.decoder.AudioDecoder
import com.pedro.encoder.input.decoder.DecoderInterface
import com.pedro.encoder.input.decoder.Extractor
import java.io.IOException

/**
Expand Down Expand Up @@ -125,6 +126,7 @@ class AudioFileSource(
val isStereo = audioDecoder.isStereo
val wasRunning = audioDecoder.isRunning
val audioDecoder = AudioDecoder(getMicrophoneData, audioDecoderInterface, decoderInterface)
audioDecoder.extractor = this.audioDecoder.extractor
if (!audioDecoder.initExtractor(context, uri)) throw IOException("Extraction failed")
if (sampleRate != audioDecoder.sampleRate) throw IOException("SampleRate must be the same that the previous file")
if (isStereo != audioDecoder.isStereo) throw IOException("Channels must be the same that the previous file")
Expand Down Expand Up @@ -161,4 +163,8 @@ class AudioFileSource(
}

fun isAudioDeviceEnabled(): Boolean = audioTrackPlayer?.playState == AudioTrack.PLAYSTATE_PLAYING

fun setExtractor(extractor: Extractor) {
audioDecoder.extractor = extractor
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.graphics.SurfaceTexture
import android.net.Uri
import android.view.Surface
import com.pedro.encoder.input.decoder.DecoderInterface
import com.pedro.encoder.input.decoder.Extractor
import com.pedro.encoder.input.decoder.VideoDecoder
import com.pedro.encoder.input.sources.OrientationForced
import java.io.IOException
Expand Down Expand Up @@ -96,6 +97,7 @@ class VideoFileSource(
val height = videoDecoder.height
val wasRunning = videoDecoder.isRunning
val videoDecoder = VideoDecoder(videoDecoderInterface, decoderInterface)
videoDecoder.extractor = this.videoDecoder.extractor
if (!videoDecoder.initExtractor(context, uri)) throw IOException("Extraction failed")
if (width != videoDecoder.width || height != videoDecoder.height) throw IOException("Resolution must be the same that the previous file")
this.videoDecoder.stop()
Expand All @@ -104,5 +106,9 @@ class VideoFileSource(
videoDecoder.prepareVideo(Surface(surfaceTexture))
videoDecoder.start()
}

fun setExtractor(extractor: Extractor) {
videoDecoder.extractor = extractor
}
}
}
11 changes: 11 additions & 0 deletions library/src/main/java/com/pedro/library/base/FromFileBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.pedro.encoder.input.decoder.AudioDecoderInterface;
import com.pedro.encoder.input.decoder.BaseDecoder;
import com.pedro.encoder.input.decoder.DecoderInterface;
import com.pedro.encoder.input.decoder.Extractor;
import com.pedro.encoder.input.decoder.VideoDecoder;
import com.pedro.encoder.input.decoder.VideoDecoderInterface;
import com.pedro.encoder.utils.CodecUtil;
Expand Down Expand Up @@ -673,6 +674,7 @@ private void resetVideoDecoder(IORunnable runnable) throws IOException {
int height = videoDecoder.getHeight();
boolean wasRunning = videoDecoder.isRunning();
VideoDecoder videoDecoder = new VideoDecoder(videoDecoderInterface, decoderInterface);
videoDecoder.setExtractor(this.videoDecoder.getExtractor());
runnable.run(videoDecoder);
if (width != videoDecoder.getWidth() || height != videoDecoder.getHeight()) throw new IOException("Resolution must be the same that the previous file");
this.videoDecoder.stop();
Expand All @@ -686,6 +688,7 @@ private void resetAudioDecoder(IORunnable runnable) throws IOException {
boolean isStereo = audioDecoder.isStereo();
boolean wasRunning = audioDecoder.isRunning();
AudioDecoder audioDecoder = new AudioDecoder(getMicrophoneData, audioDecoderInterface, decoderInterface);
audioDecoder.setExtractor(this.audioDecoder.getExtractor());
runnable.run(audioDecoder);
if (sampleRate != audioDecoder.getSampleRate()) throw new IOException("SampleRate must be the same that the previous file");
if (isStereo != audioDecoder.isStereo()) throw new IOException("Channels must be the same that the previous file");
Expand All @@ -705,6 +708,14 @@ public void moveTo(double time) {
if (audioEnabled) audioDecoder.moveTo(time);
}

public void setVideoExtractor(Extractor extractor) {
videoDecoder.setExtractor(extractor);
}

public void setAudioExtractor(Extractor extractor) {
audioDecoder.setExtractor(extractor);
}

protected abstract void onVideoInfoImp(ByteBuffer sps, ByteBuffer pps, ByteBuffer vps);

protected abstract void getVideoDataImp(ByteBuffer videoBuffer, MediaCodec.BufferInfo info);
Expand Down

0 comments on commit f73fb36

Please sign in to comment.