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 //                 M P 3   F I L E   P A R S E R
     22 
     23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
     24 
     25 
     26 /**
     27  *  @file imp3ff.h
     28  *  @brief This file defines the MP3 File Format Interface Definition.
     29  *  It initializes and maintains the MP3 File Format Library
     30  */
     31 
     32 #ifndef IMP3FF_H_INCLUDED
     33 #define IMP3FF_H_INCLUDED
     34 
     35 
     36 //----------------------------------------------------------------------
     37 // Include Files
     38 //----------------------------------------------------------------------
     39 
     40 #ifndef OSCL_BASE_H_INCLUDED
     41 #include "oscl_base.h"
     42 #endif
     43 #ifndef OSCL_VECTOR_H_INCLUDED
     44 #include "oscl_vector.h"
     45 #endif
     46 #ifndef OSCL_String_H_INCLUDED
     47 #include "oscl_string.h"
     48 
     49 #endif
     50 #ifndef OSCL_STRING_CONTAINERS_H_INCLUDED
     51 #include "oscl_string_containers.h"
     52 #endif
     53 #ifndef OSCL_FILE_IO_H_INCLUDED
     54 #include "oscl_file_io.h"
     55 #endif
     56 #ifndef OSCL_MEM_H_INCLUDED
     57 #include "oscl_mem.h"
     58 #endif
     59 #ifndef PVFILE_H_INCLUDED
     60 #include "pvfile.h"
     61 #endif
     62 
     63 #ifndef PV_ID3_PARCOM_H_INCLUDED
     64 #include "pv_id3_parcom.h"
     65 #endif
     66 // Header files reqd for multiple sample retrieval api
     67 #ifndef OSCL_MEDIA_DATA_H
     68 #include "oscl_media_data.h"
     69 #endif
     70 #ifndef PV_GAU_H_
     71 #include "pv_gau.h"
     72 #endif
     73 
     74 // Header files for pvmf metadata handling
     75 #ifndef PVMF_RETURN_CODES_H_INCLUDED
     76 #include "pvmf_return_codes.h"
     77 #endif
     78 #ifndef PVMF_META_DATA_H_INCLUDED
     79 #include "pvmf_meta_data_types.h"
     80 #endif
     81 #ifndef PVMI_KVP_INCLUDED
     82 #include "pvmi_kvp.h"
     83 #endif
     84 
     85 
     86 
     87 //----------------------------------------------------------------------
     88 // Global Type Declarations
     89 //----------------------------------------------------------------------
     90 
     91 typedef struct _MP3ContentFormatTypeTag
     92 {
     93     uint32 Bitrate;
     94     uint32 SamplingRate;
     95     uint32 NumberOfChannels;
     96     uint32 NumberOfFrames;
     97     uint32 FrameSize;
     98     uint32 FileSizeInBytes;
     99     uint32 FrameSizeUnComp;
    100     uint32 ChannelMode;  //0: Stereo 1: Joint Ch. Stereo 2: Dual  Ch. Stereo 3: Mono
    101 } MP3ContentFormatType;
    102 
    103 typedef enum
    104 {
    105     MP3_CHANNEL_MODE_STEREO = 0,
    106     MP3_CHANNEL_MODE_JOINT_CHANNEL_STEREO = 1,
    107     MP3_CHANNEL_MODE_DUAL_CHANNEL_STEREO = 2,
    108     MP3_CHANNEL_MODE_MONO = 3
    109 } MP3ChannelMode;
    110 
    111 typedef enum
    112 {
    113     MP3_ERROR_UNKNOWN = 0,
    114     MP3_SUCCESS = 1,
    115     MP3_END_OF_FILE = 2,
    116     MP3_CRC_ERR = 3,
    117     MP3_FILE_READ_ERR = 4,
    118     MP3_FILE_HDR_READ_ERR = 5,
    119     MP3_FILE_HDR_DECODE_ERR = 6,
    120     MP3_FILE_XING_HDR_ERR = 7,
    121     MP3_FILE_VBRI_HDR_ERR = 8,
    122     MP3_ERR_NO_MEMORY = 9,
    123     MP3_NO_SYNC_FOUND = 10,
    124     MP3_FILE_OPEN_ERR = 11,
    125     /* PD related Error values*/
    126     MP3_ERROR_UNKNOWN_OBJECT = 12,
    127     MP3_FILE_OPEN_FAILED = 13,
    128     MP3_INSUFFICIENT_DATA = 14,
    129     MP3_METADATA_NOTPARSED = 15,
    130     /* Duration related Info value*/
    131     MP3_DURATION_PRESENT = 16
    132 } MP3ErrorType;
    133 
    134 //----------------------------------------------------------------------
    135 // Forward Class Declarations
    136 //----------------------------------------------------------------------
    137 class MP3Parser;
    138 class PVMFCPMPluginAccessInterfaceFactory;
    139 
    140 /**
    141  *  @brief The IMpeg3File Class is the class that will construct and maintain all the
    142  *  necessary data structures to be able to render a valid MP3 file to disk.
    143  *
    144  */
    145 
    146 class IMpeg3File
    147 {
    148     public:
    149         /**
    150         * @brief Constructor
    151         *
    152         * @param filename MP3 filename
    153         * @param bSuccess Result of operation: true=successful, false=failed
    154         * @param fileServSession Pointer to opened file server session. Used when opening
    155         * and reading the file on certain operating systems.
    156         * @returns None
    157         */
    158         OSCL_IMPORT_REF  IMpeg3File(OSCL_wString& filename, MP3ErrorType &bSuccess, Oscl_FileServer* fileServSession = NULL, PVMFCPMPluginAccessInterfaceFactory*aCPM = NULL, OsclFileHandle*aHandle = NULL, bool enableCRC = true);
    159 
    160         /**
    161         * @brief Constructor
    162         *
    163         * @param bSuccess Result of operation: true=successful, false=failed
    164         * @returns None
    165         */
    166         OSCL_IMPORT_REF IMpeg3File(MP3ErrorType &bSuccess);
    167 
    168         /**
    169         * @brief Destructor
    170         *
    171         * @param None
    172         * @returns None
    173         */
    174         OSCL_IMPORT_REF ~IMpeg3File();
    175 
    176         /**
    177         * @brief Returns the parse status of the file
    178         *
    179         * @param None
    180         * @returns Result of operation
    181         */
    182         OSCL_IMPORT_REF MP3ErrorType ParseMp3File();
    183 
    184         /**
    185         * @brief Returns the configuration details of the file
    186         *
    187         * @param mp3Config Data structure that will contain config info
    188         * @returns Result of operation: 1=success; 0=fail
    189         */
    190         OSCL_IMPORT_REF MP3ErrorType GetConfigDetails(MP3ContentFormatType &mp3Config);
    191 
    192         /**
    193         * @brief Resets the parser variables so playback can be restarted at the
    194         * specified time.
    195         *
    196         * @param timestamp value as where to start repositioning to
    197         * @returns Result of operation: 1=success; 0=fail
    198         */
    199         OSCL_IMPORT_REF uint32 ResetPlayback(uint32 timestamp = 0);
    200 
    201         /**
    202         * @brief Attempts to read in the number of audio frames specified by n
    203         *
    204         * @param n Requested number of frames to be read from file
    205         * @param pgau Frame information structure of type GAU
    206         * @returns Result of operation: 1=success; 0=fail
    207         */
    208         OSCL_IMPORT_REF int32  GetNextBundledAccessUnits(uint32 *n, GAU *pgau, MP3ErrorType &err);
    209 
    210         /**
    211         * @brief Attempts to peek into the number of audio frames specified by n
    212         *
    213         * @param n Requested number of frames to be read from file
    214         * @param mInfo Frame information structure of type MediaMetaInfo
    215         * @returns Result of operation: 1=success; 0=fail
    216         */
    217         OSCL_IMPORT_REF int32  PeekNextBundledAccessUnits(uint32 *n, MediaMetaInfo *mInfo);
    218 
    219         /**
    220         * @brief Reads the next frame from the file
    221         *
    222         * @param buf Buffer containing the frame read
    223         * @param size Size of the buffer
    224         * @param framesize Size of the frame data read
    225         * @param timestamp Timestamp of the frame
    226         * @returns Result of operation: true=success; false=fail
    227         */
    228         OSCL_IMPORT_REF MP3ErrorType GetNextMediaSample(uint8 *buf, uint32 size, uint32& framesize, uint32& timestamp);
    229 
    230         /**
    231         * @brief Returns the timestamp of the current frame
    232         *
    233         * @param None
    234         * @returns Timestamp
    235         */
    236         OSCL_IMPORT_REF uint32 GetTimestampForCurrentSample();
    237 
    238         /**
    239         * @brief Moves the file pointer to the specified timestamp
    240         *
    241         * @param timestamp Time to seek to
    242         * @returns Timestamp seeked to. If timestamp is past end of clip, timestamp is 0.
    243         */
    244         OSCL_IMPORT_REF uint32  SeekToTimestamp(uint32 timestamp);
    245 
    246         /**
    247         * @brief Queries the seek point file positiion and timestamp corresponding to the specified timestamp
    248         *
    249         * @param timestamp Time to seek to. Will be set to the actual timestamp.
    250         * @returns File position closest to the specified timestamp. If timestamp is past end of clip, file position is set to 0.
    251         */
    252         OSCL_IMPORT_REF uint32  SeekPointFromTimestamp(uint32& timestamp);
    253 
    254         /**
    255         * @brief Queries the offset corresponding to the specified timestamp
    256         *
    257         * @param timestamp Time to seek to. Will be set to the actual timestamp.
    258         * @returns offset
    259         */
    260         OSCL_IMPORT_REF uint32  GetFileOffsetForAutoResume(uint32& timestamp);
    261 
    262         /**
    263         * @brief Returns whether random access is allowed or not.
    264         *
    265         * @param None
    266         * @returns true=allowed, false=not allowed
    267         */
    268         OSCL_IMPORT_REF uint8  RandomAccessDenied();
    269 
    270         /**
    271         * @brief Returns the number of tracks in the file.
    272         *
    273         * @param None
    274         * @returns Number of tracks
    275         */
    276         OSCL_IMPORT_REF int32 GetNumTracks();
    277 
    278         /**
    279         * @brief Returns the timescale used.
    280         *
    281         * @param None
    282         * @returns Timescale
    283         */
    284         OSCL_IMPORT_REF uint32 GetTimescale() const;
    285 
    286         /**
    287         * @brief Returns the duration of the clip.
    288         *
    289         * @param None
    290         * @returns Duration
    291         */
    292         OSCL_IMPORT_REF uint32 GetDuration() const;
    293 
    294         /**
    295         * @brief Returns the approximate duration of downloaded data.
    296         *
    297         * @param aFileSize, aNPTInMS
    298         * @returns aNPTInMS
    299         */
    300         OSCL_IMPORT_REF int32 ConvertSizeToTime(uint32 aFileSize, uint32& aNPTInMS) const;
    301 
    302         /**
    303         * @brief Returns the number of frames in the clip.
    304         *
    305         * @param None
    306         * @returns Number of frames
    307         */
    308         OSCL_IMPORT_REF int32 GetNumSampleEntries();
    309 
    310         /**
    311         * @brief Returns the mime type of the clip.
    312         *
    313         * @param None
    314         * @returns Mime type
    315         */
    316         OSCL_IMPORT_REF OSCL_wHeapString<OsclMemAllocator>  GetMIMEType();
    317 
    318         /**
    319         * @brief Returns the maximum buffer size used.
    320         *
    321         * @param None
    322         * @returns Buffer size
    323         */
    324         OSCL_IMPORT_REF int32 GetMaxBufferSizeDB();
    325 
    326         /**
    327         * @brief Returns the content of decoder specific info.
    328         *
    329         * @param None
    330         * @returns Decoder specific info
    331         */
    332         OSCL_IMPORT_REF uint8 const *GetDecoderSpecificInfoContent() const;
    333 
    334         /**
    335         * @brief Returns the size of decoder specific info.
    336         *
    337         * @param None
    338         * @returns Decoder specific info size
    339         */
    340         OSCL_IMPORT_REF uint32 GetDecoderSpecificInfoSize();
    341 
    342         /**
    343         * @brief Returns the number of available metadata keys. Subset is returned if a query string is specified
    344         *
    345         * @param aQueryString A query string for the keys to select a subset of the all available keys
    346         *
    347         * @returns Number of available metadata keys
    348         */
    349         OSCL_IMPORT_REF uint32 GetNumMetadataKeys(char* aQueryString = NULL);
    350 
    351         /**
    352         * @brief Returns the number of available metadata values based on the key list provided
    353         *
    354         * @param aKeyList A list of key strings to return the number of values
    355         *
    356         * @returns Number of available metadata values
    357         */
    358         OSCL_IMPORT_REF uint32 GetNumMetadataValues(PVMFMetadataList& aKeyList);
    359 
    360         /**
    361         * @brief Returns a list of the available metadata keys.
    362         *
    363         * @param aKeyList Reference to a keylist to be filled in by this method.
    364         * @param starting_index Zero based index of which keys to get.
    365         * @param max_entries Max # of entries this method should write to the key list.
    366         * @returns None
    367         */
    368         OSCL_IMPORT_REF PVMFStatus GetMetadataKeys(PVMFMetadataList& aKeyList, uint32 aStartingKeyIndex, int32 aMaxKeyEntries, char* aQueryString);
    369 
    370         /**
    371         * @brief Returns the metadata values corresponding to the specified keys.
    372         *
    373         * @param aKeyList Reference to a keylist specifying keys for which the values are being requested.
    374         * @param aValueList Reference to value list which this method will fill in.
    375         * @param starting_index
    376         */
    377         OSCL_IMPORT_REF PVMFStatus GetMetadataValues(PVMFMetadataList& aKeyList, Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList, uint32 aStartingValueIndex, int32 aMaxValueEntries);
    378 
    379         /**
    380         * @brief Releases memory allocated for the metadata values
    381         *
    382         * @param aValueKVP Reference to metadata value stored in a KVP to release memory
    383         */
    384         OSCL_IMPORT_REF PVMFStatus ReleaseMetadataValue(PvmiKvp& aValueKVP);
    385 
    386         /**
    387         * @brief Requests call back for parser node when data stream is out of data
    388         *
    389         * @param aObserver - observer, which would receive the call back once
    390         *                   the file has been downloaded till provided offset.
    391         * @param aFileOffset - offset for which data is not available.
    392         * @param aContextData - context data
    393         */
    394         OSCL_IMPORT_REF  MP3ErrorType RequestReadCapacityNotification(PvmiDataStreamObserver& aObserver,
    395                 uint32 aFileOffset,
    396                 OsclAny* aContextData = NULL);
    397         /**
    398         * @brief Retrieves the Metadata size in the mp3 clip
    399         *
    400         * @param reference to metadatasize
    401         * @returns error type.
    402         */
    403         OSCL_IMPORT_REF MP3ErrorType GetMetadataSize(uint32& aMetaDataSize);
    404 
    405         /**
    406         * @brief Retrieves minimum bytes required for getting the config info
    407         *
    408         * @param
    409         * @returns byte size of firstframe and id3 tags.
    410         */
    411         OSCL_IMPORT_REF uint32 GetMinBytesRequired(bool aNextBytes = false);
    412 
    413         /**
    414         * @brief Sets the file size to the parser
    415         *
    416         * @param aFileSize
    417         * @returns error type.
    418         */
    419         OSCL_IMPORT_REF MP3ErrorType SetFileSize(const uint32 aFileSize);
    420 
    421         /**
    422         * @brief Verifies if the supplied file is valid mp3 file
    423         *
    424         * @param aFileName
    425         * @param aCPMAccessFactory
    426         * @param aEnableCRC - whether or not to enable crc check
    427         */
    428         OSCL_IMPORT_REF MP3ErrorType IsMp3File(OSCL_wString& aFileName,
    429                                                PVMFCPMPluginAccessInterfaceFactory *aCPMAccessFactory,
    430                                                uint32 aInitSearchFileSize);
    431 
    432         OSCL_EXPORT_REF MP3ErrorType ScanMP3File(uint32 aFramesToScan);
    433 
    434     private:
    435         OsclAny* AllocateKVPKeyArray(int32& leavecode, PvmiKvpValueType aValueType, int32 aNumElements);
    436         int32 PushKVPValue(PvmiKvp aKVP, Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList);
    437         int32 PushKVPKey(const char* aString, PVMFMetadataList& aKeyList);
    438         int32 PushKVPKey(OSCL_HeapString<OsclMemAllocator>& aString, Oscl_Vector<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator>& aKeyList);
    439 
    440         MP3Parser* pMP3Parser;
    441         PVFile iMP3File;
    442         bool iEnableCrcCalc;
    443         PVFile iScanFP;
    444         Oscl_Vector<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> iAvailableMetadataKeys;
    445 };
    446 
    447 
    448 #endif // #ifndef IMP3FF_H_INCLUDED
    449