Home | History | Annotate | Download | only in nuplayer2
      1 /*
      2  * Copyright 2017 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 NUPLAYER2_SOURCE_H_
     18 
     19 #define NUPLAYER2_SOURCE_H_
     20 
     21 #include "NuPlayer2.h"
     22 
     23 #include <media/stagefright/foundation/AMessage.h>
     24 #include <media/stagefright/MetaData.h>
     25 #include <mediaplayer2/mediaplayer2.h>
     26 #include <utils/Vector.h>
     27 
     28 namespace android {
     29 
     30 struct ABuffer;
     31 struct AMediaCryptoWrapper;
     32 class MediaBuffer;
     33 
     34 struct NuPlayer2::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, // Secure codec is required.
     42         FLAG_PROTECTED          = 64, // The screen needs to be protected (screenshot is disabled).
     43     };
     44 
     45     enum {
     46         kWhatPrepared,
     47         kWhatFlagsChanged,
     48         kWhatVideoSizeChanged,
     49         kWhatBufferingUpdate,
     50         kWhatPauseOnBufferingStart,
     51         kWhatResumeOnBufferingEnd,
     52         kWhatCacheStats,
     53         kWhatSubtitleData,
     54         kWhatTimedTextData,
     55         kWhatTimedMetaData,
     56         kWhatQueueDecoderShutdown,
     57         kWhatDrmNoLicense,
     58         // Modular DRM
     59         kWhatDrmInfo,
     60     };
     61 
     62     // The provides message is used to notify the player about various
     63     // events.
     64     explicit Source(const sp<AMessage> &notify)
     65         : mNotify(notify) {
     66     }
     67 
     68     virtual status_t getBufferingSettings(
     69             BufferingSettings* buffering /* nonnull */) = 0;
     70     virtual status_t setBufferingSettings(const BufferingSettings& buffering) = 0;
     71 
     72     virtual void prepareAsync() = 0;
     73 
     74     virtual void start() = 0;
     75     virtual void stop() {}
     76     virtual void pause() {}
     77     virtual void resume() {}
     78 
     79     // Explicitly disconnect the underling data source
     80     virtual void disconnect() {}
     81 
     82     // Returns OK iff more data was available,
     83     // an error or ERROR_END_OF_STREAM if not.
     84     virtual status_t feedMoreTSData() = 0;
     85 
     86     // Returns non-NULL format when the specified track exists.
     87     // When the format has "err" set to -EWOULDBLOCK, source needs more time to get valid meta data.
     88     // Returns NULL if the specified track doesn't exist or is invalid;
     89     virtual sp<AMessage> getFormat(bool audio);
     90 
     91     virtual sp<MetaData> getFormatMeta(bool /* audio */) { return NULL; }
     92     virtual sp<MetaData> getFileFormatMeta() const { return NULL; }
     93 
     94     virtual status_t dequeueAccessUnit(
     95             bool audio, sp<ABuffer> *accessUnit) = 0;
     96 
     97     virtual status_t getDuration(int64_t * /* durationUs */) {
     98         return INVALID_OPERATION;
     99     }
    100 
    101     virtual size_t getTrackCount() const {
    102         return 0;
    103     }
    104 
    105     virtual sp<AMessage> getTrackInfo(size_t /* trackIndex */) const {
    106         return NULL;
    107     }
    108 
    109     virtual ssize_t getSelectedTrack(media_track_type /* type */) const {
    110         return INVALID_OPERATION;
    111     }
    112 
    113     virtual status_t selectTrack(size_t /* trackIndex */, bool /* select */, int64_t /* timeUs*/) {
    114         return INVALID_OPERATION;
    115     }
    116 
    117     virtual status_t seekTo(
    118             int64_t /* seekTimeUs */,
    119             MediaPlayer2SeekMode /* mode */ = MediaPlayer2SeekMode::SEEK_PREVIOUS_SYNC) {
    120         return INVALID_OPERATION;
    121     }
    122 
    123     virtual bool isRealTime() const {
    124         return false;
    125     }
    126 
    127     virtual bool isStreaming() const {
    128         return true;
    129     }
    130 
    131     virtual void setOffloadAudio(bool /* offload */) {}
    132 
    133     // Modular DRM
    134     virtual status_t prepareDrm(
    135             const uint8_t /* uuid */[16], const Vector<uint8_t> & /* drmSessionId */,
    136             sp<AMediaCryptoWrapper> * /* crypto */) {
    137         return INVALID_OPERATION;
    138     }
    139 
    140     virtual status_t releaseDrm() {
    141         return INVALID_OPERATION;
    142     }
    143 
    144 protected:
    145     virtual ~Source() {}
    146 
    147     virtual void onMessageReceived(const sp<AMessage> &msg);
    148 
    149     sp<AMessage> dupNotify() const { return mNotify->dup(); }
    150 
    151     void notifyFlagsChanged(uint32_t flags);
    152     void notifyVideoSizeChanged(const sp<AMessage> &format = NULL);
    153     void notifyPrepared(status_t err = OK);
    154     // Modular DRM
    155     void notifyDrmInfo(const sp<ABuffer> &buffer);
    156 
    157 private:
    158     sp<AMessage> mNotify;
    159 
    160     DISALLOW_EVIL_CONSTRUCTORS(Source);
    161 };
    162 
    163 }  // namespace android
    164 
    165 #endif  // NUPLAYER2_SOURCE_H_
    166 
    167