1dda3a9c3SDario Casalinuovo /* 2dda3a9c3SDario Casalinuovo * Copyright 2017, Dario Casalinuovo. All rights reserved. 3dda3a9c3SDario Casalinuovo * Distributed under the terms of the MIT License. 4dda3a9c3SDario Casalinuovo */ 5dda3a9c3SDario Casalinuovo 6dda3a9c3SDario Casalinuovo #include "MediaTest.h" 7dda3a9c3SDario Casalinuovo 8dda3a9c3SDario Casalinuovo #include <SimpleMediaClient.h> 9dda3a9c3SDario Casalinuovo #include <MediaConnection.h> 10dda3a9c3SDario Casalinuovo #include <SupportDefs.h> 11dda3a9c3SDario Casalinuovo 12dda3a9c3SDario Casalinuovo #include <assert.h> 13dda3a9c3SDario Casalinuovo #include <stdio.h> 14dda3a9c3SDario Casalinuovo 15dda3a9c3SDario Casalinuovo #include <debug.h> 16dda3a9c3SDario Casalinuovo 17dda3a9c3SDario Casalinuovo #ifdef DEBUG 18dda3a9c3SDario Casalinuovo #define DELAYED_MODE 1 19dda3a9c3SDario Casalinuovo #define SNOOZE_FOR 10000000 20dda3a9c3SDario Casalinuovo #endif 21dda3a9c3SDario Casalinuovo 22*80e9e5f3SBarrett17 #define MAX_MULTI_CLIENTS 3 23dda3a9c3SDario Casalinuovo 24dda3a9c3SDario Casalinuovo static BSimpleMediaClient* sProducer = NULL; 25dda3a9c3SDario Casalinuovo static BSimpleMediaClient* sConsumer = NULL; 26dda3a9c3SDario Casalinuovo static BSimpleMediaClient* sFilter = NULL; 27dda3a9c3SDario Casalinuovo 28*80e9e5f3SBarrett17 static BSimpleMediaClient* sProducers[MAX_MULTI_CLIENTS]; 29*80e9e5f3SBarrett17 static BSimpleMediaClient* sConsumers[MAX_MULTI_CLIENTS]; 30*80e9e5f3SBarrett17 31dda3a9c3SDario Casalinuovo 32dda3a9c3SDario Casalinuovo void 33dda3a9c3SDario Casalinuovo _InitClients(bool hasFilter) 34dda3a9c3SDario Casalinuovo { 35dda3a9c3SDario Casalinuovo sProducer = new BSimpleMediaClient("MediaClientProducer"); 36dda3a9c3SDario Casalinuovo sConsumer = new BSimpleMediaClient("MediaClientConsumer"); 37dda3a9c3SDario Casalinuovo 38dda3a9c3SDario Casalinuovo if (hasFilter) 39dda3a9c3SDario Casalinuovo sFilter = new BSimpleMediaClient("MediaClientFilter"); 40dda3a9c3SDario Casalinuovo else 41dda3a9c3SDario Casalinuovo sFilter = NULL; 42dda3a9c3SDario Casalinuovo } 43dda3a9c3SDario Casalinuovo 44dda3a9c3SDario Casalinuovo 45dda3a9c3SDario Casalinuovo void 46*80e9e5f3SBarrett17 _InitClientsMulti(bool isMixer) 47*80e9e5f3SBarrett17 { 48*80e9e5f3SBarrett17 if (!isMixer) { 49*80e9e5f3SBarrett17 for (int i = 0; i < MAX_MULTI_CLIENTS; i++) { 50*80e9e5f3SBarrett17 sConsumers[i] = new BSimpleMediaClient("Test Consumer"); 51*80e9e5f3SBarrett17 } 52*80e9e5f3SBarrett17 sProducer = new BSimpleMediaClient("MediaClientProducer"); 53*80e9e5f3SBarrett17 } else { 54*80e9e5f3SBarrett17 for (int i = 0; i < MAX_MULTI_CLIENTS; i++) { 55*80e9e5f3SBarrett17 sProducers[i] = new BSimpleMediaClient("Test Producer"); 56*80e9e5f3SBarrett17 } 57*80e9e5f3SBarrett17 sConsumer = new BSimpleMediaClient("MediaClientConsumer"); 58*80e9e5f3SBarrett17 } 59*80e9e5f3SBarrett17 60*80e9e5f3SBarrett17 sFilter = new BSimpleMediaClient("MediaClientFilter"); 61*80e9e5f3SBarrett17 } 62*80e9e5f3SBarrett17 63*80e9e5f3SBarrett17 64*80e9e5f3SBarrett17 void 65dda3a9c3SDario Casalinuovo _DeleteClients() 66dda3a9c3SDario Casalinuovo { 67dda3a9c3SDario Casalinuovo delete sProducer; 68dda3a9c3SDario Casalinuovo delete sConsumer; 69dda3a9c3SDario Casalinuovo delete sFilter; 70dda3a9c3SDario Casalinuovo } 71dda3a9c3SDario Casalinuovo 72dda3a9c3SDario Casalinuovo 73*80e9e5f3SBarrett17 void 74*80e9e5f3SBarrett17 _DeleteClientsMulti(bool isMixer) 75*80e9e5f3SBarrett17 { 76*80e9e5f3SBarrett17 if (!isMixer) { 77*80e9e5f3SBarrett17 for (int i = 0; i < MAX_MULTI_CLIENTS; i++) { 78*80e9e5f3SBarrett17 delete sConsumers[i]; 79*80e9e5f3SBarrett17 } 80*80e9e5f3SBarrett17 delete sProducer; 81*80e9e5f3SBarrett17 } else { 82*80e9e5f3SBarrett17 for (int i = 0; i < MAX_MULTI_CLIENTS; i++) { 83*80e9e5f3SBarrett17 delete sProducers[i]; 84*80e9e5f3SBarrett17 } 85*80e9e5f3SBarrett17 delete sConsumer; 86*80e9e5f3SBarrett17 } 87*80e9e5f3SBarrett17 delete sFilter; 88*80e9e5f3SBarrett17 } 89*80e9e5f3SBarrett17 90*80e9e5f3SBarrett17 91dda3a9c3SDario Casalinuovo media_format 92dda3a9c3SDario Casalinuovo _BuildRawAudioFormat() 93dda3a9c3SDario Casalinuovo { 94dda3a9c3SDario Casalinuovo media_format format; 95dda3a9c3SDario Casalinuovo format.type = B_MEDIA_RAW_AUDIO; 96dda3a9c3SDario Casalinuovo format.u.raw_audio = media_multi_audio_format::wildcard; 97dda3a9c3SDario Casalinuovo 98dda3a9c3SDario Casalinuovo return format; 99dda3a9c3SDario Casalinuovo } 100dda3a9c3SDario Casalinuovo 101dda3a9c3SDario Casalinuovo 102dda3a9c3SDario Casalinuovo void 103dda3a9c3SDario Casalinuovo _ConsumerProducerTest() 104dda3a9c3SDario Casalinuovo { 105dda3a9c3SDario Casalinuovo _InitClients(false); 106dda3a9c3SDario Casalinuovo 107dda3a9c3SDario Casalinuovo BSimpleMediaOutput* output = sProducer->BeginOutput(); 108dda3a9c3SDario Casalinuovo BSimpleMediaInput* input = sConsumer->BeginInput(); 109dda3a9c3SDario Casalinuovo 110dda3a9c3SDario Casalinuovo output->SetAcceptedFormat(_BuildRawAudioFormat()); 111dda3a9c3SDario Casalinuovo input->SetAcceptedFormat(_BuildRawAudioFormat()); 112dda3a9c3SDario Casalinuovo 113dda3a9c3SDario Casalinuovo assert(sConsumer->Connect(input, output) == B_OK); 114dda3a9c3SDario Casalinuovo 115dda3a9c3SDario Casalinuovo #ifdef DELAYED_MODE 116dda3a9c3SDario Casalinuovo snooze(SNOOZE_FOR); 117dda3a9c3SDario Casalinuovo #endif 118dda3a9c3SDario Casalinuovo 1196072c6f1SBarrett17 assert(input->Disconnect() == B_OK); 120dda3a9c3SDario Casalinuovo 1212cb3cabcSBarrett17 _DeleteClients(); 122dda3a9c3SDario Casalinuovo } 123dda3a9c3SDario Casalinuovo 124dda3a9c3SDario Casalinuovo 125dda3a9c3SDario Casalinuovo void 126dda3a9c3SDario Casalinuovo _ProducerConsumerTest() 127dda3a9c3SDario Casalinuovo { 128dda3a9c3SDario Casalinuovo _InitClients(false); 129dda3a9c3SDario Casalinuovo 130dda3a9c3SDario Casalinuovo BMediaOutput* output = sProducer->BeginOutput(); 131dda3a9c3SDario Casalinuovo BMediaInput* input = sConsumer->BeginInput(); 132dda3a9c3SDario Casalinuovo 133dda3a9c3SDario Casalinuovo assert(sProducer->Connect(output, input) == B_OK); 134dda3a9c3SDario Casalinuovo 135dda3a9c3SDario Casalinuovo #ifdef DELAYED_MODE 136dda3a9c3SDario Casalinuovo snooze(SNOOZE_FOR); 137dda3a9c3SDario Casalinuovo #endif 138dda3a9c3SDario Casalinuovo 139dda3a9c3SDario Casalinuovo assert(sProducer->Disconnect() == B_OK); 140dda3a9c3SDario Casalinuovo 141dda3a9c3SDario Casalinuovo _DeleteClients(); 142dda3a9c3SDario Casalinuovo } 143dda3a9c3SDario Casalinuovo 144dda3a9c3SDario Casalinuovo 145dda3a9c3SDario Casalinuovo void 146dda3a9c3SDario Casalinuovo _ProducerFilterConsumerTest() 147dda3a9c3SDario Casalinuovo { 148dda3a9c3SDario Casalinuovo _InitClients(true); 149dda3a9c3SDario Casalinuovo 150dda3a9c3SDario Casalinuovo BMediaOutput* output = sProducer->BeginOutput(); 151dda3a9c3SDario Casalinuovo BMediaInput* input = sConsumer->BeginInput(); 152dda3a9c3SDario Casalinuovo 153dda3a9c3SDario Casalinuovo BMediaInput* filterInput = sFilter->BeginInput(); 154dda3a9c3SDario Casalinuovo BMediaOutput* filterOutput = sFilter->BeginOutput(); 155dda3a9c3SDario Casalinuovo 156dda3a9c3SDario Casalinuovo assert(sFilter->Bind(filterInput, filterOutput) == B_OK); 157dda3a9c3SDario Casalinuovo 158dda3a9c3SDario Casalinuovo assert(sProducer->Connect(output, filterInput) == B_OK); 159dda3a9c3SDario Casalinuovo assert(sFilter->Connect(filterOutput, input) == B_OK); 160dda3a9c3SDario Casalinuovo #ifdef DELAYED_MODE 161dda3a9c3SDario Casalinuovo snooze(SNOOZE_FOR); 162dda3a9c3SDario Casalinuovo #endif 163dda3a9c3SDario Casalinuovo 164dda3a9c3SDario Casalinuovo assert(sFilter->Disconnect() == B_OK); 165dda3a9c3SDario Casalinuovo 166dda3a9c3SDario Casalinuovo _DeleteClients(); 167dda3a9c3SDario Casalinuovo } 168dda3a9c3SDario Casalinuovo 169dda3a9c3SDario Casalinuovo 170dda3a9c3SDario Casalinuovo void 171*80e9e5f3SBarrett17 _SplitterConfigurationTest() 172*80e9e5f3SBarrett17 { 173*80e9e5f3SBarrett17 _InitClientsMulti(false); 174*80e9e5f3SBarrett17 175*80e9e5f3SBarrett17 for (int i = 0; i < MAX_MULTI_CLIENTS; i++) { 176*80e9e5f3SBarrett17 BMediaOutput* output = sFilter->BeginOutput(); 177*80e9e5f3SBarrett17 assert(sFilter->Connect(output, sConsumers[i]->BeginInput()) == B_OK); 178*80e9e5f3SBarrett17 } 179*80e9e5f3SBarrett17 180*80e9e5f3SBarrett17 assert(sProducer->Connect(sProducer->BeginOutput(), 181*80e9e5f3SBarrett17 sFilter->BeginInput()) == B_OK); 182*80e9e5f3SBarrett17 183*80e9e5f3SBarrett17 #ifdef DELAYED_MODE 184*80e9e5f3SBarrett17 snooze(SNOOZE_FOR); 185*80e9e5f3SBarrett17 #endif 186*80e9e5f3SBarrett17 187*80e9e5f3SBarrett17 _DeleteClientsMulti(false); 188*80e9e5f3SBarrett17 } 189*80e9e5f3SBarrett17 190*80e9e5f3SBarrett17 191*80e9e5f3SBarrett17 void 192*80e9e5f3SBarrett17 _MixerConfigurationTest() 193*80e9e5f3SBarrett17 { 194*80e9e5f3SBarrett17 _InitClientsMulti(true); 195*80e9e5f3SBarrett17 196*80e9e5f3SBarrett17 for (int i = 0; i < MAX_MULTI_CLIENTS; i++) { 197*80e9e5f3SBarrett17 BMediaInput* input = sFilter->BeginInput(); 198*80e9e5f3SBarrett17 assert(sFilter->Connect(input, sConsumers[i]->BeginInput()) == B_OK); 199*80e9e5f3SBarrett17 } 200*80e9e5f3SBarrett17 201*80e9e5f3SBarrett17 assert(sConsumer->Connect(sConsumer->BeginInput(), 202*80e9e5f3SBarrett17 sFilter->BeginOutput()) == B_OK); 203*80e9e5f3SBarrett17 204*80e9e5f3SBarrett17 #ifdef DELAYED_MODE 205*80e9e5f3SBarrett17 snooze(SNOOZE_FOR); 206*80e9e5f3SBarrett17 #endif 207*80e9e5f3SBarrett17 208*80e9e5f3SBarrett17 _DeleteClientsMulti(true); 209*80e9e5f3SBarrett17 } 210*80e9e5f3SBarrett17 211*80e9e5f3SBarrett17 212*80e9e5f3SBarrett17 void 213dda3a9c3SDario Casalinuovo media_test() 214dda3a9c3SDario Casalinuovo { 215dda3a9c3SDario Casalinuovo printf("Testing Simple (1:1) Producer-Consumer configuration: "); 216dda3a9c3SDario Casalinuovo _ConsumerProducerTest(); 2172cb3cabcSBarrett17 _ProducerConsumerTest(); 2182cb3cabcSBarrett17 printf("OK\n"); 219dda3a9c3SDario Casalinuovo 2202cb3cabcSBarrett17 printf("Testing Simple (1:1:1) Producer-Filter-Consumer configuration: "); 2212cb3cabcSBarrett17 _ProducerFilterConsumerTest(); 222dda3a9c3SDario Casalinuovo printf("OK\n"); 223*80e9e5f3SBarrett17 224*80e9e5f3SBarrett17 printf("Testing Splitter Configuration (N:1:1): "); 225*80e9e5f3SBarrett17 _SplitterConfigurationTest(); 226*80e9e5f3SBarrett17 printf("OK\n"); 227*80e9e5f3SBarrett17 228*80e9e5f3SBarrett17 printf("Testing Mixer Configuration (N:1:1): "); 229*80e9e5f3SBarrett17 _SplitterConfigurationTest(); 230*80e9e5f3SBarrett17 printf("OK\n"); 231dda3a9c3SDario Casalinuovo } 232