1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of CCamBufferShare class. |
|
15 * Wrapper around to store and handle sharing of buffer |
|
16 * implementing MCameraBuffer interface. Counts references |
|
17 * and frees the stored buffer, when no client uses it. |
|
18 * |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 |
|
24 // =========================================================================== |
|
25 // Includes |
|
26 #include <ecam.h> // MCameraBuffer |
|
27 #include "camlogging.h" |
|
28 #include "cambuffershare.h" |
|
29 |
|
30 // =========================================================================== |
|
31 // Static data initialisation |
|
32 #ifdef _DEBUG |
|
33 TInt CCamBufferShare::isTotalBufferCount = 0; |
|
34 #endif // _DEBUG |
|
35 |
|
36 |
|
37 // =========================================================================== |
|
38 // Class methods |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // Constructor |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CCamBufferShare::CCamBufferShare( MCameraBuffer* aSharedBuffer ) |
|
45 : iSharedBuffer( aSharedBuffer ), |
|
46 iReferenceCount( 0 ) |
|
47 { |
|
48 #ifdef _DEBUG |
|
49 ++isTotalBufferCount; |
|
50 #endif // _DEBUG |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Destructor |
|
55 // Private, Release is to be used by clients. |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CCamBufferShare::~CCamBufferShare() |
|
59 { |
|
60 PRINT( _L("Camera => ~CCamBufferShare") ); |
|
61 if( iSharedBuffer ) |
|
62 { |
|
63 iSharedBuffer->Release(); |
|
64 iSharedBuffer = NULL; |
|
65 } |
|
66 #ifdef _DEBUG |
|
67 --isTotalBufferCount; |
|
68 #endif |
|
69 PRINT( _L("Camera <= ~CCamBufferShare") ); |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // Return the shared buffer. |
|
74 // Ownership never transferred to caller. |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 MCameraBuffer* |
|
78 CCamBufferShare::SharedBuffer() |
|
79 { |
|
80 return iSharedBuffer; |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // Signal, that new client uses this buffer. |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void |
|
88 CCamBufferShare::Reserve() |
|
89 { |
|
90 ++iReferenceCount; |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // Signal that one client has stopped using this buffer. |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 void |
|
98 CCamBufferShare::Release() |
|
99 { |
|
100 --iReferenceCount; |
|
101 |
|
102 if( iReferenceCount <= 0 ) |
|
103 { |
|
104 delete this; |
|
105 } |
|
106 } |
|
107 |
|
108 #ifdef _DEBUG |
|
109 // --------------------------------------------------------------------------- |
|
110 // TotalBufferShareCount <<static>> |
|
111 // |
|
112 // Debug method to follow the total amount of shared buffers in use. |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 TInt |
|
116 CCamBufferShare::TotalBufferShareCount() |
|
117 { |
|
118 return isTotalBufferCount; |
|
119 } |
|
120 #endif // _DEBUG |
|
121 |
|
122 |
|
123 // end of file |
|
124 |
|