TimedTextPlayer.h revision bae00e73c6d1d87cc5fd42b50f95d1d9572162ea
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 seekToAsync(int64_t timeUs);
44    void setDataSource(sp<TimedTextSource> source);
45
46protected:
47    virtual void onMessageReceived(const sp<AMessage> &msg);
48
49private:
50    enum {
51        kWhatPause = 'paus',
52        kWhatSeek = 'seek',
53        kWhatSendSubtitle = 'send',
54        kWhatSetSource = 'ssrc',
55    };
56
57    // To add Parcel into an AMessage as an object, it should be 'RefBase'.
58    struct ParcelEvent : public RefBase {
59        Parcel parcel;
60    };
61
62    wp<MediaPlayerBase> mListener;
63    sp<TimedTextSource> mSource;
64    int32_t mSendSubtitleGeneration;
65
66    void doSeekAndRead(int64_t seekTimeUs);
67    void doRead(MediaSource::ReadOptions* options = NULL);
68    void onTextEvent();
69    void postTextEvent(const sp<ParcelEvent>& parcel = NULL, int64_t timeUs = -1);
70    void postTextEventDelayUs(const sp<ParcelEvent>& parcel = NULL, int64_t delayUs = -1);
71    void notifyError(int error = 0);
72    void notifyListener(const Parcel *parcel = NULL);
73
74    DISALLOW_EVIL_CONSTRUCTORS(TimedTextPlayer);
75};
76
77}  // namespace android
78
79#endif  // TIMEDTEXT_PLAYER_H_
80