Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support samsung dex mirroring #898

Closed
subjectdenied opened this issue Oct 31, 2019 · 36 comments
Closed

support samsung dex mirroring #898

subjectdenied opened this issue Oct 31, 2019 · 36 comments

Comments

@subjectdenied
Copy link

as there is currently no way to use "samsung dex for pc" on linux desktops, it would be great to be able to use scrcpy for it

@thebitstick
Copy link

This would be great! DeX on Windows offers this functionality, so it shouldn't be to difficult to somehow trick the phone into displaying in Dex mode

@subjectdenied
Copy link
Author

i think this would only be useful if it would be possible to use drm-content in scrcpy

@DishanRajapaksha
Copy link

i think this would only be useful if it would be possible to use drm-content in scrcpy

Not really. Dex can do much more than playing Netflix.

@hamamoko
Copy link

scrcpy is already absolutely amazing - I love it!
but that would be the icing on the cake

@webian
Copy link

webian commented Mar 14, 2020

See #397

@rom1v
Copy link
Collaborator

rom1v commented Apr 8, 2020

Could you test the new --display option on dev (the development branch), please?

@rom1v
Copy link
Collaborator

rom1v commented Apr 8, 2020

Here is a win64 release for the current dev branch:

SHA256
09489ac673ed3b0bb7aba7e0858c43137a7480d1a2d4f8a51f698acbc49be735  scrcpy-server
c9be0cd73651a376932ca0e4ca1c07275aa776a5e5520b5b184fcff943affdd5  scrcpy.exe

(replace these two files in the v1.12.1 release)

@npes87184
Copy link
Contributor

I have tested it on my samsung galaxy note10+,
It has two displays

[server] ERROR: Try to use one of the available display ids:
[server] ERROR:     scrcpy --display 0
[server] ERROR:     scrcpy --display 2
Press any key to continue...               

Display 0 works like usual scrcpy.

scrcpy-win64-v1.12.1-4-gf9786e5> .\scrcpy.exe --display 2
INFO: scrcpy 1.12.1 <https://github.com/Genymobile/scrcpy>
.\scrcpy-server: 1 file pushed. 3.0 MB/s (27842 bytes in 0.009s)
[server] INFO: Device: samsung SM-N9750 (Android 10)
[server] WARN: Display doesn't have FLAG_SUPPORTS_PROTECTED_BUFFERS flag, mirroring can be restricted
INFO: Initial texture: 1920x1080

Display 2 has only black screen. And it doesn't have any response.

@rom1v
Copy link
Collaborator

rom1v commented Apr 8, 2020

OK, thank you for the test 👍

So this flag is not set (whatever it means) for Dex… 😞

@DishanRajapaksha
Copy link

DishanRajapaksha commented Apr 8, 2020

-- display flag worked for me on the Note 9. Dex must be running separately for the flag to work.

Annotation 2020-04-08 193334

@rom1v
Copy link
Collaborator

rom1v commented Apr 8, 2020

Cool, thanks 👍

