btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / bin / media_client / MediaTest.cpp
blobd1dbe8363d09b6f74e0ccaf57b577b5aecbb3398
1 /*
2 * Copyright 2017, Dario Casalinuovo. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
6 #include "MediaTest.h"
8 #include <SimpleMediaClient.h>
9 #include <MediaConnection.h>
10 #include <SupportDefs.h>
12 #include <assert.h>
13 #include <stdio.h>
15 #include <debug.h>
17 #ifdef DEBUG
18 #define DELAYED_MODE 1
19 #define SNOOZE_FOR 10000000
20 #endif
23 static BSimpleMediaClient* sProducer = NULL;
24 static BSimpleMediaClient* sConsumer = NULL;
25 static BSimpleMediaClient* sFilter = NULL;
28 void
29 _InitClients(bool hasFilter)
31 sProducer = new BSimpleMediaClient("MediaClientProducer");
32 sConsumer = new BSimpleMediaClient("MediaClientConsumer");
34 if (hasFilter)
35 sFilter = new BSimpleMediaClient("MediaClientFilter");
36 else
37 sFilter = NULL;
41 void
42 _DeleteClients()
44 delete sProducer;
45 delete sConsumer;
46 delete sFilter;
50 media_format
51 _BuildRawAudioFormat()
53 media_format format;
54 format.type = B_MEDIA_RAW_AUDIO;
55 format.u.raw_audio = media_multi_audio_format::wildcard;
57 return format;
61 void
62 _ConsumerProducerTest()
64 _InitClients(false);
66 BSimpleMediaOutput* output = sProducer->BeginOutput();
67 BSimpleMediaInput* input = sConsumer->BeginInput();
69 output->SetAcceptedFormat(_BuildRawAudioFormat());
70 input->SetAcceptedFormat(_BuildRawAudioFormat());
72 assert(sConsumer->Connect(input, output) == B_OK);
74 #ifdef DELAYED_MODE
75 snooze(SNOOZE_FOR);
76 #endif
78 assert(sConsumer->Disconnect() == B_OK);
80 _DeleteClients();
84 void
85 _ProducerConsumerTest()
87 _InitClients(false);
89 BMediaOutput* output = sProducer->BeginOutput();
90 BMediaInput* input = sConsumer->BeginInput();
92 assert(sProducer->Connect(output, input) == B_OK);
94 #ifdef DELAYED_MODE
95 snooze(SNOOZE_FOR);
96 #endif
98 assert(sProducer->Disconnect() == B_OK);
100 _DeleteClients();
104 void
105 _ProducerFilterConsumerTest()
107 _InitClients(true);
109 BMediaOutput* output = sProducer->BeginOutput();
110 BMediaInput* input = sConsumer->BeginInput();
112 BMediaInput* filterInput = sFilter->BeginInput();
113 BMediaOutput* filterOutput = sFilter->BeginOutput();
115 assert(sFilter->Bind(filterInput, filterOutput) == B_OK);
117 assert(sProducer->Connect(output, filterInput) == B_OK);
118 assert(sFilter->Connect(filterOutput, input) == B_OK);
119 #ifdef DELAYED_MODE
120 snooze(SNOOZE_FOR);
121 #endif
123 assert(sFilter->Disconnect() == B_OK);
125 _DeleteClients();
129 void
130 media_test()
132 printf("Testing Simple (1:1) Producer-Consumer configuration: ");
133 _ConsumerProducerTest();
134 _ProducerConsumerTest();
135 printf("OK\n");
137 printf("Testing Simple (1:1:1) Producer-Filter-Consumer configuration: ");
138 _ProducerFilterConsumerTest();
139 printf("OK\n");