1 /* 2 Copyright (c) 2012-2020 Maarten Baert <maarten-baert@hotmail.com> 3 4 This file is part of SimpleScreenRecorder. 5 6 SimpleScreenRecorder is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 SimpleScreenRecorder is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with SimpleScreenRecorder. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #pragma once 21 #include "Global.h" 22 23 #include "SSRVideoStream.h" 24 25 #include "../glinject/ShmStructs.h" 26 27 class SSRVideoStreamReader { 28 29 private: 30 struct FrameData { 31 std::string m_filename_frame; 32 int m_fd_frame; 33 void *m_mmap_ptr_frame; 34 size_t m_mmap_size_frame; 35 }; 36 37 private: 38 SSRVideoStream m_stream; 39 std::string m_channel_directory, m_filename_main; 40 size_t m_page_size; 41 42 int64_t m_fps_last_timestamp; 43 uint32_t m_fps_last_counter; 44 double m_fps_current; 45 46 int m_fd_main, m_file_lock; 47 void *m_mmap_ptr_main; 48 size_t m_mmap_size_main; 49 50 FrameData m_frame_data[GLINJECT_RING_BUFFER_SIZE]; 51 52 public: 53 SSRVideoStreamReader(const std::string& channel, const SSRVideoStream& stream); 54 ~SSRVideoStreamReader(); 55 56 private: 57 void Init(); 58 void Free(); 59 60 public: 61 // Reads the current size of the stream. If the stream hasn't been started yet, this will be 0x0. 62 void GetCurrentSize(unsigned int* width, unsigned int* height); 63 64 // Returns the current fps. 65 double GetFPS(); 66 67 // Changes the capture parameters. 68 void ChangeCaptureParameters(unsigned int flags, unsigned int target_fps); 69 70 // Clears the ring buffer (i.e. drops all frames). 71 void Clear(); 72 73 // Checks whether a new frame is available, and returns a pointer to the frame memory if it is. Otherwise it returns NULL. 74 void* GetFrame(int64_t* timestamp, unsigned int* width, unsigned int* height, int* stride); 75 76 // Drops the current frame and goes to the next frame. 77 void NextFrame(); 78 79 public: 80 81 // Returns the stream that is being read. GetStream()82 inline const SSRVideoStream& GetStream() { return m_stream; } 83 84 private: GetGLInjectHeader()85 inline GLInjectHeader* GetGLInjectHeader() { return (GLInjectHeader*) m_mmap_ptr_main; } GetGLInjectFrameInfo(unsigned int frame)86 inline GLInjectFrameInfo* GetGLInjectFrameInfo(unsigned int frame) { return (GLInjectFrameInfo*) ((char*) m_mmap_ptr_main + sizeof(GLInjectHeader) + frame * sizeof(GLInjectFrameInfo)); } 87 88 }; 89