|
1 /* |
|
2 * Copyright (c) 2006 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef MCCFILESINK_H |
|
21 #define MCCFILESINK_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <f32file.h> |
|
26 #include <e32std.h> |
|
27 #include <3gplibrary/mp4lib.h> |
|
28 #include <CamC3GPDataSink.h> |
|
29 #include <CCMRMediaSink.h> |
|
30 #include "mccdatasink.h" |
|
31 #include "mmccevents.h" |
|
32 #include "mccinternalcodecs.h" |
|
33 |
|
34 |
|
35 /** |
|
36 * Class to contain filesink user information. |
|
37 */ |
|
38 class TMccFileSinkUser |
|
39 { |
|
40 public: |
|
41 |
|
42 TMccFileSinkUser( MAsyncEventHandler* aEventHandler ) : |
|
43 iEventHandler( aEventHandler ), |
|
44 iCodecInfo() |
|
45 { |
|
46 } |
|
47 |
|
48 public: |
|
49 |
|
50 MAsyncEventHandler* iEventHandler; |
|
51 TMccCodecInfo iCodecInfo; |
|
52 }; |
|
53 |
|
54 /** |
|
55 * Class to handle file writing. |
|
56 */ |
|
57 class CMccFileSink: public CMccDataSink, public M3GPDataSinkObserver |
|
58 { |
|
59 |
|
60 public: |
|
61 |
|
62 enum TFileSinkState |
|
63 { |
|
64 EConstructed = 0, |
|
65 EReady, |
|
66 EPaused, |
|
67 EStopped, |
|
68 ERecording |
|
69 }; |
|
70 |
|
71 /** |
|
72 * Two-phased constructor. |
|
73 */ |
|
74 static MDataSink* NewSinkL( TUid aImplementationUid, |
|
75 const TDesC8& aInitData ); |
|
76 |
|
77 void ConstructSinkL ( const TDesC8& aInitData ); |
|
78 |
|
79 CMccFileSink(); |
|
80 |
|
81 virtual ~CMccFileSink(); |
|
82 |
|
83 public: // New |
|
84 |
|
85 virtual void SetCurrentUser( MAsyncEventHandler* aEventHandler ); |
|
86 virtual void SetFileNameL( const TFileName aFileName ); |
|
87 virtual void RecordTimeAvailableL( TTimeIntervalMicroSeconds& aTime ); |
|
88 |
|
89 public: // From MDataSource |
|
90 |
|
91 TFourCC SinkDataTypeCode( TMediaId /*aMediaId*/ ); |
|
92 |
|
93 TInt SetSinkDataTypeCode( TFourCC aCodec, |
|
94 TMediaId aMedia ); |
|
95 |
|
96 void BufferEmptiedL( CMMFBuffer* aBuffer ); |
|
97 |
|
98 TBool CanCreateSinkBuffer(); |
|
99 |
|
100 CMMFBuffer* CreateSinkBufferL( TMediaId, |
|
101 TBool& aReference ); |
|
102 |
|
103 TInt SinkThreadLogon( MAsyncEventHandler& aEventHandler ); |
|
104 |
|
105 void SinkThreadLogoff(); |
|
106 |
|
107 void SinkPrimeL(); |
|
108 |
|
109 void SinkPlayL(); |
|
110 |
|
111 void SinkPauseL(); |
|
112 |
|
113 void SinkStopL(); |
|
114 |
|
115 void EmptyBufferL( CMMFBuffer* aBuffer, |
|
116 MDataSource* aProvider, |
|
117 TMediaId aMediaId ); |
|
118 |
|
119 void BufferFilledL( CMMFBuffer* aBuffer ); |
|
120 |
|
121 public: // from M3GPDataSinkObserver |
|
122 |
|
123 void MfcoDiskFullL(); |
|
124 |
|
125 void MfcoSizeLimitReachedL(); |
|
126 |
|
127 public: // New methods |
|
128 |
|
129 virtual void SetVideoCodecL( const TMccCodecInfo& aVideoCodec ); |
|
130 |
|
131 virtual void SetAudioCodecL( const TMccCodecInfo& aAudioCodec ); |
|
132 |
|
133 private: |
|
134 |
|
135 void SendStreamEventToClient( TMccEventType aEventType, |
|
136 TInt aError = KErrNone, |
|
137 TBool aToAllClients = EFalse ); |
|
138 |
|
139 TTimeIntervalMicroSeconds TimeToPlayL( |
|
140 TTimeIntervalMicroSeconds aCurrentTimestamp ); |
|
141 |
|
142 void CalculateAverageTimestampDifferenceL( |
|
143 const TTimeIntervalMicroSeconds& aCurrentTimestamp ); |
|
144 |
|
145 void ResetTimers(); |
|
146 |
|
147 void SetPausedDuration( TTime aT1, TTime aT2 ); |
|
148 |
|
149 void AutomaticPauseL(); |
|
150 |
|
151 TInt FinalizeSendEvent( MAsyncEventHandler* aEventHandler, TMccEvent& aEvent ); |
|
152 |
|
153 HBufC8* GetCodecTypeStringLC( const TMccCodecInfo& aCodecInfo ); |
|
154 |
|
155 /** |
|
156 * Resolve buffer type of passed buffer based on datatype value and |
|
157 * contents of data in some cases. |
|
158 * @param aBuffer |
|
159 * @param aDataType |
|
160 * @return buffer type |
|
161 */ |
|
162 CCMRMediaBuffer::TBufferType ResolveBufferType( CMMFDataBuffer& aBuffer, |
|
163 TFourCC aDataType ); |
|
164 |
|
165 /** |
|
166 * Checks whether buffer should be written to file. |
|
167 * @param aBuffer |
|
168 * @param aBufferType |
|
169 * @return ETrue if writing to file is allowed |
|
170 */ |
|
171 TBool CheckWritingPermission( CMMFDataBuffer& aBuffer, |
|
172 const CCMRMediaBuffer::TBufferType& aBufferType ); |
|
173 |
|
174 TBool SetStateL( TFileSinkState aState ); |
|
175 |
|
176 void DoSinkPrimeL( TBool aSendEvent = ETrue ); |
|
177 |
|
178 void DoSinkPlayL( TBool aSendEvent = ETrue ); |
|
179 |
|
180 void DoSinkPauseL( TBool aSendEvent = ETrue ); |
|
181 |
|
182 void DoSinkStopL( TBool aSendEvent = ETrue ); |
|
183 |
|
184 void DoCodecChangeL(); |
|
185 |
|
186 void AddUserL( MAsyncEventHandler* aEventHandler ); |
|
187 |
|
188 TMccFileSinkUser& ActiveUserL(); |
|
189 |
|
190 TBool IsActiveUser( MAsyncEventHandler* aUser ); |
|
191 |
|
192 /** |
|
193 * Check if active user has changed and update sink accordingly. |
|
194 * @param aMediaId |
|
195 * @param aDataProvider |
|
196 * @return data type of current data provider |
|
197 */ |
|
198 TFourCC UpdateActiveUserL( TMediaId aMediaId, MDataSource& aDataProvider ); |
|
199 |
|
200 void SetActiveUserIndex( TInt aIndex ); |
|
201 |
|
202 private: |
|
203 |
|
204 TFileSinkState iCurrentState; |
|
205 CCamC3GPDataSink* iFileComposer; |
|
206 TInt iMaxFileSize; |
|
207 |
|
208 TFileName iFileName; |
|
209 TFourCC iAudioFourCC; |
|
210 |
|
211 MAsyncEventHandler* iAsyncEventHandler; |
|
212 |
|
213 private: |
|
214 TTime iT1; |
|
215 TTime iT2; |
|
216 TTimeIntervalMicroSeconds iPausedDuration; |
|
217 |
|
218 RArray<TInt64> iTimestamps; |
|
219 TTimeIntervalMicroSeconds iPreviousTimestamp; |
|
220 TInt64 iAddToTimestamp; |
|
221 |
|
222 TBool iSizeLimitReached; |
|
223 TBool iNotifySizeLimitReached; |
|
224 |
|
225 TMccCodecInfo iVideoCodec; |
|
226 |
|
227 RPointerArray<TMccFileSinkUser> iUsers; |
|
228 |
|
229 TInt iActiveUserIndex; |
|
230 |
|
231 TBool iDecSpecInfoProvided; |
|
232 TBool iKeyFrameProvided; |
|
233 |
|
234 #ifdef EUNIT_TEST |
|
235 friend class UT_CMccFileSink; |
|
236 #endif |
|
237 }; |
|
238 |
|
239 |
|
240 #endif |
|
241 |
|
242 |
|
243 // End of file |
|
244 |