1 /* 2 * Copyright 2022 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 <gui/Surface.h> 20 #include <hardware/tv_input.h> 21 #include <utils/Thread.h> 22 23 namespace android { 24 25 class BufferProducerThread : public Thread { 26 public: 27 BufferProducerThread(tv_input_device_t* device, int deviceId, const tv_stream_t* stream); 28 29 virtual status_t readyToRun(); 30 31 void setSurface(const sp<Surface>& surface); 32 void onCaptured(uint32_t seq, bool succeeded); 33 void shutdown(); 34 35 private: 36 Mutex mLock; 37 Condition mCondition; 38 sp<Surface> mSurface; 39 tv_input_device_t* mDevice; 40 int mDeviceId; 41 tv_stream_t mStream; 42 sp<ANativeWindowBuffer_t> mBuffer; 43 enum { 44 CAPTURING, 45 CAPTURED, 46 RELEASED, 47 } mBufferState; 48 uint32_t mSeq; 49 bool mShutdown; 50 51 virtual bool threadLoop(); 52 53 void setSurfaceLocked(const sp<Surface>& surface); 54 }; 55 56 } // namespace android 57