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

Bad audio packet detected with HTC Connect #338

Closed
joerg-krause opened this issue Jul 11, 2016 · 19 comments
Closed

Bad audio packet detected with HTC Connect #338

joerg-krause opened this issue Jul 11, 2016 · 19 comments

Comments

@joerg-krause
Copy link

joerg-krause commented Jul 11, 2016

HTC supports AirPlay on some Android devices, e.g. the HTC 10. To use AirPlay on these devices you need to install the updated HTC Connect app: http://www.cnet.com/how-to/how-to-use-apple-airplay-on-the-htc-10/. HTC has an officially license to use the protocol natively from Apple: http://9to5mac.com/2016/04/12/htc-10-first-android-device-native-airplay-streaming/.

Using HTC Connect with shairport-sync results in a lot of these messages:

Output from alac_decode is smaller than expected. Encrypted = 0.
Bad audio packet detected and discarded.

This is the log until the first occurence of the error:

one thread joined...
New RTSP connection from 192.168.1.116:33846 to self at 192.168.1.105:5000.
    User-Agent: iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5.
    Client-Instance: 0b3a8e540082889a.
    DACP-ID: 56B29BB6CB904862.
    Active-Remote: 1986535575.
    CSeq: 1.
RTSP Packet received of type "OPTIONS":
  Type: "User-Agent", content: "iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5"
  Type: "Client-Instance", content: "0b3a8e540082889a"
  Type: "DACP-ID", content: "56B29BB6CB904862"
  Type: "Active-Remote", content: "1986535575"
  Type: "CSeq", content: "1"
RTSP Response:
  Type: "CSeq", content: "1"
  Type: "Server", content: "AirTunes/105.1"
  Type: "Public", content: "ANNOUNCE, SETUP, RECORD, PAUSE, FLUSH, TEARDOWN, OPTIONS, GET_PARAMETER, SET_PARAMETER"
    User-Agent: iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5.
    Client-Instance: 0b3a8e540082889a.
    DACP-ID: 56B29BB6CB904862.
    Active-Remote: 1986535575.
    Content-Type: application/sdp.
    CSeq: 2.
    Content-Length: 184.
RTSP Packet received of type "ANNOUNCE":
  Type: "User-Agent", content: "iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5"
  Type: "Client-Instance", content: "0b3a8e540082889a"
  Type: "DACP-ID", content: "56B29BB6CB904862"
  Type: "Active-Remote", content: "1986535575"
  Type: "Content-Type", content: "application/sdp"
  Type: "CSeq", content: "2"
  Type: "Content-Length", content: "184"
Play connection from user agent "iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5".
RTSP Response:
  Type: "CSeq", content: "2"
  Type: "Server", content: "AirTunes/105.1"
    User-Agent: iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5.
    Client-Instance: 0b3a8e540082889a.
    DACP-ID: 56B29BB6CB904862.
    Active-Remote: 1986535575.
    Transport: RTP/AVP/UDP;unicast;interleaved=0-1;mode=record;control_port=53955;timing_port=52186.
    CSeq: 3.
RTSP Packet received of type "SETUP":
  Type: "User-Agent", content: "iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5"
  Type: "Client-Instance", content: "0b3a8e540082889a"
  Type: "DACP-ID", content: "56B29BB6CB904862"
  Type: "Active-Remote", content: "1986535575"
  Type: "Transport", content: "RTP/AVP/UDP;unicast;interleaved=0-1;mode=record;control_port=53955;timing_port=52186"
  Type: "CSeq", content: "3"
Active-Remote string seen: "1986535575".
DACP-ID string seen: "56B29BB6CB904862".
User-Agent is iTunes 10 or better, (actual version is 10); selecting the iTunes latency of -1 frames.
rtp_setup: cport=53955 tport=52186.
Set up play connection from 192.168.1.116 to self at 192.168.1.105.
listening for audio, control and timing on ports 6001, 6002, 6003.
RTSP Response:
  Type: "CSeq", content: "3"
  Type: "Server", content: "AirTunes/105.1"
  Type: "Transport", content: "RTP/AVP/UDP;unicast;interleaved=0-1;mode=record;control_port=6002;timing_port=6003;server_port=6001"
  Type: "Session", content: "1"
