From e09b50e071434c230def72e9fa555fe1c08451a5 Mon Sep 17 00:00:00 2001
From: MattKC <34096995+itsmattkc@users.noreply.github.com>
Date: Wed, 11 Dec 2024 20:22:51 -0800
Subject: [PATCH] ensure MediaInstance is audio before using it

---
 app/viewer/mediapanel.cpp | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/app/viewer/mediapanel.cpp b/app/viewer/mediapanel.cpp
index 196e690..bbf50cd 100644
--- a/app/viewer/mediapanel.cpp
+++ b/app/viewer/mediapanel.cpp
@@ -812,16 +812,18 @@ qint64 MediaAudioMixer::readData(char *data, qint64 maxSize)
     for (auto it = m_mediaInstances->cbegin(); it != m_mediaInstances->cend(); it++) {
         auto m = *it;
 
-        qint64 thisRead = m->ReadAudio(reinterpret_cast<char *>(tmp), maxSize);
-        if (thisRead > touchedBytes) {
-            memset(data + touchedBytes, 0, thisRead - touchedBytes);
-            touchedBytes = thisRead;
-        }
+        if (m->codec_type() == AVMEDIA_TYPE_AUDIO) {
+            qint64 thisRead = m->ReadAudio(reinterpret_cast<char *>(tmp), maxSize);
+            if (thisRead > touchedBytes) {
+                memset(data + touchedBytes, 0, thisRead - touchedBytes);
+                touchedBytes = thisRead;
+            }
 
-        // TODO: Optimize with SSE and NEON
-        qint64 thisSamples = thisRead / m_audioFormat.bytesPerSample();
-        for (qint64 j = 0; j < thisSamples; j++) {
-            output[j] += tmp[j] * m->GetVolume();
+            // TODO: Optimize with SSE and NEON
+            qint64 thisSamples = thisRead / m_audioFormat.bytesPerSample();
+            for (qint64 j = 0; j < thisSamples; j++) {
+                output[j] += tmp[j] * m->GetVolume();
+            }
         }
     }