summaryrefslogtreecommitdiffstats
path: root/mpeglib/lib/output/outputStream.cpp
blob: ef209cbcc7abc39030dca55fe8a689dcea2f6eff (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
  generic output class
  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 "outputStream.h"
#include "../util/mmx/mmx.h"

#include <iostream>

using namespace std;

OutputStream::OutputStream() {
  // we call mm_support() here because it is the only position
  // where we gurantee that not threads are
  // running (the call is not thread safe)
  // afer the call we never execute the asm part again
  // and everything is fine
  mm_support();
  abs_thread_mutex_init(&stateChangeMut);
  abs_thread_cond_init(&stateChangeCond);

  audioState=0;
  videoState=0;
  audioInit();
  videoInit();
}


OutputStream::~OutputStream() {
  audioInit();
  videoInit();
  abs_thread_cond_destroy(&stateChangeCond);
  abs_thread_mutex_destroy(&stateChangeMut);
}


int OutputStream::audioInit() {
  sendSignal(_STREAM_MASK_IS_INIT,false,_STREAMTYPE_AUDIO);
  sendSignal(_STREAM_MASK_IS_EOF,false,_STREAMTYPE_AUDIO);
  sendSignal(_STREAM_MASK_IS_DATA,false,_STREAMTYPE_AUDIO);
  return true;
}


int OutputStream::audioSetup(int ,int ,
			     int ,int ,int ) {
  sendSignal(_STREAM_MASK_IS_INIT,true,_STREAMTYPE_AUDIO);
  return true;
}


int OutputStream::audioPlay(TimeStamp* ,
			    TimeStamp* ,char* , int len) {
  sendSignal(_STREAM_MASK_IS_DATA,true,_STREAMTYPE_AUDIO);
  return len;
}

void OutputStream::audioFlush() {
  sendSignal(_STREAM_MASK_IS_EOF,true,_STREAMTYPE_AUDIO);
}


void OutputStream::audioClose() {
  cerr << "direct virtual call OutputStream::audioClose"<<endl;
  exit(0);
}

void OutputStream::audioOpen() {
  cerr << "direct virtual call OutputStream::audioOpen"<<endl;
  exit(0);
}



void OutputStream::sendSignal(int signal,int value,int streamType) {
  abs_thread_mutex_lock(&stateChangeMut);
  int* modifyState=NULL;
  switch(streamType) {
  case _STREAMTYPE_AUDIO:
    modifyState=&audioState;
    break;
  case _STREAMTYPE_VIDEO:
    modifyState=&videoState;
    break;
  default:
    cout << "unknown streamType:"<<streamType
	 <<" in OutputStream::sendSignal"<<endl;
    exit(0);
  }
  // should we set the bit?
  if (value==true) {
    // set it with "or"
    *modifyState|=signal;
  } else {
    // we should remove the bit
    // is it currently set?
    if (*modifyState & signal) {
      // remove it
      *modifyState-=signal;
    }
  }


  abs_thread_cond_signal(&stateChangeCond);
  abs_thread_mutex_unlock(&stateChangeMut);
 
}


int OutputStream::getPreferredDeliverSize() {
  cerr << "direct virtual call OutputStream::getPreferredDeliverSize()"<<endl;
  return 4096;
}

int OutputStream::videoInit() {
  sendSignal(_STREAM_MASK_IS_INIT,false,_STREAMTYPE_VIDEO);
  sendSignal(_STREAM_MASK_IS_EOF,false,_STREAMTYPE_VIDEO);
  sendSignal(_STREAM_MASK_IS_DATA,false,_STREAMTYPE_VIDEO);
  return true;
}

int OutputStream::openWindow(int , int ,const char* ) {
  sendSignal(_STREAM_MASK_IS_INIT,true,_STREAMTYPE_VIDEO);
  return true;
}

int OutputStream::x11WindowId() {
 cout << "direct virtual call OutputStream::x11WindowId()" << endl;
 return -1;
}

void OutputStream::closeWindow() {
  cerr << "direct virtual call OutputStream::closeWindow"<<endl;
  exit(0);
}

void OutputStream::flushWindow() {
  sendSignal(_STREAM_MASK_IS_EOF,true,_STREAMTYPE_VIDEO);
} 


PictureArray* OutputStream::lockPictureArray() {
  cerr << "direct virtual call OutputStream::lockPictureArray"<<endl;
  exit(0);
  return NULL;
}


void OutputStream::unlockPictureArray(PictureArray* ) {
  sendSignal(_STREAM_MASK_IS_DATA,true,_STREAMTYPE_VIDEO);
}





int OutputStream::getOutputInit() {
  cerr << "direct virtual call OutputStream::getOutputInit"<<endl;
  exit(0);
  return false;
}


void OutputStream::setOutputInit(int lInit) {
  cerr << "direct virtual call OutputStream::setOutputInit:"<<lInit<<endl;
  exit(0);
}



void OutputStream::writeInfo(PluginInfo* ) {

}


void OutputStream::config(const char* key,
			  const char* value,void* user_data) {
  cerr << "direct virtual call OutputStream::config"<<endl;
  printf("key:%s\n",key);
  printf("value:%s\n",value);
  printf("user_data:%p\n",user_data);
  exit(0);
}
 
int OutputStream::getFrameusec() {
  cerr << "direct virtual call OutputStream::getFrameusec"<<endl;
  return 0;
}
 


int OutputStream::waitStreamState(int method,int mask,int streamType) {

  int* waitState=NULL;
  switch(streamType) {
  case _STREAMTYPE_AUDIO:
    waitState=&audioState;
    break;
  case _STREAMTYPE_VIDEO:
    waitState=&videoState;
    break;
  default:
    cout << "unknown streamType:"<<streamType
	 <<" in OutputStream::waitStreamState"<<endl;
    exit(0);
  }

  if (method == _OUTPUT_WAIT_METHOD_BLOCK) {
    abs_thread_mutex_lock(&stateChangeMut);
    while ((*waitState &= mask)==0) {
      cout << "waitStreamState:"<<waitState<<endl;
      cout << "mask:"<<mask<<endl;
      abs_thread_cond_wait(&stateChangeCond,&stateChangeMut);
    }
    abs_thread_mutex_unlock(&stateChangeMut);
    return true;
  }
    
  int back=false;
  if (method == _OUTPUT_WAIT_METHOD_POLL) {
    abs_thread_mutex_lock(&stateChangeMut);
    back=*waitState;
    abs_thread_mutex_unlock(&stateChangeMut);
    return back;
  }    
  cout << " OutputStream::waitStreamState method not implemented"<<endl;
  exit(0);
  return 0; 
}