TimedTextDriver.h revision 613c8ae1b7a2b4f43b33a72dc2fff0bc8b7d4c6f
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(int32_t index);
44    status_t unselectTrack(int32_t index);
45
46    status_t seekToAsync(int64_t timeUs);
47
48    status_t addInBandTextSource(const sp<MediaSource>& source);
49    status_t addOutOfBandTextSource(const char *uri, const char *mimeType);
50    // Caller owns the file desriptor and caller is responsible for closing it.
51    status_t addOutOfBandTextSource(
52            int fd, off64_t offset, off64_t length, const char *mimeType);
53
54    void getTrackInfo(Parcel *parcel);
55
56private:
57    Mutex mLock;
58
59    enum State {
60        UNINITIALIZED,
61        PLAYING,
62        PAUSED,
63    };
64
65    sp<ALooper> mLooper;
66    sp<TimedTextPlayer> mPlayer;
67    wp<MediaPlayerBase> mListener;
68
69    // Variables to be guarded by mLock.
70    State mState;
71    int32_t mCurrentTrackIndex;
72    Vector<sp<TimedTextSource> > mTextSourceVector;
73    // -- End of variables to be guarded by mLock
74
75    status_t selectTrack_l(int32_t index);
76    status_t createOutOfBandTextSource(
77            const char *mimeType, const sp<DataSource>& dataSource);
78
79    DISALLOW_EVIL_CONSTRUCTORS(TimedTextDriver);
80};
81
82}  // namespace android
83
84#endif  // TIMED_TEXT_DRIVER_H_
85