0. Brief Introduction to SDK

0.1 Brief Introduction

AirFly Receiver is the mature receiver solution based on the AirPlay protocol (AirPlay Receiver / AirPlay Server), which can run on a variety of hardware and operating systems, and supports up to 16 circuits of simultaneous rendering.

We provide free SDKs (C/C++ complilation) that contain the AirPlay protocol package, which enable developers to have the fast development and customization on this basis without having to concern the complex details of the AirPlay protocol.

In this SDK, the content related to the protocol is pre-compiled into a dynamic library, and the contents will be used in the player and user interface are provided in callback functions. A protocol emulator can be launched even without any development work, so as to complete the recording of Screen Mirroring audio and video streams and so on.

0.2 System Architecture

AirFly Receiver SDK undertakes all work of the AirPlay protocol, completes the network interaction with iOS/macOS, and provides contents to the player. The architecture is as follows:

┌───────────────────────┐
│       iOS/macOS       │       Screen/TV
└───────^───────┬───────┘           ^
        │  Net  │                   │
        │   IO  │                   │
┌───────┴───────v───────┐      ┌────┴─────┐
│  AirFly Receiver SDK  ├──────>  Player  │
└───────┬───────^───────┘      └──┬────^──┘
        │       │                 │    │
┌───────v───────┴─────────────────v────┴──┐
│              Operating System           │
└─────────────────────────────────────────┘

0.3 Limit

SDK of the free version has the following restrictions:

  • It must be running in a network environment with Internet connection;
  • It will automatically exit the program if the number of use times reaches the limit in each run;
  • It allows connection of up to 4 devices at the same time.

1. Download

The latest stable version is v2.7.1 (support iOS11), released on November 3, 2016:

The current free version of the SDK only provides the above versions. For other versions and versions do not depend on the Internet connection, please contact for business cooperation.

2. Run the pre-compiled emulator

2.1 Prepare the system environment

Refer to this documentation for the setup of the development environment.

SDK will use three ports of 7000/7100/49152. Make sure that they are not occupied by other programs.

Run the emulator of Android version, and the mDNS service needs to be launched in the Android system.

2.2 Run

In the downloaded directory of release, you can find an executable file named startEmulator, then run on the corresponding system (must have an Internet connection):

$ ./startEmulator

When the device is connected, the corresponding logs will be output continuously, and the emulator will ensure that the connection is not interrupted.

2.3 Record

The emulator provides the ability to record audio and video streams in the Screen Mirroring mode:

$ env AIRFLY_REC_M=T ./startEmulator

The mkv and wav files will be generated in the /tmp/ directory (/mnt/sdcard/ in the Android version), where the wav file can be played directly with the player.

For mkv file, as the frame is saved without head, it can be first converted to standard format by using ffmpeg and then play with the player:

$ ffmpeg -i airplay_video.mkv -vcodec copy std.mkv

For the recording function of other content streaming, you can refer to the contents of the next section to develop on your own.

3. API-based development

3.1 Example of minimization

The code in Emulator.cpp is the example of minimization, which provides the same functionality as the emulator:

#include "AirFly.h"
#include <string>
#include <unistd.h>

int main()
{
    AirFlyParameters_t paras;
    strcpy(paras.password, "");
    paras.isPhotoUseMemorySpace = false;
    strcpy(paras.preferResolution, "1080");
    paras.isModernPlayer = false;
    memset(&paras.cbs, 0, sizeof(AirFlyFunctionCbs_t));  // important

    AirFlyInit(paras);
    AirFlyStartAll();

    pause();
    return 0;
}

Compile linux version and run:

$ g++ -m32 -o myAirPlayEmulator Emulator.cpp -L./lib -Wl,-rpath=./lib -lAirFlyProtocol -lavahi-client -lavahi-common -ldbus-1 -lrt -ldl -lssl -lcrypto -pthread
$ ./myAirPlayEmulator

Or compile Android version with Android release:

$ /usr/local/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-g++ -o myAirPlayEmulator Emulator.cpp -L./lib -Wl,-rpath=./lib -rdynamic -fPIE -pie -lAirFlyProtocol -ldl -lssl -lcrypto -llog -pthread

3.2 Example of modifying the display name

The modification of Emulator.cpp is as follows, add the callback function to display name:

#include "AirFly.h"
#include <string>
#include <unistd.h>

static std::string GetSystemFriendlyName()
{
    return "AirFly Demo";
}

int main()
{
    AirFlyParameters_t paras;
    strcpy(paras.password, "");
    paras.isPhotoUseMemorySpace = false;
    strcpy(paras.preferResolution, "1080");
    paras.isModernPlayer = false;
    memset(&paras.cbs, 0, sizeof(AirFlyFunctionCbs_t));  // important

    paras.cbs.GetSystemFriendlyName = GetSystemFriendlyName;

    AirFlyInit(paras);
    AirFlyStartAll();

    pause();
    return 0;
}

The difference between this example and the emulator is that the name of AirPlay Receiver at run time is AirFly Demo.

3.3 Playback of Screen Mirroring

The playback of Screen Mirroring needs to rely on the specific player. Here it is assumed that there is a DummyPlayer that supports audio and video separation and the following interface is provided (type statement omitted):