Control receiver -- Server RTP thread starting.
Audio receiver -- Server RTP thread starting.
Timing receiver -- Server RTP thread starting.
    User-Agent: iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5.
    Client-Instance: 0b3a8e540082889a.
    DACP-ID: 56B29BB6CB904862.
    Active-Remote: 1986535575.
    Session: 1.
    Range: npt=0-.
    RTP-Info: seq=33828;rtptime=10000.
    CSeq: 4.
RTSP Packet received of type "RECORD":
  Type: "User-Agent", content: "iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5"
  Type: "Client-Instance", content: "0b3a8e540082889a"
  Type: "DACP-ID", content: "56B29BB6CB904862"
Timing sender thread starting.
  Type: "Active-Remote", content: "1986535575"
  Type: "Session", content: "1"
  Type: "Range", content: "npt=0-"
  Type: "RTP-Info", content: "seq=33828;rtptime=10000"
  Type: "CSeq", content: "4"
Flush requested up to 9999. It seems as if 0 is special.
RTSP Response:
  Type: "CSeq", content: "4"
  Type: "Server", content: "AirTunes/105.1"
  Type: "Audio-Latency", content: "11025"
    User-Agent: iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5.
    Client-Instance: 0b3a8e540082889a.
    DACP-ID: 56B29BB6CB904862.
    Active-Remote: 1986535575.
    Session: 1.
    Content-Type: text/parameters.
    CSeq: 5.
    Content-Length: 20.
RTSP Packet received of type "SET_PARAMETER":
  Type: "User-Agent", content: "iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5"
  Type: "Client-Instance", content: "0b3a8e540082889a"
  Type: "DACP-ID", content: "56B29BB6CB904862"
  Type: "Active-Remote", content: "1986535575"
  Type: "Session", content: "1"
  Type: "Content-Type", content: "text/parameters"
  Type: "CSeq", content: "5"
  Type: "Content-Length", content: "20"
volume: -21.000000

Setting volume db to -3068.000000.
RTSP Response:
  Type: "CSeq", content: "5"
  Type: "Server", content: "AirTunes/105.1"
    User-Agent: iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5.
    Client-Instance: 0b3a8e540082889a.
    DACP-ID: 56B29BB6CB904862.
    Active-Remote: 1986535575.
    Session: 1.
    Content-Type: text/parameters.
    CSeq: 6.
    Content-Length: 29.
RTSP Packet received of type "SET_PARAMETER":
  Type: "User-Agent", content: "iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5"
  Type: "Client-Instance", content: "0b3a8e540082889a"
  Type: "DACP-ID", content: "56B29BB6CB904862"
  Type: "Active-Remote", content: "1986535575"
  Type: "Session", content: "1"
  Type: "Content-Type", content: "text/parameters"
  Type: "CSeq", content: "6"
  Type: "Content-Length", content: "29"
RTSP Response:
  Type: "CSeq", content: "6"
  Type: "Server", content: "AirTunes/105.1"
    User-Agent: iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5.
    Client-Instance: 0b3a8e540082889a.
    DACP-ID: 56B29BB6CB904862.
    Active-Remote: 1986535575.
    Session: 1.
    Content-Type: text/parameters.
    CSeq: 7.
    Content-Length: 20.
RTSP Packet received of type "SET_PARAMETER":
  Type: "User-Agent", content: "iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5"
  Type: "Client-Instance", content: "0b3a8e540082889a"
  Type: "DACP-ID", content: "56B29BB6CB904862"
  Type: "Active-Remote", content: "1986535575"
  Type: "Session", content: "1"
  Type: "Content-Type", content: "text/parameters"
  Type: "CSeq", content: "7"
  Type: "Content-Length", content: "20"
volume: -21.000000

Setting volume db to -3068.000000.
RTSP Response:
  Type: "CSeq", content: "7"
  Type: "Server", content: "AirTunes/105.1"
    User-Agent: iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5.
    Client-Instance: 0b3a8e540082889a.
    DACP-ID: 56B29BB6CB904862.
    Active-Remote: 1986535575.
    Session: 1.
    Content-Type: text/parameters.
    CSeq: 8.
    Content-Length: 20.
