NuPlayerSource.h revision 7c4f0d757bfeedaab4b7ef4ccf5b0a72ec8f4306
1/*
2 * Copyright (C) 2010 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 NUPLAYER_SOURCE_H_
18
19#define NUPLAYER_SOURCE_H_
20
21#include "NuPlayer.h"
22
23#include <media/stagefright/foundation/AMessage.h>
24#include <media/stagefright/MetaData.h>
25#include <media/mediaplayer.h>
26#include <utils/Vector.h>
27
28namespace android {
29
30struct ABuffer;
31struct MetaData;
32struct MediaBuffer;
33
34struct NuPlayer::Source : public AHandler {
35    enum Flags {
36        FLAG_CAN_PAUSE          = 1,
37        FLAG_CAN_SEEK_BACKWARD  = 2,  // the "10 sec back button"
38        FLAG_CAN_SEEK_FORWARD   = 4,  // the "10 sec forward button"
39        FLAG_CAN_SEEK           = 8,  // the "seek bar"
40        FLAG_DYNAMIC_DURATION   = 16,
41        FLAG_SECURE             = 32,
42    };
43
44    enum {
45        kWhatPrepared,
46        kWhatFlagsChanged,
47        kWhatVideoSizeChanged,
48        kWhatBufferingStart,
49        kWhatBufferingEnd,
50        kWhatSubtitleData,
51        kWhatTimedTextData,
52        kWhatQueueDecoderShutdown,
53    };
54
55    // The provides message is used to notify the player about various
56    // events.
57    Source(const sp<AMessage> &notify)
58        : mNotify(notify) {
59    }
60
61    virtual void prepareAsync() = 0;
62
63    virtual void start() = 0;
64    virtual void stop() {}
65    virtual void pause() {}
66    virtual void resume() {}
67
68    // Returns OK iff more data was available,
69    // an error or ERROR_END_OF_STREAM if not.
70    virtual status_t feedMoreTSData() = 0;
71
72    virtual sp<AMessage> getFormat(bool audio);
73    virtual sp<MetaData> getFormatMeta(bool /* audio */) { return NULL; }
74
75    virtual status_t dequeueAccessUnit(
76            bool audio, sp<ABuffer> *accessUnit) = 0;
77
78    virtual status_t getDuration(int64_t * /* durationUs */) {
79        return INVALID_OPERATION;
80    }
81
82    virtual size_t getTrackCount() const {
83        return 0;
84    }
85
86    virtual sp<AMessage> getTrackInfo(size_t /* trackIndex */) const {
87        return NULL;
88    }
89
90    virtual ssize_t getSelectedTrack(media_track_type /* type */) const {
91        return INVALID_OPERATION;
92    }
93
94    virtual status_t selectTrack(size_t /* trackIndex */, bool /* select */) {
95        return INVALID_OPERATION;
96    }
97
98    virtual status_t seekTo(int64_t /* seekTimeUs */) {
99        return INVALID_OPERATION;
100    }
101
102    virtual status_t setBuffers(bool /* audio */, Vector<MediaBuffer *> &/* buffers */) {
103        return INVALID_OPERATION;
104    }
105
106    virtual bool isRealTime() const {
107        return false;
108    }
109
110protected:
111    virtual ~Source() {}
112
113    virtual void onMessageReceived(const sp<AMessage> &msg);
114
115    sp<AMessage> dupNotify() const { return mNotify->dup(); }
116
117    void notifyFlagsChanged(uint32_t flags);
118    void notifyVideoSizeChanged(const sp<AMessage> &format = NULL);
119    void notifyPrepared(status_t err = OK);
120
121private:
122    sp<AMessage> mNotify;
123
124    DISALLOW_EVIL_CONSTRUCTORS(Source);
125};
126
127}  // namespace android
128
129#endif  // NUPLAYER_SOURCE_H_
130
131