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 class MediaBuffer;
     32 
     33 struct NuPlayer::Source : public AHandler {
     34     enum Flags {
     35         FLAG_CAN_PAUSE          = 1,
     36         FLAG_CAN_SEEK_BACKWARD  = 2,  // the "10 sec back button"
     37         FLAG_CAN_SEEK_FORWARD   = 4,  // the "10 sec forward button"
     38         FLAG_CAN_SEEK           = 8,  // the "seek bar"
     39         FLAG_DYNAMIC_DURATION   = 16,
     40         FLAG_SECURE             = 32,
     41         FLAG_PROTECTED          = 64,
     42     };
     43 
     44     enum {
     45         kWhatPrepared,
     46         kWhatFlagsChanged,
     47         kWhatVideoSizeChanged,
     48         kWhatBufferingUpdate,
     49         kWhatBufferingStart,
     50         kWhatBufferingEnd,
     51         kWhatPauseOnBufferingStart,
     52         kWhatResumeOnBufferingEnd,
     53         kWhatCacheStats,
     54         kWhatSubtitleData,
     55         kWhatTimedTextData,
     56         kWhatTimedMetaData,
     57         kWhatQueueDecoderShutdown,
     58         kWhatDrmNoLicense,
     59         kWhatInstantiateSecureDecoders,
     60     };
     61 
     62     // The provides message is used to notify the player about various
     63     // events.
     64     Source(const sp<AMessage> &notify)
     65         : mNotify(notify) {
     66     }
     67 
     68     virtual void prepareAsync() = 0;
     69 
     70     virtual void start() = 0;
     71     virtual void stop() {}
     72     virtual void pause() {}
     73     virtual void resume() {}
     74 
     75     // Explicitly disconnect the underling data source
     76     virtual void disconnect() {}
     77 
     78     // Returns OK iff more data was available,
     79     // an error or ERROR_END_OF_STREAM if not.
     80     virtual status_t feedMoreTSData() = 0;
     81 
     82     virtual sp<AMessage> getFormat(bool audio);
     83     virtual sp<MetaData> getFormatMeta(bool /* audio */) { return NULL; }
     84     virtual sp<MetaData> getFileFormatMeta() const { return NULL; }
     85 
     86     virtual status_t dequeueAccessUnit(
     87             bool audio, sp<ABuffer> *accessUnit) = 0;
     88 
     89     virtual status_t getDuration(int64_t * /* durationUs */) {
     90         return INVALID_OPERATION;
     91     }
     92 
     93     virtual size_t getTrackCount() const {
     94         return 0;
     95     }
     96 
     97     virtual sp<AMessage> getTrackInfo(size_t /* trackIndex */) const {
     98         return NULL;
     99     }
    100 
    101     virtual ssize_t getSelectedTrack(media_track_type /* type */) const {
    102         return INVALID_OPERATION;
    103     }
    104 
    105     virtual status_t selectTrack(size_t /* trackIndex */, bool /* select */, int64_t /* timeUs*/) {
    106         return INVALID_OPERATION;
    107     }
    108 
    109     virtual status_t seekTo(int64_t /* seekTimeUs */) {
    110         return INVALID_OPERATION;
    111     }
    112 
    113     virtual status_t setBuffers(bool /* audio */, Vector<MediaBuffer *> &/* buffers */) {
    114         return INVALID_OPERATION;
    115     }
    116 
    117     virtual bool isRealTime() const {
    118         return false;
    119     }
    120 
    121     virtual bool isStreaming() const {
    122         return true;
    123     }
    124 
    125 protected:
    126     virtual ~Source() {}
    127 
    128     virtual void onMessageReceived(const sp<AMessage> &msg);
    129 
    130     sp<AMessage> dupNotify() const { return mNotify->dup(); }
    131 
    132     void notifyFlagsChanged(uint32_t flags);
    133     void notifyVideoSizeChanged(const sp<AMessage> &format = NULL);
    134     void notifyInstantiateSecureDecoders(const sp<AMessage> &reply);
    135     void notifyPrepared(status_t err = OK);
    136 
    137 private:
    138     sp<AMessage> mNotify;
    139 
    140     DISALLOW_EVIL_CONSTRUCTORS(Source);
    141 };
    142 
    143 }  // namespace android
    144 
    145 #endif  // NUPLAYER_SOURCE_H_
    146 
    147