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

« back to all changes in this revision

Viewing changes to mpeglib_artsplug/mpeglibartsplay.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
// vim:ts=2:sw=2:sts=2:et
 
2
/**
 
3
   Starter for plugins.
 
4
   The plugins are identified by their extension
 
5
 
 
6
   .wav ->WavPlayObject
 
7
   .mp3 ->MP3PlayObject
 
8
   .mpg ->MPGPlayObject
 
9
   .ogg ->OGGPlayObject
 
10
*/
 
11
 
 
12
 
 
13
#include "soundserver.h"
 
14
#include "kmedia2.h"
 
15
 
 
16
#ifdef HAVE_CONFIG_H
 
17
#include "config.h"
 
18
#endif
 
19
 
 
20
 
 
21
#include <stdio.h>
 
22
#include <stdlib.h>
 
23
#include <vector>
 
24
#include <string>
 
25
#include <iostream>
 
26
 
 
27
using namespace std;
 
28
using namespace Arts;
 
29
 
 
30
#if defined(HAVE_GETOPT_H) 
 
31
#include <getopt.h>
 
32
#endif
 
33
 
 
34
 
 
35
string file1;
 
36
string file2;
 
37
 
 
38
Dispatcher* d=NULL;
 
39
SimpleSoundServer* server=NULL;
 
40
 
 
41
 
 
42
 
 
43
void usage() {
 
44
  cout << "mpeglibartsply command line tool for arts playobjects"<<endl;
 
45
  cout << "Usage : mpeglibartsply [url]"<<endl;
 
46
  cout << endl;
 
47
  cout << "-1 : create/destroy PlayObject test."<<endl;
 
48
  cout << "-2 : create/seek/play/destroy PlayObject test."<<endl;
 
49
  cout << "-3 : torture seek implementation test"<<endl;
 
50
  cout << "-h : help"<<endl;
 
51
  cout << endl;
 
52
  cout << "THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! " \
 
53
       << "USE AT YOUR OWN RISK!"<<endl;
 
54
  cout << endl;
 
55
  exit(0);
 
56
}
 
57
 
 
58
 
 
59
void initServer() {
 
60
  d=new Dispatcher();
 
61
  server= new SimpleSoundServer (Reference("global:Arts_SimpleSoundServer"));
 
62
  
 
63
  if(server->isNull()) {
 
64
    cerr << "Can't connect to sound server" << endl;
 
65
    exit(0);
 
66
  }
 
67
 
 
68
}
 
69
 
 
70
 
 
71
void destroyServer() {
 
72
  delete server;
 
73
  delete d;
 
74
}
 
75
 
 
76
/**
 
77
   create destroy playobjects without playing anything
 
78
*/
 
79
void doStress1() {
 
80
  int cnt=0;
 
81
  while (cnt < 10000) {
 
82
    PlayObject play=server->createPlayObject(file1);
 
83
    cout << "cnt:"<<cnt++<<endl;
 
84
  }
 
85
}
 
86
 
 
87
/**
 
88
   create playobjects playing some time, do seek play destroy
 
89
*/
 
90
void doStress2() {
 
91
  int cnt=0;
 
92
  while (cnt < 1000) {
 
93
    PlayObject play=server->createPlayObject(file1);
 
94
    play.play();
 
95
    sleep(3);
 
96
    poTime seekTime;
 
97
    seekTime.seconds=100;
 
98
    seekTime.ms=0;
 
99
    play.seek(seekTime);
 
100
    cout << "cnt:"<<cnt++<<endl;
 
101
  }
 
102
}
 
103
 
 
104
/**
 
105
   create playobject seek random play seek again
 
106
*/
 
