xref: /haiku/docs/user/media/FileInterface.dox (revision 25a7b01d15612846f332751841da3579db313082)
1495275e4SJohn Scipione/*
2*820dca4dSJohn Scipione * Copyright 2012 Haiku Inc. All rights reserved.
3495275e4SJohn Scipione * Distributed under the terms of the MIT License.
4495275e4SJohn Scipione *
5495275e4SJohn Scipione * Authors:
6495275e4SJohn Scipione *		John Scipione, jscipione@gmail.com
7495275e4SJohn Scipione *
8495275e4SJohn Scipione * Corresponds to:
9*820dca4dSJohn Scipione *		headers/os/media/FileInterface.h	hrev45081
10*820dca4dSJohn Scipione *		src/kits/media/FileInterface.cpp	hrev45081
11495275e4SJohn Scipione */
12495275e4SJohn Scipione
13495275e4SJohn Scipione
14495275e4SJohn Scipione/*!
15495275e4SJohn Scipione	\file FileInterface.h
16*820dca4dSJohn Scipione	\ingroup media
17*820dca4dSJohn Scipione	\ingroup libbe
18495275e4SJohn Scipione	\brief Provides BFileInterface abstract class.
19495275e4SJohn Scipione*/
20495275e4SJohn Scipione
21495275e4SJohn Scipione
22495275e4SJohn Scipione/*!
23495275e4SJohn Scipione	\class BFileInterface
24495275e4SJohn Scipione	\ingroup media
25495275e4SJohn Scipione	\ingroup libbe
26495275e4SJohn Scipione	\brief A node that can read and write data to a file on disk.
27495275e4SJohn Scipione
28495275e4SJohn Scipione	You should derive your subclass from BFileInterface so that your
29495275e4SJohn Scipione	application may specify the file that the node will reference.
30495275e4SJohn Scipione	The Media Server will then call upon the node to try to identify
31495275e4SJohn Scipione	and work with files that are hereunto unknown to it.
32495275e4SJohn Scipione
33495275e4SJohn Scipione	Your node must also derive from BBufferConsumer or BBufferProducer,
34495275e4SJohn Scipione	in addition to BFileInterface.
35495275e4SJohn Scipione*/
36495275e4SJohn Scipione
37495275e4SJohn Scipione
38495275e4SJohn Scipione/*!
39495275e4SJohn Scipione	\fn BFileInterface::BFileInterface()
40495275e4SJohn Scipione	\brief Constructor.
41495275e4SJohn Scipione*/
42495275e4SJohn Scipione
43495275e4SJohn Scipione
44495275e4SJohn Scipione/*!
45495275e4SJohn Scipione	\fn BFileInterface::~BFileInterface()
46495275e4SJohn Scipione	\brief Destructor.
47495275e4SJohn Scipione*/
48495275e4SJohn Scipione
49495275e4SJohn Scipione
50495275e4SJohn Scipione/*!
51495275e4SJohn Scipione	\fn status_t BFileInterface::HandleMessage(int32 message,
52495275e4SJohn Scipione		const void *data, size_t size)
53495275e4SJohn Scipione	\brief Dispatches a message to the appropriate BMediaNode hook method
54495275e4SJohn Scipione		given a message received on the control port. Implement this method
55495275e4SJohn Scipione		to handle messages that arrive on your control port.
56495275e4SJohn Scipione
57495275e4SJohn Scipione	\param message The message identifier.
58495275e4SJohn Scipione	\param data The message data.
59495275e4SJohn Scipione	\param size The size of the message data in bytes.
60495275e4SJohn Scipione
61495275e4SJohn Scipione	\returns A status code.
62495275e4SJohn Scipione	\retval B_OK Message was dispatched.
63495275e4SJohn Scipione	\retval B_ERROR There was an error dispatching the message, possibly
64495275e4SJohn Scipione			because it doesn't correspond to a hook function.
65495275e4SJohn Scipione
66495275e4SJohn Scipione	\see BMediaNode::HandleMessage() for details.
67495275e4SJohn Scipione*/
68495275e4SJohn Scipione
69495275e4SJohn Scipione
70495275e4SJohn Scipione/*!
71495275e4SJohn Scipione	\fn status_t BFileInterface::GetNextFileFormat(int32* cookie,
72495275e4SJohn Scipione		media_file_format* _format) = 0;
73495275e4SJohn Scipione	\brief Implement this method to fill out information about a file format
74495275e4SJohn Scipione		   indexed by \a cookie.
75495275e4SJohn Scipione
76495275e4SJohn Scipione	The first time this method is called \a cookie will be set to 0.
77495275e4SJohn Scipione	In your implementation you should set information about the first
78495275e4SJohn Scipione	file format you support in \a _format and set \a cookie to some
79495275e4SJohn Scipione	meaningful non-zero value to track your positing in the list of
80495275e4SJohn Scipione	supported formats, then return \c B_OK.
81495275e4SJohn Scipione
82495275e4SJohn Scipione	On successive calls return successive file format information and update
83495275e4SJohn Scipione	\a cookie to track your position in the list. Each time you return new
84495275e4SJohn Scipione	information about a file format return \c B_OK.
85495275e4SJohn Scipione
86495275e4SJohn Scipione	Once you run out of formats return \c B_ERROR.
87495275e4SJohn Scipione
88495275e4SJohn Scipione	\param cookie Index of file format to fill out.
89495275e4SJohn Scipione	\param _format Pointer to a preallocated \c media_file_format object to
90495275e4SJohn Scipione		   fill out.
91495275e4SJohn Scipione
92495275e4SJohn Scipione	\return \c B_OK if a file format was filled out for \a cookie, \c B_ERROR
93495275e4SJohn Scipione			or an appropriate error code otherwise.
94495275e4SJohn Scipione*/
95495275e4SJohn Scipione
96495275e4SJohn Scipione
97495275e4SJohn Scipione/*!
98495275e4SJohn Scipione	\fn void BFileInterface::DisposeFileFormatCookie(int32 cookie) = 0;
99495275e4SJohn Scipione	\brief Implement this method to dispose of a file format supported by your
100495275e4SJohn Scipione		   node indexed by \a cookie.
101495275e4SJohn Scipione
102495275e4SJohn Scipione	You are responsible for freeing any data blocks associated with this
103495275e4SJohn Scipione	\a cookie before returning.
104495275e4SJohn Scipione
105495275e4SJohn Scipione	\param cookie Index of the cookie you wish to dispose of.
106495275e4SJohn Scipione*/
107495275e4SJohn Scipione
108495275e4SJohn Scipione
109495275e4SJohn Scipione/*!
110495275e4SJohn Scipione	\fn status_t BFileInterface::GetDuration(bigtime_t* _time) = 0;
111495275e4SJohn Scipione	\brief Implement this method to fill out the duration in microseconds of
112495275e4SJohn Scipione		   the media data contained in the currently referenced file in
113495275e4SJohn Scipione		   \a _time.
114495275e4SJohn Scipione
115495275e4SJohn Scipione	\param _time The duration parameter to fill out.
116495275e4SJohn Scipione
117495275e4SJohn Scipione	\return A status code, typically \c B_OK on success and \c B_ERROR
118495275e4SJohn Scipione			or another error code on error.
119495275e4SJohn Scipione*/
120495275e4SJohn Scipione
121495275e4SJohn Scipione
122495275e4SJohn Scipione/*!
123495275e4SJohn Scipione	\fn status_t BFileInterface::SniffRef(const entry_ref& file,
124495275e4SJohn Scipione		char* _mimeType, float* _quality) = 0;
125495275e4SJohn Scipione	\brief Implement this method to allow the Media Roster to identify
126495275e4SJohn Scipione		   a file format associated with this node.
127495275e4SJohn Scipione
128495275e4SJohn Scipione	If you can handle the format, set \a _mimeType to the MIME type
129495275e4SJohn Scipione	of the file format and set \a _quality to indicate how well you
130495275e4SJohn Scipione	can process the file.
131495275e4SJohn Scipione
132495275e4SJohn Scipione	A \a _quality of 0.0 means that you can't handle the file format
133495275e4SJohn Scipione	at all and an \a _quality of 1.0 means you have total control over
134495275e4SJohn Scipione	the file format.
135495275e4SJohn Scipione
136495275e4SJohn Scipione	\param file The file being sniffed.
137495275e4SJohn Scipione	\param _mimeType Fill this out with the appropriate MIME type.
138495275e4SJohn Scipione	\param _quality How well you are able to handle the file format
139495275e4SJohn Scipione		   from 0.0 to 1.0.
140495275e4SJohn Scipione
141495275e4SJohn Scipione	\return \c B_OK if you can identify the file's contents, otherwise return
142495275e4SJohn Scipione			an appropriate error code. If you can't handle the file format at
143495275e4SJohn Scipione			all, you should return \c B_MEDIA_NO_HANDLER.
144495275e4SJohn Scipione*/
145495275e4SJohn Scipione
146495275e4SJohn Scipione
147495275e4SJohn Scipione/*!
148495275e4SJohn Scipione	\fn status_t BFileInterface::SetRef(const entry_ref& file, bool create,
149495275e4SJohn Scipione		bigtime_t* _time) = 0;
150495275e4SJohn Scipione	\brief Used when an application wants your node to use a specific file.
151495275e4SJohn Scipione
152495275e4SJohn Scipione	The file specified by \a file may or may not exist.
153495275e4SJohn Scipione
154495275e4SJohn Scipione	If create is \c false you should try to open the existing file, and if
155495275e4SJohn Scipione	successful you should write the running time of the file into \a _time.
156495275e4SJohn Scipione	If you the file does not exist you should return \c B_ENTRY_NOT_FOUND.
157495275e4SJohn Scipione
158495275e4SJohn Scipione	If \a create is \c true you should create a new file, initialize the file
159495275e4SJohn Scipione	for writing, and store 0 in \a _time. You should overwrite the file if
160495275e4SJohn Scipione	it already exists.
161495275e4SJohn Scipione
162495275e4SJohn Scipione	\return \c B_OK on success or an appropriate error code such as \c B_ERROR
163495275e4SJohn Scipione			or \c B_ENTRY_NOT_FOUND on error.
164495275e4SJohn Scipione*/
165495275e4SJohn Scipione
166495275e4SJohn Scipione
167495275e4SJohn Scipione/*!
168495275e4SJohn Scipione	\fn status_t BFileInterface::GetRef(entry_ref* _ref, char* _mimeType) = 0;
169495275e4SJohn Scipione	\brief Implement to set the \c entry_ref and the MIME type of the file
170495275e4SJohn Scipione		   referenced by the current node.
171495275e4SJohn Scipione
172495275e4SJohn Scipione	\param _ref Set to the \c entry_ref of the file.
173495275e4SJohn Scipione	\param _mimeType Set to the MIME type of the current file.
174495275e4SJohn Scipione
175495275e4SJohn Scipione	\return \c B_OK on success or an appropriate error code such as \c B_ERROR
176495275e4SJohn Scipione			on error.
177495275e4SJohn Scipione*/
178