mediacodec_wrapper.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Android MediaCodec Wrapper
  3. *
  4. * Copyright (c) 2015-2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVCODEC_MEDIACODEC_WRAPPER_H
  23. #define AVCODEC_MEDIACODEC_WRAPPER_H
  24. #include <stdint.h>
  25. #include <sys/types.h>
  26. #include "avcodec.h"
  27. /**
  28. * The following API around MediaCodec and MediaFormat is based on the
  29. * NDK one provided by Google since Android 5.0.
  30. *
  31. * Differences from the NDK API:
  32. *
  33. * Buffers returned by ff_AMediaFormat_toString and ff_AMediaFormat_getString
  34. * are newly allocated buffer and must be freed by the user after use.
  35. *
  36. * The MediaCrypto API is not implemented.
  37. *
  38. * ff_AMediaCodec_infoTryAgainLater, ff_AMediaCodec_infoOutputBuffersChanged,
  39. * ff_AMediaCodec_infoOutputFormatChanged, ff_AMediaCodec_cleanOutputBuffers
  40. * ff_AMediaCodec_getName and ff_AMediaCodec_getBufferFlagEndOfStream are not
  41. * part of the original NDK API and are convenience functions to hide JNI
  42. * implementation.
  43. *
  44. * The API around MediaCodecList is not part of the NDK (and is lacking as
  45. * we still need to retrieve the codec name to work around faulty decoders
  46. * and encoders).
  47. *
  48. * For documentation, please refers to NdkMediaCodec.h NdkMediaFormat.h and
  49. * http://developer.android.com/reference/android/media/MediaCodec.html.
  50. *
  51. */
  52. int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx);
  53. char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx);
  54. struct FFAMediaFormat;
  55. typedef struct FFAMediaFormat FFAMediaFormat;
  56. FFAMediaFormat *ff_AMediaFormat_new(void);
  57. int ff_AMediaFormat_delete(FFAMediaFormat* format);
  58. char* ff_AMediaFormat_toString(FFAMediaFormat* format);
  59. int ff_AMediaFormat_getInt32(FFAMediaFormat* format, const char *name, int32_t *out);
  60. int ff_AMediaFormat_getInt64(FFAMediaFormat* format, const char *name, int64_t *out);
  61. int ff_AMediaFormat_getFloat(FFAMediaFormat* format, const char *name, float *out);
  62. int ff_AMediaFormat_getBuffer(FFAMediaFormat* format, const char *name, void** data, size_t *size);
  63. int ff_AMediaFormat_getString(FFAMediaFormat* format, const char *name, const char **out);
  64. void ff_AMediaFormat_setInt32(FFAMediaFormat* format, const char* name, int32_t value);
  65. void ff_AMediaFormat_setInt64(FFAMediaFormat* format, const char* name, int64_t value);
  66. void ff_AMediaFormat_setFloat(FFAMediaFormat* format, const char* name, float value);
  67. void ff_AMediaFormat_setString(FFAMediaFormat* format, const char* name, const char* value);
  68. void ff_AMediaFormat_setBuffer(FFAMediaFormat* format, const char* name, void* data, size_t size);
  69. struct FFAMediaCodec;
  70. typedef struct FFAMediaCodec FFAMediaCodec;
  71. typedef struct FFAMediaCodecCryptoInfo FFAMediaCodecCryptoInfo;
  72. struct FFAMediaCodecBufferInfo {
  73. int32_t offset;
  74. int32_t size;
  75. int64_t presentationTimeUs;
  76. uint32_t flags;
  77. };
  78. typedef struct FFAMediaCodecBufferInfo FFAMediaCodecBufferInfo;
  79. char *ff_AMediaCodec_getName(FFAMediaCodec *codec);
  80. FFAMediaCodec* ff_AMediaCodec_createCodecByName(const char *name);
  81. FFAMediaCodec* ff_AMediaCodec_createDecoderByType(const char *mime_type);
  82. FFAMediaCodec* ff_AMediaCodec_createEncoderByType(const char *mime_type);
  83. int ff_AMediaCodec_configure(FFAMediaCodec* codec, const FFAMediaFormat* format, void* surface, void *crypto, uint32_t flags);
  84. int ff_AMediaCodec_start(FFAMediaCodec* codec);
  85. int ff_AMediaCodec_stop(FFAMediaCodec* codec);
  86. int ff_AMediaCodec_flush(FFAMediaCodec* codec);
  87. int ff_AMediaCodec_delete(FFAMediaCodec* codec);
  88. uint8_t* ff_AMediaCodec_getInputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size);
  89. uint8_t* ff_AMediaCodec_getOutputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size);
  90. ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec* codec, int64_t timeoutUs);
  91. int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec* codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags);
  92. ssize_t ff_AMediaCodec_dequeueOutputBuffer(FFAMediaCodec* codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs);
  93. FFAMediaFormat* ff_AMediaCodec_getOutputFormat(FFAMediaCodec* codec);
  94. int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec* codec, size_t idx, int render);
  95. int ff_AMediaCodec_releaseOutputBufferAtTime(FFAMediaCodec *codec, size_t idx, int64_t timestampNs);
  96. int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx);
  97. int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx);
  98. int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t indx);
  99. int ff_AMediaCodec_getBufferFlagCodecConfig (FFAMediaCodec *codec);
  100. int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec);
  101. int ff_AMediaCodec_getBufferFlagKeyFrame(FFAMediaCodec *codec);
  102. int ff_AMediaCodec_getConfigureFlagEncode(FFAMediaCodec *codec);
  103. int ff_AMediaCodec_cleanOutputBuffers(FFAMediaCodec *codec);
  104. int ff_Build_SDK_INT(AVCodecContext *avctx);
  105. #endif /* AVCODEC_MEDIACODEC_WRAPPER_H */