Skip to content

Commit

Permalink
move setVideoCodec to base
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Nov 1, 2023
1 parent 59e5053 commit 0d35e08
Show file tree
Hide file tree
Showing 26 changed files with 168 additions and 104 deletions.
11 changes: 10 additions & 1 deletion library/src/main/java/com/pedro/library/base/Camera1Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import com.pedro.library.base.recording.RecordController;
import com.pedro.library.util.AndroidMuxerRecordController;
import com.pedro.library.util.FpsListener;
import com.pedro.library.util.streamclient.RtmpStreamClient;
import com.pedro.library.util.VideoCodec;
import com.pedro.library.util.streamclient.StreamBaseClient;
import com.pedro.library.view.GlInterface;
import com.pedro.library.view.LightOpenGlView;
Expand Down Expand Up @@ -1009,4 +1009,13 @@ public void onVideoFormat(@NonNull MediaFormat mediaFormat) {
};

public abstract StreamBaseClient getStreamClient();

public void setVideoCodec(VideoCodec codec) {
recordController.setVideoMime(
codec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
videoEncoder.setType(codec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
setVideoCodecImp(codec);
}

protected abstract void setVideoCodecImp(VideoCodec codec);
}
10 changes: 10 additions & 0 deletions library/src/main/java/com/pedro/library/base/Camera2Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.pedro.library.base.recording.RecordController;
import com.pedro.library.util.AndroidMuxerRecordController;
import com.pedro.library.util.FpsListener;
import com.pedro.library.util.VideoCodec;
import com.pedro.library.util.streamclient.StreamBaseClient;
import com.pedro.library.view.GlInterface;
import com.pedro.library.view.LightOpenGlView;
Expand Down Expand Up @@ -1055,4 +1056,13 @@ public void onVideoFormat(@NonNull MediaFormat mediaFormat) {
};

public abstract StreamBaseClient getStreamClient();

public void setVideoCodec(VideoCodec codec) {
recordController.setVideoMime(
codec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
videoEncoder.setType(codec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
setVideoCodecImp(codec);
}

protected abstract void setVideoCodecImp(VideoCodec codec);
}
10 changes: 10 additions & 0 deletions library/src/main/java/com/pedro/library/base/DisplayBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.pedro.library.base.recording.RecordController;
import com.pedro.library.util.AndroidMuxerRecordController;
import com.pedro.library.util.FpsListener;
import com.pedro.library.util.VideoCodec;
import com.pedro.library.util.streamclient.StreamBaseClient;
import com.pedro.library.view.GlInterface;
import com.pedro.library.view.OffScreenGlThread;
Expand Down Expand Up @@ -604,5 +605,14 @@ public void onVideoFormat(@NonNull MediaFormat mediaFormat) {
};

public abstract StreamBaseClient getStreamClient();

public void setVideoCodec(VideoCodec codec) {
recordController.setVideoMime(
codec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
videoEncoder.setType(codec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
setVideoCodecImp(codec);
}

protected abstract void setVideoCodecImp(VideoCodec codec);
}

10 changes: 10 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 @@ -46,6 +46,7 @@
import com.pedro.library.base.recording.RecordController;
import com.pedro.library.util.AndroidMuxerRecordController;
import com.pedro.library.util.FpsListener;
import com.pedro.library.util.VideoCodec;
import com.pedro.library.util.streamclient.StreamBaseClient;
import com.pedro.library.view.GlInterface;
import com.pedro.library.view.LightOpenGlView;
Expand Down Expand Up @@ -673,4 +674,13 @@ public void onLoop() {
};

public abstract StreamBaseClient getStreamClient();

public void setVideoCodec(VideoCodec codec) {
recordController.setVideoMime(
codec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
videoEncoder.setType(codec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
setVideoCodecImp(codec);
}

protected abstract void setVideoCodecImp(VideoCodec codec);
}
12 changes: 12 additions & 0 deletions library/src/main/java/com/pedro/library/base/StreamBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import com.pedro.encoder.audio.AudioEncoder
import com.pedro.encoder.audio.GetAacData
import com.pedro.encoder.input.audio.GetMicrophoneData
import com.pedro.encoder.input.video.CameraHelper
import com.pedro.encoder.utils.CodecUtil
import com.pedro.encoder.video.FormatVideoEncoder
import com.pedro.encoder.video.GetVideoData
import com.pedro.encoder.video.VideoEncoder
import com.pedro.library.base.recording.BaseRecordController
import com.pedro.library.base.recording.RecordController
import com.pedro.library.util.AndroidMuxerRecordController
import com.pedro.library.util.VideoCodec
import com.pedro.library.util.sources.AudioManager
import com.pedro.library.util.sources.VideoManager
import com.pedro.library.util.streamclient.StreamBaseClient
Expand Down Expand Up @@ -543,4 +545,14 @@ abstract class StreamBase(
protected abstract fun getAacDataRtp(aacBuffer: ByteBuffer, info: MediaCodec.BufferInfo)

abstract fun getStreamClient(): StreamBaseClient

fun setVideoCodec(codec: VideoCodec) {
recordController.setVideoMime(
if (codec === VideoCodec.H265) CodecUtil.H265_MIME else CodecUtil.H264_MIME
)
videoEncoder.type = if (codec === VideoCodec.H265) CodecUtil.H265_MIME else CodecUtil.H264_MIME
setVideoCodecImp(codec)
}

protected abstract fun setVideoCodecImp(codec: VideoCodec)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import androidx.annotation.RequiresApi;

import com.pedro.library.base.Camera1Base;
import com.pedro.library.util.VideoCodec;
import com.pedro.library.util.streamclient.StreamBaseClient;
import com.pedro.library.view.LightOpenGlView;
import com.pedro.library.view.OpenGlView;
Expand Down Expand Up @@ -449,6 +450,16 @@ public StreamBaseClient getStreamClient() {
return null;
}

@Override
protected void setVideoCodecImp(VideoCodec codec) {
for (RtmpClient rtmpClient: rtmpClients) {
rtmpClient.setVideoCodec(codec == VideoCodec.H264 ? com.pedro.rtmp.rtmp.VideoCodec.H264 : com.pedro.rtmp.rtmp.VideoCodec.H265);
}
for (RtspClient rtspClient: rtspClients) {
rtspClient.setVideoCodec(codec == VideoCodec.H264 ? com.pedro.rtsp.rtsp.VideoCodec.H264 : com.pedro.rtsp.rtsp.VideoCodec.H265);
}
}

public void setLogs(boolean enable) {
for (RtmpClient rtmpClient: rtmpClients) {
rtmpClient.setLogs(enable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import androidx.annotation.RequiresApi;

import com.pedro.library.base.Camera2Base;
import com.pedro.library.util.VideoCodec;
import com.pedro.library.util.streamclient.StreamBaseClient;
import com.pedro.library.view.LightOpenGlView;
import com.pedro.library.view.OpenGlView;
Expand Down Expand Up @@ -449,6 +450,16 @@ public StreamBaseClient getStreamClient() {
return null;
}

@Override
protected void setVideoCodecImp(VideoCodec codec) {
for (RtmpClient rtmpClient: rtmpClients) {
rtmpClient.setVideoCodec(codec == VideoCodec.H264 ? com.pedro.rtmp.rtmp.VideoCodec.H264 : com.pedro.rtmp.rtmp.VideoCodec.H265);
}
for (RtspClient rtspClient: rtspClients) {
rtspClient.setVideoCodec(codec == VideoCodec.H264 ? com.pedro.rtsp.rtsp.VideoCodec.H264 : com.pedro.rtsp.rtsp.VideoCodec.H265);
}
}

public void setLogs(boolean enable) {
for (RtmpClient rtmpClient: rtmpClients) {
rtmpClient.setLogs(enable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import androidx.annotation.RequiresApi;

import com.pedro.library.base.DisplayBase;
import com.pedro.library.util.VideoCodec;
import com.pedro.library.util.streamclient.StreamBaseClient;
import com.pedro.rtmp.flv.video.ProfileIop;
import com.pedro.rtmp.rtmp.RtmpClient;
Expand Down Expand Up @@ -375,6 +376,16 @@ public StreamBaseClient getStreamClient() {
return null;
}

@Override
protected void setVideoCodecImp(VideoCodec codec) {
for (RtmpClient rtmpClient: rtmpClients) {
rtmpClient.setVideoCodec(codec == VideoCodec.H264 ? com.pedro.rtmp.rtmp.VideoCodec.H264 : com.pedro.rtmp.rtmp.VideoCodec.H265);
}
for (RtspClient rtspClient: rtspClients) {
rtspClient.setVideoCodec(codec == VideoCodec.H264 ? com.pedro.rtsp.rtsp.VideoCodec.H264 : com.pedro.rtsp.rtsp.VideoCodec.H265);
}
}

public void setLogs(boolean enable) {
for (RtmpClient rtmpClient : rtmpClients) {
rtmpClient.setLogs(enable);
Expand Down
11 changes: 4 additions & 7 deletions library/src/main/java/com/pedro/library/rtmp/RtmpCamera1.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@

import androidx.annotation.RequiresApi;

import com.pedro.encoder.utils.CodecUtil;
import com.pedro.library.base.Camera1Base;
import com.pedro.library.util.VideoCodec;
import com.pedro.library.util.streamclient.RtmpStreamClient;
import com.pedro.library.util.streamclient.StreamClientListener;
import com.pedro.library.view.LightOpenGlView;
import com.pedro.library.view.OpenGlView;
import com.pedro.rtmp.rtmp.RtmpClient;
import com.pedro.rtmp.rtmp.VideoCodec;
import com.pedro.rtmp.utils.ConnectCheckerRtmp;

import java.nio.ByteBuffer;
Expand Down Expand Up @@ -87,11 +86,9 @@ public RtmpStreamClient getStreamClient() {
return streamClient;
}

public void setVideoCodec(VideoCodec videoCodec) {
recordController.setVideoMime(
videoCodec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
videoEncoder.setType(videoCodec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
rtmpClient.setVideoCodec(videoCodec);
@Override
protected void setVideoCodecImp(VideoCodec codec) {
rtmpClient.setVideoCodec(codec == VideoCodec.H264 ? com.pedro.rtmp.rtmp.VideoCodec.H264 : com.pedro.rtmp.rtmp.VideoCodec.H265);
}

@Override
Expand Down
11 changes: 4 additions & 7 deletions library/src/main/java/com/pedro/library/rtmp/RtmpCamera2.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@

import androidx.annotation.RequiresApi;

import com.pedro.encoder.utils.CodecUtil;
import com.pedro.library.base.Camera2Base;
import com.pedro.library.util.VideoCodec;
import com.pedro.library.util.streamclient.RtmpStreamClient;
import com.pedro.library.util.streamclient.StreamClientListener;
import com.pedro.library.view.LightOpenGlView;
import com.pedro.library.view.OpenGlView;
import com.pedro.rtmp.rtmp.RtmpClient;
import com.pedro.rtmp.rtmp.VideoCodec;
import com.pedro.rtmp.utils.ConnectCheckerRtmp;

import java.nio.ByteBuffer;
Expand Down Expand Up @@ -96,11 +95,9 @@ public RtmpStreamClient getStreamClient() {
return streamClient;
}

public void setVideoCodec(VideoCodec videoCodec) {
recordController.setVideoMime(
videoCodec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
videoEncoder.setType(videoCodec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
rtmpClient.setVideoCodec(videoCodec);
@Override
protected void setVideoCodecImp(VideoCodec codec) {
rtmpClient.setVideoCodec(codec == VideoCodec.H264 ? com.pedro.rtmp.rtmp.VideoCodec.H264 : com.pedro.rtmp.rtmp.VideoCodec.H265);
}

@Override
Expand Down
11 changes: 4 additions & 7 deletions library/src/main/java/com/pedro/library/rtmp/RtmpDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@

import androidx.annotation.RequiresApi;

import com.pedro.encoder.utils.CodecUtil;
import com.pedro.library.base.DisplayBase;
import com.pedro.library.util.VideoCodec;
import com.pedro.library.util.streamclient.RtmpStreamClient;
import com.pedro.library.util.streamclient.StreamClientListener;
import com.pedro.rtmp.rtmp.RtmpClient;
import com.pedro.rtmp.rtmp.VideoCodec;
import com.pedro.rtmp.utils.ConnectCheckerRtmp;

import java.nio.ByteBuffer;
Expand Down Expand Up @@ -56,11 +55,9 @@ public RtmpStreamClient getStreamClient() {
return streamClient;
}

public void setVideoCodec(VideoCodec videoCodec) {
recordController.setVideoMime(
videoCodec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
videoEncoder.setType(videoCodec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
rtmpClient.setVideoCodec(videoCodec);
@Override
protected void setVideoCodecImp(VideoCodec codec) {
rtmpClient.setVideoCodec(codec == VideoCodec.H264 ? com.pedro.rtmp.rtmp.VideoCodec.H264 : com.pedro.rtmp.rtmp.VideoCodec.H265);
}

@Override
Expand Down
11 changes: 4 additions & 7 deletions library/src/main/java/com/pedro/library/rtmp/RtmpFromFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@

import com.pedro.encoder.input.decoder.AudioDecoderInterface;
import com.pedro.encoder.input.decoder.VideoDecoderInterface;
import com.pedro.encoder.utils.CodecUtil;
import com.pedro.library.base.FromFileBase;
import com.pedro.library.util.VideoCodec;
import com.pedro.library.util.streamclient.RtmpStreamClient;
import com.pedro.library.util.streamclient.StreamClientListener;
import com.pedro.library.view.LightOpenGlView;
import com.pedro.library.view.OpenGlView;
import com.pedro.rtmp.rtmp.RtmpClient;
import com.pedro.rtmp.rtmp.VideoCodec;
import com.pedro.rtmp.utils.ConnectCheckerRtmp;

import java.nio.ByteBuffer;
Expand Down Expand Up @@ -82,11 +81,9 @@ public RtmpStreamClient getStreamClient() {
return streamClient;
}

public void setVideoCodec(VideoCodec videoCodec) {
recordController.setVideoMime(
videoCodec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
videoEncoder.setType(videoCodec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
rtmpClient.setVideoCodec(videoCodec);
@Override
protected void setVideoCodecImp(VideoCodec codec) {
rtmpClient.setVideoCodec(codec == VideoCodec.H264 ? com.pedro.rtmp.rtmp.VideoCodec.H264 : com.pedro.rtmp.rtmp.VideoCodec.H265);
}

@Override
Expand Down
9 changes: 3 additions & 6 deletions library/src/main/java/com/pedro/library/rtmp/RtmpStream.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import android.content.Context
import android.media.MediaCodec
import android.os.Build
import androidx.annotation.RequiresApi
import com.pedro.encoder.utils.CodecUtil
import com.pedro.library.base.StreamBase
import com.pedro.library.util.VideoCodec
import com.pedro.library.util.sources.AudioManager
import com.pedro.library.util.sources.VideoManager
import com.pedro.library.util.streamclient.RtmpStreamClient
import com.pedro.library.util.streamclient.StreamClientListener
import com.pedro.rtmp.rtmp.RtmpClient
import com.pedro.rtmp.rtmp.VideoCodec
import com.pedro.rtmp.utils.ConnectCheckerRtmp
import java.nio.ByteBuffer

Expand Down Expand Up @@ -39,10 +38,8 @@ class RtmpStream(
constructor(context: Context, connectCheckerRtmp: ConnectCheckerRtmp):
this(context, connectCheckerRtmp, VideoManager.Source.CAMERA2, AudioManager.Source.MICROPHONE)

fun setVideoCodec(videoCodec: VideoCodec) {
val mime = if (videoCodec === VideoCodec.H265) CodecUtil.H265_MIME else CodecUtil.H264_MIME
super.setVideoMime(mime)
rtmpClient.setVideoCodec(videoCodec)
override fun setVideoCodecImp(codec: VideoCodec) {
rtmpClient.setVideoCodec(if (codec === VideoCodec.H264) com.pedro.rtmp.rtmp.VideoCodec.H264 else com.pedro.rtmp.rtmp.VideoCodec.H265)
}

override fun audioInfo(sampleRate: Int, isStereo: Boolean) {
Expand Down
11 changes: 4 additions & 7 deletions library/src/main/java/com/pedro/library/rtsp/RtspCamera1.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@

import androidx.annotation.RequiresApi;

import com.pedro.encoder.utils.CodecUtil;
import com.pedro.library.base.Camera1Base;
import com.pedro.library.util.VideoCodec;
import com.pedro.library.util.streamclient.RtspStreamClient;
import com.pedro.library.util.streamclient.StreamClientListener;
import com.pedro.library.view.LightOpenGlView;
import com.pedro.library.view.OpenGlView;
import com.pedro.rtsp.rtsp.RtspClient;
import com.pedro.rtsp.rtsp.VideoCodec;
import com.pedro.rtsp.utils.ConnectCheckerRtsp;

import java.nio.ByteBuffer;
Expand Down Expand Up @@ -87,11 +86,9 @@ public RtspStreamClient getStreamClient() {
return streamClient;
}


public void setVideoCodec(VideoCodec videoCodec) {
recordController.setVideoMime(
videoCodec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
videoEncoder.setType(videoCodec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
@Override
protected void setVideoCodecImp(VideoCodec codec) {
rtspClient.setVideoCodec(codec == VideoCodec.H264 ? com.pedro.rtsp.rtsp.VideoCodec.H264 : com.pedro.rtsp.rtsp.VideoCodec.H265);
}

@Override
Expand Down
Loading

0 comments on commit 0d35e08

Please sign in to comment.