1 // Copyright (C) 2017 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 <stdint.h> // for uint32_t 18 #include <stdbool.h> 19 20 #include "aemu/base/c_header.h" 21 #include "host-common/display_agent.h" // for QAndroidDisplay... 22 #include "host-common/multi_display_agent.h" 23 24 ANDROID_BEGIN_HEADER 25 26 // This callback will be called in the following scenarios: 27 // 28 // 1) The encoding has been stopped 29 // 2) The encoding is finished 30 // 3) An error has occurred while encoding was trying to finish. 31 // 32 // When screen_recorder_stop_async() is called, this callback will get called, 33 // with success set to 0. There is some time elapsed when we want to stop 34 // recording and when the encoding is actually finished, so we'll get a second 35 // call to the callback once the encoding is finished, with success set to 1. If 36 // any errors occur while stopping the recording, success will be set to -1. 37 typedef enum { 38 RECORD_START_INITIATED, 39 RECORD_STARTED, 40 RECORD_START_FAILED, 41 RECORD_STOP_INITIATED, 42 RECORD_STOPPED, 43 RECORD_STOP_FAILED, 44 } RecordingStatus; 45 46 typedef enum { 47 RECORDER_STARTING, 48 RECORDER_RECORDING, 49 RECORDER_STOPPING, 50 RECORDER_STOPPED, 51 } RecorderState; 52 53 typedef struct { 54 RecorderState state; 55 uint32_t displayId; 56 } RecorderStates; 57 58 typedef void (*RecordingCallback)(void* opaque, RecordingStatus status); 59 60 typedef struct RecordingInfo { 61 const char* fileName; 62 uint32_t width; 63 uint32_t height; 64 uint32_t videoBitrate; 65 uint32_t timeLimit; 66 uint32_t fps; 67 uint32_t displayId; 68 RecordingCallback cb; 69 void* opaque; 70 } RecordingInfo; 71 72 // Initializes internal global structure. Call this before doing any recording 73 // operations. |w| and |h| are the FrameBuffer width and height. |dpy_agent| is 74 // the display agent for recording in guest mode. If |dpy_agent| is NULL, then 75 // the recorder will assume it is in host mode. 76 extern void screen_recorder_init(uint32_t w, 77 uint32_t h, 78 const QAndroidDisplayAgent* dpy_agent, 79 const QAndroidMultiDisplayAgent* mdpy_agent); 80 // Starts recording the screen. When stopped, the file will be saved as 81 // |info->filename|. Set |async| true do not block as recording initialization 82 // takes time. Returns true if recorder started recording, false if it failed. 83 extern bool screen_recorder_start(const RecordingInfo* info, bool async); 84 // Stop recording. After calling this function, the encoder will stop processing 85 // frames. The encoder still needs to process any remaining frames it has, so 86 // calling this does not mean that the encoder has finished and |filename| is 87 // ready. Attach a RecordingStoppedCallback to get an update when the encoder 88 // has finished. Set |async| to false if you want to block until recording is 89 // finished. 90 extern bool screen_recorder_stop(bool async); 91 // Get the recorder's current state. 92 extern RecorderStates screen_recorder_state_get(void); 93 // Starts the shared memory region. Note that the desired framerate 94 // can be ignored. 95 extern const char* start_shared_memory_module(int desiredFps); 96 // Stops the webrtc module 97 extern bool stop_shared_memory_module(); 98 99 ANDROID_END_HEADER 100