NuPlayer2Driver.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. #include <mediaplayer2/MediaPlayer2Interface.h>
  17. #include <media/MediaMetrics.h>
  18. #include <media/stagefright/foundation/ABase.h>
  19. #include <mediaplayer2/JObjectHolder.h>
  20. namespace android {
  21. struct ALooper;
  22. struct MediaClock;
  23. struct NuPlayer2;
  24. struct NuPlayer2Driver : public MediaPlayer2Interface {
  25. explicit NuPlayer2Driver(pid_t pid, uid_t uid, const sp<JObjectHolder> &context);
  26. virtual status_t initCheck() override;
  27. virtual status_t setDataSource(const sp<DataSourceDesc> &dsd) override;
  28. virtual status_t prepareNextDataSource(const sp<DataSourceDesc> &dsd) override;
  29. virtual status_t playNextDataSource(int64_t srcId) override;
  30. virtual status_t setVideoSurfaceTexture(const sp<ANativeWindowWrapper> &nww) override;
  31. virtual status_t getBufferingSettings(
  32. BufferingSettings* buffering /* nonnull */) override;
  33. virtual status_t setBufferingSettings(const BufferingSettings& buffering) override;
  34. virtual status_t prepareAsync() override;
  35. virtual status_t start() override;
  36. virtual status_t pause() override;
  37. virtual bool isPlaying() override;
  38. virtual status_t setPlaybackSettings(const AudioPlaybackRate &rate) override;
  39. virtual status_t getPlaybackSettings(AudioPlaybackRate *rate) override;
  40. virtual status_t setSyncSettings(const AVSyncSettings &sync, float videoFpsHint) override;
  41. virtual status_t getSyncSettings(AVSyncSettings *sync, float *videoFps) override;
  42. virtual status_t seekTo(
  43. int64_t msec,
  44. MediaPlayer2SeekMode mode = MediaPlayer2SeekMode::SEEK_PREVIOUS_SYNC) override;
  45. virtual status_t getCurrentPosition(int64_t *msec) override;
  46. virtual status_t getDuration(int64_t *msec) override;
  47. virtual status_t reset() override;
  48. virtual status_t notifyAt(int64_t mediaTimeUs) override;
  49. virtual status_t setLooping(int loop) override;
  50. virtual status_t invoke(const PlayerMessage &request, PlayerMessage *response) override;
  51. virtual void setAudioSink(const sp<AudioSink> &audioSink) override;
  52. virtual status_t setParameter(int key, const Parcel &request) override;
  53. virtual status_t getParameter(int key, Parcel *reply) override;
  54. virtual status_t getMetrics(char **buf, size_t *length) override;
  55. virtual status_t dump(int fd, const Vector<String16> &args) const override;
  56. virtual void onMessageReceived(const sp<AMessage> &msg) override;
  57. void notifySetDataSourceCompleted(int64_t srcId, status_t err);
  58. void notifyPrepareCompleted(int64_t srcId, status_t err);
  59. void notifyResetComplete(int64_t srcId);
  60. void notifySetSurfaceComplete(int64_t srcId);
  61. void notifyDuration(int64_t srcId, int64_t durationUs);
  62. void notifyMorePlayingTimeUs(int64_t srcId, int64_t timeUs);
  63. void notifyMoreRebufferingTimeUs(int64_t srcId, int64_t timeUs);
  64. void notifyRebufferingWhenExit(int64_t srcId, bool status);
  65. void notifySeekComplete(int64_t srcId);
  66. void notifyListener(int64_t srcId, int msg, int ext1 = 0, int ext2 = 0,
  67. const PlayerMessage *in = NULL);
  68. void notifyFlagsChanged(int64_t srcId, uint32_t flags);
  69. // Modular DRM
  70. virtual status_t prepareDrm(
  71. int64_t srcId, const uint8_t uuid[16], const Vector<uint8_t> &drmSessionId);
  72. virtual status_t releaseDrm(int64_t srcId);
  73. protected:
  74. virtual ~NuPlayer2Driver();
  75. private:
  76. enum State {
  77. STATE_IDLE,
  78. STATE_SET_DATASOURCE_PENDING,
  79. STATE_UNPREPARED,
  80. STATE_PREPARING,
  81. STATE_PREPARED,
  82. STATE_RUNNING,
  83. STATE_PAUSED,
  84. STATE_RESET_IN_PROGRESS,
  85. };
  86. std::string stateString(State state);
  87. enum {
  88. kWhatNotifyListener,
  89. };
  90. mutable Mutex mLock;
  91. Condition mCondition;
  92. State mState;
  93. status_t mAsyncResult;
  94. // The following are protected through "mLock"
  95. // >>>
  96. int64_t mSrcId;
  97. bool mSetSurfaceInProgress;
  98. int64_t mDurationUs;
  99. int64_t mPositionUs;
  100. bool mSeekInProgress;
  101. int64_t mPlayingTimeUs;
  102. int64_t mRebufferingTimeUs;
  103. int32_t mRebufferingEvents;
  104. bool mRebufferingAtExit;
  105. // <<<
  106. sp<ALooper> mLooper;
  107. sp<ALooper> mNuPlayer2Looper;
  108. const sp<MediaClock> mMediaClock;
  109. const sp<NuPlayer2> mPlayer;
  110. sp<AudioSink> mAudioSink;
  111. uint32_t mPlayerFlags;
  112. mediametrics_handle_t mMetricsHandle;
  113. int64_t mPlayerVersion;
  114. uid_t mClientUid;
  115. bool mAtEOS;
  116. bool mLooping;
  117. bool mAutoLoop;
  118. void updateMetrics(const char *where);
  119. void logMetrics(const char *where);
  120. status_t start_l();
  121. void notifyListener_l(int64_t srcId, int msg, int ext1 = 0, int ext2 = 0,
  122. const PlayerMessage *in = NULL);
  123. DISALLOW_EVIL_CONSTRUCTORS(NuPlayer2Driver);
  124. };
  125. } // namespace android