17a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang/* 26655174826330afe66ef766258181ae8c11f3f6cInsun Kang * Copyright (C) 2012 The Android Open Source Project 37a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang * 47a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang * Licensed under the Apache License, Version 2.0 (the "License"); 57a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang * you may not use this file except in compliance with the License. 67a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang * You may obtain a copy of the License at 77a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang * 87a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang * http://www.apache.org/licenses/LICENSE-2.0 97a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang * 107a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang * Unless required by applicable law or agreed to in writing, software 117a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang * distributed under the License is distributed on an "AS IS" BASIS, 127a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang * See the License for the specific language governing permissions and 147a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang * limitations under the License. 157a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang */ 167a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang 177a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang#ifndef TIMEDTEXT_PLAYER_H_ 187a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang#define TIMEDTEXT_PLAYER_H_ 197a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang 206655174826330afe66ef766258181ae8c11f3f6cInsun Kang#include <binder/Parcel.h> 217a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang#include <media/stagefright/foundation/ABase.h> 226655174826330afe66ef766258181ae8c11f3f6cInsun Kang#include <media/stagefright/foundation/AHandler.h> 236655174826330afe66ef766258181ae8c11f3f6cInsun Kang#include <media/stagefright/MediaSource.h> 246655174826330afe66ef766258181ae8c11f3f6cInsun Kang#include <utils/RefBase.h> 257a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang 266655174826330afe66ef766258181ae8c11f3f6cInsun Kang#include "TimedTextSource.h" 277a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang 287a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wangnamespace android { 297a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang 306655174826330afe66ef766258181ae8c11f3f6cInsun Kangclass AMessage; 316655174826330afe66ef766258181ae8c11f3f6cInsun Kangclass MediaPlayerBase; 326655174826330afe66ef766258181ae8c11f3f6cInsun Kangclass TimedTextDriver; 336655174826330afe66ef766258181ae8c11f3f6cInsun Kangclass TimedTextSource; 347a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang 356655174826330afe66ef766258181ae8c11f3f6cInsun Kangclass TimedTextPlayer : public AHandler { 367a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wangpublic: 376655174826330afe66ef766258181ae8c11f3f6cInsun Kang TimedTextPlayer(const wp<MediaPlayerBase> &listener); 387a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang 397a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang virtual ~TimedTextPlayer(); 407a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang 416655174826330afe66ef766258181ae8c11f3f6cInsun Kang void start(); 427a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang void pause(); 43bb6bc8491fe819f96e1902e56694715cb110ce94Insun Kang void resume(); 446655174826330afe66ef766258181ae8c11f3f6cInsun Kang void seekToAsync(int64_t timeUs); 456655174826330afe66ef766258181ae8c11f3f6cInsun Kang void setDataSource(sp<TimedTextSource> source); 467a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang 476655174826330afe66ef766258181ae8c11f3f6cInsun Kangprotected: 486655174826330afe66ef766258181ae8c11f3f6cInsun Kang virtual void onMessageReceived(const sp<AMessage> &msg); 497a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang 507a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wangprivate: 516655174826330afe66ef766258181ae8c11f3f6cInsun Kang enum { 526655174826330afe66ef766258181ae8c11f3f6cInsun Kang kWhatPause = 'paus', 53bb6bc8491fe819f96e1902e56694715cb110ce94Insun Kang kWhatResume = 'resm', 546472badc497a9e748411f8c8c9ed5d83ef335a85Insun Kang kWhatStart = 'strt', 556472badc497a9e748411f8c8c9ed5d83ef335a85Insun Kang kWhatSeek = 'seek', 564e1c91dd07fad96ee2387eda510c6da45e5dff0aInsun Kang kWhatRetryRead = 'read', 576655174826330afe66ef766258181ae8c11f3f6cInsun Kang kWhatSendSubtitle = 'send', 586655174826330afe66ef766258181ae8c11f3f6cInsun Kang kWhatSetSource = 'ssrc', 59965d08ba16ee82bc85f69546360c18e7da907406Gloria Wang }; 60965d08ba16ee82bc85f69546360c18e7da907406Gloria Wang 616655174826330afe66ef766258181ae8c11f3f6cInsun Kang // To add Parcel into an AMessage as an object, it should be 'RefBase'. 626655174826330afe66ef766258181ae8c11f3f6cInsun Kang struct ParcelEvent : public RefBase { 636655174826330afe66ef766258181ae8c11f3f6cInsun Kang Parcel parcel; 64965d08ba16ee82bc85f69546360c18e7da907406Gloria Wang }; 65965d08ba16ee82bc85f69546360c18e7da907406Gloria Wang 666655174826330afe66ef766258181ae8c11f3f6cInsun Kang wp<MediaPlayerBase> mListener; 676655174826330afe66ef766258181ae8c11f3f6cInsun Kang sp<TimedTextSource> mSource; 686472badc497a9e748411f8c8c9ed5d83ef335a85Insun Kang int64_t mPendingSeekTimeUs; 696472badc497a9e748411f8c8c9ed5d83ef335a85Insun Kang bool mPaused; 706655174826330afe66ef766258181ae8c11f3f6cInsun Kang int32_t mSendSubtitleGeneration; 717a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang 726655174826330afe66ef766258181ae8c11f3f6cInsun Kang void doSeekAndRead(int64_t seekTimeUs); 736655174826330afe66ef766258181ae8c11f3f6cInsun Kang void doRead(MediaSource::ReadOptions* options = NULL); 747a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang void onTextEvent(); 756655174826330afe66ef766258181ae8c11f3f6cInsun Kang void postTextEvent(const sp<ParcelEvent>& parcel = NULL, int64_t timeUs = -1); 762f0632f12cd02b0350918720443c888b48f4417bInsun Kang int64_t delayUsFromCurrentTime(int64_t fireTimeUs); 77f9d660a5e0196240add5daf0199f128d471e592cInsun Kang void notifyError(int error = 0); 78f9d660a5e0196240add5daf0199f128d471e592cInsun Kang void notifyListener(const Parcel *parcel = NULL); 793b573f7bf1c5736d500e39013b8d32478a1429e6Gloria Wang 807a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang DISALLOW_EVIL_CONSTRUCTORS(TimedTextPlayer); 817a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang}; 827a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang 837a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang} // namespace android 847a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang 857a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang#endif // TIMEDTEXT_PLAYER_H_ 86