ijksdl_codec_android_mediacodec.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*****************************************************************************
  2. * ijksdl_codec_android_mediacodec.h
  3. *****************************************************************************
  4. *
  5. * Copyright (c) 2014 Bilibili
  6. * copyright (c) 2014 Zhang Rui <bbcallen@gmail.com>
  7. *
  8. * This file is part of ijkPlayer.
  9. *
  10. * ijkPlayer is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * ijkPlayer is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with ijkPlayer; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #ifndef IJKSDL_ANDROID__ANDROID_CODEC_ANDROID_MEDIACODEC_H
  25. #define IJKSDL_ANDROID__ANDROID_CODEC_ANDROID_MEDIACODEC_H
  26. #include "../ijksdl_stdinc.h"
  27. #include <stdbool.h>
  28. #include <jni.h>
  29. #include <sys/types.h>
  30. #include "../ijksdl_class.h"
  31. #include "../ijksdl_mutex.h"
  32. #include "ijksdl_codec_android_mediadef.h"
  33. #include "android_nativewindow.h"
  34. typedef struct SDL_AMediaCodecBufferInfo {
  35. int32_t offset;
  36. int32_t size;
  37. int64_t presentationTimeUs;
  38. uint32_t flags;
  39. } SDL_AMediaCodecBufferInfo;
  40. typedef struct SDL_AMediaFormat SDL_AMediaFormat;
  41. typedef struct SDL_AMediaCrypto SDL_AMediaCrypto;
  42. typedef struct SDL_AMediaCodec_Common SDL_AMediaCodec_Common;
  43. typedef struct SDL_AMediaCodec_Opaque SDL_AMediaCodec_Opaque;
  44. typedef struct SDL_AMediaCodec SDL_AMediaCodec;
  45. typedef struct SDL_AMediaCodec
  46. {
  47. SDL_mutex *mutex;
  48. volatile int ref_count;
  49. SDL_Class *opaque_class;
  50. SDL_AMediaCodec_Common *common;
  51. SDL_AMediaCodec_Opaque *opaque;
  52. bool is_configured;
  53. bool is_started;
  54. int object_serial;
  55. sdl_amedia_status_t (*func_delete)(SDL_AMediaCodec *acodec);
  56. sdl_amedia_status_t (*func_configure)(
  57. SDL_AMediaCodec* acodec,
  58. const SDL_AMediaFormat* aformat,
  59. ANativeWindow* surface,
  60. SDL_AMediaCrypto *crypto,
  61. uint32_t flags);
  62. sdl_amedia_status_t (*func_configure_surface)(
  63. JNIEnv*env,
  64. SDL_AMediaCodec* acodec,
  65. const SDL_AMediaFormat* aformat,
  66. jobject android_surface,
  67. SDL_AMediaCrypto *crypto,
  68. uint32_t flags);
  69. sdl_amedia_status_t (*func_start)(SDL_AMediaCodec* acodec);
  70. sdl_amedia_status_t (*func_stop)(SDL_AMediaCodec* acodec);
  71. sdl_amedia_status_t (*func_flush)(SDL_AMediaCodec* acodec);
  72. ssize_t (*func_writeInputData)(SDL_AMediaCodec* acodec, size_t idx, const uint8_t *data, size_t size);
  73. ssize_t (*func_dequeueInputBuffer)(SDL_AMediaCodec* acodec, int64_t timeoutUs);
  74. sdl_amedia_status_t (*func_queueInputBuffer)(SDL_AMediaCodec* acodec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags);
  75. ssize_t (*func_dequeueOutputBuffer)(SDL_AMediaCodec* acodec, SDL_AMediaCodecBufferInfo *info, int64_t timeoutUs);
  76. SDL_AMediaFormat* (*func_getOutputFormat)(SDL_AMediaCodec* acodec);
  77. sdl_amedia_status_t (*func_releaseOutputBuffer)(SDL_AMediaCodec* acodec, size_t idx, bool render);
  78. bool (*func_isInputBuffersValid)(SDL_AMediaCodec* acodec);
  79. } SDL_AMediaCodec;
  80. int SDL_AMediaCodec_create_object_serial();
  81. sdl_amedia_status_t SDL_AMediaCodec_configure(
  82. SDL_AMediaCodec* acodec,
  83. const SDL_AMediaFormat* aformat,
  84. ANativeWindow* surface,
  85. SDL_AMediaCrypto *crypto,
  86. uint32_t flags);
  87. sdl_amedia_status_t SDL_AMediaCodec_configure_surface(
  88. JNIEnv*env,
  89. SDL_AMediaCodec* acodec,
  90. const SDL_AMediaFormat* aformat,
  91. jobject android_surface,
  92. SDL_AMediaCrypto *crypto,
  93. uint32_t flags);
  94. void SDL_AMediaCodec_increaseReference(SDL_AMediaCodec *acodec);
  95. void SDL_AMediaCodec_decreaseReference(SDL_AMediaCodec *acodec);
  96. void SDL_AMediaCodec_decreaseReferenceP(SDL_AMediaCodec **acodec);
  97. bool SDL_AMediaCodec_isConfigured(SDL_AMediaCodec *acodec);
  98. bool SDL_AMediaCodec_isStarted(SDL_AMediaCodec *acodec);
  99. sdl_amedia_status_t SDL_AMediaCodec_start(SDL_AMediaCodec* acodec);
  100. sdl_amedia_status_t SDL_AMediaCodec_stop(SDL_AMediaCodec* acodec);
  101. sdl_amedia_status_t SDL_AMediaCodec_flush(SDL_AMediaCodec* acodec);
  102. ssize_t SDL_AMediaCodec_writeInputData(SDL_AMediaCodec* acodec, size_t idx, const uint8_t *data, size_t size);
  103. ssize_t SDL_AMediaCodec_dequeueInputBuffer(SDL_AMediaCodec* acodec, int64_t timeoutUs);
  104. sdl_amedia_status_t SDL_AMediaCodec_queueInputBuffer(SDL_AMediaCodec* acodec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags);
  105. ssize_t SDL_AMediaCodec_dequeueOutputBuffer(SDL_AMediaCodec* acodec, SDL_AMediaCodecBufferInfo *info, int64_t timeoutUs);
  106. SDL_AMediaFormat* SDL_AMediaCodec_getOutputFormat(SDL_AMediaCodec* acodec);
  107. sdl_amedia_status_t SDL_AMediaCodec_releaseOutputBuffer(SDL_AMediaCodec* acodec, size_t idx, bool render);
  108. bool SDL_AMediaCodec_isInputBuffersValid(SDL_AMediaCodec* acodec);
  109. int SDL_AMediaCodec_getSerial(SDL_AMediaCodec* acodec);
  110. bool SDL_AMediaCodec_isSameSerial(SDL_AMediaCodec* acodec, int acodec_serial);
  111. // extended
  112. void SDL_AMediaCodecFake_abort(SDL_AMediaCodec* acodec);
  113. void SDL_AMediaCodecFake_flushFakeFrames(SDL_AMediaCodec* acodec);
  114. sdl_amedia_status_t SDL_AMediaCodecFake_queueFakeFrame(SDL_AMediaCodec* acodec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags);
  115. ssize_t SDL_AMediaCodecFake_dequeueOutputBuffer(SDL_AMediaCodec* acodec, SDL_AMediaCodecBufferInfo *info, int64_t timeoutUs);
  116. ssize_t SDL_AMediaCodecFake_dequeueFakeFrameOnly(SDL_AMediaCodec* acodec, SDL_AMediaCodecBufferInfo *info, int64_t timeoutUs);
  117. #endif