1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_IMEDIAPLAYER_H
18#define ANDROID_IMEDIAPLAYER_H
19
20#include <utils/RefBase.h>
21#include <binder/IInterface.h>
22#include <binder/Parcel.h>
23#include <utils/KeyedVector.h>
24#include <system/audio.h>
25
26#include <media/MediaSource.h>
27#include <media/VolumeShaper.h>
28
29// Fwd decl to make sure everyone agrees that the scope of struct sockaddr_in is
30// global, and not in android::
31struct sockaddr_in;
32
33namespace android {
34
35class Parcel;
36class Surface;
37class IDataSource;
38struct IStreamSource;
39class IGraphicBufferProducer;
40struct IMediaHTTPService;
41struct AudioPlaybackRate;
42struct AVSyncSettings;
43struct BufferingSettings;
44
45typedef MediaSource::ReadOptions::SeekMode MediaPlayerSeekMode;
46
47class IMediaPlayer: public IInterface
48{
49public:
50    DECLARE_META_INTERFACE(MediaPlayer);
51
52    virtual void            disconnect() = 0;
53
54    virtual status_t        setDataSource(
55            const sp<IMediaHTTPService> &httpService,
56            const char *url,
57            const KeyedVector<String8, String8>* headers) = 0;
58
59    virtual status_t        setDataSource(int fd, int64_t offset, int64_t length) = 0;
60    virtual status_t        setDataSource(const sp<IStreamSource>& source) = 0;
61    virtual status_t        setDataSource(const sp<IDataSource>& source) = 0;
62    virtual status_t        setVideoSurfaceTexture(
63                                    const sp<IGraphicBufferProducer>& bufferProducer) = 0;
64    virtual status_t        getBufferingSettings(
65                                    BufferingSettings* buffering /* nonnull */) = 0;
66    virtual status_t        setBufferingSettings(const BufferingSettings& buffering) = 0;
67    virtual status_t        prepareAsync() = 0;
68    virtual status_t        start() = 0;
69    virtual status_t        stop() = 0;
70    virtual status_t        pause() = 0;
71    virtual status_t        isPlaying(bool* state) = 0;
72    virtual status_t        setPlaybackSettings(const AudioPlaybackRate& rate) = 0;
73    virtual status_t        getPlaybackSettings(AudioPlaybackRate* rate /* nonnull */) = 0;
74    virtual status_t        setSyncSettings(const AVSyncSettings& sync, float videoFpsHint) = 0;
75    virtual status_t        getSyncSettings(AVSyncSettings* sync /* nonnull */,
76                                            float* videoFps /* nonnull */) = 0;
77    virtual status_t        seekTo(
78            int msec,
79            MediaPlayerSeekMode mode = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC) = 0;
80    virtual status_t        getCurrentPosition(int* msec) = 0;
81    virtual status_t        getDuration(int* msec) = 0;
82    virtual status_t        notifyAt(int64_t mediaTimeUs) = 0;
83    virtual status_t        reset() = 0;
84    virtual status_t        setAudioStreamType(audio_stream_type_t type) = 0;
85    virtual status_t        setLooping(int loop) = 0;
86    virtual status_t        setVolume(float leftVolume, float rightVolume) = 0;
87    virtual status_t        setAuxEffectSendLevel(float level) = 0;
88    virtual status_t        attachAuxEffect(int effectId) = 0;
89    virtual status_t        setParameter(int key, const Parcel& request) = 0;
90    virtual status_t        getParameter(int key, Parcel* reply) = 0;
91    virtual status_t        setRetransmitEndpoint(const struct sockaddr_in* endpoint) = 0;
92    virtual status_t        getRetransmitEndpoint(struct sockaddr_in* endpoint) = 0;
93    virtual status_t        setNextPlayer(const sp<IMediaPlayer>& next) = 0;
94
95    virtual media::VolumeShaper::Status applyVolumeShaper(
96                                    const sp<media::VolumeShaper::Configuration>& configuration,
97                                    const sp<media::VolumeShaper::Operation>& operation) = 0;
98    virtual sp<media::VolumeShaper::State> getVolumeShaperState(int id) = 0;
99
100    // Modular DRM
101    virtual status_t        prepareDrm(const uint8_t uuid[16],
102                                    const Vector<uint8_t>& drmSessionId) = 0;
103    virtual status_t        releaseDrm() = 0;
104
105    // Invoke a generic method on the player by using opaque parcels
106    // for the request and reply.
107    // @param request Parcel that must start with the media player
108    // interface token.
109    // @param[out] reply Parcel to hold the reply data. Cannot be null.
110    // @return OK if the invocation was made successfully.
111    virtual status_t        invoke(const Parcel& request, Parcel *reply) = 0;
112
113    // Set a new metadata filter.
114    // @param filter A set of allow and drop rules serialized in a Parcel.
115    // @return OK if the invocation was made successfully.
116    virtual status_t        setMetadataFilter(const Parcel& filter) = 0;
117
118    // Retrieve a set of metadata.
119    // @param update_only Include only the metadata that have changed
120    //                    since the last invocation of getMetadata.
121    //                    The set is built using the unfiltered
122    //                    notifications the native player sent to the
123    //                    MediaPlayerService during that period of
124    //                    time. If false, all the metadatas are considered.
125    // @param apply_filter If true, once the metadata set has been built based
126    //                     on the value update_only, the current filter is
127    //                     applied.
128    // @param[out] metadata On exit contains a set (possibly empty) of metadata.
129    //                      Valid only if the call returned OK.
130    // @return OK if the invocation was made successfully.
131    virtual status_t        getMetadata(bool update_only,
132                                        bool apply_filter,
133                                        Parcel *metadata) = 0;
134
135    // AudioRouting
136    virtual status_t        setOutputDevice(audio_port_handle_t deviceId) = 0;
137    virtual status_t        getRoutedDeviceId(audio_port_handle_t *deviceId) = 0;
138    virtual status_t        enableAudioDeviceCallback(bool enabled) = 0;
139};
140
141// ----------------------------------------------------------------------------
142
143class BnMediaPlayer: public BnInterface<IMediaPlayer>
144{
145public:
146    virtual status_t    onTransact( uint32_t code,
147                                    const Parcel& data,
148                                    Parcel* reply,
149                                    uint32_t flags = 0);
150};
151
152}; // namespace android
153
154#endif // ANDROID_IMEDIAPLAYER_H
155