HTTP Live Streaming in iOS

HTTP Live Streaming in iOS

Presented at Battle Conference U30 http://bcu30.jp/
11 MAR. 2017
Sample app repository: https://github.com/ra1028/LiveStreamingApp

439ebe4787a98881df8a59d41baf4a43?s=128

Ryo Aoyama

March 11, 2017
Tweet

Transcript

  1. HTTP Live Streaming in iOS 2017/03/11 Battle Conference U30 Ryo

    Aoyama / ra1028 CyberAgent, Inc
  2. None
  3. FRESH!
 ϩάΠϯෆཁɾߴը࣭Ͱੜ์ૹ͕ݟ์୊

  4. Contents ̋ ͬ͘͟ΓHLSʹ͍ͭͯ ̋ ΋ͬͱͬ͘͟ΓAVFoundationʹ͍ͭͯ ̋ σϞ

  5. HLS

  6. Appleۘ੡ͷετϦʔϛϯάಈը഑৴ϓϩτίϧ HTTP Live Streaming Live or VOD(Video On Demand) HLS

    ηάϝϯτϑΝΠϧ ʴ ϓϨΠϦετ
  7. ಈըϑΝΠϧΛ͋ΔҰఆ࣌ؒͷࡉ͔͍MPEG2-TS ηάϝϯτϑΝΠϧʹ෼ׂͨ͠΋ͷ ηάϝϯτϑΝΠϧ .ts

  8. ηάϝϯτϑΝΠϧͷҐஔɺ࠶ੜ࣌ؒɺߋ৽ස౓ͳͲͷ ৘ใ͕هࡌ͞ΕͨϝλσʔλϑΝΠϧ ϓϨΠϦετ .m3u8

  9. ΦϦδφϧͷಈըϑΝΠϧ ηάϝϯτϑΝΠϧ܈ʹ෼ׂ

  10. ߋ৽ස౓৘ใΛ࢖ͬͯ ఆظతʹϓϨΠϦετͷߋ৽Λ؂ࢹ

  11. ߋ৽͕͋Ε͹࠷৽ͷ tsϑΝΠϧΛऔಘ͢Δ

  12. ߋ৽͕ͳ͚Ε͹؂ࢹ͠ͳ͕Β ࣍ͷߋ৽·Ͱ଴ͭ ͜ͷ͕࣌ؒൃੜ͠ͳ͍Α͏ͷʹߋ৽ස౓ͱ TSϑΝΠϧ࠶ੜ࣌ؒ͸ௐ੔͢Δɻ

  13. ͜ͷλά͕͋Δ͜ͱͰϓϨΠϦετ ͸ऴྃ͢Δࣄ͕Ͱ͖ΔͨΊɺVODͱ Έͳ͢͜ͱ͕Ͱ͖Δɻ

  14. جຊతʹ͸ɺ ಈըΛMPEG2-TSϑΝΠϧʹ෼ׂɺϓϨΠϦετΛߋ৽ ΫϥΠΞϯτଆͰϓϨΠϦετΛ؂ࢹɺߋ৽͞ΕͨΒ࠷৽ ͷ.tsϑΝΠϧΛ࠶ੜ ͜Ε͚ͩͰ׬݁͢Δγϯϓϧͳϓϩτίϧɻ HLS·ͱΊ

  15. iOS୺຤ͰHLS͔ΒಈըΛ࠶ੜ͢Δʹ͸ AVFoundation

  16. ࣸਅɺԻָɺಈըͷAPIΛఏڙ͢ΔɺiOS, macOS, tvOS౳ ޲͚ͷFrameworkɻ HLS͸Apple੡ͷͨΊެࣜͰڧྗʹαϙʔτ͞Ε͍ͯΔɻ ͨͩ͠ɺཧղ͠೉͍APIͱ҉໧ͷ࢓༷͕͖ͭ·ͱ͏… AVFoundation

  17. AVAsset ಈըࣗମͷϝσΟΞσʔλ΍ϝλσʔλΛϩʔυ͠ɺอ࣋ ͢ΔΫϥεɻ ͜ͷΫϥεΛҾ਺ͱͯ͠ ͷΠϯελϯεΛ࡞ Δɻ AVPlayerItem

  18. AVPlayerItem ಈըͷ࠶ੜεςʔλε΍λΠϜυϝλσʔλͳͲΛऔಘ͢ ΔΫϥεɻ ഔհͱͯ͠AVAssetͷ৘ใΛऔಘ͢Δ͜ͱ͕Ͱ͖Δɻ ͜ͷΫϥεΛҾ਺ͱͯ͠ ͷΠϯελϯεΛ࡞Δɻ AVPlayer

  19. AVPlayer ಈըͷ࠶ੜɺఀࢭͳͲΛ؅ཧ͢ΔίϯτϩʔϥΫϥεɻ Ի੠ɺ࠶ੜϨʔτͷઃఆ΍γʔΫͳͲ΋͜ͷΫϥεΛհ͠ ͯߦ͏ɻ ͜ͷΫϥεΛ ʹઃఆ͢Δ͜ͱͰಈըΛඳը ͢Δ͜ͱ͕Ͱ͖Δɻ AVPlayerLayer

  20. AVPlayerLayer AVPlayer͔Βͷ৘ใΛ࢖ͬͯಈըΛඳը͢ΔUIΛఏڙ͢Δ Ϋϥεɻ CALayerͷαϒΫϥεͳͷͰUIViewͷlayerClassΛ overrideͯ͠࢖༻͢Δ͜ͱ͕ଟ͍ɻ

  21. AVPlayerItem AVAsset AVPlayer ಈը৘ใͷऔಘ׬ྃ(࠶ੜՄೳ) AVPlayerLayer UIView ΠϯελϯεΛੜ੒ (ϝΠϯεϨουʂ) දࣔ४උ׬ྃ UIʹಈը৘ใΛ༩͑ɺ

    ඳըͤ͞Δ
  22. AVPlayerItem AVAsset AVPlayer AVPlayerLayer UIView ಈըΛมߋ͢Δ৔߹͸͜Ε Βͷάϧʔϓશͯഁغ͢Δ ಛʹͷ̎ͭ͸ಉҰεϨου Ͱಉ࣌ʹഁغ

  23. ࡉ͔ͳ੍ޚΛߦΘͳ͍࠶ੜ·Ͱ͸ɺ͔ͳΓ؆қతʹHLSΛ ѻ͏ࣄ͕Ͱ͖Δɻ νϡʔχϯάͷͨΊʹϚϧνεϨουͰѻ͏ʹ͸஫ҙ͕ඞ ཁɻ AVFoundation·ͱΊ

  24. Demo

  25. ഑৴αʔόʔͱͯ͠ΧϝϥͰࡱͬ ͨಈը͔ΒHLSΛ഑৴͢Δɻ Demo αʔόʔiPhoneʹΞΫηεͯ͠ AVFoundationͰ࠶ੜ͢Δɻ

  26. Demo GitHub Repository: https://github.com/ra1028/LiveStreamingApp

  27. iOSͷAVFoundationɺAndroidͷExoPlayerͳͲʹΑͬͯ ωΠςΟϒͰ΋ڧྗʹαϙʔτ͞Ε͍ͯΔɻ iPhoneαʔόʔͰ΋഑৴Ͱ͖ͯ͠·͏΄Ͳγϯϓϧͳಈ ը഑৴ϓϩτίϧɻ Adaptive bitrate streamingͰճઢ଎౓ʹΑΓө૾඼࣭ Λ੾Γସ͑ͯɺ҆ఆͨ͠࠶ੜΛ୲อͰ͖Δɻ ·ͱΊ