(While you're here, could you test rotation with Ctrl+ and Ctrl+, and that clicks work correctly on rotated display, please?)

@DishanRajapaksha
Copy link

DishanRajapaksha commented Apr 8, 2020

Cool, thanks 👍

(While you're here, could you test rotation with Ctrl+ and Ctrl+, and that clicks work correctly on rotated display, please?)

Rotation worked but the launcher did not adjust itself. That might be a limitation with the Dex launcher though. Clicks worked as expected too.

If we can find a way to trigger Dex manually, this would be perfect. scrcpy with a high bit rate seems to be much smoother than the Dex application.

Annotation 2020-04-08 194522

@rom1v
Copy link
Collaborator

rom1v commented Apr 8, 2020

Rotation worked but the launcher did not adjust itself. That might be a limitation with the Dex launcher though.

Yes, that's expected, this is just a local rotation, for applications like Camera or video conferencing apps which keep their system orientation but rotate their widgets (in that case, it is convenient to rotate the display manually).

To rotate the app, it's Ctrl+r (but works only if the app support the requested orientation).

If we can find a way to trigger Dex manually

(TBH, I don't really know what Dex is, so I hope other people will find a way 😉)

@DishanRajapaksha
Copy link

DishanRajapaksha commented Apr 8, 2020

Sorry, I only checked single clicks previously and they worked. But double-clicking doesn't work when rotated. And right-click does not work in any state.

To rotate the app, it's Ctrl+r (but works only if the app support the requested orientation).

Ctrl+r doesn't change anything in supported apps (WhatsApp, Gallery) in both landscape and rotated states.

@webian
Copy link

webian commented Apr 8, 2020

If we can find a way to trigger Dex manually

(TBH, I don't really know what Dex is, so I hope other people will find a way 😉)

Dex is the Samsung's "Android desktop mode" and it's triggered if you attach an external monitor to a Samsung smartphone with a cable. In practice you have a desktop computer using only your smartphone and an external monitor.

What @DishanRajapaksha means with "trigger Dex manually" (I guess since I'm looking for this solution too) is to make the smartphone to think that and external monitor is attached but without attaching an HDMI cable to the smartphone. It could be the final perfect solution to have a wireless "Android desktop mode" :)

rom1v added a commit that referenced this issue Apr 8, 2020
A double-click outside the device content (in the black borders) resizes
so that black borders are removed. But the display rotation was not
taken into account to detect the content.

Use the content size instead of the frame size to fix the issue.

Ref: <#898 (comment)>
@rom1v
Copy link
Collaborator

rom1v commented Apr 8, 2020

Sorry, I only checked single clicks previously and they worked. But double-clicking doesn't work when rotated.

Oh, good catch! Fixed by 9f4735e.

And right-click does not work in any state.

Right-click is bound to BACK, because on "normal" devices, there is no meaningful "right-click". 😕

Ctrl+r doesn't change anything in supported apps (WhatsApp, Gallery) in both landscape and rotated states.

Dex maybe does not support rotation at all.

If you use Ctrl+r on these apps on the device, does it work?

@npes87184
Copy link
Contributor

-- display flag worked for me on the Note 9. Dex must be running separately for the flag to work.

Annotation 2020-04-08 193334

Hmmm, why I only see black screen? Do you do anything else?

@DishanRajapaksha
Copy link

DishanRajapaksha commented Apr 8, 2020

Ctrl+r doesn't change anything in supported apps (WhatsApp, Gallery) in both landscape and rotated states.

Ah yes. I forgot that. Dex has some right-click menus just like what you'd find in Windows.

Also, Dex freeform windows have 'resize' cursor icon when the cursor is moved to window edges. That's not triggering in scrcpy.

Dex maybe does not support rotation at all.

I think this is the case, nothing happens in the Dex window when I press Ctrl+r.

If you use Ctrl+r on these apps on the device, does it work?

Yes. Device display apps get changed.

@DishanRajapaksha
Copy link

DishanRajapaksha commented Apr 8, 2020

Hmmm, why I only see black screen? Do you do anything else?

Did you try running the display command while Dex is running? I connected the phone to my laptop and opened Dex Windows app and then ran scrcpy with the display command.

@rom1v
Copy link
Collaborator

rom1v commented Apr 8, 2020

Also, Dex freeform windows have 'resize' cursor icon too when the cursor is moved to window edges. That's not triggering in scrcpy.

If you can build scrcpy, you could play with the source code to do some tests:

if (!event->state) {
// do not send motion events when no button is pressed
return;
}

😉

@DishanRajapaksha
Copy link

If you can build scrcpy, you could play with the source code to do some tests:

Thank you. I'll fiddle around and see what I can do 😄

@rom1v
Copy link
Collaborator

rom1v commented Apr 29, 2020

Released in v1.13.

@Naheel-Azawy
Copy link

What @DishanRajapaksha means with "trigger Dex manually" (I guess since I'm looking for this solution too) is to make the smartphone to think that and external monitor is attached but without attaching an HDMI cable to the smartphone. It could be the final perfect solution to have a wireless "Android desktop mode" :)

As far as I understood, the only way right now to make Dex run is either to have an HDMI cable connected or as @DishanRajapaksha mentioned, using the Windows Dex program, which defeats the purpose... I mean, the original question by @subjectdenied is if it can run on Linux. The original Dex program (which is needed as @DishanRajapaksha mentioned) has no Linux version. Did you @webian find any solution yet?

I'm not sure if I'm missing something, but I don't see the solution to the main question of this issue.

@webian
Copy link

webian commented Nov 12, 2020

As far as I understood, the only way right now to make Dex run is either to have an HDMI cable connected or as @DishanRajapaksha mentioned, using the Windows Dex program, which defeats the purpose...

Another new way recently added by Samsung is to cast Dex wirelessly to a TV or a Windows PC supporting Miracast (or a monitor with a wireless dongle I suppose).

@DishanRajapaksha
Copy link

As far as I understood, the only way right now to make Dex run is either to have an HDMI cable connected or as @DishanRajapaksha mentioned, using the Windows Dex program, which defeats the purpose...

Another new way recently added by Samsung is to cast Dex wirelessly to a TV or a Windows PC supporting Miracast (or a monitor with a wireless dongle I suppose).

Miracasting doesn't support input unfortunately. I couldn't figure out a way at least on my Windows PC with the Connect app.

I have seen some people talking about tricking the phone to think that an HDMI is connected using a dummy HDMI plug. See this link for more info.

I wonder if we can do do it virtually? Make the phone think an HDMI is connected suing an app?

@DishanRajapaksha
Copy link

I wonder if we can do do it virtually? Make the phone think an HDMI is connected suing an app?

I found this post but the linked apk doesn't work. Its a post from 2013, so that's expected I guess.

@webian
Copy link

webian commented Nov 14, 2020

Exactly @DishanRajapaksha, we need an HDMI Virtual Switch. Some software that make the phone (more precisely Dex) think HDMI cable is connected. Then we can use Dex with scrcpy wirelessly.

@aakodadi
Copy link

aakodadi commented Dec 16, 2020

I found this post but the linked apk doesn't work. Its a post from 2013, so that's expected I guess.

@DishanRajapaksha I think the app you mentioned works only on rooted devices. It actually doesn't do much. It just runs this command su -c echo 1 > /sys/devices/virtual/switch/hdmi/state

I was able to decompile the app and this is the code of the main activity:

public class MainActivity extends Activity {
  static Context gg1;
  
  static Notification noti;
  
  static NotificationManager notificationManager;
  
  public Button b1;
  
  public Button b2;
  
  public Button b3;
  
  public Dialog d;
  
  private void help() {
    this.d.requestWindowFeature(1);
    this.d.setContentView(2130903041);
    this.d.show();
  }
  
  public static void startSwitchoff() {
    Log.d("Launcher", "off");
    try {
      Runtime.getRuntime().exec(new String[] { "su", "-c", "echo 0 > /sys/devices/virtual/switch/hdmi/state" });
      Toast.makeText(gg1, "Hdmi Was Virtually Unplugged", 1).show();
      return;
    } catch (IOException iOException) {
      iOException.printStackTrace();
      return;
    } 
  }
  
  public void onCreate(Bundle paramBundle) {
    super.onCreate(paramBundle);
    setContentView(2130903040);
    this.d = new Dialog((Context)this);
    gg1 = (Context)this;
    this.b1 = (Button)findViewById(2131165184);
    this.b2 = (Button)findViewById(2131165185);
    this.b3 = (Button)findViewById(2131165186);
    this.b1.setOnClickListener(new View.OnClickListener() {
          public void onClick(View param1View) {
            MainActivity.startSwitchoff();
          }
        });
    this.b2.setOnClickListener(new View.OnClickListener() {
          public void onClick(View param1View) {
            MainActivity.this.startSwitchon();
          }
        });
    this.b3.setOnClickListener(new View.OnClickListener() {
          public void onClick(View param1View) {
            MainActivity.this.help();
          }
        });
  }
  
  public void startSwitchon() {
    Log.d("Launcher", "on");
    try {
      Runtime.getRuntime().exec(new String[] { "su", "-c", "echo 1 > /sys/devices/virtual/switch/hdmi/state" });
      Toast.makeText((Context)this, "Hdmi Was Virtually Plugged Back In", 1).show();
      return;
    } catch (IOException iOException) {
      iOException.printStackTrace();
      return;
    } 
  }
}

Someone with access to a rooted Samsung device should be able to test this hypothesis.

I have also taken a look at the logs and the local loop back traffic while using the windows program. It seems that samsung are able to achieve this by communicating with some system app on the device. It's maybe worth it to try and reverse engineer what they are doing. The communication appears to be secured with an authentication mechanism tho... tbc

@wokawoka
Copy link

Hello guys, any news on this? Is there by chance a way to have samsung dex streamed through scrcpy without using a hdmi cable?
I have a samsung note 9 (not rooted) and I can help to test.
Thank you!

@rom1v
Copy link
Collaborator

rom1v commented Apr 15, 2021

You should read #1887 (for Android 10+).

@wokawoka
Copy link

You should read #1887 (for Android 10+).

Thank you, I'll check that, but I was interested specifically in streaming samsung dex and not android desktop mode.
I'm on linux and there's no a samsung client to stream dex on the computer for linux (only for win and mac) so doing so scrcpy would be great.
Thank you again

@4nric
Copy link

4nric commented Apr 16, 2021

@wokawoka If your linux device have wifi capabilities, you can try miraclecast as display sink, launch wireless dex to it, then stream dex by running scrcpy --display 2 for better quality. Use a higher bitrate if your phone is connected to your linux machine via cable (e.g. -b16M or -b32M). Alternatively, you can use an old android device as a miracast display sink with the
WiFi-Display(miracast) sink
app. As long as dex is triggered, it can be accessed in linux via scrcpy. You can even normally launch dex on pc or tv monitor then access it on linux via scrcpy. Kinda hacky, but I don't know any other solutions.

@wokawoka
Copy link

@4nric
sorry for replying so late (after more than 3 months) but I've noticed your reply only now (too many emails from github!).
I just tried the miraclecast method (on my linux laptop) and it worked great! Not really that hacky, I would say quite practical and a good solution on a linux laptop.
Thank you so much once again for your detailed and useful reply!

@4nric
Copy link

4nric commented Jul 29, 2021

@wokawoka Glad it works! I was not able to test it myself as I don't have a Linux laptop nor a PC running Linux with wifi capabilities.

@nikitoz02ok
Copy link

Hi! Is there a way to run miracast locally without other devices? (like dummy/fake miracast) I'm using a mid range device (A50) with flagship based firmware, so I can't use the HDMI adapter. There are 2 ways left, wireless and DEX on PC, I have a usb wi-fi adapter but it sucks, it can reset the Miracast connection at any time. Using Dex on PC is only possible on Windows and MacOS, Linux was left without support. It would be nice to make the phone think that it is connected to a miracast device)
Sorry for my English

@Hei02
Copy link

Hei02 commented Oct 29, 2023

Is there a way to display screen in 1080P without using dex please ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests