Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

126 lignes
3.8KB

  1. /*
  2. * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
  3. *
  4. * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
  5. *
  6. * Use of this source code is governed by MIT license that can be found in the
  7. * LICENSE file in the root of the source tree. All contributing project authors
  8. * may be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "mk_transcode.h"
  11. #include "Extension/Track.h"
  12. using namespace mediakit;
  13. #ifdef ENABLE_FFMPEG
  14. #include "Codec/Transcode.h"
  15. API_EXPORT mk_decoder API_CALL mk_decoder_create(mk_track track, int thread_num) {
  16. assert(track);
  17. return new FFmpegDecoder(*((Track::Ptr *)track), thread_num);
  18. }
  19. API_EXPORT void API_CALL mk_decoder_release(mk_decoder ctx, int flush_frame) {
  20. assert(ctx);
  21. auto decoder = (FFmpegDecoder *)ctx;
  22. if (flush_frame) {
  23. decoder->stopThread(false);
  24. }
  25. delete decoder;
  26. }
  27. API_EXPORT void API_CALL mk_decoder_decode(mk_decoder ctx, mk_frame frame, int async, int enable_merge) {
  28. assert(ctx && frame);
  29. ((FFmpegDecoder *)ctx)->inputFrame(*((Frame::Ptr *)frame), false, async, enable_merge);
  30. }
  31. API_EXPORT void API_CALL mk_decoder_set_max_async_frame_size(mk_decoder ctx, size_t size) {
  32. assert(ctx && size);
  33. ((FFmpegDecoder *)ctx)->setMaxTaskSize(size);
  34. }
  35. API_EXPORT void API_CALL mk_decoder_set_cb(mk_decoder ctx, on_mk_decode cb, void *user_data) {
  36. assert(ctx && cb);
  37. ((FFmpegDecoder *)ctx)->setOnDecode([cb, user_data](const FFmpegFrame::Ptr &pix_frame) {
  38. cb(user_data, (mk_frame_pix)&pix_frame);
  39. });
  40. }
  41. API_EXPORT const AVCodecContext *API_CALL mk_decoder_get_context(mk_decoder ctx) {
  42. assert(ctx);
  43. return ((FFmpegDecoder *)ctx)->getContext();
  44. }
  45. /////////////////////////////////////////////////////////////////////////////////////////////
  46. API_EXPORT mk_frame_pix API_CALL mk_frame_pix_ref(mk_frame_pix frame) {
  47. assert(frame);
  48. return new FFmpegFrame::Ptr(*(FFmpegFrame::Ptr *)frame);
  49. }
  50. API_EXPORT mk_frame_pix API_CALL mk_frame_pix_from_av_frame(AVFrame *frame) {
  51. assert(frame);
  52. return new FFmpegFrame::Ptr(std::make_shared<FFmpegFrame>(
  53. std::shared_ptr<AVFrame>(av_frame_clone(frame), [](AVFrame *frame) { av_frame_free(&frame); })));
  54. }
  55. API_EXPORT void API_CALL mk_frame_pix_unref(mk_frame_pix frame) {
  56. assert(frame);
  57. delete (FFmpegFrame::Ptr *)frame;
  58. }
  59. API_EXPORT AVFrame *API_CALL mk_frame_pix_get_av_frame(mk_frame_pix frame) {
  60. assert(frame);
  61. return (*(FFmpegFrame::Ptr *)frame)->get();
  62. }
  63. //////////////////////////////////////////////////////////////////////////////////
  64. API_EXPORT mk_swscale mk_swscale_create(int output, int width, int height) {
  65. return new FFmpegSws((AVPixelFormat)output, width, height);
  66. }
  67. API_EXPORT void mk_swscale_release(mk_swscale ctx) {
  68. delete (FFmpegSws *)ctx;
  69. }
  70. API_EXPORT int mk_swscale_input_frame(mk_swscale ctx, mk_frame_pix frame, uint8_t *data) {
  71. return ((FFmpegSws *)ctx)->inputFrame(*(FFmpegFrame::Ptr *)frame, data);
  72. }
  73. API_EXPORT mk_frame_pix mk_swscale_input_frame2(mk_swscale ctx, mk_frame_pix frame) {
  74. return new FFmpegFrame::Ptr(((FFmpegSws *)ctx)->inputFrame(*(FFmpegFrame::Ptr *)frame));
  75. }
  76. API_EXPORT uint8_t **API_CALL mk_get_av_frame_data(AVFrame *frame) {
  77. return frame->data;
  78. }
  79. API_EXPORT int *API_CALL mk_get_av_frame_line_size(AVFrame *frame) {
  80. return frame->linesize;
  81. }
  82. API_EXPORT int64_t API_CALL mk_get_av_frame_dts(AVFrame *frame) {
  83. return frame->pkt_dts;
  84. }
  85. API_EXPORT int64_t API_CALL mk_get_av_frame_pts(AVFrame *frame) {
  86. return frame->pts;
  87. }
  88. API_EXPORT int API_CALL mk_get_av_frame_width(AVFrame *frame) {
  89. return frame->width;
  90. }
  91. API_EXPORT int API_CALL mk_get_av_frame_height(AVFrame *frame) {
  92. return frame->height;
  93. }
  94. API_EXPORT int API_CALL mk_get_av_frame_format(AVFrame *frame) {
  95. return frame->format;
  96. }
  97. #endif //ENABLE_FFMPEG