root/components/JPEG_VideoViewer/trunk/JPEG_VideoViewer/JPEG_VideoViewer.cpp @ 2915

Revision 2915, 5.5 KB (checked in by bcrosby, 6 years ago)

Init. Import

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 JPEG_VideoViewer_i::configure(const CF::Properties& props) throw (CORBA::SystemException, CF::PropertySet::InvalidConfiguration, CF::PropertySet::PartialConfiguration)
161{
162    DEBUG(3, JPEG_VideoViewer, "configure invoked")
163   
164    std::cout << "props length : " << props.length() << std::endl;
165
166    for (unsigned int i = 0; i <props.length(); i++)
167    {
168        std::cout << "Property id : " << props[i].id << std::endl;
169
170    }
171}
172
173void JPEG_VideoViewer_i::run_loop()
174{
175    DEBUG(3, JPEG_VideoViewer, "run loop invoked")
176    int i = 0;
177    short N = 0;
178    PortTypes::CharSequence *I_in_0(NULL);
179    unsigned char * image_data;
180   
181    while( true )
182    {
183      dataIn_0->getData(I_in_0);
184      N = I_in_0->length();
185      image_data = new unsigned char[N];
186      for(i = 0; i < N; i++)
187      {
188        image_data[i] = (unsigned char) (*I_in_0)[i];
189      }
190      if(VIDEOMON)
191      { 
192        refresh_screen(image_data,(unsigned char*)(pscreen->pixels),format,image_width,image_height,owidth,oheight,image_width*image_height*bpp,autobright);
193                          if (autobright)
194        {
195                            //printf("AutoBright\n");
196          //adjust_bright(&videopict, fd);
197        }     
198        SDL_UpdateRect (pscreen, 0, 0, 0, 0);   //update the entire screen
199      }
200
201      dataIn_0->bufferEmptied();
202      delete [] image_data;
203    }
204}
205
206   
Note: See TracBrowser for help on using the browser.