tvOS / Apple TV support

Hey all,

Since the recent announcement of the new Apple TV and tvOS, and developer kids of said Apple TV getting in the hands of some people who use SDL, there has been a lot of interest in getting SDL working on tvOS.

As far as I know, there are at least three people working independently on that problem (four if I include myself.) Having 3+ slightly different implementations of the same idea probably isn?t ideal, so I figured I should let everyone know that I definitely intend to have tvOS support in SDL proper ASAP.

I?m a bit hesitant to put code in SDL?s main repository that relies on a beta SDK though ? I?ll likely have things in a fork for now. I?ll post that here when I create it.

tvOS is itself a fork of iOS 9 and there aren?t a whole lot of differences between the two operating systems right now, so the good news is not a lot needs to change in SDL to have it working on an Apple TV. I also added MFi game controller support to SDL?s iOS backend yesterday, which will work on tvOS as well.

Phil Hassey is one of the people who got an Apple TV developer kit, and he got SDL working on it very quickly ? we?ve been talking a bit, and initial tvOS support in SDL will probably be based at least in part on his work.

  • Alex

This might be a tad off-topic, but do you know if tvOS libraries are currently-slated to require compilation via separate Xcode targets, or might SDL’s existing iOS projects + targets work with tvOS, off the bat?

I have a few projects I wouldn’t mind trying to experimentally-port to tvOS, but probably only if it won’t require too much effort (in terms of build setup, etc.)

Cheers!
– David L.

Hi, here’s two scripts to compile SDL libs from command line with
‘xcodebuild’.
One to compile for IOS and the other for TvOS. They could be easily merged
in one script but currently TVOs requires xcodebeta 7.1.

Cheers, Sylvain
Le 22 sept. 2015 01:43, “DLudwig” a ?crit :> This might be a tad off-topic, but do you know if tvOS libraries are

currently-slated to require compilation via separate Xcode targets, or
might SDL’s existing iOS projects + targets work with tvOS, off the bat?

I have a few projects I wouldn’t mind trying to experimentally-port to
tvOS, but probably only if it won’t require too much effort (in terms of
build setup, etc.)

Cheers!
– David L.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I?ve created an Apple TV / tvOS branch of SDL here: https://bitbucket.org/slime73/sdl-experiments/branch/AppleTV https://bitbucket.org/slime73/sdl-experiments/branch/AppleTV

