ijksdl_codec_android_mediacodec_dummy.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2014 Bilibili
  3. * copyright (c) 2014 Zhang Rui <bbcallen@gmail.com>
  4. *
  5. * This file is part of ijkPlayer.
  6. *
  7. * ijkPlayer is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * ijkPlayer is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with ijkPlayer; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "ijksdl_codec_android_mediacodec_dummy.h"
  22. #include <assert.h>
  23. #include "ijksdl/ijksdl_log.h"
  24. #include "ijksdl_codec_android_mediadef.h"
  25. #include "ijksdl_codec_android_mediacodec.h"
  26. #include "ijksdl_codec_android_mediacodec_internal.h"
  27. #define DMY_TRACE(...)
  28. //#define DMY_TRACE ALOGE
  29. static SDL_Class g_amediacodec_class = {
  30. .name = "AMediaCodecDummy",
  31. };
  32. typedef struct SDL_AMediaCodec_Opaque {
  33. bool request_stop;
  34. SDL_AMediaCodec_FakeFifo dummy_fifo;
  35. } SDL_AMediaCodec_Opaque;
  36. static SDL_AMediaFormat *SDL_AMediaCodecDummy_getOutputFormat(SDL_AMediaCodec *thiz)
  37. {
  38. return NULL;
  39. }
  40. static sdl_amedia_status_t SDL_AMediaCodecDummy_delete(SDL_AMediaCodec* acodec)
  41. {
  42. SDL_AMediaCodec_FakeFifo_destroy(&acodec->opaque->dummy_fifo);
  43. SDL_AMediaCodec_FreeInternal(acodec);
  44. return SDL_AMEDIA_OK;
  45. }
  46. static sdl_amedia_status_t SDL_AMediaCodecDummy_configure_surface(
  47. JNIEnv*env,
  48. SDL_AMediaCodec* acodec,
  49. const SDL_AMediaFormat* aformat,
  50. jobject android_surface,
  51. SDL_AMediaCrypto *crypto,
  52. uint32_t flags)
  53. {
  54. return SDL_AMEDIA_OK;
  55. }
  56. static sdl_amedia_status_t SDL_AMediaCodecDummy_start(SDL_AMediaCodec* acodec)
  57. {
  58. acodec->opaque->request_stop = false;
  59. return SDL_AMEDIA_OK;
  60. }
  61. static sdl_amedia_status_t SDL_AMediaCodecDummy_stop(SDL_AMediaCodec* acodec)
  62. {
  63. acodec->opaque->request_stop = true;
  64. SDL_AMediaCodec_FakeFifo_abort(&acodec->opaque->dummy_fifo);
  65. return SDL_AMEDIA_OK;
  66. }
  67. static sdl_amedia_status_t SDL_AMediaCodecDummy_flush(SDL_AMediaCodec* acodec)
  68. {
  69. SDL_AMediaCodec_FakeFifo_flush(&acodec->opaque->dummy_fifo);
  70. return SDL_AMEDIA_OK;
  71. }
  72. static ssize_t SDL_AMediaCodecDummy_writeInputData(SDL_AMediaCodec* acodec, size_t idx, const uint8_t *data, size_t size)
  73. {
  74. return size;
  75. }
  76. static ssize_t SDL_AMediaCodecDummy_dequeueInputBuffer(SDL_AMediaCodec* acodec, int64_t timeoutUs)
  77. {
  78. DMY_TRACE("%s", __func__);
  79. return SDL_AMediaCodec_FakeFifo_dequeueInputBuffer(&acodec->opaque->dummy_fifo, timeoutUs);
  80. }
  81. static sdl_amedia_status_t SDL_AMediaCodecDummy_queueInputBuffer(SDL_AMediaCodec* acodec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
  82. {
  83. DMY_TRACE("%s", __func__);
  84. return SDL_AMediaCodec_FakeFifo_queueInputBuffer(&acodec->opaque->dummy_fifo, idx, offset, size, time, flags | AMEDIACODEC__BUFFER_FLAG_FAKE_FRAME);
  85. }
  86. static ssize_t SDL_AMediaCodecDummy_dequeueOutputBuffer(SDL_AMediaCodec* acodec, SDL_AMediaCodecBufferInfo *info, int64_t timeoutUs)
  87. {
  88. DMY_TRACE("%s", __func__);
  89. return SDL_AMediaCodec_FakeFifo_dequeueOutputBuffer(&acodec->opaque->dummy_fifo, info, timeoutUs);
  90. }
  91. static sdl_amedia_status_t SDL_AMediaCodecDummy_releaseOutputBuffer(SDL_AMediaCodec* acodec, size_t idx, bool render)
  92. {
  93. DMY_TRACE("%s", __func__);
  94. return SDL_AMEDIA_OK;
  95. }
  96. static bool SDL_AMediaCodecDummy_isInputBuffersValid(SDL_AMediaCodec* acodec)
  97. {
  98. return !acodec->opaque->request_stop;
  99. }
  100. SDL_AMediaCodec* SDL_AMediaCodecDummy_create()
  101. {
  102. ALOGI("%s\n", __func__);
  103. SDL_AMediaCodec *acodec = SDL_AMediaCodec_CreateInternal(sizeof(SDL_AMediaCodec_Opaque));
  104. if (!acodec)
  105. return NULL;
  106. SDL_AMediaCodec_Opaque *opaque = acodec->opaque;
  107. SDL_AMediaCodec_FakeFifo_init(&opaque->dummy_fifo);
  108. acodec->opaque_class = &g_amediacodec_class;
  109. acodec->func_delete = SDL_AMediaCodecDummy_delete;
  110. acodec->func_configure = NULL;
  111. acodec->func_configure_surface = SDL_AMediaCodecDummy_configure_surface;
  112. acodec->func_start = SDL_AMediaCodecDummy_start;
  113. acodec->func_stop = SDL_AMediaCodecDummy_stop;
  114. acodec->func_flush = SDL_AMediaCodecDummy_flush;
  115. acodec->func_writeInputData = SDL_AMediaCodecDummy_writeInputData;
  116. acodec->func_dequeueInputBuffer = SDL_AMediaCodecDummy_dequeueInputBuffer;
  117. acodec->func_queueInputBuffer = SDL_AMediaCodecDummy_queueInputBuffer;
  118. acodec->func_dequeueOutputBuffer = SDL_AMediaCodecDummy_dequeueOutputBuffer;
  119. acodec->func_getOutputFormat = SDL_AMediaCodecDummy_getOutputFormat;
  120. acodec->func_releaseOutputBuffer = SDL_AMediaCodecDummy_releaseOutputBuffer;
  121. acodec->func_isInputBuffersValid = SDL_AMediaCodecDummy_isInputBuffersValid;
  122. SDL_AMediaCodec_increaseReference(acodec);
  123. return acodec;
  124. }