source: trunk/src/testing/app/hd-video-player/output_sail.cpp @ 4

Revision 4, 9.6 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
1/******************************************************************************
2 * SAGE - Scalable Adaptive Graphics Environment
3 *
4 * Copyright (C) 2004 Electronic Visualization Laboratory,
5 * University of Illinois at Chicago
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above
15 *    copyright notice, this list of conditions and the following disclaimer
16 *    in the documentation and/or other materials provided with the distribution.
17 *  * Neither the name of the University of Illinois at Chicago nor
18 *    the names of its contributors may be used to endorse or promote
19 *    products derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * Direct questions, comments etc about SAGE to http://www.evl.uic.edu/cavern/forum/
34 *
35 *****************************************************************************/
36
37#include "stdafx.h"
38#include "output_sail.h"
39
40
41C_Output_sail::C_Output_sail() {
42        SetZero();
43        sageInf = NULL;
44 }
45
46void C_Output_sail::SetZero() {
47        m_width = 0;
48        m_height = 0;
49        m_byte_pixel = 0;
50        m_color_mode = 0;
51        m_flag_empty = 0;
52        m_frame_buf = 0;
53
54        m_execConfigName = NULL;
55        m_nwID = 0;
56
57        m_flag_notinit = 1;
58        m_output_addr = 0;
59        m_output_port = 0;
60
61        //m_audioOn =true;
62        m_sailstarted =false;
63}
64
65//-------------------------------------------------------------------------------------
66void C_Output_sail::setSailEnv(char* execConfigName, int nwID) {
67        m_execConfigName = execConfigName;
68        m_nwID = nwID;
69
70        fprintf(stderr, "\r\n m_exec : %s , m_nwID : %d", execConfigName, nwID);
71}
72
73
74//-------------------------------------------------------------------------------------
75int C_Output_sail::sailInit()
76{
77    sailConfig scfg;
78    sageRect glImageMap;
79
80        glImageMap.left = 0.0;
81    glImageMap.right = 1.0;
82    glImageMap.bottom = 0.0;
83    glImageMap.top = 1.0;
84
85
86        if(sageInf != NULL) {
87                sageInf->shutdown();
88                delete sageInf;
89                sageInf = NULL;
90        }
91        sageInf = new sail();
92
93#if defined(SAGE_VERSION1)
94        scfg.cfgFile = strdup("sage.conf");
95    scfg.appName = strdup("svt");
96    scfg.rank = 0;
97    scfg.ip = NULL; // strdup("192.168.81.120");
98        scfg.execConfig = NULL;
99    scfg.nwID = 2;
100
101        if(m_color_mode == RGB24) {
102                m_byte_pixel = 3;
103                scfg.colorDepth = 24;
104            scfg.pixFmt = TVPIXFMT_888_INV;
105        } else if(m_color_mode == RGB16) {
106                m_byte_pixel = 2;
107                scfg.colorDepth = 16;
108            scfg.pixFmt = TVPIXFMT_565;
109        } else return -1;
110
111    scfg.resX = m_width;
112    scfg.resY = m_height;
113    scfg.imageMap = glImageMap;
114    scfg.rowOrd = BOTTOM_TO_TOP;
115
116        //m_frame_buf = (unsigned char *)malloc(m_width * m_height * m_byte_pixel);
117    //memset(m_frame_buf, 0, scfg.resX *scfg.resY*m_byte_pixel);
118
119#else
120        sage::win32Init();
121
122        if(m_audioOn) {
123#if defined (SAGE_AUDIO)
124                scfg.framePerBuffer = m_framePerBuffer;
125#endif
126        }
127
128        scfg.init("svt.conf");
129        scfg.setAppName("svt");
130        scfg.rank = 0;
131        scfg.master = true;
132        scfg.nwID = 1;
133        scfg.syncPort = 13000;
134        scfg.nodeNum = 1;
135        scfg.blockX= 64; // 128; // 64;
136        scfg.blockY= 64; // 90;  // 64;
137        sprintf(scfg.fsIP, "%s", m_output_addr);
138
139        if(m_color_mode == RGB24) {
140                m_byte_pixel = 3;
141            scfg.pixFmt = PIXFMT_888_INV; //PIXFMT_888;
142                scfg.rowOrd = BOTTOM_TO_TOP;
143                sage::printLog("SAGE> color mode 24 888 bits\n");
144        } else if(m_color_mode == RGB16) {
145                m_byte_pixel = 2;
146            scfg.pixFmt = PIXFMT_565;
147                scfg.rowOrd = BOTTOM_TO_TOP;
148                sage::printLog("SAGE> color mode 16 565 bits\n");
149        } else if(m_color_mode == YUV) {
150                m_byte_pixel = 2;
151            scfg.pixFmt = PIXFMT_YUV;
152                scfg.rowOrd = TOP_TO_BOTTOM;
153                sage::printLog("SAGE> color mode YUV bits\n");
154        } else return -1;
155
156    scfg.resX = m_width;
157    scfg.resY = m_height;
158    scfg.imageMap = glImageMap;
159
160                // Position and size on the display side
161    scfg.winX = 0;
162    scfg.winY = 0;
163    scfg.winWidth = m_width*1;
164    scfg.winHeight = m_height*1;
165
166        sage::printLog("SAGE> Init: w %d h %d\n\n", m_width, m_height);
167        // for setting up audio configuration
168        if(m_audioOn) {
169#if defined (SAGE_AUDIO)
170                scfg.audioMode = m_audioMode;
171                scfg.audioPort = m_audioPort;
172                scfg.audioDeviceNum = m_audioDeviceNum;
173                scfg.sampleFmt = m_sampleFmt;
174                scfg.samplingRate = m_samplingRate;
175                scfg.channels = m_channels;
176                //scfg.framePerBuffer = m_framePerBuffer;
177                scfg.audioOn = true;
178                if(m_audioMode == SAGE_AUDIO_APP) {
179                        scfg.audioBuffSize = m_abuffsize;
180                }
181#endif
182        }
183
184#endif
185
186        m_sailstarted  = true;
187    sageInf->init(scfg);
188
189        return 0;
190}
191
192//-------------------------------------------------------------------------------------
193int C_Output_sail::init(int width, int height, int color_mode, char* output_addr, int output_port)
194{
195        SetZero();
196    m_width = width;
197    m_height = height;
198
199    if(output_addr == NULL)
200        {
201            fprintf(stderr, "\r\n Output Address is needed");
202//            g_done_control = 1;
203            return -1;
204    } else
205                m_output_addr = strdup(output_addr);
206
207    m_output_port = output_port;
208    m_color_mode = color_mode;
209
210#if defined (SAGE_AUDIO)
211        if(m_audioOn == false) {
212                if(m_flag_notinit) {
213            return sailInit();
214            //m_flag_notinit = 0;
215                }
216        }
217#endif
218
219    return 0;
220}
221
222
223
224//-------------------------------------------------------------------------------------
225int C_Output_sail::push_data(unsigned char* buf , int buf_len)
226{
227                static int framenum = 0;
228
229        // check some messages
230        sageMessage msg;
231        if (sageInf->checkMsg(msg, false) > 0) {
232                switch (msg.getCode()) {
233                        case APP_QUIT : {
234                                //g_done_control = 1;
235                                return -1;
236                        }
237
238                }
239        }
240
241#if defined(SAGE_VERSION1)
242                //memcpy(m_frame_buf, buf, m_width *m_height*m_byte_pixel);
243                if(buf == NULL || sageInf->swapBuffer(buf) == -1) {
244                        //g_done_control = 1;
245                        return -1;
246                }
247#else
248
249#endif
250                if(buf == NULL)
251                {
252                        //g_done_control = 1;
253                        return -1;
254                }
255                else
256                {
257                        switch (FrameRate) {
258                                case FR10:
259                                        if ( (framenum % 3) != 0 ) {
260                                                framenum = (framenum + 1) % 30;
261                                                return 0;
262                                        }
263                                        break;
264                                case FR15:
265                                        if ( (framenum % 2) == 0 ) {
266                                                framenum = (framenum + 1) % 30;
267                                                return 0;
268                                        }
269                                        break;
270                                case FR20:
271                                        if ( (framenum % 3) == 0 ) {
272                                                framenum = (framenum + 1) % 30;
273                                                return 0;
274                                        }
275                                        break;
276                                case FR25:
277                                        if ( (framenum == 1) || (framenum == 7) || (framenum == 13) || (framenum == 19) || (framenum == 25) ) {
278                                                framenum = (framenum + 1) % 30;
279                                                return 0;
280                                        }
281                                        break;
282                                case FR30:
283                                        break;
284                                default:
285                                        break;
286                        }
287
288                        void *m_frame = sageInf->getBuffer();
289
290                        memcpy(m_frame, buf, m_width *m_height*m_byte_pixel);
291
292                        sageInf->swapBuffer();
293
294                        framenum = (framenum + 1) % 30;
295                }
296
297                return 0;
298}
299
300//-------------------------------------------------------------------------------------
301int C_Output_sail::push_audiodata(unsigned char* buf, int buf_len)
302{
303#if defined(SAGE_AUDIO)
304        sageInf->pushAudioData(buf_len, (void*)buf);
305#endif
306        return 0;
307}
308
309void C_Output_sail::setAudioOn(bool on)
310{
311        m_audioOn= on;
312}
313
314
315int C_Output_sail::init(int size)
316{
317        // for the test
318#if defined (SAGE_AUDIO)
319        m_audioMode = SAGE_AUDIO_APP;
320        m_sampleFmt = SAGE_SAMPLE_INT16;
321#endif
322        m_audioPort = 26000;
323        m_audioDeviceNum = -1;
324        m_samplingRate = 48000; //48000;                        // audio sampling rate : default-44100
325        m_channels =2;                          // number of audio channel
326        m_framePerBuffer = 512;//1024; // 1536;         // audio frames per buffer 1536 /  2 = 768
327        m_abuffsize = size;
328
329        if(m_flag_notinit) {
330        return sailInit();
331        //m_flag_notinit = 0;
332        }
333        return -1;
334}
335
336int C_Output_sail::initAudioCaptureMode()
337{
338#if defined (SAGE_AUDIO)
339        m_audioMode = SAGE_AUDIO_CAPTURE;
340        m_sampleFmt = SAGE_SAMPLE_INT16;
341#endif
342        m_audioPort = 26000;
343        m_audioDeviceNum = 0;
344        m_samplingRate = 44100;                 // audio sampling rate : default-44100
345        m_channels =2;                                  // number of audio channel
346        m_framePerBuffer = 512; // 1536;                // audio frames per buffer 1024 /  2 = 512
347
348        if(m_flag_notinit) {
349        return sailInit();
350        //m_flag_notinit = 0;
351        }
352        return -1;
353}
354
355void C_Output_sail::shutdown()
356{
357        if(m_sailstarted == true) {
358#if defined (SAGE_AUDIO)
359                // Question ????
360                //sageInf->stop();
361#endif
362                sageInf->shutdown();
363                m_sailstarted = false;
364                Sleep(100);
365                if(sageInf) {
366                        delete sageInf;
367                        sageInf = NULL;
368                }
369        }
370}
371
372C_Output_sail::~C_Output_sail ()
373{
374                if(sageInf) {
375                        sageInf->shutdown();
376                        delete sageInf;
377                        sageInf = NULL;
378                }
379}
380
381
Note: See TracBrowser for help on using the repository browser.