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