TimedTextDriver.h revision 692ac36c4b6a09fed5113a4f45f00a041665a769
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 TIMED_TEXT_DRIVER_H_
18#define TIMED_TEXT_DRIVER_H_
19
20#include <media/stagefright/foundation/ABase.h> // for DISALLOW_* macro
21#include <utils/Errors.h> // for status_t
22#include <utils/RefBase.h>
23#include <utils/threads.h>
24
25namespace android {
26
27class ALooper;
28class MediaPlayerBase;
29class MediaSource;
30class Parcel;
31class TimedTextPlayer;
32class TimedTextSource;
33class DataSource;
34
35class TimedTextDriver {
36public:
37    TimedTextDriver(const wp<MediaPlayerBase> &listener);
38
39    ~TimedTextDriver();
40
41    status_t start();
42    status_t pause();
43    status_t selectTrack(size_t index);
44    status_t unselectTrack(size_t index);
45
46    status_t seekToAsync(int64_t timeUs);
47
48    status_t addInBandTextSource(
49            size_t trackIndex, const sp<MediaSource>& source);
50
51    status_t addOutOfBandTextSource(
52            size_t trackIndex, const char *uri, const char *mimeType);
53
54    // Caller owns the file desriptor and caller is responsible for closing it.
55    status_t addOutOfBandTextSource(
56            size_t trackIndex, int fd, off64_t offset,
57            off64_t length, const char *mimeType);
58
59    void getExternalTrackInfo(Parcel *parcel);
60    size_t countExternalTracks() const;
61
62private:
63    Mutex mLock;
64
65    enum State {
66        UNINITIALIZED,
67        PLAYING,
68        PAUSED,
69    };
70
71    enum TextSourceType {
72        TEXT_SOURCE_TYPE_IN_BAND = 0,
73        TEXT_SOURCE_TYPE_OUT_OF_BAND,
74    };
75
76    sp<ALooper> mLooper;
77    sp<TimedTextPlayer> mPlayer;
78    wp<MediaPlayerBase> mListener;
79
80    // Variables to be guarded by mLock.
81    State mState;
82    size_t mCurrentTrackIndex;
83    KeyedVector<size_t, sp<TimedTextSource> > mTextSourceVector;
84    Vector<TextSourceType> mTextSourceTypeVector;
85
86    // -- End of variables to be guarded by mLock
87
88    status_t selectTrack_l(size_t index);
89
90    status_t createOutOfBandTextSource(
91            size_t trackIndex, const char* mimeType,
92            const sp<DataSource>& dataSource);
93
94    DISALLOW_EVIL_CONSTRUCTORS(TimedTextDriver);
95};
96
97}  // namespace android
98
99#endif  // TIMED_TEXT_DRIVER_H_
100