xref: /haiku/src/add-ons/media/media-add-ons/mixer/MixerAddOn.cpp (revision ed6250c95736c0b55da79d6e9dd01369532260c0)
1 /*
2  * Copyright 2002 David Shipman,
3  * Copyright 2003-2007 Marcus Overhagen
4  * Copyright 2007 Haiku Inc. All rights reserved.
5  * Distributed under the terms of the MIT License.
6  */
7 #include <MediaRoster.h>
8 #include <MediaNode.h>
9 #include <cstring>
10 #include <cstdio>
11 
12 #include "AudioMixer.h"
13 #include "MixerAddOn.h"
14 
15 // instantiation function
16 extern "C" _EXPORT BMediaAddOn* make_media_addon(image_id image) {
17 	return new AudioMixerAddon(image);
18 }
19 
20 AudioMixerAddon::AudioMixerAddon(image_id image)
21 	: BMediaAddOn(image),
22 	fFormat(new media_format),
23 	fInfo(new flavor_info)
24 {
25 	memset(fFormat, 0, sizeof(*fFormat));
26 	fFormat->type = B_MEDIA_RAW_AUDIO;
27 	fFormat->u.raw_audio = media_raw_audio_format::wildcard;
28 
29 	fInfo->internal_id = 0;
30 	fInfo->name = "Audio Mixer (Haiku)";
31 	fInfo->info = "Haiku Audio Mixer media addon";
32 	fInfo->kinds = B_BUFFER_PRODUCER | B_BUFFER_CONSUMER | B_SYSTEM_MIXER | B_CONTROLLABLE;
33 	fInfo->flavor_flags = 0;	// 0 = global or local instantiation allowed, no restrictions
34 	fInfo->possible_count = 0;	// 0 = infinite
35 	fInfo->in_format_count = 1;
36 	fInfo->in_formats = fFormat;
37 	fInfo->out_format_count = 1;
38 	fInfo->out_formats = fFormat;
39 }
40 
41 AudioMixerAddon::~AudioMixerAddon()
42 {
43 	delete fFormat;
44 	delete fInfo;
45 }
46 
47 // -------------------------------------------------------- //
48 // BMediaAddOn impl
49 // -------------------------------------------------------- //
50 
51 status_t
52 AudioMixerAddon::InitCheck(const char** out_failure_text)
53 {
54 	return B_OK;
55 }
56 
57 int32
58 AudioMixerAddon::CountFlavors()
59 {
60 	return 1;
61 }
62 
63 status_t
64 AudioMixerAddon::GetFlavorAt(int32 n, const flavor_info** out_info)
65 {
66 	// only the 0th flavor exists
67 	if (n != 0)
68 		return B_ERROR;
69 
70 	*out_info = fInfo;
71 	return B_OK;
72 }
73 
74 BMediaNode *
75 AudioMixerAddon::InstantiateNodeFor(const flavor_info* info, BMessage* config,
76 									status_t* out_error)
77 {
78 	return new AudioMixer(this, false);
79 }
80 
81 status_t
82 AudioMixerAddon::GetConfigurationFor(BMediaNode* your_node,	BMessage* into_message)
83 {
84 	// no config yet
85 	return B_ERROR;
86 }
87 
88 bool
89 AudioMixerAddon::WantsAutoStart()
90 {
91 	return true;
92 }
93 
94 status_t
95 AudioMixerAddon::AutoStart(int in_index, BMediaNode **out_node,
96 							int32 *out_internal_id, bool *out_has_more)
97 {
98 	*out_has_more = false;
99 
100 	if (in_index != 0)
101 		return B_ERROR;
102 
103 	*out_internal_id = 0;
104 	AudioMixer *mixer = new AudioMixer(this, true);
105 	*out_node = mixer;
106 
107 	return B_OK;
108 }
109