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