1 // =================================================================================================
2 // ADOBE SYSTEMS INCORPORATED
3 // Copyright 2010 Adobe Systems Incorporated
4 // All Rights Reserved
5 //
6 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
7 // of the Adobe license agreement accompanying it.
8 // =================================================================================================
9 
10 #ifndef __WAVE_Handler_hpp__
11 #define __WAVE_Handler_hpp__	1
12 
13 #include "public/include/XMP_Environment.h"	// ! XMP_Environment.h must be the first included header.
14 #include "public/include/XMP_Const.h"
15 
16 #include "XMPFiles/source/FormatSupport/IFF/ChunkController.h"
17 #include "XMPFiles/source/FormatSupport/IFF/IChunkBehavior.h"
18 #include "XMPFiles/source/FormatSupport/IFF/IChunkData.h"
19 #include "source/Endian.h"
20 #include "XMPFiles/source/FormatSupport/IFF/ChunkPath.h"
21 #include "XMPFiles/source/FormatSupport/WAVE/iXMLMetadata.h"
22 #include "XMPFiles/source/FormatSupport/WAVE/BEXTMetadata.h"
23 #include "XMPFiles/source/FormatSupport/WAVE/CartMetadata.h"
24 #include "XMPFiles/source/FormatSupport/WAVE/DISPMetadata.h"
25 #include "XMPFiles/source/FormatSupport/WAVE/INFOMetadata.h"
26 #include "source/XIO.hpp"
27 #include "XMPFiles/source/XMPFiles_Impl.hpp"
28 
29 using namespace IFF_RIFF;
30 
31 // =================================================================================================
32 /// \file WAV_Handler.hpp
33 /// \brief File format handler for AIFF.
34 // =================================================================================================
35 
36 /**
37  * Contructor for the handler.
38  */
39 extern XMPFileHandler * WAVE_MetaHandlerCTor ( XMPFiles * parent );
40 
41 /**
42  * Checks the format of the file, see common code.
43  */
44 extern bool WAVE_CheckFormat ( XMP_FileFormat format,
45 							  XMP_StringPtr  filePath,
46 			                  XMP_IO*    fileRef,
47 			                  XMPFiles *     parent );
48 
49 /** WAVE does not need kXMPFiles_CanRewrite as we can always use UpdateFile to either do
50  *  in-place update or append to the file. */
51 static const XMP_OptionBits kWAVE_HandlerFlags = (kXMPFiles_CanInjectXMP |
52 												  kXMPFiles_CanExpand |
53 												  kXMPFiles_PrefersInPlace |
54 												  kXMPFiles_CanReconcile |
55 												  kXMPFiles_ReturnsRawPacket |
56 												  kXMPFiles_AllowsSafeUpdate |
57 												  kXMPFiles_CanNotifyProgress
58 												 );
59 
60 /**
61  * Main class for the the WAVE file handler.
62  */
63 class WAVE_MetaHandler : public XMPFileHandler
64 {
65 public:
66 	WAVE_MetaHandler ( XMPFiles* parent );
67 	~WAVE_MetaHandler();
68 
69 	void CacheFileData();
70 	void ProcessXMP();
71 
72 	void UpdateFile ( bool doSafeUpdate );
73     void WriteTempFile ( XMP_IO* tempRef );
74 
75 	/**
76 	* Checks if the first 4 bytes of the given buffer are either type RIFF or RF64
77 	* @param buffer a byte buffer that must contain at least 4 bytes and point to the correct byte
78 	* @return Either kChunk_RIFF, kChunk_RF64 0 if no type could be determined
79 	*/
80 	static XMP_Uns32 whatRIFFFormat( XMP_Uns8* buffer );
81 
82 private:
83 	/**
84 	 * Updates/creates/deletes a given legacy chunk depending on the given new legacy value
85 	 * If the Chunk exists and is not empty, it is updated. If it is empty the
86 	 * Chunk is removed from the tree. If the Chunk does not exist but a value is given, it is created
87 	 * and initialized with that value
88 	 *
89 	 * @param chunk OUT pointer to the legacy chunk
90 	 * @param chunkID Id of the Chunk if it needs to be created
91 	 * @param chunkType Type of the Chunk if it needs to be created
92 	 * @param legacyData the new legacy metadata object (can be empty)
93 	 */
94 	void updateLegacyChunk( IChunkData **chunk, XMP_Uns32 chunkID, XMP_Uns32 chunkType, IMetadata &legacyData  );
95 
96 
97 	/** private standard Ctor, not to be used */
WAVE_MetaHandler()98 	WAVE_MetaHandler (): mChunkController(NULL), mChunkBehavior(NULL),
99 						mINFOMeta(), mBEXTMeta(), mCartMeta(), mDISPMeta(),
100 						mXMPChunk(NULL), mINFOChunk(NULL),
101 						mBEXTChunk(NULL), mCartChunk(NULL), mDISPChunk(NULL) {};
102 
103 	// ----- MEMBERS ----- //
104 
105 	/** Controls the parsing and writing of the passed stream. */
106 	ChunkController *mChunkController;
107 	/** Represents the rules how chunks are added, removed or rearranged */
108 	IChunkBehavior *mChunkBehavior;
109 	/** container for Legacy metadata */
110 	INFOMetadata mINFOMeta;
111 	BEXTMetadata mBEXTMeta;
112 	CartMetadata mCartMeta;
113 	DISPMetadata mDISPMeta;
114 	iXMLMetadata miXMLMeta;
115 
116 	// cr8r is not yet required for WAVE
117 	// Cr8rMetadata mCr8rMeta;
118 
119 	/** pointer to the XMP chunk */
120 	IChunkData *mXMPChunk;
121 	/** pointer to legacy chunks */
122 	IChunkData *mINFOChunk;
123 	IChunkData *mBEXTChunk;
124 	IChunkData *mCartChunk;
125 	IChunkData *mDISPChunk;
126 	IChunkData *miXMLChunk;
127 
128 	// cr8r is not yet required for WAVE
129 	// IChunkData *mCr8rChunk;
130 
131 	// ----- CONSTANTS ----- //
132 
133 	/** Chunk path identifier of interest in WAVE */
134 	static const ChunkIdentifier kRIFFXMP[2];
135 	static const ChunkIdentifier kRIFFInfo[2];
136 	static const ChunkIdentifier kRIFFDisp[2];
137 	static const ChunkIdentifier kRIFFBext[2];
138 	static const ChunkIdentifier kRIFFCart[2];
139 	static const ChunkIdentifier kRIFFiXML[2];
140 	// cr8r is not yet required for WAVE
141 	// static const ChunkIdentifier kWAVECr8r[2];
142 
143 	/** Chunk path identifier of interest in RF64 */
144 	static const ChunkIdentifier kRF64XMP[2];
145 	static const ChunkIdentifier kRF64Info[2];
146 	static const ChunkIdentifier kRF64Disp[2];
147 	static const ChunkIdentifier kRF64Bext[2];
148 	static const ChunkIdentifier kRF64Cart[2];
149 	static const ChunkIdentifier kRF64iXML[2];
150 	// cr8r is not yet required for WAVE
151 	// static const ChunkIdentifier kRF64Cr8r[2];
152 
153 	/** Path to XMP chunk */
154 	ChunkPath mWAVEXMPChunkPath;
155 
156 	/** Path to INFO chunk */
157 	ChunkPath mWAVEInfoChunkPath;
158 
159 	/** Path to DISP chunk */
160 	ChunkPath mWAVEDispChunkPath;
161 
162 	/** Path to BEXT chunk */
163 	ChunkPath mWAVEBextChunkPath;
164 
165 	/** Path to cart chunk */
166 	ChunkPath mWAVECartChunkPath;
167 
168 	/** Path to IXML chunk */
169 	ChunkPath mWAVEiXMLChunkPath;
170 
171 	//cr8r is not yet required for WAVE
172 	///** Path to Cr8r chunk */
173 	//const ChunkPath mWAVECr8rChunkPath;
174 
175 };	// WAVE_MetaHandler
176 
177 // =================================================================================================
178 
179 #endif /* __WAVE_Handler_hpp__ */
180