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