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 virtual void sendMetadata(void* ptr) override; 47 48 virtual void save(base::Stream* stream) const override; 49 virtual bool load(base::Stream* stream) override; 50 51 explicit MediaH264DecoderGeneric(uint64_t id, H264PingInfoParser parser); 52 virtual ~MediaH264DecoderGeneric(); 53 type()54 virtual int type() const override { return PLUGIN_TYPE_GENERIC; } 55 56 friend MediaH264DecoderDefault; 57 58 public: 59 private: 60 void decodeFrameInternal(const uint8_t* data, size_t len, uint64_t pts); 61 62 void try_decode(const uint8_t* data, size_t len, uint64_t pts); 63 64 void initH264ContextInternal(unsigned int width, 65 unsigned int height, 66 unsigned int outWidth, 67 unsigned int outHeight, 68 PixelFormat pixFmt); 69 uint64_t mId = 0; 70 H264PingInfoParser mParser; 71 MediaHostRenderer mRenderer; 72 // image props 73 unsigned int mWidth = 0; 74 unsigned int mHeight = 0; 75 unsigned int mOutputHeight = 0; 76 unsigned int mOutputWidth = 0; 77 uint64_t mOutputPts = 0; 78 uint64_t mInputPts = 0; 79 PixelFormat mOutPixFmt; 80 81 // color aspects related 82 private: 83 // default is 601, limited range, sRGB 84 std::unique_ptr<MetadataParam> mMetadataPtr; 85 86 private: 87 std::unique_ptr<MediaSnapshotHelper> mSnapshotHelper; 88 bool mUseGpuTexture = false; 89 90 // at any point of time, only one of the following is valid 91 std::unique_ptr<MediaVideoHelper> mHwVideoHelper; 92 std::unique_ptr<MediaVideoHelper> mSwVideoHelper; 93 std::unique_ptr<MediaVideoHelper> mVideoHelper; 94 95 bool mTrialPeriod = true; 96 97 private: 98 void fetchAllFrames(); 99 100 void createAndInitSoftVideoHelper(); 101 102 void oneShotDecode(const uint8_t* data, size_t len, uint64_t pts); 103 }; // MediaH264DecoderGeneric 104 105 } // namespace emulation 106 } // namespace android 107