NuPlayer2Source.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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_SOURCE_H_
  17. #define NUPLAYER2_SOURCE_H_
  18. #include "NuPlayer2.h"
  19. #include <media/stagefright/foundation/AMessage.h>
  20. #include <media/stagefright/MetaData.h>
  21. #include <mediaplayer2/mediaplayer2.h>
  22. #include <utils/Vector.h>
  23. namespace android {
  24. struct ABuffer;
  25. struct AMediaCryptoWrapper;
  26. class MediaBuffer;
  27. struct NuPlayer2::Source : public AHandler {
  28. enum Flags {
  29. FLAG_CAN_PAUSE = 1,
  30. FLAG_CAN_SEEK_BACKWARD = 2, // the "10 sec back button"
  31. FLAG_CAN_SEEK_FORWARD = 4, // the "10 sec forward button"
  32. FLAG_CAN_SEEK = 8, // the "seek bar"
  33. FLAG_DYNAMIC_DURATION = 16,
  34. FLAG_SECURE = 32, // Secure codec is required.
  35. FLAG_PROTECTED = 64, // The screen needs to be protected (screenshot is disabled).
  36. };
  37. enum {
  38. kWhatPrepared,
  39. kWhatFlagsChanged,
  40. kWhatVideoSizeChanged,
  41. kWhatBufferingUpdate,
  42. kWhatPauseOnBufferingStart,
  43. kWhatResumeOnBufferingEnd,
  44. kWhatCacheStats,
  45. kWhatSubtitleData,
  46. kWhatTimedTextData,
  47. kWhatTimedMetaData,
  48. kWhatQueueDecoderShutdown,
  49. kWhatDrmNoLicense,
  50. // Modular DRM
  51. kWhatDrmInfo,
  52. };
  53. // The provides message is used to notify the player about various
  54. // events.
  55. explicit Source(const sp<AMessage> &notify)
  56. : mNotify(notify) {
  57. }
  58. virtual status_t getBufferingSettings(
  59. BufferingSettings* buffering /* nonnull */) = 0;
  60. virtual status_t setBufferingSettings(const BufferingSettings& buffering) = 0;
  61. virtual void prepareAsync(int64_t startTimeUs) = 0;
  62. virtual void start() = 0;
  63. virtual void stop() {}
  64. virtual void pause() {}
  65. virtual void resume() {}
  66. // Explicitly disconnect the underling data source
  67. virtual void disconnect() {}
  68. // Returns OK iff more data was available,
  69. // an error or ERROR_END_OF_STREAM if not.
  70. virtual status_t feedMoreTSData() = 0;
  71. // Returns non-NULL format when the specified track exists.
  72. // When the format has "err" set to -EWOULDBLOCK, source needs more time to get valid meta data.
  73. // Returns NULL if the specified track doesn't exist or is invalid;
  74. virtual sp<AMessage> getFormat(bool audio);
  75. virtual sp<MetaData> getFormatMeta(bool /* audio */) { return NULL; }
  76. virtual sp<MetaData> getFileFormatMeta() const { return NULL; }
  77. virtual status_t dequeueAccessUnit(
  78. bool audio, sp<ABuffer> *accessUnit) = 0;
  79. virtual status_t getDuration(int64_t * /* durationUs */) {
  80. return INVALID_OPERATION;
  81. }
  82. virtual size_t getTrackCount() const {
  83. return 0;
  84. }
  85. virtual sp<AMessage> getTrackInfo(size_t /* trackIndex */) const {
  86. return NULL;
  87. }
  88. virtual ssize_t getSelectedTrack(media_track_type /* type */) const {
  89. return INVALID_OPERATION;
  90. }
  91. virtual status_t selectTrack(size_t /* trackIndex */, bool /* select */, int64_t /* timeUs*/) {
  92. return INVALID_OPERATION;
  93. }
  94. virtual status_t seekTo(
  95. int64_t /* seekTimeUs */,
  96. MediaPlayer2SeekMode /* mode */ = MediaPlayer2SeekMode::SEEK_PREVIOUS_SYNC) {
  97. return INVALID_OPERATION;
  98. }
  99. virtual bool isRealTime() const {
  100. return false;
  101. }
  102. virtual bool isStreaming() const {
  103. return true;
  104. }
  105. virtual void setOffloadAudio(bool /* offload */) {}
  106. // Modular DRM
  107. virtual status_t prepareDrm(
  108. const uint8_t /* uuid */[16], const Vector<uint8_t> & /* drmSessionId */,
  109. sp<AMediaCryptoWrapper> * /* crypto */) {
  110. return INVALID_OPERATION;
  111. }
  112. virtual status_t releaseDrm() {
  113. return INVALID_OPERATION;
  114. }
  115. protected:
  116. virtual ~Source() {}
  117. virtual void onMessageReceived(const sp<AMessage> &msg);
  118. sp<AMessage> dupNotify() const { return mNotify->dup(); }
  119. void notifyFlagsChanged(uint32_t flags);
  120. void notifyVideoSizeChanged(const sp<AMessage> &format = NULL);
  121. void notifyPrepared(status_t err = OK);
  122. // Modular DRM
  123. void notifyDrmInfo(const sp<ABuffer> &buffer);
  124. private:
  125. sp<AMessage> mNotify;
  126. DISALLOW_EVIL_CONSTRUCTORS(Source);
  127. };
  128. } // namespace android
  129. #endif // NUPLAYER2_SOURCE_H_