HTTPLiveSource2.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 HTTP_LIVE_SOURCE2_H_
  17. #define HTTP_LIVE_SOURCE2_H_
  18. #include "NuPlayer2.h"
  19. #include "NuPlayer2Source.h"
  20. #include "LiveSession.h"
  21. namespace android {
  22. struct LiveSession;
  23. struct NuPlayer2::HTTPLiveSource2 : public NuPlayer2::Source {
  24. HTTPLiveSource2(
  25. const sp<AMessage> &notify,
  26. const sp<MediaHTTPService> &httpService,
  27. const char *url,
  28. const KeyedVector<String8, String8> *headers);
  29. virtual status_t getBufferingSettings(
  30. BufferingSettings* buffering /* nonnull */) override;
  31. virtual status_t setBufferingSettings(const BufferingSettings& buffering) override;
  32. virtual void prepareAsync(int64_t startTimeUs);
  33. virtual void start();
  34. virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
  35. virtual sp<MetaData> getFormatMeta(bool audio);
  36. virtual sp<AMessage> getFormat(bool audio);
  37. virtual status_t feedMoreTSData();
  38. virtual status_t getDuration(int64_t *durationUs);
  39. virtual size_t getTrackCount() const;
  40. virtual sp<AMessage> getTrackInfo(size_t trackIndex) const;
  41. virtual ssize_t getSelectedTrack(media_track_type /* type */) const;
  42. virtual status_t selectTrack(size_t trackIndex, bool select, int64_t timeUs);
  43. virtual status_t seekTo(
  44. int64_t seekTimeUs,
  45. MediaPlayer2SeekMode mode = MediaPlayer2SeekMode::SEEK_PREVIOUS_SYNC) override;
  46. protected:
  47. virtual ~HTTPLiveSource2();
  48. virtual void onMessageReceived(const sp<AMessage> &msg);
  49. private:
  50. enum Flags {
  51. // Don't log any URLs.
  52. kFlagIncognito = 1,
  53. };
  54. enum {
  55. kWhatSessionNotify,
  56. kWhatFetchSubtitleData,
  57. kWhatFetchMetaData,
  58. };
  59. sp<MediaHTTPService> mHTTPService;
  60. AString mURL;
  61. KeyedVector<String8, String8> mExtraHeaders;
  62. uint32_t mFlags;
  63. status_t mFinalResult;
  64. off64_t mOffset;
  65. sp<ALooper> mLiveLooper;
  66. sp<LiveSession> mLiveSession;
  67. int32_t mFetchSubtitleDataGeneration;
  68. int32_t mFetchMetaDataGeneration;
  69. bool mHasMetadata;
  70. bool mMetadataSelected;
  71. BufferingSettings mBufferingSettings;
  72. void onSessionNotify(const sp<AMessage> &msg);
  73. void pollForRawData(
  74. const sp<AMessage> &msg, int32_t currentGeneration,
  75. LiveSession::StreamType fetchType, int32_t pushWhat);
  76. DISALLOW_EVIL_CONSTRUCTORS(HTTPLiveSource2);
  77. };
  78. } // namespace android
  79. #endif // HTTP_LIVE_SOURCE2_H_