~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/example/yaf/yafxplayer/yafOutputStream.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  concret OutputClass for yaf text consol player
 
3
  Copyright (C) 1999  Martin Vogt
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU Library General Public License as published by
 
7
  the Free Software Foundation.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
#include "yafOutputStream.h"
 
15
 
 
16
 
 
17
#define _AUDIO_DELAY_STAMPS 200
 
18
 
 
19
 
 
20
 
 
21
 
 
22
YafOutputStream::YafOutputStream(InputInterface* input) {
 
23
  lInternalDevice=false;
 
24
  bytes=0;
 
25
  allWrite=0;
 
26
  writeToBuffer=0;
 
27
  lOpen=false;
 
28
  directOutput=OutPlugin::createOutputStream(_OUTPUT_LOCAL,_OUTPUT_THREADSAFE);
 
29
 
 
30
 
 
31
  this->input=input;
 
32
  ::pipe(fd);
 
33
 
 
34
  if (errno < 0) {
 
35
    perror("YafOutputStream pipe");
 
36
    exit(0);
 
37
  }
 
38
  input->addFileDescriptor(fd[0]);
 
39
}
 
40
 
 
41
 
 
42
YafOutputStream::~YafOutputStream() {
 
43
  delete directOutput;
 
44
}
 
45
 
 
46
 
 
47
int YafOutputStream::audioSetup(int frequency,int stereo,
 
48
                                int sign,int big,int bits) {
 
49
 
 
50
  cout << "Command:0 Msg:streamInfo-Start"<<endl;
 
51
  cout << "Command:0 Msg:streamInfo-Channels "<<stereo+1<<endl;
 
52
  
 
53
  cout << "Command:0 Msg:streamInfo-SampleSize "<<bits<<endl;
 
54
  cout << "Command:0 Msg:streamInfo-Speed "<<frequency<<endl;
 
55
  cout << "Command:0 Msg:streamInfo-End"<<endl;
 
56
 
 
57
  directOutput->audioSetup(frequency,stereo,sign,big,bits);
 
58
 
 
59
  return true;
 
60
}
 
61
 
 
62
void YafOutputStream::audioOpen() {
 
63
  if (lInternalDevice) {
 
64
    directOutput->audioOpen();
 
65
  }
 
66
}
 
67
 
 
68
void YafOutputStream::audioClose(void) {
 
69
  if (lInternalDevice) {
 
70
    // never close internal audio, because
 
71
    // its not possible to open it again fast enough
 
72
    //directOutput->audioClose();
 
73
  } else {
 
74
    directOutput->audioClose();
 
75
  }
 
76
}
 
77
 
 
78
 
 
79
int YafOutputStream::audioPlay(TimeStamp* startStamp,
 
80
                               TimeStamp* endStamp,char *buffer, int size) {
 
81
 
 
82
  int ret=0;
 
83
  if (lInternalDevice) {
 
84
    directOutput->audioPlay(startStamp,endStamp,buffer,size);
 
85
  }
 
86
 
 
87
 
 
88
  
 
89
  if (lOpen) {
 
90
    // if we are doing video, we even have to sync
 
91
    // audio writing.
 
92
    // Because yaf sends the audio data to another process
 
93
    // but the video data _not_ the audio data is directly
 
94
    // flushed here, but maybe stay on the other side
 
95
    // in a very big buffer
 
96
    // until the protocol has no better handle
 
97
    // for this, we must make sure to
 
98
    // dont get the buffer on the other
 
99
    // side too big.
 
100
    // we sleep some time until we write the next sample
 
101
 
 
102
 
 
103
 
 
104
 
 
105
    directOutput->audioPlay(startStamp,endStamp,buffer,size);
 
106
 
 
107
 
 
108
    ret=::send(sd,buffer,size,0);
 
109
 
 
110
 
 
111
 
 
112
 
 
113
    
 
114
 
 
115
    if (ret < 0) {
 
116
      
 
117
      closeStream();
 
118
      cout << "fifo error in streamWriter";
 
119
      perror("writeStream");
 
120
      exit(-1);
 
121
      return ret;
 
122
    }
 
123
 
 
124
    bytes=bytes+size;
 
125
    allWrite+=size;
 
126
    return size;
 
127
  }
 
128
 
 
129
    
 
130
 
 
131
 
 
132
  bytes=bytes+size;
 
133
  allWrite+=size;
 
134
  return size;
 
135
}
 
136
 
 
137
 
 
138
void YafOutputStream::audioFlush() {
 
139
  // notify command line, that plugin state changed
 
140
  input->write(fd[1],"update\n");
 
141
 
 
142
  if (lInternalDevice) {
 
143
    directOutput->audioFlush();
 
144
  }
 
145
}
 
146
 
 
147
int YafOutputStream::getPreferredDeliverSize() {
 
148
  return directOutput->getPreferredDeliverSize();
 
149
}
 
150
 
 
151
 
 
152
 
 
153
 
 
154
int YafOutputStream::openWindow(int width, int height,const char *title) {
 
155
  return directOutput->openWindow(width,height,title);
 
156
}
 
