mediacodec.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Android MediaCodec public API
  3. *
  4. * Copyright (c) 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_H
  23. #define AVCODEC_MEDIACODEC_H
  24. #include "libavcodec/avcodec.h"
  25. /**
  26. * This structure holds a reference to a android/view/Surface object that will
  27. * be used as output by the decoder.
  28. *
  29. */
  30. typedef struct AVMediaCodecContext {
  31. /**
  32. * android/view/Surface object reference.
  33. */
  34. void *surface;
  35. } AVMediaCodecContext;
  36. /**
  37. * Allocate and initialize a MediaCodec context.
  38. *
  39. * When decoding with MediaCodec is finished, the caller must free the
  40. * MediaCodec context with av_mediacodec_default_free.
  41. *
  42. * @return a pointer to a newly allocated AVMediaCodecContext on success, NULL otherwise
  43. */
  44. AVMediaCodecContext *av_mediacodec_alloc_context(void);
  45. /**
  46. * Convenience function that sets up the MediaCodec context.
  47. *
  48. * @param avctx codec context
  49. * @param ctx MediaCodec context to initialize
  50. * @param surface reference to an android/view/Surface
  51. * @return 0 on success, < 0 otherwise
  52. */
  53. int av_mediacodec_default_init(AVCodecContext *avctx, AVMediaCodecContext *ctx, void *surface);
  54. /**
  55. * This function must be called to free the MediaCodec context initialized with
  56. * av_mediacodec_default_init().
  57. *
  58. * @param avctx codec context
  59. */
  60. void av_mediacodec_default_free(AVCodecContext *avctx);
  61. /**
  62. * Opaque structure representing a MediaCodec buffer to render.
  63. */
  64. typedef struct MediaCodecBuffer AVMediaCodecBuffer;
  65. /**
  66. * Release a MediaCodec buffer and render it to the surface that is associated
  67. * with the decoder. This function should only be called once on a given
  68. * buffer, once released the underlying buffer returns to the codec, thus
  69. * subsequent calls to this function will have no effect.
  70. *
  71. * @param buffer the buffer to render
  72. * @param render 1 to release and render the buffer to the surface or 0 to
  73. * discard the buffer
  74. * @return 0 on success, < 0 otherwise
  75. */
  76. int av_mediacodec_release_buffer(AVMediaCodecBuffer *buffer, int render);
  77. /**
  78. * Release a MediaCodec buffer and render it at the given time to the surface
  79. * that is associated with the decoder. The timestamp must be within one second
  80. * of the current java/lang/System#nanoTime() (which is implemented using
  81. * CLOCK_MONOTONIC on Android). See the Android MediaCodec documentation
  82. * of android/media/MediaCodec#releaseOutputBuffer(int,long) for more details.
  83. *
  84. * @param buffer the buffer to render
  85. * @param time timestamp in nanoseconds of when to render the buffer
  86. * @return 0 on success, < 0 otherwise
  87. */
  88. int av_mediacodec_render_buffer_at_time(AVMediaCodecBuffer *buffer, int64_t time);
  89. #endif /* AVCODEC_MEDIACODEC_H */