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 "Sender.h"
     22 #include "WifiDisplaySource.h"
     23 
     24 namespace android {
     25 
     26 struct ABuffer;
     27 struct BufferQueue;
     28 struct IHDCP;
     29 struct ISurfaceTexture;
     30 struct MediaPuller;
     31 struct MediaSource;
     32 struct TSPacketizer;
     33 
     34 // Encapsulates the state of an RTP/RTCP session in the context of wifi
     35 // display.
     36 struct WifiDisplaySource::PlaybackSession : public AHandler {
     37     PlaybackSession(
     38             const sp<ANetworkSession> &netSession,
     39             const sp<AMessage> &notify,
     40             const struct in_addr &interfaceAddr,
     41             const sp<IHDCP> &hdcp);
     42 
     43     status_t init(
     44             const char *clientIP, int32_t clientRtp, int32_t clientRtcp,
     45             Sender::TransportMode transportMode,
     46             bool usePCMAudio);
     47 
     48     void destroyAsync();
     49 
     50     int32_t getRTPPort() const;
     51 
     52     int64_t getLastLifesignUs() const;
     53     void updateLiveness();
     54 
     55     status_t play();
     56     status_t finishPlay();
     57     status_t pause();
     58 
     59     sp<ISurfaceTexture> getSurfaceTexture();
     60     int32_t width() const;
     61     int32_t height() const;
     62 
     63     void requestIDRFrame();
     64 
     65     enum {
     66         kWhatSessionDead,
     67         kWhatBinaryData,
     68         kWhatSessionEstablished,
     69         kWhatSessionDestroyed,
     70     };
     71 
     72 protected:
     73     virtual void onMessageReceived(const sp<AMessage> &msg);
     74     virtual ~PlaybackSession();
     75 
     76 private:
     77     struct Track;
     78 
     79     enum {
     80         kWhatMediaPullerNotify,
     81         kWhatConverterNotify,
     82         kWhatTrackNotify,
     83         kWhatSenderNotify,
     84         kWhatUpdateSurface,
     85         kWhatFinishPlay,
     86         kWhatPacketize,
     87     };
     88 
     89     sp<ANetworkSession> mNetSession;
     90     sp<Sender> mSender;
     91     sp<ALooper> mSenderLooper;
     92     sp<AMessage> mNotify;
     93     in_addr mInterfaceAddr;
     94     sp<IHDCP> mHDCP;
     95     bool mWeAreDead;
     96 
     97     int64_t mLastLifesignUs;
     98 
     99     sp<TSPacketizer> mPacketizer;
    100     sp<BufferQueue> mBufferQueue;
    101 
    102     KeyedVector<size_t, sp<Track> > mTracks;
    103     ssize_t mVideoTrackIndex;
    104 
    105     int64_t mPrevTimeUs;
    106 
    107     bool mAllTracksHavePacketizerIndex;
    108 
    109     status_t setupPacketizer(bool usePCMAudio);
    110 
    111     status_t addSource(
    112             bool isVideo,
    113             const sp<MediaSource> &source,
    114             bool isRepeaterSource,
    115             bool usePCMAudio,
    116             size_t *numInputBuffers);
    117 
    118     status_t addVideoSource();
    119     status_t addAudioSource(bool usePCMAudio);
    120 
    121     ssize_t appendTSData(
    122             const void *data, size_t size, bool timeDiscontinuity, bool flush);
    123 
    124     status_t onFinishPlay();
    125     status_t onFinishPlay2();
    126 
    127     bool allTracksHavePacketizerIndex();
    128 
    129     status_t packetizeAccessUnit(
    130             size_t trackIndex, const sp<ABuffer> &accessUnit,
    131             sp<ABuffer> *packets);
    132 
    133     status_t packetizeQueuedAccessUnits();
    134 
    135     void notifySessionDead();
    136 
    137     void drainAccessUnits();
    138 
    139     // Returns true iff an access unit was successfully drained.
    140     bool drainAccessUnit();
    141 
    142     DISALLOW_EVIL_CONSTRUCTORS(PlaybackSession);
    143 };
    144 
    145 }  // namespace android
    146 
    147 #endif  // PLAYBACK_SESSION_H_
    148 
    149