MediaPlayerFactory.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  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. #ifndef ANDROID_MEDIAPLAYERFACTORY_H
  18. #define ANDROID_MEDIAPLAYERFACTORY_H
  19. #include <media/MediaPlayerInterface.h>
  20. #include <media/stagefright/foundation/ABase.h>
  21. namespace android {
  22. class MediaPlayerFactory {
  23. public:
  24. class IFactory {
  25. public:
  26. virtual ~IFactory() { }
  27. virtual float scoreFactory(const sp<IMediaPlayer>& /*client*/,
  28. const char* /*url*/,
  29. float /*curScore*/) { return 0.0; }
  30. virtual float scoreFactory(const sp<IMediaPlayer>& /*client*/,
  31. int /*fd*/,
  32. int64_t /*offset*/,
  33. int64_t /*length*/,
  34. float /*curScore*/) { return 0.0; }
  35. virtual float scoreFactory(const sp<IMediaPlayer>& /*client*/,
  36. const sp<IStreamSource> &/*source*/,
  37. float /*curScore*/) { return 0.0; }
  38. virtual float scoreFactory(const sp<IMediaPlayer>& /*client*/,
  39. const sp<DataSource> &/*source*/,
  40. float /*curScore*/) { return 0.0; }
  41. virtual sp<MediaPlayerBase> createPlayer(pid_t pid) = 0;
  42. };
  43. static status_t registerFactory(IFactory* factory,
  44. player_type type);
  45. static void unregisterFactory(player_type type);
  46. static player_type getPlayerType(const sp<IMediaPlayer>& client,
  47. const char* url);
  48. static player_type getPlayerType(const sp<IMediaPlayer>& client,
  49. int fd,
  50. int64_t offset,
  51. int64_t length);
  52. static player_type getPlayerType(const sp<IMediaPlayer>& client,
  53. const sp<IStreamSource> &source);
  54. static player_type getPlayerType(const sp<IMediaPlayer>& client,
  55. const sp<DataSource> &source);
  56. static sp<MediaPlayerBase> createPlayer(player_type playerType,
  57. const sp<MediaPlayerBase::Listener> &listener,
  58. pid_t pid);
  59. static void registerBuiltinFactories();
  60. private:
  61. typedef KeyedVector<player_type, IFactory*> tFactoryMap;
  62. MediaPlayerFactory() { }
  63. static status_t registerFactory_l(IFactory* factory,
  64. player_type type);
  65. static Mutex sLock;
  66. static tFactoryMap sFactoryMap;
  67. static bool sInitComplete;
  68. DISALLOW_EVIL_CONSTRUCTORS(MediaPlayerFactory);
  69. };
  70. } // namespace android
  71. #endif // ANDROID_MEDIAPLAYERFACTORY_H