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_RTP_ASSEMBLER_H_
18 
19 #define A_RTP_ASSEMBLER_H_
20 
21 #include <media/stagefright/foundation/ABase.h>
22 #include <utils/List.h>
23 #include <utils/RefBase.h>
24 
25 namespace android {
26 
27 struct ABuffer;
28 struct ARTPSource;
29 
30 struct ARTPAssembler : public RefBase {
31     enum AssemblyStatus {
32         MALFORMED_PACKET,
33         WRONG_SEQUENCE_NUMBER,
34         NOT_ENOUGH_DATA,
35         OK
36     };
37 
38     ARTPAssembler();
39 
40     void onPacketReceived(const sp<ARTPSource> &source);
41     virtual void onByeReceived() = 0;
42 
43 protected:
44     virtual AssemblyStatus assembleMore(const sp<ARTPSource> &source) = 0;
45     virtual void packetLost() = 0;
46 
47     static void CopyTimes(const sp<ABuffer> &to, const sp<ABuffer> &from);
48 
49     static sp<ABuffer> MakeADTSCompoundFromAACFrames(
50             unsigned profile,
51             unsigned samplingFreqIndex,
52             unsigned channelConfig,
53             const List<sp<ABuffer> > &frames);
54 
55     static sp<ABuffer> MakeCompoundFromPackets(
56             const List<sp<ABuffer> > &frames);
57 
58 private:
59     int64_t mFirstFailureTimeUs;
60 
61     DISALLOW_EVIL_CONSTRUCTORS(ARTPAssembler);
62 };
63 
64 }  // namespace android
65 
66 #endif  // A_RTP_ASSEMBLER_H_
67