TimedTextPlayer.h revision 6655174826330afe66ef766258181ae8c11f3f6c
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();
437a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang    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',
536655174826330afe66ef766258181ae8c11f3f6cInsun Kang        kWhatSeek = 'seek',
546655174826330afe66ef766258181ae8c11f3f6cInsun Kang        kWhatSendSubtitle = 'send',
556655174826330afe66ef766258181ae8c11f3f6cInsun Kang        kWhatSetSource = 'ssrc',
56965d08ba16ee82bc85f69546360c18e7da907406Gloria Wang    };
57965d08ba16ee82bc85f69546360c18e7da907406Gloria Wang
586655174826330afe66ef766258181ae8c11f3f6cInsun Kang    // To add Parcel into an AMessage as an object, it should be 'RefBase'.
596655174826330afe66ef766258181ae8c11f3f6cInsun Kang    struct ParcelEvent : public RefBase {
606655174826330afe66ef766258181ae8c11f3f6cInsun Kang        Parcel parcel;
61965d08ba16ee82bc85f69546360c18e7da907406Gloria Wang    };
62965d08ba16ee82bc85f69546360c18e7da907406Gloria Wang
636655174826330afe66ef766258181ae8c11f3f6cInsun Kang    wp<MediaPlayerBase> mListener;
646655174826330afe66ef766258181ae8c11f3f6cInsun Kang    sp<TimedTextSource> mSource;
656655174826330afe66ef766258181ae8c11f3f6cInsun Kang    int32_t mSendSubtitleGeneration;
667a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang
676655174826330afe66ef766258181ae8c11f3f6cInsun Kang    void doSeekAndRead(int64_t seekTimeUs);
686655174826330afe66ef766258181ae8c11f3f6cInsun Kang    void doRead(MediaSource::ReadOptions* options = NULL);
697a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang    void onTextEvent();
706655174826330afe66ef766258181ae8c11f3f6cInsun Kang    void postTextEvent(const sp<ParcelEvent>& parcel = NULL, int64_t timeUs = -1);
713b573f7bf1c5736d500e39013b8d32478a1429e6Gloria Wang    void notifyListener(int msg, const Parcel *parcel = NULL);
723b573f7bf1c5736d500e39013b8d32478a1429e6Gloria Wang
737a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang    DISALLOW_EVIL_CONSTRUCTORS(TimedTextPlayer);
747a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang};
757a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang
767a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang}  // namespace android
777a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang
787a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang#endif  // TIMEDTEXT_PLAYER_H_
79