1 /* 2 * Copyright (C) 2018 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 17 #pragma once 18 19 #include "goldfish_vpx_defs.h" 20 #include <SimpleC2Component.h> 21 22 namespace android { 23 24 struct C2GoldfishVpxDec : public SimpleC2Component { 25 class IntfImpl; 26 27 C2GoldfishVpxDec(const char *name, c2_node_id_t id, 28 const std::shared_ptr<IntfImpl> &intfImpl); 29 virtual ~C2GoldfishVpxDec(); 30 31 // From SimpleC2Component 32 c2_status_t onInit() override; 33 c2_status_t onStop() override; 34 void onReset() override; 35 void onRelease() override; 36 c2_status_t onFlush_sm() override; 37 void process(const std::unique_ptr<C2Work> &work, 38 const std::shared_ptr<C2BlockPool> &pool) override; 39 c2_status_t drain(uint32_t drainMode, 40 const std::shared_ptr<C2BlockPool> &pool) override; 41 42 private: 43 enum { 44 MODE_VP8, 45 MODE_VP9, 46 } mMode; 47 48 struct ConversionQueue; 49 50 class ConverterThread : public Thread { 51 public: 52 explicit ConverterThread( 53 const std::shared_ptr<Mutexed<ConversionQueue>> &queue); 54 ~ConverterThread() override = default; 55 bool threadLoop() override; 56 57 private: 58 std::shared_ptr<Mutexed<ConversionQueue>> mQueue; 59 }; 60 61 // create context that talks to host decoder: it needs to use 62 // pool to decide whether decoding to host color buffer ot 63 // decode to guest bytebuffer when pool cannot fetch valid host 64 // color buffer id 65 void checkContext(const std::shared_ptr<C2BlockPool> &pool); 66 bool mEnableAndroidNativeBuffers{true}; 67 68 void setup_ctx_parameters(vpx_codec_ctx_t *ctx, int hostColorBufferId = -1); 69 70 std::shared_ptr<IntfImpl> mIntf; 71 vpx_codec_ctx_t *mCtx; 72 bool mFrameParallelMode; // Frame parallel is only supported by VP9 decoder. 73 vpx_image_t *mImg; 74 75 uint32_t mWidth; 76 uint32_t mHeight; 77 bool mSignalledOutputEos; 78 bool mSignalledError; 79 80 struct ConversionQueue { 81 std::list<std::function<void()>> entries; 82 Condition cond; 83 size_t numPending{0u}; 84 }; 85 std::shared_ptr<Mutexed<ConversionQueue>> mQueue; 86 std::vector<sp<ConverterThread>> mConverterThreads; 87 88 status_t initDecoder(); 89 status_t destroyDecoder(); 90 void finishWork(uint64_t index, const std::unique_ptr<C2Work> &work, 91 const std::shared_ptr<C2GraphicBlock> &block); 92 status_t outputBuffer(const std::shared_ptr<C2BlockPool> &pool, 93 const std::unique_ptr<C2Work> &work); 94 c2_status_t drainInternal(uint32_t drainMode, 95 const std::shared_ptr<C2BlockPool> &pool, 96 const std::unique_ptr<C2Work> &work); 97 98 C2_DO_NOT_COPY(C2GoldfishVpxDec); 99 }; 100 101 } // namespace android 102