RTSPSource2.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 RTSP_SOURCE2_H_
  17. #define RTSP_SOURCE2_H_
  18. #include "NuPlayer2Source.h"
  19. #include "ATSParser.h"
  20. namespace android {
  21. struct ALooper;
  22. struct AReplyToken;
  23. struct AnotherPacketSource;
  24. struct MyHandler;
  25. struct SDPLoader;
  26. struct NuPlayer2::RTSPSource2 : public NuPlayer2::Source {
  27. RTSPSource2(
  28. const sp<AMessage> &notify,
  29. const sp<MediaHTTPService> &httpService,
  30. const char *url,
  31. const KeyedVector<String8, String8> *headers,
  32. uid_t uid = 0,
  33. bool isSDP = false);
  34. virtual status_t getBufferingSettings(
  35. BufferingSettings* buffering /* nonnull */) override;
  36. virtual status_t setBufferingSettings(const BufferingSettings& buffering) override;
  37. virtual void prepareAsync(int64_t startTimeUs);
  38. virtual void start();
  39. virtual void stop();
  40. virtual status_t feedMoreTSData();
  41. virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
  42. virtual status_t getDuration(int64_t *durationUs);
  43. virtual status_t seekTo(
  44. int64_t seekTimeUs,
  45. MediaPlayer2SeekMode mode = MediaPlayer2SeekMode::SEEK_PREVIOUS_SYNC) override;
  46. void onMessageReceived(const sp<AMessage> &msg);
  47. protected:
  48. virtual ~RTSPSource2();
  49. virtual sp<MetaData> getFormatMeta(bool audio);
  50. private:
  51. enum {
  52. kWhatNotify = 'noti',
  53. kWhatDisconnect = 'disc',
  54. kWhatPerformSeek = 'seek',
  55. kWhatPollBuffering = 'poll',
  56. kWhatSignalEOS = 'eos ',
  57. };
  58. enum State {
  59. DISCONNECTED,
  60. CONNECTING,
  61. CONNECTED,
  62. SEEKING,
  63. };
  64. enum Flags {
  65. // Don't log any URLs.
  66. kFlagIncognito = 1,
  67. };
  68. struct TrackInfo {
  69. sp<AnotherPacketSource> mSource;
  70. int32_t mTimeScale;
  71. uint32_t mRTPTime;
  72. int64_t mNormalPlaytimeUs;
  73. bool mNPTMappingValid;
  74. };
  75. sp<MediaHTTPService> mHTTPService;
  76. AString mURL;
  77. KeyedVector<String8, String8> mExtraHeaders;
  78. uid_t mUID;
  79. uint32_t mFlags;
  80. bool mIsSDP;
  81. State mState;
  82. status_t mFinalResult;
  83. sp<AReplyToken> mDisconnectReplyID;
  84. Mutex mBufferingLock;
  85. bool mBuffering;
  86. bool mInPreparationPhase;
  87. bool mEOSPending;
  88. Mutex mBufferingSettingsLock;
  89. BufferingSettings mBufferingSettings;
  90. sp<ALooper> mLooper;
  91. sp<MyHandler> mHandler;
  92. sp<SDPLoader> mSDPLoader;
  93. Vector<TrackInfo> mTracks;
  94. sp<AnotherPacketSource> mAudioTrack;
  95. sp<AnotherPacketSource> mVideoTrack;
  96. sp<ATSParser> mTSParser;
  97. int32_t mSeekGeneration;
  98. int64_t mEOSTimeoutAudio;
  99. int64_t mEOSTimeoutVideo;
  100. sp<AReplyToken> mSeekReplyID;
  101. sp<AnotherPacketSource> getSource(bool audio);
  102. void onConnected();
  103. void onSDPLoaded(const sp<AMessage> &msg);
  104. void onDisconnected(const sp<AMessage> &msg);
  105. void finishDisconnectIfPossible();
  106. void performSeek(int64_t seekTimeUs);
  107. void schedulePollBuffering();
  108. void checkBuffering(
  109. bool *prepared,
  110. bool *underflow,
  111. bool *overflow,
  112. bool *startServer,
  113. bool *finished);
  114. void onPollBuffering();
  115. bool haveSufficientDataOnAllTracks();
  116. void setEOSTimeout(bool audio, int64_t timeout);
  117. void setError(status_t err);
  118. void startBufferingIfNecessary();
  119. bool stopBufferingIfNecessary();
  120. void finishSeek(status_t err);
  121. void postSourceEOSIfNecessary();
  122. void signalSourceEOS(status_t result);
  123. void onSignalEOS(const sp<AMessage> &msg);
  124. bool sourceNearEOS(bool audio);
  125. bool sourceReachedEOS(bool audio);
  126. DISALLOW_EVIL_CONSTRUCTORS(RTSPSource2);
  127. };
  128. } // namespace android
  129. #endif // RTSP_SOURCE2_H_