root/ossiedev/branches/deepanns/components/JPEG_VideoViewer/JPEG_VideoViewer.cpp @ 8886

Revision 8886, 6.4 KB (checked in by deepanns, 4 years ago)

updated query and configure for components

Line 
1/****************************************************************************
2
3Copyright 2006 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE JPEG_VideoViewer.
6
7OSSIE JPEG_VideoViewer is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12OSSIE JPEG_VideoViewer is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OSSIE JPEG_VideoViewer; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21****************************************************************************/
22
23
24#include <string>
25#include <iostream>
26#include "JPEG_VideoViewer.h"
27
28
29#define VIDEOMON 1
30
31unsigned int image_width = IMAGE_WIDTH;
32unsigned int image_height = IMAGE_HEIGHT;
33int owidth = 0;
34int oheight = 0;
35int testbpp=16;
36int autobright = 0;
37int bpp = 3;   
38SDL_Surface *pscreen;
39int format = VIDEO_PALETTE_JPEG;
40
41JPEG_VideoViewer_i::JPEG_VideoViewer_i(const char *uuid, omni_condition *condition)
42  : Resource_impl(uuid), component_running(condition)
43{
44    dataIn_0 = new standardInterfaces_i::realChar_p("JPEG_DataIn");
45
46
47    //Create the thread for the writer's processing function
48    processing_thread = new omni_thread(run, (void *) this);
49
50    //Start the thread containing the writer's processing function
51    processing_thread->start();
52
53}
54
55// Destructor
56JPEG_VideoViewer_i::~JPEG_VideoViewer_i(void)
57{   
58   delete dataIn_0;
59}
60
61// static function for omni thread
62void JPEG_VideoViewer_i::run( void * data )
63{
64    ((JPEG_VideoViewer_i*)data)->run_loop();
65}
66
67CORBA::Object_ptr JPEG_VideoViewer_i::getPort( const char* portName ) throw (CORBA::SystemException, CF::PortSupplier::UnknownPort)
68{
69    DEBUG(3, JPEG_VideoViewer, "getPort invoked with port name: " << portName)
70   
71    CORBA::Object_var p;
72
73    p = dataIn_0->getPort(portName);
74
75    if (!CORBA::is_nil(p))
76        return p._retn();
77
78    /*exception*/
79    throw CF::PortSupplier::UnknownPort();
80}
81
82void JPEG_VideoViewer_i::start() throw (CORBA::SystemException, CF::Resource::StartError)
83{
84    DEBUG(3, JPEG_VideoViewer, "start invoked")
85     
86               
87   
88    isRunning = true;
89
90}
91
92void JPEG_VideoViewer_i::stop() throw (CORBA::SystemException, CF::Resource::StopError)
93
94    DEBUG(3, JPEG_VideoViewer, "stop invoked")
95    //Uint32 frame_color = NULL;
96    //Uint8 r, g, b;
97
98    isRunning = false;
99   
100    //r = g = b = 0xFF;
101/*
102    frame_color = SDL_MapRGB(pscreen->format, r, g, b);
103    if(SDL_FillRect(pscreen, NULL, frame_color) < 0)
104    {
105      std::cout << "Error: Could not set frame to NULL" << std::endl;
106    }
107    SDL_UpdateRect (pscreen, 0, 0, 0, 0);       //update the entire screen
108*/
109}
110
111void JPEG_VideoViewer_i::releaseObject() throw (CORBA::SystemException, CF::LifeCycle::ReleaseError)
112{
113    DEBUG(3, JPEG_VideoViewer, "releaseObject invoked")
114   
115    if(VIDEOMON)
116    {
117      SDL_Quit();
118    }
119
120    component_running->signal();
121}
122
123void JPEG_VideoViewer_i::initialize() throw (CF::LifeCycle::InitializeError, CORBA::SystemException)
124{
125    DEBUG(3, JPEG_VideoViewer, "initialize invoked")
126
127         
128        if(VIDEOMON)
129  {
130    printf ("Initializing SDL.\n");
131
132    /* Initialize defaults, Video and Audio */
133          if ((SDL_InitSubSystem (SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1))
134    {
135                  printf ("Could not initialize SDL: %s.\n", SDL_GetError ());
136                  exit (-1);
137          }
138       
139          /* Clean up on exit */
140          atexit (SDL_Quit);
141          if(!owidth || !oheight)
142    {
143                  owidth        = image_width;
144                  oheight       = image_height;
145          }     
146          printf ("SDL initialized.\n");
147
148    printf("Creating Video Frame...\n");
149                pscreen =       SDL_SetVideoMode (owidth, oheight, testbpp, SDL_SWSURFACE);
150                if (pscreen == NULL)
151    {
152                  printf ("Couldn't set %d*%dx%d video mode: %s\n",     owidth, oheight,3 * 8, SDL_GetError ());
153                  exit (1);
154                }
155    SDL_WM_SetCaption ("OSSIE Web Cam Viewer - Recvr", NULL); //videocap.name
156    printf("Done Creating Video Frame\n");
157  }
158}
159
160void
161JPEG_VideoViewer_i::query (CF::Properties & configProperties)
162throw (CORBA::SystemException, CF::UnknownProperties)
163{
164    // for queries of zero length, return all id/value pairs in propertySet
165    if (configProperties.length () == 0)
166    {   
167        configProperties.length (propertySet.length ());
168        for (unsigned int i = 0; i < propertySet.length (); i++)
169        {
170            configProperties[i].id = CORBA::string_dup (propertySet[i].id);
171            configProperties[i].value = propertySet[i].value;
172        }
173
174        return ;
175    }   
176    else {
177        for (unsigned int i = 0; i < configProperties.length(); i++) {
178            for (unsigned int j=0; j < propertySet.length(); j++) {
179                if ( strcmp(configProperties[i].id, propertySet[i].id) == 0 ){
180                    configProperties[i].value = propertySet[i].value;
181               }
182            }
183        }
184    }   
185}
186
187
188
189
190void JPEG_VideoViewer_i::configure(const CF::Properties& props) throw (CORBA::SystemException, CF::PropertySet::InvalidConfiguration, CF::PropertySet::PartialConfiguration)
191{
192       
193    DEBUG(3, JPEG_VideoViewer, "configure invoked")
194   
195    std::cout << "props length : " << props.length() << std::endl;
196
197    for (unsigned int i = 0; i <props.length(); i++)
198    {
199        std::cout << "Property id : " << props[i].id << std::endl;
200
201    }
202}
203
204void JPEG_VideoViewer_i::run_loop()
205{
206    DEBUG(3, JPEG_VideoViewer, "run loop invoked")
207    int i = 0;
208    short N = 0;
209    PortTypes::CharSequence *I_in_0(NULL);
210    unsigned char * image_data;
211   
212    while( true )
213    {
214      dataIn_0->getData(I_in_0);
215      N = I_in_0->length();
216      image_data = new unsigned char[N];
217      for(i = 0; i < N; i++)
218      {
219        image_data[i] = (unsigned char) (*I_in_0)[i];
220      }
221      if(VIDEOMON)
222      { 
223        refresh_screen(image_data,(unsigned char*)(pscreen->pixels),format,image_width,image_height,owidth,oheight,image_width*image_height*bpp,autobright);
224                          if (autobright)
225        {
226                            //printf("AutoBright\n");
227          //adjust_bright(&videopict, fd);
228        }     
229        SDL_UpdateRect (pscreen, 0, 0, 0, 0);   //update the entire screen
230      }
231
232      dataIn_0->bufferEmptied();
233      delete [] image_data;
234    }
235}
236
237   
Note: See TracBrowser for help on using the browser.