// File: cpearce[P]OggIndex/src/SkeletonEncoder.cpp
// Function: SkeletonEncoder::AddBosPacket()
void
SkeletonEncoder::AddBosPacket()
{
  // Should not call this more than once, this should be the first packet.
  assert(mPacketCount == 0);

  // Allocate packet to return...
  ogg_packet* bos = new ogg_packet();
  memset(bos, 0, sizeof(ogg_packet));
  bos->packet = new unsigned char[SKELETON_4_0_HEADER_LENGTH];
  memset(bos->packet, 0, SKELETON_4_0_HEADER_LENGTH);
  bos->bytes = SKELETON_4_0_HEADER_LENGTH;
  bos->b_o_s = 1;
  
  if (mSkeletonDecoder) {
    // We already have a skeleton track. Use what data we can from its
    // bos packet.
    ogg_packet* original = mSkeletonDecoder->mPackets.front();
    memcpy(bos->packet, original->packet, SKELETON_3_0_HEADER_LENGTH);
  } else {
    // We need to construct the skeleton bos packet...
    memcpy(bos->packet, "fishead", 8);
    
    WriteLEUint64(bos->packet + SKELETON_PRES_TIME_DENOM_OFFSET, 1000);
    WriteLEUint64(bos->packet + SKELETON_BASE_TIME_DENOM_OFFSET, 1000);
  }
  
  // Set the version fields.
  WriteLEUint16(bos->packet + SKELETON_VERSION_MAJOR_OFFSET, SKELETON_VERSION_MAJOR);
  WriteLEUint16(bos->packet + SKELETON_VERSION_MINOR_OFFSET, SKELETON_VERSION_MINOR);
  
  WriteLEUint64(bos->packet + SKELETON_CONTENT_OFFSET, mContentOffset);

  mPacketCount++;

  mIndexPackets.push_back(bos);

}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpl $0x0, 0x34(%rax)
jne 0x116db
jmp 0x116fa
leaq 0xc8f0(%rip), %rdi      # 0x1dfd2
leaq 0xc8fb(%rip), %rsi      # 0x1dfe4
movl $0x7e, %edx
leaq 0xc907(%rip), %rcx      # 0x1dffc
callq 0x5280
movl $0x30, %edi
callq 0x53e0
movq %rax, %rdi
movq %rdi, (%rsp)
xorl %esi, %esi
movl $0x30, %edx
callq 0x5230
movq (%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x5230
movl $0x50, %edi
callq 0x5030
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
xorl %esi, %esi
movl $0x50, %edx
callq 0x5230
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rcx
movq $0x50, 0x8(%rcx)
movq 0x18(%rsp), %rcx
movq $0x1, 0x10(%rcx)
cmpq $0x0, 0x18(%rax)
je 0x117b9
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
addq $0x1d0, %rdi            # imm = 0x1D0
callq 0x14000
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
movq 0x10(%rsp), %rax
movq (%rax), %rsi
movl $0x40, %edx
callq 0x5340
jmp 0x117f7
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0xba04(%rip), %rcx      # 0x1d1cc
movq %rcx, (%rax)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
addq $0x14, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x16ad0
movq 0x18(%rsp), %rax
movq (%rax), %rdi
addq $0x24, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x16ad0
movq 0x18(%rsp), %rax
movq (%rax), %rdi
addq $0x8, %rdi
movl $0x4, %esi
callq 0x16ed0
movq 0x18(%rsp), %rax
movq (%rax), %rdi
addq $0xa, %rdi
xorl %esi, %esi
callq 0x16ed0
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rcx
movq (%rcx), %rdi
addq $0x48, %rdi
movq 0x68(%rax), %rsi
callq 0x16ad0
movq 0x8(%rsp), %rdi
movl 0x34(%rdi), %eax
addl $0x1, %eax
movl %eax, 0x34(%rdi)
addq $0x38, %rdi
leaq 0x18(%rsp), %rsi
callq 0x14030
addq $0x28, %rsp
retq
nopl (%rax,%rax)