ffmpeg-decode.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <obs.h>
  19. #ifdef _MSC_VER
  20. #pragma warning(push)
  21. #pragma warning(disable : 4244)
  22. #pragma warning(disable : 4204)
  23. #endif
  24. #include <libavcodec/avcodec.h>
  25. #include <libavutil/log.h>
  26. #ifdef _MSC_VER
  27. #pragma warning(pop)
  28. #endif
  29. struct ffmpeg_decode {
  30. AVBufferRef *hw_device_ctx;
  31. AVCodecContext *decoder;
  32. const AVCodec *codec;
  33. AVFrame *hw_frame;
  34. AVFrame *frame;
  35. bool hw;
  36. uint8_t *packet_buffer;
  37. size_t packet_size;
  38. };
  39. extern int ffmpeg_decode_init(struct ffmpeg_decode *decode, enum AVCodecID id, bool use_hw);
  40. extern void ffmpeg_decode_free(struct ffmpeg_decode *decode);
  41. extern bool ffmpeg_decode_audio(struct ffmpeg_decode *decode, uint8_t *data, size_t size,
  42. struct obs_source_audio *audio, bool *got_output);
  43. extern bool ffmpeg_decode_video(struct ffmpeg_decode *decode, uint8_t *data, size_t size, long long *ts,
  44. enum video_colorspace cs, enum video_range_type range, struct obs_source_frame2 *frame,
  45. bool *got_output);
  46. static inline bool ffmpeg_decode_valid(struct ffmpeg_decode *decode)
  47. {
  48. return decode->decoder != NULL;
  49. }
  50. #ifdef __cplusplus
  51. }
  52. #endif