// File: Themaister[P]umusd/ffmpeg.cpp
// Function: FF::FF(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
FF::FF(const std::string &path)
   : fctx(nullptr), actx(nullptr), aud_stream(-1), last_pos(0.0f), planar_audio(false)
{
   av_register_all();

   try
   {
      media_info.title = path;

      if (avformat_open_input(&fctx, path.c_str(), nullptr, nullptr) < 0)
         throw std::runtime_error("Failed to open file.\n");

      if (avformat_find_stream_info(fctx, nullptr) < 0)
         throw std::runtime_error("Failed to get stream info.\n");

      resolve_codecs();
      get_media_info();
   } 
   catch(...)
   {
      if (actx)
         avcodec_close(actx);
      if (fctx)
         avformat_close_input(&fctx);
      throw;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x28(%rbp)
movq $0x0, (%rdi)
movq $0x0, 0x8(%rdi)
movl $0xffffffff, 0x10(%rdi) # imm = 0xFFFFFFFF
movl $0x0, 0x14(%rdi)
addq $0x18, %rdi
movq %rdi, -0x38(%rbp)
callq 0x17a70
movq -0x28(%rbp), %rdi
addq $0x88, %rdi
movq %rdi, -0x30(%rbp)
callq 0x17ab0
movq -0x28(%rbp), %rax
movb $0x0, 0xa0(%rax)
callq 0x52b0
jmp 0x16dd8
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x28, %rdi
callq 0x57a0
jmp 0x16deb
movq -0x10(%rbp), %rdi
callq 0x5460
movq -0x28(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x5580
movl %eax, -0x3c(%rbp)
jmp 0x16e0c
movl -0x3c(%rbp), %eax
cmpl $0x0, %eax
jge 0x16e8b
movl $0x10, %edi
callq 0x5540
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x48(%rbp)
leaq 0xf851(%rip), %rsi      # 0x26680
callq 0x5140
jmp 0x16e36
movq -0x48(%rbp), %rdi
movq 0x2414f(%rip), %rsi     # 0x3af90
movq 0x24198(%rip), %rdx     # 0x3afe0
callq 0x5260
jmp 0x16f94
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x16f71
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x16efb
movq -0x48(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x56d0
jmp 0x16efb
movq -0x28(%rbp), %rax
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x5600
movl %eax, -0x4c(%rbp)
jmp 0x16ea0
movl -0x4c(%rbp), %eax
cmpl $0x0, %eax
jge 0x16f20
movl $0x10, %edi
callq 0x5540
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x58(%rbp)
leaq 0xf7d3(%rip), %rsi      # 0x26696
callq 0x5140
jmp 0x16eca
movq -0x58(%rbp), %rdi
movq 0x240bb(%rip), %rsi     # 0x3af90
movq 0x24104(%rip), %rdx     # 0x3afe0
callq 0x5260
jmp 0x16f94
movq -0x58(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x56d0
movq -0x18(%rbp), %rdi
callq 0x5080
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x16f4b
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5700
jmp 0x16f1e
jmp 0x16f4b
movq -0x28(%rbp), %rdi
callq 0x16fa0
jmp 0x16f2b
movq -0x28(%rbp), %rdi
callq 0x17180
jmp 0x16f36
jmp 0x16f6b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x5660
jmp 0x16f69
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
je 0x16f62
movq -0x28(%rbp), %rdi
callq 0x5630
jmp 0x16f60
jmp 0x16f62
callq 0x5690
jmp 0x16f94
jmp 0x16f71
addq $0x60, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x86e0
movq -0x38(%rbp), %rdi
callq 0x14460
movq -0x18(%rbp), %rdi
callq 0x52a0
movq %rax, %rdi
callq 0x6700
nopw %cs:(%rax,%rax)