OSDN Git Service

LinGui: reposition the presets frame below toolbar
[handbrake-jp/handbrake-jp-git.git] / contrib / patch-mpeg4ip-ac3.patch
1 diff -Naur mpeg4ip/lib/mp4v2/Makefile.am mpeg4ip-patched/lib/mp4v2/Makefile.am
2 --- mpeg4ip/lib/mp4v2/Makefile.am       2008-02-14 14:44:36.000000000 +1300
3 +++ mpeg4ip-patched/lib/mp4v2/Makefile.am       2008-02-13 15:50:50.000000000 +1300
4 @@ -10,6 +10,7 @@
5  
6  libmp4v2_la_SOURCES = \
7         3gp.cpp \
8 +       atom_ac3.cpp \
9         atom_amr.cpp \
10         atom_avc1.cpp \
11         atom_avcC.cpp \
12 @@ -33,6 +34,7 @@
13         atom_mp4s.cpp \
14         atom_mp4v.cpp \
15         atom_mvhd.cpp \
16 +       atom_name.cpp \
17         atom_pasp.cpp \
18         atom_root.cpp \
19         atom_rtp.cpp \
20 diff -Naur mpeg4ip/lib/mp4v2/Makefile.in mpeg4ip-patched/lib/mp4v2/Makefile.in
21 --- mpeg4ip/lib/mp4v2/Makefile.in       2008-02-14 14:44:36.000000000 +1300
22 +++ mpeg4ip-patched/lib/mp4v2/Makefile.in       2008-02-14 14:38:05.000000000 +1300
23 @@ -55,7 +55,7 @@
24  am_libmp4v2_la_OBJECTS = 3gp.lo atom_amr.lo atom_avc1.lo atom_avcC.lo \
25         atom_d263.lo atom_damr.lo atom_dref.lo atom_elst.lo \
26         atom_enca.lo atom_encv.lo atom_free.lo atom_ftyp.lo \
27 -       atom_gmin.lo atom_text.lo \
28 +       atom_gmin.lo atom_text.lo atom_ac3.lo \
29         atom_hdlr.lo atom_hinf.lo atom_hnti.lo atom_href.lo \
30         atom_mdat.lo atom_mdhd.lo atom_meta.lo atom_mp4a.lo \
31         atom_mp4s.lo atom_mp4v.lo atom_mvhd.lo atom_pasp.lo atom_root.lo \
32 @@ -73,6 +73,7 @@
33  depcomp = $(SHELL) $(top_srcdir)/depcomp
34  am__depfiles_maybe = depfiles
35  @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/3gp.Plo ./$(DEPDIR)/atom_amr.Plo \
36 +@AMDEP_TRUE@   ./$(DEPDIR)/atom_ac3.Plo \
37  @AMDEP_TRUE@   ./$(DEPDIR)/atom_avc1.Plo \
38  @AMDEP_TRUE@   ./$(DEPDIR)/atom_avcC.Plo \
39  @AMDEP_TRUE@   ./$(DEPDIR)/atom_d263.Plo \
40 @@ -342,6 +343,7 @@
41  include_HEADERS = mp4.h
42  libmp4v2_la_SOURCES = \
43         3gp.cpp \
44 +       atom_ac3.cpp \
45         atom_amr.cpp \
46         atom_avc1.cpp \
47         atom_avcC.cpp \
48 @@ -497,6 +499,7 @@
49         -rm -f *.tab.c
50  
51  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/3gp.Plo@am__quote@
52 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atom_ac3.Plo@am__quote@
53  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atom_amr.Plo@am__quote@
54  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atom_avc1.Plo@am__quote@
55  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atom_avcC.Plo@am__quote@
56 diff -Naur mpeg4ip/lib/mp4v2/atom_ac3.cpp mpeg4ip-patched/lib/mp4v2/atom_ac3.cpp
57 --- mpeg4ip/lib/mp4v2/atom_ac3.cpp      1970-01-01 12:00:00.000000000 +1200
58 +++ mpeg4ip-patched/lib/mp4v2/atom_ac3.cpp      2008-02-14 14:29:52.000000000 +1300
59 @@ -0,0 +1,51 @@
60 +/*
61 + * The contents of this file are subject to the Mozilla Public
62 + * License Version 1.1 (the "License"); you may not use this file
63 + * except in compliance with the License. You may obtain a copy of
64 + * the License at http://www.mozilla.org/MPL/
65 + * 
66 + * Software distributed under the License is distributed on an "AS
67 + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
68 + * implied. See the License for the specific language governing
69 + * rights and limitations under the License.
70 + * 
71 + * The Original Code is MPEG4IP.
72 + * 
73 + * The Initial Developer of the Original Code is Cisco Systems Inc.
74 + * Portions created by Cisco Systems Inc. are
75 + * Copyright (C) Cisco Systems Inc. 2001.  All Rights Reserved.
76 + * 
77 + * Contributor(s): 
78 + *             Dave Mackie             dmackie@cisco.com
79 + */
80 +
81 +#include "mp4common.h"
82 +
83 +MP4Ac3Atom::MP4Ac3Atom() 
84 +       : MP4Atom("ac-3") 
85 +{
86 +
87 +    AddProperty( new MP4BytesProperty("data", 47));
88 +}
89 +
90 +void MP4Ac3Atom::Generate()
91 +{
92 +       MP4Atom::Generate();
93 +
94 +        // This is a nasty nasty hack because Apple haven't told us what is
95 +        // in the AC3 atom. So I've just copied this raw data from a sample
96 +        // file.
97 +        // I believe most of this is actually the same as the mp4a atom.
98 +        // I can play with this later to get it 100% right, for now this works.
99 +        static u_int8_t ac3[39] = {
100 +            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
101 +            0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
102 +            0x00, 0x02, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xbb,
103 +            0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 
104 +            0x64, 0x61, 0x63, 0x33, 0x10, 0x3d, 0x40,
105 +        };
106 +
107 +        m_pProperties[0]->SetReadOnly(false);
108 +        ((MP4BytesProperty*)m_pProperties[0])->
109 +            SetValue(ac3, sizeof(ac3));
110 +}
111 diff -Naur mpeg4ip/lib/mp4v2/atom_meta.cpp mpeg4ip-patched/lib/mp4v2/atom_meta.cpp
112 --- mpeg4ip/lib/mp4v2/atom_meta.cpp     2004-12-15 10:35:35.000000000 +1300
113 +++ mpeg4ip-patched/lib/mp4v2/atom_meta.cpp     2008-02-13 16:49:16.000000000 +1300
114 @@ -43,20 +43,33 @@
115  MP4NameAtom::MP4NameAtom()
116      : MP4Atom("name")
117  {
118 -       AddVersionAndFlags(); /* 0, 1 */
119 -
120 -    AddProperty(
121 -        new MP4BytesProperty("metadata")); /* 2 */
122
123  }
124  
125  void MP4NameAtom::Read() 
126  {
127 +    if (ATOMID(m_pParentAtom->GetType()) != ATOMID("udta")) {
128         // calculate size of the metadata from the atom size
129         ((MP4BytesProperty*)m_pProperties[2])->SetValueSize(m_size - 4);
130 +    }
131  
132 -       MP4Atom::Read();
133 +    MP4Atom::Read();
134  }
135  
136 +void MP4NameAtom::Generate()
137 +{
138 +    if (ATOMID(m_pParentAtom->GetType()) == ATOMID("udta")) {
139 +        AddProperty(new MP4BytesProperty("value"));
140 +    } else {
141 +       AddVersionAndFlags(); /* 0, 1 */
142 +        
143 +        AddProperty(
144 +            new MP4BytesProperty("metadata")); /* 2 */
145 +    }
146 +    MP4Atom::Generate();
147 +}
148 +
149 +
150  MP4DataAtom::MP4DataAtom()
151      : MP4Atom("data")
152  {
153 diff -Naur mpeg4ip/lib/mp4v2/atom_stsd.cpp mpeg4ip-patched/lib/mp4v2/atom_stsd.cpp
154 --- mpeg4ip/lib/mp4v2/atom_stsd.cpp     2008-02-14 14:44:36.000000000 +1300
155 +++ mpeg4ip-patched/lib/mp4v2/atom_stsd.cpp     2008-02-13 14:52:10.000000000 +1300
156 @@ -51,6 +51,7 @@
157         ExpectChildAtom("avc1", Optional, Many);
158         ExpectChildAtom("text", Optional, Many);
159         ExpectChildAtom("pasp", Optional, Many);
160 +       ExpectChildAtom("ac-3", Optional, Many);
161  }
162  
163  void MP4StsdAtom::Read() 
164 diff -Naur mpeg4ip/lib/mp4v2/atom_udta.cpp mpeg4ip-patched/lib/mp4v2/atom_udta.cpp
165 --- mpeg4ip/lib/mp4v2/atom_udta.cpp     2003-08-05 09:59:56.000000000 +1200
166 +++ mpeg4ip-patched/lib/mp4v2/atom_udta.cpp     2008-02-13 16:25:08.000000000 +1300
167 @@ -33,6 +33,7 @@
168  {
169         if (ATOMID(m_pParentAtom->GetType()) == ATOMID("trak")) {
170                 ExpectChildAtom("hinf", Optional, OnlyOne);
171 +                ExpectChildAtom("name", Optional, OnlyOne);
172         }
173  
174         MP4Atom::Read();
175 diff -Naur mpeg4ip/lib/mp4v2/atoms.h mpeg4ip-patched/lib/mp4v2/atoms.h
176 --- mpeg4ip/lib/mp4v2/atoms.h   2008-02-14 14:44:36.000000000 +1300
177 +++ mpeg4ip-patched/lib/mp4v2/atoms.h   2008-02-14 14:54:20.000000000 +1300
178 @@ -146,6 +146,12 @@
179         void Generate();
180  };
181  
182 +class MP4Ac3Atom : public MP4Atom {
183 +public:
184 +       MP4Ac3Atom();
185 +       void Generate();
186 +};
187 +
188  class MP4Mp4sAtom : public MP4Atom {
189  public:
190         MP4Mp4sAtom();
191 @@ -267,6 +273,7 @@
192  public:
193      MP4NameAtom();
194      void Read();
195 +    void Generate();
196  };
197  
198  class MP4RtpAtom : public MP4Atom {
199 diff -Naur mpeg4ip/lib/mp4v2/mp4.cpp mpeg4ip-patched/lib/mp4v2/mp4.cpp
200 --- mpeg4ip/lib/mp4v2/mp4.cpp   2008-02-14 14:44:36.000000000 +1300
201 +++ mpeg4ip-patched/lib/mp4v2/mp4.cpp   2008-02-13 17:16:33.000000000 +1300
202 @@ -592,6 +592,25 @@
203         return MP4_INVALID_TRACK_ID;
204  }
205  
206 +extern "C" MP4TrackId MP4AddAC3AudioTrack(
207 +       MP4FileHandle hFile, 
208 +       u_int32_t timeScale, 
209 +       MP4Duration sampleDuration, 
210 +       u_int8_t audioType)
211 +{
212 +       if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
213 +               try {
214 +                       return ((MP4File*)hFile)->
215 +                               AddAC3AudioTrack(timeScale, sampleDuration, audioType);
216 +               }
217 +               catch (MP4Error* e) {
218 +                       PRINT_ERROR(e);
219 +                       delete e;
220 +               }
221 +       }
222 +       return MP4_INVALID_TRACK_ID;
223 +}
224 +
225  extern "C" MP4TrackId MP4AddEncAudioTrack(MP4FileHandle hFile, 
226                                           u_int32_t timeScale, 
227                                           MP4Duration sampleDuration,
228 diff -Naur mpeg4ip/lib/mp4v2/mp4.h mpeg4ip-patched/lib/mp4v2/mp4.h
229 --- mpeg4ip/lib/mp4v2/mp4.h     2008-02-14 14:44:36.000000000 +1300
230 +++ mpeg4ip-patched/lib/mp4v2/mp4.h     2008-02-13 17:15:24.000000000 +1300
231 @@ -432,6 +432,12 @@
232         MP4Duration sampleDuration,
233         u_int8_t audioType DEFAULT(MP4_MPEG4_AUDIO_TYPE));
234  
235 +MP4TrackId MP4AddAC3AudioTrack(
236 +       MP4FileHandle hFile, 
237 +       u_int32_t timeScale, 
238 +       MP4Duration sampleDuration,
239 +       u_int8_t audioType DEFAULT(MP4_MPEG4_AUDIO_TYPE));
240 +
241  typedef struct mp4v2_ismacryp_session_params {
242    u_int32_t  scheme_type;
243    u_int16_t  scheme_version;
244 diff -Naur mpeg4ip/lib/mp4v2/mp4atom.cpp mpeg4ip-patched/lib/mp4v2/mp4atom.cpp
245 --- mpeg4ip/lib/mp4v2/mp4atom.cpp       2008-02-14 14:44:36.000000000 +1300
246 +++ mpeg4ip-patched/lib/mp4v2/mp4atom.cpp       2008-02-13 16:03:41.000000000 +1300
247 @@ -76,6 +76,8 @@
248      case 'a':
249        if (ATOMID(type) == ATOMID("avc1")) {
250         pAtom = new MP4Avc1Atom();
251 +      } else if (ATOMID(type) == ATOMID("ac-3")) {
252 +       pAtom = new MP4Ac3Atom();
253        } else if (ATOMID(type) == ATOMID("avcC")) {
254         pAtom = new MP4AvcCAtom();
255        } else if (ATOMID(type) == ATOMID("alis")) {
256 diff -Naur mpeg4ip/lib/mp4v2/mp4file.cpp mpeg4ip-patched/lib/mp4v2/mp4file.cpp
257 --- mpeg4ip/lib/mp4v2/mp4file.cpp       2008-02-14 14:44:36.000000000 +1300
258 +++ mpeg4ip-patched/lib/mp4v2/mp4file.cpp       2008-02-13 17:47:11.000000000 +1300
259 @@ -1301,6 +1301,8 @@
260  
261         AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), "mp4a");
262  
263 +        AddDescendantAtoms(MakeTrackName(trackId, NULL), "udta.name");
264 +
265         // stsd is a unique beast in that it has a count of the number 
266         // of child atoms that needs to be incremented after we add the mp4a atom
267         MP4Integer32Property* pStsdCountProperty;
268 @@ -1337,6 +1339,60 @@
269         return trackId;
270  }
271  
272 +MP4TrackId MP4File::AddAC3AudioTrack(
273 +       u_int32_t timeScale, 
274 +       MP4Duration sampleDuration, 
275 +       u_int8_t audioType)
276 +{
277 +       MP4TrackId trackId = AddTrack(MP4_AUDIO_TRACK_TYPE, timeScale);
278 +
279 +       AddTrackToOd(trackId);
280 +
281 +       SetTrackFloatProperty(trackId, "tkhd.volume", 1.0);
282 +
283 +       InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "smhd", 0);
284 +
285 +       AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), "ac-3");
286 +
287 +        AddDescendantAtoms(MakeTrackName(trackId, NULL), "udta.name");
288 +
289 +       // stsd is a unique beast in that it has a count of the number 
290 +       // of child atoms that needs to be incremented after we add the mp4a atom
291 +       MP4Integer32Property* pStsdCountProperty;
292 +       FindIntegerProperty(
293 +               MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"),
294 +               (MP4Property**)&pStsdCountProperty);
295 +       pStsdCountProperty->IncrementValue();
296 +
297 +       //SetTrackIntegerProperty(trackId, 
298 +       //      "mdia.minf.stbl.stsd.ac-3.timeScale", timeScale);
299 +
300 +        //
301 +       //SetTrackIntegerProperty(trackId, 
302 +       //                      "mdia.minf.stbl.stsd.ac-3.esds.ESID", 
303 +#if 0
304 +                               // note - for a file, these values need to 
305 +                               // be 0 - wmay - 04/16/2003
306 +       //                      trackId
307 +#else
308 +        //             0
309 +#endif
310 +        //             );
311 +
312 +       //SetTrackIntegerProperty(trackId, 
313 +       //      "mdia.minf.stbl.stsd.ac-3.esds.decConfigDescr.objectTypeId", 
314 +       //      audioType);
315 +
316 +       //SetTrackIntegerProperty(trackId, 
317 +       //      "mdia.minf.stbl.stsd.ac-3.esds.decConfigDescr.streamType", 
318 +       //      MP4AudioStreamType);
319 +
320 +       m_pTracks[FindTrackIndex(trackId)]->
321 +               SetFixedSampleDuration(sampleDuration);
322 +
323 +       return trackId;
324 +}
325 +
326  MP4TrackId MP4File::AddEncAudioTrack(u_int32_t timeScale, 
327                                      MP4Duration sampleDuration, 
328                                      u_int8_t audioType,
329 diff -Naur mpeg4ip/lib/mp4v2/mp4file.h mpeg4ip-patched/lib/mp4v2/mp4file.h
330 --- mpeg4ip/lib/mp4v2/mp4file.h 2008-02-14 14:44:36.000000000 +1300
331 +++ mpeg4ip-patched/lib/mp4v2/mp4file.h 2008-02-13 17:17:11.000000000 +1300
332 @@ -203,6 +203,11 @@
333                 MP4Duration sampleDuration,
334                 u_int8_t audioType);
335  
336 +       MP4TrackId AddAC3AudioTrack(
337 +               u_int32_t timeScale, 
338 +               MP4Duration sampleDuration,
339 +               u_int8_t audioType);
340 +
341         MP4TrackId AddEncAudioTrack( // ismacryp
342                 u_int32_t timeScale, 
343                 MP4Duration sampleDuration,