[FFmpeg-devel] [PATCH 1/2] avformat/mov: factorize setting little endian PCM streams

Marton Balint cus at passwd.hu
Mon Jun 20 00:53:39 EEST 2022


Signed-off-by: Marton Balint <cus at passwd.hu>
---
 libavformat/mov.c | 51 +++++++++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 24 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 3ec0ea2361..0660a51492 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1544,35 +1544,38 @@ static int mov_read_mvhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     return 0;
 }
 
-static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+static void set_last_stream_little_endian(AVFormatContext *fc)
 {
     AVStream *st;
-    int little_endian;
 
-    if (c->fc->nb_streams < 1)
-        return 0;
-    st = c->fc->streams[c->fc->nb_streams-1];
+    if (fc->nb_streams < 1)
+        return;
+    st = fc->streams[fc->nb_streams-1];
 
-    little_endian = avio_rb16(pb) & 0xFF;
-    av_log(c->fc, AV_LOG_TRACE, "enda %d\n", little_endian);
-    if (little_endian == 1) {
-        switch (st->codecpar->codec_id) {
-        case AV_CODEC_ID_PCM_S24BE:
-            st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;
-            break;
-        case AV_CODEC_ID_PCM_S32BE:
-            st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE;
-            break;
-        case AV_CODEC_ID_PCM_F32BE:
-            st->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE;
-            break;
-        case AV_CODEC_ID_PCM_F64BE:
-            st->codecpar->codec_id = AV_CODEC_ID_PCM_F64LE;
-            break;
-        default:
-            break;
-        }
+    switch (st->codecpar->codec_id) {
+    case AV_CODEC_ID_PCM_S24BE:
+        st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;
+        break;
+    case AV_CODEC_ID_PCM_S32BE:
+        st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE;
+        break;
+    case AV_CODEC_ID_PCM_F32BE:
+        st->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE;
+        break;
+    case AV_CODEC_ID_PCM_F64BE:
+        st->codecpar->codec_id = AV_CODEC_ID_PCM_F64LE;
+        break;
+    default:
+        break;
     }
+}
+
+static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+    int little_endian = avio_rb16(pb) & 0xFF;
+    av_log(c->fc, AV_LOG_TRACE, "enda %d\n", little_endian);
+    if (little_endian == 1)
+        set_last_stream_little_endian(c->fc);
     return 0;
 }
 
-- 
2.35.3



More information about the ffmpeg-devel mailing list