content/media/encoder/fmp4_muxer/MP4ESDS.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/encoder/fmp4_muxer/MP4ESDS.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,138 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include <climits>
    1.10 +#include "ISOControl.h"
    1.11 +#include "ISOMediaBoxes.h"
    1.12 +#include "MP4ESDS.h"
    1.13 +
    1.14 +namespace mozilla {
    1.15 +
    1.16 +nsresult
    1.17 +MP4AudioSampleEntry::Generate(uint32_t* aBoxSize)
    1.18 +{
    1.19 +  uint32_t box_size;
    1.20 +  nsresult rv = es->Generate(&box_size);
    1.21 +  NS_ENSURE_SUCCESS(rv, rv);
    1.22 +  size += box_size;
    1.23 +
    1.24 +  *aBoxSize = size;
    1.25 +  return NS_OK;
    1.26 +}
    1.27 +
    1.28 +nsresult
    1.29 +MP4AudioSampleEntry::Write()
    1.30 +{
    1.31 +  BoxSizeChecker checker(mControl, size);
    1.32 +  nsresult rv;
    1.33 +  rv = AudioSampleEntry::Write();
    1.34 +  NS_ENSURE_SUCCESS(rv, rv);
    1.35 +  rv = es->Write();
    1.36 +  NS_ENSURE_SUCCESS(rv, rv);
    1.37 +
    1.38 +  return NS_OK;
    1.39 +}
    1.40 +
    1.41 +MP4AudioSampleEntry::MP4AudioSampleEntry(ISOControl* aControl)
    1.42 +  : AudioSampleEntry(NS_LITERAL_CSTRING("mp4a"), aControl)
    1.43 +{
    1.44 +  es = new ESDBox(aControl);
    1.45 +  MOZ_COUNT_CTOR(MP4AudioSampleEntry);
    1.46 +}
    1.47 +
    1.48 +MP4AudioSampleEntry::~MP4AudioSampleEntry()
    1.49 +{
    1.50 +  MOZ_COUNT_DTOR(MP4AudioSampleEntry);
    1.51 +}
    1.52 +
    1.53 +nsresult
    1.54 +ESDBox::Generate(uint32_t* aBoxSize)
    1.55 +{
    1.56 +  uint32_t box_size;
    1.57 +  es_descriptor->Generate(&box_size);
    1.58 +  size += box_size;
    1.59 +  *aBoxSize = size;
    1.60 +  return NS_OK;
    1.61 +}
    1.62 +
    1.63 +nsresult
    1.64 +ESDBox::Write()
    1.65 +{
    1.66 +  WRITE_FULLBOX(mControl, size)
    1.67 +  es_descriptor->Write();
    1.68 +  return NS_OK;
    1.69 +}
    1.70 +
    1.71 +ESDBox::ESDBox(ISOControl* aControl)
    1.72 +  : FullBox(NS_LITERAL_CSTRING("esds"), 0, 0, aControl)
    1.73 +{
    1.74 +  es_descriptor = new ES_Descriptor(aControl);
    1.75 +  MOZ_COUNT_CTOR(ESDBox);
    1.76 +}
    1.77 +
    1.78 +ESDBox::~ESDBox()
    1.79 +{
    1.80 +  MOZ_COUNT_DTOR(ESDBox);
    1.81 +}
    1.82 +
    1.83 +nsresult
    1.84 +ES_Descriptor::Find(const nsACString& aType,
    1.85 +                    nsTArray<nsRefPtr<MuxerOperation>>& aOperations)
    1.86 +{
    1.87 +  // ES_Descriptor is not a real ISOMediaBox, so we return nothing here.
    1.88 +  return NS_OK;
    1.89 +}
    1.90 +
    1.91 +nsresult
    1.92 +ES_Descriptor::Write()
    1.93 +{
    1.94 +  mControl->Write(tag);
    1.95 +  mControl->Write(length);
    1.96 +  mControl->Write(ES_ID);
    1.97 +  mControl->WriteBits(streamDependenceFlag.to_ulong(), streamDependenceFlag.size());
    1.98 +  mControl->WriteBits(URL_Flag.to_ulong(), URL_Flag.size());
    1.99 +  mControl->WriteBits(reserved.to_ulong(), reserved.size());
   1.100 +  mControl->WriteBits(streamPriority.to_ulong(), streamPriority.size());
   1.101 +  mControl->Write(DecodeSpecificInfo.Elements(), DecodeSpecificInfo.Length());
   1.102 +
   1.103 +  return NS_OK;
   1.104 +}
   1.105 +
   1.106 +nsresult
   1.107 +ES_Descriptor::Generate(uint32_t* aBoxSize)
   1.108 +{
   1.109 +  nsresult rv;
   1.110 +  //   14496-1 '8.3.4 DecoderConfigDescriptor'
   1.111 +  //   14496-1 '10.2.3 SL Packet Header Configuration'
   1.112 +  FragmentBuffer* frag = mControl->GetFragment(Audio_Track);
   1.113 +  rv = frag->GetCSD(DecodeSpecificInfo);
   1.114 +  NS_ENSURE_SUCCESS(rv, rv);
   1.115 +
   1.116 +  length = sizeof(ES_ID) + 1;
   1.117 +  length += DecodeSpecificInfo.Length();
   1.118 +
   1.119 +  *aBoxSize = sizeof(tag) + sizeof(length) + length;
   1.120 +  return NS_OK;
   1.121 +}
   1.122 +
   1.123 +ES_Descriptor::ES_Descriptor(ISOControl* aControl)
   1.124 +  : tag(ESDescrTag)
   1.125 +  , length(0)
   1.126 +  , ES_ID(0)
   1.127 +  , streamDependenceFlag(0)
   1.128 +  , URL_Flag(0)
   1.129 +  , reserved(0)
   1.130 +  , streamPriority(0)
   1.131 +  , mControl(aControl)
   1.132 +{
   1.133 +  MOZ_COUNT_CTOR(ES_Descriptor);
   1.134 +}
   1.135 +
   1.136 +ES_Descriptor::~ES_Descriptor()
   1.137 +{
   1.138 +  MOZ_COUNT_DTOR(ES_Descriptor);
   1.139 +}
   1.140 +
   1.141 +}

mercurial