summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2017-01-22 21:39:58 +0200
committerJari Vetoniemi <mailroxas@gmail.com>2017-01-22 21:39:58 +0200
commit8f4379c29d4cbae652f74bb9eb4fa935f542d826 (patch)
treec86e2e2bea58ced0b7f838a0146d573f299fff1d
parent3074b506519ed43f3b1888740b8f7364cdfa3a89 (diff)
Handle stream information changes properly
-rw-r--r--glcapture.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/glcapture.c b/glcapture.c
index b4dde20..1907ef6 100644
--- a/glcapture.c
+++ b/glcapture.c
@@ -23,6 +23,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
+#include <assert.h>
#include <time.h>
#include <err.h>
#include <pthread.h>
@@ -116,9 +117,30 @@ reset_fifo(struct fifo *fifo)
WARNX("reseting fifo");
}
+static bool
+stream_info_changed(const struct frame_info *current, const struct frame_info *last)
+{
+ assert(current->stream == last->stream);
+
+ if (current->stream == STREAM_VIDEO) {
+ return (current->video.format != last->video.format ||
+ current->video.width != last->video.width ||
+ current->video.height != last->video.height);
+ }
+
+ return (current->audio.format != last->audio.format ||
+ current->audio.rate != last->audio.rate ||
+ current->audio.channels != last->audio.channels);
+}
+
static void
write_data_unsafe(struct fifo *fifo, const struct frame_info *info, const void *buffer, const size_t size)
{
+ if (fifo->stream[info->stream].ready && stream_info_changed(info, &fifo->stream[info->stream].info)) {
+ WARNX("stream information has changed");
+ reset_fifo(fifo);
+ }
+
fifo->stream[info->stream].info = *info;
fifo->stream[info->stream].ready = true;
@@ -127,9 +149,6 @@ write_data_unsafe(struct fifo *fifo, const struct frame_info *info, const void *
return;
}
- if (memcmp(info, &fifo->stream[info->stream].info, sizeof(*info)))
- reset_fifo(fifo);
-
if (!fifo->created) {
remove(FIFO_PATH);