DP      *DummyPlayerCreate(enum DP_VIDEO_TYPE vtype, enum DP_AUDIO_TYPE atype);
int      DummyPlayerDestroy(DP *dp);
void     DummyPlayerSetAudioAttr(DP *dp, enum DP_AUDIO_ATTR attr, int64_t value);
int64_t  DummyPlayerSendVideoData(DP *dp, const char *buf, size_t len);
int64_t  DummyPlayerSendAudioData(DP *dp, const char *buf, size_t len);

As it is known from AirFly.h, the main callback interface is as follows:

void (*StartMirrorPlayback) (const std::string& ip, bool isAudioOnly);
void (*StopMirrorPlayback)  (const std::string& ip);
int  (*WriteMirrorAudioData)(const std::string& ip, const void *p_src, int size, double ptsValue);
int  (*WriteMirrorVideoData)(const std::string& ip, const void *p_src, int size, double ptsValue);

Then the Emulator.cpp can be modified as follows, associate the DummyPlayer interfaces and the SDK callback interfaces:

#include "AirFly.h"
#include "DummyPlayer.h"
#include <string>
#include <unistd.h>

static DP *dp;

void StartMirrorPlayback(const std::string& ip, bool isAudioOnly)
{
    dp = DummyPlayerCreate(DP_VIDEO_TYPE_H264, DP_AUDIO_TYPE_PCM);
    DummyPlayerSetAudioAttr(dp, DP_AUDIO_ATTR_CHANNEL, 2);
    DummyPlayerSetAudioAttr(dp, DP_AUDIO_ATTR_BITS, 16);
    DummyPlayerSetAudioAttr(dp, DP_AUDIO_ATTR_SAMPLE_RATE, 44100);
}

void StopMirrorPlayback(const std::string& ip)
{
    DummyPlayerDestroy(dp);
}

int WriteMirrorAudioData(const std::string& ip, const void *p_src, int size, double ptsValue)
{
    return DummyPlayerSendAudioData(dp, p_src, size);
}

int WriteMirrorVideoData(const std::string& ip, const void *p_src, int size, double ptsValue)
{
    return DummyPlayerSendVideoData(dp, p_src, size);
}

int main()
{
    AirFlyParameters_t paras;
    strcpy(paras.password, "");
    paras.isPhotoUseMemorySpace = false;
    strcpy(paras.preferResolution, "1080");
    paras.isModernPlayer = false;
    memset(&paras.cbs, 0, sizeof(AirFlyFunctionCbs_t));  // important

    paras.cbs.StartMirrorPlayback  = StartMirrorPlayback;
    paras.cbs.StopMirrorPlayback   = StopMirrorPlayback;
    paras.cbs.WriteMirrorAudioData = WriteMirrorAudioData;
    paras.cbs.WriteMirrorVideoData = WriteMirrorVideoData;

    AirFlyInit(paras);
    AirFlyStartAll();

    pause();
    return 0;
}

As the above four callback interfaces are not called by the same thread, and may be protected by using mutex.

4. FAQ

Does the AirFly Receiver SDK also support other systems such as some embedded Linux system, as well as Windows system? If so, how to get them?

SDK supports Linux/macOS/Windows, and of course Android and various types of embedded Linux systems.
SDK of the free version is designed to help reduce the technical threshold for most developers who develop AirPlay Receiver, so only the versions with more receivers will be provided.
Other versions can be obtained through business cooperation.

How can I get technical support when I have some difficulties in the development process by using AirFly Receiver SDK?

No technical support will be provided for SDK of the current free version.
For customers established through our business cooperation channel, we provide support via mail, work orders and telephone.

Can the free AirFly Receiver SDK be used in the production environment?

It is very dangerous as there are various restrictions in the SDK of the free version, and it can only be used by developers.

AirFly Receiver SDK is crashed in the run time, which is very unstable.

The free version of the SDK needs to complete some of the key work in the AirPlay protocol by depending on the Internet connection, so it will crash when the network is unstable, and you will usually see Network unavailable, protocol panic.
There are restrictions of use times in the free version of the SDK after each start, and you will see the output Test over, exit now, before the exit.
The version which does not depend on the Internet connection is quite stable. If you need this version, please contact for business cooperation.

Running of the protocol emulator cannot be found on iOS/macOS.

This is because the system environment is not ready, so please read carefully the part about building the development environment and running on this page.
It is also possible that the router does not allow Zeroconf, and please check this item.

In the development process by using AirFly Receiver SDK, I encountered more difficulties because there are more callback interfaces.

Due to the complexity of AirPlay technology and the diversity of AirPlay scenes, it is inevitable to provide more callback interfaces to suit all situations.
There are detailed descriptions of how to use the various interfaces in AirFly.h. For the use scenarios, the interfaces can be generally divided into several categories, which are briefly described as follows:

System Interface  System Universal Interface
Video Interface   Video Interface under mirror and non-mirror
Audio Interface   Audio interface under non-mirror
Photo Interface   Photo interface under some situations 
Mirror Interface  Mirror Interface

The picture and sound are not smooth when using Screen Mirroring.

As the SDK is compiled by using C/C++, it is in good performance. When it is not smooth, the following several items shall be mainly checked:

  • Whether the network environment is good and clean
  • System CPU usage
  • Whether the codes related to the player are less efficient
  • Whether the player parameters are optimized

Whether AirFly Receiver SDK supports YouTube?

SDK can support YouTube, but the free version does not. If you need to make it support YouTube, please contact for business cooperation.