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 PLAYBACK_SESSION_H_ 18 19 #define PLAYBACK_SESSION_H_ 20 21 #include "MediaSender.h" 22 #include "VideoFormats.h" 23 #include "WifiDisplaySource.h" 24 25 namespace android { 26 27 struct ABuffer; 28 struct BufferQueue; 29 struct IHDCP; 30 struct IGraphicBufferProducer; 31 struct MediaPuller; 32 struct MediaSource; 33 struct MediaSender; 34 struct NuMediaExtractor; 35 36 // Encapsulates the state of an RTP/RTCP session in the context of wifi 37 // display. 38 struct WifiDisplaySource::PlaybackSession : public AHandler { 39 PlaybackSession( 40 const sp<ANetworkSession> &netSession, 41 const sp<AMessage> ¬ify, 42 const struct in_addr &interfaceAddr, 43 const sp<IHDCP> &hdcp, 44 const char *path = NULL); 45 46 status_t init( 47 const char *clientIP, 48 int32_t clientRtp, 49 RTPSender::TransportMode rtpMode, 50 int32_t clientRtcp, 51 RTPSender::TransportMode rtcpMode, 52 bool enableAudio, 53 bool usePCMAudio, 54 bool enableVideo, 55 VideoFormats::ResolutionType videoResolutionType, 56 size_t videoResolutionIndex); 57 58 void destroyAsync(); 59 60 int32_t getRTPPort() const; 61 62 int64_t getLastLifesignUs() const; 63 void updateLiveness(); 64 65 status_t play(); 66 status_t finishPlay(); 67 status_t pause(); 68 69 sp<IGraphicBufferProducer> getSurfaceTexture(); 70 71 void requestIDRFrame(); 72 73 enum { 74 kWhatSessionDead, 75 kWhatBinaryData, 76 kWhatSessionEstablished, 77 kWhatSessionDestroyed, 78 }; 79 80 protected: 81 virtual void onMessageReceived(const sp<AMessage> &msg); 82 virtual ~PlaybackSession(); 83 84 private: 85 struct Track; 86 87 enum { 88 kWhatMediaPullerNotify, 89 kWhatConverterNotify, 90 kWhatTrackNotify, 91 kWhatUpdateSurface, 92 kWhatPause, 93 kWhatResume, 94 kWhatMediaSenderNotify, 95 kWhatPullExtractorSample, 96 }; 97 98 sp<ANetworkSession> mNetSession; 99 sp<AMessage> mNotify; 100 in_addr mInterfaceAddr; 101 sp<IHDCP> mHDCP; 102 AString mMediaPath; 103 104 sp<MediaSender> mMediaSender; 105 int32_t mLocalRTPPort; 106 107 bool mWeAreDead; 108 bool mPaused; 109 110 int64_t mLastLifesignUs; 111 112 sp<BufferQueue> mBufferQueue; 113 114 KeyedVector<size_t, sp<Track> > mTracks; 115 ssize_t mVideoTrackIndex; 116 117 int64_t mPrevTimeUs; 118 119 sp<NuMediaExtractor> mExtractor; 120 KeyedVector<size_t, size_t> mExtractorTrackToInternalTrack; 121 bool mPullExtractorPending; 122 int32_t mPullExtractorGeneration; 123 int64_t mFirstSampleTimeRealUs; 124 int64_t mFirstSampleTimeUs; 125 126 status_t setupMediaPacketizer(bool enableAudio, bool enableVideo); 127 128 status_t setupPacketizer( 129 bool enableAudio, 130 bool usePCMAudio, 131 bool enableVideo, 132 VideoFormats::ResolutionType videoResolutionType, 133 size_t videoResolutionIndex); 134 135 status_t addSource( 136 bool isVideo, 137 const sp<MediaSource> &source, 138 bool isRepeaterSource, 139 bool usePCMAudio, 140 size_t *numInputBuffers); 141 142 status_t addVideoSource( 143 VideoFormats::ResolutionType videoResolutionType, 144 size_t videoResolutionIndex); 145 146 status_t addAudioSource(bool usePCMAudio); 147 148 status_t onMediaSenderInitialized(); 149 150 void notifySessionDead(); 151 152 void schedulePullExtractor(); 153 void onPullExtractor(); 154 155 void onSinkFeedback(const sp<AMessage> &msg); 156 157 DISALLOW_EVIL_CONSTRUCTORS(PlaybackSession); 158 }; 159 160 } // namespace android 161 162 #endif // PLAYBACK_SESSION_H_ 163 164