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