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 } 61*ca6f35b1Sshatty flavor_info * infos = new flavor_info[1]; 62*ca6f35b1Sshatty MediaReader::GetFlavor(&infos[0],n); 63*ca6f35b1Sshatty (*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 } 77820c41b9Sshatty size_t defaultChunkSize = size_t(8192); // XXX: read from add-on's attributes 78820c41b9Sshatty float defaultBitRate = 800000; 79794887f8Sshatty MediaReader * node 80794887f8Sshatty = new MediaReader(defaultChunkSize, 81820c41b9Sshatty defaultBitRate, 82820c41b9Sshatty info,config,this); 83820c41b9Sshatty if (node == 0) { 84820c41b9Sshatty *out_error = B_NO_MEMORY; 85820c41b9Sshatty fprintf(stderr,"<- B_NO_MEMORY\n"); 86820c41b9Sshatty } else { 87820c41b9Sshatty *out_error = node->InitCheck(); 88820c41b9Sshatty } 89820c41b9Sshatty return node; 90820c41b9Sshatty } 91820c41b9Sshatty 92820c41b9Sshatty status_t MediaReaderAddOn::GetConfigurationFor( 93820c41b9Sshatty BMediaNode * your_node, 94820c41b9Sshatty BMessage * into_message) 95820c41b9Sshatty { 96820c41b9Sshatty fprintf(stderr,"MediaReaderAddOn::GetConfigurationFor\n"); 97820c41b9Sshatty if (into_message == 0) { 98820c41b9Sshatty fprintf(stderr,"<- B_BAD_VALUE\n"); 99820c41b9Sshatty return B_BAD_VALUE; // we refuse to crash because you were stupid 100820c41b9Sshatty } 101794887f8Sshatty MediaReader * node 102794887f8Sshatty = dynamic_cast<MediaReader*>(your_node); 103820c41b9Sshatty if (node == 0) { 104820c41b9Sshatty fprintf(stderr,"<- B_BAD_TYPE\n"); 105820c41b9Sshatty return B_BAD_TYPE; 106820c41b9Sshatty } 107820c41b9Sshatty return node->GetConfigurationFor(into_message); 108820c41b9Sshatty } 109820c41b9Sshatty 110820c41b9Sshatty // -------------------------------------------------------- // 111820c41b9Sshatty // BMediaAddOn impl for B_FILE_INTERFACE nodes 112820c41b9Sshatty // -------------------------------------------------------- // 113820c41b9Sshatty 114820c41b9Sshatty // This function treats null pointers slightly differently than the others. 115820c41b9Sshatty // This is because a program could reasonably call this function with just 116794887f8Sshatty // about any junk, get the out_read_items or out_write_items and then use 117794887f8Sshatty // that to create an array of sufficient size to hold the result, and then 118794887f8Sshatty // call us again. So we won't punish them if they supply us with null 119794887f8Sshatty // pointers the first time around. 120794887f8Sshatty // 121794887f8Sshatty // A stupid program might not supply an out_read_items, but actually supply 122820c41b9Sshatty // an out_readable_formats and then try to do something useful with it. As 123820c41b9Sshatty // an extreme gesture of nicety we will fill the out_readable_formats with 124820c41b9Sshatty // a valid entry, although they could easily read into garbage after that... 125820c41b9Sshatty status_t MediaReaderAddOn::GetFileFormatList( 126820c41b9Sshatty int32 flavor_id, 127820c41b9Sshatty media_file_format * out_writable_formats, 128820c41b9Sshatty int32 in_write_items, 129820c41b9Sshatty int32 * out_write_items, 130820c41b9Sshatty media_file_format * out_readable_formats, 131820c41b9Sshatty int32 in_read_items, 132820c41b9Sshatty int32 * out_read_items, 133820c41b9Sshatty void * _reserved) 134820c41b9Sshatty { 135820c41b9Sshatty fprintf(stderr,"MediaReaderAddOn::GetFileFormatList\n"); 136820c41b9Sshatty if (flavor_id != 0) { 137820c41b9Sshatty // this is a sanity check for now 138820c41b9Sshatty fprintf(stderr,"<- B_BAD_INDEX\n"); 139820c41b9Sshatty return B_BAD_INDEX; 140820c41b9Sshatty } 141820c41b9Sshatty // see null check comment above 142820c41b9Sshatty if (out_write_items != 0) { 143820c41b9Sshatty *out_write_items = 0; 144820c41b9Sshatty } 145820c41b9Sshatty // see null check comment above 146820c41b9Sshatty if (out_read_items != 0) { 147820c41b9Sshatty *out_read_items = 1; 148820c41b9Sshatty } 149820c41b9Sshatty if (out_readable_formats != 0) { 150820c41b9Sshatty // don't go off the end 151820c41b9Sshatty if (in_read_items > 0) { 152794887f8Sshatty out_readable_formats[0] = *MediaReader::GetFileFormat(); 153820c41b9Sshatty } 154820c41b9Sshatty } 155820c41b9Sshatty return B_OK; 156820c41b9Sshatty } 157820c41b9Sshatty 158820c41b9Sshatty status_t MediaReaderAddOn::SniffTypeKind( 159820c41b9Sshatty const BMimeType & type, 160820c41b9Sshatty uint64 in_kinds, 161820c41b9Sshatty float * out_quality, 162820c41b9Sshatty int32 * out_internal_id, 163820c41b9Sshatty void * _reserved) 164820c41b9Sshatty { 165820c41b9Sshatty fprintf(stderr,"MediaReaderAddOn::SniffTypeKind\n"); 166794887f8Sshatty return AbstractFileInterfaceAddOn::SniffTypeKind(type,in_kinds, 167794887f8Sshatty B_BUFFER_PRODUCER, 168794887f8Sshatty out_quality,out_internal_id, 169794887f8Sshatty _reserved); 170820c41b9Sshatty } 171820c41b9Sshatty 172820c41b9Sshatty // -------------------------------------------------------- // 173820c41b9Sshatty // stuffing 174820c41b9Sshatty // -------------------------------------------------------- // 175820c41b9Sshatty 176820c41b9Sshatty int main(int argc, char *argv[]) 177820c41b9Sshatty { 178820c41b9Sshatty 179820c41b9Sshatty } 180820c41b9Sshatty 181820c41b9Sshatty // -------------------------------------------------------- // 182820c41b9Sshatty // stuffing 183820c41b9Sshatty // -------------------------------------------------------- // 184820c41b9Sshatty 185820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_0(void *) {}; 186820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_1(void *) {}; 187820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_2(void *) {}; 188820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_3(void *) {}; 189820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_4(void *) {}; 190820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_5(void *) {}; 191820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_6(void *) {}; 192820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_7(void *) {}; 193820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_8(void *) {}; 194820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_9(void *) {}; 195820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_10(void *) {}; 196820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_11(void *) {}; 197820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_12(void *) {}; 198820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_13(void *) {}; 199820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_14(void *) {}; 200820c41b9Sshatty status_t MediaReaderAddOn::_Reserved_MediaReaderAddOn_15(void *) {}; 201