1255a01c7Sbeveloper /*
2eb5b2f6fSMarcus Overhagen * Copyright (c) 2002, 2003, 2008 Marcus Overhagen <Marcus@Overhagen.de>
3255a01c7Sbeveloper *
4255a01c7Sbeveloper * Permission is hereby granted, free of charge, to any person obtaining
5255a01c7Sbeveloper * a copy of this software and associated documentation files or portions
6255a01c7Sbeveloper * thereof (the "Software"), to deal in the Software without restriction,
7255a01c7Sbeveloper * including without limitation the rights to use, copy, modify, merge,
8255a01c7Sbeveloper * publish, distribute, sublicense, and/or sell copies of the Software,
9255a01c7Sbeveloper * and to permit persons to whom the Software is furnished to do so, subject
10255a01c7Sbeveloper * to the following conditions:
11255a01c7Sbeveloper *
12255a01c7Sbeveloper * * Redistributions of source code must retain the above copyright notice,
13255a01c7Sbeveloper * this list of conditions and the following disclaimer.
14255a01c7Sbeveloper *
15255a01c7Sbeveloper * * Redistributions in binary form must reproduce the above copyright notice
16255a01c7Sbeveloper * in the binary, as well as this list of conditions and the following
17255a01c7Sbeveloper * disclaimer in the documentation and/or other materials provided with
18255a01c7Sbeveloper * the distribution.
19255a01c7Sbeveloper *
20255a01c7Sbeveloper * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21255a01c7Sbeveloper * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22255a01c7Sbeveloper * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23255a01c7Sbeveloper * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24255a01c7Sbeveloper * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25255a01c7Sbeveloper * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26255a01c7Sbeveloper * THE SOFTWARE.
27255a01c7Sbeveloper *
28255a01c7Sbeveloper */
29255a01c7Sbeveloper
30d4708399SAxel Dörfler
3152a38012Sejakowatz #include <MediaAddOn.h>
3252a38012Sejakowatz #include <string.h>
336e927a5fSIngo Weinhold #include <stdlib.h>
34eb5b2f6fSMarcus Overhagen #include <new>
35b84955d4SBarrett17 #include "MediaDebug.h"
36dfb2ad61Sbeveloper #include "DataExchange.h"
3752a38012Sejakowatz
3852a38012Sejakowatz
39d4708399SAxel Dörfler #define MAX_FLAVOR_IN_FORMAT_COUNT 300
40d4708399SAxel Dörfler #define MAX_FLAVOR_OUT_FORMAT_COUNT 300
41d4708399SAxel Dörfler
42d4708399SAxel Dörfler #define FLATTEN_MAGIC 'CODE'
43d4708399SAxel Dörfler #define FLATTEN_TYPECODE 'DFIT'
44d4708399SAxel Dörfler
45d4708399SAxel Dörfler
46d4708399SAxel Dörfler static char *
_newstrdup(const char * str)47d4708399SAxel Dörfler _newstrdup(const char *str)
4852a38012Sejakowatz {
4952a38012Sejakowatz if (str == NULL)
5052a38012Sejakowatz return NULL;
5152a38012Sejakowatz int len = strlen(str) + 1;
52eb5b2f6fSMarcus Overhagen char *p = new(std::nothrow) char[len];
53eb5b2f6fSMarcus Overhagen if (p)
5452a38012Sejakowatz memcpy(p, str, len);
5552a38012Sejakowatz return p;
5652a38012Sejakowatz }
5752a38012Sejakowatz
58eb5b2f6fSMarcus Overhagen
59d4708399SAxel Dörfler // #pragma mark - dormant_node_info
6052a38012Sejakowatz
6152a38012Sejakowatz
dormant_node_info()6252a38012Sejakowatz dormant_node_info::dormant_node_info()
63d4708399SAxel Dörfler :
64d4708399SAxel Dörfler addon(-1),
6552a38012Sejakowatz flavor_id(-1)
6652a38012Sejakowatz {
6752a38012Sejakowatz name[0] = '\0';
6852a38012Sejakowatz }
6952a38012Sejakowatz
70d4708399SAxel Dörfler
~dormant_node_info()7152a38012Sejakowatz dormant_node_info::~dormant_node_info()
7252a38012Sejakowatz {
7352a38012Sejakowatz }
7452a38012Sejakowatz
75d4708399SAxel Dörfler
76d4708399SAxel Dörfler // #pragma mark - flavor_info
77d4708399SAxel Dörfler
7852a38012Sejakowatz
7952a38012Sejakowatz /* DO NOT IMPLEMENT */
8052a38012Sejakowatz /*
8152a38012Sejakowatz flavor_info &flavor_info::operator=(const flavor_info &other)
8252a38012Sejakowatz */
8352a38012Sejakowatz
8452a38012Sejakowatz
85d4708399SAxel Dörfler // #pragma mark - dormant_flavor_info
86d4708399SAxel Dörfler
87d4708399SAxel Dörfler
dormant_flavor_info()8852a38012Sejakowatz dormant_flavor_info::dormant_flavor_info()
8952a38012Sejakowatz {
90d4708399SAxel Dörfler name = NULL;
91d4708399SAxel Dörfler info = NULL;
9252a38012Sejakowatz kinds = 0;
9352a38012Sejakowatz flavor_flags = 0;
9452a38012Sejakowatz internal_id = 0;
9552a38012Sejakowatz possible_count = 0;
9652a38012Sejakowatz in_format_count = 0;
9752a38012Sejakowatz in_format_flags = 0;
98d4708399SAxel Dörfler in_formats = NULL;
9952a38012Sejakowatz out_format_count = 0;
10052a38012Sejakowatz out_format_flags = 0;
101d4708399SAxel Dörfler out_formats = NULL;
10252a38012Sejakowatz }
10352a38012Sejakowatz
10452a38012Sejakowatz
~dormant_flavor_info()10552a38012Sejakowatz dormant_flavor_info::~dormant_flavor_info()
10652a38012Sejakowatz {
10752a38012Sejakowatz delete[] name;
10852a38012Sejakowatz delete[] info;
10952a38012Sejakowatz delete[] in_formats;
11052a38012Sejakowatz delete[] out_formats;
11152a38012Sejakowatz }
11252a38012Sejakowatz
11352a38012Sejakowatz
dormant_flavor_info(const dormant_flavor_info & clone)11452a38012Sejakowatz dormant_flavor_info::dormant_flavor_info(const dormant_flavor_info &clone)
11552a38012Sejakowatz {
116d4708399SAxel Dörfler name = NULL;
117d4708399SAxel Dörfler info = NULL;
118d4708399SAxel Dörfler in_formats = NULL;
119d4708399SAxel Dörfler out_formats = NULL;
120d4708399SAxel Dörfler
12152a38012Sejakowatz *this = clone;
12252a38012Sejakowatz }
12352a38012Sejakowatz
12452a38012Sejakowatz
12552a38012Sejakowatz dormant_flavor_info &
operator =(const dormant_flavor_info & clone)12652a38012Sejakowatz dormant_flavor_info::operator=(const dormant_flavor_info &clone)
12752a38012Sejakowatz {
1287d3a9826Sbeveloper // call operator=(const flavor_info &clone) to copy the flavor_info base class
1297d3a9826Sbeveloper *this = static_cast<const flavor_info>(clone);
1307d3a9826Sbeveloper // copy the dormant_node_info member variable
13152a38012Sejakowatz node_info = clone.node_info;
13252a38012Sejakowatz return *this;
13352a38012Sejakowatz }
13452a38012Sejakowatz
13552a38012Sejakowatz
13652a38012Sejakowatz dormant_flavor_info &
operator =(const flavor_info & clone)13752a38012Sejakowatz dormant_flavor_info::operator=(const flavor_info &clone)
13852a38012Sejakowatz {
13952a38012Sejakowatz kinds = clone.kinds;
14052a38012Sejakowatz flavor_flags = clone.flavor_flags;
14152a38012Sejakowatz internal_id = clone.internal_id;
14252a38012Sejakowatz possible_count = clone.possible_count;
14352a38012Sejakowatz
144eb5b2f6fSMarcus Overhagen delete [] info;
145eb5b2f6fSMarcus Overhagen info = _newstrdup(clone.info);
14652a38012Sejakowatz
147eb5b2f6fSMarcus Overhagen delete [] name;
148eb5b2f6fSMarcus Overhagen name = _newstrdup(clone.name);
149eb5b2f6fSMarcus Overhagen
150eb5b2f6fSMarcus Overhagen delete [] in_formats;
151d4708399SAxel Dörfler in_formats = NULL;
152eb5b2f6fSMarcus Overhagen in_format_count = 0;
153eb5b2f6fSMarcus Overhagen in_format_flags = clone.in_format_flags;
154d4708399SAxel Dörfler if ((kinds & B_BUFFER_CONSUMER) != 0) {
155d4708399SAxel Dörfler if (clone.in_format_count >= 0
156d4708399SAxel Dörfler && clone.in_format_count <= MAX_FLAVOR_IN_FORMAT_COUNT) {
157eb5b2f6fSMarcus Overhagen in_formats = new(std::nothrow) media_format[clone.in_format_count];
158eb5b2f6fSMarcus Overhagen if (in_formats != NULL && clone.in_formats != NULL) {
159eb5b2f6fSMarcus Overhagen in_format_count = clone.in_format_count;
160d4708399SAxel Dörfler for (int i = 0; i < in_format_count; i++) {
161d4708399SAxel Dörfler const_cast<media_format &>(in_formats[i])
162d4708399SAxel Dörfler = clone.in_formats[i];
16352a38012Sejakowatz }
164d4708399SAxel Dörfler }
165d4708399SAxel Dörfler } else {
166d4708399SAxel Dörfler fprintf(stderr, "error: dormant_flavor_info::operator= clone.in_"
167d4708399SAxel Dörfler "format_count is invalid\n");
168d4708399SAxel Dörfler }
169d4708399SAxel Dörfler } else if (clone.in_format_count) {
170d4708399SAxel Dörfler fprintf(stderr, "warning: dormant_flavor_info::operator= not "
171d4708399SAxel Dörfler "B_BUFFER_CONSUMER and clone.in_format_count is != 0\n");
172d4708399SAxel Dörfler }
17352a38012Sejakowatz
174eb5b2f6fSMarcus Overhagen delete [] out_formats;
175d4708399SAxel Dörfler out_formats = NULL;
176eb5b2f6fSMarcus Overhagen out_format_count = 0;
177eb5b2f6fSMarcus Overhagen out_format_flags = clone.out_format_flags;
178eb5b2f6fSMarcus Overhagen if (kinds & B_BUFFER_PRODUCER) {
179d4708399SAxel Dörfler if (clone.out_format_count >= 0
180d4708399SAxel Dörfler && clone.out_format_count <= MAX_FLAVOR_OUT_FORMAT_COUNT) {
181eb5b2f6fSMarcus Overhagen out_formats = new(std::nothrow) media_format[clone.out_format_count];
182eb5b2f6fSMarcus Overhagen if (out_formats != NULL && clone.out_formats != NULL) {
183eb5b2f6fSMarcus Overhagen out_format_count = clone.out_format_count;
184d4708399SAxel Dörfler for (int i = 0; i < out_format_count; i++) {
185d4708399SAxel Dörfler const_cast<media_format &>(out_formats[i])
186d4708399SAxel Dörfler = clone.out_formats[i];
18752a38012Sejakowatz }
188d4708399SAxel Dörfler }
189d4708399SAxel Dörfler } else {
190d4708399SAxel Dörfler fprintf(stderr, "error dormant_flavor_info::operator= clone.out_"
191d4708399SAxel Dörfler "format_count is invalid\n");
192d4708399SAxel Dörfler }
193d4708399SAxel Dörfler } else if (clone.out_format_count) {
194d4708399SAxel Dörfler fprintf(stderr, "warning: dormant_flavor_info::operator= not "
195d4708399SAxel Dörfler "B_BUFFER_PRODUCER and clone.out_format_count is != 0\n");
196d4708399SAxel Dörfler }
19752a38012Sejakowatz
198d4708399SAxel Dörfler // initialize node_info with default values
199eb5b2f6fSMarcus Overhagen dormant_node_info defaultValues;
200eb5b2f6fSMarcus Overhagen node_info = defaultValues;
20152a38012Sejakowatz
20252a38012Sejakowatz return *this;
20352a38012Sejakowatz }
20452a38012Sejakowatz
20552a38012Sejakowatz
20652a38012Sejakowatz void
set_name(const char * newName)207d4708399SAxel Dörfler dormant_flavor_info::set_name(const char *newName)
20852a38012Sejakowatz {
20952a38012Sejakowatz delete[] name;
210d4708399SAxel Dörfler name = _newstrdup(newName);
21152a38012Sejakowatz }
21252a38012Sejakowatz
21352a38012Sejakowatz
21452a38012Sejakowatz void
set_info(const char * newInfo)215d4708399SAxel Dörfler dormant_flavor_info::set_info(const char *newInfo)
21652a38012Sejakowatz {
21752a38012Sejakowatz delete[] info;
218d4708399SAxel Dörfler info = _newstrdup(newInfo);
21952a38012Sejakowatz }
22052a38012Sejakowatz
22152a38012Sejakowatz
22252a38012Sejakowatz void
add_in_format(const media_format & in_format)22352a38012Sejakowatz dormant_flavor_info::add_in_format(const media_format &in_format)
22452a38012Sejakowatz {
225eb5b2f6fSMarcus Overhagen media_format *p = new(std::nothrow) media_format[in_format_count + 1];
226eb5b2f6fSMarcus Overhagen if (p) {
22752a38012Sejakowatz for (int i = 0; i < in_format_count; i++)
228eb5b2f6fSMarcus Overhagen p[i] = in_formats[i];
229eb5b2f6fSMarcus Overhagen p[in_format_count] = in_format;
23052a38012Sejakowatz delete [] in_formats;
231eb5b2f6fSMarcus Overhagen in_formats = p;
23252a38012Sejakowatz in_format_count += 1;
233eb5b2f6fSMarcus Overhagen }
23452a38012Sejakowatz }
23552a38012Sejakowatz
23652a38012Sejakowatz
23752a38012Sejakowatz void
add_out_format(const media_format & out_format)23852a38012Sejakowatz dormant_flavor_info::add_out_format(const media_format &out_format)
23952a38012Sejakowatz {
240eb5b2f6fSMarcus Overhagen media_format *p = new(std::nothrow) media_format[out_format_count + 1];
241eb5b2f6fSMarcus Overhagen if (p) {
24252a38012Sejakowatz for (int i = 0; i < out_format_count; i++)
243eb5b2f6fSMarcus Overhagen p[i] = out_formats[i];
244eb5b2f6fSMarcus Overhagen p[out_format_count] = out_format;
24552a38012Sejakowatz delete [] out_formats;
246eb5b2f6fSMarcus Overhagen out_formats = p;
24752a38012Sejakowatz out_format_count += 1;
248eb5b2f6fSMarcus Overhagen }
24952a38012Sejakowatz }
25052a38012Sejakowatz
25152a38012Sejakowatz
252d4708399SAxel Dörfler bool
IsFixedSize() const25352a38012Sejakowatz dormant_flavor_info::IsFixedSize() const
25452a38012Sejakowatz {
25552a38012Sejakowatz return false;
25652a38012Sejakowatz }
25752a38012Sejakowatz
25852a38012Sejakowatz
259d4708399SAxel Dörfler type_code
TypeCode() const26052a38012Sejakowatz dormant_flavor_info::TypeCode() const
26152a38012Sejakowatz {
26252a38012Sejakowatz return FLATTEN_TYPECODE;
26352a38012Sejakowatz }
26452a38012Sejakowatz
26552a38012Sejakowatz
266d4708399SAxel Dörfler ssize_t
FlattenedSize() const26752a38012Sejakowatz dormant_flavor_info::FlattenedSize() const
26852a38012Sejakowatz {
26952a38012Sejakowatz ssize_t size = 0;
27052a38012Sejakowatz // magic
27152a38012Sejakowatz size += sizeof(int32);
27252a38012Sejakowatz // size
27352a38012Sejakowatz size += sizeof(int32);
27452a38012Sejakowatz // struct flavor_info
27552a38012Sejakowatz size += sizeof(int32) + strlen(name);
27652a38012Sejakowatz size += sizeof(int32) + strlen(info);
27752a38012Sejakowatz size += sizeof(kinds);
27852a38012Sejakowatz size += sizeof(flavor_flags);
27952a38012Sejakowatz size += sizeof(internal_id);
28052a38012Sejakowatz size += sizeof(possible_count);
28152a38012Sejakowatz size += sizeof(in_format_count);
28252a38012Sejakowatz size += sizeof(in_format_flags);
283d4708399SAxel Dörfler if (in_format_count > 0 && in_format_count <= MAX_FLAVOR_IN_FORMAT_COUNT
284d4708399SAxel Dörfler && in_formats != NULL)
28552a38012Sejakowatz size += in_format_count * sizeof(media_format);
28652a38012Sejakowatz size += sizeof(out_format_count);
28752a38012Sejakowatz size += sizeof(out_format_flags);
288d4708399SAxel Dörfler if (out_format_count > 0 && out_format_count <= MAX_FLAVOR_OUT_FORMAT_COUNT
289d4708399SAxel Dörfler && out_formats != NULL)
29052a38012Sejakowatz size += out_format_count * sizeof(media_format);
29152a38012Sejakowatz // struct dormant_node_info node_info
29252a38012Sejakowatz size += sizeof(node_info);
29352a38012Sejakowatz
29452a38012Sejakowatz return size;
29552a38012Sejakowatz }
29652a38012Sejakowatz
29752a38012Sejakowatz
298d4708399SAxel Dörfler status_t
Flatten(void * buffer,ssize_t size) const299d4708399SAxel Dörfler dormant_flavor_info::Flatten(void *buffer, ssize_t size) const
30052a38012Sejakowatz {
30152a38012Sejakowatz if (size < FlattenedSize())
30252a38012Sejakowatz return B_ERROR;
30352a38012Sejakowatz
30452a38012Sejakowatz char *buf = (char *)buffer;
305eb5b2f6fSMarcus Overhagen int32 nameLength = name ? (int32)strlen(name) : -1;
306eb5b2f6fSMarcus Overhagen int32 infoLength = info ? (int32)strlen(info) : -1;
307eb5b2f6fSMarcus Overhagen int32 inFormatCount = 0;
308eb5b2f6fSMarcus Overhagen size_t inFormatSize = 0;
309eb5b2f6fSMarcus Overhagen int32 outFormatCount = 0;
310eb5b2f6fSMarcus Overhagen size_t outFormatSize = 0;
311eb5b2f6fSMarcus Overhagen
312d4708399SAxel Dörfler if ((kinds & B_BUFFER_CONSUMER) != 0 && in_format_count > 0
313d4708399SAxel Dörfler && in_formats != NULL) {
314eb5b2f6fSMarcus Overhagen if (in_format_count <= MAX_FLAVOR_IN_FORMAT_COUNT) {
315eb5b2f6fSMarcus Overhagen inFormatCount = in_format_count;
316eb5b2f6fSMarcus Overhagen inFormatSize = in_format_count * sizeof(media_format);
317eb5b2f6fSMarcus Overhagen } else {
318d4708399SAxel Dörfler fprintf(stderr, "error dormant_flavor_info::Flatten: "
319d4708399SAxel Dörfler "in_format_count is too large\n");
320eb5b2f6fSMarcus Overhagen return B_ERROR;
321eb5b2f6fSMarcus Overhagen }
322eb5b2f6fSMarcus Overhagen }
323eb5b2f6fSMarcus Overhagen
324d4708399SAxel Dörfler if ((kinds & B_BUFFER_PRODUCER) != 0 && out_format_count > 0
325d4708399SAxel Dörfler && out_formats != NULL) {
326eb5b2f6fSMarcus Overhagen if (out_format_count <= MAX_FLAVOR_OUT_FORMAT_COUNT) {
327eb5b2f6fSMarcus Overhagen outFormatCount = out_format_count;
328eb5b2f6fSMarcus Overhagen outFormatSize = out_format_count * sizeof(media_format);
329eb5b2f6fSMarcus Overhagen } else {
330d4708399SAxel Dörfler fprintf(stderr, "error dormant_flavor_info::Flatten: "
331d4708399SAxel Dörfler "out_format_count is too large\n");
332eb5b2f6fSMarcus Overhagen return B_ERROR;
333eb5b2f6fSMarcus Overhagen }
334eb5b2f6fSMarcus Overhagen }
33552a38012Sejakowatz
33652a38012Sejakowatz // magic
33752a38012Sejakowatz *(int32*)buf = FLATTEN_MAGIC; buf += sizeof(int32);
33852a38012Sejakowatz
33952a38012Sejakowatz // size
34052a38012Sejakowatz *(int32*)buf = FlattenedSize(); buf += sizeof(int32);
34152a38012Sejakowatz
34252a38012Sejakowatz // struct flavor_info
343eb5b2f6fSMarcus Overhagen *(int32*)buf = nameLength; buf += sizeof(int32);
344eb5b2f6fSMarcus Overhagen if (nameLength > 0) {
345eb5b2f6fSMarcus Overhagen memcpy(buf, name, nameLength);
346eb5b2f6fSMarcus Overhagen buf += nameLength;
34752a38012Sejakowatz }
348eb5b2f6fSMarcus Overhagen *(int32*)buf = infoLength; buf += sizeof(int32);
349eb5b2f6fSMarcus Overhagen if (infoLength > 0) {
350eb5b2f6fSMarcus Overhagen memcpy(buf, info, infoLength);
351eb5b2f6fSMarcus Overhagen buf += infoLength;
35252a38012Sejakowatz }
35352a38012Sejakowatz
35452a38012Sejakowatz *(uint64*)buf = kinds; buf += sizeof(uint64);
35552a38012Sejakowatz *(uint32*)buf = flavor_flags; buf += sizeof(uint32);
35652a38012Sejakowatz *(int32*)buf = internal_id; buf += sizeof(int32);
35752a38012Sejakowatz *(int32*)buf = possible_count; buf += sizeof(int32);
358eb5b2f6fSMarcus Overhagen *(int32*)buf = inFormatCount; buf += sizeof(int32);
35952a38012Sejakowatz *(uint32*)buf = in_format_flags; buf += sizeof(uint32);
36052a38012Sejakowatz
36152a38012Sejakowatz // XXX FIXME! we should not!!! make flat copies of media_format
362eb5b2f6fSMarcus Overhagen memcpy(buf, in_formats, inFormatSize); buf += inFormatSize;
36352a38012Sejakowatz
364eb5b2f6fSMarcus Overhagen *(int32*)buf = outFormatCount; buf += sizeof(int32);
36552a38012Sejakowatz *(uint32*)buf = out_format_flags; buf += sizeof(uint32);
36652a38012Sejakowatz
36752a38012Sejakowatz // XXX FIXME! we should not!!! make flat copies of media_format
368eb5b2f6fSMarcus Overhagen memcpy(buf, out_formats, outFormatSize); buf += outFormatSize;
36952a38012Sejakowatz
37052a38012Sejakowatz *(dormant_node_info*)buf = node_info; buf += sizeof(dormant_node_info);
37152a38012Sejakowatz
37252a38012Sejakowatz return B_OK;
37352a38012Sejakowatz }
37452a38012Sejakowatz
37552a38012Sejakowatz
376d4708399SAxel Dörfler status_t
Unflatten(type_code c,const void * buffer,ssize_t size)377d4708399SAxel Dörfler dormant_flavor_info::Unflatten(type_code c, const void *buffer, ssize_t size)
37852a38012Sejakowatz {
37952a38012Sejakowatz if (c != FLATTEN_TYPECODE)
38052a38012Sejakowatz return B_ERROR;
38152a38012Sejakowatz if (size < 8)
38252a38012Sejakowatz return B_ERROR;
38352a38012Sejakowatz
38452a38012Sejakowatz const char *buf = (const char *)buffer;
385eb5b2f6fSMarcus Overhagen int32 nameLength;
386eb5b2f6fSMarcus Overhagen int32 infoLength;
38752a38012Sejakowatz
388eb5b2f6fSMarcus Overhagen // check magic
38952a38012Sejakowatz if (*(int32*)buf != FLATTEN_MAGIC)
39052a38012Sejakowatz return B_ERROR;
39152a38012Sejakowatz buf += sizeof(int32);
39252a38012Sejakowatz
393eb5b2f6fSMarcus Overhagen // check size
394eb5b2f6fSMarcus Overhagen if (*(uint32*)buf > (uint32)size)
39552a38012Sejakowatz return B_ERROR;
39652a38012Sejakowatz buf += sizeof(int32);
39752a38012Sejakowatz
39852a38012Sejakowatz delete[] name;
399eb5b2f6fSMarcus Overhagen name = NULL;
40052a38012Sejakowatz delete[] info;
401eb5b2f6fSMarcus Overhagen info = NULL;
40252a38012Sejakowatz delete[] in_formats;
403eb5b2f6fSMarcus Overhagen in_formats = NULL;
404eb5b2f6fSMarcus Overhagen in_format_count = 0;
40552a38012Sejakowatz delete[] out_formats;
406eb5b2f6fSMarcus Overhagen out_formats = NULL;
407eb5b2f6fSMarcus Overhagen out_format_count = 0;
40852a38012Sejakowatz
40952a38012Sejakowatz // struct flavor_info
410eb5b2f6fSMarcus Overhagen nameLength = *(int32*)buf; buf += sizeof(int32);
411eb5b2f6fSMarcus Overhagen if (nameLength >= 0) { // if nameLength is -1, we leave name = 0
412*fb5c24d8SAdrien Destugues char* nameStorage = new(std::nothrow) char [nameLength + 1];
413*fb5c24d8SAdrien Destugues name = nameStorage;
414*fb5c24d8SAdrien Destugues if (nameStorage) {
415*fb5c24d8SAdrien Destugues memcpy(nameStorage, buf, nameLength);
416*fb5c24d8SAdrien Destugues nameStorage[nameLength] = 0;
417eb5b2f6fSMarcus Overhagen buf += nameLength; // XXX not save
418eb5b2f6fSMarcus Overhagen }
41952a38012Sejakowatz }
42052a38012Sejakowatz
421eb5b2f6fSMarcus Overhagen infoLength = *(int32*)buf; buf += sizeof(int32);
422eb5b2f6fSMarcus Overhagen if (infoLength >= 0) { // if infoLength is -1, we leave info = 0
423*fb5c24d8SAdrien Destugues char* infoStorage = new(std::nothrow) char [infoLength + 1];
424*fb5c24d8SAdrien Destugues info = infoStorage;
425*fb5c24d8SAdrien Destugues if (infoStorage) {
426*fb5c24d8SAdrien Destugues memcpy(infoStorage, buf, infoLength);
427*fb5c24d8SAdrien Destugues infoStorage[infoLength] = 0;
428eb5b2f6fSMarcus Overhagen buf += infoLength; // XXX not save
42952a38012Sejakowatz }
430eb5b2f6fSMarcus Overhagen }
431eb5b2f6fSMarcus Overhagen
432eb5b2f6fSMarcus Overhagen int32 count;
43352a38012Sejakowatz
43452a38012Sejakowatz kinds = *(uint64*)buf; buf += sizeof(uint64);
43552a38012Sejakowatz flavor_flags = *(uint32*)buf; buf += sizeof(uint32);
43652a38012Sejakowatz internal_id = *(int32*)buf; buf += sizeof(int32);
43752a38012Sejakowatz possible_count = *(int32*)buf; buf += sizeof(int32);
438eb5b2f6fSMarcus Overhagen count = *(int32*)buf; buf += sizeof(int32);
43952a38012Sejakowatz in_format_flags = *(uint32*)buf; buf += sizeof(uint32);
44052a38012Sejakowatz
441eb5b2f6fSMarcus Overhagen if (count > 0) {
442eb5b2f6fSMarcus Overhagen if (count <= MAX_FLAVOR_IN_FORMAT_COUNT) {
443eb5b2f6fSMarcus Overhagen in_formats = new(std::nothrow) media_format[count];
444eb5b2f6fSMarcus Overhagen if (!in_formats)
445eb5b2f6fSMarcus Overhagen return B_NO_MEMORY;
446d4708399SAxel Dörfler // TODO: we should not!!! make flat copies of media_format
44712ed45b6SMurai Takashi for (int32 i = 0; i < count; i++) {
44812ed45b6SMurai Takashi const_cast<media_format*>
44912ed45b6SMurai Takashi (&in_formats[i])->Unflatten(buf);
45012ed45b6SMurai Takashi buf += sizeof(media_format); // TODO: not save
45112ed45b6SMurai Takashi }
452eb5b2f6fSMarcus Overhagen in_format_count = count;
453eb5b2f6fSMarcus Overhagen }
45452a38012Sejakowatz }
45552a38012Sejakowatz
456eb5b2f6fSMarcus Overhagen count = *(int32*)buf; buf += sizeof(int32);
45752a38012Sejakowatz out_format_flags = *(uint32*)buf; buf += sizeof(uint32);
45852a38012Sejakowatz
459eb5b2f6fSMarcus Overhagen if (count > 0) {
460eb5b2f6fSMarcus Overhagen if (count <= MAX_FLAVOR_OUT_FORMAT_COUNT) {
461eb5b2f6fSMarcus Overhagen out_formats = new(std::nothrow) media_format[count];
462eb5b2f6fSMarcus Overhagen if (!out_formats)
463eb5b2f6fSMarcus Overhagen return B_NO_MEMORY;
464d4708399SAxel Dörfler // TODO: we should not!!! make flat copies of media_format
46512ed45b6SMurai Takashi for (int32 i = 0; i < count; i++) {
46612ed45b6SMurai Takashi const_cast<media_format*>
46712ed45b6SMurai Takashi (&out_formats[i])->Unflatten(buf);
46812ed45b6SMurai Takashi buf += sizeof(media_format); // TODO: not save
46912ed45b6SMurai Takashi }
470eb5b2f6fSMarcus Overhagen out_format_count = count;
471eb5b2f6fSMarcus Overhagen }
47252a38012Sejakowatz }
47352a38012Sejakowatz
47452a38012Sejakowatz node_info = *(dormant_node_info*)buf; buf += sizeof(dormant_node_info);
47552a38012Sejakowatz
47652a38012Sejakowatz return B_OK;
47752a38012Sejakowatz }
47852a38012Sejakowatz
47952a38012Sejakowatz
480d4708399SAxel Dörfler // #pragma mark - BMediaAddOn
481d4708399SAxel Dörfler
482d4708399SAxel Dörfler
BMediaAddOn(image_id image)483d4708399SAxel Dörfler BMediaAddOn::BMediaAddOn(image_id image)
484d4708399SAxel Dörfler :
48544213a4dSbeveloper fImage(image),
48644213a4dSbeveloper fAddon(0)
48752a38012Sejakowatz {
48852a38012Sejakowatz CALLED();
48952a38012Sejakowatz }
49052a38012Sejakowatz
49152a38012Sejakowatz
~BMediaAddOn()49252a38012Sejakowatz BMediaAddOn::~BMediaAddOn()
49352a38012Sejakowatz {
49452a38012Sejakowatz CALLED();
49552a38012Sejakowatz }
49652a38012Sejakowatz
49752a38012Sejakowatz
498d4708399SAxel Dörfler status_t
InitCheck(const char ** _failureText)499d4708399SAxel Dörfler BMediaAddOn::InitCheck(const char **_failureText)
50052a38012Sejakowatz {
50152a38012Sejakowatz CALLED();
50252a38012Sejakowatz // only to be implemented by derived classes
503d4708399SAxel Dörfler *_failureText = "no error";
50452a38012Sejakowatz return B_OK;
50552a38012Sejakowatz }
50652a38012Sejakowatz
50752a38012Sejakowatz
508d4708399SAxel Dörfler int32
CountFlavors()50952a38012Sejakowatz BMediaAddOn::CountFlavors()
51052a38012Sejakowatz {
51152a38012Sejakowatz CALLED();
51252a38012Sejakowatz // only to be implemented by derived classes
51352a38012Sejakowatz return 0;
51452a38012Sejakowatz }
51552a38012Sejakowatz
51652a38012Sejakowatz
517d4708399SAxel Dörfler status_t
GetFlavorAt(int32 n,const flavor_info ** _info)518d4708399SAxel Dörfler BMediaAddOn::GetFlavorAt(int32 n, const flavor_info **_info)
51952a38012Sejakowatz {
52052a38012Sejakowatz CALLED();
52152a38012Sejakowatz // only to be implemented by derived classes
52252a38012Sejakowatz return B_ERROR;
52352a38012Sejakowatz }
52452a38012Sejakowatz
52552a38012Sejakowatz
526d4708399SAxel Dörfler BMediaNode*
InstantiateNodeFor(const flavor_info * info,BMessage * config,status_t * _error)527d4708399SAxel Dörfler BMediaAddOn::InstantiateNodeFor(const flavor_info *info, BMessage *config,
528d4708399SAxel Dörfler status_t *_error)
52952a38012Sejakowatz {
53052a38012Sejakowatz CALLED();
53152a38012Sejakowatz // only to be implemented by derived classes
53252a38012Sejakowatz return NULL;
53352a38012Sejakowatz }
53452a38012Sejakowatz
53552a38012Sejakowatz
536d4708399SAxel Dörfler status_t
GetConfigurationFor(BMediaNode * node,BMessage * toMessage)537d4708399SAxel Dörfler BMediaAddOn::GetConfigurationFor(BMediaNode *node, BMessage *toMessage)
53852a38012Sejakowatz {
53952a38012Sejakowatz CALLED();
54052a38012Sejakowatz // only to be implemented by derived classes
54152a38012Sejakowatz return B_ERROR;
54252a38012Sejakowatz }
54352a38012Sejakowatz
54452a38012Sejakowatz
545d4708399SAxel Dörfler bool
WantsAutoStart()54652a38012Sejakowatz BMediaAddOn::WantsAutoStart()
54752a38012Sejakowatz {
54852a38012Sejakowatz CALLED();
54952a38012Sejakowatz // only to be implemented by derived classes
55052a38012Sejakowatz return false;
55152a38012Sejakowatz }
55252a38012Sejakowatz
55352a38012Sejakowatz
554d4708399SAxel Dörfler status_t
AutoStart(int count,BMediaNode ** _node,int32 * _internalID,bool * _hasMore)555d4708399SAxel Dörfler BMediaAddOn::AutoStart(int count, BMediaNode **_node, int32 *_internalID,
556d4708399SAxel Dörfler bool *_hasMore)
55752a38012Sejakowatz {
55852a38012Sejakowatz CALLED();
55952a38012Sejakowatz // only to be implemented by derived classes
56052a38012Sejakowatz return B_ERROR;
56152a38012Sejakowatz }
56252a38012Sejakowatz
56352a38012Sejakowatz
564d4708399SAxel Dörfler status_t
SniffRef(const entry_ref & file,BMimeType * mimeType,float * _quality,int32 * _internalID)565d4708399SAxel Dörfler BMediaAddOn::SniffRef(const entry_ref &file, BMimeType *mimeType,
566d4708399SAxel Dörfler float *_quality, int32 *_internalID)
56752a38012Sejakowatz {
56852a38012Sejakowatz CALLED();
56952a38012Sejakowatz // only to be implemented by BFileInterface derived classes
57052a38012Sejakowatz return B_ERROR;
57152a38012Sejakowatz }
57252a38012Sejakowatz
57352a38012Sejakowatz
574d4708399SAxel Dörfler status_t
SniffType(const BMimeType & type,float * _quality,int32 * _internalID)575d4708399SAxel Dörfler BMediaAddOn::SniffType(const BMimeType &type, float *_quality,
576d4708399SAxel Dörfler int32 *_internalID)
57752a38012Sejakowatz {
57852a38012Sejakowatz CALLED();
57952a38012Sejakowatz // only to be implemented by BFileInterface derived classes
58052a38012Sejakowatz return B_ERROR;
58152a38012Sejakowatz }
58252a38012Sejakowatz
58352a38012Sejakowatz
584d4708399SAxel Dörfler status_t
GetFileFormatList(int32 flavorID,media_file_format * writableFormats,int32 maxWriteItems,int32 * _writeItems,media_file_format * readableFormats,int32 maxReadItems,int32 * _readItems,void * _reserved)585d4708399SAxel Dörfler BMediaAddOn::GetFileFormatList(int32 flavorID,
586d4708399SAxel Dörfler media_file_format *writableFormats, int32 maxWriteItems, int32 *_writeItems,
587d4708399SAxel Dörfler media_file_format *readableFormats, int32 maxReadItems, int32 *_readItems,
58852a38012Sejakowatz void *_reserved)
58952a38012Sejakowatz {
59052a38012Sejakowatz CALLED();
59152a38012Sejakowatz // only to be implemented by BFileInterface derived classes
59252a38012Sejakowatz return B_ERROR;
59352a38012Sejakowatz }
59452a38012Sejakowatz
59552a38012Sejakowatz
596d4708399SAxel Dörfler status_t
SniffTypeKind(const BMimeType & type,uint64 kinds,float * _quality,int32 * _internalID,void * _reserved)597d4708399SAxel Dörfler BMediaAddOn::SniffTypeKind(const BMimeType &type, uint64 kinds, float *_quality,
598d4708399SAxel Dörfler int32 *_internalID, void *_reserved)
59952a38012Sejakowatz {
60052a38012Sejakowatz CALLED();
60152a38012Sejakowatz // only to be implemented by BFileInterface derived classes
60252a38012Sejakowatz return B_ERROR;
60352a38012Sejakowatz }
60452a38012Sejakowatz
60552a38012Sejakowatz
60652a38012Sejakowatz image_id
ImageID()60752a38012Sejakowatz BMediaAddOn::ImageID()
60852a38012Sejakowatz {
60944213a4dSbeveloper return fImage;
61052a38012Sejakowatz }
61152a38012Sejakowatz
61252a38012Sejakowatz
61352a38012Sejakowatz media_addon_id
AddonID()61452a38012Sejakowatz BMediaAddOn::AddonID()
61552a38012Sejakowatz {
61644213a4dSbeveloper return fAddon;
61752a38012Sejakowatz }
61852a38012Sejakowatz
619d4708399SAxel Dörfler
620d4708399SAxel Dörfler // #pragma mark - protected BMediaAddOn
621d4708399SAxel Dörfler
62252a38012Sejakowatz
62352a38012Sejakowatz status_t
NotifyFlavorChange()62452a38012Sejakowatz BMediaAddOn::NotifyFlavorChange()
62552a38012Sejakowatz {
62616b7eea4Sbeveloper CALLED();
62744213a4dSbeveloper if (fAddon == 0)
62852a38012Sejakowatz return B_ERROR;
62952a38012Sejakowatz
6309c3b4706SAxel Dörfler add_on_server_rescan_flavors_command command;
6319c3b4706SAxel Dörfler command.add_on_id = fAddon;
6329c3b4706SAxel Dörfler return SendToAddOnServer(ADD_ON_SERVER_RESCAN_ADD_ON_FLAVORS, &command,
6339c3b4706SAxel Dörfler sizeof(command));
63452a38012Sejakowatz }
63552a38012Sejakowatz
636d4708399SAxel Dörfler
637d4708399SAxel Dörfler // #pragma mark - private BMediaAddOn
638d4708399SAxel Dörfler
63952a38012Sejakowatz
64052a38012Sejakowatz /*
64152a38012Sejakowatz unimplemented:
64252a38012Sejakowatz BMediaAddOn::BMediaAddOn()
64352a38012Sejakowatz BMediaAddOn::BMediaAddOn(const BMediaAddOn &clone)
64452a38012Sejakowatz BMediaAddOn & BMediaAddOn::operator=(const BMediaAddOn &clone)
64552a38012Sejakowatz */
64652a38012Sejakowatz
64752a38012Sejakowatz
64852a38012Sejakowatz extern "C" {
64952a38012Sejakowatz // declared here to remove them from the class header file
65052a38012Sejakowatz status_t _Reserved_MediaAddOn_0__11BMediaAddOnPv(void *, void *); /* now used for BMediaAddOn::GetFileFormatList */
65152a38012Sejakowatz status_t _Reserved_MediaAddOn_1__11BMediaAddOnPv(void *, void *); /* now used for BMediaAddOn::SniffTypeKind */
_Reserved_MediaAddOn_0__11BMediaAddOnPv(void *,void *)65252a38012Sejakowatz status_t _Reserved_MediaAddOn_0__11BMediaAddOnPv(void *, void *) { return B_ERROR; }
_Reserved_MediaAddOn_1__11BMediaAddOnPv(void *,void *)65352a38012Sejakowatz status_t _Reserved_MediaAddOn_1__11BMediaAddOnPv(void *, void *) { return B_ERROR; }
65452a38012Sejakowatz };
65552a38012Sejakowatz
_Reserved_MediaAddOn_2(void *)65652a38012Sejakowatz status_t BMediaAddOn::_Reserved_MediaAddOn_2(void *) { return B_ERROR; }
_Reserved_MediaAddOn_3(void *)65752a38012Sejakowatz status_t BMediaAddOn::_Reserved_MediaAddOn_3(void *) { return B_ERROR; }
_Reserved_MediaAddOn_4(void *)65852a38012Sejakowatz status_t BMediaAddOn::_Reserved_MediaAddOn_4(void *) { return B_ERROR; }
_Reserved_MediaAddOn_5(void *)65952a38012Sejakowatz status_t BMediaAddOn::_Reserved_MediaAddOn_5(void *) { return B_ERROR; }
_Reserved_MediaAddOn_6(void *)66052a38012Sejakowatz status_t BMediaAddOn::_Reserved_MediaAddOn_6(void *) { return B_ERROR; }
_Reserved_MediaAddOn_7(void *)66152a38012Sejakowatz status_t BMediaAddOn::_Reserved_MediaAddOn_7(void *) { return B_ERROR; }
66252a38012Sejakowatz
663