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 <Catalog.h>
42#include <cstring>
43#include <cstdlib>
44
45#undef B_TRANSLATION_CONTEXT
46#define B_TRANSLATION_CONTEXT "CortexAddOnsNullFilter"
47
48// -------------------------------------------------------- //
49// _NullFilterNode
50// -------------------------------------------------------- //
51
52class _NullFilterNode :
53	public	AudioFilterNode {
54	typedef	AudioFilterNode _inherited;
55
56public:
57	virtual ~_NullFilterNode() {}
58	_NullFilterNode(
59		const char*									name,
60		IAudioOpFactory*						opFactory,
61		BMediaAddOn*								addOn=0) :
62		BMediaNode(name),
63		AudioFilterNode(name, opFactory, addOn) {}
64
65	// be rather permissive about formats
66	status_t getRequiredFormat(
67		media_format&								ioFormat) {
68
69		if(ioFormat.type != B_MEDIA_RAW_AUDIO)
70			return B_MEDIA_BAD_FORMAT;
71		ioFormat.u.raw_audio = media_raw_audio_format::wildcard;
72		ioFormat.u.raw_audio.channel_count = 1;
73
74		return B_OK;
75	}
76
77	status_t getPreferredFormat(
78		media_format&								ioFormat) {
79		status_t err = _inherited::getPreferredFormat(ioFormat);
80		if(err < B_OK)
81			return err;
82
83		ioFormat.u.raw_audio.channel_count = 1;
84		return B_OK;
85	}
86};
87
88
89// -------------------------------------------------------- //
90// instantiation function
91// -------------------------------------------------------- //
92
93extern "C" _EXPORT BMediaAddOn* make_media_addon(image_id image) {
94	return new NullFilterAddOn(image);
95}
96
97// -------------------------------------------------------- //
98// ctor/dtor
99// -------------------------------------------------------- //
100
101//NullFilterAddOn::~NullFilterAddOn() {}
102NullFilterAddOn::NullFilterAddOn(image_id id) :
103	BMediaAddOn(id) {}
104
105// -------------------------------------------------------- //
106// BMediaAddOn impl
107// -------------------------------------------------------- //
108
109status_t NullFilterAddOn::InitCheck(
110	const char** out_failure_text) {
111	return B_OK;
112}
113
114int32 NullFilterAddOn::CountFlavors() {
115	return 1;
116}
117
118status_t NullFilterAddOn::GetFlavorAt(
119	int32 n,
120	const flavor_info** out_info) {
121	if(n)
122		return B_ERROR;
123
124	flavor_info* pInfo = new flavor_info;
125	pInfo->internal_id = n;
126	pInfo->name = B_TRANSLATE("NullFilter");
127	pInfo->info =
128		B_TRANSLATE("NullFilter (empty test filter).\n"
129		"by Eric Moon (8 September 1999)");
130	pInfo->kinds = B_BUFFER_CONSUMER | B_BUFFER_PRODUCER | B_CONTROLLABLE;
131	pInfo->flavor_flags = 0;
132	pInfo->possible_count = 0;
133
134	pInfo->in_format_count = 1;
135	media_format* pFormat = new media_format;
136	pFormat->type = B_MEDIA_RAW_AUDIO;
137	pFormat->u.raw_audio = media_raw_audio_format::wildcard;
138	pInfo->in_formats = pFormat;
139
140	pInfo->out_format_count = 1;
141	pFormat = new media_format;
142	pFormat->type = B_MEDIA_RAW_AUDIO;
143	pFormat->u.raw_audio = media_raw_audio_format::wildcard;
144	pInfo->out_formats = pFormat;
145
146	*out_info = pInfo;
147	return B_OK;
148}
149
150BMediaNode* NullFilterAddOn::InstantiateNodeFor(
151	const flavor_info* info,
152	BMessage* config,
153	status_t* out_error) {
154
155	return new _NullFilterNode(
156		"NullFilter",
157		new NullAudioOpFactory(),
158		this);
159}
160
161status_t NullFilterAddOn::GetConfigurationFor(
162	BMediaNode* your_node,
163	BMessage* into_message) {
164
165	// no config yet
166	return B_OK;
167}
168
169
170// END -- NullFilterAddOn.cpp --
171