157
 
 
158
 
 
159
void YafOutputStream::closeWindow() {
 
160
  directOutput->closeWindow();
 
161
}
 
162
 
 
163
void YafOutputStream::flushWindow() {
 
164
  directOutput->flushWindow();
 
165
 
166
 
 
167
PictureArray* YafOutputStream::lockPictureArray() {
 
168
  return directOutput->lockPictureArray();
 
169
}
 
170
 
 
171
 
 
172
void YafOutputStream::unlockPictureArray(PictureArray* pictureArray) {
 
173
  directOutput->unlockPictureArray(pictureArray);
 
174
}
 
175
 
 
176
 
 
177
int YafOutputStream::getFrameusec() {
 
178
  return directOutput->getFrameusec();
 
179
}
 
180
 
 
181
 
 
182
 
 
183
int YafOutputStream::getOutputInit() {
 
184
  return directOutput->getOutputInit();
 
185
}
 
186
 
 
187
 
 
188
void YafOutputStream::setOutputInit(int lInit) {
 
189
  directOutput->setOutputInit(lInit);
 
190
}
 
191
 
 
192
 
 
193
 
 
194
 
 
195
void YafOutputStream::writeInfo(PluginInfo* pluginInfo) {
 
196
  char* url=pluginInfo->getUrl();
 
197
  const char* nameStart=strrchr(url,'/');
 
198
 
 
199
  if (nameStart==NULL) {
 
200
    nameStart="noname";
 
201
  } else {
 
202
    nameStart++;
 
203
    if (strlen(nameStart) == 0) {
 
204
      nameStart="noname";
 
205
    }
 
206
  }
 
207
      
 
208
  cout << "Command:0 Msg:musicinfo-Start"<<endl;
 
209
  cout << "Command:0 Msg:song_filename "<<pluginInfo->getUrl()<<endl;
 
210
  cout << "Command:0 Msg:song_name "<<nameStart<<endl;
 
211
  cout << "Command:0 Msg:song_len  "<<pluginInfo->getLength()<<endl;
 
212
  cout << "Command:0 Msg:song_jumps 0"<<endl;
 
213
  cout << "Command:0 Msg:musicinfo-End"<<endl;
 
214
}
 
215
 
 
216
 
 
217
 
 
218
 
 
219
 
 
220
 
 
221
void YafOutputStream::setBytesCounter(long value) {
 
222
  bytes=value;
 
223
  writeToBuffer=value;
 
224
}
 
225
 
 
226
 
 
227
 
 
228
int YafOutputStream::isOpenStream() {
 
229
  return lOpen;
 
230
}
 
231
 
 
232
 
 
233
void YafOutputStream::setStreamFile(const char* filename) {
 
234
  if (lOpen == true) {
 
235
    closeStream();
 
236
  }
 
237
  this->filename=filename;
 
238
}
 
239
 
 
240
 
 
241
int YafOutputStream::openStream() {
 
242
  if (lOpen == true) {
 
243
    cout << "stream already open! call ignored"<<endl;
 
244
    return sd;
 
245
  }
 
246
  sd=::socket(AF_UNIX,SOCK_STREAM,0);
 
247
  if (sd < 0) {
 
248
    perror("sd-Socket StreamWriter");exit(1);
 
249
  }
 
250
  
 
251
  unsigned int i=0;
 
252
  sockad.sun_family=AF_UNIX;
 
253
 
 
254
  while(i<strlen(filename)) {
 
255
        sockad.sun_path[i]=filename[i];
 
256
        i++;
 
257
  }
 
258
  sockad.sun_path[i]=0;
 
259
  if (::connect(sd,(sockaddr*)&sockad,strlen(filename)+2)<0) {
 
260
    perror("connect StreamWriter");exit(1);
 
261
  }
 
262
  if (sd > 0) {
 
263
    lOpen=true;
 
264
  }
 
265
  return sd;
 
266
}
 
267
 
 
268
 
 
269
int YafOutputStream::closeStream() {
 
270
  int ret=0;
 
271
  if (lOpen) {
 
272
    ret=close(sd);
 
273
    lOpen=false;
 
274
    filename=NULL;
 
275
  } else {
 
276
    cout << "stream already closed. call ignored!"<<endl;
 
277
  }
 
278
  return ret;
 
279
}
 
280
 
 
281
 
 
282
void YafOutputStream::internalDevice(int lInternal){
 
283
  lInternalDevice=lInternal;
 
284
}
 
285
 
 
286
 
 
287
 
 
288
long YafOutputStream::getBytesCounter() {
 
289
  return bytes;
 
290
}
 
291
 
 
292
 
 
293
long YafOutputStream::getAllWriteCounter() {
 
294
  return allWrite;
 
295
}
 
296
 
 
297
 
 
298
 
 
299
void YafOutputStream::config(const char* key,const char* value,
 
300
                             void* user_data) {
 
301
 
 
302
  directOutput->config(key,value,user_data);
 
303
  
 
304
}
 
305