From edf7a53148fc565d1d8ff31285ebeedb0f698f61 Mon Sep 17 00:00:00 2001
From: philippegorley <philippe.gorley@savoirfairelinux.com>
Date: Tue, 11 Sep 2018 13:31:19 -0400
Subject: [PATCH] media: update MediaStream objects if properties change

This sets the stage for automatic reinitialization of MediaFilter if the
input properties change.

Change-Id: I899834f0bbeb4ca0425fd6ba5a89460c0c9bda99
---
 src/media/media_stream.h | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/media/media_stream.h b/src/media/media_stream.h
index a8f8eeeb41..b3e43e4ebc 100644
--- a/src/media/media_stream.h
+++ b/src/media/media_stream.h
@@ -80,9 +80,9 @@ struct MediaStream {
 
     MediaStream(std::string name, AVCodecContext* c, int64_t firstTimestamp)
         : name(name)
+        , firstTimestamp(firstTimestamp)
     {
         timeBase = c->time_base;
-        this->firstTimestamp = firstTimestamp;
         switch (c->codec_type) {
         case AVMEDIA_TYPE_VIDEO:
             format = c->pix_fmt;
@@ -114,6 +114,20 @@ struct MediaStream {
         else
             return sampleRate > 0 && nbChannels > 0;
     }
+
+    void update(AVFrame* f)
+    {
+        // update all info possible (AVFrame has no fps data)
+        format = f->format;
+        if (isVideo) {
+            width = f->width;
+            height = f->height;
+            aspectRatio = f->sample_aspect_ratio;
+        } else {
+            sampleRate = f->sample_rate;
+            nbChannels = f->channels;
+        }
+    }
 };
 
 inline std::ostream& operator<<(std::ostream& os, const MediaStream& ms)
-- 
GitLab