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 TIMED_TEXT_DRIVER_H_ 18 #define TIMED_TEXT_DRIVER_H_ 19 20 #include <media/stagefright/foundation/ABase.h> // for DISALLOW_* macro 21 #include <utils/Errors.h> // for status_t 22 #include <utils/RefBase.h> 23 #include <utils/threads.h> 24 25 namespace android { 26 27 class ALooper; 28 struct IMediaHTTPService; 29 class MediaPlayerBase; 30 class MediaSource; 31 class Parcel; 32 class TimedTextPlayer; 33 class TimedTextSource; 34 class DataSource; 35 36 class TimedTextDriver { 37 public: 38 TimedTextDriver( 39 const wp<MediaPlayerBase> &listener, 40 const sp<IMediaHTTPService> &httpService); 41 42 ~TimedTextDriver(); 43 44 status_t start(); 45 status_t pause(); 46 status_t selectTrack(size_t index); 47 status_t unselectTrack(size_t index); 48 49 status_t seekToAsync(int64_t timeUs); 50 51 status_t addInBandTextSource( 52 size_t trackIndex, const sp<MediaSource>& source); 53 54 status_t addOutOfBandTextSource( 55 size_t trackIndex, const char *uri, const char *mimeType); 56 57 // Caller owns the file desriptor and caller is responsible for closing it. 58 status_t addOutOfBandTextSource( 59 size_t trackIndex, int fd, off64_t offset, 60 off64_t length, const char *mimeType); 61 62 void getExternalTrackInfo(Parcel *parcel); 63 size_t countExternalTracks() const; 64 65 private: 66 Mutex mLock; 67 68 enum State { 69 UNINITIALIZED, 70 PREPARED, 71 PLAYING, 72 PAUSED, 73 }; 74 75 enum TextSourceType { 76 TEXT_SOURCE_TYPE_IN_BAND = 0, 77 TEXT_SOURCE_TYPE_OUT_OF_BAND, 78 }; 79 80 sp<ALooper> mLooper; 81 sp<TimedTextPlayer> mPlayer; 82 wp<MediaPlayerBase> mListener; 83 sp<IMediaHTTPService> mHTTPService; 84 85 // Variables to be guarded by mLock. 86 State mState; 87 size_t mCurrentTrackIndex; 88 KeyedVector<size_t, sp<TimedTextSource> > mTextSourceVector; 89 Vector<TextSourceType> mTextSourceTypeVector; 90 91 // -- End of variables to be guarded by mLock 92 93 status_t selectTrack_l(size_t index); 94 95 status_t createOutOfBandTextSource( 96 size_t trackIndex, const char* mimeType, 97 const sp<DataSource>& dataSource); 98 99 DISALLOW_EVIL_CONSTRUCTORS(TimedTextDriver); 100 }; 101 102 } // namespace android 103 104 #endif // TIMED_TEXT_DRIVER_H_ 105