• 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 /**
19  *
20  * @file pvmf_media_input_node_outport.h
21  * @brief Output port for media io interface wrapper node
22  *
23  */
24 
25 #ifndef PV_COMMS_IO_NODE_PORT_H_INCLUDED
26 #define PV_COMMS_IO_NODE_PORT_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 PVMI_MIO_COMM_DATA_BUFFER_H_INCLUDED
59 #include "pvmi_mio_comm_data_buffer.h"
60 #endif
61 
62 // TEMP -RH TSC deletes the allocators while comm node holds buffers
63 // so copy them for now to avoid holding onto TSC fragments.
64 #define USE_COPY_BUFFER
65 #ifdef USE_COPY_BUFFER
66 #define NUM_COPY_BUFFERS 2
67 #define COPY_BUFFER_SIZE 1024
68 #endif
69 
70 // Forward declaration
71 class PVCommsIONode;
72 
73 class PVCommsIONodePort : public OsclTimerObject,
74         public PvmfPortBaseImpl,
75         public PvmiMediaTransfer,
76         public PVMFPortActivityHandler,
77         public PvmiCapabilityAndConfig
78 {
79     public:
80         PVCommsIONodePort(int32 aPortTag, PVCommsIONode* aNode);
81         ~PVCommsIONodePort();
82 
83         OSCL_IMPORT_REF void Start();
84         OSCL_IMPORT_REF void MediaIOStarted();
85         OSCL_IMPORT_REF void Pause();
86         OSCL_IMPORT_REF void Stop();
87 
88         OSCL_IMPORT_REF PVMFStatus Configure(PVMFFormatType aPortProperty);
89 
90         // these override the PvmfPortBaseImpl routines
91         OSCL_IMPORT_REF PVMFStatus Connect(PVMFPortInterface* aPort);
92         OSCL_IMPORT_REF PVMFStatus Disconnect();
93         OSCL_IMPORT_REF PVMFStatus PeerConnect(PVMFPortInterface* aPort);
94         OSCL_IMPORT_REF PVMFStatus PeerDisconnect();
QueryInterface(const PVUuid & aUuid,OsclAny * & aPtr)95         void QueryInterface(const PVUuid &aUuid, OsclAny*&aPtr)
96         {
97             if (aUuid == PVMI_CAPABILITY_AND_CONFIG_PVUUID)
98             {
99                 aPtr = (PvmiCapabilityAndConfig*)this;
100             }
101             else
102             {
103                 aPtr = NULL;
104             }
105         }
106 
107         //from PVMFPortActivityHandler
108         void HandlePortActivity(const PVMFPortActivity& aActivity);
109 
110         // Pure virtuals from PvmiMediaTransfer
111         void setPeer(PvmiMediaTransfer *aPeer);
112         void useMemoryAllocators(OsclMemAllocator* write_alloc = NULL);
113         PVMFCommandId writeAsync(uint8 format_type, int32 format_index, uint8* data, uint32 data_len,
114                                  const PvmiMediaXferHeader& data_header_info, OsclAny* aContext = NULL);
115         void writeComplete(PVMFStatus aStatus, PVMFCommandId  write_cmd_id, OsclAny* aContext);
116         PVMFCommandId readAsync(uint8* data, uint32 max_data_len, OsclAny* aContext = NULL,
117                                 int32* formats = NULL, uint16 num_formats = 0);
118 //  void readComplete(PVMFStatus aStatus, PVMFCommandId  read_cmd_id, int32 format_index,
119         //uint32 seq_num, uint32 flags, const PVMFTimestamp& timestamp, OsclAny* aContext);
120         void readComplete(PVMFStatus aStatus, PVMFCommandId  read_cmd_id, int32 format_index,
121                           const PvmiMediaXferHeader& data_header_info, OsclAny* aContext);
122 
123         void statusUpdate(uint32 status_flags);
124         void cancelCommand(PVMFCommandId  command_id);
125         void cancelAllCommands();
126 
127         // Implement pure virtuals from PvmiCapabilityAndConfig interface
128         OSCL_IMPORT_REF void setObserver(PvmiConfigAndCapabilityCmdObserver* aObserver);
129         OSCL_IMPORT_REF PVMFStatus getParametersSync(PvmiMIOSession aSession, PvmiKeyType aIdentifier,
130                 PvmiKvp*& aParameters, int& num_parameter_elements,
131                 PvmiCapabilityContext aContext);
132         OSCL_IMPORT_REF PVMFStatus releaseParameters(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
133         OSCL_IMPORT_REF void createContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext);
134         OSCL_IMPORT_REF void setContextParameters(PvmiMIOSession aSession, PvmiCapabilityContext& aContext,
135                 PvmiKvp* aParameters, int num_parameter_elements);
136         OSCL_IMPORT_REF void DeleteContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext);
137         OSCL_IMPORT_REF void setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters,
138                                                int num_elements, PvmiKvp * & aRet_kvp);
139         OSCL_IMPORT_REF PVMFCommandId setParametersAsync(PvmiMIOSession aSession, PvmiKvp* aParameters,
140                 int num_elements, PvmiKvp*& aRet_kvp, OsclAny* context = NULL);
141         OSCL_IMPORT_REF uint32 getCapabilityMetric(PvmiMIOSession aSession);
142         OSCL_IMPORT_REF PVMFStatus verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
143 
isActiveCommsRead()144         OSCL_IMPORT_REF bool isActiveCommsRead()
145         {
146             return iActiveCommsRead;
147         }
isActiveCommsWrite()148         OSCL_IMPORT_REF bool isActiveCommsWrite()
149         {
150             return iActiveCommsWrite;
151         }
152 
153         OSCL_EXPORT_REF bool isIncomingFull();
154 
155     private:
156         int32 WriteAsync(int32& cmdId,
157                          OsclRefCounterMemFrag frag,
158                          PvmiMediaXferHeader data_hdr);
159 
160         void Run();
161 
162         void QueueData(PVMFSharedMediaDataPtr aData, bool requeue = false, uint32 fragindex = 0);
163         PVMFStatus DequeueData(PVMFSharedMediaDataPtr &aData, bool &aResend, uint32 &aFragment);
164 
165         void SetDataTransferModels();
166 
167         // Container node
168         PVCommsIONode* iNode;
169 
170         // Rx/Tx bitstream loggers;
171         PVLogger *iRxLogger;
172         PVLogger *iTxLogger;
173 
174         class AsyncIOCmd
175         {
176             public:
iID(id)177                 AsyncIOCmd(PVMFCommandId id, OsclAny* context = NULL): iID(id), iContext(context) {}
178                 PVMFCommandId iID;
179                 OsclAny *iContext;
180         };
181         Oscl_Vector<AsyncIOCmd, OsclMemAllocator> iReadAsyncCmds;
182 
183         //Format
184         PVMFFormatType iFormatType;
185 
186         PvmiMediaTransfer* iMediaOutputTransfer;
187         PvmiMediaTransfer* iMediaInputTransfer;
188         uint32 iRemoteStatus;
189 
190         uint32 cmdId;
191 
192         //media data re-send queue
193         bool iResend;
194         uint32 iResendSeqNum;
195         uint32 iResendFragment;
196         uint32 iWriteAsyncContext;
197 
198         PvmiMIOCommDataBufferAlloc iMediaDataAlloc;
199         OsclMemPoolFixedChunkAllocator iMediaDataMemPool;
200 
201         enum PortState
202         {
203             PORT_STATE_BUFFERING = 0,
204             PORT_STATE_STARTED,
205         };
206         PortState iState;
207         PVMFFormatType iFormat;
208 
209         enum WriteState {EWriteBusy, EWriteWait, EWriteOK};
210         WriteState iWriteState;
211 
212         //media data cleanup queue
213         class CleanupQueueElement
214         {
215             public:
CleanupQueueElement(PVMFSharedMediaDataPtr d,PVMFCommandId id)216                 CleanupQueueElement(PVMFSharedMediaDataPtr d, PVMFCommandId id): iData(d), iCmdId(id) {}
217                 PVMFSharedMediaDataPtr iData;
218                 PVMFCommandId iCmdId;
219         };
220         Oscl_Vector<CleanupQueueElement, OsclMemAllocator> iCleanupQueue;
221 
222         // Receive and Send models for the MediaDataTransfer
223         // interface.  Threading model will likely dictate
224         // how these are set.
225         bool iActiveCommsWrite;
226         bool iActiveCommsRead;
227 
228         uint32 iQueueLimit;
229 
230         bool iEndOfInputPortDataReached;
231         bool iEndOfOutputPortDataReached;
232 
233         //for flow control
234         bool iWriteFailed;
235         PvmiMediaTransfer* iPeer;
236 
237         void ClearCleanupQueue();
238         void CleanupMediaTransfer();
239 
240         bool CanSendCommsData();
241         void SendCommsData();
242 
243         bool EndOfData(int32 aTag);
244 
245         //for datapath logging
246         void LogMediaDataInfo(const char*msg, PVMFSharedMediaDataPtr mediaData, int32 p1, int32 p2);
247         void LogMediaDataInfo(const char*msg, PVMFSharedMediaDataPtr mediaData);
248         void LogDatapath(const char*msg);
249 
250 #ifdef USE_COPY_BUFFER
251         uint8 iCopyBuffer[NUM_COPY_BUFFERS][COPY_BUFFER_SIZE];
252         uint32 iCopyBufferSize[NUM_COPY_BUFFERS];
253         uint32 iCopyBufferIndex;
254         bool iCopyBufferSent;
255 
256         void CopyBuffer();
257         void SendCopyBuffer();
258 #endif
259 };
260 
261 #endif // PV_COMMS_IO_NODE_PORT_H_INCLUDED
262