Once you have that code (make sure to use the correct branch! A direct download is here: https://bitbucket.org/slime73/sdl-experiments/get/AppleTV.zip https://bitbucket.org/slime73/sdl-experiments/get/AppleTV.zip ), you can build SDL for tvOS if you have the Xcode 7.1 beta by choosing the libSDL-tv target in the SDL xcode project in Xcode-iOS/SDL/.

I haven?t actually done any testing yet, since the Apple TV simulator isn?t showing up in Xcode for some reason (I?ll see about that tomorrow maybe). I expect there will be bugs. If anyone finds any please let me know. :slight_smile:

Comments and suggestions for the code and how to deal with Apple TV platform-specific things are also welcome.

  • Alex

Hi Alex,

I tried your branch and it is good ! Here’s some feedback:

1/ I got a very small problem of linking:
Undefined symbols of “_UIKit_GetSupportedOrientations”, referenced from:
-[SDL_uikitviewcontroller supportedInterfaceOrientations] in
libSDL2.a(SDL_uikitviewcontroller.o)
I commented out “supportedInterfaceOrientations” and
"shouldAutorotateToInterfaceOrientation" from the files
SDL_uikitviewcontroller.{h,m}

2/ OSTV-Simulator wasn’t working neither for me at first. But I got it
running by changing the “build settings > architectures” of my xcode
project to “Standard architectures (arm64) - $(ARCHS_STANDARD)”. (I
generated my xcode app project with a CMakeFile …).

3/ On the OSTV-Simulator: it seems to detect an “ExtendedGamepad” but no
data (Axis, Dpad) comes from it. Even if the “Apple TV Remote” of the
simulator is shown/hidden.
Though the keyboard works.

4/ On the real AppleTV, it detect correctly the real remote as a
micro-gamepad and datas (Axis, DPad, Button) are coming.

5/ But the DPad datas are impossible to use. It’s almost never in the state
Up/Down/Left/Right, but always in a diagonal state.
I have looked at the code of “SDL_SYS_MFIJoystickHatStateForDPad” and it is
correct.
It’s just the way the data are coming. Maybe the raw datas should be used.

6/ I tried mixer/image/ttf and all was working with no modification.

So for me it is in a very good state,

Thanks,
Sylvain

Alex Szpakowski wrote:

I???ve created an Apple TV / tvOS branch of SDL here: https://bitbucket.org/slime73/sdl-experiments/branch/AppleTV (https://bitbucket.org/slime73/sdl-experiments/branch/AppleTV)

Neat!

Now if Microsoft would just release the Win10 + Xbox One dev tools, I could get started on Xbox One support. :wink:

– David L.

Thanks for testing!

1/ I got a very small problem of linking:
Undefined symbols of “_UIKit_GetSupportedOrientations”, referenced from:
-[SDL_uikitviewcontroller supportedInterfaceOrientations] in libSDL2.a(SDL_uikitviewcontroller.o)
I commented out “supportedInterfaceOrientations” and “shouldAutorotateToInterfaceOrientation” from the files SDL_uikitviewcontroller.{h,m}

Oops. I just pushed a commit that should fix that.

3/ On the OSTV-Simulator: it seems to detect an “ExtendedGamepad” but no data (Axis, Dpad) comes from it. Even if the “Apple TV Remote” of the simulator is shown/hidden.
Though the keyboard works.

4/ On the real AppleTV, it detect correctly the real remote as a micro-gamepad and datas (Axis, DPad, Button) are coming.

I suspect the beta Apple TV Simulator is just buggy right now ? it didn?t support the remote as a GameController at all in beta 1, apparently.

5/ But the DPad datas are impossible to use. It’s almost never in the state Up/Down/Left/Right, but always in a diagonal state.
I have looked at the code of “SDL_SYS_MFIJoystickHatStateForDPad” and it is correct.
It’s just the way the data are coming. Maybe the raw datas should be used.

Weird. If you set the reportsAbsoluteDpadValues boolean property of GCMicroGamepad to YES somewhere in the joystick code, does it report more sensible values?

  • Alex

“reportsAbsoluteDpadValues” seems to center the coordinates or not. It
could be used in SDL anyway but not for this I guess.

In fact, I have dumped the field “value” (dpad.{up,down,left,right}.value)
together with “isPressed”.

INFO: Hat/isPressed/Value up/0/0.000000/ down/1/0.009222 left/1/0.699115
right/0/0.000000
INFO: Hat/isPressed/Value up/0/0.000000/ down/1/0.009222 left/1/0.699115
right/0/0.000000
INFO: Hat/isPressed/Value up/0/0.000000/ down/1/0.009222 left/1/0.699115
right/0/0.000000

Even a very small “value” triggers the “isPressed”, so we have more likely
diagonals.

I have changed the function “SDL_SYS_MFIJoystickHatStateForDPad” to use the
raws values, and it works better like this (sorry for the copy paste):

SDL_SYS_MFIJoystickHatStateForDPad(GCControllerDirectionPad *dpad)
{
float values[4];
int arrows[4];
int nb = 0;

if (dpad.up.value != 0) {
  values[nb] = dpad.up.value;
  arrows[nb] = SDL_HAT_UP;
  nb += 1;
}

if (dpad.down.value != 0) {
  values[nb] = dpad.down.value;
  arrows[nb] = SDL_HAT_DOWN;
  nb += 1;
}

if (dpad.left.value != 0) {
  values[nb] = dpad.left.value;
  arrows[nb] = SDL_HAT_LEFT;
  nb += 1;
}

if (dpad.right.value != 0) {
  values[nb] = dpad.right.value;
  arrows[nb] = SDL_HAT_RIGHT;
  nb += 1;
}

// (nb == 3) and (nb == 4) would be an error, since Up and Down are

exclusive. and also Left and Right are exclusive
if (nb == 0 || nb == 3 || nb == 4) {
return SDL_HAT_CENTERED;
}

// Only one direction
if (nb == 1) {
  return arrows[0];
}

// Two values.  let's find which
float angle = SDL_atan(values[1] / values[0]);

if (angle < M_PI / 8.0) {
   return arrows[0];
} else if (angle > 3.0 * M_PI / 8.0) {
   return arrows[1];
} else {
   return arrows[0] | arrows[1];
}

}

About this: "Figure out what to do with reportsAbsoluteDpadValues"
Since it changes the Siri Remote behavior, I think you can implement that the same way as you did with controllerUserInteractionEnabled, as a Hint.

Also, I have seen another issue on the real box:

Datas coming from the Joystick Micro Remote are duplicated as Keyboard and
Mouse.
I mean: in addition to Joystick events, I always received Mouse events
(SDL_MOUSEMOTION, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP) and also Keyboard
events) (SDL_KEYDOWN, mostly ENTER and ESCAPE).

