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

« back to all changes in this revision

Viewing changes to mpeglib/example/yaf/yafyuv/yuv_control.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
  generic interactive controler 
 
3
  Copyright (C) 1998  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
 
 
15
// Set for local include
 
16
#define DIRECT_INCLUDE
 
17
 
 
18
#include "../yafcore/yaf_control.h"
 
19
#include "../yafxplayer/inputDecoderYAF.h"
 
20
 
 
21
 
 
22
#include <math.h>
 
23
 
 
24
 
 
25
 
 
26
// we include our plugin here
 
27
#include "../../../lib/yuv/yuvPlugin.h"
 
28
 
 
29
#if defined(HAVE_GETOPT_H) 
 
30
#include <getopt.h>
 
31
#endif
 
32
 
 
33
 
 
34
void control_yuv(InputInterface* input,OutputInterface* output,
 
35
                 InputDecoder* decoder) {
 
36
 
 
37
 
 
38
  cout<< "Command:0 Msg:protocol yaf-0.1" << endl;
 
39
  cout<< "Command:0 Msg:implements xplayer" << endl;
 
40
  cout<< "Command:0 Msg:decoder yuv Version:0.0.2" << endl;
 
41
  cout<< "Command:0 Msg:mimetypes vide/yuv1;" << endl;
 
42
  cout<< "Command:0 Msg:comment yuv Plugin by Martin Vogt" << endl;
 
43
  cout<< "Command:0 Msg:comment yaf port by mvogt@rhrk.uni-kl.de"<<endl;
 
44
  cout<< "Command:0 Msg:comment enter 'help' " << endl;
 
45
 
 
46
 
 
47
  
 
48
  yaf_control(input,output,decoder);
 
49
}
 
50
 
 
51
 
 
52
void usage() {
 
53
  cout << "yaf-yuv is a interactive frontend for the still image decoder"
 
54
       <<endl;
 
55
  cout << "Usage : yaf-yuv [w:g:y:f:hr:] <file.raw> [url]"<<endl;
 
56
  cout << endl;
 
57
  cout << "-w : width of raw yuv stream in pixel"<<endl;
 
58
  cout << "-g : heigth of raw yuv stream in pixel"<<endl;
 
59
  cout << "-h : help"<<endl;
 
60
  cout << "-y : set image Format:"<<endl;
 
61
  cout << "                      1   : yuv lum/Cr/Cb"<<endl;
 
62
  cout << "                      2   : yuv lum/Cb/Cr"<<endl;
 
63
  cout << "                      3   : rgb 24 BIT"<<endl;
 
64
  cout << "                      4   : rgb 24 BIT (flipped)"<<endl;
 
65
 
 
66
  cout << "-f : [1..n] frames per second"<<endl;
 
67
 
 
68
  cout << endl;
 
69
  cout << "THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! " \
 
70
       << "USE AT YOUR OWN RISK!"<<endl;
 
71
  cout << endl;
 
72
  cout << "for more help type 'help' in interactive mode"<<endl;
 
73
}
 
74
 
 
75
 
 
76
int readFormat(int* w,int* h,char* filename) {
 
77
  char formatFileName[100];
 
78
  FILE* file=NULL;
 
79
  snprintf(formatFileName,100,"%s.format",filename);
 
80
  cout << "open:"<<formatFileName<<endl;
 
81
  file=fopen(formatFileName,"r");
 
82
  if (file == NULL) {
 
83
    cout << "no format file found"<<endl;
 
84
    return false;
 
85
  }
 
86
 
 
87
  if (fscanf(file,"Version 0.1\nw:%dh:%d\n",w,h)==2) {
 
88
    cout << "read ! w:"<<*w<<"h:"<<*h<<endl;
 
89
    return true;
 
90
  }
 
91
 
 
92
  
 
93
  cout << "format file mismatch"<<endl;
 
94
  return false;
 
95
}
 
96
 
 
97
 
 
98
int main(int argc, char** argv) {
 
99
  int c;
 
100
  int lInternalAudio=true;
 
101
  char* width=NULL;
 
102
  char* height=NULL;
 
103
  int fps=1;
 
104
 
 
105
  pow(6.0,3.0);            // fixes bug in __math.h
 
106
 
 
107
 
 
108
 
 
109
  
 
110
  InputInterface* input=new InputInterface();
 
111
 
 
112
  OutputInterface output(&cout);
 
113
 
 
114
  YafOutputStream* yafOutput=new YafOutputStream(input);
 
115
 
 
116
  YUVPlugin* plugin=new YUVPlugin();
 
117
 
 
118
  plugin->setOutputPlugin(yafOutput);
 
119
  InputDecoderYAF decoder(plugin,yafOutput);
 
120
  
 
121
 
 
122
 
 
123
  while(1) { 
 
124
    c = getopt (argc, argv, "w:g:y:hf:");
 
125
    if (c == -1) break;
 
126
    switch(c) {
 
127
    case 'a': {    
 
128
      lInternalAudio=false;
 
129
      break;
 
130
    }
 
131
    case 'h': {
 
132
      cout << "query for help"<<endl;
 
133
      usage();
 
134
      exit(0);
 
135
    }
 
136
    case 'w': {    
 
137
      width=optarg;
 
138
      printf("setting width:%s\n",width);
 
139
      break;
 
140
    }
 
141
    case 'f': {    
 
142
      fps=atoi(optarg);
 
143
      if (fps <= 0) {
 
144
        cout << "wrong fps. must be > 0"<<endl;
 
145
        exit(0);
 
146
      }
 
147
      break;
 
148
    }
 
149
    case 'g': {
 
150
      height=optarg;
 
151
      printf("setting height:%s\n",height);
 
152
      break;
 
153
    }
 
154
    case 'y': {
 
155
      cout << "config:imageType:"<<optarg<<endl;
 
156
      plugin->config("imageType",optarg,NULL);
 
157
      break;
 
158
    }
 
159
 
 
160
    default:
 
161
      printf ("?? getopt returned character code 0%o ??\n", c);
 
162
      usage();
 
163
      exit(-1);
 
164
    }
 
165
  }
 
166
  if (optind < argc ) {
 
167
    Buffer buffer(300);
 
168
    buffer.append("open ");
 
169
    buffer.append(argv[optind]);
 
170
    buffer.append("\n");
 
171
    
 
172
    input->addInputLine(&buffer);
 
173
 
 
174
  }
 
175
  if ((width == NULL) || (height == NULL)) {
 
176
    int w;
 
177
    int h;
 
178
    cout << "automatic try to read a .format file"<<endl;
 
179
    if (readFormat(&w,&h,argv[optind]) == false) {
 
180
      cout << "no format specified"<<endl;
 
181
      exit(-1);
 
182
    }
 
183
    width=new char[20];
 
184
    height=new char[20];
 
185
    snprintf(width,20,"%d",w);
 
186
    snprintf(height,20,"%d",h);
 
187
  }
 
188
 
 
189
  char* picPerSec=new char[20];
 
190
  snprintf(picPerSec,20,"%d",fps);
 
191
  
 
192
 
 
193
  plugin->config("picPerSec",picPerSec,NULL);
 
194
  plugin->config("height",height,NULL);
 
195
  plugin->config("width",width,NULL);
 
196
 
 
197
 
 
198
  yafOutput->internalDevice(lInternalAudio);
 
199
  control_yuv(input,&output,&decoder);
 
200
  delete plugin;
 
201
  delete yafOutput;
 
202
  delete input;
 
203
 
 
204
}
 
205