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