Home | History | Annotate | Download | only in include
      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 // -*- c++ -*-
     19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
     20 
     21 //           A U D I O    M P 3   G E T    I D 3    I N F O
     22 
     23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
     24 
     25 
     26 /**
     27  *  @file pvfile.h
     28  *  @brief This include file contains the definitions and classes needed
     29  *  to access a file either through Oscl File I/O or CPM.
     30  */
     31 
     32 
     33 #ifndef PVFILE_H_INCLUDED
     34 #define PVFILE_H_INCLUDED
     35 
     36 #ifndef OSCL_TYPES_H_INCLUDED
     37 #include "oscl_types.h"
     38 #endif
     39 #ifndef OSCL_FILE_IO_H_INCLUDED
     40 #include "oscl_file_io.h"
     41 #endif
     42 
     43 /**
     44 * PVFile is a class with an API similar to Oscl File I/O.
     45 * It allows the parser libraries to access a local file
     46 * source either through CPM or through Oscl File I/O, depending
     47 * on the parameters provided in the local source data.
     48 */
     49 
     50 class PVMFCPMPluginAccessInterfaceFactory;
     51 class PVMIDataStreamSyncInterface;
     52 class PvmiDataStreamObserver;
     53 
     54 #define PVFILE_DEFAULT_CACHE_SIZE 4*1024
     55 #define PVFILE_DEFAULT_ASYNC_READ_BUFFER_SIZE 0
     56 #define PVFILE_DEFAULT_NATIVE_ACCESS_MODE 0
     57 
     58 class PVFileCacheParams
     59 {
     60     public:
     61         PVFileCacheParams()
     62         {
     63             iCacheSize = PVFILE_DEFAULT_CACHE_SIZE;
     64             iAsyncReadBuffSize = PVFILE_DEFAULT_ASYNC_READ_BUFFER_SIZE;
     65             iNativeAccessMode = PVFILE_DEFAULT_NATIVE_ACCESS_MODE;
     66             iPVLoggerEnableFlag = false;
     67             iPVLoggerStateEnableFlag = false;
     68         }
     69 
     70         PVFileCacheParams(const PVFileCacheParams& a)
     71         {
     72             MyCopy(a);
     73         }
     74 
     75         /**
     76          * The assignment operator
     77          */
     78         PVFileCacheParams& operator=(const PVFileCacheParams& a)
     79         {
     80             if (&a != this)
     81             {
     82                 MyCopy(a);
     83             }
     84             return *this;
     85         }
     86 
     87         uint32 iCacheSize;
     88         uint32 iAsyncReadBuffSize;
     89         bool iPVLoggerEnableFlag;
     90         bool iPVLoggerStateEnableFlag;
     91         uint32 iNativeAccessMode;
     92 
     93     private:
     94         void MyCopy(const PVFileCacheParams& a)
     95         {
     96             iCacheSize = a.iCacheSize;
     97             iAsyncReadBuffSize = a.iAsyncReadBuffSize;
     98             iPVLoggerEnableFlag = a.iPVLoggerEnableFlag;
     99             iPVLoggerStateEnableFlag = a.iPVLoggerStateEnableFlag;
    100             iNativeAccessMode = a.iNativeAccessMode;
    101         }
    102 };
    103 
    104 class PVFile
    105 {
    106     public:
    107         //default constructor.
    108         PVFile()
    109         {
    110             Reset();
    111         }
    112 
    113         //API to copy all fields from another object.
    114         void Copy(const PVFile&a)
    115         {
    116             iFile = a.iFile;
    117             iFilePtr = a.iFilePtr;
    118             iFileHandle = a.iFileHandle;
    119             iCPMAccessFactory = a.iCPMAccessFactory;
    120             iDataStreamAccess = a.iDataStreamAccess;
    121             iFileSize = a.iFileSize;
    122             iFileSizeAvailable = a.iFileSizeAvailable;
    123             iDataStreamSession = a.iDataStreamSession;
    124             iRequestReadCapacityNotificationID = a.iRequestReadCapacityNotificationID;
    125             iOsclFileCacheParams = a.iOsclFileCacheParams;
    126         }
    127 
    128         //copy constructor.
    129         PVFile(const PVFile&a)
    130         {
    131             Copy(a);
    132         }
    133 
    134         ~PVFile()
    135         {
    136         }
    137 
    138         void Reset()
    139         {
    140             iFile = NULL;
    141             iFileHandle = NULL;
    142             iCPMAccessFactory = NULL;
    143             iFilePtr = NULL;
    144             iDataStreamAccess = NULL;
    145             iFileSize = 0;
    146             iFileSizeAvailable = false;
    147             iRequestReadCapacityNotificationID = 0;
    148         }
    149 
    150         //API to set the CPM access interface.
    151         //The CPM access interface is provided in the
    152         //local file source data.
    153         void SetCPM(PVMFCPMPluginAccessInterfaceFactory*a)
    154         {
    155             iCPMAccessFactory = a;
    156         }
    157 
    158         //API to get the CPM access interface factory
    159         PVMFCPMPluginAccessInterfaceFactory* GetCPM()
    160         {
    161             return iCPMAccessFactory;
    162         }
    163 
    164         //API to set the internal file handle.
    165         //The file handle is provided in the local file source data.
    166         void SetFileHandle(OsclFileHandle*a)
    167         {
    168             iFileHandle = a;
    169         }
    170 
    171         //To support access through an existing, open Oscl_File object.
    172         //This was an add-on for some MP4 file parser libraries-- not
    173         //used with the normal local file source access.
    174         //With this access mode, Open/Close should not be called.
    175         void SetFilePtr(Oscl_File*a)
    176         {
    177             iFilePtr = a;
    178         }
    179 
    180         //API to copy the access parameters from another object
    181         void SetAccess(const PVFile& a)
    182         {
    183             iCPMAccessFactory = a.iCPMAccessFactory;
    184             iFileHandle = a.iFileHandle;
    185             iFilePtr = a.iFilePtr;
    186             iFile = a.iFile;
    187         }
    188 
    189         //API to tell whether file is open.
    190         bool IsOpen()
    191         {
    192             if ((iFilePtr != NULL) ||
    193                     (iFile != NULL) ||
    194                     (iDataStreamAccess != NULL))
    195             {
    196                 return true;
    197             }
    198             return false;
    199         }
    200 
    201         //Only valid in case Oscl_File class is being used
    202         //internally for file access. In case of datastream
    203         //access or in case of Oscl_File ptr provided for outside
    204         //via SetFilePtr API, it is assumed that implementor of datastream
    205         //has picked appropriate caching mechanism.
    206         void SetFileCacheParams(PVFileCacheParams aParams)
    207         {
    208             iOsclFileCacheParams = aParams;
    209         }
    210 
    211         //Access APIs, same functionality as Oscl File I/O.
    212         OSCL_IMPORT_REF int32 Seek(int32 offset, Oscl_File::seek_type origin);
    213         OSCL_IMPORT_REF int32 Tell();
    214         OSCL_IMPORT_REF uint32 Read(OsclAny *buffer, uint32 size, uint32 numelements) ;
    215         OSCL_IMPORT_REF int32 Close();
    216         OSCL_IMPORT_REF int32 Flush();
    217         OSCL_IMPORT_REF int32 Open(const oscl_wchar *filename,
    218                                    uint32 mode,
    219                                    Oscl_FileServer& fileserv);
    220         OSCL_IMPORT_REF bool GetRemainingBytes(uint32& aNumBytes);
    221 
    222         OSCL_IMPORT_REF bool RequestReadCapacityNotification(PvmiDataStreamObserver& aObserver,
    223                 uint32 aCapacity,
    224                 OsclAny* aContextData = NULL);
    225 
    226         OSCL_IMPORT_REF bool CancelNotificationSync();
    227 
    228         // For memory buffer data stream
    229         // file size is content length from HTTP HEAD response
    230         OSCL_IMPORT_REF uint32 GetContentLength();
    231 
    232         // memory cache size, is 0 if not MBDS
    233         OSCL_IMPORT_REF uint32 GetFileBufferingCapacity();
    234 
    235         // For memory buffer data stream
    236         // portion of the data can be copied to persistent storage for the duration of playback
    237         OSCL_IMPORT_REF bool MakePersistent(int32 offset, uint32 size);
    238 
    239         // For memory buffer data stream
    240         // to trigger a http GET request
    241         // like a seek but read pointer doesn't change
    242         OSCL_IMPORT_REF int32 Skip(int32 offset, Oscl_File::seek_type origin);
    243 
    244         // For memory buffer data stream
    245         // returns the byte range availabe in the stream cache
    246         OSCL_IMPORT_REF void GetCurrentByteRange(uint32& aCurrentFirstByteOffset, uint32& aCurrentLastByteOffset);
    247 
    248     private:
    249         //Access parameters from local source data
    250         PVMFCPMPluginAccessInterfaceFactory* iCPMAccessFactory;
    251         OsclFileHandle* iFileHandle;
    252 
    253         //Internal implementation.
    254         Oscl_File* iFile;
    255         PVMIDataStreamSyncInterface* iDataStreamAccess;
    256         int32 iDataStreamSession;
    257 
    258         //For the alternate access method-- through an existing file object.
    259         Oscl_File* iFilePtr;
    260         uint32 iFileSize;
    261         bool iFileSizeAvailable;
    262         uint32 iRequestReadCapacityNotificationID;
    263         PVFileCacheParams iOsclFileCacheParams;
    264 };
    265 
    266 
    267 
    268 #endif  // PVFILE_H_INCLUDED
    269 
    270