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 28 extern "C" _EXPORT BMediaAddOn * make_media_addon(image_id image) { 29 return new MediaReaderAddOn(image); 30 } 31 32 33 MediaReaderAddOn::~MediaReaderAddOn() 34 { 35 } 36 37 38 MediaReaderAddOn::MediaReaderAddOn(image_id image) : 39 AbstractFileInterfaceAddOn(image) 40 { 41 CALLED(); 42 } 43 44 45 // -------------------------------------------------------- // 46 // BMediaAddOn impl 47 // -------------------------------------------------------- // 48 status_t MediaReaderAddOn::GetFlavorAt( 49 int32 n, 50 const flavor_info ** out_info) 51 { 52 CALLED(); 53 54 if (out_info == 0) { 55 PRINT("\t<- B_BAD_VALUE\n"); 56 return B_BAD_VALUE; // avoid crash 57 } 58 if (n != 0) { 59 PRINT("\t<- B_BAD_INDEX\n"); 60 return B_BAD_INDEX; 61 } 62 63 flavor_info * infos = new flavor_info[1]; 64 MediaReader::GetFlavor(&infos[0],n); 65 (*out_info) = infos; 66 return B_OK; 67 } 68 69 70 BMediaNode * MediaReaderAddOn::InstantiateNodeFor( 71 const flavor_info * info, 72 BMessage * config, 73 status_t * out_error) 74 { 75 CALLED(); 76 77 if (out_error == 0) { 78 PRINT("\t<- NULL\n"); 79 return 0; // avoid crash 80 } 81 82 // XXX: read from add-on's attributes 83 size_t defaultChunkSize = size_t(8192); // 8192 bytes = 8 Kilobytes 84 // = 2048 kilobits/millisec = 256000 Kilobytes/sec 85 float defaultBitRate = 2048; 86 MediaReader * node 87 = new MediaReader(defaultChunkSize, 88 defaultBitRate, 89 info,config,this); 90 if (node == 0) { 91 *out_error = B_NO_MEMORY; 92 PRINT("\t<- B_NO_MEMORY\n"); 93 } else { 94 *out_error = node->InitCheck(); 95 } 96 return node; 97 } 98 99 100 status_t MediaReaderAddOn::GetConfigurationFor( 101 BMediaNode * your_node, 102 BMessage * into_message) 103 { 104 CALLED(); 105 106 if (into_message == 0) { 107 PRINT("\t<- B_BAD_VALUE\n"); 108 return B_BAD_VALUE; // avoid crash 109 } 110 111 MediaReader * node 112 = dynamic_cast<MediaReader*>(your_node); 113 if (node == 0) { 114 fprintf(stderr,"<- B_BAD_TYPE\n"); 115 return B_BAD_TYPE; 116 } 117 return node->GetConfigurationFor(into_message); 118 } 119 120 121 // -------------------------------------------------------- // 122 // BMediaAddOn impl for B_FILE_INTERFACE nodes 123 // -------------------------------------------------------- // 124 125 // This function treats null pointers slightly differently than the others. 126 // This is because a program could reasonably call this function with just 127 // about any junk, get the out_read_items or out_write_items and then use 128 // that to create an array of sufficient size to hold the result, and then 129 // call us again. So we won't punish them if they supply us with null 130 // pointers the first time around. 131 // 132 // A stupid program might not supply an out_read_items, but actually supply 133 // an out_readable_formats and then try to do something useful with it. As 134 // an extreme gesture of nicety we will fill the out_readable_formats with 135 // a valid entry, although they could easily read into garbage after that... 136 status_t MediaReaderAddOn::GetFileFormatList( 137 int32 flavor_id, 138 media_file_format * out_writable_formats, 139 int32 in_write_items, 140 int32 * out_write_items, 141 media_file_format * out_readable_formats, 142 int32 in_read_items, 143 int32 * out_read_items, 144 void * _reserved) 145 { 146 CALLED(); 147 148 if (flavor_id != 0) { 149 // this is a sanity check for now 150 PRINT("\t<- B_BAD_INDEX\n"); 151 return B_BAD_INDEX; 152 } 153 // see null check comment above 154 if (out_write_items != 0) { 155 *out_write_items = 0; 156 } 157 // see null check comment above 158 if (out_read_items != 0) { 159 *out_read_items = 1; 160 } 161 if (out_readable_formats != 0) { 162 // don't go off the end 163 if (in_read_items > 0) { 164 MediaReader::GetFileFormat(&out_readable_formats[0]); 165 } 166 } 167 return B_OK; 168 } 169 170 171 status_t MediaReaderAddOn::SniffTypeKind( 172 const BMimeType & type, 173 uint64 in_kinds, 174 float * out_quality, 175 int32 * out_internal_id, 176 void * _reserved) 177 { 178 CALLED(); 179 return AbstractFileInterfaceAddOn::SniffTypeKind(type,in_kinds, 180 B_BUFFER_PRODUCER, 181 out_quality,out_internal_id, 182 _reserved); 183 } 184 185 // -------------------------------------------------------- // 186 // main 187 // -------------------------------------------------------- // 188 int main(int argc, char *argv[]) 189 { 190 fprintf(stderr,"main called for MediaReaderAddOn\n"); 191 return 0; 192 } 193 194 // -------------------------------------------------------- // 195 // stuffing 196 // -------------------------------------------------------- // 197 198 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_0(void *) {return B_ERROR;}; 199 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_1(void *) {return B_ERROR;}; 200 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_2(void *) {return B_ERROR;}; 201 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_3(void *) {return B_ERROR;}; 202 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_4(void *) {return B_ERROR;}; 203 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_5(void *) {return B_ERROR;}; 204 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_6(void *) {return B_ERROR;}; 205 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_7(void *) {return B_ERROR;}; 206 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_8(void *) {return B_ERROR;}; 207 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_9(void *) {return B_ERROR;}; 208 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_10(void *) {return B_ERROR;}; 209 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_11(void *) {return B_ERROR;}; 210 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_12(void *) {return B_ERROR;}; 211 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_13(void *) {return B_ERROR;}; 212 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_14(void *) {return B_ERROR;}; 213 status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_15(void *) {return B_ERROR;}; 214