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 pvmf_rtcp_timer.cpp
20 * @brief RTCP timer to Jitter Buffer Node
21 */
22 #ifndef PVMF_RTCP_TIMER_H_INCLUDED
23 #include "pvmf_rtcp_timer.h"
24 #endif
25
26 #ifndef PVMF_JITTER_BUFFER_COMMON_INTERNAL_H
27 #include "pvmf_jitter_buffer_common_internal.h"
28 #endif
29
30 #define RTCP_HOLD_DATA_SIZE 2
31
32 ////////////////////////////////////////////////////////////////////////////
PvmfRtcpTimer(PvmfRtcpTimerObserver * aObserver)33 PvmfRtcpTimer::PvmfRtcpTimer(PvmfRtcpTimerObserver* aObserver)
34 : OsclTimerObject(OsclActiveObject::EPriorityNominal, "PvmfRtcpTimer"),
35 iRTCPTimeIntervalInMicroSecs(DEFAULT_RTCP_INTERVAL_USEC),
36 iObserver(aObserver),
37 iStarted(false)
38 {
39 iBufAlloc = NULL;
40 ipLogger = PVLogger::GetLoggerObject("PvmfRtcpTimer");
41 AddToScheduler();
42 iRTCPBufAlloc.ipRTCPRRMsgBufAlloc = createRTCPRRBufAllocReSize();
43 }
44
45 ////////////////////////////////////////////////////////////////////////////
~PvmfRtcpTimer()46 PvmfRtcpTimer::~PvmfRtcpTimer()
47 {
48 Stop();
49 if (iBufAlloc != NULL)
50 {
51 iBufAlloc->removeRef();
52 iBufAlloc = NULL;
53 }
54 if (iImplAlloc != NULL)
55 {
56 OSCL_DELETE(iImplAlloc);
57 }
58 }
59
60 ////////////////////////////////////////////////////////////////////////////
Start()61 PVMFStatus PvmfRtcpTimer::Start()
62 {
63 PVMF_JB_LOGINFO((0, "PvmfRtcpTimer::Start iRTCPTimeIntervalInMicroSecs Interval %d", iRTCPTimeIntervalInMicroSecs));
64 if (iRTCPTimeIntervalInMicroSecs > 0)
65 {
66 RunIfNotReady(iRTCPTimeIntervalInMicroSecs);
67 iStarted = true;
68 return PVMFSuccess;
69 }
70 else
71 {
72 return PVMFFailure;
73 }
74 }
75
76 ////////////////////////////////////////////////////////////////////////////
setRTCPInterval(uint32 rtcpTimeIntervalInMicroSecs)77 PVMFStatus PvmfRtcpTimer::setRTCPInterval(uint32 rtcpTimeIntervalInMicroSecs)
78 {
79 PVMF_JB_LOGINFO((0, "PvmfRtcpTimer::ResetRTCPInterval"));
80 iRTCPTimeIntervalInMicroSecs = rtcpTimeIntervalInMicroSecs;
81 return PVMFSuccess;
82 }
83
84 ////////////////////////////////////////////////////////////////////////////
Stop()85 PVMFStatus PvmfRtcpTimer::Stop()
86 {
87 PVMF_JB_LOGINFO((0, "PvmfRtcpTimer::Stop"));
88 Cancel();
89 iStarted = false;
90 return PVMFSuccess;
91 }
92
93 ////////////////////////////////////////////////////////////////////////////
Run()94 void PvmfRtcpTimer::Run()
95 {
96 PVMF_JB_LOGINFO((0, "PvmfRtcpTimer::Run"));
97
98 if (!iStarted)
99 return;
100
101 if (!iObserver)
102 {
103 PVMF_JB_LOGERROR((0, "PvmfRtcpTimer::Run: Error - Observer not set"));
104 return;
105 }
106
107 iObserver->RtcpTimerEvent();
108 /*
109 * Do not reschudule the AO here. Observer would reschedule this AO
110 * once it is done processing the timer event.
111 */
112 }
113
114 PVMFResizableSimpleMediaMsgAlloc*
createRTCPRRBufAllocReSize()115 PvmfRtcpTimer::createRTCPRRBufAllocReSize()
116 {
117 int32 leavecode = 0;
118
119 OSCL_TRY(leavecode,
120 iBufAlloc = OSCL_NEW(OsclMemPoolResizableAllocator, (DEFAULT_RTCP_SOCKET_MEM_POOL_SIZE_IN_BYTES, 1));
121 iImplAlloc = OSCL_NEW(PVMFResizableSimpleMediaMsgAlloc, (iBufAlloc));
122 );
123
124 if (leavecode || (!iBufAlloc) || (!iImplAlloc))
125 {
126 PVMF_JB_LOGERROR((0, "PvmfRtcpTimer::createRTCPRRBufAllocReSize: Error - Memory allocation failed"));
127 OSCL_LEAVE(OsclErrNoMemory);
128 }
129
130 iBufAlloc->enablenullpointerreturn();
131
132 return iImplAlloc;
133 }
134