1/* 2 * Copyright (C) 2011 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 TIMEDTEXT_PLAYER_H_ 18 19#define TIMEDTEXT_PLAYER_H_ 20 21#include <media/MediaPlayerInterface.h> 22#include <media/stagefright/foundation/ABase.h> 23#include <media/stagefright/foundation/AString.h> 24 25#include "include/TimedEventQueue.h" 26#include "TimedTextParser.h" 27 28namespace android { 29 30class MediaSource; 31class AwesomePlayer; 32class MediaBuffer; 33 34class TimedTextPlayer { 35public: 36 TimedTextPlayer(AwesomePlayer *observer, 37 const wp<MediaPlayerBase> &listener, 38 TimedEventQueue *queue); 39 40 virtual ~TimedTextPlayer(); 41 42 // index: the index of the text track which will 43 // be turned on 44 status_t start(uint8_t index); 45 46 void pause(); 47 48 void resume(); 49 50 status_t seekTo(int64_t time_us); 51 52 void addTextSource(sp<MediaSource> source); 53 54 status_t setTimedTextTrackIndex(int32_t index); 55 status_t setParameter(int key, const Parcel &request); 56 57private: 58 enum TextType { 59 kNoText = 0, 60 kInBandText = 1, 61 kOutOfBandText = 2, 62 }; 63 64 Mutex mLock; 65 66 sp<MediaSource> mSource; 67 sp<DataSource> mOutOfBandSource; 68 69 bool mSeeking; 70 int64_t mSeekTimeUs; 71 72 bool mStarted; 73 74 sp<TimedEventQueue::Event> mTextEvent; 75 bool mTextEventPending; 76 77 TimedEventQueue *mQueue; 78 79 wp<MediaPlayerBase> mListener; 80 AwesomePlayer *mObserver; 81 82 MediaBuffer *mTextBuffer; 83 Parcel mData; 84 85 // for in-band timed text 86 Vector<sp<MediaSource> > mTextTrackVector; 87 88 // for out-of-band timed text 89 struct OutOfBandText { 90 TimedTextParser::FileType type; 91 sp<DataSource> source; 92 }; 93 Vector<OutOfBandText > mTextOutOfBandVector; 94 95 sp<TimedTextParser> mTextParser; 96 AString mText; 97 98 TextType mTextType; 99 100 void reset(); 101 102 void onTextEvent(); 103 void postTextEvent(int64_t delayUs = -1); 104 void cancelTextEvent(); 105 106 void notifyListener(int msg, const Parcel *parcel = NULL); 107 108 status_t extractAndAppendLocalDescriptions(int64_t timeUs); 109 status_t extractAndSendGlobalDescriptions(); 110 111 DISALLOW_EVIL_CONSTRUCTORS(TimedTextPlayer); 112}; 113 114} // namespace android 115 116#endif // TIMEDTEXT_PLAYER_H_ 117