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