1ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean/*
2ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean * Copyright (C) 2016 The Android Open Source Project
3ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean *
4ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean * Licensed under the Apache License, Version 2.0 (the "License");
5ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean * you may not use this file except in compliance with the License.
6ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean * You may obtain a copy of the License at
7ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean *
8ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean *      http://www.apache.org/licenses/LICENSE-2.0
9ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean *
10ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean * Unless required by applicable law or agreed to in writing, software
11ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean * distributed under the License is distributed on an "AS IS" BASIS,
12ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean * See the License for the specific language governing permissions and
14ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean * limitations under the License.
15ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean */
16ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean
17ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLeanpackage android.media;
18ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean
19ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLeanimport android.os.Handler;
20ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLeanimport android.os.Looper;
21ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean
22ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean/**
23ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean * AudioRouting defines an interface for controlling routing and routing notifications in
24ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean * AudioTrack and AudioRecord objects.
25ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean */
26ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLeanpublic interface AudioRouting {
27ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean    /**
28ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * Specifies an audio device (via an {@link AudioDeviceInfo} object) to route
29ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * the output/input to/from.
30ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * @param deviceInfo The {@link AudioDeviceInfo} specifying the audio sink or source.
31ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     *  If deviceInfo is null, default routing is restored.
32ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * @return true if succesful, false if the specified {@link AudioDeviceInfo} is non-null and
33ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * does not correspond to a valid audio device.
34ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     */
35ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean    public boolean setPreferredDevice(AudioDeviceInfo deviceInfo);
36ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean
37ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean    /**
38ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * Returns the selected output/input specified by {@link #setPreferredDevice}. Note that this
39ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * is not guaranteed to correspond to the actual device being used for playback/recording.
40ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     */
41ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean    public AudioDeviceInfo getPreferredDevice();
42ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean
43ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean    /**
449b09e533ac67d3d25465e3312b4957bc90b0c84fPaul McLean     * Returns an {@link AudioDeviceInfo} identifying the current routing of this
459b09e533ac67d3d25465e3312b4957bc90b0c84fPaul McLean     * AudioTrack/AudioRecord.
469b09e533ac67d3d25465e3312b4957bc90b0c84fPaul McLean     * Note: The query is only valid if the AudioTrack/AudioRecord is currently playing.
479b09e533ac67d3d25465e3312b4957bc90b0c84fPaul McLean     * If it is not, <code>getRoutedDevice()</code> will return null.
489b09e533ac67d3d25465e3312b4957bc90b0c84fPaul McLean     */
499b09e533ac67d3d25465e3312b4957bc90b0c84fPaul McLean    public AudioDeviceInfo getRoutedDevice();
509b09e533ac67d3d25465e3312b4957bc90b0c84fPaul McLean
519b09e533ac67d3d25465e3312b4957bc90b0c84fPaul McLean    /**
52ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * Adds an {@link AudioRouting.OnRoutingChangedListener} to receive notifications of routing
53ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * changes on this AudioTrack/AudioRecord.
54ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * @param listener The {@link AudioRouting.OnRoutingChangedListener} interface to receive
55ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * notifications of rerouting events.
56ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * @param handler  Specifies the {@link Handler} object for the thread on which to execute
57ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * the callback. If <code>null</code>, the {@link Handler} associated with the main
58ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * {@link Looper} will be used.
59ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     */
60ed2edc7a8e044e31a6c9db638c97f9c21fb1d946Jeff Sharkey    public void addOnRoutingChangedListener(OnRoutingChangedListener listener,
61ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean            Handler handler);
62ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean
63ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean    /**
64ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * Removes an {@link AudioRouting.OnRoutingChangedListener} which has been previously added
65ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * to receive rerouting notifications.
66ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * @param listener The previously added {@link AudioRouting.OnRoutingChangedListener} interface
67ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * to remove.
68ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     */
69ed2edc7a8e044e31a6c9db638c97f9c21fb1d946Jeff Sharkey    public void removeOnRoutingChangedListener(OnRoutingChangedListener listener);
70ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean
71ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean    /**
72ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * Defines the interface by which applications can receive notifications of routing
73ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     * changes for the associated {@link AudioRouting}.
74ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean     */
75ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean    public interface OnRoutingChangedListener {
76ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean        public void onRoutingChanged(AudioRouting router);
77ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean    }
78ed36ca3d4f4f8aa0ee2951eab143a3c96b76158bPaul McLean}
79