• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 #ifndef PVMI_DATASTREAMSYNCINTERFACE_REF_IMPL_H_INCLUDED
19 #include "pvmi_datastreamsyncinterface_ref_impl.h"
20 #endif
21 
22 #define LOGDEBUG(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG,iLogger,PVLOGMSG_DEBUG,m);
23 
24 
CreateDataStreamSyncInterfaceRefImpl(OSCL_wString & aFileName)25 OSCL_EXPORT_REF PVMIDataStreamSyncInterface* PVMIDataStreamSyncInterfaceRefImpl::CreateDataStreamSyncInterfaceRefImpl(OSCL_wString& aFileName)
26 {
27     PVMIDataStreamSyncInterfaceRefImpl* newsyncif = OSCL_NEW(PVMIDataStreamSyncInterfaceRefImpl, (aFileName));
28     return OSCL_STATIC_CAST(PVMIDataStreamSyncInterface*, newsyncif);
29 }
30 
31 
CreateDataStreamSyncInterfaceRefImpl(OsclFileHandle * aFileHandle)32 OSCL_EXPORT_REF PVMIDataStreamSyncInterface* PVMIDataStreamSyncInterfaceRefImpl::CreateDataStreamSyncInterfaceRefImpl(OsclFileHandle* aFileHandle)
33 {
34     PVMIDataStreamSyncInterfaceRefImpl* newsyncif = OSCL_NEW(PVMIDataStreamSyncInterfaceRefImpl, (aFileHandle));
35     return OSCL_STATIC_CAST(PVMIDataStreamSyncInterface*, newsyncif);
36 }
37 
38 
DestroyDataStreamSyncInterfaceRefImpl(PVMIDataStreamSyncInterface * aInterface)39 OSCL_EXPORT_REF void PVMIDataStreamSyncInterfaceRefImpl::DestroyDataStreamSyncInterfaceRefImpl(PVMIDataStreamSyncInterface* aInterface)
40 {
41     PVMIDataStreamSyncInterfaceRefImpl* syncif = OSCL_STATIC_CAST(PVMIDataStreamSyncInterfaceRefImpl*, aInterface);
42     OSCL_DELETE(syncif);
43 }
44 
45 
PVMIDataStreamSyncInterfaceRefImpl(OSCL_wString & aFileName)46 PVMIDataStreamSyncInterfaceRefImpl::PVMIDataStreamSyncInterfaceRefImpl(OSCL_wString& aFileName)
47 {
48     iSessionID = 0;
49     iFileName = aFileName;
50     iFileHandle = NULL;
51     iFileObject = NULL;
52     iLogger = PVLogger::GetLoggerObject("PVMIDataStreamSyncInterfaceRefImpl");
53     iFs.Connect();
54     LOGDEBUG((0, "PVMIDataStreamSyncInterfaceRefImpl::PVMIDataStreamSyncInterfaceRefImpl"));
55 }
56 
PVMIDataStreamSyncInterfaceRefImpl(OsclFileHandle * aFileHandle)57 PVMIDataStreamSyncInterfaceRefImpl::PVMIDataStreamSyncInterfaceRefImpl(OsclFileHandle* aFileHandle)
58 {
59     iSessionID = 0;
60     iFileHandle = aFileHandle;
61     iFileObject = NULL;
62     iLogger = PVLogger::GetLoggerObject("PVMIDataStreamSyncInterfaceRefImpl");
63     iFs.Connect();
64     LOGDEBUG((0, "PVMIDataStreamSyncInterfaceRefImpl::PVMIDataStreamSyncInterfaceRefImpl"));
65 }
66 
~PVMIDataStreamSyncInterfaceRefImpl()67 PVMIDataStreamSyncInterfaceRefImpl::~PVMIDataStreamSyncInterfaceRefImpl()
68 {
69     LOGDEBUG((0, "PVMIDataStreamSyncInterfaceRefImpl::~PVMIDataStreamSyncInterfaceRefImpl"));
70     if (iFileObject)
71         OSCL_DELETE(iFileObject);
72     iFileObject = NULL;
73     iFs.Close();
74     iLogger = NULL;
75 }
76 
77 OSCL_EXPORT_REF bool
queryInterface(const PVUuid & uuid,PVInterface * & iface)78 PVMIDataStreamSyncInterfaceRefImpl::queryInterface(const PVUuid& uuid,
79         PVInterface*& iface)
80 {
81     iface = NULL;
82     LOGDEBUG((0, "PVMIDataStreamSyncInterfaceRefImpl::queryInterface"));
83     if (uuid == PVMIDataStreamSyncInterfaceUuid)
84     {
85         PVMIDataStreamSyncInterface* myInterface
86         = OSCL_STATIC_CAST(PVMIDataStreamSyncInterface*, this);
87         iface = OSCL_STATIC_CAST(PVInterface*, myInterface);
88         return true;
89     }
90     return false;
91 }
92 
93 OSCL_EXPORT_REF PvmiDataStreamStatus
OpenSession(PvmiDataStreamSession & aSessionID,PvmiDataStreamMode aMode,bool nonblocking)94 PVMIDataStreamSyncInterfaceRefImpl::OpenSession(PvmiDataStreamSession& aSessionID,
95         PvmiDataStreamMode aMode,
96         bool nonblocking)
97 {
98     OSCL_UNUSED_ARG(nonblocking);
99 
100     LOGDEBUG((0, "PVMIDataStreamSyncInterfaceRefImpl::OpenSession"));
101     if (!iFileObject)
102         iFileObject = OSCL_NEW(Oscl_File, (OSCL_FILE_BUFFER_MAX_SIZE, iFileHandle));
103 
104     int32 result;
105     if (iFileHandle)
106     {
107         result = 0;
108     }
109     else
110     {
111         if (aMode == PVDS_READ_ONLY)
112         {
113             result = iFileObject->Open(iFileName.get_cstr(), Oscl_File::MODE_READ, iFs);
114             LOGDEBUG((0, "PVMIDataStreamSyncInterfaceRefImpl::OpenSession - File Open returning %d", result));
115         }
116         else
117         {
118             return PVDS_UNSUPPORTED_MODE;
119         }
120     }
121 
122     if (result == 0)
123     {
124         iFileNumBytes = 0;
125         int32 res = iFileObject->Seek(0, Oscl_File::SEEKEND);
126         if (res == 0)
127         {
128             iFileNumBytes = (TOsclFileOffsetInt32)iFileObject->Tell();
129             iFileObject->Seek(0, Oscl_File::SEEKSET);
130         }
131         aSessionID = iSessionID;
132         return PVDS_SUCCESS;
133     }
134     return PVDS_FAILURE;
135 }
136 
137 OSCL_EXPORT_REF PvmiDataStreamStatus
CloseSession(PvmiDataStreamSession sessionID)138 PVMIDataStreamSyncInterfaceRefImpl::CloseSession(PvmiDataStreamSession sessionID)
139 {
140     OSCL_UNUSED_ARG(sessionID);
141     if (!iFileObject)
142     {
143         LOGDEBUG((0, "PVMIDataStreamSyncInterfaceRefImpl::CloseSession returning %d", -1));
144         return PVDS_FAILURE;
145     }
146     int32 result = 0;
147     if (!iFileHandle)
148         result = iFileObject->Close();
149     LOGDEBUG((0, "PVMIDataStreamSyncInterfaceRefImpl::CloseSession returning %d", result));
150     OSCL_DELETE(iFileObject);
151     iFileObject = NULL;
152     if (result == 0)
153         return PVDS_SUCCESS;
154 
155     return PVDS_FAILURE;
156 }
157 
158 OSCL_EXPORT_REF PvmiDataStreamRandomAccessType
QueryRandomAccessCapability()159 PVMIDataStreamSyncInterfaceRefImpl::QueryRandomAccessCapability()
160 {
161     return PVDS_FULL_RANDOM_ACCESS;
162 }
163 
164 OSCL_EXPORT_REF PvmiDataStreamStatus
QueryReadCapacity(PvmiDataStreamSession sessionID,uint32 & capacity)165 PVMIDataStreamSyncInterfaceRefImpl::QueryReadCapacity(PvmiDataStreamSession sessionID,
166         uint32& capacity)
167 {
168     OSCL_UNUSED_ARG(sessionID);
169 
170     uint32 currFilePosition = GetCurrentPointerPosition(iSessionID);
171     capacity = ((uint32)iFileNumBytes - currFilePosition);
172     return PVDS_SUCCESS;
173 }
174 
175 OSCL_EXPORT_REF PvmiDataStreamCommandId
RequestReadCapacityNotification(PvmiDataStreamSession sessionID,PvmiDataStreamObserver & observer,uint32 capacity,OsclAny * aContextData)176 PVMIDataStreamSyncInterfaceRefImpl::RequestReadCapacityNotification(PvmiDataStreamSession sessionID,
177         PvmiDataStreamObserver& observer,
178         uint32 capacity,
179         OsclAny* aContextData)
180 {
181     OSCL_UNUSED_ARG(sessionID);
182     OSCL_UNUSED_ARG(observer);
183     OSCL_UNUSED_ARG(capacity);
184     OSCL_UNUSED_ARG(aContextData);
185 
186     OSCL_LEAVE(OsclErrNotSupported);
187     return 0;
188 }
189 
190 OSCL_EXPORT_REF PvmiDataStreamStatus
QueryWriteCapacity(PvmiDataStreamSession sessionID,uint32 & capacity)191 PVMIDataStreamSyncInterfaceRefImpl::QueryWriteCapacity(PvmiDataStreamSession sessionID,
192         uint32& capacity)
193 {
194     OSCL_UNUSED_ARG(sessionID);
195     OSCL_UNUSED_ARG(capacity);
196 
197     return PVDS_NOT_SUPPORTED;
198 }
199 
200 OSCL_EXPORT_REF PvmiDataStreamCommandId
RequestWriteCapacityNotification(PvmiDataStreamSession sessionID,PvmiDataStreamObserver & observer,uint32 capacity,OsclAny * aContextData)201 PVMIDataStreamSyncInterfaceRefImpl::RequestWriteCapacityNotification(PvmiDataStreamSession sessionID,
202         PvmiDataStreamObserver& observer,
203         uint32 capacity,
204         OsclAny* aContextData)
205 {
206     OSCL_UNUSED_ARG(sessionID);
207     OSCL_UNUSED_ARG(observer);
208     OSCL_UNUSED_ARG(capacity);
209     OSCL_UNUSED_ARG(aContextData);
210 
211     OSCL_LEAVE(OsclErrNotSupported);
212     return 0;
213 }
214 
215 OSCL_EXPORT_REF PvmiDataStreamCommandId
CancelNotification(PvmiDataStreamSession sessionID,PvmiDataStreamObserver & observer,PvmiDataStreamCommandId aID,OsclAny * aContextData)216 PVMIDataStreamSyncInterfaceRefImpl::CancelNotification(PvmiDataStreamSession sessionID,
217         PvmiDataStreamObserver& observer,
218         PvmiDataStreamCommandId aID,
219         OsclAny* aContextData)
220 {
221     OSCL_UNUSED_ARG(sessionID);
222     OSCL_UNUSED_ARG(observer);
223     OSCL_UNUSED_ARG(aID);
224     OSCL_UNUSED_ARG(aContextData);
225 
226     OSCL_LEAVE(OsclErrNotSupported);
227     return 0;
228 }
229 
230 OSCL_EXPORT_REF PvmiDataStreamStatus
Read(PvmiDataStreamSession sessionID,uint8 * buffer,uint32 size,uint32 & numelements)231 PVMIDataStreamSyncInterfaceRefImpl::Read(PvmiDataStreamSession sessionID,
232         uint8* buffer,
233         uint32 size,
234         uint32& numelements)
235 {
236     OSCL_UNUSED_ARG(sessionID);
237 
238     if (!iFileObject)
239         return PVDS_FAILURE;
240     uint32 result = iFileObject->Read(buffer, size, numelements);
241     LOGDEBUG((0, "PVMIDataStreamSyncInterfaceRefImpl::ReadAndUnlockContent returning %d", result));
242     numelements = result;
243     return PVDS_SUCCESS;
244 }
245 
246 OSCL_EXPORT_REF PvmiDataStreamStatus
Write(PvmiDataStreamSession sessionID,uint8 * buffer,uint32 size,uint32 & numelements)247 PVMIDataStreamSyncInterfaceRefImpl::Write(PvmiDataStreamSession sessionID,
248         uint8* buffer,
249         uint32 size,
250         uint32& numelements)
251 {
252     OSCL_UNUSED_ARG(sessionID);
253     OSCL_UNUSED_ARG(buffer);
254     OSCL_UNUSED_ARG(size);
255     OSCL_UNUSED_ARG(numelements);
256 
257     return PVDS_NOT_SUPPORTED;
258 }
259 
260 OSCL_EXPORT_REF PvmiDataStreamStatus
Seek(PvmiDataStreamSession sessionID,int32 offset,PvmiDataStreamSeekType origin)261 PVMIDataStreamSyncInterfaceRefImpl::Seek(PvmiDataStreamSession sessionID,
262         int32 offset,
263         PvmiDataStreamSeekType origin)
264 {
265     OSCL_UNUSED_ARG(sessionID);
266 
267     if (!iFileObject)
268         return PVDS_FAILURE;
269     Oscl_File::seek_type seekType = Oscl_File::SEEKCUR;
270     if (origin == PVDS_SEEK_SET)
271     {
272         seekType = Oscl_File::SEEKSET;
273     }
274     if (origin == PVDS_SEEK_CUR)
275     {
276         seekType = Oscl_File::SEEKCUR;
277     }
278     if (origin == PVDS_SEEK_END)
279     {
280         seekType = Oscl_File::SEEKEND;
281     }
282     int32 result = iFileObject->Seek(offset, seekType);
283     LOGDEBUG((0, "PVMIDataStreamSyncInterfaceRefImpl::SeekContent returning %d", result));
284     if (result != 0)
285     {
286         return PVDS_FAILURE;
287     }
288     return PVDS_SUCCESS;
289 }
290 
291 OSCL_EXPORT_REF uint32
GetCurrentPointerPosition(PvmiDataStreamSession sessionID)292 PVMIDataStreamSyncInterfaceRefImpl::GetCurrentPointerPosition(PvmiDataStreamSession sessionID)
293 {
294     OSCL_UNUSED_ARG(sessionID);
295 
296     if (!iFileObject)
297         return 0;
298     int32 result = (TOsclFileOffsetInt32)iFileObject->Tell();
299     LOGDEBUG((0, "PVMIDataStreamSyncInterfaceRefImpl::GetCurrentContentPosition returning %d", result));
300     return (uint32)(result);
301 }
302 
303 OSCL_EXPORT_REF PvmiDataStreamStatus
Flush(PvmiDataStreamSession sessionID)304 PVMIDataStreamSyncInterfaceRefImpl::Flush(PvmiDataStreamSession sessionID)
305 {
306     OSCL_UNUSED_ARG(sessionID);
307 
308     if (!iFileObject)
309     {
310         LOGDEBUG((0, "PVMIDataStreamSyncInterfaceRefImpl::Flush returning %d", -1));
311         return PVDS_FAILURE;
312     }
313     int32 result;
314     result = iFileObject->Flush();
315     LOGDEBUG((0, "PVMIDataStreamSyncInterfaceRefImpl::Flush returning %d", result));
316     if (result == 0) //Flush will return 0 when successful
317         return PVDS_SUCCESS;
318     else
319         return PVDS_FAILURE;
320 
321 }
322 
323 
324