I have tried to use “SDL_HINT_APPLE_TV_REMOTE_KEYPRESS” but seems to have
the same behavior (tried: no used, “0” and also “1”).

could be improved not calculating the SDL_atan each time. I only put the
last part:

// Two values. let’s find which
// tan(Pi/8) == 0.41421
// tan(3Pi/8) == 2.41421
float tan_angle = values[1] / values[0];
if (tan_angle < 0.41421) {
return arrows[0];
} else if (tan_angle > 2.41421) {
return arrows[1];
} else {
return arrows[0] | arrows[1];
}

Thanks for you help,
Sylvain>From my previous mail, the function “SDL_SYS_MFIJoystickHatStateForDPad”

Weird. The Apple documentation is pretty explicit about apple tv remote input being routed either through the GameController APIs or the other input APIs, and not both at once. Are you using the simulator or a real device?

I wonder if it?s a bug in tvOS…> On Oct 2, 2015, at 9:24 AM, Sylvain Becker <sylvain.becker at gmail.com> wrote:

Also, I have seen another issue on the real box:

Datas coming from the Joystick Micro Remote are duplicated as Keyboard and Mouse.
I mean: in addition to Joystick events, I always received Mouse events (SDL_MOUSEMOTION, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP) and also Keyboard events) (SDL_KEYDOWN, mostly ENTER and ESCAPE).

I have tried to use “SDL_HINT_APPLE_TV_REMOTE_KEYPRESS” but seems to have the same behavior (tried: no used, “0” and also “1”).

Yes, this is happens on the real device. Using xcode beta2, and latest tvOS
firmware.
Indeed, it could be a bug in tvOS …On 2 October 2015 at 20:38, Alex Szpakowski wrote:

Weird. The Apple documentation is pretty explicit about apple tv remote
input being routed either through the GameController APIs or the other
input APIs, and not both at once. Are you using the simulator or a real
device?

I wonder if it?s a bug in tvOS…

On Oct 2, 2015, at 9:24 AM, Sylvain Becker <@Sylvain_Becker> wrote:

Also, I have seen another issue on the real box:

Datas coming from the Joystick Micro Remote are duplicated as Keyboard
and Mouse.
I mean: in addition to Joystick events, I always received Mouse events
(SDL_MOUSEMOTION, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP) and also Keyboard
events) (SDL_KEYDOWN, mostly ENTER and ESCAPE).

I have tried to use “SDL_HINT_APPLE_TV_REMOTE_KEYPRESS” but seems to
have the same behavior (tried: no used, “0” and also “1”).


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Sylvain Becker

Is there a way to detect a click (on the touchpad, not just a finger press but an actual click)? I don’t see any SDL event that comes through from a click.

The microgamepad remote is recognized as a joystick by SDL.
First, you need to call SDL_JoystickOpen, then, you’ll received various
joystick events (see SDL_JOYBUTTONDOWN).

By the way, Apple has released two days ago the latest version of xcode
that includes tvOS sdk. So it’s not a beta anymore.
Latest tvOS firmware has also been released.

