TimedTextPlayer.h revision 6655174826330afe66ef766258181ae8c11f3f6c
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 TIMEDTEXT_PLAYER_H_
18#define TIMEDTEXT_PLAYER_H_
19
20#include <binder/Parcel.h>
21#include <media/stagefright/foundation/ABase.h>
22#include <media/stagefright/foundation/AHandler.h>
23#include <media/stagefright/MediaSource.h>
24#include <utils/RefBase.h>
25
26#include "TimedTextSource.h"
27
28namespace android {
29
30class AMessage;
31class MediaPlayerBase;
32class TimedTextDriver;
33class TimedTextSource;
34
35class TimedTextPlayer : public AHandler {
36public:
37    TimedTextPlayer(const wp<MediaPlayerBase> &listener);
38
39    virtual ~TimedTextPlayer();
40
41    void start();
42    void pause();
43    void resume();
44    void seekToAsync(int64_t timeUs);
45    void setDataSource(sp<TimedTextSource> source);
46
47protected:
48    virtual void onMessageReceived(const sp<AMessage> &msg);
49
50private:
51    enum {
52        kWhatPause = 'paus',
53        kWhatSeek = 'seek',
54        kWhatSendSubtitle = 'send',
55        kWhatSetSource = 'ssrc',
56    };
57
58    // To add Parcel into an AMessage as an object, it should be 'RefBase'.
59    struct ParcelEvent : public RefBase {
60        Parcel parcel;
61    };
62
63    wp<MediaPlayerBase> mListener;
64    sp<TimedTextSource> mSource;
65    int32_t mSendSubtitleGeneration;
66
67    void doSeekAndRead(int64_t seekTimeUs);
68    void doRead(MediaSource::ReadOptions* options = NULL);
69    void onTextEvent();
70    void postTextEvent(const sp<ParcelEvent>& parcel = NULL, int64_t timeUs = -1);
71    void notifyListener(int msg, const Parcel *parcel = NULL);
72
73    DISALLOW_EVIL_CONSTRUCTORS(TimedTextPlayer);
74};
75
76}  // namespace android
77
78#endif  // TIMEDTEXT_PLAYER_H_
79