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 #ifndef PVMF_AMRFFPARSER_OUTPORT_H_INCLUDED
     19 #define PVMF_AMRFFPARSER_OUTPORT_H_INCLUDED
     20 
     21 #ifndef OSCL_BASE_H_INCLUDED
     22 #include "oscl_base.h"
     23 #endif
     24 #ifndef PVLOGGER_H_INCLUDED
     25 #include "pvlogger.h"
     26 #endif
     27 
     28 #ifndef PVLOGGER_FILE_APPENDER_H_INCLUDED
     29 #include "pvlogger_file_appender.h"
     30 #endif
     31 
     32 #ifndef PVMF_PORT_BASE_IMPL_H_INCLUDED
     33 #include "pvmf_port_base_impl.h"
     34 #endif
     35 #ifndef PVMI_CONFIG_AND_CAPABILITY_UTILS_H_INCLUDED
     36 #include "pvmi_config_and_capability_utils.h"
     37 #endif
     38 
     39 
     40 #ifndef OSCL_SCHEDULER_AO_H_INCLUDED
     41 #include "oscl_scheduler_ao.h"
     42 #endif
     43 
     44 #ifndef OSCL_FILE_IO_H_INCLUDED
     45 #include "oscl_file_io.h"
     46 #endif
     47 
     48 #ifndef OSCL_STRING_H_INCLUDED
     49 #include "oscl_string.h"
     50 #endif
     51 
     52 #ifndef OSCL_BIN_STREAM_H_INCLUDED
     53 #include "oscl_bin_stream.h"
     54 #endif
     55 
     56 #ifndef PVMF_MEDIA_CLOCK_H_INCLUDED
     57 #include "pvmf_media_clock.h"
     58 #endif
     59 
     60 #ifndef OSCL_TIMER_H_INCLUDED
     61 #include "oscl_timer.h"
     62 #endif
     63 
     64 #ifndef PVMF_MEMPOOL_H_INCLUDED
     65 #include "pvmf_mempool.h"
     66 #endif
     67 
     68 #ifndef PVMF_FORMAT_TYPE_H_INCLUDED
     69 #include "pvmf_format_type.h"
     70 #endif
     71 
     72 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED
     73 #include "pvmf_node_interface.h"
     74 #endif
     75 
     76 #ifndef PVMF_NODE_UTILS_H_INCLUDED
     77 #include "pvmf_node_utils.h"
     78 #endif
     79 
     80 #ifndef OSCL_PRIQUEUE_H_INCLUDED
     81 #include "oscl_priqueue.h"
     82 #endif
     83 
     84 #ifndef PVMF_MEDIA_DATA_H_INCLUDED
     85 #include "pvmf_media_data.h"
     86 #endif
     87 
     88 #ifndef OSCL_MEM_MEMPOOL_H_INCLUDED
     89 #include "oscl_mem_mempool.h"
     90 #endif
     91 
     92 #ifndef PVMF_SIMPLE_MEDIA_BUFFER_H_INCLUDED
     93 #include "pvmf_simple_media_buffer.h"
     94 #endif
     95 
     96 #ifndef PVMF_MEDIA_FRAG_GROUP_H_INCLUDED
     97 #include "pvmf_media_frag_group.h"
     98 #endif
     99 
    100 #ifndef PVMF_RESIZABLE_SIMPLE_MEDIAMSG_H_INCLUDED
    101 #include "pvmf_resizable_simple_mediamsg.h"
    102 #endif
    103 
    104 typedef OsclMemAllocator PVMFAMRParserNodeAllocator;
    105 
    106 #define PVMF_AMRPARSERNODE_LOGERROR(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iLogger,PVLOGMSG_ERR,m);
    107 #define PVMF_AMRPARSERNODE_LOGWARNING(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iLogger,PVLOGMSG_WARNING,m);
    108 #define PVMF_AMRPARSERNODE_LOGINFOHI(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG,iLogger,PVLOGMSG_INFO,m);
    109 #define PVMF_AMRPARSERNODE_LOGINFOMED(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG,iLogger,PVLOGMSG_INFO,m);
    110 #define PVMF_AMRPARSERNODE_LOGINFOLOW(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG,iLogger,PVLOGMSG_INFO,m);
    111 #define PVMF_AMRPARSERNODE_LOGINFO(m) PVMF_AMRPARSERNODE_LOGINFOMED(m)
    112 #define PVMF_AMRPARSERNODE_LOGSTACKTRACE(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG,iLogger,PVLOGMSG_STACK_TRACE,m);
    113 #define PVMF_AMRPARSERNODE_LOGDATATRAFFIC(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iDataPathLogger,PVLOGMSG_INFO,m);
    114 #define PVMF_AMRPARSERNODE_LOGCLOCK(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iClockLogger,PVLOGMSG_INFO,m);
    115 #define PVMF_AMRPARSERNODE_LOGBIN(iPortLogger, m) PVLOGGER_LOGBIN(PVLOGMSG_INST_LLDBG, iPortLogger, PVLOGMSG_ERR, m);
    116 
    117 
    118 class PVMFAMRParserNodeLoggerDestructDealloc : public OsclDestructDealloc
    119 {
    120     public:
    121         void destruct_and_dealloc(OsclAny* ptr)
    122         {
    123             PVLoggerAppender* p = OSCL_REINTERPRET_CAST(PVLoggerAppender*, ptr);
    124             BinaryFileAppender* binPtr = OSCL_REINTERPRET_CAST(BinaryFileAppender*, p);
    125             if (!binPtr)
    126                 return;
    127             OSCL_DELETE(binPtr);
    128         }
    129 };
    130 
    131 /**
    132 * Track/Port information
    133 */
    134 class MediaClockConverter;
    135 class PVMFAMRFFParserNode;
    136 
    137 class PVAMRFFNodeTrackPortInfo : public OsclMemPoolFixedChunkAllocatorObserver,
    138         public OsclMemPoolResizableAllocatorObserver
    139 {
    140     public:
    141 
    142         PVAMRFFNodeTrackPortInfo()
    143         {
    144             iTrackId = -1;
    145             iPort = NULL;
    146             iClockConverter = NULL;
    147             iTrackDataMemoryPool = NULL;
    148             iMediaDataImplAlloc = NULL;
    149             iMediaDataMemPool = NULL;
    150             iNode = NULL;
    151             iSeqNum = 0;
    152             iTimestampOffset = 0;
    153             iFormatType                   = PVMF_MIME_FORMAT_UNKNOWN;
    154 
    155             iResizableDataMemoryPool      = NULL;
    156             iResizableSimpleMediaMsgAlloc = NULL;
    157 
    158             iTimestamp                    = 0;
    159             iFirstFrame                   = false;
    160 
    161             oEOSReached                   = false;
    162             oEOSSent                      = false;
    163             oTrackSelected                = false;
    164             oQueueOutgoingMessages        = true;
    165             oProcessOutgoingMessages      = true;
    166             iTrackBitRate                 = 0;
    167             iTrackDuration                = 0;
    168             iContinuousTimeStamp          = 0;
    169 
    170 
    171             iResizableDataMemoryPoolSize  = 0;
    172             iTrackMaxSampleSize           = 0;
    173 
    174             iAudioSampleRate              = 0;
    175             iAudioNumChannels             = 0;
    176 
    177             iAudioBitsPerSample           = 0;
    178             iCodecName                    = NULL;
    179             iCodecDescription             = NULL;
    180 
    181             iSendBOS = false;
    182 
    183             iLogger = PVLogger::GetLoggerObject("PVMFASFParserNode");
    184             iDataPathLogger = PVLogger::GetLoggerObject("datapath.asfparsernode");
    185             if (iDataPathLogger)
    186                 iDataPathLogger->DisableAppenderInheritance();
    187             iClockLogger = PVLogger::GetLoggerObject("clock");
    188             iPortLogger = NULL;
    189             oFormatSpecificInfoLogged = false;
    190         }
    191 
    192         PVAMRFFNodeTrackPortInfo(const PVAMRFFNodeTrackPortInfo& aSrc) :
    193                 OsclMemPoolFixedChunkAllocatorObserver(aSrc),
    194                 OsclMemPoolResizableAllocatorObserver(aSrc)
    195         {
    196             iTrackId = aSrc.iTrackId;
    197             iPort = aSrc.iPort;
    198             iTag = aSrc.iTag;
    199             iClockConverter = aSrc.iClockConverter;
    200             iMediaData = aSrc.iMediaData;
    201             iTrackDataMemoryPool = aSrc.iTrackDataMemoryPool;
    202             iMediaDataImplAlloc = aSrc.iMediaDataImplAlloc;
    203             iMediaDataMemPool = aSrc.iMediaDataMemPool;
    204             iNode = aSrc.iNode;
    205             iSeqNum = aSrc.iSeqNum;
    206             iTimestampOffset = aSrc.iTimestampOffset;
    207             iFirstFrame = aSrc.iFirstFrame;
    208 
    209             iFormatType                        = aSrc.iFormatType;
    210             iTrackMimeType                     = aSrc.iTrackMimeType;
    211             iClockConverter                    = aSrc.iClockConverter;
    212             iFormatSpecificConfig              = aSrc.iFormatSpecificConfig;
    213             iResizableDataMemoryPool           = aSrc.iResizableDataMemoryPool;
    214             iResizableSimpleMediaMsgAlloc      = aSrc.iResizableSimpleMediaMsgAlloc;
    215             iMediaDataMemPool                  = aSrc.iMediaDataMemPool;
    216             iTimestamp                         = aSrc.iTimestamp;
    217             oEOSReached                        = aSrc.oEOSReached;
    218             oEOSSent                           = aSrc.oEOSSent;
    219             oTrackSelected                     = aSrc.oTrackSelected;
    220             oQueueOutgoingMessages             = aSrc.oQueueOutgoingMessages;
    221             oProcessOutgoingMessages           = aSrc.oProcessOutgoingMessages;
    222             iTrackBitRate                      = aSrc.iTrackBitRate;
    223             iTrackDuration                     = aSrc.iTrackDuration;
    224             iContinuousTimeStamp               = aSrc.iContinuousTimeStamp;
    225 
    226 
    227             iResizableDataMemoryPoolSize       = aSrc.iResizableDataMemoryPoolSize;
    228             iTrackMaxSampleSize                = aSrc.iTrackMaxSampleSize;
    229             iLogger                            = aSrc.iLogger;
    230             iDataPathLogger                    = aSrc.iDataPathLogger;
    231             iClockLogger                       = aSrc.iClockLogger;
    232             iPortLogger                        = aSrc.iPortLogger;
    233             oFormatSpecificInfoLogged          = aSrc.oFormatSpecificInfoLogged;
    234             iAudioSampleRate                   = aSrc.iAudioSampleRate;
    235             iAudioNumChannels                  = aSrc.iAudioNumChannels;
    236             iAudioBitsPerSample                = aSrc.iAudioBitsPerSample;
    237             iCodecName                         = aSrc.iCodecName;;
    238             iCodecDescription                  = aSrc.iCodecDescription;
    239 
    240             iSendBOS = aSrc.iSendBOS;
    241 
    242         }
    243 
    244         virtual ~PVAMRFFNodeTrackPortInfo()
    245         {
    246         }
    247 
    248         // From OsclMemPoolFixedChunkAllocatorObserver
    249         // Callback handler when mempool's deallocate() is called after
    250         // calling notifyfreechunkavailable() on the mempool
    251         void freechunkavailable(OsclAny* aContextData)
    252         {
    253             OSCL_UNUSED_ARG(aContextData);
    254             PVMF_AMRPARSERNODE_LOGINFO((0, "MimeType = %s, freeblockavailable", iTrackMimeType.get_cstr()));
    255             oQueueOutgoingMessages = true;
    256             if (iNode)
    257             {
    258                 /* Activate the parent node if necessary */
    259                 iNode->RunIfNotReady();
    260             }
    261         }
    262 
    263         /*
    264          * From OsclMemPoolResizableAllocatorObserver
    265          * Callback handler when mempool's deallocate() is called after
    266          * calling notifyfreeblockavailable() on the mempool
    267          */
    268         void freeblockavailable(OsclAny* aContextData)
    269         {
    270             OSCL_UNUSED_ARG(aContextData);
    271             PVMF_AMRPARSERNODE_LOGINFO((0, "MimeType = %s, freeblockavailable", iTrackMimeType.get_cstr()));
    272             oQueueOutgoingMessages = true;
    273             if (iNode)
    274             {
    275                 /* Activate the parent node if necessary */
    276                 iNode->RunIfNotReady();
    277             }
    278         }
    279 
    280         // Track ID number in AMR FF
    281         int32 iTrackId;
    282         // Output port to send the data downstream
    283         PVMFPortInterface* iPort;
    284         int32 iTag;
    285 
    286         /* Track Duration */
    287         uint64 iTrackDuration;
    288 
    289         /* PVMF mime type for track */
    290         OSCL_HeapString<PVMFAMRParserNodeAllocator> iTrackMimeType;
    291 
    292         /* Format type for the port */
    293         PVMFFormatType iFormatType;
    294 
    295         // Converter to convert from track timescale to milliseconds
    296         MediaClockConverter* iClockConverter;
    297 
    298         /* Shared memory pointer holding the decoder specific config info for this track */
    299         OsclRefCounterMemFrag iFormatSpecificConfig;
    300 
    301         /////////////////////////////////////////////////////////////////////
    302         // Shared memory pointer holding the currently retrieved track data
    303         PVMFSharedMediaDataPtr iMediaData;
    304 
    305         /* Resizable mem allocator */
    306         OsclMemPoolResizableAllocator *iResizableDataMemoryPool;
    307 
    308         /* Allocator for simple media buffer impl */
    309         PVMFResizableSimpleMediaMsgAlloc* iResizableSimpleMediaMsgAlloc;
    310 
    311         /* Timestamp */
    312         uint32 iTimestamp;
    313 
    314         /* Track Bitrate */
    315         uint32 iTrackBitRate;
    316 
    317         /* port flow control */
    318         bool oQueueOutgoingMessages;
    319         bool oProcessOutgoingMessages;
    320 
    321         /* End of Track */
    322         bool oEOSReached;
    323         bool oEOSSent;
    324 
    325         /* Track Selection */
    326         bool oTrackSelected;
    327 
    328         /* Continuous timestamp */
    329         uint64 iContinuousTimeStamp;
    330 
    331         /* Mem pool size */
    332         uint32 iResizableDataMemoryPoolSize;
    333 
    334         /* Track Max Sample Size */
    335         uint32 iTrackMaxSampleSize;
    336 
    337         /* Audio - Video specfic info */
    338         uint32 iAudioSampleRate;
    339         uint32 iAudioNumChannels;
    340         uint32 iAudioBitsPerSample;
    341         OSCL_wHeapString<OsclMemAllocator> iCodecName;
    342         OSCL_wHeapString<OsclMemAllocator> iCodecDescription;
    343 
    344         // Output buffer memory pool
    345         OsclMemPoolFixedChunkAllocator *iTrackDataMemoryPool;
    346         // Allocator for simple media data buffer impl
    347         PVMFSimpleMediaBufferCombinedAlloc *iMediaDataImplAlloc;
    348         // Memory pool for simple media data
    349         PVMFMemPoolFixedChunkAllocator *iMediaDataMemPool;
    350         // AMR FF parser node handle
    351         OsclTimerObject* iNode;
    352         // Sequence number
    353         uint32 iSeqNum;
    354         // Timestamp offset
    355         uint32 iTimestampOffset;
    356         // Set if first frame after repositioning
    357         bool iFirstFrame;
    358 
    359         // bos flag
    360         bool iSendBOS;
    361         /* Loggers */
    362         PVLogger* iLogger;
    363         PVLogger* iDataPathLogger;
    364         PVLogger* iClockLogger;
    365         /* bitstream logging */
    366         PVLogger* iPortLogger;
    367         OSCL_HeapString<PVMFAMRParserNodeAllocator> iLogFile;
    368         bool oFormatSpecificInfoLogged;
    369 
    370         OsclSharedPtr<PVLoggerAppender> iBinAppenderPtr;
    371 };
    372 
    373 class PVMFAMRFFParserOutPort : public PvmfPortBaseImpl
    374         , public PvmiCapabilityAndConfig
    375 {
    376     public:
    377         /**
    378          * Default constructor. Default settings will be used for the data queues.
    379          * @param aId ID assigned to this port
    380          * @param aTag Port tag
    381          * @param aNode Container node
    382          */
    383         PVMFAMRFFParserOutPort(int32 aTag
    384                                , PVMFNodeInterface* aNode);
    385 
    386         /**
    387          * Constructor that allows the node to configure the data queues of this port.
    388          * @param aTag Port tag
    389          * @param aNode Container node
    390          * @param aSize Data queue capacity. The data queue size will not grow beyond this capacity.
    391          * @param aReserve Size of data queue for which memory is reserved. This must be
    392          * less than or equal to the capacity. If this is less than capacity, memory will be
    393          * allocated when the queue grows beyond the reserve size, but will stop growing at
    394          * capacity.
    395          * @param aThreshold Ready-to-receive threshold, in terms of percentage of the data queue capacity.
    396          * This value should be between 0 - 100.
    397          */
    398         PVMFAMRFFParserOutPort(int32 aTag
    399                                , PVMFNodeInterface* aNode
    400                                , uint32 aInCapacity
    401                                , uint32 aInReserve
    402                                , uint32 aInThreshold
    403                                , uint32 aOutCapacity
    404                                , uint32 aOutReserve
    405                                , uint32 aOutThreshold);
    406 
    407         /** Destructor */
    408         ~PVMFAMRFFParserOutPort();
    409 
    410         // Implement pure virtuals from PvmiCapabilityAndConfigPortFormatImpl interface
    411         bool IsFormatSupported(PVMFFormatType);
    412         void FormatUpdated();
    413 
    414         // this port supports config interface
    415         void QueryInterface(const PVUuid &aUuid, OsclAny*&aPtr)
    416         {
    417             if (aUuid == PVMI_CAPABILITY_AND_CONFIG_PVUUID)
    418                 aPtr = (PvmiCapabilityAndConfig*)this;
    419             else
    420                 aPtr = NULL;
    421         }
    422 
    423 
    424 
    425         /* Over ride Connect() */
    426         PVMFStatus Connect(PVMFPortInterface* aPort);
    427 
    428         /* Implement pure virtuals from PvmiCapabilityAndConfig interface */
    429         PVMFStatus getParametersSync(PvmiMIOSession aSession, PvmiKeyType aIdentifier,
    430                                      PvmiKvp*& aParameters, int& num_parameter_elements,    PvmiCapabilityContext aContext);
    431         PVMFStatus releaseParameters(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
    432         void setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters,
    433                                int num_elements, PvmiKvp * & aRet_kvp);
    434         PVMFStatus verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
    435 
    436         /* Unsupported PvmiCapabilityAndConfig methods */
    437         void setObserver(PvmiConfigAndCapabilityCmdObserver* aObserver)
    438         {
    439             OSCL_UNUSED_ARG(aObserver);
    440         };
    441         void createContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext)
    442         {
    443             OSCL_UNUSED_ARG(aSession);
    444             OSCL_UNUSED_ARG(aContext);
    445         };
    446         void setContextParameters(PvmiMIOSession aSession, PvmiCapabilityContext& aContext,
    447                                   PvmiKvp* aParameters, int num_parameter_elements)
    448         {
    449             OSCL_UNUSED_ARG(aSession);
    450             OSCL_UNUSED_ARG(aContext);
    451             OSCL_UNUSED_ARG(aParameters);
    452             OSCL_UNUSED_ARG(num_parameter_elements);
    453         };
    454         void DeleteContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext)
    455         {
    456             OSCL_UNUSED_ARG(aSession);
    457             OSCL_UNUSED_ARG(aContext);
    458         };
    459         PVMFCommandId setParametersAsync(PvmiMIOSession aSession, PvmiKvp* aParameters,
    460                                          int num_elements, PvmiKvp*& aRet_kvp, OsclAny* context = NULL)
    461         {
    462             OSCL_UNUSED_ARG(aRet_kvp);
    463             OSCL_UNUSED_ARG(aSession);
    464             OSCL_UNUSED_ARG(aParameters);
    465             OSCL_UNUSED_ARG(num_elements);
    466             OSCL_UNUSED_ARG(context);
    467             return -1;
    468         }
    469         uint32 getCapabilityMetric(PvmiMIOSession aSession)
    470         {
    471             OSCL_UNUSED_ARG(aSession);
    472             return 0;
    473         }
    474 
    475     private:
    476         void Construct();
    477 
    478         bool pvmiSetPortFormatSpecificInfoSync(PvmiCapabilityAndConfig *aPort,
    479                                                const char* aFormatValType);
    480 
    481         bool pvmiGetPortFormatSpecificInfoSync(const char* aFormatValType,
    482                                                PvmiKvp*& aKvp);
    483 
    484         PVLogger *iLogger;
    485         uint32 iNumFramesGenerated; //number of source frames generated.
    486         uint32 iNumFramesConsumed; //number of frames consumed & discarded.
    487 
    488         PVMFAMRFFParserNode* iAMRParserNode;
    489 };
    490 
    491 #endif // PVMF_AMRFFPARSER_OUTPORT_H_INCLUDED
    492