GenericSource.h revision a19f33e4e50cda5d5953fa0cc662502262ac9dfd
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 kWhatFetchSubtitleData, 74 kWhatFetchTimedTextData, 75 kWhatSendSubtitleData, 76 kWhatSendTimedTextData, 77 kWhatChangeAVSource, 78 }; 79 80 Vector<sp<MediaSource> > mSources; 81 82 struct Track { 83 size_t mIndex; 84 sp<MediaSource> mSource; 85 sp<AnotherPacketSource> mPackets; 86 }; 87 88 Track mAudioTrack; 89 Track mVideoTrack; 90 Track mSubtitleTrack; 91 Track mTimedTextTrack; 92 93 int32_t mFetchSubtitleDataGeneration; 94 int32_t mFetchTimedTextDataGeneration; 95 int64_t mDurationUs; 96 bool mAudioIsVorbis; 97 bool mIsWidevine; 98 bool mUIDValid; 99 uid_t mUID; 100 sp<IMediaHTTPService> mHTTPService; 101 AString mUri; 102 KeyedVector<String8, String8> mUriHeaders; 103 int mFd; 104 int64_t mOffset; 105 int64_t mLength; 106 107 void resetDataSource(); 108 109 status_t initFromDataSource( 110 const sp<DataSource> &dataSource, 111 const char *mime); 112 113 void fetchTextData( 114 uint32_t what, media_track_type type, 115 int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg); 116 117 void sendTextData( 118 uint32_t what, media_track_type type, 119 int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg); 120 121 sp<ABuffer> mediaBufferToABuffer( 122 MediaBuffer *mbuf, 123 media_track_type trackType, 124 int64_t *actualTimeUs = NULL); 125 126 void readBuffer( 127 media_track_type trackType, 128 int64_t seekTimeUs = -1ll, int64_t *actualTimeUs = NULL, bool formatChange = false); 129 130 DISALLOW_EVIL_CONSTRUCTORS(GenericSource); 131}; 132 133} // namespace android 134 135#endif // GENERIC_SOURCE_H_ 136