• 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  * @file pvmp4ffcn_port.h
20  * @brief Port for PVMp4FFComposerNode
21  */
22 
23 #ifndef PVMP4FFCN_PORT_H_INCLUDED
24 #define PVMP4FFCN_PORT_H_INCLUDED
25 
26 #ifndef OSCL_BASE_H_INCLUDED
27 #include "oscl_base.h"
28 #endif
29 #ifndef OSCL_SCHEDULER_AO_H_INCLUDED
30 #include "oscl_scheduler_ao.h"
31 #endif
32 #ifndef PVMF_PORT_BASE_IMPL_H_INCLUDED
33 #include "pvmf_port_base_impl.h"
34 #endif
35 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED
36 #include "pvmf_node_interface.h"
37 #endif
38 #ifndef PVMI_CONFIG_AND_CAPABILITY_H_INCLUDED
39 #include "pvmi_config_and_capability.h"
40 #endif
41 #ifndef TEXTSAMPLEDESCINFO_H
42 #include "textsampledescinfo.h"
43 #endif
44 
45 class PVMp4FFComposerNode;
46 class PVLogger;
47 
48 typedef enum
49 {
50     PVMP4FFCN_RATE_CONTROL_UNKNOWN = 0,
51     PVMP4FFCN_RATE_CONTROL_CBR = 1,
52     PVMP4FFCN_RATE_CONTROL_VBR = 2,
53     PVMP4FFCN_RATE_CONTROL_LOW_DELAY = 3
54 } PVMP4FFCNRateControlType;
55 
56 struct PVMP4FFCNFormatSpecificConfig
57 {
58     uint32 iBitrate;
59     uint32 iTimescale;
60 
61     // Video configuration
62     OsclFloat iFrameRate;
63     uint32 iIFrameInterval;
64     uint32 iWidth;
65     uint32 iHeight;
66     PVMP4FFCNRateControlType iRateControlType;
67 
68     // H263 configuration
69     uint8 iH263Profile;
70     uint8 iH263Level;
71 };
72 
73 class PVMp4FFComposerPort : public PvmfPortBaseImpl,
74         public PvmiCapabilityAndConfig,
75         public PVMFPortActivityHandler,
76         public OsclActiveObject
77 {
78     public:
79         PVMp4FFComposerPort(int32 aTag, PVMp4FFComposerNode* aNode, int32 aPriority, const char* aName = NULL);
80         ~PVMp4FFComposerPort();
81 
82         // Overload PvmfPortBaseImpl methods
83         OSCL_IMPORT_REF PVMFStatus Connect(PVMFPortInterface* aPort);
84         OSCL_IMPORT_REF PVMFStatus PeerConnect(PVMFPortInterface* aPort);
85         OSCL_IMPORT_REF void QueryInterface(const PVUuid& aUuid, OsclAny*& aPtr);
86 
87         // Implement pure virtuals from PvmiCapabilityAndConfig interface
88         OSCL_IMPORT_REF void setObserver(PvmiConfigAndCapabilityCmdObserver* aObserver);
89         OSCL_IMPORT_REF PVMFStatus getParametersSync(PvmiMIOSession aSession, PvmiKeyType aIdentifier,
90                 PvmiKvp*& aParameters, int& num_parameter_elements,
91                 PvmiCapabilityContext aContext);
92         OSCL_IMPORT_REF PVMFStatus releaseParameters(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
93         OSCL_IMPORT_REF void createContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext);
94         OSCL_IMPORT_REF void setContextParameters(PvmiMIOSession aSession, PvmiCapabilityContext& aContext,
95                 PvmiKvp* aParameters, int num_parameter_elements);
96         OSCL_IMPORT_REF void DeleteContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext);
97         OSCL_IMPORT_REF void setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters,
98                                                int num_elements, PvmiKvp * & aRet_kvp);
99         OSCL_IMPORT_REF PVMFCommandId setParametersAsync(PvmiMIOSession aSession, PvmiKvp* aParameters,
100                 int num_elements, PvmiKvp*& aRet_kvp, OsclAny* context = NULL);
101         OSCL_IMPORT_REF uint32 getCapabilityMetric(PvmiMIOSession aSession);
102         OSCL_IMPORT_REF PVMFStatus verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
103 
104         // For node to notify the port that it's ready to process incoming message
105         void ProcessIncomingMsgReady();
106 
107         // From PVMFPortActivityHandler
108         void HandlePortActivity(const PVMFPortActivity& aActivity);
109 
110         // Track ID
SetTrackId(int32 aTrackId)111         void SetTrackId(int32 aTrackId)
112         {
113             iTrackId = aTrackId;
114         }
GetTrackId()115         int32 GetTrackId()
116         {
117             return iTrackId;
118         }
119 
120         // Provide port configuration to node
SetFormat(PVMFFormatType aFormat)121         void SetFormat(PVMFFormatType aFormat)
122         {
123             iFormat = aFormat;
124             iMimeType = aFormat.getMIMEStrPtr();
125         }
GetFormat()126         PVMFFormatType GetFormat()
127         {
128             return iFormat;
129         }
GetMimeType()130         OSCL_String& GetMimeType()
131         {
132             return iMimeType;
133         }
SetCodecType(int32 aCodecType)134         void SetCodecType(int32 aCodecType)
135         {
136             iCodecType = aCodecType;
137         }
GetCodecType()138         int32 GetCodecType()
139         {
140             return iCodecType;
141         }
GetFormatSpecificConfig()142         PVMP4FFCNFormatSpecificConfig* GetFormatSpecificConfig()
143         {
144             PvmiCapabilityAndConfig* config = NULL;
145             if (iConnectedPort)
146             {
147                 OsclAny* temp = NULL;
148                 iConnectedPort->QueryInterface(PVMI_CAPABILITY_AND_CONFIG_PVUUID, temp);
149                 config = OSCL_STATIC_CAST(PvmiCapabilityAndConfig*, temp);
150                 if (config)
151                 {
152                     GetInputParametersFromPeer(config);
153                 }
154             }
155             return &iFormatSpecificConfig;
156         }
157 
158 
159         // Reference track settings
SetReferencePort(PVMp4FFComposerPort * aPort)160         void SetReferencePort(PVMp4FFComposerPort* aPort)
161         {
162             iReferencePort = aPort;
163         }
GetReferencePort()164         const PVMp4FFComposerPort* GetReferencePort()
165         {
166             return iReferencePort;
167         }
168 
169         // Real-time TS routines
GetLastTS()170         uint32 GetLastTS()
171         {
172             return iLastTS;
173         }
SetLastTS(uint32 aTS)174         void SetLastTS(uint32 aTS)
175         {
176             iLastTS = aTS;
177         }
178 
179         friend class PVMp4FFComposerNode;
180     private:
181         // Implement pure virtuals from OsclActiveObject
182         void Run();
183 
184         /**
185          * Allocate a specified number of key-value pairs and set the keys
186          *
187          * @param aKvp Output parameter to hold the allocated key-value pairs
188          * @param aKey Key for the allocated key-value pairs
189          * @param aNumParams Number of key-value pairs to be allocated
190          * @return Completion status
191          */
192         PVMFStatus AllocateKvp(PvmiKvp*& aKvp, PvmiKeyType aKey, int32 aNumParams);
193 
194         /**
195          * Verify one key-value pair parameter against capability of the port and
196          * if the aSetParam flag is set, set the value of the parameter corresponding to
197          * the key.
198          *
199          * @param aKvp Key-value pair parameter to be verified
200          * @param aSetParam If true, set the value of parameter corresponding to the key.
201          * @return PVMFSuccess if parameter is supported, else PVMFFailure
202          */
203         PVMFStatus VerifyAndSetParameter(PvmiKvp* aKvp, bool aSetParam = false);
204 
205         /**
206          * Negotiates input port settings (format, video size and frame rate) and
207          * configures the peer port and the container node with these settings
208          *
209          * @param aConfig Capability and config object for peer port
210          * @return PVMFSuccess if settings are successfully negotiated.
211          */
212         PVMFStatus NegotiateInputSettings(PvmiCapabilityAndConfig* aConfig);
213 
214         /**
215          * Query peer port for properties of incoming data.
216          * @return Completion status
217          */
218         PVMFStatus GetInputParametersFromPeer(PvmiCapabilityAndConfig* aConfig);
219 
220         /**
221          * Query peer port for properties of incoming data.
222          * @return Completion status
223          */
224         PVMFStatus GetVideoInputParametersFromPeer(PvmiCapabilityAndConfig* aConfig);
225 
226     private:
227 
228         // Container node
229         PVMp4FFComposerNode* iNode;
230 
231         // Port configuration
232         int32 iTrackId;
233         PVMFFormatType iFormat;
234         int32 iCodecType; //integer value to avoid formatype comparisons
235         PVMP4FFCNFormatSpecificConfig iFormatSpecificConfig;
236         PVMp4FFComposerPort* iReferencePort;
237         OsclMemoryFragment* memfrag_sps;
238         OsclMemoryFragment* memfrag_pps;
239         // Real-time TS
240         uint32 iLastTS;
241 
242         OsclMemAllocator iAlloc;
243         PVLogger* iLogger;
244         bool iEndOfDataReached;
245 
246         //logging
247         OSCL_HeapString<OsclMemAllocator> iMimeType;
248 };
249 
250 #endif // PVMP4FFCN_PORT_H_INCLUDED
251