NuPlayer2Decoder.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_DECODER_H_
  17. #define NUPLAYER2_DECODER_H_
  18. #include "NuPlayer2.h"
  19. #include "NuPlayer2DecoderBase.h"
  20. namespace android {
  21. class MediaCodecBuffer;
  22. struct AMediaCodecWrapper;
  23. struct AMediaFormatWrapper;
  24. struct NuPlayer2::Decoder : public DecoderBase {
  25. Decoder(const sp<AMessage> &notify,
  26. const sp<Source> &source,
  27. pid_t pid,
  28. uid_t uid,
  29. const sp<Renderer> &renderer = NULL,
  30. const sp<ANativeWindowWrapper> &nww = NULL,
  31. const sp<CCDecoder> &ccDecoder = NULL);
  32. virtual sp<AMessage> getStats() const;
  33. // sets the output surface of video decoders.
  34. virtual status_t setVideoSurface(const sp<ANativeWindowWrapper> &nww);
  35. virtual status_t releaseCrypto();
  36. protected:
  37. virtual ~Decoder();
  38. virtual void onMessageReceived(const sp<AMessage> &msg);
  39. virtual void onConfigure(const sp<AMessage> &format);
  40. virtual void onSetParameters(const sp<AMessage> &params);
  41. virtual void onSetRenderer(const sp<Renderer> &renderer);
  42. virtual void onResume(bool notifyComplete);
  43. virtual void onFlush();
  44. virtual void onShutdown(bool notifyComplete);
  45. virtual bool doRequestBuffers();
  46. private:
  47. enum {
  48. kWhatCodecNotify = 'cdcN',
  49. kWhatRenderBuffer = 'rndr',
  50. kWhatSetVideoSurface = 'sSur',
  51. kWhatAudioOutputFormatChanged = 'aofc',
  52. kWhatDrmReleaseCrypto = 'rDrm',
  53. };
  54. enum {
  55. kMaxNumVideoTemporalLayers = 32,
  56. };
  57. sp<ANativeWindowWrapper> mNativeWindow;
  58. sp<Source> mSource;
  59. sp<Renderer> mRenderer;
  60. sp<CCDecoder> mCCDecoder;
  61. sp<AMediaFormatWrapper> mInputFormat;
  62. sp<AMediaCodecWrapper> mCodec;
  63. List<sp<AMessage> > mPendingInputMessages;
  64. Vector<sp<MediaCodecBuffer> > mInputBuffers;
  65. Vector<sp<MediaCodecBuffer> > mOutputBuffers;
  66. Vector<sp<ABuffer> > mCSDsForCurrentFormat;
  67. Vector<sp<ABuffer> > mCSDsToSubmit;
  68. Vector<bool> mInputBufferIsDequeued;
  69. Vector<MediaBuffer *> mMediaBuffers;
  70. Vector<size_t> mDequeuedInputBuffers;
  71. const pid_t mPid;
  72. const uid_t mUid;
  73. int64_t mSkipRenderingUntilMediaTimeUs;
  74. int64_t mNumFramesTotal;
  75. int64_t mNumInputFramesDropped;
  76. int64_t mNumOutputFramesDropped;
  77. int32_t mVideoWidth;
  78. int32_t mVideoHeight;
  79. bool mIsAudio;
  80. bool mIsVideoAVC;
  81. bool mIsSecure;
  82. bool mIsEncrypted;
  83. bool mIsEncryptedObservedEarlier;
  84. bool mFormatChangePending;
  85. bool mTimeChangePending;
  86. float mFrameRateTotal;
  87. float mPlaybackSpeed;
  88. int32_t mNumVideoTemporalLayerTotal;
  89. int32_t mNumVideoTemporalLayerAllowed;
  90. int32_t mCurrentMaxVideoTemporalLayerId;
  91. float mVideoTemporalLayerAggregateFps[kMaxNumVideoTemporalLayers];
  92. bool mResumePending;
  93. AString mComponentName;
  94. void handleError(int32_t err);
  95. bool handleAnInputBuffer(size_t index);
  96. bool handleAnOutputBuffer(
  97. size_t index,
  98. size_t offset,
  99. size_t size,
  100. int64_t timeUs,
  101. int32_t flags);
  102. void handleOutputFormatChange(const sp<AMessage> &format);
  103. void releaseAndResetMediaBuffers();
  104. bool isStaleReply(const sp<AMessage> &msg);
  105. void doFlush(bool notifyComplete);
  106. status_t fetchInputData(sp<AMessage> &reply);
  107. bool onInputBufferFetched(const sp<AMessage> &msg);
  108. void onRenderBuffer(const sp<AMessage> &msg);
  109. bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;
  110. bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const;
  111. void rememberCodecSpecificData(const sp<AMessage> &format);
  112. bool isDiscontinuityPending() const;
  113. void finishHandleDiscontinuity(bool flushOnTimeChange);
  114. void notifyResumeCompleteIfNecessary();
  115. void onReleaseCrypto(const sp<AMessage>& msg);
  116. DISALLOW_EVIL_CONSTRUCTORS(Decoder);
  117. };
  118. } // namespace android
  119. #endif // NUPLAYER2_DECODER_H_