blob: 37b82309e5a47ab75d73067be5ca3acf467c674b [file] [log] [blame]
Chong Zhang7137ec72014-11-12 16:41:05 -08001/*
2 * Copyright 2014 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_CCDECODER_H_
18
19#define NUPLAYER_CCDECODER_H_
20
21#include "NuPlayer.h"
22
23namespace android {
24
25struct NuPlayer::CCDecoder : public RefBase {
26 enum {
27 kWhatClosedCaptionData,
28 kWhatTrackAdded,
29 };
30
Jaesung Chung3694d7c2015-10-21 11:41:38 +090031 enum {
32 kTrackTypeCEA608,
33 kTrackTypeCEA708,
34 };
35
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -070036 explicit CCDecoder(const sp<AMessage> &notify);
Chong Zhang7137ec72014-11-12 16:41:05 -080037
38 size_t getTrackCount() const;
39 sp<AMessage> getTrackInfo(size_t index) const;
40 status_t selectTrack(size_t index, bool select);
Wei Jia039224f2018-11-29 17:25:17 -080041 ssize_t getSelectedTrack(media_track_type type) const;
Chong Zhang7137ec72014-11-12 16:41:05 -080042 bool isSelected() const;
43 void decode(const sp<ABuffer> &accessUnit);
44 void display(int64_t timeUs);
45 void flush();
46
47private:
Jaesung Chung3694d7c2015-10-21 11:41:38 +090048 // CC track identifier.
49 struct CCTrack {
50 CCTrack() : mTrackType(0), mTrackChannel(0) { }
51
52 CCTrack(const int32_t trackType, const size_t trackChannel)
53 : mTrackType(trackType), mTrackChannel(trackChannel) { }
54
55 int32_t mTrackType;
56 size_t mTrackChannel;
57
58 // The ordering of CCTracks is to build a map of track to index.
59 // It is necessary to find the index of the matched CCTrack when CC data comes.
60 int compare(const NuPlayer::CCDecoder::CCTrack& rhs) const;
61 inline bool operator<(const NuPlayer::CCDecoder::CCTrack& rhs) const;
62 inline bool operator==(const NuPlayer::CCDecoder::CCTrack& rhs) const;
63 inline bool operator!=(const NuPlayer::CCDecoder::CCTrack& rhs) const;
64 };
65
Chong Zhang7137ec72014-11-12 16:41:05 -080066 sp<AMessage> mNotify;
67 KeyedVector<int64_t, sp<ABuffer> > mCCMap;
Jaesung Chung3694d7c2015-10-21 11:41:38 +090068 ssize_t mSelectedTrack;
69 KeyedVector<CCTrack, size_t> mTrackIndices;
70 Vector<CCTrack> mTracks;
71
72 // CEA-608 closed caption
73 size_t mLine21Channels[2]; // The current channels of NTSC_CC_FIELD_{1, 2}
74
75 // CEA-708 closed caption
76 sp<ABuffer> mDTVCCPacket;
Chong Zhang7137ec72014-11-12 16:41:05 -080077
78 bool isTrackValid(size_t index) const;
Jaesung Chung3694d7c2015-10-21 11:41:38 +090079 size_t getTrackIndex(int32_t trackType, size_t channel, bool *trackAdded);
80
81 // Extract from H.264 SEIs
Chong Zhang7137ec72014-11-12 16:41:05 -080082 bool extractFromSEI(const sp<ABuffer> &accessUnit);
Jaesung Chung3694d7c2015-10-21 11:41:38 +090083 bool parseSEINalUnit(int64_t timeUs, const uint8_t *data, size_t size);
84
85 // Extract from MPEG user data
86 bool extractFromMPEGUserData(const sp<ABuffer> &accessUnit);
87 bool parseMPEGUserDataUnit(int64_t timeUs, const uint8_t *data, size_t size);
88
89 // Extract CC tracks from MPEG_cc_data
90 bool parseMPEGCCData(int64_t timeUs, const uint8_t *data, size_t size);
91 bool parseDTVCCPacket(int64_t timeUs, const uint8_t *data, size_t size);
Chong Zhang7137ec72014-11-12 16:41:05 -080092
93 DISALLOW_EVIL_CONSTRUCTORS(CCDecoder);
94};
95
96} // namespace android
97
98#endif // NUPLAYER_CCDECODER_H_