Alex,

Thanks for the branch! All the work you’ve done on SDL for iOS and tvOS has been a big help to me.
Currently, tvOS apps are required to exit an app and return to the home screen when the menu button is pressed. The following links provide some details.
https://forums.developer.apple.com/thread/17807
https://forums.developer.apple.com/thread/23786

It seems like SDL is permanently overriding the menu recognizer. What’s the best way to solve this?

Hi,

I got the same issue.
More precisely, there are two distinct issues:

1/ SDL “overriding the menu recognizer” : I haven’t seen this one because I
handle the remote as a SDL joystick. Then, Menu button is seen as
“SDL_CONTROLLER_BUTTON_X”.

2/ When ending the application (returning from the SDL_main()), the
application is not exiting:
I quicky modified the file “src/video/uikit/SDL_uikitappdelegate.m”. In the
function “postFinishLaunch”, uncomment the last line to make sure that
“exit(exit_status)” is called after the SDL_main has returned.

Cheers,
SylvainOn 28 October 2015 at 04:16, ace491 wrote:

Alex,

Thanks for the branch! All the work you’ve done on SDL for iOS and tvOS
has been a big help to me.
Currently, tvOS apps are required to exit an app and return to the home
screen when the menu button is pressed. The following links provide some
details.
Menu button exit to Apple TV Home … | Apple Developer Forums
Apple TV App not exiting to the ho… | Apple Developer Forums

It seems like SDL is permanently overriding the menu recognizer. What’s
the best way to solve this?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I don’t think we’re supposed to actually return from main. As long as nothing is intercepting the menu button, pressing it will leave the app as if you had pressed the home button on the iPhone.

If you disable interaction by setting setUserInteractionEnabled to NO on the view of the rootViewController of the uiwindow, then pressing menu will leave the app. Although, this isn’t useful because you lose all interaction. It needs to be on a per button basis.
I tried adding the super function calls to the all the presses and touches functions in SDL_uikitview.m but that didn’t work.

slvn wrote:> Hi,

I got the same issue.
More precisely, there are two distinct issues:

1/ SDL “overriding the menu recognizer” : I haven’t seen this one because I handle the remote as a SDL joystick. Then, Menu button is seen as “SDL_CONTROLLER_BUTTON_X”.

2/ When ending the application (returning from the SDL_main()), the application is not exiting:

I quicky modified the file “src/video/uikit/SDL_uikitappdelegate.m”. In the function “postFinishLaunch”, uncomment the last line to make sure that “exit(exit_status)” is called after the SDL_main has returned.

??

Cheers,

Sylvain

On 28 October 2015 at 04:16, ace491 <@diego (@diego)> wrote:

  Alex, 

Thanks for the branch! All the work you’ve done on SDL for iOS and tvOS has been a big help to me.
Currently, tvOS apps are required to exit an app and return to the home screen when the menu button is pressed. The following links provide some details.
Menu button exit to Apple TV Home … | Apple Developer Forums (Menu button exit to Apple TV Home … | Apple Developer Forums)
Apple TV App not exiting to the ho… | Apple Developer Forums (Apple TV App not exiting to the ho… | Apple Developer Forums)

It seems like SDL is permanently overriding the menu recognizer. What’s the best way to solve this?


SDL mailing list
SDL at lists.libsdl.org (SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

So, is there a way to turn on/off the detection of the menu button? I too want the default functionality when you press the menu button.

I just pushed a commit to my Apple TV branch of SDL which removes the old hint (SDL_HINT_APPLE_TV_REMOTE_KEYPRESS) and adds a new hint (SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS) which, when set to ?1?, will cause the app to be backgrounded when the menu button is pressed.

A bit more description is in the commit (and the comment in the declaration of the hint #define): https://bitbucket.org/slime73/sdl-experiments/commits/034d986

Let me know if that works for everyone!> On Oct 28, 2015, at 5:13 PM, divad wrote:

So, is there a way to turn on/off the detection of the menu button? I too want the default functionality when you press the menu button.


SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org