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