Andreas Huber | 8a61c22 | 2012-08-31 14:05:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012, 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 RTP_SINK_H_ |
| 18 | |
| 19 | #define RTP_SINK_H_ |
| 20 | |
| 21 | #include <media/stagefright/foundation/AHandler.h> |
| 22 | |
| 23 | #include "LinearRegression.h" |
| 24 | |
| 25 | #include <gui/Surface.h> |
| 26 | |
Andreas Huber | bf049b9 | 2013-01-29 09:22:16 -0800 | [diff] [blame^] | 27 | #define USE_TUNNEL_RENDERER 0 |
| 28 | |
Andreas Huber | 8a61c22 | 2012-08-31 14:05:27 -0700 | [diff] [blame] | 29 | namespace android { |
| 30 | |
| 31 | struct ABuffer; |
| 32 | struct ANetworkSession; |
Andreas Huber | bf049b9 | 2013-01-29 09:22:16 -0800 | [diff] [blame^] | 33 | |
| 34 | #if USE_TUNNEL_RENDERER |
Andreas Huber | 8a61c22 | 2012-08-31 14:05:27 -0700 | [diff] [blame] | 35 | struct TunnelRenderer; |
Andreas Huber | bf049b9 | 2013-01-29 09:22:16 -0800 | [diff] [blame^] | 36 | #else |
| 37 | struct DirectRenderer; |
| 38 | #endif |
Andreas Huber | 8a61c22 | 2012-08-31 14:05:27 -0700 | [diff] [blame] | 39 | |
| 40 | // Creates a pair of sockets for RTP/RTCP traffic, instantiates a renderer |
| 41 | // for incoming transport stream data and occasionally sends statistics over |
| 42 | // the RTCP channel. |
| 43 | struct RTPSink : public AHandler { |
| 44 | RTPSink(const sp<ANetworkSession> &netSession, |
Andreas Huber | bf049b9 | 2013-01-29 09:22:16 -0800 | [diff] [blame^] | 45 | const sp<IGraphicBufferProducer> &bufferProducer, |
| 46 | const sp<AMessage> ¬ify); |
Andreas Huber | 8a61c22 | 2012-08-31 14:05:27 -0700 | [diff] [blame] | 47 | |
| 48 | // If TCP interleaving is used, no UDP sockets are created, instead |
| 49 | // incoming RTP/RTCP packets (arriving on the RTSP control connection) |
| 50 | // are manually injected by WifiDisplaySink. |
| 51 | status_t init(bool useTCPInterleaving); |
| 52 | |
| 53 | status_t connect( |
| 54 | const char *host, int32_t remoteRtpPort, int32_t remoteRtcpPort); |
| 55 | |
| 56 | int32_t getRTPPort() const; |
| 57 | |
| 58 | status_t injectPacket(bool isRTP, const sp<ABuffer> &buffer); |
| 59 | |
| 60 | protected: |
| 61 | virtual void onMessageReceived(const sp<AMessage> &msg); |
| 62 | virtual ~RTPSink(); |
| 63 | |
| 64 | private: |
| 65 | enum { |
| 66 | kWhatRTPNotify, |
| 67 | kWhatRTCPNotify, |
| 68 | kWhatSendRR, |
| 69 | kWhatPacketLost, |
| 70 | kWhatInject, |
| 71 | }; |
| 72 | |
| 73 | struct Source; |
| 74 | struct StreamSource; |
| 75 | |
| 76 | sp<ANetworkSession> mNetSession; |
Andy McFadden | 484566c | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 77 | sp<IGraphicBufferProducer> mSurfaceTex; |
Andreas Huber | bf049b9 | 2013-01-29 09:22:16 -0800 | [diff] [blame^] | 78 | sp<AMessage> mNotify; |
Andreas Huber | 8a61c22 | 2012-08-31 14:05:27 -0700 | [diff] [blame] | 79 | KeyedVector<uint32_t, sp<Source> > mSources; |
| 80 | |
| 81 | int32_t mRTPPort; |
| 82 | int32_t mRTPSessionID; |
| 83 | int32_t mRTCPSessionID; |
| 84 | |
| 85 | int64_t mFirstArrivalTimeUs; |
| 86 | int64_t mNumPacketsReceived; |
| 87 | LinearRegression mRegression; |
| 88 | int64_t mMaxDelayMs; |
| 89 | |
Andreas Huber | bf049b9 | 2013-01-29 09:22:16 -0800 | [diff] [blame^] | 90 | #if USE_TUNNEL_RENDERER |
Andreas Huber | 8a61c22 | 2012-08-31 14:05:27 -0700 | [diff] [blame] | 91 | sp<TunnelRenderer> mRenderer; |
Andreas Huber | bf049b9 | 2013-01-29 09:22:16 -0800 | [diff] [blame^] | 92 | #else |
| 93 | sp<DirectRenderer> mRenderer; |
| 94 | #endif |
Andreas Huber | 8a61c22 | 2012-08-31 14:05:27 -0700 | [diff] [blame] | 95 | |
| 96 | status_t parseRTP(const sp<ABuffer> &buffer); |
| 97 | status_t parseRTCP(const sp<ABuffer> &buffer); |
| 98 | status_t parseBYE(const uint8_t *data, size_t size); |
| 99 | status_t parseSR(const uint8_t *data, size_t size); |
| 100 | |
| 101 | void addSDES(const sp<ABuffer> &buffer); |
| 102 | void onSendRR(); |
| 103 | void onPacketLost(const sp<AMessage> &msg); |
| 104 | void scheduleSendRR(); |
| 105 | |
| 106 | DISALLOW_EVIL_CONSTRUCTORS(RTPSink); |
| 107 | }; |
| 108 | |
| 109 | } // namespace android |
| 110 | |
| 111 | #endif // RTP_SINK_H_ |