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 TIMED_TEXT_SRT_SOURCE_H_
     18 #define TIMED_TEXT_SRT_SOURCE_H_
     19 
     20 #include <media/stagefright/MediaErrors.h>
     21 #include <media/stagefright/MediaSource.h>
     22 #include <utils/Compat.h>  // off64_t
     23 
     24 #include "TimedTextSource.h"
     25 
     26 namespace android {
     27 
     28 class AString;
     29 class DataSource;
     30 class MediaBuffer;
     31 class Parcel;
     32 
     33 class TimedTextSRTSource : public TimedTextSource {
     34 public:
     35     TimedTextSRTSource(const sp<DataSource>& dataSource);
     36     virtual status_t start();
     37     virtual status_t stop();
     38     virtual status_t read(
     39             int64_t *startTimeUs,
     40             int64_t *endTimeUs,
     41             Parcel *parcel,
     42             const MediaSource::ReadOptions *options = NULL);
     43     virtual sp<MetaData> getFormat();
     44 
     45 protected:
     46     virtual ~TimedTextSRTSource();
     47 
     48 private:
     49     sp<DataSource> mSource;
     50     sp<MetaData> mMetaData;
     51 
     52     struct TextInfo {
     53         int64_t endTimeUs;
     54         // The offset of the text in the original file.
     55         off64_t offset;
     56         int textLen;
     57     };
     58 
     59     size_t mIndex;
     60     KeyedVector<int64_t, TextInfo> mTextVector;
     61 
     62     void reset();
     63     status_t scanFile();
     64     status_t getNextSubtitleInfo(
     65             off64_t *offset, int64_t *startTimeUs, TextInfo *info);
     66     status_t readNextLine(off64_t *offset, AString *data);
     67     status_t getText(
     68             const MediaSource::ReadOptions *options,
     69             AString *text, int64_t *startTimeUs, int64_t *endTimeUs);
     70     status_t extractAndAppendLocalDescriptions(
     71             int64_t timeUs, const AString &text, Parcel *parcel);
     72 
     73     DISALLOW_EVIL_CONSTRUCTORS(TimedTextSRTSource);
     74 };
     75 
     76 }  // namespace android
     77 
     78 #endif  // TIMED_TEXT_SRT_SOURCE_H_
     79