NuPlayer2DecoderBase.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_BASE_H_
  17. #define NUPLAYER2_DECODER_BASE_H_
  18. #include "NuPlayer2.h"
  19. #include <media/stagefright/foundation/AHandler.h>
  20. namespace android {
  21. struct ABuffer;
  22. struct ANativeWindowWrapper;
  23. struct MediaCodec;
  24. class MediaBuffer;
  25. class MediaCodecBuffer;
  26. struct NuPlayer2::DecoderBase : public AHandler {
  27. explicit DecoderBase(const sp<AMessage> &notify);
  28. void configure(const sp<AMessage> &format);
  29. void init();
  30. void setParameters(const sp<AMessage> &params);
  31. // Synchronous call to ensure decoder will not request or send out data.
  32. void pause();
  33. void setRenderer(const sp<Renderer> &renderer);
  34. virtual status_t setVideoSurface(const sp<ANativeWindowWrapper> &) { return INVALID_OPERATION; }
  35. void signalFlush();
  36. void signalResume(bool notifyComplete);
  37. void initiateShutdown();
  38. virtual sp<AMessage> getStats() const {
  39. return mStats;
  40. }
  41. virtual status_t releaseCrypto() {
  42. return INVALID_OPERATION;
  43. }
  44. enum {
  45. kWhatInputDiscontinuity = 'inDi',
  46. kWhatVideoSizeChanged = 'viSC',
  47. kWhatFlushCompleted = 'flsC',
  48. kWhatShutdownCompleted = 'shDC',
  49. kWhatResumeCompleted = 'resC',
  50. kWhatEOS = 'eos ',
  51. kWhatError = 'err ',
  52. };
  53. protected:
  54. virtual ~DecoderBase();
  55. void stopLooper();
  56. virtual void onMessageReceived(const sp<AMessage> &msg);
  57. virtual void onConfigure(const sp<AMessage> &format) = 0;
  58. virtual void onSetParameters(const sp<AMessage> &params) = 0;
  59. virtual void onSetRenderer(const sp<Renderer> &renderer) = 0;
  60. virtual void onResume(bool notifyComplete) = 0;
  61. virtual void onFlush() = 0;
  62. virtual void onShutdown(bool notifyComplete) = 0;
  63. void onRequestInputBuffers();
  64. virtual bool doRequestBuffers() = 0;
  65. virtual void handleError(int32_t err);
  66. sp<AMessage> mNotify;
  67. int32_t mBufferGeneration;
  68. bool mPaused;
  69. sp<AMessage> mStats;
  70. private:
  71. enum {
  72. kWhatConfigure = 'conf',
  73. kWhatSetParameters = 'setP',
  74. kWhatSetRenderer = 'setR',
  75. kWhatPause = 'paus',
  76. kWhatRequestInputBuffers = 'reqB',
  77. kWhatFlush = 'flus',
  78. kWhatShutdown = 'shuD',
  79. };
  80. sp<ALooper> mDecoderLooper;
  81. bool mRequestInputBuffersPending;
  82. DISALLOW_EVIL_CONSTRUCTORS(DecoderBase);
  83. };
  84. } // namespace android
  85. #endif // NUPLAYER2_DECODER_BASE_H_