In an attempt to get sidecar subtitles working in a native iOS app similarly to WebKits sidecar capabilities, I noticed that one can init an AVPlayerItem directly with a WebVTT URL. This seems to work an allows me to synchronize playback with a normal local asset, or remote without much issue.
What is interesting is that I get occasional crashes within WebVTTParserParseBlockBuffer but only when loading remote webVTT files. Local files from disk have not to my knowledge triggered the crash.
Questions:
A) Is it accepted and correct that an AVAsset may be initted with a URL pointing to only a WebVTT file on disk or remote? my AVAsset is reported like so :
po [self.subtitlePlayer.currentItem asset]
<AVURLAsset: 0x7ffe40f38500, URL = someURL.vtt>
(lldb) po [[self.subtitlePlayer.currentItem asset] tracks]
<__NSArrayM 0x7ffe40c39ac0>(
<AVAssetTrack: 0x7ffe4280dd60, trackID = 1, mediaType = text>
)
B) if so, it appears there is a bug in WebVTT parsing that rears its head on occasion. This smells thread like. Is there any particular nuance?
The same WebVTT file locally works sans issue (apparently so at least) - weve checked URL encoding, mime type issues etc, and about 19/20 times it works great, otherwise we get an error. Ive ensured all my asset loading and KVO is on the main queue.
Thank you for any information.
Backtrace and crash:
bt
* thread #6: tid = 0x1a6fc2, 0x000000011290b64d MediaToolbox`WebVTTParserParseBlockBuffer + 376, queue = 'URLAssetWorkQueue', stop reason = EXC_BAD_ACCESS (code=2, address=0x11cf06000)
* frame #0: 0x000000011290b64d MediaToolbox`WebVTTParserParseBlockBuffer + 376
frame #1: 0x000000011286f52e MediaToolbox`EnsureWebVTTFileIsParsed + 294
frame #2: 0x000000011286f2e7 MediaToolbox`WebVTTFormatReaderCopyTrackByIndex + 46
frame #3: 0x00000001128f3b09 MediaToolbox`EnsureTracksArrayCreated + 286
frame #4: 0x00000001128ec846 MediaToolbox`ProduceFormatReaderAssetProperty + 74
frame #5: 0x00000001128e9365 MediaToolbox`URLAssetPropertyWorkFunction + 333
frame #6: 0x0000000111d5f614 libdispatch.dylib`_dispatch_client_callout + 8
frame #7: 0x0000000111d466a7 libdispatch.dylib`_dispatch_queue_drain + 2176
frame #8: 0x0000000111d45cc0 libdispatch.dylib`_dispatch_queue_invoke + 235
frame #9: 0x0000000111d493b9 libdispatch.dylib`_dispatch_root_queue_drain + 1359
frame #10: 0x0000000111d4ab17 libdispatch.dylib`_dispatch_worker_thread3 + 111
frame #11: 0x00000001120cc637 libsystem_pthread.dylib`_pthread_wqthread + 729
frame #12: 0x00000001120ca40d libsystem_pthread.dylib`start_wqthread + 13
MediaToolbox`WebVTTParserParseBlockBuffer:
0x11290b4d5 <+0>: pushq %rbp
0x11290b4d6 <+1>: movq %rsp, %rbp
0x11290b4d9 <+4>: pushq %r15
0x11290b4db <+6>: pushq %r14
0x11290b4dd <+8>: pushq %r13
0x11290b4df <+10>: pushq %r12
0x11290b4e1 <+12>: pushq %rbx
0x11290b4e2 <+13>: subq $0x38, %rsp
0x11290b4e6 <+17>: movq %rsi, %rbx
0x11290b4e9 <+20>: movq %rdi, %r14
0x11290b4ec <+23>: movq %rbx, %rdi
0x11290b4ef <+26>: callq 0x11293230c ; symbol stub for: CMBlockBufferGetDataLength
0x11290b4f4 <+31>: movq %rax, %r15
0x11290b4f7 <+34>: leaq -0x30(%rbp), %r8
0x11290b4fb <+38>: xorl %esi, %esi
0x11290b4fd <+40>: xorl %edx, %edx
0x11290b4ff <+42>: xorl %ecx, %ecx
0x11290b501 <+44>: movq %rbx, %rdi
0x11290b504 <+47>: callq 0x112932312 ; symbol stub for: CMBlockBufferGetDataPointer
0x11290b509 <+52>: testl %eax, %eax
0x11290b50b <+54>: jne 0x11290b743 ; <+622>
0x11290b511 <+60>: leaq 0x20(%r14), %rdx
0x11290b515 <+64>: movq 0x20(%r14), %r13
0x11290b519 <+68>: testq %r13, %r13
0x11290b51c <+71>: je 0x11290b5e4 ; <+271>
0x11290b522 <+77>: xorl %r12d, %r12d
0x11290b525 <+80>: testq %r15, %r15
0x11290b528 <+83>: je 0x11290b5ea ; <+277>
0x11290b52e <+89>: movq -0x30(%rbp), %rax
0x11290b532 <+93>: xorl %r12d, %r12d
0x11290b535 <+96>: movzbl (%rax,%r12), %ecx
0x11290b53a <+101>: cmpl $0xa, %ecx
0x11290b53d <+104>: je 0x11290b554 ; <+127>
0x11290b53f <+106>: movzbl %cl, %ecx
0x11290b542 <+109>: cmpl $0xd, %ecx
0x11290b545 <+112>: je 0x11290b554 ; <+127>
0x11290b547 <+114>: incq %r12
0x11290b54a <+117>: cmpq %r15, %r12
0x11290b54d <+120>: jb 0x11290b535 ; <+96>
0x11290b54f <+122>: jmp 0x11290b5ea ; <+277>
0x11290b554 <+127>: movq %rbx, -0x48(%rbp)
0x11290b558 <+131>: movzbl (%rax,%r12), %ecx
0x11290b55d <+136>: movl $0x1, %ebx
0x11290b562 <+141>: cmpl $0xa, %ecx
0x11290b565 <+144>: je 0x11290b591 ; <+188>
0x11290b567 <+146>: movzbl %cl, %ecx
0x11290b56a <+149>: cmpl $0xd, %ecx
0x11290b56d <+152>: movq -0x48(%rbp), %rbx
0x11290b571 <+156>: jne 0x11290b5ea ; <+277>
0x11290b573 <+158>: movq %r15, %rcx
0x11290b576 <+161>: subq %r12, %rcx
0x11290b579 <+164>: cmpq $0x2, %rcx
0x11290b57d <+168>: jb 0x11290b5ea ; <+277>
0x11290b57f <+170>: movzbl 0x1(%rax,%r12), %eax
0x11290b585 <+176>: cmpl $0xa, %eax
0x11290b588 <+179>: sete %al
0x11290b58b <+182>: movzbl %al, %ebx
0x11290b58e <+185>: incq %rbx
0x11290b591 <+188>: movq %rdx, -0x40(%rbp)
0x11290b595 <+192>: testq %r12, %r12
0x11290b598 <+195>: jne 0x11290b602 ; <+301>
0x11290b59a <+197>: cmpq $0x1, %rbx
0x11290b59e <+201>: jne 0x11290b602 ; <+301>
0x11290b5a0 <+203>: movq %r13, %rdi
0x11290b5a3 <+206>: callq 0x11293230c ; symbol stub for: CMBlockBufferGetDataLength
0x11290b5a8 <+211>: leaq -0x1(%rax), %rsi
0x11290b5ac <+215>: leaq -0x31(%rbp), %rcx
0x11290b5b0 <+219>: movl $0x1, %edx
0x11290b5b5 <+224>: movq %r13, %rdi
0x11290b5b8 <+227>: callq 0x1129322e8 ; symbol stub for: CMBlockBufferCopyDataBytes
0x11290b5bd <+232>: testl %eax, %eax
0x11290b5bf <+234>: jne 0x11290b743 ; <+622>
0x11290b5c5 <+240>: movzbl -0x31(%rbp), %eax
0x11290b5c9 <+244>: cmpl $0xd, %eax
0x11290b5cc <+247>: sete %al
0x11290b5cf <+250>: movzbl %al, %ebx
0x11290b5d2 <+253>: incq %rbx
0x11290b5d5 <+256>: movq -0x40(%rbp), %rax
0x11290b5d9 <+260>: movq (%rax), %r13
0x11290b5dc <+263>: movl $0x1, %r12d
0x11290b5e2 <+269>: jmp 0x11290b605 ; <+304>
0x11290b5e4 <+271>: movq %rdx, -0x40(%rbp)
0x11290b5e8 <+275>: jmp 0x11290b63b ; <+358>
0x11290b5ea <+277>: xorl %edx, %edx
0x11290b5ec <+279>: xorl %r8d, %r8d
0x11290b5ef <+282>: movq %r13, %rdi
0x11290b5f2 <+285>: movq %rbx, %rsi
0x11290b5f5 <+288>: movq %r12, %rcx
0x11290b5f8 <+291>: callq 0x1129322d6 ; symbol stub for: CMBlockBufferAppendBufferReference
0x11290b5fd <+296>: jmp 0x11290b743 ; <+622>
0x11290b602 <+301>: addq %rbx, %r12
0x11290b605 <+304>: xorl %edx, %edx
0x11290b607 <+306>: xorl %r8d, %r8d
0x11290b60a <+309>: movq %r13, %rdi
0x11290b60d <+312>: movq -0x48(%rbp), %rsi
0x11290b611 <+316>: movq %r12, %rcx
0x11290b614 <+319>: callq 0x1129322d6 ; symbol stub for: CMBlockBufferAppendBufferReference
0x11290b619 <+324>: testl %eax, %eax
0x11290b61b <+326>: jne 0x11290b743 ; <+622>
0x11290b621 <+332>: movq %r14, %rdi
0x11290b624 <+335>: movq %rbx, %rsi
0x11290b627 <+338>: callq 0x11290b752 ; webVTTProcessLineBB
0x11290b62c <+343>: testl %eax, %eax
0x11290b62e <+345>: jne 0x11290b743 ; <+622>
0x11290b634 <+351>: addq %r12, -0x30(%rbp)
0x11290b638 <+355>: subq %r12, %r15
0x11290b63b <+358>: xorl %eax, %eax
0x11290b63d <+360>: testq %r15, %r15
0x11290b640 <+363>: je 0x11290b743 ; <+622>
0x11290b646 <+369>: movq -0x30(%rbp), %rsi
0x11290b64a <+373>: xorl %r12d, %r12d
-> 0x11290b64d <+376>: movzbl (%rsi,%r12), %eax
0x11290b652 <+381>: cmpl $0xa, %eax
0x11290b655 <+384>: je 0x11290b669 ; <+404>
0x11290b657 <+386>: movzbl %al, %eax
0x11290b65a <+389>: cmpl $0xd, %eax
0x11290b65d <+392>: je 0x11290b669 ; <+404>
0x11290b65f <+394>: incq %r12
0x11290b662 <+397>: cmpq %r15, %r12
0x11290b665 <+400>: jb 0x11290b64d ; <+376>
0x11290b667 <+402>: jmp 0x11290b6d3 ; <+510>
0x11290b669 <+404>: movzbl (%rsi,%r12), %eax
0x11290b66e <+409>: cmpl $0xa, %eax
0x11290b671 <+412>: movl $0x1, %ebx
0x11290b676 <+417>: je 0x11290b69e ; <+457>
0x11290b678 <+419>: movzbl %al, %eax
0x11290b67b <+422>: cmpl $0xd, %eax
0x11290b67e <+425>: jne 0x11290b6d3 ; <+510>
0x11290b680 <+427>: movq %r15, %rax
0x11290b683 <+430>: subq %r12, %rax
0x11290b686 <+433>: cmpq $0x2, %rax
0x11290b68a <+437>: jb 0x11290b6d3 ; <+510>
0x11290b68c <+439>: movzbl 0x1(%rsi,%r12), %eax
0x11290b692 <+445>: cmpl $0xa, %eax
0x11290b695 <+448>: sete %al
0x11290b698 <+451>: movzbl %al, %ebx
0x11290b69b <+454>: incq %rbx
0x11290b69e <+457>: leaq (%rbx,%r12), %rdx
0x11290b6a2 <+461>: movq %r14, %rdi
0x11290b6a5 <+464>: movq %rbx, %rcx
0x11290b6a8 <+467>: callq 0x11290b829 ; webVTTProcessLine
0x11290b6ad <+472>: testl %eax, %eax
0x11290b6af <+474>: jne 0x11290b743 ; <+622>
0x11290b6b5 <+480>: subq %rbx, %r15
0x11290b6b8 <+483>: addq -0x30(%rbp), %rbx
0x11290b6bc <+487>: addq %r12, %rbx
0x11290b6bf <+490>: movq %rbx, -0x30(%rbp)
0x11290b6c3 <+494>: xorl %eax, %eax
0x11290b6c5 <+496>: subq %r12, %r15
0x11290b6c8 <+499>: movq %rbx, %rsi
0x11290b6cb <+502>: jne 0x11290b64a ; <+373>
0x11290b6d1 <+508>: jmp 0x11290b743 ; <+622>
0x11290b6d3 <+510>: movq 0x8ba7e(%rip), %rax ; (void *)0x000000010f77f208: kCFAllocatorDefault
0x11290b6da <+517>: movq (%rax), %rdi
0x11290b6dd <+520>: movq -0x40(%rbp), %rax
0x11290b6e1 <+524>: movq %rax, 0x10(%rsp)
0x11290b6e6 <+529>: movq %r15, (%rsp)
0x11290b6ea <+533>: movl $0x1, 0x8(%rsp)
0x11290b6f2 <+541>: xorl %esi, %esi
0x11290b6f4 <+543>: xorl %r8d, %r8d
0x11290b6f7 <+546>: xorl %r9d, %r9d
0x11290b6fa <+549>: movq %r15, %rdx
0x11290b6fd <+552>: movq %rdi, %rcx
0x11290b700 <+555>: callq 0x112932300 ; symbol stub for: CMBlockBufferCreateWithMemoryBlock
0x11290b705 <+560>: testl %eax, %eax
0x11290b707 <+562>: jne 0x11290b743 ; <+622>
0x11290b709 <+564>: movq -0x30(%rbp), %rdi
0x11290b70d <+568>: movq -0x40(%rbp), %rax
0x11290b711 <+572>: movq (%rax), %rsi
0x11290b714 <+575>: xorl %edx, %edx
0x11290b716 <+577>: movq %r15, %rcx
0x11290b719 <+580>: callq 0x11293232a ; symbol stub for: CMBlockBufferReplaceDataBytes
0x11290b71e <+585>: movl %eax, %ebx
0x11290b720 <+587>: testl %ebx, %ebx
0x11290b722 <+589>: movl $0x0, %eax
0x11290b727 <+594>: je 0x11290b743 ; <+622>
0x11290b729 <+596>: movq -0x40(%rbp), %rax
0x11290b72d <+600>: movq (%rax), %rdi
0x11290b730 <+603>: testq %rdi, %rdi
0x11290b733 <+606>: je 0x11290b741 ; <+620>
0x11290b735 <+608>: movq $0x0, (%rax)
0x11290b73c <+615>: callq 0x112931bc8 ; symbol stub for: CFRelease
0x11290b741 <+620>: movl %ebx, %eax
0x11290b743 <+622>: addq $0x38, %rsp
0x11290b747 <+626>: popq %rbx
0x11290b748 <+627>: popq %r12
0x11290b74a <+629>: popq %r13
0x11290b74c <+631>: popq %r14
0x11290b74e <+633>: popq %r15
0x11290b750 <+635>: popq %rbp
0x11290b751 <+636>: retq