blob: e88700cf5847310c97760d004e07f8d7f00afa9a [file] [log] [blame]
John Grossman44a7e422012-06-21 17:29:24 -07001/*
2**
3** Copyright 2012, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#ifndef ANDROID_MEDIAPLAYERFACTORY_H
19#define ANDROID_MEDIAPLAYERFACTORY_H
20
21#include <media/MediaPlayerInterface.h>
22#include <media/stagefright/foundation/ABase.h>
23
24namespace android {
25
26class MediaPlayerFactory {
27 public:
28 class IFactory {
29 public:
30 virtual ~IFactory() { }
31
Mark Salyzyn247d9eb2014-06-23 14:14:40 -070032 virtual float scoreFactory(const sp<IMediaPlayer>& /*client*/,
33 const char* /*url*/,
34 float /*curScore*/) { return 0.0; }
John Grossman44a7e422012-06-21 17:29:24 -070035
Mark Salyzyn247d9eb2014-06-23 14:14:40 -070036 virtual float scoreFactory(const sp<IMediaPlayer>& /*client*/,
37 int /*fd*/,
38 int64_t /*offset*/,
39 int64_t /*length*/,
40 float /*curScore*/) { return 0.0; }
John Grossman44a7e422012-06-21 17:29:24 -070041
Mark Salyzyn247d9eb2014-06-23 14:14:40 -070042 virtual float scoreFactory(const sp<IMediaPlayer>& /*client*/,
43 const sp<IStreamSource> &/*source*/,
44 float /*curScore*/) { return 0.0; }
John Grossman44a7e422012-06-21 17:29:24 -070045
Chris Watkins99f31602015-03-20 13:06:33 -070046 virtual float scoreFactory(const sp<IMediaPlayer>& /*client*/,
47 const sp<DataSource> &/*source*/,
48 float /*curScore*/) { return 0.0; }
49
Ronghua Wu68845c12015-07-21 09:50:48 -070050 virtual sp<MediaPlayerBase> createPlayer(pid_t pid) = 0;
John Grossman44a7e422012-06-21 17:29:24 -070051 };
52
53 static status_t registerFactory(IFactory* factory,
54 player_type type);
55 static void unregisterFactory(player_type type);
56 static player_type getPlayerType(const sp<IMediaPlayer>& client,
57 const char* url);
58 static player_type getPlayerType(const sp<IMediaPlayer>& client,
59 int fd,
60 int64_t offset,
61 int64_t length);
62 static player_type getPlayerType(const sp<IMediaPlayer>& client,
63 const sp<IStreamSource> &source);
Chris Watkins99f31602015-03-20 13:06:33 -070064 static player_type getPlayerType(const sp<IMediaPlayer>& client,
65 const sp<DataSource> &source);
John Grossman44a7e422012-06-21 17:29:24 -070066
67 static sp<MediaPlayerBase> createPlayer(player_type playerType,
Pawin Vongmasa082e4f72017-12-17 02:31:18 -080068 const sp<MediaPlayerBase::Listener> &listener,
Ronghua Wu68845c12015-07-21 09:50:48 -070069 pid_t pid);
John Grossman44a7e422012-06-21 17:29:24 -070070
71 static void registerBuiltinFactories();
72
73 private:
74 typedef KeyedVector<player_type, IFactory*> tFactoryMap;
75
76 MediaPlayerFactory() { }
77
78 static status_t registerFactory_l(IFactory* factory,
79 player_type type);
John Grossman44a7e422012-06-21 17:29:24 -070080
81 static Mutex sLock;
82 static tFactoryMap sFactoryMap;
83 static bool sInitComplete;
84
85 DISALLOW_EVIL_CONSTRUCTORS(MediaPlayerFactory);
86};
87
88} // namespace android
89#endif // ANDROID_MEDIAPLAYERFACTORY_H