summaryrefslogtreecommitdiff
path: root/XMPFiles/source/FileHandlers/MPEG4_Handler.hpp
blob: a55aa1e26e608607c866632502e1cbc07e5d1d21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef __MPEG4_Handler_hpp__
#define __MPEG4_Handler_hpp__	1

// =================================================================================================
// Copyright Adobe
// Copyright 2006 Adobe
// All Rights Reserved
//
// NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
// of the Adobe license agreement accompanying it. If you have received this file from a source other 
// than Adobe, then your use, modification, or distribution of it requires the prior written permission
// of Adobe.
// =================================================================================================

#include "XMPFiles/source/XMPFiles_Impl.hpp"

#include "XMPFiles/source/FormatSupport/MOOV_Support.hpp"
#include "XMPFiles/source/FormatSupport/QuickTime_Support.hpp"
#include "XMPFiles/source/FormatSupport/META_Support.hpp"


//  ================================================================================================
/// \file MPEG4_Handler.hpp
/// \brief File format handler for MPEG-4.
///
/// This header ...
///
//  ================================================================================================

extern XMPFileHandler * MPEG4_MetaHandlerCTor ( XMPFiles * parent );

extern bool MPEG4_CheckFormat ( XMP_FileFormat format,
								XMP_StringPtr  filePath,
								XMP_IO*    fileRef,
								XMPFiles *     parent );

static const XMP_OptionBits kMPEG4_HandlerFlags = ( kXMPFiles_CanInjectXMP |
													kXMPFiles_CanExpand |
													kXMPFiles_CanRewrite |
													kXMPFiles_PrefersInPlace |
													kXMPFiles_CanReconcile |
													kXMPFiles_AllowsOnlyXMP |
													kXMPFiles_ReturnsRawPacket |
													kXMPFiles_AllowsSafeUpdate |
													kXMPFiles_CanNotifyProgress
												  );

class MPEG4_MetaHandler : public XMPFileHandler
{
public:

	void CacheFileData();
	void ProcessXMP();

	void UpdateFile ( bool doSafeUpdate );
    void WriteTempFile ( XMP_IO* tempRef );


	MPEG4_MetaHandler ( XMPFiles * _parent );
	virtual ~MPEG4_MetaHandler();

	struct TimecodeTrackInfo {	// Info about a QuickTime timecode track.
		bool stsdBoxFound, isDropFrame;
		XMP_Uns32 timeScale;
		XMP_Uns32 frameDuration;
		XMP_Uns32 timecodeSample;
		XMP_Uns64 sampleOffset;	// Absolute file offset of the timecode sample, 0 if none.
		XMP_Uns32 nameOffset;	// The offset of the 'name' box relative to the 'stsd' box content.
		XMP_Uns16   macLang;	// The Mac language code of the trailing 'name' box.
		std::string macName;	// The text part of the trailing 'name' box, in macLang encoding.
		TimecodeTrackInfo()
			: stsdBoxFound(false), isDropFrame(false), timeScale(0), frameDuration(0),
			  timecodeSample(0), sampleOffset(0), nameOffset(0), macLang(0) {};
	};

private:

	MPEG4_MetaHandler() : fileMode(0), havePreferredXMP(false),
						  xmpBoxPos(0), moovBoxPos(0), xmpBoxSize(0), moovBoxSize(0)
	{};	// Hidden on purpose.

	bool ParseTimecodeTrack();
	void UpdateTopLevelBox ( XMP_Uns64 oldOffset, XMP_Uns32 oldSize, const XMP_Uns8 * newBox, XMP_Uns32 newSize );

	void OptimizeFileLayout();

	XMP_Uns8 fileMode;
	bool havePreferredXMP;
	XMP_Uns64 xmpBoxPos;	// The file offset of the XMP box (the size field, not the content).
	XMP_Uns64 moovBoxPos;	// The file offset of the 'moov' box (the size field, not the content).
	XMP_Uns32 xmpBoxSize, moovBoxSize;	// The full size of the boxes, not just the content.
	
	MOOV_Manager moovMgr;

	TradQT_Manager tradQTMgr;

	TimecodeTrackInfo tmcdInfo;

};	// MPEG4_MetaHandler

// =================================================================================================

#endif // __MPEG4_Handler_hpp__