15bc087c573c70c84c6a39946457590b42d392a33Andreas Huber/*
25bc087c573c70c84c6a39946457590b42d392a33Andreas Huber * Copyright (C) 2010 The Android Open Source Project
35bc087c573c70c84c6a39946457590b42d392a33Andreas Huber *
45bc087c573c70c84c6a39946457590b42d392a33Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
55bc087c573c70c84c6a39946457590b42d392a33Andreas Huber * you may not use this file except in compliance with the License.
65bc087c573c70c84c6a39946457590b42d392a33Andreas Huber * You may obtain a copy of the License at
75bc087c573c70c84c6a39946457590b42d392a33Andreas Huber *
85bc087c573c70c84c6a39946457590b42d392a33Andreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
95bc087c573c70c84c6a39946457590b42d392a33Andreas Huber *
105bc087c573c70c84c6a39946457590b42d392a33Andreas Huber * Unless required by applicable law or agreed to in writing, software
115bc087c573c70c84c6a39946457590b42d392a33Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
125bc087c573c70c84c6a39946457590b42d392a33Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135bc087c573c70c84c6a39946457590b42d392a33Andreas Huber * See the License for the specific language governing permissions and
145bc087c573c70c84c6a39946457590b42d392a33Andreas Huber * limitations under the License.
155bc087c573c70c84c6a39946457590b42d392a33Andreas Huber */
165bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
175bc087c573c70c84c6a39946457590b42d392a33Andreas Huber#ifndef NUPLAYER_SOURCE_H_
185bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
195bc087c573c70c84c6a39946457590b42d392a33Andreas Huber#define NUPLAYER_SOURCE_H_
205bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
215bc087c573c70c84c6a39946457590b42d392a33Andreas Huber#include "NuPlayer.h"
225bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
23b5f25f005bc1d3ae35f45b58c88345e183dc336dAndreas Huber#include <media/stagefright/foundation/AMessage.h>
24cc227036b05f7c2f960a89c567a61f9decefe742Lajos Molnar#include <media/stagefright/MetaData.h>
257c4f0d757bfeedaab4b7ef4ccf5b0a72ec8f4306Robert Shih#include <media/mediaplayer.h>
26cc227036b05f7c2f960a89c567a61f9decefe742Lajos Molnar#include <utils/Vector.h>
27b5f25f005bc1d3ae35f45b58c88345e183dc336dAndreas Huber
285bc087c573c70c84c6a39946457590b42d392a33Andreas Hubernamespace android {
295bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
305bc087c573c70c84c6a39946457590b42d392a33Andreas Huberstruct ABuffer;
31ee4e1b1a63758941460ae79a064249d3a5189443Lajos Molnarclass MediaBuffer;
325bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
33b5f25f005bc1d3ae35f45b58c88345e183dc336dAndreas Huberstruct NuPlayer::Source : public AHandler {
34b7c8e91880463ff4981e3e53e98e45d68e2fe374Andreas Huber    enum Flags {
359575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber        FLAG_CAN_PAUSE          = 1,
369575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber        FLAG_CAN_SEEK_BACKWARD  = 2,  // the "10 sec back button"
379575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber        FLAG_CAN_SEEK_FORWARD   = 4,  // the "10 sec forward button"
389575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber        FLAG_CAN_SEEK           = 8,  // the "seek bar"
399575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber        FLAG_DYNAMIC_DURATION   = 16,
40cc227036b05f7c2f960a89c567a61f9decefe742Lajos Molnar        FLAG_SECURE             = 32,
411713460104b86f6be3a5d9993d9ace864d889b2dChong Zhang        FLAG_PROTECTED          = 64,
429575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber    };
439575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber
449575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber    enum {
459575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber        kWhatPrepared,
469575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber        kWhatFlagsChanged,
479575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber        kWhatVideoSizeChanged,
482a3cc9a64330dd36e466fe5e1b634146f2d641c1Chong Zhang        kWhatBufferingUpdate,
49efbb61950db36a5eb789be83f077246172507c67Chong Zhang        kWhatPauseOnBufferingStart,
50efbb61950db36a5eb789be83f077246172507c67Chong Zhang        kWhatResumeOnBufferingEnd,
51efbb61950db36a5eb789be83f077246172507c67Chong Zhang        kWhatCacheStats,
52dcb89b3b505522efde173c105a851c412f947178Chong Zhang        kWhatSubtitleData,
53d3b0bbb8a37f90fba84eb4e95c58aa0fec6c51e7Robert Shih        kWhatTimedTextData,
540852843d304006e3ab333081fddda13b07193de8Robert Shih        kWhatTimedMetaData,
5514f7672b5d450ed26a06fd3bb3ce045ea78b11b2Andreas Huber        kWhatQueueDecoderShutdown,
56802768790c131f8237364906fd13981a6bb91193Ronghua Wu        kWhatDrmNoLicense,
57fcd3e94c075e964670d946f6ec5d82d059bf9e09Lajos Molnar        kWhatInstantiateSecureDecoders,
58b7c8e91880463ff4981e3e53e98e45d68e2fe374Andreas Huber    };
59b7c8e91880463ff4981e3e53e98e45d68e2fe374Andreas Huber
60b5f25f005bc1d3ae35f45b58c88345e183dc336dAndreas Huber    // The provides message is used to notify the player about various
61b5f25f005bc1d3ae35f45b58c88345e183dc336dAndreas Huber    // events.
62b5f25f005bc1d3ae35f45b58c88345e183dc336dAndreas Huber    Source(const sp<AMessage> &notify)
63b5f25f005bc1d3ae35f45b58c88345e183dc336dAndreas Huber        : mNotify(notify) {
64b5f25f005bc1d3ae35f45b58c88345e183dc336dAndreas Huber    }
655bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
669575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber    virtual void prepareAsync() = 0;
679575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber
685bc087c573c70c84c6a39946457590b42d392a33Andreas Huber    virtual void start() = 0;
692bfdd428c56c7524d1a11979f200a1762866032dAndreas Huber    virtual void stop() {}
70fba60daf77cc74a13ae3bf4b0e9925dd2ee4470cRoger Jönsson    virtual void pause() {}
71fba60daf77cc74a13ae3bf4b0e9925dd2ee4470cRoger Jönsson    virtual void resume() {}
725bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
7348296b792a8d68358de74141fa80bd5bd84d0307Chong Zhang    // Explicitly disconnect the underling data source
7448296b792a8d68358de74141fa80bd5bd84d0307Chong Zhang    virtual void disconnect() {}
7548296b792a8d68358de74141fa80bd5bd84d0307Chong Zhang
76eac68baf095aeef54865c28b6888924dc6295cbdAndreas Huber    // Returns OK iff more data was available,
77eac68baf095aeef54865c28b6888924dc6295cbdAndreas Huber    // an error or ERROR_END_OF_STREAM if not.
78eac68baf095aeef54865c28b6888924dc6295cbdAndreas Huber    virtual status_t feedMoreTSData() = 0;
795bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
80840667883fd09d44015716d79bc3ac4d60edc0f0Andreas Huber    virtual sp<AMessage> getFormat(bool audio);
81bc2fb720bbd0acd122bacc67e844e982d068f6f9Wei Jia    virtual sp<MetaData> getFormatMeta(bool /* audio */) { return NULL; }
82f0b72b509ab1147a2a0925aced970dd68fd7fa4fMarco Nelissen    virtual sp<MetaData> getFileFormatMeta() const { return NULL; }
835bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
845bc087c573c70c84c6a39946457590b42d392a33Andreas Huber    virtual status_t dequeueAccessUnit(
855bc087c573c70c84c6a39946457590b42d392a33Andreas Huber            bool audio, sp<ABuffer> *accessUnit) = 0;
865bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
8784333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber    virtual status_t getDuration(int64_t * /* durationUs */) {
8843c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber        return INVALID_OPERATION;
8943c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    }
9043c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber
91404fced9bfa8fa423ee210a271ca051ffd1bec13Chong Zhang    virtual size_t getTrackCount() const {
92404fced9bfa8fa423ee210a271ca051ffd1bec13Chong Zhang        return 0;
93404fced9bfa8fa423ee210a271ca051ffd1bec13Chong Zhang    }
94404fced9bfa8fa423ee210a271ca051ffd1bec13Chong Zhang
95404fced9bfa8fa423ee210a271ca051ffd1bec13Chong Zhang    virtual sp<AMessage> getTrackInfo(size_t /* trackIndex */) const {
96404fced9bfa8fa423ee210a271ca051ffd1bec13Chong Zhang        return NULL;
97dcb89b3b505522efde173c105a851c412f947178Chong Zhang    }
98dcb89b3b505522efde173c105a851c412f947178Chong Zhang
997c4f0d757bfeedaab4b7ef4ccf5b0a72ec8f4306Robert Shih    virtual ssize_t getSelectedTrack(media_track_type /* type */) const {
1007c4f0d757bfeedaab4b7ef4ccf5b0a72ec8f4306Robert Shih        return INVALID_OPERATION;
1017c4f0d757bfeedaab4b7ef4ccf5b0a72ec8f4306Robert Shih    }
1027c4f0d757bfeedaab4b7ef4ccf5b0a72ec8f4306Robert Shih
1036ffb1fd67eb8f00f130a6db914ba42a8432aec70Robert Shih    virtual status_t selectTrack(size_t /* trackIndex */, bool /* select */, int64_t /* timeUs*/) {
104dcb89b3b505522efde173c105a851c412f947178Chong Zhang        return INVALID_OPERATION;
105dcb89b3b505522efde173c105a851c412f947178Chong Zhang    }
106dcb89b3b505522efde173c105a851c412f947178Chong Zhang
10784333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber    virtual status_t seekTo(int64_t /* seekTimeUs */) {
10843c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber        return INVALID_OPERATION;
10943c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    }
11043c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber
111cc227036b05f7c2f960a89c567a61f9decefe742Lajos Molnar    virtual status_t setBuffers(bool /* audio */, Vector<MediaBuffer *> &/* buffers */) {
112cc227036b05f7c2f960a89c567a61f9decefe742Lajos Molnar        return INVALID_OPERATION;
113cc227036b05f7c2f960a89c567a61f9decefe742Lajos Molnar    }
114cc227036b05f7c2f960a89c567a61f9decefe742Lajos Molnar
115d5e56231a598b180a1d898bb7dc61b75580e59a4Andreas Huber    virtual bool isRealTime() const {
116d5e56231a598b180a1d898bb7dc61b75580e59a4Andreas Huber        return false;
117d5e56231a598b180a1d898bb7dc61b75580e59a4Andreas Huber    }
118d5e56231a598b180a1d898bb7dc61b75580e59a4Andreas Huber
11902cb98d726b97d8e6dbb9c6c60d32a3cedc7f82dRonghua Wu    virtual bool isStreaming() const {
12002cb98d726b97d8e6dbb9c6c60d32a3cedc7f82dRonghua Wu        return true;
12102cb98d726b97d8e6dbb9c6c60d32a3cedc7f82dRonghua Wu    }
12202cb98d726b97d8e6dbb9c6c60d32a3cedc7f82dRonghua Wu
12314532f2383c3849d0db59a607ed0bd802f57155cWei Jia    virtual void setOffloadAudio(bool /* offload */) {}
12414532f2383c3849d0db59a607ed0bd802f57155cWei Jia
1255bc087c573c70c84c6a39946457590b42d392a33Andreas Huberprotected:
1265bc087c573c70c84c6a39946457590b42d392a33Andreas Huber    virtual ~Source() {}
1275bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
128b5f25f005bc1d3ae35f45b58c88345e183dc336dAndreas Huber    virtual void onMessageReceived(const sp<AMessage> &msg);
129b5f25f005bc1d3ae35f45b58c88345e183dc336dAndreas Huber
130b5f25f005bc1d3ae35f45b58c88345e183dc336dAndreas Huber    sp<AMessage> dupNotify() const { return mNotify->dup(); }
131b5f25f005bc1d3ae35f45b58c88345e183dc336dAndreas Huber
1329575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber    void notifyFlagsChanged(uint32_t flags);
133ced1c2f8f6c422063092f5cc5c675ccdebb2dc10Chong Zhang    void notifyVideoSizeChanged(const sp<AMessage> &format = NULL);
134fcd3e94c075e964670d946f6ec5d82d059bf9e09Lajos Molnar    void notifyInstantiateSecureDecoders(const sp<AMessage> &reply);
135ec0c597cabf169ca646bcea5faac1bd81ed4484dAndreas Huber    void notifyPrepared(status_t err = OK);
1369575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber
1375bc087c573c70c84c6a39946457590b42d392a33Andreas Huberprivate:
138b5f25f005bc1d3ae35f45b58c88345e183dc336dAndreas Huber    sp<AMessage> mNotify;
139b5f25f005bc1d3ae35f45b58c88345e183dc336dAndreas Huber
1405bc087c573c70c84c6a39946457590b42d392a33Andreas Huber    DISALLOW_EVIL_CONSTRUCTORS(Source);
1415bc087c573c70c84c6a39946457590b42d392a33Andreas Huber};
1425bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
1435bc087c573c70c84c6a39946457590b42d392a33Andreas Huber}  // namespace android
1445bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
1455bc087c573c70c84c6a39946457590b42d392a33Andreas Huber#endif  // NUPLAYER_SOURCE_H_
1465bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
147