1 // Copyright (C) 2019 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include "host-common/GoldfishMediaDefs.h" 18 #include "host-common/MediaHostRenderer.h" 19 #include "host-common/MediaSnapshotHelper.h" 20 #include "host-common/MediaSnapshotState.h" 21 #include "host-common/MediaVideoHelper.h" 22 #include "host-common/MediaVpxDecoderPlugin.h" 23 #include "host-common/VpxPingInfoParser.h" 24 25 #include <stddef.h> 26 #include <stdint.h> 27 #include <vector> 28 29 extern "C" { 30 #include "vpx/vp8dx.h" 31 #include "vpx/vpx_codec.h" 32 #include "vpx/vpx_decoder.h" 33 #include "vpx/vpx_image.h" 34 } 35 36 namespace android { 37 namespace emulation { 38 39 class MediaVpxDecoderGeneric : public MediaVpxDecoderPlugin { 40 public: 41 virtual void initVpxContext(void* ptr) override; 42 virtual void decodeFrame(void* ptr) override; 43 virtual void getImage(void* ptr) override; 44 virtual void flush(void* ptr) override; 45 virtual void destroyVpxContext(void* ptr) override; 46 47 explicit MediaVpxDecoderGeneric(VpxPingInfoParser parser, 48 MediaCodecType type); 49 virtual ~MediaVpxDecoderGeneric(); 50 51 virtual void save(base::Stream* stream) const override; 52 bool load(base::Stream* stream) override; 53 54 friend MediaSnapshotHelper; 55 56 protected: 57 // this is required by save/load type()58 virtual int type() const override { return PLUGIN_TYPE_GENERIC; } vpxtype()59 virtual int vpxtype() const override { 60 return mType == MediaCodecType::VP8Codec ? 8 : 9; 61 } version()62 virtual int version() const override { return mParser.version(); } 63 64 private: 65 MediaCodecType mType; // vp8 or vp9 66 VpxPingInfoParser mParser; 67 MediaHostRenderer mRenderer; 68 69 int mNumFramesDecoded = 0; 70 71 bool mUseGpuTexture = false; 72 bool mTrialPeriod = true; 73 // at any point of time, only one of the following is valid 74 std::unique_ptr<MediaVideoHelper> mHwVideoHelper; 75 std::unique_ptr<MediaVideoHelper> mSwVideoHelper; 76 std::unique_ptr<MediaVideoHelper> mVideoHelper; 77 78 void fetchAllFrames(); 79 void createAndInitSoftVideoHelper(); 80 81 private: 82 void decode_internal(const uint8_t* data, size_t len, uint64_t pts); 83 void oneShotDecode(const uint8_t* data, size_t len, uint64_t pts); 84 void try_decode(const uint8_t* data, size_t len, uint64_t pts); 85 mutable MediaSnapshotHelper mSnapshotHelper; 86 }; 87 88 } // namespace emulation 89 } // namespace android 90