Skip to content

Commit

Permalink
Modification of SPS VUI params for low-latency
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyvasilyev committed Nov 14, 2024
1 parent 41b30be commit c8b16c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'

def androidx_navigation_version = '2.8.3'
def androidx_navigation_version = '2.8.4'
implementation "androidx.navigation:navigation-fragment-ktx:$androidx_navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$androidx_navigation_version"
implementation "androidx.navigation:navigation-fragment-ktx:$androidx_navigation_version"
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ buildscript {
ext.compile_sdk_version = 35
ext.min_sdk_version = 24
ext.target_sdk_version = 35
ext.project_version_code = 520
ext.project_version_name = '5.2.0'
ext.project_version_code = 521
ext.project_version_name = '5.2.1'

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.alexvas.rtsp.codec.VideoFrameQueue
import com.alexvas.utils.NetUtils
import com.alexvas.utils.VideoCodecUtils
import org.jcodec.codecs.h264.io.model.SeqParameterSet
import org.jcodec.codecs.h264.io.model.VUIParameters
import java.net.Socket
import java.nio.ByteBuffer
import java.util.concurrent.atomic.AtomicBoolean
Expand Down Expand Up @@ -494,14 +495,30 @@ class RtspProcessor(
// Read SPS frame
val spsSet = SeqParameterSet.read(spsBufferReadFrame)

// SPS frame already has num_ref_frames set to 0. Return original frame.
if (spsSet.numRefFrames == 0)
return frame

// Change SPS frame
if (debug)
Log.d(TAG, "Changed SPS num_ref_frames ${spsSet.numRefFrames} -> 0")
spsSet.numRefFrames = 0
// adding VUI might decrease latency for some streams, if max_dec_frame_buffering is set properly
// https://community.intel.com/t5/Media-Intel-oneAPI-Video/h-264-decoder-gives-two-frames-latency-while-decoding-a-stream/td-p/1099694
// https://github.com/Consti10/LiveVideo10ms/blob/master/VideoCore/src/main/cpp/NALU/H26X.hpp
fun modifyVui() {
// spsSet.vuiParams = VUIParameters()
spsSet.vuiParams.apply {
// videoSignalTypePresentFlag = true
// videoFormat = 5
// colourDescriptionPresentFlag = true
// matrixCoefficients = 5
// timingInfoPresentFlag = true
// numUnitsInTick = 1
// timeScale = 120
// fixedFrameRateFlag = true
bitstreamRestriction = VUIParameters.BitstreamRestriction().apply {
// motionVectorsOverPicBoundariesFlag = true
// log2MaxMvLengthHorizontal = 16
// log2MaxMvLengthVertical = 16
maxDecFrameBuffering = 1
numReorderFrames = 0
}
}
}
modifyVui()

// Write SPS frame
spsBufferWriteFrame.rewind()
Expand Down

0 comments on commit c8b16c2

Please sign in to comment.