HeifDecoderImpl.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 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 _HEIF_DECODER_IMPL_
  17. #define _HEIF_DECODER_IMPL_
  18. #include "include/HeifDecoderAPI.h"
  19. #include <system/graphics.h>
  20. #include <utils/Condition.h>
  21. #include <utils/Mutex.h>
  22. #include <utils/RefBase.h>
  23. namespace android {
  24. class IDataSource;
  25. class IMemory;
  26. class MediaMetadataRetriever;
  27. /*
  28. * An implementation of HeifDecoder based on Android's MediaMetadataRetriever.
  29. */
  30. class HeifDecoderImpl : public HeifDecoder {
  31. public:
  32. HeifDecoderImpl();
  33. ~HeifDecoderImpl() override;
  34. bool init(HeifStream* stream, HeifFrameInfo* frameInfo) override;
  35. bool getEncodedColor(HeifEncodedColor* outColor) const override;
  36. bool setOutputColor(HeifColorFormat heifColor) override;
  37. bool decode(HeifFrameInfo* frameInfo) override;
  38. bool getScanline(uint8_t* dst) override;
  39. size_t skipScanlines(size_t count) override;
  40. private:
  41. struct DecodeThread;
  42. sp<IDataSource> mDataSource;
  43. sp<MediaMetadataRetriever> mRetriever;
  44. sp<IMemory> mFrameMemory;
  45. android_pixel_format_t mOutputColor;
  46. size_t mCurScanline;
  47. uint32_t mWidth;
  48. uint32_t mHeight;
  49. bool mFrameDecoded;
  50. bool mHasImage;
  51. bool mHasVideo;
  52. // Slice decoding only
  53. Mutex mLock;
  54. Condition mScanlineReady;
  55. sp<DecodeThread> mThread;
  56. size_t mAvailableLines;
  57. size_t mNumSlices;
  58. uint32_t mSliceHeight;
  59. bool mAsyncDecodeDone;
  60. bool decodeAsync();
  61. bool getScanlineInner(uint8_t* dst);
  62. };
  63. } // namespace android
  64. #endif // _HEIF_DECODER_IMPL_