xref: /haiku/src/add-ons/media/media-add-ons/reader/MediaReaderAddOn.cpp (revision bcf291ed9b7e872a4b60160de829153188a8ea2f)
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 #include "MediaReader.h"
10820c41b9Sshatty #include "MediaReaderAddOn.h"
11*fb16552fSMaurice Kalinowski #include "debug.h"
12*fb16552fSMaurice Kalinowski 
13*fb16552fSMaurice Kalinowski #include <Errors.h>
14*fb16552fSMaurice Kalinowski #include <MediaAddOn.h>
15*fb16552fSMaurice Kalinowski #include <MediaDefs.h>
16*fb16552fSMaurice Kalinowski #include <MediaRoster.h>
17*fb16552fSMaurice Kalinowski #include <Mime.h>
18*fb16552fSMaurice Kalinowski #include <Node.h>
19*fb16552fSMaurice Kalinowski #include <StorageDefs.h>
20*fb16552fSMaurice Kalinowski 
21820c41b9Sshatty 
22820c41b9Sshatty #include <limits.h>
23820c41b9Sshatty #include <stdio.h>
24820c41b9Sshatty #include <string.h>
25820c41b9Sshatty 
26*fb16552fSMaurice Kalinowski 
27820c41b9Sshatty // instantiation function
make_media_addon(image_id image)28820c41b9Sshatty extern "C" _EXPORT BMediaAddOn * make_media_addon(image_id image) {
29820c41b9Sshatty 	return new MediaReaderAddOn(image);
30820c41b9Sshatty }
31820c41b9Sshatty 
32820c41b9Sshatty 
~MediaReaderAddOn()33820c41b9Sshatty MediaReaderAddOn::~MediaReaderAddOn()
34820c41b9Sshatty {
35820c41b9Sshatty }
36820c41b9Sshatty 
37*fb16552fSMaurice Kalinowski 
MediaReaderAddOn(image_id image)38820c41b9Sshatty MediaReaderAddOn::MediaReaderAddOn(image_id image) :
39794887f8Sshatty 	AbstractFileInterfaceAddOn(image)
40820c41b9Sshatty {
41*fb16552fSMaurice Kalinowski 	CALLED();
42820c41b9Sshatty }
43820c41b9Sshatty 
44*fb16552fSMaurice Kalinowski 
45820c41b9Sshatty // -------------------------------------------------------- //
46820c41b9Sshatty // BMediaAddOn impl
47820c41b9Sshatty // -------------------------------------------------------- //
GetFlavorAt(int32 n,const flavor_info ** out_info)48820c41b9Sshatty status_t MediaReaderAddOn::GetFlavorAt(
49820c41b9Sshatty 	int32 n,
50820c41b9Sshatty 	const flavor_info ** out_info)
51820c41b9Sshatty {
52*fb16552fSMaurice Kalinowski 	CALLED();
53*fb16552fSMaurice Kalinowski 
54820c41b9Sshatty 	if (n != 0) {
55*fb16552fSMaurice Kalinowski 		PRINT("\t<- B_BAD_INDEX\n");
56820c41b9Sshatty 		return B_BAD_INDEX;
57820c41b9Sshatty 	}
58*fb16552fSMaurice Kalinowski 
59ca6f35b1Sshatty 	flavor_info * infos = new flavor_info[1];
60ca6f35b1Sshatty 	MediaReader::GetFlavor(&infos[0],n);
61ca6f35b1Sshatty 	(*out_info) = infos;
62794887f8Sshatty 	return B_OK;
63820c41b9Sshatty }
64820c41b9Sshatty 
65*fb16552fSMaurice Kalinowski 
InstantiateNodeFor(const flavor_info * info,BMessage * config,status_t * out_error)66820c41b9Sshatty BMediaNode * MediaReaderAddOn::InstantiateNodeFor(
67820c41b9Sshatty 				const flavor_info * info,
68820c41b9Sshatty 				BMessage * config,
69820c41b9Sshatty 				status_t * out_error)
70820c41b9Sshatty {
71*fb16552fSMaurice Kalinowski 	CALLED();
72*fb16552fSMaurice Kalinowski 
73a1eca89cSshatty 	// XXX: read from add-on's attributes
74a1eca89cSshatty 	size_t defaultChunkSize = size_t(8192); // 8192 bytes = 8 Kilobytes
75*fb16552fSMaurice Kalinowski 	// = 2048 kilobits/millisec = 256000 Kilobytes/sec
76*fb16552fSMaurice Kalinowski 	float defaultBitRate = 2048;
77794887f8Sshatty 	MediaReader * node
78794887f8Sshatty 		= new MediaReader(defaultChunkSize,
79820c41b9Sshatty 						  defaultBitRate,
80820c41b9Sshatty 						  info,config,this);
81820c41b9Sshatty 	if (node == 0) {
82820c41b9Sshatty 		*out_error = B_NO_MEMORY;
83*fb16552fSMaurice Kalinowski 		PRINT("\t<- B_NO_MEMORY\n");
84820c41b9Sshatty 	} else {
85820c41b9Sshatty 		*out_error = node->InitCheck();
86820c41b9Sshatty 	}
87820c41b9Sshatty 	return node;
88820c41b9Sshatty }
89820c41b9Sshatty 
90*fb16552fSMaurice Kalinowski 
GetConfigurationFor(BMediaNode * your_node,BMessage * into_message)91820c41b9Sshatty status_t MediaReaderAddOn::GetConfigurationFor(
92820c41b9Sshatty 				BMediaNode * your_node,
93820c41b9Sshatty 				BMessage * into_message)
94820c41b9Sshatty {
95*fb16552fSMaurice Kalinowski 	CALLED();
96*fb16552fSMaurice Kalinowski 
97794887f8Sshatty 	MediaReader * node
98794887f8Sshatty 		= dynamic_cast<MediaReader*>(your_node);
99820c41b9Sshatty 	if (node == 0) {
100820c41b9Sshatty 		fprintf(stderr,"<- B_BAD_TYPE\n");
101820c41b9Sshatty 		return B_BAD_TYPE;
102820c41b9Sshatty 	}
103820c41b9Sshatty 	return node->GetConfigurationFor(into_message);
104820c41b9Sshatty }
105820c41b9Sshatty 
106*fb16552fSMaurice Kalinowski 
107820c41b9Sshatty // -------------------------------------------------------- //
108820c41b9Sshatty // BMediaAddOn impl for B_FILE_INTERFACE nodes
109820c41b9Sshatty // -------------------------------------------------------- //
110820c41b9Sshatty 
GetFileFormatList(int32 flavor_id,media_file_format * out_writable_formats,int32 in_write_items,int32 * out_write_items,media_file_format * out_readable_formats,int32 in_read_items,int32 * out_read_items,void * _reserved)111820c41b9Sshatty status_t MediaReaderAddOn::GetFileFormatList(
112820c41b9Sshatty 				int32 flavor_id,
113820c41b9Sshatty 				media_file_format * out_writable_formats,
114820c41b9Sshatty 				int32 in_write_items,
115820c41b9Sshatty 				int32 * out_write_items,
116820c41b9Sshatty 				media_file_format * out_readable_formats,
117820c41b9Sshatty 				int32 in_read_items,
118820c41b9Sshatty 				int32 * out_read_items,
119820c41b9Sshatty 				void * _reserved)
120820c41b9Sshatty {
121*fb16552fSMaurice Kalinowski 	CALLED();
122*fb16552fSMaurice Kalinowski 
123820c41b9Sshatty 	if (flavor_id != 0) {
124820c41b9Sshatty 		// this is a sanity check for now
125*fb16552fSMaurice Kalinowski 		PRINT("\t<- B_BAD_INDEX\n");
126820c41b9Sshatty 		return B_BAD_INDEX;
127820c41b9Sshatty 	}
128820c41b9Sshatty 		// don't go off the end
129820c41b9Sshatty 		if (in_read_items > 0) {
13045ed7b19Sshatty 			MediaReader::GetFileFormat(&out_readable_formats[0]);
131820c41b9Sshatty 		}
132820c41b9Sshatty 	return B_OK;
133820c41b9Sshatty }
134820c41b9Sshatty 
135*fb16552fSMaurice Kalinowski 
SniffTypeKind(const BMimeType & type,uint64 in_kinds,float * out_quality,int32 * out_internal_id,void * _reserved)136820c41b9Sshatty status_t MediaReaderAddOn::SniffTypeKind(
137820c41b9Sshatty 				const BMimeType & type,
138820c41b9Sshatty 				uint64 in_kinds,
139820c41b9Sshatty 				float * out_quality,
140820c41b9Sshatty 				int32 * out_internal_id,
141820c41b9Sshatty 				void * _reserved)
142820c41b9Sshatty {
143*fb16552fSMaurice Kalinowski 	CALLED();
144794887f8Sshatty 	return AbstractFileInterfaceAddOn::SniffTypeKind(type,in_kinds,
145794887f8Sshatty 													 B_BUFFER_PRODUCER,
146794887f8Sshatty 													 out_quality,out_internal_id,
147794887f8Sshatty 													 _reserved);
148820c41b9Sshatty }
149820c41b9Sshatty 
150820c41b9Sshatty // -------------------------------------------------------- //
1519ed520d8Sshatty // main
152820c41b9Sshatty // -------------------------------------------------------- //
main(int argc,char * argv[])153820c41b9Sshatty int main(int argc, char *argv[])
154820c41b9Sshatty {
1559ed520d8Sshatty 	fprintf(stderr,"main called for MediaReaderAddOn\n");
156*fb16552fSMaurice Kalinowski 	return 0;
157820c41b9Sshatty }
158820c41b9Sshatty 
159820c41b9Sshatty // -------------------------------------------------------- //
160820c41b9Sshatty // stuffing
161820c41b9Sshatty // -------------------------------------------------------- //
162820c41b9Sshatty 
_Reserved_MediaReaderAddOn_0(void *)163*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_0(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_1(void *)164*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_1(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_2(void *)165*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_2(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_3(void *)166*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_3(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_4(void *)167*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_4(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_5(void *)168*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_5(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_6(void *)169*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_6(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_7(void *)170*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_7(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_8(void *)171*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_8(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_9(void *)172*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_9(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_10(void *)173*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_10(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_11(void *)174*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_11(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_12(void *)175*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_12(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_13(void *)176*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_13(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_14(void *)177*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_14(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_15(void *)178*fb16552fSMaurice Kalinowski status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_15(void *) {return B_ERROR;};
179