video_state.h 1.9 KB

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