1/*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions, and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions, and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * 3. The name of the author may not be used to endorse or promote products
17 *    derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31
32// NullFilterAddOn.cpp
33
34#include "NullFilterAddOn.h"
35
36#include "AudioFilterNode.h"
37#include "NullAudioOp.h"
38
39#include <Entry.h>
40#include <Debug.h>
41#include <cstring>
42#include <cstdlib>
43
44// -------------------------------------------------------- //
45// _NullFilterNode
46// -------------------------------------------------------- //
47
48class _NullFilterNode :
49	public	AudioFilterNode {
50	typedef	AudioFilterNode _inherited;
51
52public:
53	virtual ~_NullFilterNode() {}
54	_NullFilterNode(
55		const char*									name,
56		IAudioOpFactory*						opFactory,
57		BMediaAddOn*								addOn=0) :
58		BMediaNode(name),
59		AudioFilterNode(name, opFactory, addOn) {}
60
61	// be rather permissive about formats
62	status_t getRequiredFormat(
63		media_format&								ioFormat) {
64
65		if(ioFormat.type != B_MEDIA_RAW_AUDIO)
66			return B_MEDIA_BAD_FORMAT;
67		ioFormat.u.raw_audio = media_raw_audio_format::wildcard;
68		ioFormat.u.raw_audio.channel_count = 1;
69
70		return B_OK;
71	}
72
73	status_t getPreferredFormat(
74		media_format&								ioFormat) {
75		status_t err = _inherited::getPreferredFormat(ioFormat);
76		if(err < B_OK)
77			return err;
78
79		ioFormat.u.raw_audio.channel_count = 1;
80		return B_OK;
81	}
82};
83
84
85// -------------------------------------------------------- //
86// instantiation function
87// -------------------------------------------------------- //
88
89extern "C" _EXPORT BMediaAddOn* make_media_addon(image_id image) {
90	return new NullFilterAddOn(image);
91}
92
93// -------------------------------------------------------- //
94// ctor/dtor
95// -------------------------------------------------------- //
96
97//NullFilterAddOn::~NullFilterAddOn() {}
98NullFilterAddOn::NullFilterAddOn(image_id id) :
99	BMediaAddOn(id) {}
100
101// -------------------------------------------------------- //
102// BMediaAddOn impl
103// -------------------------------------------------------- //
104
105status_t NullFilterAddOn::InitCheck(
106	const char** out_failure_text) {
107	return B_OK;
108}
109
110int32 NullFilterAddOn::CountFlavors() {
111	return 1;
112}
113
114status_t NullFilterAddOn::GetFlavorAt(
115	int32 n,
116	const flavor_info** out_info) {
117	if(n)
118		return B_ERROR;
119
120	flavor_info* pInfo = new flavor_info;
121	pInfo->internal_id = n;
122	pInfo->name = "NullFilter";
123	pInfo->info =
124		"NullFilter (empty test filter).\n"
125		"by Eric Moon (8 September 1999)";
126	pInfo->kinds = B_BUFFER_CONSUMER | B_BUFFER_PRODUCER | B_CONTROLLABLE;
127	pInfo->flavor_flags = 0;
128	pInfo->possible_count = 0;
129
130	pInfo->in_format_count = 1;
131	media_format* pFormat = new media_format;
132	pFormat->type = B_MEDIA_RAW_AUDIO;
133	pFormat->u.raw_audio = media_raw_audio_format::wildcard;
134	pInfo->in_formats = pFormat;
135
136	pInfo->out_format_count = 1;
137	pFormat = new media_format;
138	pFormat->type = B_MEDIA_RAW_AUDIO;
139	pFormat->u.raw_audio = media_raw_audio_format::wildcard;
140	pInfo->out_formats = pFormat;
141
142	*out_info = pInfo;
143	return B_OK;
144}
145
146BMediaNode* NullFilterAddOn::InstantiateNodeFor(
147	const flavor_info* info,
148	BMessage* config,
149	status_t* out_error) {
150
151	return new _NullFilterNode(
152		"NullFilter",
153		new NullAudioOpFactory(),
154		this);
155}
156
157status_t NullFilterAddOn::GetConfigurationFor(
158	BMediaNode* your_node,
159	BMessage* into_message) {
160
161	// no config yet
162	return B_OK;
163}
164
165
166// END -- NullFilterAddOn.cpp --