Compare commits

..

4 Commits

Author SHA1 Message Date
Romain Vimont
190a90f45d Request scan media on push
After a file is pushed, send a broadcast to request the media scanner to
scan the "push target" directory.

In practice, this allows some apps to detect the new file immediately.
2021-06-13 22:32:36 +02:00
Romain Vimont
cda4aa1623 Add method to send a broadcast
Implement the equivalent of Context.sendBroadcast(Intent).
2021-06-13 22:32:36 +02:00
Romain Vimont
310f5721d9 Move file_handler initialization
This will allow to (properly) reference the controller from the
file_handler initializer.
2021-06-13 22:32:36 +02:00
Romain Vimont
af228706f1 Fix compatibility with old FFmpeg
V4L2 sink used a "url" field format AVFormatContext which has been
introduced in lavf 58.7.100.

Fixes #2382 <https://github.com/Genymobile/scrcpy/issues/2382>

Refs <ea3672b7d6>
Refs <fa8308d3d4>
2021-06-13 19:20:57 +02:00
6 changed files with 52 additions and 10 deletions

View File

@@ -22,6 +22,18 @@
# define SCRCPY_LAVF_REQUIRES_REGISTER_ALL
#endif
// In ffmpeg/doc/APIchanges:
// 2018-01-28 - ea3672b7d6 - lavf 58.7.100 - avformat.h
// Deprecate AVFormatContext filename field which had limited length, use the
// new dynamically allocated url field instead.
//
// 2018-01-28 - ea3672b7d6 - lavf 58.7.100 - avformat.h
// Add url field to AVFormatContext and add ff_format_set_url helper function.
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 7, 100)
# define SCRCPY_LAVF_HAS_AVFORMATCONTEXT_URL
#endif
#if SDL_VERSION_ATLEAST(2, 0, 5)
// <https://wiki.libsdl.org/SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH>
# define SCRCPY_SDL_HAS_HINT_MOUSE_FOCUS_CLICKTHROUGH

View File

@@ -4,6 +4,8 @@
#include <string.h>
#include "adb.h"
#include "control_msg.h"
#include "controller.h"
#include "util/log.h"
#define DEFAULT_PUSH_TARGET "/sdcard/"
@@ -14,7 +16,8 @@ file_handler_request_destroy(struct file_handler_request *req) {
}
bool
file_handler_init(struct file_handler *file_handler, const char *serial,
file_handler_init(struct file_handler *file_handler,
struct controller *controller, const char *serial,
const char *push_target) {
cbuf_init(&file_handler->queue);
@@ -50,6 +53,8 @@ file_handler_init(struct file_handler *file_handler, const char *serial,
file_handler->push_target = push_target ? push_target : DEFAULT_PUSH_TARGET;
file_handler->controller = controller;
return true;
}
@@ -103,6 +108,24 @@ file_handler_request(struct file_handler *file_handler,
return res;
}
static bool
request_scan_media(struct file_handler *file_handler) {
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_SCAN_MEDIA;
msg.scan_media.path = strdup(file_handler->push_target);
if (!msg.scan_media.path) {
LOGW("Could not strdup() media path");
return false;
}
if (!controller_push_msg(file_handler->controller, &msg)) {
LOGW("Could not request 'scan media'");
return false;
}
return true;
}
static int
run_file_handler(void *data) {
struct file_handler *file_handler = data;
@@ -145,6 +168,7 @@ run_file_handler(void *data) {
if (process_check_success(process, "adb push", false)) {
LOGI("%s successfully pushed to %s", req.file,
file_handler->push_target);
request_scan_media(file_handler);
} else {
LOGE("Failed to push %s to %s", req.file,
file_handler->push_target);

View File

@@ -22,6 +22,7 @@ struct file_handler_request {
struct file_handler_request_queue CBUF(struct file_handler_request, 16);
struct file_handler {
struct controller *controller;
char *serial;
const char *push_target;
sc_thread thread;
@@ -34,7 +35,8 @@ struct file_handler {
};
bool
file_handler_init(struct file_handler *file_handler, const char *serial,
file_handler_init(struct file_handler *file_handler,
struct controller *controller, const char *serial,
const char *push_target);
void

View File

@@ -297,14 +297,6 @@ scrcpy(const struct scrcpy_options *options) {
goto end;
}
if (options->display && options->control) {
if (!file_handler_init(&s->file_handler, s->server.serial,
options->push_target)) {
goto end;
}
file_handler_initialized = true;
}
struct decoder *dec = NULL;
bool needs_decoder = options->display;
#ifdef HAVE_V4L2
@@ -353,6 +345,12 @@ scrcpy(const struct scrcpy_options *options) {
goto end;
}
controller_started = true;
if (!file_handler_init(&s->file_handler, &s->controller,
s->server.serial, options->push_target)) {
goto end;
}
file_handler_initialized = true;
}
const char *window_title =

View File

@@ -180,12 +180,17 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) {
// still expects a pointer-to-non-const (it has not be updated accordingly)
// <https://github.com/FFmpeg/FFmpeg/commit/0694d8702421e7aff1340038559c438b61bb30dd>
vs->format_ctx->oformat = (AVOutputFormat *) format;
#ifdef SCRCPY_LAVF_HAS_AVFORMATCONTEXT_URL
vs->format_ctx->url = strdup(vs->device_name);
if (!vs->format_ctx->url) {
LOGE("Could not strdup v4l2 device name");
goto error_avformat_free_context;
return false;
}
#else
strncpy(vs->format_ctx->filename, vs->device_name,
sizeof(vs->format_ctx->filename));
#endif
AVStream *ostream = avformat_new_stream(vs->format_ctx, encoder);
if (!ostream) {

View File

@@ -140,6 +140,7 @@ public class Controller {
break;
case ControlMessage.TYPE_SCAN_MEDIA:
String path = msg.getText();
@SuppressWarnings("deprecation")
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(new File(path)));
Device.sendBroadcast(intent);