blob: 416d241c553cbd7946714cf4ea900d141cd5744c [file] [log] [blame]
Wei Jia53692fa2017-12-11 10:33:46 -08001/*
2**
3** Copyright 2017, 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_MEDIAPLAYER2FACTORY_H
19#define ANDROID_MEDIAPLAYER2FACTORY_H
20
21#include <media/MediaPlayer2Interface.h>
22#include <media/stagefright/foundation/ABase.h>
23
24namespace android {
25
26class MediaPlayer2Factory {
27 public:
28 class IFactory {
29 public:
30 virtual ~IFactory() { }
31
32 virtual float scoreFactory(const sp<MediaPlayer2Engine>& /*client*/,
33 const char* /*url*/,
34 float /*curScore*/) { return 0.0; }
35
36 virtual float scoreFactory(const sp<MediaPlayer2Engine>& /*client*/,
37 int /*fd*/,
38 int64_t /*offset*/,
39 int64_t /*length*/,
40 float /*curScore*/) { return 0.0; }
41
42 virtual float scoreFactory(const sp<MediaPlayer2Engine>& /*client*/,
43 const sp<IStreamSource> &/*source*/,
44 float /*curScore*/) { return 0.0; }
45
46 virtual float scoreFactory(const sp<MediaPlayer2Engine>& /*client*/,
47 const sp<DataSource> &/*source*/,
48 float /*curScore*/) { return 0.0; }
49
50 virtual sp<MediaPlayer2Base> createPlayer(pid_t pid) = 0;
51 };
52
Wei Jia53692fa2017-12-11 10:33:46 -080053 static player2_type getPlayerType(const sp<MediaPlayer2Engine>& client,
54 const char* url);
55 static player2_type getPlayerType(const sp<MediaPlayer2Engine>& client,
56 int fd,
57 int64_t offset,
58 int64_t length);
59 static player2_type getPlayerType(const sp<MediaPlayer2Engine>& client,
60 const sp<IStreamSource> &source);
61 static player2_type getPlayerType(const sp<MediaPlayer2Engine>& client,
62 const sp<DataSource> &source);
63
64 static sp<MediaPlayer2Base> createPlayer(player2_type playerType,
Pawin Vongmasa50963852017-12-12 06:24:42 -080065 const wp<MediaPlayer2Engine> &client,
66 MediaPlayer2Base::NotifyCallback notifyFunc,
Wei Jia53692fa2017-12-11 10:33:46 -080067 pid_t pid);
68
69 static void registerBuiltinFactories();
70
71 private:
72 typedef KeyedVector<player2_type, IFactory*> tFactoryMap;
73
74 MediaPlayer2Factory() { }
75
Wei Jia787ed442018-01-24 18:03:04 -080076 static bool ensureInit_l();
77
Wei Jia53692fa2017-12-11 10:33:46 -080078 static status_t registerFactory_l(IFactory* factory,
79 player2_type type);
80
81 static Mutex sLock;
Wei Jia787ed442018-01-24 18:03:04 -080082 static tFactoryMap *sFactoryMap;
Wei Jia53692fa2017-12-11 10:33:46 -080083 static bool sInitComplete;
84
85 DISALLOW_EVIL_CONSTRUCTORS(MediaPlayer2Factory);
86};
87
88} // namespace android
89#endif // ANDROID_MEDIAPLAYER2FACTORY_H