NuPlayer2CCDecoder.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #ifndef NUPLAYER2_CCDECODER_H_
  17. #define NUPLAYER2_CCDECODER_H_
  18. #include "NuPlayer2.h"
  19. namespace android {
  20. struct NuPlayer2::CCDecoder : public RefBase {
  21. enum {
  22. kWhatClosedCaptionData,
  23. kWhatTrackAdded,
  24. };
  25. enum {
  26. kTrackTypeCEA608,
  27. kTrackTypeCEA708,
  28. };
  29. explicit CCDecoder(const sp<AMessage> &notify);
  30. size_t getTrackCount() const;
  31. sp<AMessage> getTrackInfo(size_t index) const;
  32. status_t selectTrack(size_t index, bool select);
  33. ssize_t getSelectedTrack(media_track_type type) const;
  34. bool isSelected() const;
  35. void decode(const sp<ABuffer> &accessUnit);
  36. void display(int64_t timeUs);
  37. void flush();
  38. private:
  39. // CC track identifier.
  40. struct CCTrack {
  41. CCTrack() : mTrackType(0), mTrackChannel(0) { }
  42. CCTrack(const int32_t trackType, const size_t trackChannel)
  43. : mTrackType(trackType), mTrackChannel(trackChannel) { }
  44. int32_t mTrackType;
  45. size_t mTrackChannel;
  46. // The ordering of CCTracks is to build a map of track to index.
  47. // It is necessary to find the index of the matched CCTrack when CC data comes.
  48. int compare(const NuPlayer2::CCDecoder::CCTrack& rhs) const;
  49. inline bool operator<(const NuPlayer2::CCDecoder::CCTrack& rhs) const;
  50. inline bool operator==(const NuPlayer2::CCDecoder::CCTrack& rhs) const;
  51. inline bool operator!=(const NuPlayer2::CCDecoder::CCTrack& rhs) const;
  52. };
  53. sp<AMessage> mNotify;
  54. KeyedVector<int64_t, sp<ABuffer> > mCCMap;
  55. ssize_t mSelectedTrack;
  56. KeyedVector<CCTrack, size_t> mTrackIndices;
  57. Vector<CCTrack> mTracks;
  58. // CEA-608 closed caption
  59. size_t mLine21Channels[2]; // The current channels of NTSC_CC_FIELD_{1, 2}
  60. // CEA-708 closed caption
  61. sp<ABuffer> mDTVCCPacket;
  62. bool isTrackValid(size_t index) const;
  63. size_t getTrackIndex(int32_t trackType, size_t channel, bool *trackAdded);
  64. // Extract from H.264 SEIs
  65. bool extractFromSEI(const sp<ABuffer> &accessUnit);
  66. bool parseSEINalUnit(int64_t timeUs, const uint8_t *data, size_t size);
  67. // Extract from MPEG user data
  68. bool extractFromMPEGUserData(const sp<ABuffer> &accessUnit);
  69. bool parseMPEGUserDataUnit(int64_t timeUs, const uint8_t *data, size_t size);
  70. // Extract CC tracks from MPEG_cc_data
  71. bool parseMPEGCCData(int64_t timeUs, const uint8_t *data, size_t size);
  72. bool parseDTVCCPacket(int64_t timeUs, const uint8_t *data, size_t size);
  73. DISALLOW_EVIL_CONSTRUCTORS(CCDecoder);
  74. };
  75. } // namespace android
  76. #endif // NUPLAYER2_CCDECODER_H_