1 /* 2 * Copyright (C) 2023 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 #include <linux/videodev2.h> 19 #include <utility> 20 #include <vector> 21 #include <android/hardware_buffer.h> 22 23 #include "Buffer.h" 24 #include "Utils.h" 25 26 namespace android { 27 namespace webcam { 28 29 struct CameraConfig { 30 uint32_t width = 0; 31 uint32_t height = 0; 32 uint32_t fps = 0; 33 uint32_t fcc = V4L2_PIX_FMT_MJPEG; 34 }; 35 36 // Abstract class which maps camera operations 37 class FrameProvider { 38 public: FrameProvider(std::shared_ptr<BufferProducer> producer,CameraConfig config)39 FrameProvider(std::shared_ptr<BufferProducer> producer, CameraConfig config) 40 : mBufferProducer(std::move(producer)), mConfig(config) {} 41 virtual ~FrameProvider() = default; 42 virtual void setStreamConfig() = 0; 43 virtual Status startStreaming() = 0; 44 virtual Status stopStreaming() = 0; 45 virtual Status encodeImage(AHardwareBuffer* hardwareBuffer, long timestamp, int rotation) = 0; isInited()46 [[nodiscard]] virtual bool isInited() const { return mInited; } 47 48 protected: 49 std::shared_ptr<BufferProducer> mBufferProducer; 50 CameraConfig mConfig; 51 bool mInited = false; 52 }; 53 54 } // namespace webcam 55 } // namespace android 56