TimedTextSRTSource.h revision 6655174826330afe66ef766258181ae8c11f3f6c
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
26namespace android {
27
28class AString;
29class DataSource;
30class MediaBuffer;
31class Parcel;
32
33class 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 *timeUs,
40          Parcel *parcel,
41          const MediaSource::ReadOptions *options = NULL);
42
43 protected:
44  virtual ~TimedTextSRTSource();
45
46 private:
47  sp<DataSource> mSource;
48
49  struct TextInfo {
50      int64_t endTimeUs;
51      // The offset of the text in the original file.
52      off64_t offset;
53      int textLen;
54  };
55
56  int mIndex;
57  KeyedVector<int64_t, TextInfo> mTextVector;
58
59  void reset();
60  status_t scanFile();
61  status_t getNextSubtitleInfo(
62          off64_t *offset, int64_t *startTimeUs, TextInfo *info);
63  status_t readNextLine(off64_t *offset, AString *data);
64  status_t getText(
65          const MediaSource::ReadOptions *options,
66          AString *text, int64_t *startTimeUs, int64_t *endTimeUs);
67  status_t extractAndAppendLocalDescriptions(
68          int64_t timeUs, const AString &text, Parcel *parcel);
69
70  DISALLOW_EVIL_CONSTRUCTORS(TimedTextSRTSource);
71};
72
73}  // namespace android
74
75#endif  // TIMED_TEXT_SRT_SOURCE_H_
76