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

複数のライブ映像を同期再生するのが大変だったので知見をお伝えします / iOSDC Japan 2018

FromAtom
August 31, 2018

複数のライブ映像を同期再生するのが大変だったので知見をお伝えします / iOSDC Japan 2018

iOSDC Japan 2018
2018/08/31 10:50~
Track C

FromAtom

August 31, 2018
Tweet

More Decks by FromAtom

Other Decks in Technology

Transcript

  1. ෳ਺ͷϥΠϒө૾Λ
    ಉظ࠶ੜ͢Δͷ͕େมͩͬͨͷͰ
    ஌ݟΛ͓఻͑͠·͢
    iOSDC Japan 2018
    2018.8.31 10:50~ Track C
    pixiv.inc
    FromAtom

    View full-size slide

  2. • FromAtom / @FromAtom / id:FromAtom
    • ͸ͯͳΠϯλʔϯˠ͸ͯͳΞϧόΠτˠϐΫγϒ
    • pixiv Sketch / pixiv Sketch LIVE / pixivίϛοΫ
    • Swift 1.2 ͔ΒiOSΞϓϦ։ൃͷੈք΁


    ࣗݾ঺հ

    View full-size slide

  3. ͓ֆ͔͖ίϛϡχέʔγϣϯΞϓϦ
    pixiv Sketch


    View full-size slide



  4. ϐΫγϒגࣜձࣾͬͯձࣾͰ͢

    View full-size slide



  5. ͍Ζ͍Ζ΍ͬͯ·͢

    View full-size slide



  6. ͜͜Ͱ౾஌ࣝ

    View full-size slide



  7. pixivͷ "p" ͸খจࣈ

    View full-size slide



  8. γϧόʔεϙϯαʔͰ͢ʂ

    View full-size slide



  9. ϊϕϧςΟ΋༻ҙ͓ͯ͠Γ·͢ʂ

    View full-size slide



  10. खʹೖΕΔํ๏

    View full-size slide



  11. ϐΫγϒࣾһΛݟ͚͍ͭͯͩ͘͞

    View full-size slide



  12. ʮίʔυϨϏϡʔ͓ئ͍͠·͢ʯ

    View full-size slide



  13. ࠓ೔͸ઌண15ਓʹϓϨθϯτʂ
    ࣋ͬͯΔࣾһΛ୳ͤʂ

    View full-size slide

  14. ෳ਺ͷϥΠϒө૾Λ
    ಉظ࠶ੜ͢Δͷ͕େมͩͬͨͷͰ
    ஌ݟΛ͓఻͑͠·͢


    iOSDC Japan 2018
    08/31 10:50 Track C

    pixiv.inc
    FromAtom

    View full-size slide



  15. iOSͰಈը࠶ੜ͢Δ

    View full-size slide



  16. iOSͰಈը࠶ੜ͢Δ
    ࢀߟɿ [iOS] iOSͰಈըΛ࠶ੜ͢Δ̐ͭͷํ๏ | Developers.IO (https://dev.classmethod.jp/smartphone/ios-video/)
    ࠶ੜํ๏ ൑அج४ ࣮૷ίετ
    MPMoviePlayerController iOS9 ͔Β Deprecated -
    WKWebView ؆୯ʹαοͱग़͍ͨ࣌͠ খ
    AVPlayerViewController WKWebViewΑΓগ͚ͩ͠ڽΓ͍ͨ࣌ খ
    AVPlayer ෳࡶͳ੍ޚɾදࣔΛߦ͍͍ͨ࣌ େ

    View full-size slide



  17. WKWebView
    or
    AVPlayerViewController
    Λ࢖͓͏ʂʂʂ

    View full-size slide



  18. AVPlayer͸େม͔ͩΒ
    ࢖Θͳ͍Α͏ʹؤுͬͯʂʂʂ

    View full-size slide



  19. AVPlayerΛ͔ͭ͏࣌

    View full-size slide



  20. AVPlayerΛ͔ͭ͏࣌
    • ෳࡶͳ࠶ੜ੍ޚΛߦ͍͍ͨ
    • ಠࣗͷૢ࡞ύωϧΛ࡞Γ͍ͨ
    • ϑϧεΫϦʔϯػೳΛࣗ࡞͍ͨ͠
    • ෳ਺ಈըͷಉظ࠶ੜΛ࣮ݱ͍ͨ͠

    View full-size slide



  21. AVPlayerΛ͔ͭ͏࣌
    • ෳࡶͳ࠶ੜ੍ޚΛߦ͍͍ͨ
    • ಠࣗͷૢ࡞ύωϧΛ࡞Γ͍ͨ
    • ϑϧεΫϦʔϯػೳΛࣗ࡞͍ͨ͠
    • ෳ਺ಈըͷಉظ࠶ੜΛ࣮ݱ͍ͨ͠

    View full-size slide



  22. ͳΜͰෳ਺ಈըͷಉظ͢ΔΜʁ

    View full-size slide



  23. pixiv Sketch LIVE

    View full-size slide

  24. ෳ਺ਓ഑৴


    • ࠷େ4ਓ·Ͱಉ࣌഑৴͕Ͱ͖Δ
    • ഑৴ऀ͸్தͰ૿ݮ͢Δ
    • ࢹௌऀ͸͢΂ͯͷಈըΛ࠶ੜ

    View full-size slide

  25. ෳ਺ਓ഑৴


    • ࠷େ4ਓ·Ͱಉ࣌഑৴͕Ͱ͖Δ
    • ഑৴ऀ͸్தͰ૿ݮ͢Δ
    • ࢹௌऀ͸͢΂ͯͷಈըΛ࠶ੜ
    1
    2 3 4

    View full-size slide



  26. ෳ਺ਓ഑৴
    • ഑৴ऀಉ࢜͸WebRTCͰ௿஗ԆʹίϛϡχέʔγϣϯՄೳ
    • ࢹௌऀଆʹ͸HLSಈը͕࠷େ4ͭ߱ͬͯ͘Δ
    • ී௨ʹ࠶ੜ͢ΔͱHLSಈըͷ࠶ੜλΠϛϯά͕ζϨΔ
    • ձ࿩ͷ಺༰͕ζϨͯ·ͱ΋ʹࢹௌͰ͖ͳ͍

    View full-size slide



  27. ෳ਺HLSʢಈըʣͷಉظ࠶ੜ͕ඞཁ

    View full-size slide



  28. ͜ͷൃදͷํ਑
    • ϥΠϒ഑৴͞Ε͍ͯΔHLSಈըͷ࿩Λ͠·͢
    • ࣮૷ํ๏͸ WWDC 2017ͷ "Advances in HTTP Live Streaming" Ͱ΄΅෼͔Δ
    • αϯϓϧίʔυ΋͋Γ·͢
    • ͳͷͰৄ͍࣮͠૷ͷ࿩͸ͤͣɺίπ΍ϊ΢ϋ΢Λڞ༗͠·͢
    • কདྷෳ਺HLSΛಉظ࠶ੜ͢Δ࣌ͷखॿ͚ʹͳΔࢿྉΛ໨ࢦ͢
    ࢀߟɿ Advances in HTTP Live Streaming - WWDC2017 (https://developer.apple.com/videos/play/wwdc2017/504/)

    View full-size slide



  29. 1ͭͷHLSಈըΛ࠶ੜ͢Δࡍͷίπ

    View full-size slide



  30. AVPlayerLayerͷίπ
    LICENSE: "Big Buck Bunny" by Blender Foundation is licensed under CC BY 3.0
    ૝ఆ ݱ࣮

    View full-size slide



  31. • .frame Λઃఆ͠ͳ͍ͱಈըαΠζ͕͓͔͘͠ͳΔ
    AVPlayerLayerͷίπ

    View full-size slide



  32. KVOͷίπ
    • ͜ͷ5छྨΛ؂ࢹ͓ͯ͘͠
    • .status, .loadedTimeRangesɿओʹಉظ࠶ੜʹ࢖͏
    • .isPlayback*ɿϩʔσΟϯάɾϦϩʔυදࣔͷϋϯυϦϯάʹ࢖͏

    View full-size slide



  33. KVOͷίπ
    • removeObserver ͤͣʹഁغ͢Δͱ࣮ߦ࣌Ϋϥογϡ
    • iOS9 ͔Β NotificationCenter ͷ removeObserver ͸ෆཁʹͳ͚ͬͨͲKVO͸ผ
    ࢀߟɿiOS9Ҏ߱Ͱ͸ "NotificationCenter.default.removeObserver(_:name:object:)" Λdeinitʹॻ͔ͳͯ͘΋ྑ͍Ͱ͢Αɻ(https://fromatom.hatenablog.com/entry/2017/12/13/135542)

    View full-size slide



  34. KVOͷίπ
    • addObserver ͍ͯ͠ͳ͍ঢ়ଶͰ removeObserver ͢Δͱ࣮ߦ࣌Ϋϥογϡ
    • addObserver ͞Ε͍ͯΔ͔஌Δํ๏͕ͳͦ͞͏
    • DispatchQueueͱϑϥάΛ༻͍ͯஸೡʹ؅ཧ͢Δඞཁ͕͋Δ

    View full-size slide



  35. block-based KVOΛ࢖͏
    • removeObserver ͠ͳͯ͘΋Ϋϥογϡ͠ͳ͍
    • observer?.invalidate() Ͱ໌ࣔతʹഁغ΋Ͱ͖Δ

    View full-size slide



  36. ෳ਺ͷHLSಈըΛ࠶ੜ͢Δࡍͷίπ

    View full-size slide



  37. iOS 9 ͷαϙʔτΛ੾Δ
    • ಉظ࠶ੜʹඞཁͳAPI͕ iOS 10+
    • iOS 9 ҎલͰ͸Ͳ͏͕Μ͹ͬͯ΋ແཧ
    • શͯͷಈըΛಉ࣌ʹϦϩʔυͯٙ͠ࣅಉظͳͲ͸ՄೳʢζϨΔʣ
    • ΋͘͠͸ iOS 9 ͷ৔߹͚ͩಈըΛݟΕͳ͘͢Δ

    View full-size slide



  38. ಉظͷ࢓૊Έ
    ͬ͘͟Γͱ

    View full-size slide




  39. ࢠ ࢠ ࢠ
    Seekͯ͠࠶ੜ

    View full-size slide




  40. ࢠ ࢠ ࢠ
    ζϨΛΈΔ

    View full-size slide




  41. ࢠ ࢠ ࢠ
    Seekͯ͠࠶ੜ

    View full-size slide



  42. ઃܭͷίπ
    • View (VC) ʹσʔλ͕ີ݁߹͠΍͍͢
    • ෳ਺ͷಈը (UIView) ͕ີ݁߹ͯ͠େมʹͳΔʢͳͬͨʣ
    • ManagerΛ࡞ΓಉظʹඞཁͳσʔλΛView֎ʹग़͢
    • γϯάϧτϯ or ಈըΛ؅ཧ͢ΔView (VC) ʹΠϯελϯεΛ΋ͨͤΔ

    View full-size slide





  43. ͍·࣌ؒͲΜͳʁ

    View full-size slide





  44. ͍·࣌ؒͲΜͳʁ
    σʔλ

    View full-size slide




  45. Manager
    σ
    ʔ
    λ

    View full-size slide




  46. Manager
    σ
    ʔ
    λ

    ͍·࣌ؒͲΜͳʁ

    View full-size slide




  47. Manager
    σ
    ʔ
    λ



    View full-size slide

  48. খٳࢭ
    ͜͜Ͱ࢒Γ5෼ or 10෼ܦա ͩͱ͍͍ײ͡Β͍͠Α


    View full-size slide



  49. ϋϚͬͨ໰୊

    View full-size slide



  50. ਌ಈը͕ૣૹΓ͞ΕΔ
    • ࠶ੜˠ͠͹Β͘ࢹௌˠఀࢭˠ࠶ੜ Λߦͳ͏ͱى͜Δ
    • Buffer͕͔ͬ͠Γͱཷ·͍ͬͯΔͱൃੜ
    • ૣૹΓ͕ऴΘΔ·Ͱಉظ͕Ͱ͖ͳ͍ͷͰࢠͷಈը΋ࢭ·Δ

    View full-size slide



  51. ਌ಈը͕ૣૹΓ͞ΕΔ
    • preferredForwardBufferDuration ͷ஋Λখͯ͘͞͠ղܾ
    • ੜ੒͞Ε͍ͯΔHLSͷઃఆͰม͑ͨ΄͏͕ແ೉
    • σϑΥϧτ͸"0"ͰࣗಈͰ͍͍ײ͡ʹͯ͘͠ΕΔ
    • automaticallyWaitsToMinimizeStalling Λ true ʹ͠ͳ͍ͱ༗ޮʹͳΒͳ͍

    View full-size slide



  52. ࢠͷಈը͕࠶ੜ͞Εͳ͍
    • ಉظ࠶ੜʹ͸HLSͷ EXT-X-PROGRAM-DATE-TIME λάΛ࢖͏
    • ͜ͷλάͰࢦఆ͞Ε͕ͨ࣌ؒͣΕ͍ͯͨ
    • ͲͷϨΠϠʔͷ໰୊͔Θ͔ΒͣɺݪҼڀ໌ʹ͕͔͔࣌ؒͬͨ
    • αʔόαΠυͱͷίϛϡχέʔγϣϯ͕େࣄ
    ࢀߟɿHLS WWDC 2017 Preliminary spec (https://developer.apple.com/streaming/HLS-WWDC-2017-Preliminary-Spec.pdf)

    View full-size slide



  53. σόοάํ๏

    View full-size slide



  54. HLS͕ు͘ΤϥʔΛݟΔํ๏
    • .AVPlayerItemNewErrorLogEntry ͷ௨஌Λड͚औΔ
    • ௨஌Λड͚औͬͨΒ AVPlayer ͕͍࣋ͬͯΔ errorLog() ͷ࠷ޙΛݟΔ

    View full-size slide



  55. AVPlayerItemErrorLogEvent.errorComment ͷத਎
    Failure Error Code
    Authentication failures 401 Unauthorized
    Client doesn’t have permissions 403 Forbidden
    Resource unavailable but may become available in the future 404 Not Found
    Resource unavailable and will never become available in the future 410 Gone
    Internal server errors 500 Internal Server Error
    Invalid response from gateway 502 Bad Gateway
    Server unavailable 503 Service Unavailable
    Gateway timeouts 504 Gateway Time-Out
    ࢀߟɿError Handling Best Practices for HTTP Live Streaming - WWDC 2017 (https://developer.apple.com/videos/play/wwdc2017/514/?time=218)

    View full-size slide



  56. αʔόαΠυͱͷ࿈ܞ
    • αʔόαΠυ͸֤ϓϥοτϑΥʔϜʹରԠ͢Δඞཁ͕͋Δ
    • iOSͷSafariͰಈ͍ͯ΋AVPlayerͰ͸ಈ͔ͳ͍͜ͱ͕͋Δ
    • खݩͰؾܰʹσόοάͯ͠΋Β͑Δ΄͏͕Α͍

    View full-size slide



  57. σόοά༻ΞϓϦ
    • HLSͷURL͔Β࠶ੜͰ͖Δ
    • ֤छϩάΛਨΕྲྀ͍ͯ͠Δ
    • In-HouseϏϧυͰ഑෍
    LICENSE: "Big Buck Bunny" by Blender Foundation is licensed under CC BY 3.0

    View full-size slide



  58. Androidͷ৔߹͸ʁ

    View full-size slide



  59. google/ExoPlayer Λ࢖͑͹ղܾ
    • Googleۘ੡
    • શ෦΍ͬͯ͘ΕΔʂ࠷ߴʂ
    • https://github.com/google/ExoPlayer

    View full-size slide