144a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman/*
244a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman**
344a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman** Copyright 2012, The Android Open Source Project
444a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman**
544a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman** Licensed under the Apache License, Version 2.0 (the "License");
644a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman** you may not use this file except in compliance with the License.
744a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman** You may obtain a copy of the License at
844a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman**
944a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman**     http://www.apache.org/licenses/LICENSE-2.0
1044a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman**
1144a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman** Unless required by applicable law or agreed to in writing, software
1244a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman** distributed under the License is distributed on an "AS IS" BASIS,
1344a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1444a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman** See the License for the specific language governing permissions and
1544a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman** limitations under the License.
1644a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman*/
1744a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
1844a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman#ifndef ANDROID_MEDIAPLAYERFACTORY_H
1944a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman#define ANDROID_MEDIAPLAYERFACTORY_H
2044a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
2144a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman#include <media/MediaPlayerInterface.h>
2244a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman#include <media/stagefright/foundation/ABase.h>
2344a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
2444a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossmannamespace android {
2544a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
2644a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossmanclass MediaPlayerFactory {
2744a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman  public:
2844a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    class IFactory {
2944a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman      public:
3044a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman        virtual ~IFactory() { }
3144a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
32247d9ebdbe7f165644f308745eee061fcbb77771Mark Salyzyn        virtual float scoreFactory(const sp<IMediaPlayer>& /*client*/,
33247d9ebdbe7f165644f308745eee061fcbb77771Mark Salyzyn                                   const char* /*url*/,
34247d9ebdbe7f165644f308745eee061fcbb77771Mark Salyzyn                                   float /*curScore*/) { return 0.0; }
35247d9ebdbe7f165644f308745eee061fcbb77771Mark Salyzyn
36247d9ebdbe7f165644f308745eee061fcbb77771Mark Salyzyn        virtual float scoreFactory(const sp<IMediaPlayer>& /*client*/,
37247d9ebdbe7f165644f308745eee061fcbb77771Mark Salyzyn                                   int /*fd*/,
38247d9ebdbe7f165644f308745eee061fcbb77771Mark Salyzyn                                   int64_t /*offset*/,
39247d9ebdbe7f165644f308745eee061fcbb77771Mark Salyzyn                                   int64_t /*length*/,
40247d9ebdbe7f165644f308745eee061fcbb77771Mark Salyzyn                                   float /*curScore*/) { return 0.0; }
41247d9ebdbe7f165644f308745eee061fcbb77771Mark Salyzyn
42247d9ebdbe7f165644f308745eee061fcbb77771Mark Salyzyn        virtual float scoreFactory(const sp<IMediaPlayer>& /*client*/,
43247d9ebdbe7f165644f308745eee061fcbb77771Mark Salyzyn                                   const sp<IStreamSource> &/*source*/,
44247d9ebdbe7f165644f308745eee061fcbb77771Mark Salyzyn                                   float /*curScore*/) { return 0.0; }
4544a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
4699f31604136d66ae10e20669fb6b5716f342bde0Chris Watkins        virtual float scoreFactory(const sp<IMediaPlayer>& /*client*/,
4799f31604136d66ae10e20669fb6b5716f342bde0Chris Watkins                                   const sp<DataSource> &/*source*/,
4899f31604136d66ae10e20669fb6b5716f342bde0Chris Watkins                                   float /*curScore*/) { return 0.0; }
4999f31604136d66ae10e20669fb6b5716f342bde0Chris Watkins
5068845c14ebf2c7282800b1abffde38d8e9a57aabRonghua Wu        virtual sp<MediaPlayerBase> createPlayer(pid_t pid) = 0;
5144a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    };
5244a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
5344a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    static status_t registerFactory(IFactory* factory,
5444a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman                                    player_type type);
5544a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    static void unregisterFactory(player_type type);
5644a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    static player_type getPlayerType(const sp<IMediaPlayer>& client,
5744a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman                                     const char* url);
5844a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    static player_type getPlayerType(const sp<IMediaPlayer>& client,
5944a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman                                     int fd,
6044a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman                                     int64_t offset,
6144a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman                                     int64_t length);
6244a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    static player_type getPlayerType(const sp<IMediaPlayer>& client,
6344a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman                                     const sp<IStreamSource> &source);
6499f31604136d66ae10e20669fb6b5716f342bde0Chris Watkins    static player_type getPlayerType(const sp<IMediaPlayer>& client,
6599f31604136d66ae10e20669fb6b5716f342bde0Chris Watkins                                     const sp<DataSource> &source);
6644a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
6744a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    static sp<MediaPlayerBase> createPlayer(player_type playerType,
6844a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman                                            void* cookie,
6968845c14ebf2c7282800b1abffde38d8e9a57aabRonghua Wu                                            notify_callback_f notifyFunc,
7068845c14ebf2c7282800b1abffde38d8e9a57aabRonghua Wu                                            pid_t pid);
7144a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
7244a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    static void registerBuiltinFactories();
7344a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
7444a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman  private:
7544a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    typedef KeyedVector<player_type, IFactory*> tFactoryMap;
7644a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
7744a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    MediaPlayerFactory() { }
7844a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
7944a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    static status_t registerFactory_l(IFactory* factory,
8044a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman                                      player_type type);
8144a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
8244a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    static Mutex       sLock;
8344a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    static tFactoryMap sFactoryMap;
8444a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    static bool        sInitComplete;
8544a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
8644a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman    DISALLOW_EVIL_CONSTRUCTORS(MediaPlayerFactory);
8744a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman};
8844a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman
8944a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman}  // namespace android
9044a7e42f0310831e6a846d1b6bb40bf3a399bf6dJohn Grossman#endif  // ANDROID_MEDIAPLAYERFACTORY_H
91