Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

Ryo Aoyama

March 11, 2017
Tweet

More Decks by Ryo Aoyama

Other Decks in Programming

Transcript

  1. HTTP Live Streaming
    in iOS
    2017/03/11 Battle Conference U30
    Ryo Aoyama / ra1028
    CyberAgent, Inc

    View full-size slide

  2. FRESH!

    ϩάΠϯෆཁɾߴը࣭Ͱੜ์ૹ͕ݟ์୊

    View full-size slide

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

    View full-size slide

  4. Appleۘ੡ͷετϦʔϛϯάಈը഑৴ϓϩτίϧ
    HTTP Live Streaming
    Live or VOD(Video On Demand)
    HLS
    ηάϝϯτϑΝΠϧ ʴ ϓϨΠϦετ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide