Home | History | Annotate | Download | only in rtsp
      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_SOURCE_H_
     18 
     19 #define A_RTP_SOURCE_H_
     20 
     21 #include <stdint.h>
     22 
     23 #include <media/stagefright/foundation/ABase.h>
     24 #include <utils/List.h>
     25 #include <utils/RefBase.h>
     26 
     27 namespace android {
     28 
     29 struct ABuffer;
     30 struct AMessage;
     31 struct ARTPAssembler;
     32 struct ASessionDescription;
     33 
     34 struct ARTPSource : public RefBase {
     35     ARTPSource(
     36             uint32_t id,
     37             const sp<ASessionDescription> &sessionDesc, size_t index,
     38             const sp<AMessage> &notify);
     39 
     40     void processRTPPacket(const sp<ABuffer> &buffer);
     41     void timeUpdate(uint32_t rtpTime, uint64_t ntpTime);
     42     void byeReceived();
     43 
     44     List<sp<ABuffer> > *queue() { return &mQueue; }
     45 
     46     void addReceiverReport(const sp<ABuffer> &buffer);
     47     void addFIR(const sp<ABuffer> &buffer);
     48 
     49     bool timeEstablished() const {
     50         return mNumTimes == 2;
     51     }
     52 
     53 private:
     54     uint32_t mID;
     55     uint32_t mHighestSeqNumber;
     56     int32_t mNumBuffersReceived;
     57 
     58     List<sp<ABuffer> > mQueue;
     59     sp<ARTPAssembler> mAssembler;
     60 
     61     size_t mNumTimes;
     62     uint64_t mNTPTime[2];
     63     uint32_t mRTPTime[2];
     64 
     65     uint64_t mLastNTPTime;
     66     int64_t mLastNTPTimeUpdateUs;
     67 
     68     bool mIssueFIRRequests;
     69     int64_t mLastFIRRequestUs;
     70     uint8_t mNextFIRSeqNo;
     71 
     72     uint64_t RTP2NTP(uint32_t rtpTime) const;
     73 
     74     bool queuePacket(const sp<ABuffer> &buffer);
     75 
     76     DISALLOW_EVIL_CONSTRUCTORS(ARTPSource);
     77 };
     78 
     79 }  // namespace android
     80 
     81 #endif  // A_RTP_SOURCE_H_
     82