Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a8d851090 |
6
BUILD.md
6
BUILD.md
@@ -234,10 +234,10 @@ You can then [run](README.md#run) _scrcpy_.
|
||||
|
||||
## Prebuilt server
|
||||
|
||||
- [`scrcpy-server-v1.6.jar`][direct-scrcpy-server]
|
||||
_(SHA-256: 08df924bf6d10943df9eaacfff548a99871ebfca4641f8c7ddddb73f27cb905b)_
|
||||
- [`scrcpy-server-v1.5.jar`][direct-scrcpy-server]
|
||||
_(SHA-256: d97aab6f60294e33e7ff79c2856ad3e01f912892395131f4f337e9ece03c24de)_
|
||||
|
||||
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.6/scrcpy-server-v1.6.jar
|
||||
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.5-fixversion/scrcpy-server-v1.5.jar
|
||||
|
||||
Download the prebuilt server somewhere, and specify its path during the Meson
|
||||
configuration:
|
||||
|
||||
14
FAQ.md
14
FAQ.md
@@ -24,6 +24,20 @@ If you still encounter problems, please see [issue 9].
|
||||
[issue 9]: https://github.com/Genymobile/scrcpy/issues/9
|
||||
|
||||
|
||||
### I get a black screen for some applications like Silence
|
||||
|
||||
This is expected, they requested to [protect] the screen.
|
||||
|
||||
In [Silence], you can disable it in settings → Privacy → Screen security.
|
||||
|
||||
[protect]: https://developer.android.com/reference/android/view/Display#FLAG_SECURE
|
||||
[silence]: https://f-droid.org/en/packages/org.smssecure.smssecure/
|
||||
|
||||
See [issue 36].
|
||||
|
||||
[issue 36]: https://github.com/Genymobile/scrcpy/issues/36
|
||||
|
||||
|
||||
### Mouse clicks do not work
|
||||
|
||||
On some devices, you may need to enable an option to allow [simulating input].
|
||||
|
||||
@@ -34,7 +34,7 @@ WIN32_TARGET := $(WIN32_TARGET_DIR)-$(VERSION).zip
|
||||
WIN64_TARGET := $(WIN64_TARGET_DIR)-$(VERSION).zip
|
||||
|
||||
release: clean zip-win32 zip-win64 sums
|
||||
@echo "Windows archives generated in $(DIST)/"
|
||||
@echo "Release created in $(DIST)/."
|
||||
|
||||
clean:
|
||||
$(GRADLE) clean
|
||||
@@ -100,10 +100,10 @@ dist-win32: build-server build-win32 build-win32-noconsole
|
||||
cp "$(SERVER_BUILD_DIR)"/server/scrcpy-server.jar "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp "$(WIN32_BUILD_DIR)"/app/scrcpy.exe "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp "$(WIN32_NOCONSOLE_BUILD_DIR)"/app/scrcpy.exe "$(DIST)/$(WIN32_TARGET_DIR)/scrcpy-noconsole.exe"
|
||||
cp prebuilt-deps/ffmpeg-4.1-win32-shared/bin/avutil-56.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/ffmpeg-4.1-win32-shared/bin/avcodec-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/ffmpeg-4.1-win32-shared/bin/avformat-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/ffmpeg-4.1-win32-shared/bin/swresample-3.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/ffmpeg-4.0.2-win32-shared/bin/avutil-56.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/ffmpeg-4.0.2-win32-shared/bin/avcodec-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/ffmpeg-4.0.2-win32-shared/bin/avformat-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/ffmpeg-4.0.2-win32-shared/bin/swresample-3.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/platform-tools/adb.exe "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/platform-tools/AdbWinApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/platform-tools/AdbWinUsbApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
@@ -114,10 +114,10 @@ dist-win64: build-server build-win64 build-win64-noconsole
|
||||
cp "$(SERVER_BUILD_DIR)"/server/scrcpy-server.jar "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp "$(WIN64_BUILD_DIR)"/app/scrcpy.exe "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp "$(WIN64_NOCONSOLE_BUILD_DIR)"/app/scrcpy.exe "$(DIST)/$(WIN64_TARGET_DIR)/scrcpy-noconsole.exe"
|
||||
cp prebuilt-deps/ffmpeg-4.1-win64-shared/bin/avutil-56.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/ffmpeg-4.1-win64-shared/bin/avcodec-58.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/ffmpeg-4.1-win64-shared/bin/avformat-58.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/ffmpeg-4.1-win64-shared/bin/swresample-3.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/ffmpeg-4.0.2-win64-shared/bin/avutil-56.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/ffmpeg-4.0.2-win64-shared/bin/avcodec-58.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/ffmpeg-4.0.2-win64-shared/bin/avformat-58.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/ffmpeg-4.0.2-win64-shared/bin/swresample-3.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/platform-tools/adb.exe "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/platform-tools/AdbWinApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/platform-tools/AdbWinUsbApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
|
||||
26
README.md
26
README.md
@@ -1,4 +1,4 @@
|
||||
# scrcpy (v1.6)
|
||||
# scrcpy (v1.5)
|
||||
|
||||
This application provides display and control of Android devices connected on
|
||||
USB (or [over TCP/IP][article-tcpip]). It does not require any _root_ access.
|
||||
@@ -47,13 +47,13 @@ For Gentoo, an [Ebuild] is available: [`scrcpy/`][ebuild-link].
|
||||
For Windows, for simplicity, prebuilt archives with all the dependencies
|
||||
(including `adb`) are available:
|
||||
|
||||
- [`scrcpy-win32-v1.6.zip`][direct-win32]
|
||||
_(SHA-256: 4ca0c5924ab2ebf19b70f6598b2e546f65ba469a72ded2d1b213df3380fb46b1)_
|
||||
- [`scrcpy-win64-v1.6.zip`][direct-win64]
|
||||
_(SHA-256: f66b7eace8dd6537a9a27176fd824704a284d8e82077ccc903344396043f90c9)_
|
||||
- [`scrcpy-win32-v1.5.zip`][direct-win32]
|
||||
_(SHA-256: 46ae0d4c1c6bd049ec4a30080d2ad91a32b31d3f758afdca2c3a915ecabf02c1)_
|
||||
- [`scrcpy-win64-v1.5.zip`][direct-win64]
|
||||
_(SHA-256: 89daa07325129617cf943a84bc4e304ee5e57118416fe265b9b5d4a1bf87c501)_
|
||||
|
||||
[direct-win32]: https://github.com/Genymobile/scrcpy/releases/download/v1.6/scrcpy-win32-v1.6.zip
|
||||
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.6/scrcpy-win64-v1.6.zip
|
||||
[direct-win32]: https://github.com/Genymobile/scrcpy/releases/download/v1.5-fixversion/scrcpy-win32-v1.5.zip
|
||||
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.5-fixversion/scrcpy-win64-v1.5.zip
|
||||
|
||||
You can also [build the app manually][BUILD].
|
||||
|
||||
@@ -162,7 +162,7 @@ It is possible to record the screen while mirroring:
|
||||
|
||||
```bash
|
||||
scrcpy --record file.mp4
|
||||
scrcpy -r file.mkv
|
||||
scrcpy -r file.mp4
|
||||
```
|
||||
|
||||
"Skipped frames" are recorded, even if they are not displayed in real time (for
|
||||
@@ -196,16 +196,6 @@ scrcpy -f # short version
|
||||
Fullscreen can then be toggled dynamically with `Ctrl`+`f`.
|
||||
|
||||
|
||||
### Always on top
|
||||
|
||||
The window of app can always be above others by:
|
||||
|
||||
```bash
|
||||
scrcpy --always-on-top
|
||||
scrcpy -T # short version
|
||||
```
|
||||
|
||||
|
||||
### Show touches
|
||||
|
||||
For presentations, it may be useful to show physical touches (on the physical
|
||||
|
||||
@@ -135,6 +135,11 @@ process_t adb_install(const char *serial, const char *local) {
|
||||
return proc;
|
||||
}
|
||||
|
||||
process_t adb_remove_path(const char *serial, const char *path) {
|
||||
const char *const adb_cmd[] = {"shell", "rm", path};
|
||||
return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
||||
}
|
||||
|
||||
SDL_bool process_check_success(process_t proc, const char *name) {
|
||||
if (proc == PROCESS_NONE) {
|
||||
LOGE("Could not execute \"%s\"", name);
|
||||
|
||||
@@ -3,33 +3,33 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <SDL2/SDL_stdinc.h>
|
||||
#include <SDL2/SDL_platform.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
# include <winsock2.h> // not needed here, but must never be included AFTER windows.h
|
||||
# include <windows.h>
|
||||
# define PRIexitcode "lu"
|
||||
// <https://stackoverflow.com/a/44383330/1987178>
|
||||
#ifdef _WIN32
|
||||
# define PRIexitcode "lu"
|
||||
# ifdef _WIN64
|
||||
# define PRIsizet PRIu64
|
||||
# else
|
||||
# define PRIsizet PRIu32
|
||||
# endif
|
||||
#else
|
||||
# define PRIsizet "zu"
|
||||
# define PRIexitcode "d"
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
# include <winsock2.h> // not needed here, but must never be included AFTER windows.h
|
||||
# include <windows.h>
|
||||
# define PROCESS_NONE NULL
|
||||
typedef HANDLE process_t;
|
||||
typedef DWORD exit_code_t;
|
||||
|
||||
#else
|
||||
|
||||
# include <sys/types.h>
|
||||
# define PRIsizet "zu"
|
||||
# define PRIexitcode "d"
|
||||
# define PROCESS_NONE -1
|
||||
typedef pid_t process_t;
|
||||
typedef int exit_code_t;
|
||||
|
||||
#endif
|
||||
|
||||
# define NO_EXIT_CODE -1
|
||||
|
||||
enum process_result {
|
||||
@@ -49,6 +49,7 @@ process_t adb_reverse(const char *serial, const char *device_socket_name, uint16
|
||||
process_t adb_reverse_remove(const char *serial, const char *device_socket_name);
|
||||
process_t adb_push(const char *serial, const char *local, const char *remote);
|
||||
process_t adb_install(const char *serial, const char *local);
|
||||
process_t adb_remove_path(const char *serial, const char *path);
|
||||
|
||||
// convenience function to wait for a successful process execution
|
||||
// automatically log process errors with the provided process name
|
||||
|
||||
@@ -13,8 +13,8 @@ struct size {
|
||||
};
|
||||
|
||||
struct point {
|
||||
Sint32 x;
|
||||
Sint32 y;
|
||||
Uint16 x;
|
||||
Uint16 y;
|
||||
};
|
||||
|
||||
struct position {
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
#include "log.h"
|
||||
|
||||
static void write_position(Uint8 *buf, const struct position *position) {
|
||||
buffer_write32be(&buf[0], position->point.x);
|
||||
buffer_write32be(&buf[4], position->point.y);
|
||||
buffer_write16be(&buf[8], position->screen_size.width);
|
||||
buffer_write16be(&buf[10], position->screen_size.height);
|
||||
buffer_write16be(&buf[0], position->point.x);
|
||||
buffer_write16be(&buf[2], position->point.y);
|
||||
buffer_write16be(&buf[4], position->screen_size.width);
|
||||
buffer_write16be(&buf[6], position->screen_size.height);
|
||||
}
|
||||
|
||||
int control_event_serialize(const struct control_event *event, unsigned char *buf) {
|
||||
@@ -23,7 +23,7 @@ int control_event_serialize(const struct control_event *event, unsigned char *bu
|
||||
buffer_write32be(&buf[6], event->keycode_event.metastate);
|
||||
return 10;
|
||||
case CONTROL_EVENT_TYPE_TEXT: {
|
||||
// write length (2 bytes) + string (non nul-terminated)
|
||||
// write length (1 byte) + date (non nul-terminated)
|
||||
size_t len = strlen(event->text_event.text);
|
||||
if (len > TEXT_MAX_LENGTH) {
|
||||
// injecting a text takes time, so limit the text length
|
||||
@@ -37,12 +37,12 @@ int control_event_serialize(const struct control_event *event, unsigned char *bu
|
||||
buf[1] = event->mouse_event.action;
|
||||
buffer_write32be(&buf[2], event->mouse_event.buttons);
|
||||
write_position(&buf[6], &event->mouse_event.position);
|
||||
return 18;
|
||||
return 14;
|
||||
case CONTROL_EVENT_TYPE_SCROLL:
|
||||
write_position(&buf[1], &event->scroll_event.position);
|
||||
buffer_write32be(&buf[13], (Uint32) event->scroll_event.hscroll);
|
||||
buffer_write32be(&buf[17], (Uint32) event->scroll_event.vscroll);
|
||||
return 21;
|
||||
buffer_write32be(&buf[9], (Uint32) event->scroll_event.hscroll);
|
||||
buffer_write32be(&buf[13], (Uint32) event->scroll_event.vscroll);
|
||||
return 17;
|
||||
case CONTROL_EVENT_TYPE_COMMAND:
|
||||
buf[1] = event->command_event.action;
|
||||
return 2;
|
||||
|
||||
@@ -284,8 +284,7 @@ run_quit:
|
||||
run_finally_close_input:
|
||||
avformat_close_input(&format_ctx);
|
||||
run_finally_free_avio_ctx:
|
||||
av_free(avio_ctx->buffer);
|
||||
av_free(avio_ctx);
|
||||
av_freep(&avio_ctx);
|
||||
run_finally_free_format_ctx:
|
||||
avformat_free_context(format_ctx);
|
||||
run_finally_close_codec:
|
||||
|
||||
@@ -18,15 +18,9 @@ static void convert_to_renderer_coordinates(SDL_Renderer *renderer, int *x, int
|
||||
*y = (int) (*y / scale_y) - viewport.y;
|
||||
}
|
||||
|
||||
static struct point get_mouse_point(struct screen *screen) {
|
||||
int x;
|
||||
int y;
|
||||
SDL_GetMouseState(&x, &y);
|
||||
convert_to_renderer_coordinates(screen->renderer, &x, &y);
|
||||
return (struct point) {
|
||||
.x = x,
|
||||
.y = y,
|
||||
};
|
||||
static void get_mouse_point(struct screen *screen, int *x, int *y) {
|
||||
SDL_GetMouseState(x, y);
|
||||
convert_to_renderer_coordinates(screen->renderer, x, y);
|
||||
}
|
||||
|
||||
static const int ACTION_DOWN = 1;
|
||||
@@ -279,6 +273,9 @@ static SDL_bool is_outside_device_screen(struct input_manager *input_manager,
|
||||
|
||||
void input_manager_process_mouse_button(struct input_manager *input_manager,
|
||||
const SDL_MouseButtonEvent *event) {
|
||||
SDL_bool outside_device_screen = is_outside_device_screen(input_manager,
|
||||
event->x,
|
||||
event->y);
|
||||
if (event->type == SDL_MOUSEBUTTONDOWN) {
|
||||
if (event->button == SDL_BUTTON_RIGHT) {
|
||||
press_back_or_turn_screen_on(input_manager->controller);
|
||||
@@ -289,18 +286,19 @@ void input_manager_process_mouse_button(struct input_manager *input_manager,
|
||||
return;
|
||||
}
|
||||
// double-click on black borders resize to fit the device screen
|
||||
if (event->button == SDL_BUTTON_LEFT && event->clicks == 2) {
|
||||
SDL_bool outside= is_outside_device_screen(input_manager,
|
||||
event->x,
|
||||
event->y);
|
||||
if (outside) {
|
||||
screen_resize_to_fit(input_manager->screen);
|
||||
return;
|
||||
}
|
||||
if (event->button == SDL_BUTTON_LEFT && event->clicks == 2
|
||||
&& outside_device_screen) {
|
||||
screen_resize_to_fit(input_manager->screen);
|
||||
return;
|
||||
}
|
||||
// otherwise, send the click event to the device
|
||||
}
|
||||
|
||||
if (outside_device_screen) {
|
||||
// ignore
|
||||
return;
|
||||
}
|
||||
|
||||
struct control_event control_event;
|
||||
if (mouse_button_from_sdl_to_android(event, input_manager->screen->frame_size, &control_event)) {
|
||||
if (!controller_push_event(input_manager->controller, &control_event)) {
|
||||
@@ -311,9 +309,22 @@ void input_manager_process_mouse_button(struct input_manager *input_manager,
|
||||
|
||||
void input_manager_process_mouse_wheel(struct input_manager *input_manager,
|
||||
const SDL_MouseWheelEvent *event) {
|
||||
int x;
|
||||
int y;
|
||||
get_mouse_point(input_manager->screen, &x, &y);
|
||||
if (is_outside_device_screen(input_manager, x, y)) {
|
||||
// ignore
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_assert_release(x >= 0 && x < 0x10000 && y >= 0 && y < 0x10000);
|
||||
|
||||
struct position position = {
|
||||
.screen_size = input_manager->screen->frame_size,
|
||||
.point = get_mouse_point(input_manager->screen),
|
||||
.point = {
|
||||
.x = (Uint16) x,
|
||||
.y = (Uint16) y,
|
||||
},
|
||||
};
|
||||
struct control_event control_event;
|
||||
if (mouse_wheel_from_sdl_to_android(event, position, &control_event)) {
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <SDL2/SDL_log.h>
|
||||
|
||||
#define LOGV(...) SDL_LogVerbose(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||
#define LOGD(...) SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||
#define LOGI(...) SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||
#define LOGW(...) SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||
|
||||
@@ -7,13 +7,11 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "recorder.h"
|
||||
|
||||
struct args {
|
||||
const char *serial;
|
||||
const char *crop;
|
||||
const char *record_filename;
|
||||
enum recorder_format record_format;
|
||||
SDL_bool fullscreen;
|
||||
SDL_bool help;
|
||||
SDL_bool version;
|
||||
@@ -21,7 +19,6 @@ struct args {
|
||||
Uint16 port;
|
||||
Uint16 max_size;
|
||||
Uint32 bit_rate;
|
||||
SDL_bool always_on_top;
|
||||
};
|
||||
|
||||
static void usage(const char *arg0) {
|
||||
@@ -44,9 +41,6 @@ static void usage(const char *arg0) {
|
||||
" -f, --fullscreen\n"
|
||||
" Start in fullscreen.\n"
|
||||
"\n"
|
||||
" -F, --record-format\n"
|
||||
" Force recording format (either mp4 or mkv).\n"
|
||||
"\n"
|
||||
" -h, --help\n"
|
||||
" Print this help.\n"
|
||||
"\n"
|
||||
@@ -62,8 +56,6 @@ static void usage(const char *arg0) {
|
||||
"\n"
|
||||
" -r, --record file.mp4\n"
|
||||
" Record screen to file.\n"
|
||||
" The format is determined by the -F/--record-format option if\n"
|
||||
" set, or by the file extension (.mp4 or .mkv).\n"
|
||||
"\n"
|
||||
" -s, --serial\n"
|
||||
" The device serial number. Mandatory only if several devices\n"
|
||||
@@ -73,9 +65,6 @@ static void usage(const char *arg0) {
|
||||
" Enable \"show touches\" on start, disable on quit.\n"
|
||||
" It only shows physical touches (not clicks from scrcpy).\n"
|
||||
"\n"
|
||||
" -T, --always-on-top\n"
|
||||
" Make scrcpy window always on top (above other windows).\n"
|
||||
"\n"
|
||||
" -v, --version\n"
|
||||
" Print the version of scrcpy.\n"
|
||||
"\n"
|
||||
@@ -215,54 +204,22 @@ static SDL_bool parse_port(char *optarg, Uint16 *port) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
parse_record_format(const char *optarg, enum recorder_format *format) {
|
||||
if (!strcmp(optarg, "mp4")) {
|
||||
*format = RECORDER_FORMAT_MP4;
|
||||
return SDL_TRUE;
|
||||
}
|
||||
if (!strcmp(optarg, "mkv")) {
|
||||
*format = RECORDER_FORMAT_MKV;
|
||||
return SDL_TRUE;
|
||||
}
|
||||
LOGE("Unsupported format: %s (expected mp4 or mkv)", optarg);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static enum recorder_format
|
||||
guess_record_format(const char *filename) {
|
||||
size_t len = strlen(filename);
|
||||
if (len < 4) {
|
||||
return 0;
|
||||
}
|
||||
const char *ext = &filename[len - 4];
|
||||
if (!strcmp(ext, ".mp4")) {
|
||||
return RECORDER_FORMAT_MP4;
|
||||
}
|
||||
if (!strcmp(ext, ".mkv")) {
|
||||
return RECORDER_FORMAT_MKV;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
|
||||
static const struct option long_options[] = {
|
||||
{"always-on-top", no_argument, NULL, 'T'},
|
||||
{"bit-rate", required_argument, NULL, 'b'},
|
||||
{"crop", required_argument, NULL, 'c'},
|
||||
{"fullscreen", no_argument, NULL, 'f'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"max-size", required_argument, NULL, 'm'},
|
||||
{"port", required_argument, NULL, 'p'},
|
||||
{"record", required_argument, NULL, 'r'},
|
||||
{"record-format", required_argument, NULL, 'f'},
|
||||
{"serial", required_argument, NULL, 's'},
|
||||
{"show-touches", no_argument, NULL, 't'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{NULL, 0, NULL, 0 },
|
||||
{"bit-rate", required_argument, NULL, 'b'},
|
||||
{"crop", required_argument, NULL, 'c'},
|
||||
{"fullscreen", no_argument, NULL, 'f'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"max-size", required_argument, NULL, 'm'},
|
||||
{"port", required_argument, NULL, 'p'},
|
||||
{"record", required_argument, NULL, 'r'},
|
||||
{"serial", required_argument, NULL, 's'},
|
||||
{"show-touches", no_argument, NULL, 't'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{NULL, 0, NULL, 0 },
|
||||
};
|
||||
int c;
|
||||
while ((c = getopt_long(argc, argv, "b:c:fF:hm:p:r:s:tTv", long_options, NULL)) != -1) {
|
||||
while ((c = getopt_long(argc, argv, "b:c:fhm:p:r:s:tv", long_options, NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'b':
|
||||
if (!parse_bit_rate(optarg, &args->bit_rate)) {
|
||||
@@ -275,11 +232,6 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
|
||||
case 'f':
|
||||
args->fullscreen = SDL_TRUE;
|
||||
break;
|
||||
case 'F':
|
||||
if (!parse_record_format(optarg, &args->record_format)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
args->help = SDL_TRUE;
|
||||
break;
|
||||
@@ -302,9 +254,6 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
|
||||
case 't':
|
||||
args->show_touches = SDL_TRUE;
|
||||
break;
|
||||
case 'T':
|
||||
args->always_on_top = SDL_TRUE;
|
||||
break;
|
||||
case 'v':
|
||||
args->version = SDL_TRUE;
|
||||
break;
|
||||
@@ -319,21 +268,6 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
|
||||
LOGE("Unexpected additional argument: %s", argv[index]);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (args->record_format && !args->record_filename) {
|
||||
LOGE("Record format specified without recording");
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (args->record_filename && !args->record_format) {
|
||||
args->record_format = guess_record_format(args->record_filename);
|
||||
if (!args->record_format) {
|
||||
LOGE("No format specified for \"%s\" (try with -F mkv)",
|
||||
args->record_filename);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
@@ -348,14 +282,12 @@ int main(int argc, char *argv[]) {
|
||||
.serial = NULL,
|
||||
.crop = NULL,
|
||||
.record_filename = NULL,
|
||||
.record_format = 0,
|
||||
.help = SDL_FALSE,
|
||||
.version = SDL_FALSE,
|
||||
.show_touches = SDL_FALSE,
|
||||
.port = DEFAULT_LOCAL_PORT,
|
||||
.max_size = DEFAULT_MAX_SIZE,
|
||||
.bit_rate = DEFAULT_BIT_RATE,
|
||||
.always_on_top = SDL_FALSE,
|
||||
};
|
||||
if (!parse_args(&args, argc, argv)) {
|
||||
return 1;
|
||||
@@ -388,12 +320,10 @@ int main(int argc, char *argv[]) {
|
||||
.crop = args.crop,
|
||||
.port = args.port,
|
||||
.record_filename = args.record_filename,
|
||||
.record_format = args.record_format,
|
||||
.max_size = args.max_size,
|
||||
.bit_rate = args.bit_rate,
|
||||
.show_touches = args.show_touches,
|
||||
.fullscreen = args.fullscreen,
|
||||
.always_on_top = args.always_on_top,
|
||||
};
|
||||
int res = scrcpy(&options) ? 0 : 1;
|
||||
|
||||
|
||||
@@ -1,24 +1,11 @@
|
||||
#include "recorder.h"
|
||||
|
||||
#include <libavutil/time.h>
|
||||
#include <SDL2/SDL_assert.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
|
||||
// In ffmpeg/doc/APIchanges:
|
||||
// 2016-04-11 - 6f69f7a / 9200514 - lavf 57.33.100 / 57.5.0 - avformat.h
|
||||
// Add AVStream.codecpar, deprecate AVStream.codec.
|
||||
#if (LIBAVFORMAT_VERSION_MICRO >= 100 /* FFmpeg */ && \
|
||||
LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 33, 100)) \
|
||||
|| (LIBAVFORMAT_VERSION_MICRO < 100 && /* Libav */ \
|
||||
LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 5, 0))
|
||||
# define LAVF_NEW_CODEC_API
|
||||
#endif
|
||||
|
||||
static const AVRational SCRCPY_TIME_BASE = {1, 1000000}; // timestamps in us
|
||||
|
||||
static const AVOutputFormat *find_muxer(const char *name) {
|
||||
static const AVOutputFormat *find_mp4_muxer(void) {
|
||||
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100)
|
||||
void *opaque = NULL;
|
||||
#endif
|
||||
@@ -30,13 +17,11 @@ static const AVOutputFormat *find_muxer(const char *name) {
|
||||
oformat = av_oformat_next(oformat);
|
||||
#endif
|
||||
// until null or with name "mp4"
|
||||
} while (oformat && strcmp(oformat->name, name));
|
||||
} while (oformat && strcmp(oformat->name, "mp4"));
|
||||
return oformat;
|
||||
}
|
||||
|
||||
SDL_bool recorder_init(struct recorder *recorder,
|
||||
const char *filename,
|
||||
enum recorder_format format,
|
||||
SDL_bool recorder_init(struct recorder *recorder, const char *filename,
|
||||
struct size declared_frame_size) {
|
||||
recorder->filename = SDL_strdup(filename);
|
||||
if (!recorder->filename) {
|
||||
@@ -44,9 +29,7 @@ SDL_bool recorder_init(struct recorder *recorder,
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
recorder->format = format;
|
||||
recorder->declared_frame_size = declared_frame_size;
|
||||
recorder->header_written = SDL_FALSE;
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
@@ -55,21 +38,10 @@ void recorder_destroy(struct recorder *recorder) {
|
||||
SDL_free(recorder->filename);
|
||||
}
|
||||
|
||||
static const char *
|
||||
recorder_get_format_name(enum recorder_format format) {
|
||||
switch (format) {
|
||||
case RECORDER_FORMAT_MP4: return "mp4";
|
||||
case RECORDER_FORMAT_MKV: return "matroska";
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_bool recorder_open(struct recorder *recorder, AVCodec *input_codec) {
|
||||
const char *format_name = recorder_get_format_name(recorder->format);
|
||||
SDL_assert(format_name);
|
||||
const AVOutputFormat *format = find_muxer(format_name);
|
||||
if (!format) {
|
||||
LOGE("Could not find muxer");
|
||||
const AVOutputFormat *mp4 = find_mp4_muxer();
|
||||
if (!mp4) {
|
||||
LOGE("Could not find mp4 muxer");
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -83,7 +55,7 @@ SDL_bool recorder_open(struct recorder *recorder, AVCodec *input_codec) {
|
||||
// returns (on purpose) a pointer-to-const, but AVFormatContext.oformat
|
||||
// still expects a pointer-to-non-const (it has not be updated accordingly)
|
||||
// <https://github.com/FFmpeg/FFmpeg/commit/0694d8702421e7aff1340038559c438b61bb30dd>
|
||||
recorder->ctx->oformat = (AVOutputFormat *) format;
|
||||
recorder->ctx->oformat = (AVOutputFormat *) mp4;
|
||||
|
||||
AVStream *ostream = avformat_new_stream(recorder->ctx, input_codec);
|
||||
if (!ostream) {
|
||||
@@ -91,7 +63,13 @@ SDL_bool recorder_open(struct recorder *recorder, AVCodec *input_codec) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
#ifdef LAVF_NEW_CODEC_API
|
||||
// In ffmpeg/doc/APIchanges:
|
||||
// 2016-04-11 - 6f69f7a / 9200514 - lavf 57.33.100 / 57.5.0 - avformat.h
|
||||
// Add AVStream.codecpar, deprecate AVStream.codec.
|
||||
#if (LIBAVFORMAT_VERSION_MICRO >= 100 /* FFmpeg */ && \
|
||||
LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 33, 100)) \
|
||||
|| (LIBAVFORMAT_VERSION_MICRO < 100 && /* Libav */ \
|
||||
LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 5, 0))
|
||||
ostream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
||||
ostream->codecpar->codec_id = input_codec->id;
|
||||
ostream->codecpar->format = AV_PIX_FMT_YUV420P;
|
||||
@@ -103,7 +81,9 @@ SDL_bool recorder_open(struct recorder *recorder, AVCodec *input_codec) {
|
||||
ostream->codec->pix_fmt = AV_PIX_FMT_YUV420P;
|
||||
ostream->codec->width = recorder->declared_frame_size.width;
|
||||
ostream->codec->height = recorder->declared_frame_size.height;
|
||||
ostream->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
|
||||
#endif
|
||||
ostream->time_base = (AVRational) {1, 1000000}; // timestamps in us
|
||||
|
||||
int ret = avio_open(&recorder->ctx->pb, recorder->filename,
|
||||
AVIO_FLAG_WRITE);
|
||||
@@ -114,7 +94,13 @@ SDL_bool recorder_open(struct recorder *recorder, AVCodec *input_codec) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
LOGI("Recording started to %s file: %s", format_name, recorder->filename);
|
||||
ret = avformat_write_header(recorder->ctx, NULL);
|
||||
if (ret < 0) {
|
||||
LOGE("Failed to write header to %s", recorder->filename);
|
||||
avio_closep(&recorder->ctx->pb);
|
||||
avformat_free_context(recorder->ctx);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
@@ -126,59 +112,8 @@ void recorder_close(struct recorder *recorder) {
|
||||
}
|
||||
avio_close(recorder->ctx->pb);
|
||||
avformat_free_context(recorder->ctx);
|
||||
|
||||
const char *format_name = recorder_get_format_name(recorder->format);
|
||||
LOGI("Recording complete to %s file: %s", format_name, recorder->filename);
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
recorder_write_header(struct recorder *recorder, AVPacket *packet) {
|
||||
AVStream *ostream = recorder->ctx->streams[0];
|
||||
|
||||
uint8_t *extradata = av_malloc(packet->size * sizeof(uint8_t));
|
||||
if (!extradata) {
|
||||
LOGC("Cannot allocate extradata");
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
// copy the first packet to the extra data
|
||||
memcpy(extradata, packet->data, packet->size);
|
||||
|
||||
#ifdef LAVF_NEW_CODEC_API
|
||||
ostream->codecpar->extradata = extradata;
|
||||
ostream->codecpar->extradata_size = packet->size;
|
||||
#else
|
||||
ostream->codec->extradata = extradata;
|
||||
ostream->codec->extradata_size = packet->size;
|
||||
#endif
|
||||
|
||||
int ret = avformat_write_header(recorder->ctx, NULL);
|
||||
if (ret < 0) {
|
||||
LOGE("Failed to write header to %s", recorder->filename);
|
||||
SDL_free(extradata);
|
||||
avio_closep(&recorder->ctx->pb);
|
||||
avformat_free_context(recorder->ctx);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
recorder_rescale_packet(struct recorder *recorder, AVPacket *packet) {
|
||||
AVStream *ostream = recorder->ctx->streams[0];
|
||||
av_packet_rescale_ts(packet, SCRCPY_TIME_BASE, ostream->time_base);
|
||||
}
|
||||
|
||||
SDL_bool recorder_write(struct recorder *recorder, AVPacket *packet) {
|
||||
if (!recorder->header_written) {
|
||||
SDL_bool ok = recorder_write_header(recorder, packet);
|
||||
if (!ok) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
recorder->header_written = SDL_TRUE;
|
||||
}
|
||||
|
||||
recorder_rescale_packet(recorder, packet);
|
||||
return av_write_frame(recorder->ctx, packet) >= 0;
|
||||
}
|
||||
|
||||
@@ -6,24 +6,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
enum recorder_format {
|
||||
RECORDER_FORMAT_MP4 = 1,
|
||||
RECORDER_FORMAT_MKV,
|
||||
};
|
||||
|
||||
struct recorder {
|
||||
char *filename;
|
||||
enum recorder_format format;
|
||||
AVFormatContext *ctx;
|
||||
struct size declared_frame_size;
|
||||
SDL_bool header_written;
|
||||
};
|
||||
|
||||
SDL_bool recorder_init(struct recorder *recoder,
|
||||
const char *filename,
|
||||
enum recorder_format format,
|
||||
SDL_bool recorder_init(struct recorder *recoder, const char *filename,
|
||||
struct size declared_frame_size);
|
||||
|
||||
void recorder_destroy(struct recorder *recorder);
|
||||
|
||||
SDL_bool recorder_open(struct recorder *recorder, AVCodec *input_codec);
|
||||
|
||||
@@ -139,40 +139,6 @@ static void wait_show_touches(process_t process) {
|
||||
process_check_success(process, "show_touches");
|
||||
}
|
||||
|
||||
static SDL_LogPriority sdl_priority_from_av_level(int level) {
|
||||
switch (level) {
|
||||
case AV_LOG_PANIC:
|
||||
case AV_LOG_FATAL:
|
||||
return SDL_LOG_PRIORITY_CRITICAL;
|
||||
case AV_LOG_ERROR:
|
||||
return SDL_LOG_PRIORITY_ERROR;
|
||||
case AV_LOG_WARNING:
|
||||
return SDL_LOG_PRIORITY_WARN;
|
||||
case AV_LOG_INFO:
|
||||
return SDL_LOG_PRIORITY_INFO;
|
||||
}
|
||||
// do not forward others, which are too verbose
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
av_log_callback(void *avcl, int level, const char *fmt, va_list vl) {
|
||||
SDL_LogPriority priority = sdl_priority_from_av_level(level);
|
||||
if (priority == 0) {
|
||||
return;
|
||||
}
|
||||
char *local_fmt = SDL_malloc(strlen(fmt) + 10);
|
||||
if (!local_fmt) {
|
||||
LOGC("Cannot allocate string");
|
||||
return;
|
||||
}
|
||||
// strcpy is safe here, the destination is large enough
|
||||
strcpy(local_fmt, "[FFmpeg] ");
|
||||
strcpy(local_fmt + 9, fmt);
|
||||
SDL_LogMessageV(SDL_LOG_CATEGORY_VIDEO, priority, local_fmt, vl);
|
||||
SDL_free(local_fmt);
|
||||
}
|
||||
|
||||
SDL_bool scrcpy(const struct scrcpy_options *options) {
|
||||
SDL_bool send_frame_meta = !!options->record_filename;
|
||||
if (!server_start(&server, options->serial, options->port,
|
||||
@@ -229,10 +195,7 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
|
||||
|
||||
struct recorder *rec = NULL;
|
||||
if (options->record_filename) {
|
||||
if (!recorder_init(&recorder,
|
||||
options->record_filename,
|
||||
options->record_format,
|
||||
frame_size)) {
|
||||
if (!recorder_init(&recorder, options->record_filename, frame_size)) {
|
||||
ret = SDL_FALSE;
|
||||
server_stop(&server);
|
||||
goto finally_destroy_file_handler;
|
||||
@@ -240,8 +203,6 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
|
||||
rec = &recorder;
|
||||
}
|
||||
|
||||
av_log_set_callback(av_log_callback);
|
||||
|
||||
decoder_init(&decoder, &frames, device_socket, rec);
|
||||
|
||||
// now we consumed the header values, the socket receives the video stream
|
||||
@@ -262,7 +223,7 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
|
||||
goto finally_destroy_controller;
|
||||
}
|
||||
|
||||
if (!screen_init_rendering(&screen, device_name, frame_size, options->always_on_top)) {
|
||||
if (!screen_init_rendering(&screen, device_name, frame_size)) {
|
||||
ret = SDL_FALSE;
|
||||
goto finally_stop_and_join_controller;
|
||||
}
|
||||
|
||||
@@ -2,19 +2,16 @@
|
||||
#define SCRCPY_H
|
||||
|
||||
#include <SDL2/SDL_stdinc.h>
|
||||
#include <recorder.h>
|
||||
|
||||
struct scrcpy_options {
|
||||
const char *serial;
|
||||
const char *crop;
|
||||
const char *record_filename;
|
||||
enum recorder_format record_format;
|
||||
Uint16 port;
|
||||
Uint16 max_size;
|
||||
Uint32 bit_rate;
|
||||
SDL_bool show_touches;
|
||||
SDL_bool fullscreen;
|
||||
SDL_bool always_on_top;
|
||||
};
|
||||
|
||||
SDL_bool scrcpy(const struct scrcpy_options *options);
|
||||
|
||||
@@ -30,9 +30,6 @@ SDL_bool sdl_init_and_configure(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Do not disable the screensaver when scrcpy is running
|
||||
SDL_EnableScreenSaver();
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
@@ -144,10 +141,7 @@ static inline SDL_Texture *create_texture(SDL_Renderer *renderer, struct size fr
|
||||
frame_size.width, frame_size.height);
|
||||
}
|
||||
|
||||
SDL_bool screen_init_rendering(struct screen *screen,
|
||||
const char *device_name,
|
||||
struct size frame_size,
|
||||
SDL_bool always_on_top) {
|
||||
SDL_bool screen_init_rendering(struct screen *screen, const char *device_name, struct size frame_size) {
|
||||
screen->frame_size = frame_size;
|
||||
|
||||
struct size window_size = get_initial_optimal_size(frame_size);
|
||||
@@ -155,10 +149,6 @@ SDL_bool screen_init_rendering(struct screen *screen,
|
||||
#ifdef HIDPI_SUPPORT
|
||||
window_flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
#endif
|
||||
if (always_on_top) {
|
||||
window_flags |= SDL_WINDOW_ALWAYS_ON_TOP;
|
||||
}
|
||||
|
||||
screen->window = SDL_CreateWindow(device_name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
window_size.width, window_size.height, window_flags);
|
||||
if (!screen->window) {
|
||||
|
||||
@@ -43,8 +43,7 @@ void screen_init(struct screen *screen);
|
||||
// initialize screen, create window, renderer and texture (window is hidden)
|
||||
SDL_bool screen_init_rendering(struct screen *screen,
|
||||
const char *device_name,
|
||||
struct size frame_size,
|
||||
SDL_bool always_on_top);
|
||||
struct size frame_size);
|
||||
|
||||
// show the window
|
||||
void screen_show_window(struct screen *screen);
|
||||
|
||||
@@ -34,6 +34,11 @@ static SDL_bool push_server(const char *serial) {
|
||||
return process_check_success(process, "adb push");
|
||||
}
|
||||
|
||||
static SDL_bool remove_server(const char *serial) {
|
||||
process_t process = adb_remove_path(serial, DEVICE_SERVER_PATH);
|
||||
return process_check_success(process, "adb shell rm");
|
||||
}
|
||||
|
||||
static SDL_bool enable_tunnel_reverse(const char *serial, Uint16 local_port) {
|
||||
process_t process = adb_reverse(serial, SOCKET_NAME, local_port);
|
||||
return process_check_success(process, "adb reverse");
|
||||
@@ -88,7 +93,7 @@ static process_t execute_server(const char *serial,
|
||||
max_size_string,
|
||||
bit_rate_string,
|
||||
tunnel_forward ? "true" : "false",
|
||||
crop ? crop : "-",
|
||||
crop ? crop : "''",
|
||||
send_frame_meta ? "true" : "false",
|
||||
};
|
||||
return adb_execute(serial, cmd, sizeof(cmd) / sizeof(cmd[0]));
|
||||
@@ -162,6 +167,8 @@ SDL_bool server_start(struct server *server, const char *serial,
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
server->server_copied_to_device = SDL_TRUE;
|
||||
|
||||
if (!enable_tunnel(server)) {
|
||||
SDL_free((void *) server->serial);
|
||||
return SDL_FALSE;
|
||||
@@ -222,6 +229,10 @@ socket_t server_connect_to(struct server *server) {
|
||||
close_socket(&server->server_socket);
|
||||
}
|
||||
|
||||
// the server is started, we can clean up the jar from the temporary folder
|
||||
remove_server(server->serial); // ignore failure
|
||||
server->server_copied_to_device = SDL_FALSE;
|
||||
|
||||
// we don't need the adb tunnel anymore
|
||||
disable_tunnel(server); // ignore failure
|
||||
server->tunnel_enabled = SDL_FALSE;
|
||||
@@ -243,6 +254,10 @@ void server_stop(struct server *server) {
|
||||
// ignore failure
|
||||
disable_tunnel(server);
|
||||
}
|
||||
|
||||
if (server->server_copied_to_device) {
|
||||
remove_server(server->serial); // ignore failure
|
||||
}
|
||||
}
|
||||
|
||||
void server_destroy(struct server *server) {
|
||||
|
||||
@@ -13,6 +13,7 @@ struct server {
|
||||
SDL_bool tunnel_enabled;
|
||||
SDL_bool tunnel_forward; // use "adb forward" instead of "adb reverse"
|
||||
SDL_bool send_frame_meta; // request frame PTS to be able to record properly
|
||||
SDL_bool server_copied_to_device;
|
||||
};
|
||||
|
||||
#define SERVER_INITIALIZER { \
|
||||
@@ -24,6 +25,7 @@ struct server {
|
||||
.tunnel_enabled = SDL_FALSE, \
|
||||
.tunnel_forward = SDL_FALSE, \
|
||||
.send_frame_meta = SDL_FALSE, \
|
||||
.server_copied_to_device = SDL_FALSE, \
|
||||
}
|
||||
|
||||
// init default values
|
||||
|
||||
@@ -3,11 +3,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <windows.h>
|
||||
# include <tchar.h>
|
||||
#endif
|
||||
|
||||
size_t xstrncpy(char *dest, const char *src, size_t n) {
|
||||
size_t i;
|
||||
for (i = 0; i < n - 1 && src[i] != '\0'; ++i)
|
||||
@@ -52,22 +47,3 @@ char *strquote(const char *src) {
|
||||
quoted[len + 2] = '\0';
|
||||
return quoted;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
wchar_t *utf8_to_wide_char(const char *utf8) {
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
|
||||
if (!len) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wchar_t *wide = malloc(len * sizeof(wchar_t));
|
||||
if (!wide) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wide, len);
|
||||
return wide;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -20,10 +20,4 @@ size_t xstrjoin(char *dst, const char *const tokens[], char sep, size_t n);
|
||||
// returns the new allocated string, to be freed by the caller
|
||||
char *strquote(const char *src);
|
||||
|
||||
#ifdef _WIN32
|
||||
// convert a UTF-8 string to a wchar_t string
|
||||
// returns the new allocated string, to be freed by the caller
|
||||
wchar_t *utf8_to_wide_char(const char *utf8);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -18,7 +18,7 @@ static int build_cmd(char *cmd, size_t len, const char *const argv[]) {
|
||||
}
|
||||
|
||||
enum process_result cmd_execute(const char *path, const char *const argv[], HANDLE *handle) {
|
||||
STARTUPINFOW si;
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
memset(&si, 0, sizeof(si));
|
||||
si.cb = sizeof(si);
|
||||
@@ -29,19 +29,12 @@ enum process_result cmd_execute(const char *path, const char *const argv[], HAND
|
||||
return PROCESS_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
wchar_t *wide = utf8_to_wide_char(cmd);
|
||||
if (!wide) {
|
||||
LOGC("Cannot allocate wide char string");
|
||||
return PROCESS_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS_NOCONSOLE
|
||||
int flags = CREATE_NO_WINDOW;
|
||||
#else
|
||||
int flags = 0;
|
||||
#endif
|
||||
if (!CreateProcessW(NULL, wide, NULL, NULL, FALSE, flags, NULL, NULL, &si, &pi)) {
|
||||
free(wide);
|
||||
if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE, flags, NULL, NULL, &si, &pi)) {
|
||||
*handle = NULL;
|
||||
if (GetLastError() == ERROR_FILE_NOT_FOUND) {
|
||||
return PROCESS_ERROR_MISSING_BINARY;
|
||||
@@ -49,7 +42,6 @@ enum process_result cmd_execute(const char *path, const char *const argv[], HAND
|
||||
return PROCESS_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
free(wide);
|
||||
*handle = pi.hProcess;
|
||||
return PROCESS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -87,13 +87,13 @@ static void test_serialize_mouse_event(void) {
|
||||
|
||||
unsigned char buf[SERIALIZED_EVENT_MAX_SIZE];
|
||||
int size = control_event_serialize(&event, buf);
|
||||
assert(size == 18);
|
||||
assert(size == 14);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
0x02, // CONTROL_EVENT_TYPE_MOUSE
|
||||
0x00, // AKEY_EVENT_ACTION_DOWN
|
||||
0x00, 0x00, 0x00, 0x01, // AMOTION_EVENT_BUTTON_PRIMARY
|
||||
0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x04, 0x02, // 260 1026
|
||||
0x01, 0x04, 0x04, 0x02, // 260 1026
|
||||
0x04, 0x38, 0x07, 0x80, // 1080 1920
|
||||
};
|
||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||
@@ -120,11 +120,11 @@ static void test_serialize_scroll_event(void) {
|
||||
|
||||
unsigned char buf[SERIALIZED_EVENT_MAX_SIZE];
|
||||
int size = control_event_serialize(&event, buf);
|
||||
assert(size == 21);
|
||||
assert(size == 17);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
0x03, // CONTROL_EVENT_TYPE_SCROLL
|
||||
0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x04, 0x02, // 260 1026
|
||||
0x01, 0x04, 0x04, 0x02, // 260 1026
|
||||
0x04, 0x38, 0x07, 0x80, // 1080 1920
|
||||
0x00, 0x00, 0x00, 0x01, // 1
|
||||
0xFF, 0xFF, 0xFF, 0xFF, // -1
|
||||
|
||||
@@ -15,6 +15,6 @@ cpu = 'i686'
|
||||
endian = 'little'
|
||||
|
||||
[properties]
|
||||
prebuilt_ffmpeg_shared = 'ffmpeg-4.1-win32-shared'
|
||||
prebuilt_ffmpeg_dev = 'ffmpeg-4.1-win32-dev'
|
||||
prebuilt_ffmpeg_shared = 'ffmpeg-4.0.2-win32-shared'
|
||||
prebuilt_ffmpeg_dev = 'ffmpeg-4.0.2-win32-dev'
|
||||
prebuilt_sdl2 = 'SDL2-2.0.9/i686-w64-mingw32'
|
||||
|
||||
@@ -15,6 +15,6 @@ cpu = 'x86_64'
|
||||
endian = 'little'
|
||||
|
||||
[properties]
|
||||
prebuilt_ffmpeg_shared = 'ffmpeg-4.1-win64-shared'
|
||||
prebuilt_ffmpeg_dev = 'ffmpeg-4.1-win64-dev'
|
||||
prebuilt_ffmpeg_shared = 'ffmpeg-4.0.2-win64-shared'
|
||||
prebuilt_ffmpeg_dev = 'ffmpeg-4.0.2-win64-dev'
|
||||
prebuilt_sdl2 = 'SDL2-2.0.9/x86_64-w64-mingw32'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
project('scrcpy', 'c',
|
||||
version: '1.7',
|
||||
version: '1.5',
|
||||
meson_version: '>= 0.37',
|
||||
default_options: 'c_std=c11')
|
||||
|
||||
|
||||
@@ -10,24 +10,24 @@ prepare-win32: prepare-sdl2 prepare-ffmpeg-shared-win32 prepare-ffmpeg-dev-win32
|
||||
prepare-win64: prepare-sdl2 prepare-ffmpeg-shared-win64 prepare-ffmpeg-dev-win64 prepare-adb
|
||||
|
||||
prepare-ffmpeg-shared-win32:
|
||||
@./prepare-dep https://ffmpeg.zeranoe.com/builds/win32/shared/ffmpeg-4.1-win32-shared.zip \
|
||||
e692b18c01745d262c03294b382fd64df68fabe3c66aa4546a3ad3935175cde3 \
|
||||
ffmpeg-4.1-win32-shared
|
||||
@./prepare-dep https://ffmpeg.zeranoe.com/builds/win32/shared/ffmpeg-4.0.2-win32-shared.zip \
|
||||
cc190a3a4cf7bfbd4fbaa92609c1501a1de458055e6cfea8b745c1d515013aa8 \
|
||||
ffmpeg-4.0.2-win32-shared
|
||||
|
||||
prepare-ffmpeg-dev-win32:
|
||||
@./prepare-dep https://ffmpeg.zeranoe.com/builds/win32/dev/ffmpeg-4.1-win32-dev.zip \
|
||||
34bc5e471fb9160609abd6bc271e361050f3ff7376b1b8a0873cca02b38277c8 \
|
||||
ffmpeg-4.1-win32-dev
|
||||
@./prepare-dep https://ffmpeg.zeranoe.com/builds/win32/dev/ffmpeg-4.0.2-win32-dev.zip \
|
||||
c72c74bad74ac0541f1b43090c26a50017c49041c182a703abd2057bb8cdc238 \
|
||||
ffmpeg-4.0.2-win32-dev
|
||||
|
||||
prepare-ffmpeg-shared-win64:
|
||||
@./prepare-dep https://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-4.1-win64-shared.zip \
|
||||
c4908c97436c946509dc365e421159274fa4b1e66dce6fb5b63d82a6294d5357 \
|
||||
ffmpeg-4.1-win64-shared
|
||||
@./prepare-dep https://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-4.0.2-win64-shared.zip \
|
||||
ede566aca8b5348dff85570f9638c6bad33209f9419f79db7bde7daa37599bff \
|
||||
ffmpeg-4.0.2-win64-shared
|
||||
|
||||
prepare-ffmpeg-dev-win64:
|
||||
@./prepare-dep https://ffmpeg.zeranoe.com/builds/win64/dev/ffmpeg-4.1-win64-dev.zip \
|
||||
761ec79aa3dae66698c9791a2f0bb9da8794246f8356cadc741ddc0eabab0471 \
|
||||
ffmpeg-4.1-win64-dev
|
||||
@./prepare-dep https://ffmpeg.zeranoe.com/builds/win64/dev/ffmpeg-4.0.2-win64-dev.zip \
|
||||
23ee994161c51285cb956b98d3caa499d48083dae7b26c1fdf77f22e98df1c5f \
|
||||
ffmpeg-4.0.2-win64-dev
|
||||
|
||||
prepare-sdl2:
|
||||
@./prepare-dep https://libsdl.org/release/SDL2-devel-2.0.9-mingw.tar.gz \
|
||||
|
||||
@@ -55,4 +55,4 @@ get_dep() {
|
||||
fi
|
||||
}
|
||||
|
||||
get_dep "$url" "$sum" "$dir"
|
||||
get_dep "$1" "$2" "$3"
|
||||
|
||||
35
release.sh
35
release.sh
@@ -1,35 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# build and test locally
|
||||
BUILDDIR=build_release
|
||||
rm -rf "$BUILDDIR"
|
||||
meson "$BUILDDIR" --buildtype release --strip -Db_lto=true
|
||||
cd "$BUILDDIR"
|
||||
ninja
|
||||
ninja test
|
||||
cd -
|
||||
|
||||
# build Windows releases
|
||||
make -f Makefile.CrossWindows
|
||||
|
||||
# the generated server must be the same everywhere
|
||||
cmp "$BUILDDIR/server/scrcpy-server.jar" dist/scrcpy-win32/scrcpy-server.jar
|
||||
cmp "$BUILDDIR/server/scrcpy-server.jar" dist/scrcpy-win64/scrcpy-server.jar
|
||||
|
||||
# get version name
|
||||
TAG=$(git describe --tags --always)
|
||||
|
||||
# create release directory
|
||||
mkdir -p "release-$TAG"
|
||||
cp "$BUILDDIR/server/scrcpy-server.jar" "release-$TAG/scrcpy-server-$TAG.jar"
|
||||
cp "dist/scrcpy-win32-$TAG.zip" "release-$TAG/"
|
||||
cp "dist/scrcpy-win64-$TAG.zip" "release-$TAG/"
|
||||
|
||||
# generate checksums
|
||||
cd "release-$TAG"
|
||||
sha256sum "scrcpy-server-$TAG.jar" \
|
||||
"scrcpy-win32-$TAG.zip" \
|
||||
"scrcpy-win64-$TAG.zip" > SHA256SUMS.txt
|
||||
|
||||
echo "Release generated in release-$TAG/"
|
||||
@@ -6,8 +6,8 @@ android {
|
||||
applicationId "com.genymobile.scrcpy"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 27
|
||||
versionCode 8
|
||||
versionName "1.7"
|
||||
versionCode 6
|
||||
versionName "1.5"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
|
||||
@@ -9,8 +9,8 @@ import java.nio.charset.StandardCharsets;
|
||||
public class ControlEventReader {
|
||||
|
||||
private static final int KEYCODE_PAYLOAD_LENGTH = 9;
|
||||
private static final int MOUSE_PAYLOAD_LENGTH = 17;
|
||||
private static final int SCROLL_PAYLOAD_LENGTH = 20;
|
||||
private static final int MOUSE_PAYLOAD_LENGTH = 13;
|
||||
private static final int SCROLL_PAYLOAD_LENGTH = 16;
|
||||
private static final int COMMAND_PAYLOAD_LENGTH = 1;
|
||||
|
||||
public static final int TEXT_MAX_LENGTH = 300;
|
||||
@@ -132,8 +132,8 @@ public class ControlEventReader {
|
||||
}
|
||||
|
||||
private static Position readPosition(ByteBuffer buffer) {
|
||||
int x = buffer.getInt();
|
||||
int y = buffer.getInt();
|
||||
int x = toUnsigned(buffer.getShort());
|
||||
int y = toUnsigned(buffer.getShort());
|
||||
int screenWidth = toUnsigned(buffer.getShort());
|
||||
int screenHeight = toUnsigned(buffer.getShort());
|
||||
return new Position(x, y, screenWidth, screenHeight);
|
||||
|
||||
@@ -151,7 +151,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||
}
|
||||
|
||||
private static IBinder createDisplay() {
|
||||
return SurfaceControl.createDisplay("scrcpy", true);
|
||||
return SurfaceControl.createDisplay("scrcpy", false);
|
||||
}
|
||||
|
||||
private static void configure(MediaCodec codec, MediaFormat format) {
|
||||
|
||||
@@ -2,14 +2,11 @@ package com.genymobile.scrcpy;
|
||||
|
||||
import android.graphics.Rect;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class Server {
|
||||
|
||||
private static final String SERVER_PATH = "/data/local/tmp/scrcpy-server.jar";
|
||||
|
||||
private Server() {
|
||||
// not instantiable
|
||||
}
|
||||
@@ -49,24 +46,35 @@ public final class Server {
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
private static Options createOptions(String... args) {
|
||||
if (args.length != 5)
|
||||
throw new IllegalArgumentException("Expecting 5 parameters");
|
||||
|
||||
Options options = new Options();
|
||||
|
||||
if (args.length < 1) {
|
||||
return options;
|
||||
}
|
||||
int maxSize = Integer.parseInt(args[0]) & ~7; // multiple of 8
|
||||
options.setMaxSize(maxSize);
|
||||
|
||||
if (args.length < 2) {
|
||||
return options;
|
||||
}
|
||||
int bitRate = Integer.parseInt(args[1]);
|
||||
options.setBitRate(bitRate);
|
||||
|
||||
if (args.length < 3) {
|
||||
return options;
|
||||
}
|
||||
// use "adb forward" instead of "adb tunnel"? (so the server must listen)
|
||||
boolean tunnelForward = Boolean.parseBoolean(args[2]);
|
||||
options.setTunnelForward(tunnelForward);
|
||||
|
||||
if (args.length < 4) {
|
||||
return options;
|
||||
}
|
||||
Rect crop = parseCrop(args[3]);
|
||||
options.setCrop(crop);
|
||||
|
||||
if (args.length < 5) {
|
||||
return options;
|
||||
}
|
||||
boolean sendFrameMeta = Boolean.parseBoolean(args[4]);
|
||||
options.setSendFrameMeta(sendFrameMeta);
|
||||
|
||||
@@ -74,7 +82,7 @@ public final class Server {
|
||||
}
|
||||
|
||||
private static Rect parseCrop(String crop) {
|
||||
if ("-".equals(crop)) {
|
||||
if (crop.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// input format: "width:height:x:y"
|
||||
@@ -89,14 +97,6 @@ public final class Server {
|
||||
return new Rect(x, y, x + width, y + height);
|
||||
}
|
||||
|
||||
private static void unlinkSelf() {
|
||||
try {
|
||||
new File(SERVER_PATH).delete();
|
||||
} catch (Exception e) {
|
||||
Ln.e("Cannot unlink server", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
||||
@Override
|
||||
@@ -105,7 +105,6 @@ public final class Server {
|
||||
}
|
||||
});
|
||||
|
||||
unlinkSelf();
|
||||
Options options = createOptions(args);
|
||||
scrcpy(options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user