Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include <climits> |
michael@0 | 7 | #include "ISOControl.h" |
michael@0 | 8 | #include "ISOMediaBoxes.h" |
michael@0 | 9 | #include "MP4ESDS.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace mozilla { |
michael@0 | 12 | |
michael@0 | 13 | nsresult |
michael@0 | 14 | MP4AudioSampleEntry::Generate(uint32_t* aBoxSize) |
michael@0 | 15 | { |
michael@0 | 16 | uint32_t box_size; |
michael@0 | 17 | nsresult rv = es->Generate(&box_size); |
michael@0 | 18 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 19 | size += box_size; |
michael@0 | 20 | |
michael@0 | 21 | *aBoxSize = size; |
michael@0 | 22 | return NS_OK; |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | nsresult |
michael@0 | 26 | MP4AudioSampleEntry::Write() |
michael@0 | 27 | { |
michael@0 | 28 | BoxSizeChecker checker(mControl, size); |
michael@0 | 29 | nsresult rv; |
michael@0 | 30 | rv = AudioSampleEntry::Write(); |
michael@0 | 31 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 32 | rv = es->Write(); |
michael@0 | 33 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 34 | |
michael@0 | 35 | return NS_OK; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | MP4AudioSampleEntry::MP4AudioSampleEntry(ISOControl* aControl) |
michael@0 | 39 | : AudioSampleEntry(NS_LITERAL_CSTRING("mp4a"), aControl) |
michael@0 | 40 | { |
michael@0 | 41 | es = new ESDBox(aControl); |
michael@0 | 42 | MOZ_COUNT_CTOR(MP4AudioSampleEntry); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | MP4AudioSampleEntry::~MP4AudioSampleEntry() |
michael@0 | 46 | { |
michael@0 | 47 | MOZ_COUNT_DTOR(MP4AudioSampleEntry); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | nsresult |
michael@0 | 51 | ESDBox::Generate(uint32_t* aBoxSize) |
michael@0 | 52 | { |
michael@0 | 53 | uint32_t box_size; |
michael@0 | 54 | es_descriptor->Generate(&box_size); |
michael@0 | 55 | size += box_size; |
michael@0 | 56 | *aBoxSize = size; |
michael@0 | 57 | return NS_OK; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | nsresult |
michael@0 | 61 | ESDBox::Write() |
michael@0 | 62 | { |
michael@0 | 63 | WRITE_FULLBOX(mControl, size) |
michael@0 | 64 | es_descriptor->Write(); |
michael@0 | 65 | return NS_OK; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | ESDBox::ESDBox(ISOControl* aControl) |
michael@0 | 69 | : FullBox(NS_LITERAL_CSTRING("esds"), 0, 0, aControl) |
michael@0 | 70 | { |
michael@0 | 71 | es_descriptor = new ES_Descriptor(aControl); |
michael@0 | 72 | MOZ_COUNT_CTOR(ESDBox); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | ESDBox::~ESDBox() |
michael@0 | 76 | { |
michael@0 | 77 | MOZ_COUNT_DTOR(ESDBox); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | nsresult |
michael@0 | 81 | ES_Descriptor::Find(const nsACString& aType, |
michael@0 | 82 | nsTArray<nsRefPtr<MuxerOperation>>& aOperations) |
michael@0 | 83 | { |
michael@0 | 84 | // ES_Descriptor is not a real ISOMediaBox, so we return nothing here. |
michael@0 | 85 | return NS_OK; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | nsresult |
michael@0 | 89 | ES_Descriptor::Write() |
michael@0 | 90 | { |
michael@0 | 91 | mControl->Write(tag); |
michael@0 | 92 | mControl->Write(length); |
michael@0 | 93 | mControl->Write(ES_ID); |
michael@0 | 94 | mControl->WriteBits(streamDependenceFlag.to_ulong(), streamDependenceFlag.size()); |
michael@0 | 95 | mControl->WriteBits(URL_Flag.to_ulong(), URL_Flag.size()); |
michael@0 | 96 | mControl->WriteBits(reserved.to_ulong(), reserved.size()); |
michael@0 | 97 | mControl->WriteBits(streamPriority.to_ulong(), streamPriority.size()); |
michael@0 | 98 | mControl->Write(DecodeSpecificInfo.Elements(), DecodeSpecificInfo.Length()); |
michael@0 | 99 | |
michael@0 | 100 | return NS_OK; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | nsresult |
michael@0 | 104 | ES_Descriptor::Generate(uint32_t* aBoxSize) |
michael@0 | 105 | { |
michael@0 | 106 | nsresult rv; |
michael@0 | 107 | // 14496-1 '8.3.4 DecoderConfigDescriptor' |
michael@0 | 108 | // 14496-1 '10.2.3 SL Packet Header Configuration' |
michael@0 | 109 | FragmentBuffer* frag = mControl->GetFragment(Audio_Track); |
michael@0 | 110 | rv = frag->GetCSD(DecodeSpecificInfo); |
michael@0 | 111 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 112 | |
michael@0 | 113 | length = sizeof(ES_ID) + 1; |
michael@0 | 114 | length += DecodeSpecificInfo.Length(); |
michael@0 | 115 | |
michael@0 | 116 | *aBoxSize = sizeof(tag) + sizeof(length) + length; |
michael@0 | 117 | return NS_OK; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | ES_Descriptor::ES_Descriptor(ISOControl* aControl) |
michael@0 | 121 | : tag(ESDescrTag) |
michael@0 | 122 | , length(0) |
michael@0 | 123 | , ES_ID(0) |
michael@0 | 124 | , streamDependenceFlag(0) |
michael@0 | 125 | , URL_Flag(0) |
michael@0 | 126 | , reserved(0) |
michael@0 | 127 | , streamPriority(0) |
michael@0 | 128 | , mControl(aControl) |
michael@0 | 129 | { |
michael@0 | 130 | MOZ_COUNT_CTOR(ES_Descriptor); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | ES_Descriptor::~ES_Descriptor() |
michael@0 | 134 | { |
michael@0 | 135 | MOZ_COUNT_DTOR(ES_Descriptor); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | } |