1 // Copyright (C) 2020 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/H264PingInfoParser.h" 19 #include "host-common/MediaFfmpegVideoHelper.h" 20 #include "host-common/MediaH264DecoderPlugin.h" 21 #include "host-common/MediaHostRenderer.h" 22 #include "host-common/MediaSnapshotHelper.h" 23 #include "host-common/MediaSnapshotState.h" 24 25 #include <cstdint> 26 #include <string> 27 #include <vector> 28 29 #include <stdio.h> 30 #include <string.h> 31 32 #include <stddef.h> 33 34 namespace android { 35 namespace emulation { 36 37 class MediaH264DecoderGeneric : public MediaH264DecoderPlugin { 38 public: 39 virtual void reset(void* ptr) override; 40 virtual void initH264Context(void* ptr) override; 41 virtual MediaH264DecoderPlugin* clone() override; 42 virtual void destroyH264Context() override; 43 virtual void decodeFrame(void* ptr) override; 44 virtual void flush(void* ptr) override; 45 virtual void getImage(void* ptr) override; 46 47 virtual void save(base::Stream* stream) const override; 48 virtual bool load(base::Stream* stream) override; 49 50 explicit MediaH264DecoderGeneric(uint64_t id, H264PingInfoParser parser); 51 virtual ~MediaH264DecoderGeneric(); 52 type()53 virtual int type() const override { return PLUGIN_TYPE_GENERIC; } 54 55 friend MediaH264DecoderDefault; 56 57 public: 58 private: 59 void decodeFrameInternal(const uint8_t* data, size_t len, uint64_t pts); 60 61 void try_decode(const uint8_t* data, size_t len, uint64_t pts); 62 63 void initH264ContextInternal(unsigned int width, 64 unsigned int height, 65 unsigned int outWidth, 66 unsigned int outHeight, 67 PixelFormat pixFmt); 68 uint64_t mId = 0; 69 H264PingInfoParser mParser; 70 MediaHostRenderer mRenderer; 71 // image props 72 unsigned int mWidth = 0; 73 unsigned int mHeight = 0; 74 unsigned int mOutputHeight = 0; 75 unsigned int mOutputWidth = 0; 76 uint64_t mOutputPts = 0; 77 uint64_t mInputPts = 0; 78 PixelFormat mOutPixFmt; 79 80 private: 81 std::unique_ptr<MediaSnapshotHelper> mSnapshotHelper; 82 bool mUseGpuTexture = false; 83 84 // at any point of time, only one of the following is valid 85 std::unique_ptr<MediaVideoHelper> mHwVideoHelper; 86 std::unique_ptr<MediaVideoHelper> mSwVideoHelper; 87 std::unique_ptr<MediaVideoHelper> mVideoHelper; 88 89 bool mTrialPeriod = true; 90 91 private: 92 void fetchAllFrames(); 93 94 void createAndInitSoftVideoHelper(); 95 96 void oneShotDecode(const uint8_t* data, size_t len, uint64_t pts); 97 }; // MediaH264DecoderGeneric 98 99 } // namespace emulation 100 } // namespace android 101