Home | History | Annotate | Download | only in nuplayer
      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 
     28 namespace android {
     29 
     30 struct ABuffer;
     31 struct MetaData;
     32 struct MediaBuffer;
     33 
     34 struct 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         kWhatBufferingUpdate,
     49         kWhatBufferingStart,
     50         kWhatBufferingEnd,
     51         kWhatSubtitleData,
     52         kWhatTimedTextData,
     53         kWhatQueueDecoderShutdown,
     54         kWhatDrmNoLicense,
     55     };
     56 
     57     // The provides message is used to notify the player about various
     58     // events.
     59     Source(const sp<AMessage> &notify)
     60         : mNotify(notify) {
     61     }
     62 
     63     virtual void prepareAsync() = 0;
     64 
     65     virtual void start() = 0;
     66     virtual void stop() {}
     67     virtual void pause() {}
     68     virtual void resume() {}
     69 
     70     // Explicitly disconnect the underling data source
     71     virtual void disconnect() {}
     72 
     73     // Returns OK iff more data was available,
     74     // an error or ERROR_END_OF_STREAM if not.
     75     virtual status_t feedMoreTSData() = 0;
     76 
     77     virtual sp<AMessage> getFormat(bool audio);
     78     virtual sp<MetaData> getFormatMeta(bool /* audio */) { return NULL; }
     79     virtual sp<MetaData> getFileFormatMeta() const { return NULL; }
     80 
     81     virtual status_t dequeueAccessUnit(
     82             bool audio, sp<ABuffer> *accessUnit) = 0;
     83 
     84     virtual status_t getDuration(int64_t * /* durationUs */) {
     85         return INVALID_OPERATION;
     86     }
     87 
     88     virtual size_t getTrackCount() const {
     89         return 0;
     90     }
     91 
     92     virtual sp<AMessage> getTrackInfo(size_t /* trackIndex */) const {
     93         return NULL;
     94     }
     95 
     96     virtual ssize_t getSelectedTrack(media_track_type /* type */) const {
     97         return INVALID_OPERATION;
     98     }
     99 
    100     virtual status_t selectTrack(size_t /* trackIndex */, bool /* select */) {
    101         return INVALID_OPERATION;
    102     }
    103 
    104     virtual status_t seekTo(int64_t /* seekTimeUs */) {
    105         return INVALID_OPERATION;
    106     }
    107 
    108     virtual status_t setBuffers(bool /* audio */, Vector<MediaBuffer *> &/* buffers */) {
    109         return INVALID_OPERATION;
    110     }
    111 
    112     virtual bool isRealTime() const {
    113         return false;
    114     }
    115 
    116 protected:
    117     virtual ~Source() {}
    118 
    119     virtual void onMessageReceived(const sp<AMessage> &msg);
    120 
    121     sp<AMessage> dupNotify() const { return mNotify->dup(); }
    122 
    123     void notifyFlagsChanged(uint32_t flags);
    124     void notifyVideoSizeChanged(const sp<AMessage> &format = NULL);
    125     void notifyPrepared(status_t err = OK);
    126 
    127 private:
    128     sp<AMessage> mNotify;
    129 
    130     DISALLOW_EVIL_CONSTRUCTORS(Source);
    131 };
    132 
    133 }  // namespace android
    134 
    135 #endif  // NUPLAYER_SOURCE_H_
    136 
    137