blob: 9a50f9a382ca3a7913387c3e1c693cfe4c88a182 [file] [log] [blame]
Andreas Hubera556c482013-03-05 10:56:27 -08001/*
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> &notify);
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
Andreas Huberbfd79f22013-03-07 10:33:20 -0800110 FILE *mLogFile;
111
Andreas Hubera556c482013-03-05 10:56:27 -0800112 void onSenderNotify(const sp<AMessage> &msg);
113
114 void notifyInitDone(status_t err);
115 void notifyError(status_t err);
116
117 status_t packetizeAccessUnit(
118 size_t trackIndex,
119 sp<ABuffer> accessUnit,
120 sp<ABuffer> *tsPackets);
121
122 DISALLOW_EVIL_CONSTRUCTORS(MediaSender);
123};
124
125} // namespace android
126
127#endif // MEDIA_SENDER_H_
128