107
void doStress3() {
 
108
  int cnt=0;
 
109
  PlayObject play=server->createPlayObject(file1);
 
110
  play.play();
 
111
  long secs=0;
 
112
  while(1) {
 
113
    cout << "waiting for length info.."<<endl;
 
114
    sleep(3);
 
115
    poTime length=play.overallTime();
 
116
    secs=length.seconds;
 
117
    if (secs > 0) break;
 
118
  }
 
119
  // do not jump near to end, the danger that
 
120
  // we get an eof is to high
 
121
  if (secs < 100) {
 
122
    cout << "file to short for test"<<endl;
 
123
    exit(-1);
 
124
  }
 
125
  secs-=10;
 
126
  poTime seekTime;
 
127
  poTime startTime;
 
128
  startTime.seconds=0;
 
129
  startTime.ms=0;
 
130
 
 
131
  while (cnt < 1000) {
 
132
 
 
133
    //
 
134
    // seek to a know position
 
135
    //
 
136
    play.seek(startTime);
 
137
    // now wait for seek completion we need a poll here
 
138
    while(1) {
 
139
      poTime current=play.currentTime();
 
140
      if (current.seconds < 5) {
 
141
        break;
 
142
      }
 
143
      usleep(50000);
 
144
    }
 
145
 
 
146
    //
 
147
    // now we know that the playObject is near the beginning
 
148
    //
 
149
 
 
150
    int randNo=rand();
 
151
    long seekPos=(long)(((float)randNo*(float)secs)/(float)RAND_MAX);
 
152
    // need to jump over the start area
 
153
 
 
154
    seekPos+=5;
 
155
    cout << "seek to :"<<seekPos
 
156
         << " | cnt:"<<cnt++
 
157
         << " of 1000"<<endl;
 
158
    seekTime.seconds=seekPos;
 
159
    seekTime.ms=0;
 
160
    play.seek(seekTime);
 
161
    // now wait for seek completion we need a poll here
 
162
    while(1) {
 
163
      poTime current=play.currentTime();
 
164
      if (current.seconds > seekPos) {
 
165
        break;
 
166
      }
 
167
      if (current.seconds == seekPos) {
 
168
        if (current.ms > 0) {
 
169
          break;
 
170
        }
 
171
      }      
 
172
      usleep(50000);
 
173
    }
 
174
    
 
175
 
 
176
  }
 
177
  cout << "stresstest successfully passed."<<endl;
 
178
}
 
179
 
 
180
 
 
181
int main(int argc, char **argv) {
 
182
  int testNr=0;
 
183
  int c;
 
184
  initServer();
 
185
 
 
186
  while(1) { 
 
187
    c = getopt (argc, argv, "123456h");
 
188
    if (c == -1) break;
 
189
    switch(c) {
 
190
    case '1': {    
 
191
      testNr=1;
 
192
      break;
 
193
    }
 
194
    case '2': {
 
195
      testNr=2;
 
196
      break;
 
197
    }
 
198
    case '3': {
 
199
      testNr=3;
 
200
      break;
 
201
    }
 
202
    case '4': {
 
203
      testNr=4;
 
204
      break;
 
205
    }
 
206
    case '5': {
 
207
      testNr=5;
 
208
      break;
 
209
    }
 
210
    case '6': {
 
211
      testNr=5;
 
212
      break;
 
213
    }
 
214
    case 'h': {
 
215
      usage();
 
216
      break;
 
217
    }
 
218
    default:
 
219
      printf ("?? getopt returned character code 0%o ??\n", c);
 
220
      usage();
 
221
      exit(-1);
 
222
    }
 
223
  }
 
224
 
 
225
  if (optind >= argc ) {
 
226
    usage();
 
227
    exit(-1);
 
228
  }
 
229
 
 
230
  if (optind < argc ) {
 
231
    file1=argv[optind];
 
232
    optind++;
 
233
    file2=file1;
 
234
  }
 
235
  if (optind < argc ) {
 
236
    file2=argv[optind];
 
237
  }  
 
238
 
 
239
 
 
240
  switch(testNr) {
 
241
  case 1: {
 
242
    doStress1();
 
243
    break;
 
244
  }
 
245
  case 2: {
 
246
    doStress2();
 
247
    break;
 
248
  }
 
249
  case 3: {
 
250
    doStress3();
 
251
    break;
 
252
  }
 
253
  default:
 
254
    if (file1[0] != '/') {
 
255
      char buf[PATH_MAX+1];
 
256
      char *path = getcwd(buf, PATH_MAX - file1.length());
 
257
      if (path) {
 
258
        file1.insert(0, "/");
 
259
        file1.insert(0, path);
 
260
      }
 
261
    }
 
262
    PlayObject play=server->createPlayObject(file1);
 
263
    if (play.isNull()) {
 
264
      cout << "cannot play this"<<endl;
 
265
      destroyServer();
 
266
      exit(0);
 
267
    }
 
268
    play.play();
 
269
    while (play.state() != posIdle) {
 
270
      sleep(1);
 
271
    }
 
272
  }
 
273
 
 
274
  destroyServer();
 
275
}