xref: /haiku/src/apps/cortex/Persistence/Wrappers/MediaFormatIO.h (revision 19ae20e67e91fc09cc9fc5c0e60e21e24e7a53eb)
1 /*
2  * Copyright (c) 1999-2000, Eric Moon.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions, and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions, and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 
32 // MediaFormatIO.h
33 // * PURPOSE
34 //   Wrapper class for media_format, providing XML
35 //   serialization support using the Cortex::XML package.
36 //
37 // * TO DO +++++
38 //   - import & export user data?
39 //   - import & export metadata?
40 //
41 // * HISTORY
42 //   e.moon		1jul99		Begun.
43 
44 #ifndef __MediaFormatIO_H__
45 #define __MediaFormatIO_H__
46 
47 #include "XML.h"
48 #include <MediaDefs.h>
49 #include <String.h>
50 
51 #include "cortex_defs.h"
52 __BEGIN_CORTEX_NAMESPACE
53 
54 class MediaFormatIO :
55 	public		IPersistent {
56 
57 public:				// *** ctor/dtor
58 	virtual ~MediaFormatIO();
59 
60 	MediaFormatIO();
61 	MediaFormatIO(const media_format& format);
62 
63 public:				// *** accessors
64 	// returns B_OK if the object contains a valid format,
65 	// or B_ERROR if not.
66 	status_t getFormat(media_format& outFormat) const;
67 
68 public:				// *** static setup method
69 	// call this method to install hooks for the tags needed by
70 	// MediaFormatIO into the given document type
71 	static void AddTo(XML::DocumentType* pDocType);
72 
73 public:				// *** top-level tags
74 
75 	// these tags map directly to MediaFormatIO
76 	static const char* const s_multi_audio_tag;
77 	static const char* const s_raw_audio_tag;
78 	static const char* const s_raw_video_tag;
79 	static const char* const s_multistream_tag;
80 	static const char* const s_encoded_audio_tag;
81 	static const char* const s_encoded_video_tag;
82 
83 public:				// *** nested tags
84 
85 	static const char* const s_video_display_info_tag;
86 
87 	static const char* const s_multistream_flags_tag;
88 	static const char* const s_multistream_vid_info_tag;
89 	static const char* const s_multistream_avi_info_tag;
90 
91 	static const char* const s_multi_audio_info_tag;
92 
93 	static const char* const s_media_type_tag;
94 
95 public:				// *** IPersistent
96 
97 //	void xmlExport(
98 //		ostream& 					stream,
99 //		ExportContext&		context) const;
100 
101 	// EXPORT:
102 
103 	void xmlExportBegin(
104 		ExportContext& context) const;
105 
106 	void xmlExportAttributes(
107 		ExportContext& context) const;
108 
109 	void xmlExportContent(
110 		ExportContext& context) const;
111 
112 	void xmlExportEnd(
113 		ExportContext& context) const;
114 
115 	// IMPORT
116 
117 	void xmlImportBegin(
118 		ImportContext&		context);
119 
120 	void xmlImportAttribute(
121 		const char*					key,
122 		const char*					value,
123 		ImportContext&		context);
124 
125 	void xmlImportContent(
126 		const char*					data,
127 		uint32						length,
128 		ImportContext&		context);
129 
130 	void xmlImportChild(
131 		IPersistent*			child,
132 		ImportContext&		context);
133 
134 	void xmlImportComplete(
135 		ImportContext&		context);
136 
137 	void xmlImportChildBegin(
138 		const char*					name,
139 		ImportContext&		context);
140 
141 	void xmlImportChildAttribute(
142 		const char*					key,
143 		const char*					value,
144 		ImportContext&		context);
145 
146 	void xmlImportChildContent(
147 		const char*					data,
148 		uint32						length,
149 		ImportContext&		context);
150 
151 	void xmlImportChildComplete(
152 		const char*					name,
153 		ImportContext&		context);
154 
155 private:				// *** state
156 	bool						m_complete;
157 	media_format		m_format;
158 
159 	BString					m_mediaType;
160 };
161 
162 __END_CORTEX_NAMESPACE
163 #endif /*__MediaFormatIO_H__*/
164