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