summaryrefslogtreecommitdiffstats
path: root/mpeglib/lib/output/audioDataArray.cpp
blob: a0b91ec11eaec4cbf7fdcff7b4ffff31d3766bfd (plain)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
  fifo for audioData
  Copyright (C) 1999  Martin Vogt

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Library General Public License as published by
  the Free Software Foundation.

  For more information look at the file COPYRIGHT in this package

 */



#include "audioDataArray.h"

#include <iostream>

using namespace std;


AudioDataArray::AudioDataArray(int entries) {

  this->entries=entries;
  fillgrade=0;
  readPos=0;
  writePos=0;
  pcmSum=0;
  abs_thread_mutex_init(&writeInMut);
  abs_thread_mutex_init(&changeMut);

  audioDataArray=new AudioData*[entries];

  int i;
  for(i=0;i<entries;i++) {
    audioDataArray[i]=new AudioData();
  }

  abs_thread_mutex_init(&writeInMut);
  abs_thread_mutex_init(&changeMut);

}

AudioDataArray::~AudioDataArray() {

  int i;
  for(i=0;i<entries;i++) {
    delete audioDataArray[i];
  } 

  delete audioDataArray;

  abs_thread_mutex_destroy(&writeInMut);
  abs_thread_mutex_destroy(&changeMut);

}




void AudioDataArray::lockStampArray() {

  abs_thread_mutex_lock(&changeMut);
  abs_thread_mutex_lock(&writeInMut);
  abs_thread_mutex_unlock(&changeMut);

}


void AudioDataArray::unlockStampArray() {
  abs_thread_mutex_unlock(&writeInMut); 
}


void AudioDataArray::internalForward() {
  pcmSum=pcmSum-readAudioData()->getPCMLen();
  readPos++;
  fillgrade--;
  if (readPos == entries-1) {
    readPos=0;
  }
}

int AudioDataArray::getPCMSum() {
  return pcmSum;
}



int AudioDataArray::insertAudioData(AudioData* src) {
  lockStampArray();

  int back=true;
  src->copyTo(audioDataArray[writePos]);
  pcmSum+=src->getPCMLen();

  writePos++;
  fillgrade++;
  if (writePos == entries-1) {
    writePos=0;
  }
  if (fillgrade == entries) {
    cout <<" Audiodata::array overfull forward"<<endl;
    internalForward();
    back=false;
  }
  unlockStampArray();
  return back;
}


AudioData* AudioDataArray::readAudioData() {
  return audioDataArray[readPos];
}


int AudioDataArray::getFillgrade() {
  return fillgrade;
}


void AudioDataArray::forward() {
  lockStampArray();
  internalForward();
  unlockStampArray();
}


void AudioDataArray::clear() {
  lockStampArray();
  fillgrade=0;
  readPos=0;
  writePos=0;
  pcmSum=0;
  unlockStampArray();
}