video_state.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. int seekByBytes() { return seek_by_bytes; }
  26. private:
  27. VideoState* stream_open(const char* filename, const AVInputFormat* iformat = NULL);
  28. void stream_close(VideoState* is);
  29. int stream_component_open(VideoState* is, int stream_index);
  30. void stream_component_close(VideoState* is, int stream_index);
  31. int open_media(VideoState* is);
  32. enum AVHWDeviceType get_hwdevice(const char* device) const;
  33. enum AVPixelFormat get_hwdevice_decoder(const AVCodec* decoder, enum AVHWDeviceType type) const;
  34. bool open_hardware(AVCodecContext* avctx, const AVCodec* codec, const char* device = "dxva2");
  35. void close_hardware();
  36. int hw_decoder_init(AVCodecContext* ctx, const enum AVHWDeviceType type);
  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{true};
  51. int seek_by_bytes = -1;
  52. };
  53. #endif // AVPLAYER2_VIDEO_STATE_H