1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/*
* audio.cpp: A program for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id$
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "audio.h"
cMarkAdAudio::cMarkAdAudio(MarkAdContext *maContext)
{
macontext=maContext;
mark.Comment=NULL;
mark.Position=0;
mark.Type=0;
result.CommentBefore=NULL;
result.CommentAfter=NULL;
Clear();
}
cMarkAdAudio::~cMarkAdAudio()
{
ResetMark();
Clear();
}
void cMarkAdAudio::Clear()
{
channels=0;
if (result.CommentBefore) free(result.CommentBefore);
if (result.CommentAfter) free(result.CommentAfter);
memset(&result,0,sizeof(result));
}
void cMarkAdAudio::ResetMark()
{
if (!mark.Type) return;
if (mark.Comment) free(mark.Comment);
mark.Comment=NULL;
mark.Position=0;
mark.Type=0;
}
bool cMarkAdAudio::AddMark(int Type, 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;
mark.Type=Type;
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 FrameNumber, int FrameNumberNext)
{
if ((!FrameNumber) || (!FrameNumberNext)) return NULL;
ResetMark();
if (ChannelChange(macontext->Audio.Info.Channels,channels))
{
char *buf=(char *) calloc(1,256);
if (!buf) return NULL;
snprintf(buf,255,"audio channel change from %i to %i (", channels,
macontext->Audio.Info.Channels);
if (macontext->Audio.Info.Channels>2)
{
char nbuf[20];
snprintf(nbuf,sizeof(nbuf),"%i)*",FrameNumberNext);
nbuf[19]=0;
strcat(buf,nbuf);
AddMark(MT_CHANNELSTART,FrameNumberNext,buf);
}
else
{
char nbuf[20];
snprintf(nbuf,sizeof(nbuf),"%i)",framelast);
nbuf[19]=0;
strcat(buf,nbuf);
AddMark(MT_CHANNELSTOP,framelast,buf);
}
free(buf);
}
channels=macontext->Audio.Info.Channels;
framelast=FrameNumber;
if (mark.Position)
{
return &mark;
}
else
{
return NULL;
}
}
|