Home | History | Annotate | Download | only in timedtext
      1 /*
      2  * Copyright (C) 2012 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 TIMEDTEXT_PLAYER_H_
     18 #define TIMEDTEXT_PLAYER_H_
     19 
     20 #include <binder/Parcel.h>
     21 #include <media/stagefright/foundation/ABase.h>
     22 #include <media/stagefright/foundation/AHandler.h>
     23 #include <media/stagefright/MediaSource.h>
     24 #include <utils/RefBase.h>
     25 
     26 #include "TimedTextSource.h"
     27 
     28 namespace android {
     29 
     30 class AMessage;
     31 class MediaPlayerBase;
     32 class TimedTextDriver;
     33 class TimedTextSource;
     34 
     35 class TimedTextPlayer : public AHandler {
     36 public:
     37     TimedTextPlayer(const wp<MediaPlayerBase> &listener);
     38 
     39     virtual ~TimedTextPlayer();
     40 
     41     void start();
     42     void pause();
     43     void resume();
     44     void seekToAsync(int64_t timeUs);
     45     void setDataSource(sp<TimedTextSource> source);
     46 
     47 protected:
     48     virtual void onMessageReceived(const sp<AMessage> &msg);
     49 
     50 private:
     51     enum {
     52         kWhatPause = 'paus',
     53         kWhatResume = 'resm',
     54         kWhatStart = 'strt',
     55         kWhatSeek = 'seek',
     56         kWhatRetryRead = 'read',
     57         kWhatSendSubtitle = 'send',
     58         kWhatSetSource = 'ssrc',
     59     };
     60 
     61     // To add Parcel into an AMessage as an object, it should be 'RefBase'.
     62     struct ParcelEvent : public RefBase {
     63         Parcel parcel;
     64     };
     65 
     66     wp<MediaPlayerBase> mListener;
     67     sp<TimedTextSource> mSource;
     68     int64_t mPendingSeekTimeUs;
     69     bool mPaused;
     70     int32_t mSendSubtitleGeneration;
     71 
     72     void doSeekAndRead(int64_t seekTimeUs);
     73     void doRead(MediaSource::ReadOptions* options = NULL);
     74     void onTextEvent();
     75     void postTextEvent(const sp<ParcelEvent>& parcel = NULL, int64_t timeUs = -1);
     76     int64_t delayUsFromCurrentTime(int64_t fireTimeUs);
     77     void notifyError(int error = 0);
     78     void notifyListener(const Parcel *parcel = NULL);
     79 
     80     DISALLOW_EVIL_CONSTRUCTORS(TimedTextPlayer);
     81 };
     82 
     83 }  // namespace android
     84 
     85 #endif  // TIMEDTEXT_PLAYER_H_
     86