MediaSender.h revision a556c4822fc205db0d27834ba5b637c351d73ffa
1/* 2 * Copyright 2013, 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 MEDIA_SENDER_H_ 18 19#define MEDIA_SENDER_H_ 20 21#include "rtp/RTPSender.h" 22 23#include <media/stagefright/foundation/ABase.h> 24#include <media/stagefright/foundation/AHandler.h> 25#include <utils/Errors.h> 26#include <utils/Vector.h> 27 28namespace android { 29 30struct ABuffer; 31struct ANetworkSession; 32struct AMessage; 33struct IHDCP; 34struct TSPacketizer; 35 36// This class facilitates sending of data from one or more media tracks 37// through one or more RTP channels, either providing a 1:1 mapping from 38// track to RTP channel or muxing all tracks into a single RTP channel and 39// using transport stream encapsulation. 40// Optionally the (video) data is encrypted using the provided hdcp object. 41struct MediaSender : public AHandler { 42 enum { 43 kWhatInitDone, 44 kWhatError, 45 }; 46 47 MediaSender( 48 const sp<ANetworkSession> &netSession, 49 const sp<AMessage> ¬ify); 50 51 status_t setHDCP(const sp<IHDCP> &hdcp); 52 53 enum FlagBits { 54 FLAG_MANUALLY_PREPEND_SPS_PPS = 1, 55 }; 56 ssize_t addTrack(const sp<AMessage> &format, uint32_t flags); 57 58 // If trackIndex == -1, initialize for transport stream muxing. 59 status_t initAsync( 60 ssize_t trackIndex, 61 RTPSender::TransportMode transportMode, 62 const char *remoteHost, 63 int32_t remoteRTPPort, 64 int32_t remoteRTCPPort, 65 int32_t *localRTPPort); 66 67 status_t queueAccessUnit( 68 size_t trackIndex, const sp<ABuffer> &accessUnit); 69 70protected: 71 virtual void onMessageReceived(const sp<AMessage> &msg); 72 virtual ~MediaSender(); 73 74private: 75 enum { 76 kWhatSenderNotify, 77 }; 78 79 enum Mode { 80 MODE_UNDEFINED, 81 MODE_TRANSPORT_STREAM, 82 MODE_ELEMENTARY_STREAMS, 83 }; 84 85 struct TrackInfo { 86 sp<AMessage> mFormat; 87 uint32_t mFlags; 88 sp<RTPSender> mSender; 89 List<sp<ABuffer> > mAccessUnits; 90 ssize_t mPacketizerTrackIndex; 91 bool mIsAudio; 92 }; 93 94 sp<ANetworkSession> mNetSession; 95 sp<AMessage> mNotify; 96 97 sp<IHDCP> mHDCP; 98 99 Mode mMode; 100 int32_t mGeneration; 101 102 Vector<TrackInfo> mTrackInfos; 103 104 sp<TSPacketizer> mTSPacketizer; 105 sp<RTPSender> mTSSender; 106 int64_t mPrevTimeUs; 107 108 size_t mInitDoneCount; 109 110 void onSenderNotify(const sp<AMessage> &msg); 111 112 void notifyInitDone(status_t err); 113 void notifyError(status_t err); 114 115 status_t packetizeAccessUnit( 116 size_t trackIndex, 117 sp<ABuffer> accessUnit, 118 sp<ABuffer> *tsPackets); 119 120 DISALLOW_EVIL_CONSTRUCTORS(MediaSender); 121}; 122 123} // namespace android 124 125#endif // MEDIA_SENDER_H_ 126 127