xref: /haiku/src/add-ons/media/media-add-ons/reader/MediaReaderAddOn.cpp (revision bcf291ed9b7e872a4b60160de829153188a8ea2f)
1 // MediaReaderAddOn.cpp
2 //
3 // Andrew Bachmann, 2002
4 //
5 // A MediaReaderAddOn is an add-on
6 // that can make MediaReader nodes
7 //
8 // MediaReader nodes read a file into a multistream
9 #include "MediaReader.h"
10 #include "MediaReaderAddOn.h"
11 #include "debug.h"
12 
13 #include <Errors.h>
14 #include <MediaAddOn.h>
15 #include <MediaDefs.h>
16 #include <MediaRoster.h>
17 #include <Mime.h>
18 #include <Node.h>
19 #include <StorageDefs.h>
20 
21 
22 #include <limits.h>
23 #include <stdio.h>
24 #include <string.h>
25 
26 
27 // instantiation function
make_media_addon(image_id image)28 extern "C" _EXPORT BMediaAddOn * make_media_addon(image_id image) {
29 	return new MediaReaderAddOn(image);
30 }
31 
32 
~MediaReaderAddOn()33 MediaReaderAddOn::~MediaReaderAddOn()
34 {
35 }
36 
37 
MediaReaderAddOn(image_id image)38 MediaReaderAddOn::MediaReaderAddOn(image_id image) :
39 	AbstractFileInterfaceAddOn(image)
40 {
41 	CALLED();
42 }
43 
44 
45 // -------------------------------------------------------- //
46 // BMediaAddOn impl
47 // -------------------------------------------------------- //
GetFlavorAt(int32 n,const flavor_info ** out_info)48 status_t MediaReaderAddOn::GetFlavorAt(
49 	int32 n,
50 	const flavor_info ** out_info)
51 {
52 	CALLED();
53 
54 	if (n != 0) {
55 		PRINT("\t<- B_BAD_INDEX\n");
56 		return B_BAD_INDEX;
57 	}
58 
59 	flavor_info * infos = new flavor_info[1];
60 	MediaReader::GetFlavor(&infos[0],n);
61 	(*out_info) = infos;
62 	return B_OK;
63 }
64 
65 
InstantiateNodeFor(const flavor_info * info,BMessage * config,status_t * out_error)66 BMediaNode * MediaReaderAddOn::InstantiateNodeFor(
67 				const flavor_info * info,
68 				BMessage * config,
69 				status_t * out_error)
70 {
71 	CALLED();
72 
73 	// XXX: read from add-on's attributes
74 	size_t defaultChunkSize = size_t(8192); // 8192 bytes = 8 Kilobytes
75 	// = 2048 kilobits/millisec = 256000 Kilobytes/sec
76 	float defaultBitRate = 2048;
77 	MediaReader * node
78 		= new MediaReader(defaultChunkSize,
79 						  defaultBitRate,
80 						  info,config,this);
81 	if (node == 0) {
82 		*out_error = B_NO_MEMORY;
83 		PRINT("\t<- B_NO_MEMORY\n");
84 	} else {
85 		*out_error = node->InitCheck();
86 	}
87 	return node;
88 }
89 
90 
GetConfigurationFor(BMediaNode * your_node,BMessage * into_message)91 status_t MediaReaderAddOn::GetConfigurationFor(
92 				BMediaNode * your_node,
93 				BMessage * into_message)
94 {
95 	CALLED();
96 
97 	MediaReader * node
98 		= dynamic_cast<MediaReader*>(your_node);
99 	if (node == 0) {
100 		fprintf(stderr,"<- B_BAD_TYPE\n");
101 		return B_BAD_TYPE;
102 	}
103 	return node->GetConfigurationFor(into_message);
104 }
105 
106 
107 // -------------------------------------------------------- //
108 // BMediaAddOn impl for B_FILE_INTERFACE nodes
109 // -------------------------------------------------------- //
110 
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)111 status_t MediaReaderAddOn::GetFileFormatList(
112 				int32 flavor_id,
113 				media_file_format * out_writable_formats,
114 				int32 in_write_items,
115 				int32 * out_write_items,
116 				media_file_format * out_readable_formats,
117 				int32 in_read_items,
118 				int32 * out_read_items,
119 				void * _reserved)
120 {
121 	CALLED();
122 
123 	if (flavor_id != 0) {
124 		// this is a sanity check for now
125 		PRINT("\t<- B_BAD_INDEX\n");
126 		return B_BAD_INDEX;
127 	}
128 		// don't go off the end
129 		if (in_read_items > 0) {
130 			MediaReader::GetFileFormat(&out_readable_formats[0]);
131 		}
132 	return B_OK;
133 }
134 
135 
SniffTypeKind(const BMimeType & type,uint64 in_kinds,float * out_quality,int32 * out_internal_id,void * _reserved)136 status_t MediaReaderAddOn::SniffTypeKind(
137 				const BMimeType & type,
138 				uint64 in_kinds,
139 				float * out_quality,
140 				int32 * out_internal_id,
141 				void * _reserved)
142 {
143 	CALLED();
144 	return AbstractFileInterfaceAddOn::SniffTypeKind(type,in_kinds,
145 													 B_BUFFER_PRODUCER,
146 													 out_quality,out_internal_id,
147 													 _reserved);
148 }
149 
150 // -------------------------------------------------------- //
151 // main
152 // -------------------------------------------------------- //
main(int argc,char * argv[])153 int main(int argc, char *argv[])
154 {
155 	fprintf(stderr,"main called for MediaReaderAddOn\n");
156 	return 0;
157 }
158 
159 // -------------------------------------------------------- //
160 // stuffing
161 // -------------------------------------------------------- //
162 
_Reserved_MediaReaderAddOn_0(void *)163 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_0(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_1(void *)164 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_1(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_2(void *)165 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_2(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_3(void *)166 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_3(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_4(void *)167 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_4(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_5(void *)168 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_5(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_6(void *)169 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_6(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_7(void *)170 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_7(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_8(void *)171 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_8(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_9(void *)172 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_9(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_10(void *)173 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_10(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_11(void *)174 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_11(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_12(void *)175 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_12(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_13(void *)176 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_13(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_14(void *)177 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_14(void *) {return B_ERROR;};
_Reserved_MediaReaderAddOn_15(void *)178 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_15(void *) {return B_ERROR;};
179