GenericSource.h revision 615fb231ac0c750af41d35dfe13e752630fea00b
1/* 2 * Copyright (C) 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 GENERIC_SOURCE_H_ 18 19#define GENERIC_SOURCE_H_ 20 21#include "NuPlayer.h" 22#include "NuPlayerSource.h" 23 24#include "ATSParser.h" 25 26#include <media/mediaplayer.h> 27 28namespace android { 29 30struct AnotherPacketSource; 31struct ARTSPController; 32struct DataSource; 33struct IMediaHTTPService; 34struct MediaSource; 35class MediaBuffer; 36struct NuCachedSource2; 37 38struct NuPlayer::GenericSource : public NuPlayer::Source { 39 GenericSource(const sp<AMessage> ¬ify, bool uidValid, uid_t uid); 40 41 status_t setDataSource( 42 const sp<IMediaHTTPService> &httpService, 43 const char *url, 44 const KeyedVector<String8, String8> *headers); 45 46 status_t setDataSource(int fd, int64_t offset, int64_t length); 47 48 virtual void prepareAsync(); 49 50 virtual void start(); 51 52 virtual status_t feedMoreTSData(); 53 54 virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit); 55 56 virtual status_t getDuration(int64_t *durationUs); 57 virtual size_t getTrackCount() const; 58 virtual sp<AMessage> getTrackInfo(size_t trackIndex) const; 59 virtual ssize_t getSelectedTrack(media_track_type type) const; 60 virtual status_t selectTrack(size_t trackIndex, bool select); 61 virtual status_t seekTo(int64_t seekTimeUs); 62 63 virtual status_t setBuffers(bool audio, Vector<MediaBuffer *> &buffers); 64 65protected: 66 virtual ~GenericSource(); 67 68 virtual void onMessageReceived(const sp<AMessage> &msg); 69 70 virtual sp<MetaData> getFormatMeta(bool audio); 71 72private: 73 enum { 74 kWhatPrepareAsync, 75 kWhatFetchSubtitleData, 76 kWhatFetchTimedTextData, 77 kWhatSendSubtitleData, 78 kWhatSendTimedTextData, 79 kWhatChangeAVSource, 80 }; 81 82 Vector<sp<MediaSource> > mSources; 83 84 struct Track { 85 size_t mIndex; 86 sp<MediaSource> mSource; 87 sp<AnotherPacketSource> mPackets; 88 }; 89 90 Track mAudioTrack; 91 Track mVideoTrack; 92 Track mSubtitleTrack; 93 Track mTimedTextTrack; 94 95 int32_t mFetchSubtitleDataGeneration; 96 int32_t mFetchTimedTextDataGeneration; 97 int64_t mDurationUs; 98 bool mAudioIsVorbis; 99 bool mIsWidevine; 100 bool mUIDValid; 101 uid_t mUID; 102 sp<IMediaHTTPService> mHTTPService; 103 AString mUri; 104 KeyedVector<String8, String8> mUriHeaders; 105 int mFd; 106 int64_t mOffset; 107 int64_t mLength; 108 109 sp<DataSource> mDataSource; 110 sp<NuCachedSource2> mCachedSource; 111 String8 mContentType; 112 AString mSniffedMIME; 113 off64_t mMetaDataSize; 114 115 sp<ALooper> mLooper; 116 117 void resetDataSource(); 118 119 status_t initFromDataSource(); 120 121 status_t prefillCacheIfNecessary(); 122 123 void notifyPreparedAndCleanup(status_t err); 124 125 void onPrepareAsync(); 126 127 void fetchTextData( 128 uint32_t what, media_track_type type, 129 int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg); 130 131 void sendTextData( 132 uint32_t what, media_track_type type, 133 int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg); 134 135 sp<ABuffer> mediaBufferToABuffer( 136 MediaBuffer *mbuf, 137 media_track_type trackType, 138 int64_t *actualTimeUs = NULL); 139 140 void readBuffer( 141 media_track_type trackType, 142 int64_t seekTimeUs = -1ll, int64_t *actualTimeUs = NULL, bool formatChange = false); 143 144 DISALLOW_EVIL_CONSTRUCTORS(GenericSource); 145}; 146 147} // namespace android 148 149#endif // GENERIC_SOURCE_H_ 150