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