1 /**
2 * Copyright (C) 2022 The Android Open Source Project
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 express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <BaseJitterBuffer.h>
18 #include <ImsMediaTrace.h>
19
BaseJitterBuffer()20 BaseJitterBuffer::BaseJitterBuffer()
21 {
22 mCallback = nullptr;
23 mFirstFrameReceived = false;
24 mSsrc = 0;
25 mCodecType = 0;
26 mInitJitterBufferSize = 4;
27 mMinJitterBufferSize = 4;
28 mMaxJitterBufferSize = 9;
29 mLastPlayedSeqNum = 0;
30 mLastPlayedTimestamp = 0;
31 mMaxSaveFrameNum = 0;
32 }
33
~BaseJitterBuffer()34 BaseJitterBuffer::~BaseJitterBuffer()
35 {
36 mDataQueue.Clear();
37 }
38
SetSessionCallback(BaseSessionCallback * callback)39 void BaseJitterBuffer::SetSessionCallback(BaseSessionCallback* callback)
40 {
41 mCallback = callback;
42 }
43
SetCodecType(uint32_t type)44 void BaseJitterBuffer::SetCodecType(uint32_t type)
45 {
46 mCodecType = type;
47 }
48
SetJitterBufferSize(uint32_t nInit,uint32_t nMin,uint32_t nMax)49 void BaseJitterBuffer::SetJitterBufferSize(uint32_t nInit, uint32_t nMin, uint32_t nMax)
50 {
51 mInitJitterBufferSize = nInit;
52 mMinJitterBufferSize = nMin;
53 mMaxJitterBufferSize = nMax;
54 }
55
GetCount()56 uint32_t BaseJitterBuffer::GetCount()
57 {
58 return mDataQueue.GetCount();
59 }
60
Reset()61 void BaseJitterBuffer::Reset()
62 {
63 IMLOGD0("[Reset]");
64 std::lock_guard<std::mutex> guard(mMutex);
65 mFirstFrameReceived = false;
66 mLastPlayedSeqNum = 0;
67 mLastPlayedTimestamp = 0;
68 }
69
Delete()70 void BaseJitterBuffer::Delete()
71 {
72 std::lock_guard<std::mutex> guard(mMutex);
73 mDataQueue.Delete();
74 }
75
ClearBuffer()76 void BaseJitterBuffer::ClearBuffer()
77 {
78 IMLOGD0("[ClearBuffer]");
79 std::lock_guard<std::mutex> guard(mMutex);
80 DataEntry* entry = nullptr;
81
82 while (mDataQueue.Get(&entry))
83 {
84 mDataQueue.Delete();
85 }
86 }
87
GetRedundantFrame(uint32_t,uint8_t **,uint32_t *,bool *,uint8_t *)88 bool BaseJitterBuffer::GetRedundantFrame(uint32_t /*lostSeq*/, uint8_t** /*ppData*/,
89 uint32_t* /*pnDataSize*/, bool* /*hasNextFrame*/, uint8_t* /*nextFrameFirstByte*/)
90 {
91 return false;
92 }