Home | History | Annotate | Download | only in src
      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 /**
     19  *
     20  * @file pvmf_media_input_node_outport.h
     21  * @brief Output port for media io interface wrapper node
     22  *
     23  */
     24 
     25 #ifndef PVMF_MEDIA_INPUT_NODE_OUTPORT_H_INCLUDED
     26 #define PVMF_MEDIA_INPUT_NODE_OUTPORT_H_INCLUDED
     27 
     28 #ifndef OSCL_BASE_H_INCLUDED
     29 #include "oscl_base.h"
     30 #endif
     31 #ifndef OSCL_VECTOR_H_INCLUDED
     32 #include "oscl_vector.h"
     33 #endif
     34 #ifndef OSCL_MEM_H_INCLUDED
     35 #include "oscl_mem.h"
     36 #endif
     37 #ifndef OSCL_SCHEDULER_AO_H_INCLUDED
     38 #include "oscl_scheduler_ao.h"
     39 #endif
     40 #ifndef PVMF_MEDIA_DATA_H_INCLUDED
     41 #include "pvmf_media_data.h"
     42 #endif
     43 #ifndef PVMF_PORT_BASE_IMPL_H_INCLUDED
     44 #include "pvmf_port_base_impl.h"
     45 #endif
     46 #ifndef PVMI_MEDIA_TRANSFER_H_INCLUDED
     47 #include "pvmi_media_transfer.h"
     48 #endif
     49 #ifndef OSCL_MEM_MEMPOOL_H_INCLUDED
     50 #include "oscl_mem_mempool.h"
     51 #endif
     52 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED
     53 #include "pvmf_node_interface.h"
     54 #endif
     55 #ifndef PVMI_CONFIG_AND_CAPABILITY_UTILS_H_INCLUDED
     56 #include "pvmi_config_and_capability_utils.h"
     57 #endif
     58 #ifndef PVMF_MEDIA_INPUT_DATA_BUFFER_H_INCLUDED
     59 #include "pvmf_media_input_data_buffer.h"
     60 #endif
     61 
     62 #include "pvmf_pool_buffer_allocator.h"
     63 
     64 // Forward declaration
     65 class PvmfMediaInputNode;
     66 
     67 class PvmfMediaInputNodeOutPort : public OsclTimerObject,
     68         public OsclMemPoolFixedChunkAllocatorObserver,
     69         public PvmfPortBaseImpl,
     70         public PvmiMediaTransfer,
     71         public PVMFPortActivityHandler,
     72         public PvmiCapabilityAndConfig
     73 {
     74     public:
     75         PvmfMediaInputNodeOutPort(PvmfMediaInputNode* aNode, const char* aName = NULL);
     76         ~PvmfMediaInputNodeOutPort();
     77 
     78         void Start();
     79         void MediaIOStarted();
     80         void Pause();
     81         void Stop();
     82 
     83         PVMFStatus Configure(PVMFFormatType aPortProperty, OSCL_String* aMime);
     84 
     85         // these override the PvmfPortBaseImpl routines
     86         OSCL_IMPORT_REF PVMFStatus Connect(PVMFPortInterface* aPort);
     87         OSCL_IMPORT_REF PVMFStatus Disconnect();
     88         OSCL_IMPORT_REF PVMFStatus PeerConnect(PVMFPortInterface* aPort);
     89         OSCL_IMPORT_REF PVMFStatus PeerDisconnect();
     90         void QueryInterface(const PVUuid &aUuid, OsclAny*&aPtr)
     91         {
     92             if (aUuid == PVMI_CAPABILITY_AND_CONFIG_PVUUID)
     93             {
     94                 aPtr = (PvmiCapabilityAndConfig*)this;
     95             }
     96             else
     97             {
     98                 aPtr = NULL;
     99             }
    100         }
    101 
    102         //from PVMFPortActivityHandler
    103         void HandlePortActivity(const PVMFPortActivity& aActivity);
    104 
    105         // Pure virtuals from PvmiMediaTransfer
    106         void setPeer(PvmiMediaTransfer *aPeer);
    107         void useMemoryAllocators(OsclMemAllocator* write_alloc = NULL);
    108         PVMFCommandId writeAsync(uint8 format_type, int32 format_index, uint8* data, uint32 data_len,
    109                                  const PvmiMediaXferHeader& data_header_info, OsclAny* aContext = NULL);
    110         void writeComplete(PVMFStatus aStatus, PVMFCommandId  write_cmd_id, OsclAny* aContext);
    111         PVMFCommandId readAsync(uint8* data, uint32 max_data_len, OsclAny* aContext = NULL,
    112                                 int32* formats = NULL, uint16 num_formats = 0);
    113         void readComplete(PVMFStatus aStatus, PVMFCommandId  read_cmd_id, int32 format_index,
    114                           const PvmiMediaXferHeader& data_header_info, OsclAny* aContext);
    115         void statusUpdate(uint32 status_flags);
    116         void cancelCommand(PVMFCommandId  command_id);
    117         void cancelAllCommands();
    118 
    119         // Implement pure virtuals from PvmiCapabilityAndConfig interface
    120         OSCL_IMPORT_REF void setObserver(PvmiConfigAndCapabilityCmdObserver* aObserver);
    121         OSCL_IMPORT_REF PVMFStatus getParametersSync(PvmiMIOSession aSession, PvmiKeyType aIdentifier,
    122                 PvmiKvp*& aParameters, int& num_parameter_elements,
    123                 PvmiCapabilityContext aContext);
    124         OSCL_IMPORT_REF PVMFStatus releaseParameters(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
    125         OSCL_IMPORT_REF void createContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext);
    126         OSCL_IMPORT_REF void setContextParameters(PvmiMIOSession aSession, PvmiCapabilityContext& aContext,
    127                 PvmiKvp* aParameters, int num_parameter_elements);
    128         OSCL_IMPORT_REF void DeleteContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext);
    129         OSCL_IMPORT_REF void setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters,
    130                                                int num_elements, PvmiKvp * & aRet_kvp);
    131         OSCL_IMPORT_REF PVMFCommandId setParametersAsync(PvmiMIOSession aSession, PvmiKvp* aParameters,
    132                 int num_elements, PvmiKvp*& aRet_kvp, OsclAny* context = NULL);
    133         OSCL_IMPORT_REF uint32 getCapabilityMetric(PvmiMIOSession aSession);
    134         OSCL_IMPORT_REF PVMFStatus verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
    135         void SendEndOfTrackCommand(const PvmiMediaXferHeader& data_header_info);
    136 
    137         PVMFPortInterface* getConnectedPort() {
    138             return iConnectedPort;
    139        }
    140 
    141     private:
    142 
    143         void Run();
    144         void freechunkavailable(OsclAny*);
    145         // Container node
    146         PvmfMediaInputNode* iNode;
    147 
    148         //Format
    149         PVMFFormatType iFormatType;
    150 
    151         PvmiMediaTransfer* iMediaInput;
    152         uint32 iRemoteStatus;
    153 
    154         uint32 iCmdId;
    155 
    156         PvmfMediaInputDataBufferAlloc* iMediaDataAlloc;
    157         OsclMemPoolFixedChunkAllocator* iMediaDataAllocMemPool;
    158         OsclMemPoolFixedChunkAllocator* iMediaDataMemPool;
    159 
    160         enum WriteState {EWriteBusy, EWriteOK};
    161         WriteState iWriteState;
    162         enum PortState
    163         {
    164             PORT_STATE_BUFFERING = 0,
    165             PORT_STATE_STARTED,
    166             PORT_STATE_STOPPED,
    167             PORT_STATE_ENDOFTRACK
    168         };
    169         PortState iState;
    170         PVMFFormatType iFormat;
    171 
    172         //for flow control
    173 
    174         PvmiMediaTransfer* iPeer;
    175 
    176 
    177 
    178         // Format specific info
    179         OsclRefCounterMemFrag iFormatSpecificInfo;
    180         uint32 inum_text_sample;
    181         uint32 imax_num_sample;
    182 #ifdef _TEST_AE_ERROR_HANDLING
    183         uint32 iTimeStampJunk;
    184 #endif
    185         //logging
    186         OSCL_HeapString<OsclMemAllocator> iMimeType;
    187         PVLogger* iDataPathLogger;
    188 };
    189 
    190 #endif // PVMF_MEDIA_INPUT_NODE_INPORT_H_INCLUDED
    191