video_state.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @file video_state.h
  3. * @author Steven Huang
  4. */
  5. #pragma once
  6. #include "packets_sync.h"
  7. class VideoStateData
  8. {
  9. public:
  10. explicit VideoStateData(bool use_hardware = false, bool loop_play = false);
  11. virtual ~VideoStateData();
  12. public:
  13. bool has_video() const;
  14. bool has_audio() const;
  15. bool has_subtitle() const;
  16. AVCodecContext* get_contex(AVMediaType type) const;
  17. bool is_hardware_decode() const;
  18. int create_video_state(const char* filename);
  19. void delete_video_state();
  20. VideoState* get_state() const;
  21. void print_state() const;
  22. void threads_setting(VideoState* is, const Threads& threads);
  23. private:
  24. VideoState* stream_open(const char* filename, const AVInputFormat* iformat = NULL);
  25. void stream_close(VideoState* is);
  26. int stream_component_open(VideoState* is, int stream_index);
  27. void stream_component_close(VideoState* is, int stream_index);
  28. int open_media(VideoState* is);
  29. enum AVHWDeviceType get_hwdevice(const char* device) const;
  30. enum AVPixelFormat get_hwdevice_decoder(const AVCodec* decoder, enum AVHWDeviceType type) const;
  31. bool open_hardware(AVCodecContext* avctx, const AVCodec* codec, const char* device = "dxva2");
  32. void close_hardware();
  33. int hw_decoder_init(AVCodecContext* ctx, const enum AVHWDeviceType type);
  34. void read_thread_exit_wait(VideoState* is);
  35. void threads_exit_wait(VideoState* is);
  36. private:
  37. VideoState* m_pState{nullptr};
  38. bool m_bHasVideo{false};
  39. bool m_bHasAudio{false};
  40. bool m_bHasSubtitle{false};
  41. AVCodecContext* m_avctxVideo{nullptr};
  42. AVCodecContext* m_avctxAudio{nullptr};
  43. AVCodecContext* m_avctxSubtitle{nullptr};
  44. /**hardware decode**/
  45. bool m_bUseHardware{false};
  46. bool m_bHardwareSuccess{false};
  47. AVBufferRef* m_hw_device_ctx{nullptr};
  48. //enum AVPixelFormat m_hw_pix_fmt;
  49. bool m_bLoopPlay{false};
  50. };