TimedTextDriver.h revision eec46abb88dcc50621fd2d3f17a6b8d24fd07a19
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 25namespace android { 26 27class ALooper; 28class MediaPlayerBase; 29class MediaSource; 30class Parcel; 31class TimedTextPlayer; 32class TimedTextSource; 33class DataSource; 34 35class TimedTextDriver { 36public: 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 62private: 63 Mutex mLock; 64 65 enum State { 66 UNINITIALIZED, 67 PLAYING, 68 PAUSED, 69 }; 70 71 sp<ALooper> mLooper; 72 sp<TimedTextPlayer> mPlayer; 73 wp<MediaPlayerBase> mListener; 74 75 // Variables to be guarded by mLock. 76 State mState; 77 size_t mCurrentTrackIndex; 78 KeyedVector<size_t, sp<TimedTextSource> > mTextSourceVector; 79 Vector<bool> mTextSourceTypeVector; 80 81 // -- End of variables to be guarded by mLock 82 83 status_t selectTrack_l(size_t index); 84 85 status_t createOutOfBandTextSource( 86 size_t trackIndex, const char* mimeType, 87 const sp<DataSource>& dataSource); 88 89 DISALLOW_EVIL_CONSTRUCTORS(TimedTextDriver); 90}; 91 92} // namespace android 93 94#endif // TIMED_TEXT_DRIVER_H_ 95