RTSP Packet received of type "SET_PARAMETER":
  Type: "User-Agent", content: "iTunes/10.6 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/535.18.5"syncing to seqno 33828.

  Type: "Client-Instance", content: "0b3a8e540082889a"
  Type: "DACP-ID", content: "56B29BB6CB904862"
  Type: "Active-Remote", content: "1986535575"
  Type: "Session", content: "1"
  Type: "Content-Type", content: "text/parameters"
  Type: "CSeq", content: "8"
  Type: "Content-Length", content: "20"
volume: -21.000000

Open Mixer
Mixer device name is "softvol".
Mixer Control name is "Master".
Setting volume db to -3068.000000.
RTSP Response:
  Type: "CSeq", content: "8"
  Type: "Server", content: "AirTunes/105.1"
Setting volume db to -3068.000000.
Output from alac_decode is smaller than expected. Encrypted = 0.
Bad audio packet detected and discarded
@mikebrady
Copy link
Owner

Hi Jörg Krause. This is intriguing. Does any sound come from Shairport Sync?

@joerg-krause
Copy link
Author

Only some chunks.

@joerg-krause
Copy link
Author

I enhanced the debug output of https://github.com/mikebrady/shairport-sync/blob/master/player.c#L249 to print the value of the variable outsize:

Output from alac_decode is smaller than expected (604 < 1408). Encrypted = 0.
Output from alac_decode is smaller than expected (488 < 1408). Encrypted = 0.
Output from alac_decode is smaller than expected (484 < 1408). Encrypted = 0.
Output from alac_decode is smaller than expected (488 < 1408). Encrypted = 0.
Output from alac_decode is smaller than expected (488 < 1408). Encrypted = 0.
Output from alac_decode is smaller than expected (484 < 1408). Encrypted = 0.
Output from alac_decode is smaller than expected (488 < 1408). Encrypted = 0.
Output from alac_decode is smaller than expected (948 < 1408). Encrypted = 0.

@joerg-krause
Copy link
Author

I added some debug outputs to the alac decoder and compared the outputs between HTC Connect and iOS 9.3. The main difference are the parameter hassize and isnotcompressed:

Parameter HTC Connect iOS
hassize 1 0
isnotcompressed 1 0

