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/MediaH264DecoderPlugin.h" 19 #include "host-common/MediaH264Decoder.h" 20 21 #include <stddef.h> 22 #include <mutex> 23 #include <unordered_map> 24 25 namespace android { 26 namespace emulation { 27 28 29 class MediaH264DecoderDefault : public MediaH264Decoder { 30 public: 31 MediaH264DecoderDefault() = default; 32 virtual ~MediaH264DecoderDefault() = default; 33 34 // This is the entry point 35 virtual void handlePing(MediaCodecType type, MediaOperation op, void* ptr) override; 36 37 // For snapshots 38 virtual void save(base::Stream* stream) const override; 39 virtual bool load(base::Stream* stream) override; 40 41 private: 42 std::mutex mIdLock{}; 43 std::mutex mMapLock{}; 44 uint64_t mId = 0; 45 std::unordered_map<uint64_t, MediaH264DecoderPlugin*> mDecoders; 46 uint64_t readId(void* ptr); // read id from the address 47 void removeDecoder(uint64_t id); 48 uint64_t createId(); 49 void addDecoder(uint64_t key, 50 MediaH264DecoderPlugin* val); // this just add 51 void updateDecoder( 52 uint64_t key, 53 MediaH264DecoderPlugin* val); // this will overwrite 54 MediaH264DecoderPlugin* getDecoder(uint64_t key); 55 }; 56 57 } // namespace emulation 58 } // namespace android 59