1 /*******************************************************************************
2  wave.c
3 
4  libquicktime - A library for reading and writing quicktime/avi/mp4 files.
5  http://libquicktime.sourceforge.net
6 
7  Copyright (C) 2002 Heroine Virtual Ltd.
8  Copyright (C) 2002-2011 Members of the libquicktime project.
9 
10  This library is free software; you can redistribute it and/or modify it under
11  the terms of the GNU Lesser General Public License as published by the Free
12  Software Foundation; either version 2.1 of the License, or (at your option)
13  any later version.
14 
15  This library is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18  details.
19 
20  You should have received a copy of the GNU Lesser General Public License along
21  with this library; if not, write to the Free Software Foundation, Inc., 51
22  Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 *******************************************************************************/
24 
25 #include "lqt_private.h"
26 
quicktime_wave_get_user_atom(quicktime_trak_t * trak,char * name,uint32_t * len)27 uint8_t * quicktime_wave_get_user_atom(quicktime_trak_t * trak, char * name, uint32_t * len)
28   {
29   quicktime_wave_t * wave = &trak->mdia.minf.stbl.stsd.table[0].wave;
30   return(quicktime_user_atoms_get_atom(&wave->user_atoms, name, len));
31   }
32 
33 
quicktime_wave_set_user_atom(quicktime_trak_t * trak,char * name,uint8_t * data,uint32_t len)34 void quicktime_wave_set_user_atom(quicktime_trak_t * trak, char * name,
35                                   uint8_t * data, uint32_t len)
36   {
37   quicktime_wave_t * wave = &trak->mdia.minf.stbl.stsd.table[0].wave;
38 
39   quicktime_user_atoms_add_atom(&wave->user_atoms,
40                                 name, data, len);
41   trak->mdia.minf.stbl.stsd.table[0].has_wave = 1;
42   }
43 
quicktime_wave_delete(quicktime_wave_t * wave)44 void quicktime_wave_delete(quicktime_wave_t *wave)
45   {
46   quicktime_user_atoms_delete(&wave->user_atoms);
47   quicktime_esds_delete(&wave->esds);
48   }
49 
quicktime_read_wave(quicktime_t * file,quicktime_wave_t * wave,quicktime_atom_t * wave_atom)50 void quicktime_read_wave(quicktime_t *file, quicktime_wave_t *wave,
51                          quicktime_atom_t *wave_atom)
52   {
53   quicktime_atom_t leaf_atom;
54   do{
55     quicktime_atom_read_header(file, &leaf_atom);
56 
57     if(quicktime_atom_is(&leaf_atom, "frma"))
58       {
59       quicktime_read_frma(file, &wave->frma, &leaf_atom);
60       wave->has_frma = 1;
61       }
62     else if(quicktime_atom_is(&leaf_atom, "enda"))
63       {
64       quicktime_read_enda(file, &wave->enda, &leaf_atom);
65       wave->has_enda = 1;
66       }
67     else if(quicktime_atom_is(&leaf_atom, "esds"))
68       {
69       quicktime_read_esds(file, &wave->esds);
70       wave->has_esds = 1;
71       quicktime_atom_skip(file, &leaf_atom);
72       }
73     else if(quicktime_atom_is(&leaf_atom, (char[]){ 0x00, 0x00, 0x00, 0x00 }))
74       {
75       break;
76       }
77     else /* Add to user atoms */
78       {
79       quicktime_user_atoms_read_atom(file,
80                                      &wave->user_atoms,
81                                      &leaf_atom);
82       }
83     quicktime_atom_skip(file, &leaf_atom);
84   }while(quicktime_position(file) < wave_atom->end);
85 
86   }
87 
quicktime_write_wave(quicktime_t * file,quicktime_wave_t * wave)88 void quicktime_write_wave(quicktime_t *file, quicktime_wave_t *wave)
89   {
90   quicktime_atom_t atom;
91   quicktime_atom_write_header(file, &atom, "wave");
92 
93   if(wave->has_frma)
94     quicktime_write_frma(file, &wave->frma);
95   if(wave->has_esds)
96     quicktime_write_esds(file, &wave->esds);
97   if(wave->has_enda)
98     quicktime_write_enda(file, &wave->enda);
99 
100   quicktime_write_user_atoms(file, &wave->user_atoms);
101 
102   quicktime_atom_write_footer(file, &atom);
103   }
104 
quicktime_wave_dump(quicktime_wave_t * wave)105 void quicktime_wave_dump(quicktime_wave_t *wave)
106   {
107   lqt_dump("       wave: \n");
108   if(wave->has_frma)
109     quicktime_frma_dump(&wave->frma);
110   if(wave->has_enda)
111     quicktime_enda_dump(&wave->enda);
112   if(wave->has_esds)
113     quicktime_esds_dump(&wave->esds);
114 
115   quicktime_user_atoms_dump(&wave->user_atoms);
116 
117   }
118