TestPlayerStub.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2009 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. #ifndef ANDROID_FRAMEWORKS_BASE_MEDIA_LIBMEDIAPLAYERSERVICE_TESTPLAYERSTUB_H__
  17. #define ANDROID_FRAMEWORKS_BASE_MEDIA_LIBMEDIAPLAYERSERVICE_TESTPLAYERSTUB_H__
  18. #include <media/MediaPlayerInterface.h>
  19. #include <utils/Errors.h>
  20. namespace android {
  21. class MediaPlayerBase; // in media/MediaPlayerInterface.h
  22. // Wrapper around a test media player that gets dynamically loaded.
  23. //
  24. // The URL passed to setDataSource has this format:
  25. //
  26. // test:<name of the .so>?url=<url for the real setDataSource impl.>
  27. //
  28. // e.g:
  29. // test:invoke_test_media_player.so?url=http://youtube.com/
  30. // test:invoke_test_media_player.so?url=speedtest
  31. //
  32. // TestPlayerStub::setDataSource loads the library in the test url. 2
  33. // entry points with C linkage are expected. One to create the test
  34. // player and one to destroy it.
  35. //
  36. // extern "C" android::MediaPlayerBase* newPlayer();
  37. // extern "C" android::status_t deletePlayer(android::MediaPlayerBase *p);
  38. //
  39. // Once the test player has been loaded, its setDataSource
  40. // implementation is called with the value of the 'url' parameter.
  41. //
  42. // typical usage in a java test:
  43. // ============================
  44. //
  45. // MediaPlayer p = new MediaPlayer();
  46. // p.setDataSource("test:invoke_mock_media_player.so?url=http://youtube.com");
  47. // p.prepare();
  48. // ...
  49. // p.release();
  50. class TestPlayerStub : public MediaPlayerInterface {
  51. public:
  52. typedef MediaPlayerBase* (*NEW_PLAYER)();
  53. typedef status_t (*DELETE_PLAYER)(MediaPlayerBase *);
  54. TestPlayerStub();
  55. virtual ~TestPlayerStub();
  56. // Called right after the constructor. Check if the current build
  57. // allows test players.
  58. virtual status_t initCheck();
  59. // @param url Should be a test url. See class comment.
  60. virtual status_t setDataSource(
  61. const sp<IMediaHTTPService> &httpService,
  62. const char* url,
  63. const KeyedVector<String8, String8> *headers);
  64. // Test player for a file descriptor source is not supported.
  65. virtual status_t setDataSource(int, int64_t, int64_t) {
  66. return INVALID_OPERATION;
  67. }
  68. // All the methods below wrap the mPlayer instance.
  69. virtual status_t setVideoSurfaceTexture(
  70. const android::sp<android::IGraphicBufferProducer>& st) {
  71. return mPlayer->setVideoSurfaceTexture(st);
  72. }
  73. virtual status_t prepare() {return mPlayer->prepare();}
  74. virtual status_t prepareAsync() {return mPlayer->prepareAsync();}
  75. virtual status_t start() {return mPlayer->start();}
  76. virtual status_t stop() {return mPlayer->stop();}
  77. virtual status_t pause() {return mPlayer->pause();}
  78. virtual bool isPlaying() {return mPlayer->isPlaying();}
  79. virtual status_t seekTo(
  80. int msec,
  81. MediaPlayerSeekMode mode = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC) {
  82. return mPlayer->seekTo(msec, mode);
  83. }
  84. virtual status_t getCurrentPosition(int *p) {
  85. return mPlayer->getCurrentPosition(p);
  86. }
  87. virtual status_t getDuration(int *d) {return mPlayer->getDuration(d);}
  88. virtual status_t reset() {return mPlayer->reset();}
  89. virtual status_t setLooping(int b) {return mPlayer->setLooping(b);}
  90. virtual player_type playerType() {return mPlayer->playerType();}
  91. virtual status_t invoke(const android::Parcel& in, android::Parcel *out) {
  92. return mPlayer->invoke(in, out);
  93. }
  94. virtual status_t setParameter(int key, const Parcel &request) {
  95. return mPlayer->setParameter(key, request);
  96. }
  97. virtual status_t getParameter(int key, Parcel *reply) {
  98. return mPlayer->getParameter(key, reply);
  99. }
  100. // @return true if the current build is 'eng' or 'test' and the
  101. // url's scheme is 'test:'
  102. static bool canBeUsed(const char *url);
  103. private:
  104. // Release the player, dlclose the library.
  105. status_t resetInternal();
  106. status_t parseUrl();
  107. char *mUrl; // test:foo.so?url=http://bar
  108. char *mFilename; // foo.so
  109. char *mContentUrl; // http://bar
  110. void *mHandle; // returned by dlopen
  111. NEW_PLAYER mNewPlayer;
  112. DELETE_PLAYER mDeletePlayer;
  113. MediaPlayerBase *mPlayer; // wrapped player
  114. };
  115. } // namespace android
  116. #endif