summaryrefslogtreecommitdiff
path: root/audio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'audio.cpp')
-rw-r--r--audio.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/audio.cpp b/audio.cpp
new file mode 100644
index 0000000..d34ceae
--- /dev/null
+++ b/audio.cpp
@@ -0,0 +1,88 @@
+/*
+ * audio.cpp: A plugin for the Video Disk Recorder
+ *
+ * See the README file for copyright information and how to reach the author.
+ *
+ * $Id$
+ */
+
+#include "audio.h"
+
+cMarkAdAudio::cMarkAdAudio(int RecvNumber,MarkAdContext *maContext)
+{
+ macontext=maContext;
+ recvnumber=RecvNumber;
+ mark.Comment=NULL;
+ mark.Position=0;
+ channels=0;
+}
+
+cMarkAdAudio::~cMarkAdAudio()
+{
+ ResetMark();
+}
+
+void cMarkAdAudio::ResetMark()
+{
+ if (mark.Comment) free(mark.Comment);
+ mark.Comment=NULL;
+ mark.Position=0;
+}
+
+bool cMarkAdAudio::AddMark(int Position, const char *Comment)
+{
+ if (!Comment) return false;
+ if (mark.Comment)
+ {
+ int oldlen=strlen(mark.Comment);
+ mark.Comment=(char *) realloc(mark.Comment,oldlen+10+strlen(Comment));
+ if (!mark.Comment)
+ {
+ mark.Position=0;
+ return false;
+ }
+ strcat(mark.Comment," [");
+ strcat(mark.Comment,Comment);
+ strcat(mark.Comment,"]");
+ }
+ else
+ {
+ mark.Comment=strdup(Comment);
+ }
+ mark.Position=Position;
+ return true;
+}
+
+bool cMarkAdAudio::ChannelChange(int a, int b)
+{
+ if ((a==0) || (b==0)) return false;
+ if (a!=b) return true;
+ return false;
+}
+
+MarkAdMark *cMarkAdAudio::Process(int LastIFrame)
+{
+ ResetMark();
+ if (!LastIFrame) return NULL;
+
+
+ if (macontext->State.ContentStarted)
+ {
+ if (ChannelChange(macontext->Audio.Info.Channels,channels))
+ {
+ char *buf=NULL;
+ asprintf(&buf,"audio channel change from %i to %i (%i)", channels,
+ macontext->Audio.Info.Channels,LastIFrame);
+ if (buf)
+ {
+ isyslog("markad [%i]: %s",recvnumber, buf);
+ AddMark(LastIFrame,buf);
+ free(buf);
+ }
+ }
+ }
+
+ channels=macontext->Audio.Info.Channels;
+ return &mark;
+}
+