1 /*
2  * Copyright (C) 2010 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 #ifndef A_AVC_ASSEMBLER_H_
18 
19 #define A_AVC_ASSEMBLER_H_
20 
21 #include "ARTPAssembler.h"
22 
23 #include <utils/List.h>
24 #include <utils/RefBase.h>
25 #include <utils/String8.h>
26 
27 namespace android {
28 
29 struct ABuffer;
30 struct AMessage;
31 
32 struct AAVCAssembler : public ARTPAssembler {
33     explicit AAVCAssembler(const sp<AMessage> &notify);
34 
35     typedef List<sp<ABuffer> > Queue;
36 protected:
37     virtual ~AAVCAssembler();
38 
39     virtual AssemblyStatus assembleMore(const sp<ARTPSource> &source);
40     virtual void onByeReceived();
41     virtual void packetLost();
42 
43 private:
44     sp<AMessage> mNotifyMsg;
45 
46     uint32_t mAccessUnitRTPTime;
47     bool mNextExpectedSeqNoValid;
48     uint32_t mNextExpectedSeqNo;
49     bool mAccessUnitDamaged;
50     bool mFirstIFrameProvided;
51     int32_t mLastCvo;
52     uint64_t mLastIFrameProvidedAtMs;
53     int64_t mLastRtpTimeJitterDataUs;
54     int32_t mWidth;
55     int32_t mHeight;
56     List<sp<ABuffer> > mNALUnits;
57 
58     int32_t addNack(const sp<ARTPSource> &source);
59     void checkSpsUpdated(const sp<ABuffer> &buffer);
60     void checkIFrameProvided(const sp<ABuffer> &buffer);
61     bool dropFramesUntilIframe(const sp<ABuffer> &buffer);
62     AssemblyStatus addNALUnit(const sp<ARTPSource> &source);
63     void addSingleNALUnit(const sp<ABuffer> &buffer);
64     AssemblyStatus addFragmentedNALUnit(List<sp<ABuffer> > *queue);
65     bool addSingleTimeAggregationPacket(const sp<ABuffer> &buffer);
66 
67     void submitAccessUnit();
68 
69     int32_t pickStartSeq(const Queue *q, uint32_t first, int64_t play, int64_t jit);
70     int32_t deleteUnitUnderSeq(Queue *q, uint32_t seq);
71 
72     DISALLOW_EVIL_CONSTRUCTORS(AAVCAssembler);
73 };
74 
75 }  // namespace android
76 
77 #endif  // A_AVC_ASSEMBLER_H_
78