xref: /haiku/src/add-ons/media/media-add-ons/reader/MediaReaderAddOn.cpp (revision 9ed520d828d76d0d4cd81ffc9abf75f10f490dd8)
1820c41b9Sshatty // MediaReaderAddOn.cpp
2820c41b9Sshatty //
3820c41b9Sshatty // Andrew Bachmann, 2002
4820c41b9Sshatty //
5820c41b9Sshatty // A MediaReaderAddOn is an add-on
6820c41b9Sshatty // that can make MediaReader nodes
7820c41b9Sshatty //
8820c41b9Sshatty // MediaReader nodes read a file into a multistream
9820c41b9Sshatty 
10820c41b9Sshatty 
11820c41b9Sshatty #include <MediaDefs.h>
12820c41b9Sshatty #include <MediaAddOn.h>
13820c41b9Sshatty #include <Errors.h>
14820c41b9Sshatty #include <Node.h>
15820c41b9Sshatty #include <Mime.h>
16820c41b9Sshatty #include <StorageDefs.h>
17820c41b9Sshatty 
18820c41b9Sshatty #include "MediaReader.h"
19820c41b9Sshatty #include "MediaReaderAddOn.h"
20820c41b9Sshatty 
21820c41b9Sshatty #include <limits.h>
22820c41b9Sshatty #include <stdio.h>
23820c41b9Sshatty #include <string.h>
24820c41b9Sshatty 
25820c41b9Sshatty // instantiation function
26820c41b9Sshatty extern "C" _EXPORT BMediaAddOn * make_media_addon(image_id image) {
27820c41b9Sshatty 	return new MediaReaderAddOn(image);
28820c41b9Sshatty }
29820c41b9Sshatty 
30820c41b9Sshatty // -------------------------------------------------------- //
31820c41b9Sshatty // ctor/dtor
32820c41b9Sshatty // -------------------------------------------------------- //
33820c41b9Sshatty 
34820c41b9Sshatty MediaReaderAddOn::~MediaReaderAddOn()
35820c41b9Sshatty {
36820c41b9Sshatty }
37820c41b9Sshatty 
38820c41b9Sshatty MediaReaderAddOn::MediaReaderAddOn(image_id image) :
39794887f8Sshatty 	AbstractFileInterfaceAddOn(image)
40820c41b9Sshatty {
41820c41b9Sshatty 	fprintf(stderr,"MediaReaderAddOn::MediaReaderAddOn\n");
42820c41b9Sshatty }
43820c41b9Sshatty 
44820c41b9Sshatty // -------------------------------------------------------- //
45820c41b9Sshatty // BMediaAddOn impl
46820c41b9Sshatty // -------------------------------------------------------- //
47820c41b9Sshatty 
48820c41b9Sshatty status_t MediaReaderAddOn::GetFlavorAt(
49820c41b9Sshatty 	int32 n,
50820c41b9Sshatty 	const flavor_info ** out_info)
51820c41b9Sshatty {
52820c41b9Sshatty 	fprintf(stderr,"MediaReaderAddOn::GetFlavorAt\n");
53820c41b9Sshatty 	if (out_info == 0) {
54820c41b9Sshatty 		fprintf(stderr,"<- B_BAD_VALUE\n");
55820c41b9Sshatty 		return B_BAD_VALUE; // we refuse to crash because you were stupid
56820c41b9Sshatty 	}
57820c41b9Sshatty 	if (n != 0) {
58820c41b9Sshatty 		fprintf(stderr,"<- B_BAD_INDEX\n");
59820c41b9Sshatty 		return B_BAD_INDEX;
60820c41b9Sshatty 	}
61ca6f35b1Sshatty 	flavor_info * infos = new flavor_info[1];
62ca6f35b1Sshatty 	MediaReader::GetFlavor(&infos[0],n);
63ca6f35b1Sshatty 	(*out_info) = infos;
64794887f8Sshatty 	return B_OK;
65820c41b9Sshatty }
66820c41b9Sshatty 
67820c41b9Sshatty BMediaNode * MediaReaderAddOn::InstantiateNodeFor(
68820c41b9Sshatty 				const flavor_info * info,
69820c41b9Sshatty 				BMessage * config,
70820c41b9Sshatty 				status_t * out_error)
71820c41b9Sshatty {
72820c41b9Sshatty 	fprintf(stderr,"MediaReaderAddOn::InstantiateNodeFor\n");
73820c41b9Sshatty 	if (out_error == 0) {
74820c41b9Sshatty 		fprintf(stderr,"<- NULL\n");
75820c41b9Sshatty 		return 0; // we refuse to crash because you were stupid
76820c41b9Sshatty 	}
77a1eca89cSshatty 	// XXX: read from add-on's attributes
78a1eca89cSshatty 	size_t defaultChunkSize = size_t(8192); // 8192 bytes = 8 Kilobytes
79a1eca89cSshatty 	float defaultBitRate = 2048; // = 2048 kilobits/millisec = 256000 Kilobytes/sec
80794887f8Sshatty 	MediaReader * node
81794887f8Sshatty 		= new MediaReader(defaultChunkSize,
82820c41b9Sshatty 						  defaultBitRate,
83820c41b9Sshatty 						  info,config,this);
84820c41b9Sshatty 	if (node == 0) {
85820c41b9Sshatty 		*out_error = B_NO_MEMORY;
86820c41b9Sshatty 		fprintf(stderr,"<- B_NO_MEMORY\n");
87820c41b9Sshatty 	} else {
88820c41b9Sshatty 		*out_error = node->InitCheck();
89820c41b9Sshatty 	}
90820c41b9Sshatty 	return node;
91820c41b9Sshatty }
92820c41b9Sshatty 
93820c41b9Sshatty status_t MediaReaderAddOn::GetConfigurationFor(
94820c41b9Sshatty 				BMediaNode * your_node,
95820c41b9Sshatty 				BMessage * into_message)
96820c41b9Sshatty {
97820c41b9Sshatty 	fprintf(stderr,"MediaReaderAddOn::GetConfigurationFor\n");
98820c41b9Sshatty 	if (into_message == 0) {
99820c41b9Sshatty 		fprintf(stderr,"<- B_BAD_VALUE\n");
100820c41b9Sshatty 		return B_BAD_VALUE; // we refuse to crash because you were stupid
101820c41b9Sshatty 	}
102794887f8Sshatty 	MediaReader * node
103794887f8Sshatty 		= dynamic_cast<MediaReader*>(your_node);
104820c41b9Sshatty 	if (node == 0) {
105820c41b9Sshatty 		fprintf(stderr,"<- B_BAD_TYPE\n");
106820c41b9Sshatty 		return B_BAD_TYPE;
107820c41b9Sshatty 	}
108820c41b9Sshatty 	return node->GetConfigurationFor(into_message);
109820c41b9Sshatty }
110820c41b9Sshatty 
111820c41b9Sshatty // -------------------------------------------------------- //
112820c41b9Sshatty // BMediaAddOn impl for B_FILE_INTERFACE nodes
113820c41b9Sshatty // -------------------------------------------------------- //
114820c41b9Sshatty 
115820c41b9Sshatty // This function treats null pointers slightly differently than the others.
116820c41b9Sshatty // This is because a program could reasonably call this function with just
117794887f8Sshatty // about any junk, get the out_read_items or out_write_items and then use
118794887f8Sshatty // that to create an array of sufficient size to hold the result, and then
119794887f8Sshatty // call us again.  So we won't punish them if they supply us with null
120794887f8Sshatty // pointers the first time around.
121794887f8Sshatty //
122794887f8Sshatty // A stupid program might not supply an out_read_items, but actually supply
123820c41b9Sshatty // an out_readable_formats and then try to do something useful with it. As
124820c41b9Sshatty // an extreme gesture of nicety we will fill the out_readable_formats with
125820c41b9Sshatty // a valid entry, although they could easily read into garbage after that...
126820c41b9Sshatty status_t MediaReaderAddOn::GetFileFormatList(
127820c41b9Sshatty 				int32 flavor_id,
128820c41b9Sshatty 				media_file_format * out_writable_formats,
129820c41b9Sshatty 				int32 in_write_items,
130820c41b9Sshatty 				int32 * out_write_items,
131820c41b9Sshatty 				media_file_format * out_readable_formats,
132820c41b9Sshatty 				int32 in_read_items,
133820c41b9Sshatty 				int32 * out_read_items,
134820c41b9Sshatty 				void * _reserved)
135820c41b9Sshatty {
136820c41b9Sshatty 	fprintf(stderr,"MediaReaderAddOn::GetFileFormatList\n");
137820c41b9Sshatty 	if (flavor_id != 0) {
138820c41b9Sshatty 		// this is a sanity check for now
139820c41b9Sshatty 		fprintf(stderr,"<- B_BAD_INDEX\n");
140820c41b9Sshatty 		return B_BAD_INDEX;
141820c41b9Sshatty 	}
142820c41b9Sshatty 	// see null check comment above
143820c41b9Sshatty 	if (out_write_items != 0) {
144820c41b9Sshatty 		*out_write_items = 0;
145820c41b9Sshatty 	}
146820c41b9Sshatty 	// see null check comment above
147820c41b9Sshatty 	if (out_read_items != 0) {
148820c41b9Sshatty 		*out_read_items = 1;
149820c41b9Sshatty 	}
150820c41b9Sshatty 	if (out_readable_formats != 0) {
151820c41b9Sshatty 		// don't go off the end
152820c41b9Sshatty 		if (in_read_items > 0) {
15345ed7b19Sshatty 			MediaReader::GetFileFormat(&out_readable_formats[0]);
154820c41b9Sshatty 		}
155820c41b9Sshatty 	}
156820c41b9Sshatty 	return B_OK;
157820c41b9Sshatty }
158820c41b9Sshatty 
159820c41b9Sshatty status_t MediaReaderAddOn::SniffTypeKind(
160820c41b9Sshatty 				const BMimeType & type,
161820c41b9Sshatty 				uint64 in_kinds,
162820c41b9Sshatty 				float * out_quality,
163820c41b9Sshatty 				int32 * out_internal_id,
164820c41b9Sshatty 				void * _reserved)
165820c41b9Sshatty {
166820c41b9Sshatty 	fprintf(stderr,"MediaReaderAddOn::SniffTypeKind\n");
167794887f8Sshatty 	return AbstractFileInterfaceAddOn::SniffTypeKind(type,in_kinds,
168794887f8Sshatty 													 B_BUFFER_PRODUCER,
169794887f8Sshatty 													 out_quality,out_internal_id,
170794887f8Sshatty 													 _reserved);
171820c41b9Sshatty }
172820c41b9Sshatty 
173820c41b9Sshatty // -------------------------------------------------------- //
174*9ed520d8Sshatty // main
175820c41b9Sshatty // -------------------------------------------------------- //
176820c41b9Sshatty 
177820c41b9Sshatty int main(int argc, char *argv[])
178820c41b9Sshatty {
179*9ed520d8Sshatty 	fprintf(stderr,"main called for MediaReaderAddOn\n");
180820c41b9Sshatty }
181820c41b9Sshatty 
182820c41b9Sshatty // -------------------------------------------------------- //
183820c41b9Sshatty // stuffing
184820c41b9Sshatty // -------------------------------------------------------- //
185820c41b9Sshatty 
186820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_0(void *) {};
187820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_1(void *) {};
188820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_2(void *) {};
189820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_3(void *) {};
190820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_4(void *) {};
191820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_5(void *) {};
192820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_6(void *) {};
193820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_7(void *) {};
194820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_8(void *) {};
195820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_9(void *) {};
196820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_10(void *) {};
197820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_11(void *) {};
198820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_12(void *) {};
199820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_13(void *) {};
200820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_14(void *) {};
201820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_15(void *) {};
202