• 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 // only include pvmf_downloadmanager_config.h if CML2 is NOT being used
19 #ifndef USE_CML2_CONFIG
20 #ifndef PVMF_DOWNLOADMANAGER_CONFIG_H_INCLUDED
21 #include "pvmf_downloadmanager_config.h"
22 #endif
23 #endif
24 
25 #if(PVMF_DOWNLOADMANAGER_SUPPORT_PPB)
26 
27 #ifndef PVMF_MEMORYBUFFERDATASTREAM_FACTORY_H_INCLUDED
28 #define PVMF_MEMORYBUFFERDATASTREAM_FACTORY_H_INCLUDED
29 
30 #ifndef OSCL_BASE_H_INCLUDED
31 #include "oscl_base.h"
32 #endif
33 #ifndef OSCL_QUEUE_H_INCLUDED
34 #include "oscl_queue.h"
35 #endif
36 #ifndef OSCL_ERROR_CODES_H_INCLUDED
37 #include "oscl_error_codes.h"
38 #endif
39 #ifndef OSCL_TYPES_H_INCLUDED
40 #include "oscl_types.h"
41 #endif
42 #ifndef OSCL_STRING_CONTAINERS_H_INCLUDED
43 #include "oscl_string_containers.h"
44 #endif
45 #ifndef PVLOGGER_H_INCLUDED
46 #include "pvlogger.h"
47 #endif
48 #ifndef PVMF_EVENT_HANDLING_H_INCLUDED
49 #include "pvmf_event_handling.h"
50 #endif
51 #ifndef PVMI_DATA_STREAM_INTERFACE_H_INCLUDED
52 #include "pvmi_data_stream_interface.h"
53 #endif
54 #ifndef PVMF_CPMPLUGIN_ACCESS_INTERFACE_FACTORY_H_INCLUDED
55 #include "pvmf_cpmplugin_access_interface_factory.h"
56 #endif
57 #ifndef PVMI_DATASTREAMUSER_INTERFACE_H_INCLUDED
58 #include "pvmi_datastreamuser_interface.h"
59 #endif
60 #ifndef PVMF_MEDIA_DATA_H_INCLUDED
61 #include "pvmf_media_data.h"
62 #endif
63 #ifndef OSCL_MUTEX_H_INCLUDED
64 #include "oscl_mutex.h"
65 #endif
66 #ifndef OSCL_SEMAPHORE_H_INCLUDED
67 #include "oscl_semaphore.h"
68 #endif
69 
70 
71 #define PV_MBDS_MAX_NUMBER_OF_READ_CONNECTIONS  16
72 
73 #define PV_MBDS_MAX_NUMBER_OF_WRITE_CONNECTIONS 1
74 
75 #define PV_MBDS_MAX_NUMBER_OF_TOTAL_CONNECTIONS  PV_MB_MAX_NUMBER_OF_WRITE_CONNECTIONS + PV_MB_MAX_NUMBER_OF_READ_CONNECTIONS
76 
77 
78 #define PV_MBDS_TEMP_CACHE_TRIM_MARGIN_PS                   64000
79 #define PV_MBDS_TEMP_CACHE_TRIM_THRESHOLD_PS(capacity)              (capacity * 2) / 3
80 // for shoutcast
81 #define PV_MBDS_TEMP_CACHE_TRIM_MARGIN_SC                   4096
82 #define PV_MBDS_TEMP_CACHE_TRIM_THRESHOLD_SC(capacity)                          capacity / 6
83 
84 #define NO_LIMIT        0
85 #define PV_MBDS_PERM_CACHE_SIZE     NO_LIMIT
86 
87 // how many bytes are we willing to wait for assuming they are coming
88 // instead of repositioning
89 // this depends on channel bandwidth and network condition
90 #define PV_MBDS_BYTES_TO_WAIT         4 * 1024
91 
92 // In forward repositioning, if the data is going to come in soon,
93 // which is defined as requested offset minus the download offset (aka current write pointer)
94 // being less than this threshold, then don't disconnect to send a new GET request.
95 #define PV_MBDS_FWD_SEEKING_NO_GET_REQUEST_THRESHOLD 64000
96 
97 typedef enum
98 {
99     MBDS_CACHE_TRIM_NONE,       // invalid node
100     MBDS_CACHE_TRIM_HEAD_ONLY,  // trim the beginning of cache only
101     MBDS_CACHE_TRIM_TAIL_ONLY,  // trim from the end of cache only
102     MBDS_CACHE_TRIM_HEAD_AND_TAIL,  // trim the both ends of cache
103     MBDS_CACHE_TRIM_EMPTY,      // empty the cache
104 } MBDSCacheTrimMode;
105 
106 typedef enum
107 {
108     MBDS_REPOSITION_EXACT,
109     MBDS_REPOSITION_WITH_MARGIN
110 } MBDSRepositionMode;
111 
112 typedef enum
113 {
114     MBDS_STREAM_FORMAT_UNKNOWN,
115     MBDS_STREAM_FORMAT_PROGRESSIVE_PLAYBACK,
116     MBDS_STREAM_FORMAT_SHOUTCAST
117 } MBDSStreamFormat;
118 
119 class PVMFMemoryBufferWriteDataStreamImpl;
120 
121 class PVMFMemoryBufferReadDataStreamImpl;
122 
123 class PVMFMemoryBufferDataStreamTempCache
124 {
125     public:
126         PVMFMemoryBufferDataStreamTempCache();
127         ~PVMFMemoryBufferDataStreamTempCache();
128 
129         uint32 GetTotalBytes();
130 
131         void GetFileOffsets(uint32& aFirstByte, uint32& aLastByte);
132 
133         PvmiDataStreamStatus AddEntry(OsclRefCounterMemFrag* aFrag, uint8* aFragPtr, uint32 aFragSize, uint32 aFileOffset);
134 
135         uint32 ReadBytes(uint8* aBuffer, uint32 aFirstByte, uint32 aLastByte, uint32& firstEntry);
136 
137         bool RemoveFirstEntry(OsclRefCounterMemFrag*& aFrag, uint8*& aFragPtr);
138 
139         bool RemoveLastEntry(OsclRefCounterMemFrag*& aFrag, uint8*& aFragPtr);
140 
141         void GetFirstEntryInfo(uint32& entryOffset, uint32& entrySize);
142 
143         void GetLastEntryInfo(uint32& entryOffset, uint32& entrySize);
144 
145         uint32 GetNumEntries();
146 
147     private:
148 
149         struct MBDSTempCacheEntry
150         {
151             // mem frag was allocated by protocol engine
152             OsclRefCounterMemFrag* frag;
153             // mem ptr
154             uint8* fragPtr;
155             // size of mem frag
156             uint32 fragSize;
157             // file offset corresponding to the first byte of the mem frag
158             uint32 fileOffset;
159         };
160 
161         // total number of bytes of data in this cache
162         uint32 iTotalBytes;
163         // file offset of first byte in cache, use iLock
164         uint32 iFirstByteFileOffset;
165         // file offset of last byte in cache, use iLock
166         uint32 iLastByteFileOffset;
167         // list of temp cache entries
168         Oscl_Vector<MBDSTempCacheEntry*, OsclMemAllocator> iEntries;
169 
170         PVLogger* iLogger;
171 };
172 
173 class PVMFMemoryBufferDataStreamPermCache
174 {
175     public:
176         PVMFMemoryBufferDataStreamPermCache();
177         ~PVMFMemoryBufferDataStreamPermCache();
178 
179         uint32 GetTotalBytes();
180 
181         // these are the offsets of bytes already in the cache
182         void GetFileOffsets(uint32& aFirstByte, uint32& aLastByte);
183 
184         // this byte range have made persistent, but not all the bytes are there yet
185         // use GetFileOffsets to check what bytes are available for reading
186         void GetPermOffsets(uint32& aFirstByte, uint32& aLastByte);
187 
188         PvmiDataStreamStatus AddEntry(uint8* aBufPtr, uint32 aBufSize, uint8* aFillPtr, uint32 aFirstOffset, uint32 aLastOffset, uint32 aFillOffset, uint32 aFillSize);
189 
190         PvmiDataStreamStatus WriteBytes(uint8* aFragPtr, uint32 aFragSize, uint32 aFileOffset);
191 
192         uint32 ReadBytes(uint8* aBuffer, uint32 aFirstByte, uint32 aLastByte);
193 
194         bool RemoveFirstEntry(uint8*& aFragPtr);
195 
196         uint32 GetNumEntries();
197 
198         uint32 GetCacheSize();
199 
200     private:
201 
202         struct MBDSPermCacheEntry
203         {
204             // mem ptr from malloc, saved for freeing later
205             uint8* bufPtr;
206             // size of mem from malloc
207             uint32 bufSize;
208             // mem ptr to the next byte to be written to
209             uint8* fillBufPtr;
210             // file offset of first byte in buffer
211             uint32 firstFileOffset;
212             // file offset of last byte in buffer
213             uint32 lastFileOffset;
214             // file offset of the next byte to be written to
215             uint32 fillFileOffset;
216             // number of bytes already written to buffer
217             uint32 fillSize;
218         };
219 
220         // total number of bytes of data in this cache
221         uint32 iTotalBytes;
222         // total number of bytes allocated in this cache
223         uint32 iTotalBufferAlloc;
224         // file offset of first readable byte in cache
225         uint32 iFirstByteFileOffset;
226         // file offset of last readable byte in cache
227         uint32 iLastByteFileOffset;
228         // file offset of first byte to be made persistent
229         uint32 iFirstPermByteOffset;
230         // file offset of last byte to be made persistent
231         uint32 iLastPermByteOffset;
232         // list of perm cache entries
233         Oscl_Vector<MBDSPermCacheEntry*, OsclMemAllocator> iEntries;
234 
235         PVLogger* iLogger;
236 };
237 
238 //////////////////////////////////////////////////////////////////////
239 // PVMFMemoryBufferReadDataStreamFactoryImpl
240 //////////////////////////////////////////////////////////////////////
241 class PVMFMemoryBufferReadDataStreamFactoryImpl : public PVMFDataStreamFactory
242 {
243     public:
244         OSCL_IMPORT_REF PVMFMemoryBufferReadDataStreamFactoryImpl(PVMFMemoryBufferDataStreamTempCache* aTempCache,
245                 PVMFMemoryBufferDataStreamPermCache* aPermCache);
246 
247         OSCL_IMPORT_REF void SetWriteDataStreamPtr(PVInterface* aWriteDataStream);
248 
249         OSCL_IMPORT_REF PVMFStatus QueryAccessInterfaceUUIDs(Oscl_Vector<PVUuid, OsclMemAllocator>& aUuids);
250 
251         OSCL_IMPORT_REF PVInterface* CreatePVMFCPMPluginAccessInterface(PVUuid& aUuid);
252 
253         OSCL_IMPORT_REF void DestroyPVMFCPMPluginAccessInterface(PVUuid& aUuid, PVInterface* aPtr);
254 
255         OSCL_IMPORT_REF void NotifyDownloadComplete();
256 
257     private:
addRef()258         void addRef() {};
259 
removeRef()260         void removeRef() {};
261 
queryInterface(const PVUuid &,PVInterface * &)262         bool queryInterface(const PVUuid&, PVInterface*&)
263         {
264             return false;
265         };
266 
267         PVMFMemoryBufferWriteDataStreamImpl *iWriteDataStream;
268 
269         PVMFMemoryBufferDataStreamTempCache* iTempCache;
270 
271         PVMFMemoryBufferDataStreamPermCache* iPermCache;
272 
273         bool iDownloadComplete;
274 
275         Oscl_Vector<PVMFMemoryBufferReadDataStreamImpl*, OsclMemAllocator> iReadStreamVec;
276 };
277 
278 
279 //////////////////////////////////////////////////////////////////////
280 // PVMFMemoryBufferWriteDataStreamFactoryImpl
281 //////////////////////////////////////////////////////////////////////
282 class PVMFMemoryBufferWriteDataStreamFactoryImpl : public PVMFDataStreamFactory
283 {
284     public:
285         OSCL_IMPORT_REF PVMFMemoryBufferWriteDataStreamFactoryImpl(PVMFMemoryBufferDataStreamTempCache* aTempCache,
286                 PVMFMemoryBufferDataStreamPermCache* aPermCache, MBDSStreamFormat aStreamFormat, uint32 aTempCacheCapacity);
287 
288         OSCL_IMPORT_REF ~PVMFMemoryBufferWriteDataStreamFactoryImpl();
289 
290         OSCL_IMPORT_REF PVMFStatus QueryAccessInterfaceUUIDs(Oscl_Vector<PVUuid, OsclMemAllocator>& aUuids);
291 
292         OSCL_IMPORT_REF PVInterface* CreatePVMFCPMPluginAccessInterface(PVUuid& aUuid);
293 
294         OSCL_IMPORT_REF void DestroyPVMFCPMPluginAccessInterface(PVUuid& aUuid, PVInterface* aPtr);
295 
296         OSCL_IMPORT_REF void NotifyDownloadComplete();
297 
298     private:
addRef()299         void addRef() {};
300 
removeRef()301         void removeRef() {};
302 
queryInterface(const PVUuid &,PVInterface * &)303         bool queryInterface(const PVUuid&, PVInterface*&)
304         {
305             return false;
306         };
307 
308         PVMFMemoryBufferWriteDataStreamImpl *iWriteDataStream;
309 
310         PVMFMemoryBufferDataStreamTempCache* iTempCache;
311 
312         PVMFMemoryBufferDataStreamPermCache* iPermCache;
313 
314         bool iDownloadComplete;
315 
316         MBDSStreamFormat iStreamFormat;
317 
318         uint32 iTempCacheCapacity;
319 };
320 
321 
322 //////////////////////////////////////////////////////////////////////
323 // PVMFMemoryBufferReadDataStreamImpl
324 //////////////////////////////////////////////////////////////////////
325 class PVMFMemoryBufferReadDataStreamImpl : public PVMIDataStreamSyncInterface
326 {
327     public:
328         OSCL_IMPORT_REF PVMFMemoryBufferReadDataStreamImpl(PVMFMemoryBufferWriteDataStreamImpl* aWriteDataStream,
329                 PVMFMemoryBufferDataStreamTempCache* aTempCache,
330                 PVMFMemoryBufferDataStreamPermCache* aPermCache);
331 
332         OSCL_IMPORT_REF ~PVMFMemoryBufferReadDataStreamImpl();
333 
334         // From PVInterface
addRef()335         void addRef() {};
336 
removeRef()337         void removeRef() {};
338 
339         OSCL_IMPORT_REF bool queryInterface(const PVUuid& uuid, PVInterface*& iface);
340 
341         OSCL_IMPORT_REF PvmiDataStreamStatus OpenSession(PvmiDataStreamSession& aSessionID,
342                 PvmiDataStreamMode aMode,
343                 bool nonblocking = false);
344 
345         OSCL_IMPORT_REF PvmiDataStreamStatus CloseSession(PvmiDataStreamSession aSessionID);
346 
347         OSCL_IMPORT_REF PvmiDataStreamRandomAccessType QueryRandomAccessCapability();
348 
349         OSCL_IMPORT_REF PvmiDataStreamStatus QueryReadCapacity(PvmiDataStreamSession aSessionID,
350                 uint32& capacity);
351 
352         OSCL_IMPORT_REF PvmiDataStreamCommandId RequestReadCapacityNotification(PvmiDataStreamSession aSessionID,
353                 PvmiDataStreamObserver& observer,
354                 uint32 capacity,
355                 OsclAny* aContextData = NULL);
356 
357         OSCL_IMPORT_REF PvmiDataStreamStatus QueryWriteCapacity(PvmiDataStreamSession aSessionID,
358                 uint32& capacity);
359 
360         OSCL_IMPORT_REF PvmiDataStreamCommandId RequestWriteCapacityNotification(PvmiDataStreamSession aSessionID,
361                 PvmiDataStreamObserver& observer,
362                 uint32 capacity,
363                 OsclAny* aContextData = NULL);
364 
365         OSCL_IMPORT_REF PvmiDataStreamCommandId CancelNotification(PvmiDataStreamSession aSessionID,
366                 PvmiDataStreamObserver& observer,
367                 PvmiDataStreamCommandId aID,
368                 OsclAny* aContextData = NULL);
369 
370         OSCL_IMPORT_REF PvmiDataStreamStatus CancelNotificationSync(PvmiDataStreamSession aSessionID);
371 
372         OSCL_IMPORT_REF PvmiDataStreamStatus Read(PvmiDataStreamSession aSessionID, uint8* buffer,
373                 uint32 size, uint32& numelements);
374 
375         OSCL_IMPORT_REF PvmiDataStreamStatus Write(PvmiDataStreamSession aSessionID, uint8* buffer,
376                 uint32 size, uint32& numelements);
377 
378         OSCL_IMPORT_REF PvmiDataStreamStatus Write(PvmiDataStreamSession aSessionID, OsclRefCounterMemFrag* frag,
379                 uint32& aNumElements);
380 
381         OSCL_IMPORT_REF PvmiDataStreamStatus Seek(PvmiDataStreamSession aSessionID,
382                 int32 offset, PvmiDataStreamSeekType origin);
383 
384         OSCL_IMPORT_REF uint32 GetCurrentPointerPosition(PvmiDataStreamSession aSessionID);
385 
386         OSCL_IMPORT_REF PvmiDataStreamStatus Flush(PvmiDataStreamSession aSessionID);
387 
388         OSCL_IMPORT_REF void NotifyDownloadComplete();
389 
SetContentLength(uint32 aContentLength)390         void SetContentLength(uint32 aContentLength)
391         {
392             OSCL_UNUSED_ARG(aContentLength);
393         }
394 
395         OSCL_IMPORT_REF uint32 GetContentLength();
396 
397         OSCL_IMPORT_REF PvmiDataStreamStatus SetSourceRequestObserver(PvmiDataStreamRequestObserver& aObserver);
398 
399         OSCL_IMPORT_REF PvmiDataStreamStatus SetBufferingCapacityAndTrimMargin(uint32 aMinCapacity, uint32 aTrimMargin);
400 
401         OSCL_IMPORT_REF uint32 QueryBufferingCapacity();
402 
403         OSCL_IMPORT_REF uint32 QueryBufferingTrimMargin();
404 
SourceRequestCompleted(const PVMFCmdResp & aResponse)405         void SourceRequestCompleted(const PVMFCmdResp& aResponse)
406         {
407             OSCL_UNUSED_ARG(aResponse);
408         }
409 
410         OSCL_IMPORT_REF PvmiDataStreamStatus MakePersistent(int32 aOffset, uint32 aSize);
411 
412         // This returns the offsets in the temp cache
413         OSCL_IMPORT_REF void GetCurrentByteRange(uint32& aCurrentFirstByteOffset, uint32& aCurrentLastByteOffset);
414 
415     public:
416         bool iDownloadComplete;
417 
418     private:
419         PVMFMemoryBufferDataStreamTempCache* iTempCache;
420 
421         PVMFMemoryBufferDataStreamPermCache* iPermCache;
422 
423         PVMFMemoryBufferWriteDataStreamImpl* iWriteDataStream;
424 
425         OSCL_wHeapString<OsclMemAllocator> iFileName;
426 
427         PvmiDataStreamSession iSessionID;
428 
429         PVLogger* iLogger;
430 
431         uint32 iFilePtrPos;
432 
433         bool iReadSessionOpened;
434 };
435 
436 
437 //////////////////////////////////////////////////////////////////////
438 // PVMFMemoryBufferWriteDataStreamImpl
439 //////////////////////////////////////////////////////////////////////
440 class PVMFMemoryBufferWriteDataStreamImpl : public PVMIDataStreamSyncInterface
441 {
442     public:
443         OSCL_IMPORT_REF PVMFMemoryBufferWriteDataStreamImpl(PVMFMemoryBufferDataStreamTempCache* aTempCache,
444                 PVMFMemoryBufferDataStreamPermCache* aPermCache, MBDSStreamFormat aStreamFormat,
445                 uint32 aTempCacheCapacity);
446 
447         OSCL_IMPORT_REF ~PVMFMemoryBufferWriteDataStreamImpl();
448 
449         // From PVInterface
addRef()450         void addRef() {};
451 
removeRef()452         void removeRef() {};
453 
454         OSCL_IMPORT_REF bool queryInterface(const PVUuid& uuid, PVInterface*& iface);
455 
456         OSCL_IMPORT_REF PvmiDataStreamStatus OpenSession(PvmiDataStreamSession& aSessionID,
457                 PvmiDataStreamMode aMode,
458                 bool nonblocking = false);
459 
460         OSCL_IMPORT_REF PvmiDataStreamStatus CloseSession(PvmiDataStreamSession aSessionID);
461 
462         OSCL_IMPORT_REF PvmiDataStreamStatus OpenReadSession(PvmiDataStreamSession& aSessionID,
463                 PvmiDataStreamMode aMode,
464                 bool nonblocking = false,
465                 PVMFMemoryBufferReadDataStreamImpl* aReadDataStream = NULL);
466 
467         OSCL_IMPORT_REF PvmiDataStreamRandomAccessType QueryRandomAccessCapability();
468 
469         OSCL_IMPORT_REF PvmiDataStreamStatus QueryReadCapacity(PvmiDataStreamSession aSessionID,
470                 uint32& aCapacity);
471 
472         OSCL_IMPORT_REF PvmiDataStreamCommandId RequestReadCapacityNotification(PvmiDataStreamSession aSessionID,
473                 PvmiDataStreamObserver& aobserver,
474                 uint32 aCapacity,
475                 OsclAny* aContextData = NULL);
476 
477         OSCL_IMPORT_REF PvmiDataStreamStatus QueryWriteCapacity(PvmiDataStreamSession aSessionID,
478                 uint32& aCapacity);
479 
480         OSCL_IMPORT_REF PvmiDataStreamCommandId RequestWriteCapacityNotification(PvmiDataStreamSession aSessionID,
481                 PvmiDataStreamObserver& aObserver,
482                 uint32 aCapacity,
483                 OsclAny* aContextData = NULL);
484 
485         OSCL_IMPORT_REF PvmiDataStreamCommandId CancelNotification(PvmiDataStreamSession aSessionID,
486                 PvmiDataStreamObserver& aObserver,
487                 PvmiDataStreamCommandId aID,
488                 OsclAny* aContextData = NULL);
489         OSCL_IMPORT_REF PvmiDataStreamStatus CancelNotificationSync(PvmiDataStreamSession aSessionID);
490 
491         OSCL_IMPORT_REF PvmiDataStreamStatus Read(PvmiDataStreamSession aSessionID, uint8* buffer,
492                 uint32 size, uint32& numelements);
493 
494         OSCL_IMPORT_REF PvmiDataStreamStatus Write(PvmiDataStreamSession aSessionID, uint8* buffer,
495                 uint32 size, uint32& numelements);
496 
497         OSCL_IMPORT_REF PvmiDataStreamStatus Write(PvmiDataStreamSession aSessionID, OsclRefCounterMemFrag* frag,
498                 uint32& aNumElements);
499 
500 
501         OSCL_IMPORT_REF PvmiDataStreamStatus Seek(PvmiDataStreamSession aSessionID, int32 offset,
502                 PvmiDataStreamSeekType origin);
503 
504         OSCL_IMPORT_REF PvmiDataStreamStatus Reposition(PvmiDataStreamSession aSessionID,
505                 uint32 aOffset, MBDSRepositionMode aMode);
506 
507         OSCL_IMPORT_REF uint32 GetCurrentPointerPosition(PvmiDataStreamSession aSessionID) ;
508 
509         OSCL_IMPORT_REF PvmiDataStreamStatus Flush(PvmiDataStreamSession aSessionID);
510 
511         OSCL_IMPORT_REF void NotifyDownloadComplete();
512 
513         OSCL_IMPORT_REF void SetContentLength(uint32 aContentLength);
514 
515         OSCL_IMPORT_REF uint32 GetContentLength();
516 
517         OSCL_IMPORT_REF PvmiDataStreamStatus SetSourceRequestObserver(PvmiDataStreamRequestObserver& aObserver);
518 
519         OSCL_IMPORT_REF void SourceRequestCompleted(const PVMFCmdResp& aResponse);
520 
521         OSCL_IMPORT_REF PvmiDataStreamStatus MakePersistent(int32 aOffset, uint32 aSize);
522 
523         OSCL_IMPORT_REF PvmiDataStreamStatus SetBufferingCapacityAndTrimMargin(uint32 aMinCapacity, uint32 aTrimMargin);
524 
525         OSCL_IMPORT_REF uint32 QueryBufferingCapacity();
526 
527         OSCL_IMPORT_REF uint32 QueryBufferingTrimMargin();
528 
529         OSCL_IMPORT_REF PvmiDataStreamStatus SetReadPointerPosition(PvmiDataStreamSession aSessionID, uint32 aFilePosition);
530 
531 
532         OSCL_IMPORT_REF PvmiDataStreamStatus SetReadPointerCacheLocation(PvmiDataStreamSession aSessionID, bool aInTempCache);
533 
534         OSCL_IMPORT_REF void ManageCache();
535 
536         OSCL_IMPORT_REF void TrimTempCache(MBDSCacheTrimMode aTrimMode);
537 
538         OSCL_IMPORT_REF void UpdateReadPointersAfterMakePersistent();
539 
540         OSCL_IMPORT_REF bool GetPermCachePersistence(uint32& aFirstOffset, uint32& aLastOffset);
541 
542         OSCL_IMPORT_REF void SetStreamFormat(MBDSStreamFormat aStreamFormat);
543 
544         OSCL_IMPORT_REF void SetTempCacheCapacity(uint32 aCapacity);
545 
546         OSCL_IMPORT_REF MBDSStreamFormat GetStreamFormat();
547 
548         OSCL_IMPORT_REF uint32 GetTempCacheCapacity();
549 
550     public:
551         bool iDownloadComplete;
552 
553     private:
554 
555         OSCL_IMPORT_REF void ManageReadCapacityNotifications();
556 
557     private:
558 
559         struct ReadCapacityNotificationStruct
560         {
561             bool iReadStructValid;
562 
563             bool iOutstanding;
564 
565             PvmiDataStreamSession iReadSessionID;
566 
567             PvmiDataStreamObserver *iReadObserver;
568 
569             uint32 iFilePosition;
570 
571             uint32 iReadCapacity;
572 
573             OsclAny* iContextData;
574 
575             PVMFCommandId iCommandID;
576 
577             PVMFCommandId iCurrentCommandID;
578         };
579 
580 
581         struct WriteCapacityNotificationStruct
582         {
583             bool iOutstanding;
584 
585             PvmiDataStreamSession iWriteSessionID;
586 
587             PvmiDataStreamObserver *iWriteObserver;
588 
589             uint32 iFilePosition;
590 
591             uint32 iWriteCapacity;
592 
593             OsclAny* iContextData;
594 
595             PVMFCommandId iCommandID;
596 
597             PVMFCommandId iCurrentCommandID;
598         };
599 
600 
601         struct RepositionRequestStruct
602         {
603             bool iOutstanding;
604 
605             bool iRequestCompleted;
606 
607             PvmiDataStreamStatus iSuccess;
608 
609             PvmiDataStreamSession iRepositionSessionID;
610 
611             uint32 iNewFilePosition;
612 
613             bool iFlushCache;
614 
RepositionRequestStructRepositionRequestStruct615             RepositionRequestStruct():
616                 iOutstanding(false),
617                 iRequestCompleted(false),
618                 iSuccess(PVDS_FAILURE),
619                 iRepositionSessionID(-1),
620                 iNewFilePosition(0),
621                 iFlushCache(false)
622             {}
623         };
624 
625         struct ReadFilePositionStruct
626         {
627             bool iReadPositionStructValid;
628 
629             uint32 iReadFilePtr;
630 
631             bool iInTempCache;
632 
633             PVMFMemoryBufferReadDataStreamImpl* iReadDataStream;
634         };
635 
636         PVMFMemoryBufferDataStreamTempCache* iTempCache;
637 
638         PVMFMemoryBufferDataStreamPermCache* iPermCache;
639 
640         uint32 iNumReadSessions;
641 
642         ReadCapacityNotificationStruct iReadNotifications[PV_MBDS_MAX_NUMBER_OF_READ_CONNECTIONS];
643 
644         RepositionRequestStruct iRepositionRequest;
645 
646         ReadFilePositionStruct iReadFilePositions[PV_MBDS_MAX_NUMBER_OF_READ_CONNECTIONS];
647 
648         PvmiDataStreamSession iSessionID;
649 
650         int32 iFileNumBytes;
651 
652         PVLogger* iLogger;
653 
654         uint32 iContentLength;
655 
656         PvmiDataStreamRequestObserver* iRequestObserver;
657 
658         bool iWriteSessionOpened;
659 
660         WriteCapacityNotificationStruct iWriteNotification;
661 
662         // Tracks current write file pointer position
663         uint32 iFilePtrPos;
664 
665         bool iThrowAwayData;
666 
667         // Tracks the audio/video/text session read pointers
668         PvmiDataStreamSession iAVTSessionID[3];
669         uint32 iAVTOffsetDelta;
670 
671         bool iMadePersistent;
672 
673         MBDSStreamFormat iStreamFormat;
674 
675         uint32 iTempCacheCapacity;
676 
677         uint32 iTempCacheTrimThreshold;
678 
679         uint32 iTempCacheTrimMargin;
680 };
681 
682 
683 //////////////////////////////////////////////////////////////////////
684 // PVMFMemoryBufferDataStream
685 //////////////////////////////////////////////////////////////////////
686 class PVMFMemoryBufferDataStream
687 {
688     public:
689         // in case we would want to pass the constructor an existing cache
690         OSCL_IMPORT_REF PVMFMemoryBufferDataStream(PVMFFormatType& aStreamFormat, uint32 aTempCacheCapacity);
691 
692         OSCL_IMPORT_REF ~PVMFMemoryBufferDataStream();
693 
694         OSCL_IMPORT_REF PVMFDataStreamFactory* GetReadDataStreamFactoryPtr();
695 
696         OSCL_IMPORT_REF PVMFDataStreamFactory* GetWriteDataStreamFactoryPtr();
697 
698         OSCL_IMPORT_REF void NotifyDownloadComplete();
699 
700     private:
701         PVMFMemoryBufferReadDataStreamFactoryImpl* iReadDataStreamFactory;
702 
703         PVMFMemoryBufferWriteDataStreamFactoryImpl* iWriteDataStreamFactory;
704 
705         PVInterface* iWriteDataStream;
706 
707         PVMFMemoryBufferDataStreamTempCache* iTemporaryCache;
708 
709         PVMFMemoryBufferDataStreamPermCache* iPermanentCache;
710 
711         PVLogger* iLogger;
712 };
713 
714 #endif // PVMF_MEMORYBUFFERDATASTREAM_FACTORY_H_INCLUDED
715 
716 
717 #endif//PVMF_DOWNLOADMANAGER_SUPPORT_PPB
718 
719