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
55 changes: 35 additions & 20 deletions app/videostreaming/android/lowlagdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,45 @@ LowLagDecoder::LowLagDecoder(JNIEnv* env, bool verboseLogging, std::string logTa

void LowLagDecoder::setOutputSurface(JNIEnv* env,jobject surface){
USE_SW_DECODER_INSTEAD=false;
if(surface==nullptr){
//MLOGD<<"Set output surface to null";
//assert(decoder.window!=nullptr);
if(decoder.window== nullptr){
//MLOGD<<"Decoder window is already null";
return;
}

auto releaseDecoderResources = [this]() {
std::lock_guard<std::mutex> lock(mMutexInputPipe);
inputPipeClosed=true;
if(decoder.configured){
AMediaCodec_stop(decoder.codec);
AMediaCodec_delete(decoder.codec);
decoder.codec=nullptr;
if (decoder.codec) {
AMediaCodec_stop(decoder.codec);
AMediaCodec_delete(decoder.codec);
decoder.codec=nullptr;
}
mKeyFrameFinder.reset();
decoder.configured=false;
if(mCheckOutputThread->joinable()){
if(mCheckOutputThread && mCheckOutputThread->joinable()){
mCheckOutputThread->join();
mCheckOutputThread.reset();
}
mCheckOutputThread.reset();
}
if (decoder.window) {
ANativeWindow_release(decoder.window);
decoder.window=nullptr;
}
ANativeWindow_release(decoder.window);
decoder.window=nullptr;
resetStatistics();
}else{
// Throw warning if the surface is set without clearing it first
assert(decoder.window==nullptr);
decoder.window=ANativeWindow_fromSurface(env,surface);
// open the input pipe - now the decoder will start as soon as enough data is available
inputPipeClosed=false;
};

if(surface==nullptr){
if(decoder.window== nullptr){
return;
}
releaseDecoderResources();
return;
}

if(decoder.window!=nullptr){
releaseDecoderResources();
}

decoder.window=ANativeWindow_fromSurface(env,surface);
// open the input pipe - now the decoder will start as soon as enough data is available
inputPipeClosed=false;
}

void LowLagDecoder::registerOnDecoderRatioChangedCallback(DECODER_RATIO_CHANGED decoderRatioChangedC) {
Expand Down Expand Up @@ -167,6 +176,12 @@ void LowLagDecoder::configureStartDecoder(){
//MLOGD<<"Created decoder "<<std::string(name);
//AMediaCodec_releaseName(decoder.codec,name);
}
if (decoder.codec== nullptr) {
MLOGD<<"Cannot create decoder";
//set csd-0 and csd-1 back to 0, maybe they were just faulty but we have better luck with the next ones
mKeyFrameFinder.reset();
return;
}
AMediaFormat* format=AMediaFormat_new();
AMediaFormat_setString(format,AMEDIAFORMAT_KEY_MIME,MIME.c_str());
if(IS_H265){
Expand Down
17 changes: 16 additions & 1 deletion app/videostreaming/android/qandroidsecondarymediaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ void QAndroidSecondaryMediaPlayer::setVideoOut(QSurfaceTexture *videoOut)
if (m_videoOut == videoOut)
return;

if (m_videoOut)
if (m_videoOut) {
m_videoOut->disconnect(this);
stopPlayback();
}

m_videoOut = videoOut;

if (!m_videoOut) {
stopPlayback();
} else {
connect(m_videoOut.data(), &QSurfaceTexture::surfaceTextureChanged, this, [this] {
stopPlayback();
m_pendingPlayback = true;
tryStartPlayback();
});
Expand Down Expand Up @@ -90,6 +93,16 @@ void QAndroidSecondaryMediaPlayer::tryStartPlayback()
if (!m_videoOut)
return;

if (m_playbackRunning) {
m_pendingPlayback = false;
return;
}

const auto streamConfig = resolveStreamConfig();
if (!streamConfig) {
return;
}

const auto streamConfig = resolveStreamConfig();
if (!streamConfig) {
return;
Expand Down Expand Up @@ -170,6 +183,7 @@ void QAndroidSecondaryMediaPlayer::startPlaybackOnAndroidThread(const QAndroidJn
});

m_pendingPlayback = false;
m_playbackRunning = true;
}

void QAndroidSecondaryMediaPlayer::stopPlayback()
Expand All @@ -188,4 +202,5 @@ void QAndroidSecondaryMediaPlayer::stopPlayback()

m_activeConfig.reset();
m_pendingPlayback = false;
m_playbackRunning = false;
}
1 change: 1 addition & 0 deletions app/videostreaming/android/qandroidsecondarymediaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class QAndroidSecondaryMediaPlayer : public QObject

QPointer<QSurfaceTexture> m_videoOut;
bool m_pendingPlayback = false;
bool m_playbackRunning = false;
std::optional<QOpenHDVideoHelper::VideoStreamConfigXX> m_activeConfig;
std::unique_ptr<LowLagDecoder> m_lowLagDecoder;
std::unique_ptr<GstRtpReceiver> m_receiver;
Expand Down
Loading