1 #ifndef WIN32
2    #pragma message ("WIN32 not defined. Not compiling CVPlatformWin32")
3 #else
4 
5 /// \file CVPlatformWin32.cpp
6 /// \brief Win32 Platform-specific object factory
7 // Written by Michael Ellison
8 //-------------------------------------------------------------------------
9 //                      CodeVis's Free License
10 //                         www.codevis.com
11 //
12 // Copyright (c) 2003 by Michael Ellison (mike@codevis.com)
13 // All rights reserved.
14 //
15 // You may use this software in source and/or binary form, with or without
16 // modification, for commercial or non-commercial purposes, provided that
17 // you comply with the following conditions:
18 //
19 // * Redistributions of source code must retain the above copyright notice,
20 //   this list of conditions and the following disclaimer.
21 //
22 // * Redistributions of modified source must be clearly marked as modified,
23 //   and due notice must be placed in the modified source indicating the
24 //   type of modification(s) and the name(s) of the person(s) performing
25 //   said modification(s).
26 //
27 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
33 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 //---------------------------------------------------------------------------
40 // Modifications:
41 //
42 //---------------------------------------------------------------------------
43 // CVPlatformWin32
44 // Win32 Platform-specific object factory
45 //
46 // CVPlatform is a singleton class factory for platform-specific classes.
47 // This allows us to instantiate totally different objects on different
48 // platforms without making the calling code platform-specific.
49 //
50 // When setting up a project for a specific platform, make sure to add in
51 // the appropriate CVPlatform*.cpp for that platform. It implements
52 // the CVPlatform class for us.
53 //
54 // $RCSfile: CVPlatformWin32.cpp,v $
55 // $Date: 2004/02/08 23:47:39 $
56 // $Revision: 1.1.1.1 $
57 // $Author: mikeellison $
58 
59 #include "CVPlatform.h"
60 #include "CVVidCaptureDSWin32.h"
61 
62 /// Our static platform pointer
63 CVPlatform* CVPlatform::sPlatform = 0;
64 
65 //--------------------------------------------------------------------------
66 // GetPlatform() retrieves a pointer to the singleton platform object.
67 //
68 // Only one instance will be created on the first call.
69 // It is automatically freed on exit from the process.
70 //
71 // \return CVPlatform* - pointer to CVPlatform object
72 //--------------------------------------------------------------------------
GetPlatform()73 CVPlatform* CVPlatform::GetPlatform()
74 {
75    // If we've already created the platform object, just return it.
76    if (sPlatform != 0)
77    {
78       return sPlatform;
79    }
80 
81    sPlatform = new CVPlatform();
82 
83    // Register for deletion at process exit.
84    // This isn't strictly necessary, but it makes BoundsChecker and similar
85    // tools whine a lot less (otherwise we leak a few bytes on exit).
86    atexit(FreePlatform);
87 
88 
89    return sPlatform;
90 }
91 
92 //--------------------------------------------------------------------------
93 // AcquireVideoCapture() acquires a CVVidCapture object appropriate
94 // for the current system.
95 //--------------------------------------------------------------------------
AcquireVideoCapture()96 CVVidCapture* CVPlatform::AcquireVideoCapture()
97 {
98    return new CVVidCaptureDSWin32();
99 }
100 
101 //--------------------------------------------------------------------------
102 // Release() releases an object and sets the pointer to NULL.
103 //
104 // This version is for video capture objects (CVVidCapture and children).
105 //
106 // \param vidCap - a CVVidCapture* previously allocated by
107 //                 AcquireVideoCapture().
108 // \sa CVVidCapture, CVVidCaptureDSWin32, AcquireVideoCapture()
109 //--------------------------------------------------------------------------
Release(CVVidCapture * & vidCap)110 void CVPlatform::Release(CVVidCapture*& vidCap)
111 {
112    if (vidCap != 0)
113    {
114       delete vidCap;
115       vidCap = 0;
116    }
117 }
118 
119 //--------------------------------------------------------------------------
120 // CVPlatform constructor - use GetPlatform() instead.
121 //
122 // GetPlatform() creates the platform object if needed.
123 //--------------------------------------------------------------------------
CVPlatform()124 CVPlatform::CVPlatform()
125 {
126 }
127 
128 //--------------------------------------------------------------------------
129 // CVPlatform destructor - don't delete CVPlatform directly.
130 //
131 // GetPlatform() registers with the runtime library for
132 // deletion when the process exits.
133 //--------------------------------------------------------------------------
~CVPlatform()134 CVPlatform::~CVPlatform()
135 {
136 }
137 
138 //--------------------------------------------------------------------------
139 // FreePlatform() frees the static platform object as the
140 // process exits.
141 //
142 // Do not call it directly. It is made to be called
143 // from the atexit() handler.
144 //
145 //--------------------------------------------------------------------------
FreePlatform()146 void CVPlatform::FreePlatform()
147 {
148    if (sPlatform != 0)
149    {
150       delete sPlatform;
151       sPlatform = 0;
152    }
153 }
154 
155 #endif // WIN32
156