Additionally, I added a debug message to see if a 'good' audio packet was detected [](compared to a ['bad' audio packet]%28https://github.com/mikebrady/shairport-sync/blob/master/player.c#L401%29). Furhtermore, I logged the output samples in the ALAC decoder. This is the output for the HTC Connect:

outputsamples = 352
Good audio packet detected.

outputsamples = 352
Good audio packet detected.

outputsamples = 352
Good audio packet detected.

outputsamples = 151
Bad audio packet detected and discarded.

outputsamples = 352
Good audio packet detected.

outputsamples = 352
Good audio packet detected.

outputsamples = 352
Good audio packet detected.

outputsamples = 352
Good audio packet detected.

outputsamples = 352
Good audio packet detected.

outputsamples = 122
Bad audio packet detected and discarded.

@joerg-krause
Copy link
Author

I can confirm that HTC Connect works fine with an Apple TV.

@mikebrady
Copy link
Owner

Hi Jörg-Krause. Thanks for all this detective work. I am very reluctant to start using the Apple decoder at this time, as the way I went about including it is a dirty rotten hack. It'll take me a while to straighten it out for public consumption. In any case, it would still suffer from the problem of that all packets are assumed to be the same length – 352 frames. This assumption is built in to Shairport Sync, and is not a property of the existing decoder, made by David Hammerton.

What I will try to do is modify Shairport Sync to work when the number of frames is less than 352. Then we can see if David Hammerton's decoder continues to work. If not, then we might be forced to use the Apple decoder.

@joerg-krause
Copy link
Author

Fair enough! Many thanks!

@mikebrady
Copy link
Owner

mikebrady commented Jul 15, 2016

Thanks. Part of my delay in responding was [unsuccessfully] trying to get hold of a HTC phone. Anyway, I'll keep trying.

@mikebrady
Copy link
Owner

I've just pushed a new branch called small-packets that should work, but I haven't really been able to test it. Would you be kind enough to give it a try?

@joerg-krause
Copy link
Author

Awesome! Yeah, it works! Many thanks for implementing this without the ability to test!

@mikebrady
Copy link
Owner

Thanks to you for such precise information – it would not have been possible to attempt this otherwise. I made quite a few changes, so it really needs a lot of testing. I'll move it to the development branch in the next few days.

@mikebrady
Copy link
Owner

Hi Jörg-Krause. Would you have any statistics output from the HTC? Most of the Android implementations of AirPlay players I've seen so far have wide timing variations and I was wondering if an "official" one would be better...

@joerg-krause
Copy link
Author

Sure!

sync error in frames, net correction in ppm, corrections in ppm, total packets, missing packets, late packets, too late packets, resend requests, min DAC queue size, min buffer occupancy, max buffer occupancy
     -27.2,      73.7,     146.7,        3758,      0,      2,      0,      2,   4418,  281,  302
      88.4,      17.4,     229.1,        7516,      0,      2,      0,      2,   4809,  277,  300
     105.1,      37.0,     422.6,       11274,      0,      3,      0,      3,   5030,  262,  301
     111.0,      21.9,     206.4,       15032,      0,     10,      0,     10,   5166,  273,  300
       2.5,      31.8,     340.2,       18790,      0,     11,      0,     11,   4788,  274,  301
     252.7,    -266.1,     313.0,       22548,      0,     13,      0,     13,   5248,  274,  300
     -56.5,     136.8,     333.4,       26306,      0,     15,      0,     15,   4817,  265,  301
      47.4,      18.1,     532.2,       30064,      0,     15,      0,     15,   4895,  229,  301
     140.6,     -24.2,     563.9,       33822,      0,     15,      0,     15,   4874,  275,  301
     100.3,    -138.3,     667.5,       37580,      0,     15,      0,     15,   4876,  282,  301
     -26.9,      83.2,     681.9,       41338,      0,     15,      0,     15,   4730,  277,  301
      74.9,     -48.4,     642.6,       45096,      0,     17,      0,     17,   4673,  267,  301
     -92.7,    -127.8,     856.5,       48854,      0,     17,      0,     17,   4847,  276,  301
    -210.7,     242.7,     451.3,       52612,      0,     17,      0,     17,   4782,  276,  301
     114.3,     -74.8,     353.0,       56370,      0,     17,      0,     17,   5078,  275,  301
     100.0,      13.6,     291.8,       60128,      0,     23,      0,     23,   5156,  266,  301
    -157.8,     433.9,     470.2,       63886,      0,     23,      0,     23,   4874,  274,  301
     -98.4,     294.1,     353.0,       67644,      0,     23,      0,     23,   4884,  286,  301
       6.0,      93.7,      93.7,       71402,      0,     24,      0,     24,   4818,  276,  300
     112.6,    -142.9,     356.1,       75160,      0,     24,      0,     24,   4651,  280,  301
     125.8,      83.2,     276.7,       78918,      0,     28,      0,     28,   4822,  276,  301
      40.8,     -68.0,     358.3,       82676,      0,     28,      0,     28,   4928,  278,  300
      19.6,     -42.3,     592.7,       86434,      0,     28,      0,     28,   4878,  281,  300
     117.1,     -18.9,     717.4,       90192,      0,     29,      0,     29,   4621,  275,  301
     134.3,     -31.0,     582.8,       93950,      0,     29,      0,     29,   4684,  274,  301
      81.1,     -24.2,     606.3,       97708,      0,     30,      0,     30,   4745,  265,  300
     100.7,     110.4,     695.5,      101466,      0,     30,      0,     30,   4698,  281,  301
     160.1,     -70.3,     591.9,      105224,      0,     30,      0,     30,   4684,  285,  300
     -25.6,      46.1,     489.1,      108982,      0,     30,      0,     30,   4838,  277,  301
     130.5,    -223.0,    1047.0,      112740,      0,     34,      0,     34,   4794,  262,  302
      -3.1,      23.4,     539.0,      116498,      0,     34,      0,     34,   4839,  277,  301
     -34.1,      62.7,     486.1,      120256,      0,     34,      0,     34,   4418,  283,  301
      49.6,      34.0,     681.1,      124014,      0,     34,      0,     34,   4830,  277,  301
     -28.0,     153.5,     451.3,      127772,      0,     34,      0,     34,   4588,  278,  300
     -39.9,     207.1,     598.7,      131530,      0,     39,      0,     39,   4886,  263,  301
     -70.7,     156.5,     688.7,      135288,      0,     39,      0,     39,   4704,  269,  301
    -155.9,      47.6,     743.1,      139046,      0,     39,      0,     39,   4736,  257,  300
    -219.5,     -35.5,     959.3,      142804,      0,     42,      0,     42,   4468,  277,  300
    -145.9,     101.3,     943.4,      146562,      0,     47,      0,     47,   4790,  261,  301
     -72.7,    -114.2,     501.2,      150320,      0,     47,      0,     47,   4657,  281,  301
    -119.9,     -15.1,     594.2,      154078,      0,     47,      0,     47,   4817,  276,  300
    -206.4,      68.0,     680.4,      157836,      0,     49,      0,     49,   4645,  283,  301
    -179.7,      63.5,     468.7,      161594,      0,     49,      0,     49,   4852,  273,  301
     225.3,     255.5,     293.3,      165352,      4,     63,     14,     77,      0,   53,  302
     426.5,    -282.7,     282.7,      169110,      4,     63,     14,     77,   5369,  275,  298
     217.1,     -96.0,      97.5,      172868,      4,     64,     14,     78,   5270,  287,  298
     184.4,       0.8,       0.8,      176626,      4,     64,     14,     78,   5205,  289,  298
      52.7,     -55.9,     105.8,      180384,      4,     69,     14,     83,   5211,  265,  298
      -4.2,      13.6,      16.6,      184142,      4,     69,     14,     83,   4937,  285,  298
      47.6,    -164.8,     417.3,      187900,      4,     71,     14,     85,   4901,  287,  299
     -50.1,      88.4,     285.0,      191658,      4,     71,     14,     85,   5137,  287,  298
      24.9,     -50.6,      90.0,      195416,      4,     71,     14,     85,   5136,  242,  298
      -2.5,    -130.8,     244.2,      199174,      4,     72,     14,     86,   4981,  266,  298
     -58.5,     -18.9,     554.1,      202932,      4,     72,     14,     86,   4948,  280,  298
      56.2,     138.3,     242.7,      206690,      4,     72,     14,     86,   5105,  274,  298
      74.5,     114.2,     295.6,      210448,      4,     72,     14,     86,   5050,  284,  299
      93.1,     -93.0,     100.5,      214206,      4,     73,     14,     87,   5139,  268,  298
      52.5,    -105.1,     215.4,      217964,      4,     73,     14,     87,   5211,  278,  298
       1.2,      44.6,     318.3,      221722,      4,     73,     14,     87,   5030,  278,  298
     -55.4,     139.9,     223.0,      225480,      4,     73,     14,     87,   4986,  275,  298
     -63.7,     464.2,     485.3,      229238,      4,     73,     14,     87,   4970,  273,  299
       9.2,     239.6,     239.6,      232996,      4,     76,     14,     90,   5024,  268,  298
     177.4,      -6.0,     151.2,      236754,      4,     76,     14,     90,   5109,  251,  298
     108.1,      -7.6,      24.2,      240512,      4,     76,     14,     90,   5022,  273,  299

@mikebrady
Copy link
Owner

Thanks. It looks like the timing variations are just as large – it's probably worth making the drift larger, e.g. 176 or even 352...

@joerg-krause
Copy link
Author

I did set the drift to 882.

@mikebrady
Copy link
Owner

Wow, then it's really all over the place!

@joerg-krause
Copy link
Author

Sorry, but what does it mean?

@mikebrady
Copy link
Owner

Sorry – it's English idiom -- see http://english.stackexchange.com/a/310124 for example. In this situation it means that the HTC's timing is very imprecise.

@joerg-krause
Copy link
Author

I see! I thought as much, but was not sure. Many thanks for the explanation.

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

No branches or pull requests

2 participants