ffmpeg-decode.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /******************************************************************************
  2. Copyright (C) 2014 by Hugh 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,
  40. bool use_hw);
  41. extern void ffmpeg_decode_free(struct ffmpeg_decode *decode);
  42. extern bool ffmpeg_decode_audio(struct ffmpeg_decode *decode, uint8_t *data,
  43. size_t size, struct obs_source_audio *audio,
  44. bool *got_output);
  45. extern bool ffmpeg_decode_video(struct ffmpeg_decode *decode, uint8_t *data,
  46. size_t size, long long *ts,
  47. enum video_range_type range,
  48. struct obs_source_frame2 *frame,
  49. bool *got_output);
  50. static inline bool ffmpeg_decode_valid(struct ffmpeg_decode *decode)
  51. {
  52. return decode->decoder != NULL;
  53. }
  54. #ifdef __cplusplus
  55. }
  56. #endif